Changeset 8b51009 in mainline for uspace/app/hrctl/hrctl.c


Ignore:
Timestamp:
2025-03-28T23:37:16Z (3 months ago)
Author:
Miroslav Cimerman <mc@…>
Children:
0437dd5
Parents:
7bfe468
git-author:
Miroslav Cimerman <mc@…> (2025-03-28 23:25:57)
git-committer:
Miroslav Cimerman <mc@…> (2025-03-28 23:37:16)
Message:

hr: auto assembly, refactor

Added automatic assembly (with hrctl -A). All disks or their partitions
are scanned for HelenRAID metadata and assembly is attempted.

Main volume list is now locked with RW lock. The volume list
manipulation functions are moved into util.c.

hr_{create,destroy}_vol_struct() are implemented for better reusability
and modularity.

Volume destroy/stop (hrctl -D) now returns EBUSY if someone has still
the volume open()-ed.

File:
1 edited

Legend:

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

    r7bfe468 r8b51009  
    11/*
    2  * Copyright (c) 2024 Miroslav Cimerman
     2 * Copyright (c) 2025 Miroslav Cimerman
    33 * All rights reserved.
    44 *
     
    4545#define HRCTL_SAMPLE_CONFIG_PATH "/cfg/sample_hr_config.sif"
    4646
    47 static void usage(void);
    48 static errno_t fill_config_devs(int, char **, int, hr_config_t *);
    49 static errno_t load_config(const char *, hr_config_t *);
     47static void     usage(void);
     48static errno_t  fill_config_devs(int, char **, int, hr_config_t *);
     49static errno_t  load_config(const char *, hr_config_t *);
    5050
    5151static const char usage_str[] =
     
    5353    "\n"
    5454    "Options:\n"
    55     "  -h, --help                display this help and exit\n"
     55    "  -h, --help                display this message and exit\n"
    5656    "  -C, --create-file=PATH    create an array from file,\n"
    5757    "                            sample file at: " HRCTL_SAMPLE_CONFIG_PATH "\n"
    58     "  -A, --assemble-file=PATH  create an array from file\n"
     58    "  -A, --auto-assemble       try to auto assemble all valid arrays\n"
    5959    "  -s, --status              display status of active arrays\n"
    6060    "  -H, --hotspare=DEV        add hotspare extent\n"
     
    6262    "  -F, --fail-extent         fail an extent, use with -D and set it before\n"
    6363    "  -c, --create=NAME         create new array\n"
    64     "  -a, --assemble=NAME       assemble an existing array\n"
     64    "  -a, --assemble=NAME       assemble from specified extents\n"
    6565    "  -n                        non-zero number of devices\n"
    6666    "  -l, --level=LEVEL         set the RAID level,\n"
     
    9595        { "level", required_argument, 0, 'l' },
    9696        { "create-file", required_argument, 0, 'C' },
    97         { "assemble-file", required_argument, 0, 'A' },
     97        { "auto-assemble", no_argument, 0, 'A' },
    9898        { "destroy", required_argument, 0, 'D' },
    9999        { "fail-extent", required_argument, 0, 'F' },
     
    253253
    254254        while (c != -1) {
    255                 c = getopt_long(argc, argv, "hsC:c:A:a:l:0145Ln:D:F:H:",
     255                c = getopt_long(argc, argv, "hsC:c:Aa:l:0145Ln:D:F:H:",
    256256                    long_options, NULL);
    257257                switch (c) {
     
    282282                        break;
    283283                case 'A':
    284                         rc = load_config(optarg, cfg);
    285                         if (rc != EOK) {
    286                                 printf("hrctl: failed to load config\n");
    287                                 free(cfg);
    288                                 return 1;
    289                         }
    290                         assemble = true;
    291                         goto skip;
     284                        size_t cnt;
     285                        rc = hr_auto_assemble(&cnt);
     286                        if (rc != EOK) {
     287                                /* XXX: here have own error codes */
     288                                printf("hrctl: auto assemble rc: %s\n",
     289                                    str_error(rc));
     290                        } else {
     291                                printf("hrctl: auto assembled %lu volumes\n",
     292                                    cnt);
     293                        }
     294                        return rc;
    292295                case 'a':
    293296                        if (str_size(optarg) > sizeof(cfg->devname) - 1) {
     
    303306                        free(cfg);
    304307                        if (rc != EOK) {
    305                                 if (rc == ENOENT)
    306                                         printf("hrctl: service named \"%s\" does not exist\n",
    307                                             optarg);
    308                                 return 1;
     308                                printf("hrctl: got %s\n", str_error(rc));
     309                                return rc;
    309310                        }
    310311                        return 0;
Note: See TracChangeset for help on using the changeset viewer.