Changeset 95ca19d in mainline for uspace/app/hrctl/hrctl.c


Ignore:
Timestamp:
2025-06-30T09:31:21Z (3 weeks ago)
Author:
Miroslav Cimerman <mc@…>
Children:
059885c
Parents:
640250b
Message:

hr: add —read-only volume flag

File:
1 edited

Legend:

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

    r640250b r95ca19d  
    5555static int create_from_argv(hr_t *, int, char **, uint8_t);
    5656static int handle_create(hr_t *, int, char **);
    57 static int assemble_from_config(hr_t *, const char *);
    58 static int assemble_from_argv(hr_t *, int, char **);
     57static int assemble_from_config(hr_t *, const char *, uint8_t);
     58static int assemble_from_argv(hr_t *, int, char **, uint8_t);
    5959static int handle_assemble(hr_t *, int, char **);
    6060static int handle_disassemble(hr_t *, int, char **);
     
    7070    "  -h, --help                                Display this message and exit.\n"
    7171    "\n"
    72     "  -c, --create [--no_meta]                  Create a volume, options:\n"
     72    "  -c, --create [--no-meta] [--read-only]    Create a volume, options:\n"
    7373    "      name {-l , --level level} device...   manual device specification, or\n"
    7474    "      -f configuration.sif                  create from configuration file.\n"
    7575    "\n"
    7676    "  -a, --assemble                            Assemble volume(s), options:\n"
    77     "      [device...]                           manual device specification, or\n"
    78     "      [-f configuration.sif]                assemble from configuration file, or\n"
     77    "      [[--read-only] device...]             manual device specification, or\n"
     78    "      [[--read-only] -f configuration.sif]  assemble from configuration file, or\n"
    7979    "                                            no option is automatic assembly.\n"
    8080    "\n"
     
    108108    "\n"
    109109    "Notes:\n"
    110     "  Add --no_meta after --create to disable storing on-disk metadata.\n"
     110    "  Add --no-meta after --create to disable storing on-disk metadata.\n"
    111111    "  Simulating an extent failure with -m volume -f index is dangerous. It marks\n"
    112112    "  metadata as dirty in other healthy extents, and zeroes out the superblock\n"
     
    445445}
    446446
     447static bool try_to_get_additional_flags(int argc, char **argv,
     448    uint8_t test_flags, uint8_t *flags)
     449{
     450        if (test_flags & HR_VOL_FLAG_NOOP_META) {
     451                if (str_cmp(argv[optind], "--no-meta") == 0) {
     452                        *flags |= HR_VOL_FLAG_NOOP_META;
     453                        optind++;
     454                        return true;
     455                }
     456        }
     457
     458        if (test_flags & HR_VOL_FLAG_READ_ONLY) {
     459                if (str_cmp(argv[optind], "--read-only") == 0) {
     460                        *flags |= HR_VOL_FLAG_READ_ONLY;
     461                        optind++;
     462                        return true;
     463                }
     464        }
     465
     466        return false;
     467}
     468
    447469static int handle_create(hr_t *hr, int argc, char **argv)
    448470{
    449471        int rc;
    450         uint8_t vol_flags = 0;
     472        uint8_t vflags = 0;
    451473
    452474        if (optind >= argc) {
     
    455477        }
    456478
    457         if (str_cmp(argv[optind], "--no_meta") == 0) {
    458                 vol_flags |= HR_VOL_FLAG_NOOP_META;
    459                 optind++;
    460         }
     479        uint8_t test_flags = HR_VOL_FLAG_NOOP_META | HR_VOL_FLAG_READ_ONLY;
     480        while (try_to_get_additional_flags(argc, argv, test_flags, &vflags))
     481                ;
    461482
    462483        if (str_cmp(argv[optind], "-f") == 0) {
     
    474495                }
    475496
    476                 rc = create_from_config(hr, config_path, vol_flags);
     497                rc = create_from_config(hr, config_path, vflags);
    477498        } else {
    478                 rc = create_from_argv(hr, argc, argv, vol_flags);
     499                rc = create_from_argv(hr, argc, argv, vflags);
    479500        }
    480501
     
    482503}
    483504
    484 static int assemble_from_config(hr_t *hr, const char *config_path)
     505static int assemble_from_config(hr_t *hr, const char *config_path,
     506    uint8_t vflags)
    485507{
    486508        hr_config_t *vol_configs = NULL;
     
    496518        for (size_t i = 0; i < vol_count; i++) {
    497519                size_t tmpcnt = 0;
     520                vol_configs[i].vol_flags = vflags;
    498521                (void)hr_assemble(hr, &vol_configs[i], &tmpcnt);
    499522                cnt += tmpcnt;
     
    506529}
    507530
    508 static int assemble_from_argv(hr_t *hr, int argc, char **argv)
     531static int assemble_from_argv(hr_t *hr, int argc, char **argv, uint8_t vflags)
    509532{
    510533        hr_config_t *vol_config = calloc(1, sizeof(hr_config_t));
     
    513536                return ENOMEM;
    514537        }
     538
     539        vol_config->vol_flags = vflags;
    515540
    516541        errno_t rc = fill_config_devs(argc, argv, vol_config);
     
    551576        }
    552577
     578        uint8_t vflags = 0;
     579        uint8_t test_flags = HR_VOL_FLAG_NOOP_META | HR_VOL_FLAG_READ_ONLY;
     580        while (try_to_get_additional_flags(argc, argv, test_flags, &vflags))
     581                ;
     582
     583        if (test_flags & HR_VOL_FLAG_NOOP_META)
     584                printf(NAME ": assembling, --no-meta flag will be ignored\n");
     585
    553586        if (str_cmp(argv[optind], "-f") == 0) {
    554587                if (++optind >= argc) {
     
    563596                }
    564597
    565                 rc = assemble_from_config(hr, config_path);
     598                rc = assemble_from_config(hr, config_path, vflags);
    566599        } else {
    567                 rc = assemble_from_argv(hr, argc, argv);
     600                rc = assemble_from_argv(hr, argc, argv, vflags);
    568601        }
    569602
     
    658691        printf("|   metadata type: %s\n",
    659692            hr_get_metadata_type_str(info->meta_type));
     693
     694        printf("|          vflags: ");
     695        for (size_t v = 0; v < HR_VOL_FLAG_COUNT; v++) {
     696                if (info->vflags & (1 << v)) {
     697                        printf("%s ",
     698                            hr_get_vol_flag_str(info->vflags & (1 << v)));
     699                }
     700        }
     701        printf("\n");
     702
    660703        printf("|           level: %s\n", hr_get_level_str(info->level));
    661704        if (info->layout != HR_LAYOUT_NONE)
Note: See TracChangeset for help on using the changeset viewer.