Changeset fc265b4 in mainline for uspace/app/hrctl/hrctl.c


Ignore:
Timestamp:
2025-05-07T10:41:29Z (5 weeks ago)
Author:
Miroslav Cimerman <mc@…>
Children:
af4ecb76
Parents:
ac4b70b
Message:

hr: IPC methods: don't create own hr_t session

File:
1 edited

Legend:

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

    rac4b70b rfc265b4  
    229229}
    230230
    231 static int handle_create(int argc, char **argv)
     231static int handle_create(hr_t *hr, int argc, char **argv)
    232232{
    233233        if (optind >= argc) {
     
    287287        }
    288288
    289         hr_t *hr;
    290         errno_t rc = hr_sess_init(&hr);
    291         if (rc != EOK) {
    292                 printf(NAME ": server session init failed: %s\n",
    293                     str_error(rc));
    294                 goto error;
    295         }
    296 
    297         rc = hr_create(hr, vol_config);
     289        errno_t rc = hr_create(hr, vol_config);
    298290        if (rc != EOK) {
    299291                printf(NAME ": creation failed: %s\n",
     
    301293                goto error;
    302294        }
    303 
    304         hr_sess_destroy(hr);
    305295
    306296        free(vol_config);
     
    311301}
    312302
    313 static int handle_assemble(int argc, char **argv)
     303static int handle_assemble(hr_t *hr, int argc, char **argv)
    314304{
    315305        if (optind >= argc) {
    316306                size_t cnt;
    317                 errno_t rc = hr_auto_assemble(&cnt);
     307                errno_t rc = hr_auto_assemble(hr, &cnt);
    318308                if (rc != EOK) {
    319309                        /* XXX: here have own error codes */
     
    353343        }
    354344
    355         hr_t *hr;
    356         errno_t rc = hr_sess_init(&hr);
    357         if (rc != EOK) {
    358                 printf(NAME ": server session init failed: %s\n",
    359                     str_error(rc));
    360                 goto error;
    361         }
    362 
    363345        size_t cnt;
    364         rc = hr_assemble(hr, vol_config, &cnt);
     346        errno_t rc = hr_assemble(hr, vol_config, &cnt);
    365347        if (rc != EOK) {
    366348                printf(NAME ": assmeble failed: %s\n", str_error(rc));
     
    369351
    370352        printf("hrctl: auto assembled %zu volumes\n", cnt);
    371 
    372         hr_sess_destroy(hr);
    373353
    374354        free(vol_config);
     
    379359}
    380360
    381 static int handle_disassemble(int argc, char **argv)
     361static int handle_disassemble(hr_t *hr, int argc, char **argv)
    382362{
    383363        if (optind >= argc) {
    384                 errno_t rc = hr_stop_all();
     364                errno_t rc = hr_stop_all(hr);
    385365                if (rc != EOK) {
    386366                        printf(NAME ": stopping some volumes failed: %s\n",
     
    398378        const char *devname = argv[optind++];
    399379
    400         errno_t rc = hr_stop(devname);
     380        errno_t rc = hr_stop(hr, devname);
    401381        if (rc != EOK) {
    402382                printf(NAME ": disassembly of device \"%s\" failed: %s\n",
     
    408388}
    409389
    410 static int handle_modify(int argc, char **argv)
     390static int handle_modify(hr_t *hr, int argc, char **argv)
    411391{
    412392        if (optind >= argc) {
     
    432412                optind++;
    433413                unsigned long extent = strtol(argv[optind++], NULL, 10);
    434                 errno_t rc = hr_fail_extent(volname, extent);
     414                errno_t rc = hr_fail_extent(hr, volname, extent);
    435415                if (rc != EOK) {
    436416                        printf(NAME ": failing extent failed: %s\n",
     
    441421            str_cmp(argv[optind], "-h") == 0) {
    442422                optind++;
    443                 errno_t rc = hr_add_hotspare(volname, argv[optind++]);
     423                errno_t rc = hr_add_hotspare(hr, volname, argv[optind++]);
    444424                if (rc != EOK) {
    445425                        printf(NAME ": adding hotspare failed: %s\n",
     
    455435}
    456436
    457 static int handle_status(int argc, char **argv)
     437static int handle_status(hr_t *hr, int argc, char **argv)
    458438{
    459439        (void)argc;
    460440        (void)argv;
    461441
    462         errno_t rc = hr_print_status();
     442        errno_t rc = hr_print_status(hr);
    463443        if (rc != EOK) {
    464444                printf(NAME ": status printing failed: %s\n", str_error(rc));
     
    472452{
    473453        int rc = EXIT_SUCCESS;
    474         int c;
     454        hr_t *hr = NULL;
    475455
    476456        if (argc < 2) {
     
    479459        }
    480460
    481         c = 0;
     461        if (hr_sess_init(&hr) != EOK) {
     462                printf(NAME ": hr server session init failed: %s\n",
     463                    str_error(rc));
     464                return EXIT_FAILURE;
     465        }
     466
    482467        optreset = 1;
    483468        optind = 0;
     
    493478        };
    494479
    495         while (c != -1) {
    496                 c = getopt_long(argc, argv, "hcadms", top_level_opts, NULL);
    497                 switch (c) {
    498                 case 'h':
    499                         usage();
    500                         return EXIT_SUCCESS;
    501                 case 'c':
    502                         rc = handle_create(argc, argv);
    503                         goto end;
    504                 case 'a':
    505                         rc = handle_assemble(argc, argv);
    506                         goto end;
    507                 case 'd':
    508                         rc = handle_disassemble(argc, argv);
    509                         goto end;
    510                 case 'm':
    511                         rc = handle_modify(argc, argv);
    512                         goto end;
    513                 case 's':
    514                         rc = handle_status(argc, argv);
    515                         goto end;
    516                 default:
    517                         goto end;
    518                 }
     480        int c = getopt_long(argc, argv, "hcadms", top_level_opts, NULL);
     481        switch (c) {
     482        case 'h':
     483                usage();
     484                goto end;
     485        case 'c':
     486                rc = handle_create(hr, argc, argv);
     487                goto end;
     488        case 'a':
     489                rc = handle_assemble(hr, argc, argv);
     490                goto end;
     491        case 'd':
     492                rc = handle_disassemble(hr, argc, argv);
     493                goto end;
     494        case 'm':
     495                rc = handle_modify(hr, argc, argv);
     496                goto end;
     497        case 's':
     498                rc = handle_status(hr, argc, argv);
     499                goto end;
     500        default:
     501                goto end;
    519502        }
    520503
    521504end:
     505        hr_sess_destroy(hr);
     506
    522507        if (rc != EXIT_SUCCESS)
    523508                printf(NAME ": use --help to see usage\n");
Note: See TracChangeset for help on using the changeset viewer.