Changeset 5d96f427 in mainline


Ignore:
Timestamp:
2024-11-15T16:44:25Z (6 months ago)
Author:
Miroslav Cimerman <mc@…>
Children:
733564a
Parents:
bd51105
git-author:
Miroslav Cimerman <mc@…> (2024-11-15 16:08:11)
git-committer:
Miroslav Cimerman <mc@…> (2024-11-15 16:44:25)
Message:

hr: use DPRINTF and ERR_PRINTF macros from util.h

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

Legend:

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

    rbd51105 r5d96f427  
    6262static hr_volume_t *hr_get_volume(service_id_t svc_id)
    6363{
    64         log_msg(LOG_DEFAULT, LVL_DEBUG, "hr_get_volume(): (%" PRIun ")",
    65             svc_id);
     64        DPRINTF("hr_get_volume(): (%" PRIun ")\n", svc_id);
    6665
    6766        fibril_mutex_lock(&hr_volumes_lock);
     
    7978static errno_t hr_remove_volume(service_id_t svc_id)
    8079{
    81         log_msg(LOG_DEFAULT, LVL_DEBUG, "hr_remove_volume(): (%" PRIun ")",
    82             svc_id);
     80        DPRINTF("hr_remove_volume(): (%" PRIun ")\n", svc_id);
    8381
    8482        fibril_mutex_lock(&hr_volumes_lock);
     
    9997static void hr_create_srv(ipc_call_t *icall, bool assemble)
    10098{
    101         log_msg(LOG_DEFAULT, LVL_NOTE, "hr_create_srv()");
     99        DPRINTF("hr_create_srv()\n");
    102100
    103101        errno_t rc;
     
    141139                for (i = 0; i < cfg->dev_no; i++) {
    142140                        if (cfg->devs[i] == 0) {
     141                                ERR_PRINTF("missing device provided for array "
     142                                    "creation, aborting");
    143143                                free(cfg);
    144144                                async_answer_0(icall, EINVAL);
     
    205205                break;
    206206        default:
    207                 log_msg(LOG_DEFAULT, LVL_ERROR,
    208                     "level %d not implemented yet", new_volume->level);
     207                ERR_PRINTF("unkown level: %d, aborting\n", new_volume->level);
    209208                rc = EINVAL;
    210209                goto error;
     
    232231
    233232        if (assemble) {
    234                 log_msg(LOG_DEFAULT, LVL_NOTE,
    235                     "assembled volume \"%s\" (%" PRIun ")",
     233                DPRINTF("assembled volume \"%s\" (%" PRIun ")\n",
    236234                    new_volume->devname, new_volume->svc_id);
    237235        } else {
    238                 log_msg(LOG_DEFAULT, LVL_NOTE,
    239                     "created volume \"%s\" (%" PRIun ")",
     236                DPRINTF("created volume \"%s\" (%" PRIun ")\n",
    240237                    new_volume->devname, new_volume->svc_id);
    241238        }
     
    253250static void hr_stop_srv(ipc_call_t *icall)
    254251{
    255         log_msg(LOG_DEFAULT, LVL_NOTE, "hr_stop_srv()");
     252        DPRINTF("hr_stop_srv()\n");
    256253
    257254        errno_t rc = EOK;
     
    287284static void hr_print_status_srv(ipc_call_t *icall)
    288285{
    289         log_msg(LOG_DEFAULT, LVL_NOTE, "hr_status_srv()");
     286        DPRINTF("hr_status_srv()\n");
    290287
    291288        errno_t rc;
     
    351348static void hr_ctl_conn(ipc_call_t *icall, void *arg)
    352349{
    353         log_msg(LOG_DEFAULT, LVL_NOTE, "hr_ctl_conn()");
     350        DPRINTF("hr_ctl_conn()\n");
    354351
    355352        async_accept_0(icall);
     
    386383static void hr_client_conn(ipc_call_t *icall, void *arg)
    387384{
    388         log_msg(LOG_DEFAULT, LVL_NOTE, "hr_client_conn()");
     385        DPRINTF("hr_client_conn()\n");
    389386
    390387        hr_volume_t *vol;
     
    395392                hr_ctl_conn(icall, arg);
    396393        } else {
    397                 log_msg(LOG_DEFAULT, LVL_NOTE, "bd_conn()");
     394                DPRINTF("bd_conn()\n");
    398395                vol = hr_get_volume(svc_id);
    399396                if (vol == NULL)
     
    422419        rc = loc_server_register(NAME, &hr_srv);
    423420        if (rc != EOK) {
    424                 log_msg(LOG_DEFAULT, LVL_ERROR,
    425                     "failed registering server: %s", str_error(rc));
     421                ERR_PRINTF("failed registering server: %s", str_error(rc));
    426422                return EEXIST;
    427423        }
     
    429425        rc = loc_service_register(hr_srv, SERVICE_NAME_HR, &ctl_sid);
    430426        if (rc != EOK) {
    431                 log_msg(LOG_DEFAULT, LVL_ERROR,
    432                     "failed registering service: %s", str_error(rc));
     427                ERR_PRINTF("failed registering service: %s", str_error(rc));
    433428                return EEXIST;
    434429        }
  • uspace/srv/bd/hr/raid0.c

    rbd51105 r5d96f427  
    8989        for (size_t i = 0; i < vol->dev_no; i++) {
    9090                if (vol->extents[i].status != HR_EXT_ONLINE) {
    91                         log_msg(LOG_DEFAULT, LVL_ERROR,
    92                             "RAID 0 needs all extents to be ONLINE, marking "
    93                             "\"%s\" (%lu) as FAULTY",
     91                        ERR_PRINTF("RAID 0 needs all extents to be ONLINE, "
     92                            "marking \"%s\" (%lu) as FAULTY",
    9493                            vol->devname, vol->svc_id);
    9594                        vol->status = HR_VOL_FAULTY;
     
    104103static errno_t hr_raid0_bd_open(bd_srvs_t *bds, bd_srv_t *bd)
    105104{
    106         log_msg(LOG_DEFAULT, LVL_NOTE, "hr_bd_open()");
     105        DPRINTF("hr_bd_open()\n");
    107106        return EOK;
    108107}
     
    110109static errno_t hr_raid0_bd_close(bd_srv_t *bd)
    111110{
    112         log_msg(LOG_DEFAULT, LVL_NOTE, "hr_bd_close()");
     111        DPRINTF("hr_bd_close()\n");
    113112        return EOK;
    114113}
     
    246245
    247246        if (new_volume->dev_no < 2) {
    248                 log_msg(LOG_DEFAULT, LVL_ERROR,
    249                     "RAID 0 array needs at least 2 devices");
     247                ERR_PRINTF("RAID 0 array needs at least 2 devices");
    250248                return EINVAL;
    251249        }
  • uspace/srv/bd/hr/raid1.c

    rbd51105 r5d96f427  
    9595        if (healthy == 0) {
    9696                if (old_state != HR_VOL_FAULTY) {
    97                         log_msg(LOG_DEFAULT, LVL_ERROR,
    98                             "RAID 1 needs at least 1 extent to be ONLINE, "
    99                             "marking \"%s\" (%lu) as FAULTY",
     97                        ERR_PRINTF("RAID 1 needs at least 1 extent to be"
     98                            "ONLINE, marking \"%s\" (%lu) volume as FAULTY",
    10099                            vol->devname, vol->svc_id);
    101100                        vol->status = HR_VOL_FAULTY;
     
    104103        } else if (healthy < vol->dev_no) {
    105104                if (old_state != HR_VOL_DEGRADED) {
    106                         log_msg(LOG_DEFAULT, LVL_ERROR,
    107                             "RAID 1 array \"%s\" (%lu) has some inactive "
    108                             "extents, marking as DEGRADED",
     105                        ERR_PRINTF("RAID 1 array \"%s\" (%lu) has some "
     106                            "inactive extent(s), marking volume as DEGRADED",
    109107                            vol->devname, vol->svc_id);
    110108                        vol->status = HR_VOL_DEGRADED;
     
    113111        } else {
    114112                if (old_state != HR_VOL_ONLINE) {
    115                         log_msg(LOG_DEFAULT, LVL_ERROR,
    116                             "RAID 1 array \"%s\" (%lu) has all extents active, "
    117                             "marking as ONLINE",
     113                        DPRINTF("RAID 1 array \"%s\" (%lu) has all extents "
     114                            "active, marking volume as ONLINE",
    118115                            vol->devname, vol->svc_id);
    119116                        vol->status = HR_VOL_ONLINE;
     
    125122static errno_t hr_raid1_bd_open(bd_srvs_t *bds, bd_srv_t *bd)
    126123{
    127         log_msg(LOG_DEFAULT, LVL_NOTE, "hr_bd_open()");
     124        DPRINTF("hr_bd_open()\n");
    128125        return EOK;
    129126}
     
    131128static errno_t hr_raid1_bd_close(bd_srv_t *bd)
    132129{
    133         log_msg(LOG_DEFAULT, LVL_NOTE, "hr_bd_close()");
     130        DPRINTF("hr_bd_close()\n");
    134131        return EOK;
    135132}
     
    260257
    261258        if (new_volume->dev_no < 2) {
    262                 log_msg(LOG_DEFAULT, LVL_ERROR,
    263                     "RAID 1 array needs at least 2 devices");
     259                ERR_PRINTF("RAID 1 array needs at least 2 devices\n");
    264260                return EINVAL;
    265261        }
  • uspace/srv/bd/hr/raid4.c

    rbd51105 r5d96f427  
    109109        case 0:
    110110                if (old_state != HR_VOL_ONLINE) {
    111                         log_msg(LOG_DEFAULT, LVL_ERROR,
    112                             "RAID 4 has all extents online, "
     111                        DPRINTF("RAID 4 has all extents online, "
    113112                            "marking \"%s\" (%lu) as ONLINE",
    114113                            vol->devname, vol->svc_id);
     
    118117        case 1:
    119118                if (old_state != HR_VOL_DEGRADED) {
    120                         log_msg(LOG_DEFAULT, LVL_ERROR,
    121                             "RAID 4 array \"%s\" (%lu) has 1 extent inactive, "
    122                             "marking as DEGRADED",
     119                        ERR_PRINTF("RAID 4 array \"%s\" (%lu) has 1 extent "
     120                            "inactive, marking as DEGRADED",
    123121                            vol->devname, vol->svc_id);
    124122                        vol->status = HR_VOL_DEGRADED;
     
    127125        default:
    128126                if (old_state != HR_VOL_FAULTY) {
    129                         log_msg(LOG_DEFAULT, LVL_ERROR,
    130                             "RAID 4 array \"%s\" (%lu) has more than one 1 "
    131                             "extent inactive, marking as FAULTY",
     127                        ERR_PRINTF("RAID 4 array \"%s\" (%lu) has more "
     128                            "than one 1 extent inactive, marking as FAULTY",
    132129                            vol->devname, vol->svc_id);
    133130                        vol->status = HR_VOL_FAULTY;
     
    324321static errno_t hr_raid4_bd_open(bd_srvs_t *bds, bd_srv_t *bd)
    325322{
    326         log_msg(LOG_DEFAULT, LVL_NOTE, "hr_bd_open()");
     323        DPRINTF("hr_bd_open()\n");
    327324        return EOK;
    328325}
     
    330327static errno_t hr_raid4_bd_close(bd_srv_t *bd)
    331328{
    332         log_msg(LOG_DEFAULT, LVL_NOTE, "hr_bd_close()");
     329        DPRINTF("hr_bd_close()\n");
    333330        return EOK;
    334331}
     
    495492
    496493        if (new_volume->dev_no < 3) {
    497                 log_msg(LOG_DEFAULT, LVL_ERROR,
    498                     "RAID 4 array needs at least 3 devices");
     494                ERR_PRINTF("RAID 4 array needs at least 3 devices");
    499495                return EINVAL;
    500496        }
  • uspace/srv/bd/hr/raid5.c

    rbd51105 r5d96f427  
    109109        case 0:
    110110                if (old_state != HR_VOL_ONLINE) {
    111                         log_msg(LOG_DEFAULT, LVL_ERROR,
    112                             "RAID 5 has all extents online, "
     111                        DPRINTF("RAID 5 has all extents online, "
    113112                            "marking \"%s\" (%lu) as ONLINE",
    114113                            vol->devname, vol->svc_id);
     
    118117        case 1:
    119118                if (old_state != HR_VOL_DEGRADED) {
    120                         log_msg(LOG_DEFAULT, LVL_ERROR,
    121                             "RAID 5 array \"%s\" (%lu) has 1 extent inactive, "
    122                             "marking as DEGRADED",
     119                        ERR_PRINTF("RAID 5 array \"%s\" (%lu) has 1 extent "
     120                            "inactive, marking as DEGRADED",
    123121                            vol->devname, vol->svc_id);
    124122                        vol->status = HR_VOL_DEGRADED;
     
    127125        default:
    128126                if (old_state != HR_VOL_FAULTY) {
    129                         log_msg(LOG_DEFAULT, LVL_ERROR,
    130                             "RAID 5 array \"%s\" (%lu) has more than one 1 "
    131                             "extent inactive, marking as FAULTY",
     127                        ERR_PRINTF("RAID 5 array \"%s\" (%lu) has more "
     128                            "than one 1 extent inactive, marking as FAULTY",
    132129                            vol->devname, vol->svc_id);
    133130                        vol->status = HR_VOL_FAULTY;
     
    324321static errno_t hr_raid5_bd_open(bd_srvs_t *bds, bd_srv_t *bd)
    325322{
    326         log_msg(LOG_DEFAULT, LVL_NOTE, "hr_bd_open()");
     323        DPRINTF("hr_bd_open()\n");
    327324        return EOK;
    328325}
     
    330327static errno_t hr_raid5_bd_close(bd_srv_t *bd)
    331328{
    332         log_msg(LOG_DEFAULT, LVL_NOTE, "hr_bd_close()");
     329        DPRINTF("hr_bd_close()\n");
    333330        return EOK;
    334331}
     
    504501
    505502        if (new_volume->dev_no < 3) {
    506                 log_msg(LOG_DEFAULT, LVL_ERROR,
    507                     "RAID 5 array needs at least 3 devices");
     503                ERR_PRINTF("RAID 5 array needs at least 3 devices");
    508504                return EINVAL;
    509505        }
  • uspace/srv/bd/hr/superblock.c

    rbd51105 r5d96f427  
    5454errno_t hr_write_meta_to_vol(hr_volume_t *vol)
    5555{
    56         log_msg(LOG_DEFAULT, LVL_NOTE, "hr_write_meta_to_vol()");
     56        DPRINTF("hr_write_meta_to_vol()\n");
    5757
    5858        errno_t rc;
     
    7171
    7272        if (vol->nblocks < meta_blkno) {
    73                 log_msg(LOG_DEFAULT, LVL_ERROR,
    74                     "not enough blocks to write metadata");
     73                ERR_PRINTF("not enough blocks to write metadat\n");
    7574                rc = EINVAL;
    7675                goto error;
    7776        } else if (vol->nblocks == meta_blkno) {
    78                 log_msg(LOG_DEFAULT, LVL_ERROR,
    79                     "there would be zero data blocks after writing metadata, aborting");
     77                ERR_PRINTF("there would be zero data blocks after writing "
     78                    "metadata, aborting");
    8079                rc = EINVAL;
    8180                goto error;
     
    115114{
    116115        if (uint64_t_le2host(md->magic) != HR_MAGIC) {
    117                 printf("invalid magic\n");
     116                ERR_PRINTF("invalid magic\n");
    118117                return EINVAL;
    119118        }
     
    123122errno_t hr_fill_vol_from_meta(hr_volume_t *vol)
    124123{
    125         log_msg(LOG_DEFAULT, LVL_NOTE, "hr_get_vol_from_meta()");
     124        DPRINTF("hr_get_vol_from_meta()\n");
    126125
    127126        errno_t rc;
     
    171170
    172171        if (vol->dev_no != uint32_t_le2host(metadata->extent_no)) {
    173                 log_msg(LOG_DEFAULT, LVL_ERROR,
    174                     "number of divices in array differ: specified %zu, metadata states %u",
     172                ERR_PRINTF("number of divices in array differ: specified %zu, "
     173                    "metadata states %u",
    175174                    vol->dev_no, uint32_t_le2host(metadata->extent_no));
    176175                rc = EINVAL;
     
    185184
    186185        if (str_cmp(metadata->devname, vol->devname) != 0) {
    187                 log_msg(LOG_DEFAULT, LVL_NOTE,
    188                     "devname on metadata (%s) and config (%s) differ, using config",
    189                     metadata->devname, vol->devname);
     186                log_msg(LOG_DEFAULT, LVL_WARN,
     187                    "devname on metadata (%s) and config (%s) differ, "
     188                    "using config", metadata->devname, vol->devname);
    190189        }
    191190end:
  • uspace/srv/bd/hr/util.c

    rbd51105 r5d96f427  
    5050errno_t hr_init_devs(hr_volume_t *vol)
    5151{
    52         log_msg(LOG_DEFAULT, LVL_NOTE, "hr_init_devs()");
     52        DPRINTF("hr_init_devs()\n");
    5353
    5454        errno_t rc;
    5555        size_t i;
    56 
    57         for (i = 0; i < vol->dev_no; i++) {
    58                 if (vol->extents[i].svc_id == 0) {
    59                         vol->extents[i].status = HR_EXT_MISSING;
    60                         continue;
    61                 }
    62                 rc = block_init(vol->extents[i].svc_id);
    63                 vol->extents[i].status = HR_EXT_ONLINE;
    64                 log_msg(LOG_DEFAULT, LVL_DEBUG,
    65                     "hr_init_devs(): initing (%" PRIun ")",
    66                     vol->extents[i].svc_id);
     56        hr_extent_t *extent;
     57
     58        for (i = 0; i < vol->dev_no; i++) {
     59                extent = &vol->extents[i];
     60                if (extent->svc_id == 0) {
     61                        extent->status = HR_EXT_MISSING;
     62                        continue;
     63                }
     64
     65                DPRINTF("hr_init_devs(): block_init() on (%lu)\n",
     66                    extent->svc_id);
     67                rc = block_init(extent->svc_id);
     68                extent->status = HR_EXT_ONLINE;
     69
    6770                if (rc != EOK) {
    68                         log_msg(LOG_DEFAULT, LVL_ERROR,
    69                             "hr_init_devs(): initing (%" PRIun ") failed, aborting",
     71                        ERR_PRINTF("hr_init_devs(): initing (%lu) failed, "
     72                            "aborting\n", extent->svc_id);
     73                        break;
     74                }
     75        }
     76
     77        return rc;
     78}
     79
     80void hr_fini_devs(hr_volume_t *vol)
     81{
     82        DPRINTF("hr_fini_devs()\n");
     83
     84        size_t i;
     85
     86        for (i = 0; i < vol->dev_no; i++) {
     87                if (vol->extents[i].status != HR_EXT_MISSING) {
     88                        DPRINTF("hr_fini_devs(): block_fini() on (%lu)\n",
    7089                            vol->extents[i].svc_id);
    71                         break;
    72                 }
    73         }
    74 
    75         return rc;
    76 }
    77 
    78 void hr_fini_devs(hr_volume_t *vol)
    79 {
    80         log_msg(LOG_DEFAULT, LVL_NOTE, "hr_fini_devs()");
    81 
    82         size_t i;
    83 
    84         for (i = 0; i < vol->dev_no; i++)
    85                 if (vol->extents[i].status != HR_EXT_MISSING)
    8690                        block_fini(vol->extents[i].svc_id);
    87 }
    88 
    89 errno_t hr_register_volume(hr_volume_t *new_volume)
    90 {
    91         log_msg(LOG_DEFAULT, LVL_NOTE, "hr_register_volume()");
     91                }
     92        }
     93}
     94
     95errno_t hr_register_volume(hr_volume_t *vol)
     96{
     97        DPRINTF("hr_register_volume()\n");
    9298
    9399        errno_t rc;
     
    95101        category_id_t cat_id;
    96102        char *fullname = NULL;
    97 
    98         if (asprintf(&fullname, "devices/%s", new_volume->devname) < 0)
     103        char *devname = vol->devname;
     104
     105        if (asprintf(&fullname, "devices/%s", devname) < 0)
    99106                return ENOMEM;
    100107
    101108        rc = loc_service_register(hr_srv, fullname, &new_id);
    102109        if (rc != EOK) {
    103                 log_msg(LOG_DEFAULT, LVL_ERROR,
    104                     "unable to register device \"%s\": %s\n",
    105                     new_volume->devname, str_error(rc));
     110                ERR_PRINTF("unable to register device \"%s\": %s\n",
     111                    fullname, str_error(rc));
    106112                goto error;
    107113        }
     
    109115        rc = loc_category_get_id("raid", &cat_id, IPC_FLAG_BLOCKING);
    110116        if (rc != EOK) {
    111                 log_msg(LOG_DEFAULT, LVL_ERROR,
    112                     "failed resolving category \"raid\": %s\n", str_error(rc));
     117                ERR_PRINTF("failed resolving category \"raid\": %s\n",
     118                    str_error(rc));
    113119                goto error;
    114120        }
     
    116122        rc = loc_service_add_to_cat(hr_srv, new_id, cat_id);
    117123        if (rc != EOK) {
    118                 log_msg(LOG_DEFAULT, LVL_ERROR,
    119                     "failed adding \"%s\" to category \"raid\": %s\n",
    120                     new_volume->devname, str_error(rc));
     124                ERR_PRINTF("failed adding \"%s\" to category \"raid\": %s\n",
     125                    fullname, str_error(rc));
    121126                goto error;
    122127        }
    123128
    124         new_volume->svc_id = new_id;
     129        vol->svc_id = new_id;
    125130
    126131error:
     
    131136errno_t hr_check_devs(hr_volume_t *vol, uint64_t *rblkno, size_t *rbsize)
    132137{
    133         log_msg(LOG_DEFAULT, LVL_NOTE, "hr_check_devs()");
     138        DPRINTF("hr_check_devs()\n");
    134139
    135140        errno_t rc;
     
    139144        uint64_t last_nblocks = 0;
    140145        uint64_t total_blocks = 0;
    141 
    142         for (i = 0; i < vol->dev_no; i++) {
    143                 if (vol->extents[i].status == HR_EXT_MISSING)
    144                         continue;
    145                 rc = block_get_nblocks(vol->extents[i].svc_id, &nblocks);
     146        hr_extent_t *extent;
     147
     148        for (i = 0; i < vol->dev_no; i++) {
     149                extent = &vol->extents[i];
     150                if (extent->status == HR_EXT_MISSING)
     151                        continue;
     152                rc = block_get_nblocks(extent->svc_id, &nblocks);
    146153                if (rc != EOK)
    147154                        goto error;
    148155                if (last_nblocks != 0 && nblocks != last_nblocks) {
    149                         log_msg(LOG_DEFAULT, LVL_ERROR,
    150                             "number of blocks differs");
     156                        ERR_PRINTF("number of blocks differs\n");
    151157                        rc = EINVAL;
    152158                        goto error;
    153159                }
     160
    154161                total_blocks += nblocks;
    155162                last_nblocks = nblocks;
     
    157164
    158165        for (i = 0; i < vol->dev_no; i++) {
    159                 if (vol->extents[i].status == HR_EXT_MISSING)
    160                         continue;
    161                 rc = block_get_bsize(vol->extents[i].svc_id, &bsize);
     166                extent = &vol->extents[i];
     167                if (extent->status == HR_EXT_MISSING)
     168                        continue;
     169                rc = block_get_bsize(extent->svc_id, &bsize);
    162170                if (rc != EOK)
    163171                        goto error;
    164172                if (last_bsize != 0 && bsize != last_bsize) {
    165                         log_msg(LOG_DEFAULT, LVL_ERROR, "block sizes differ");
     173                        ERR_PRINTF("block sizes differ\n");
    166174                        rc = EINVAL;
    167175                        goto error;
    168176                }
     177
    169178                last_bsize = bsize;
    170179        }
    171180
    172181        if ((bsize % 512) != 0) {
    173                 log_msg(LOG_DEFAULT, LVL_ERROR,
    174                     "block size not multiple of 512");
     182                ERR_PRINTF("block size not multiple of 512\n");
    175183                return EINVAL;
    176184        }
Note: See TracChangeset for help on using the changeset viewer.