@@ -8446,6 +8446,11 @@ date_string_to_sec(const char *timestr, boolean_t rounding)
8446
8446
return (mktime (& tm ) + adjustment );
8447
8447
}
8448
8448
8449
+ struct zpool_scrub_option {
8450
+ char name ;
8451
+ boolean_t enabled ;
8452
+ };
8453
+
8449
8454
/*
8450
8455
* zpool scrub [-e | -s | -p | -C | -E | -S] [-w] [-a | <pool> ...]
8451
8456
*
@@ -8463,27 +8468,27 @@ zpool_do_scrub(int argc, char **argv)
8463
8468
{
8464
8469
int c ;
8465
8470
scrub_cbdata_t cb ;
8466
- boolean_t wait = B_FALSE ;
8467
8471
int error ;
8468
8472
8469
8473
cb .cb_type = POOL_SCAN_SCRUB ;
8470
8474
cb .cb_scrub_cmd = POOL_SCRUB_NORMAL ;
8471
8475
cb .cb_date_start = cb .cb_date_end = 0 ;
8472
8476
8473
- boolean_t is_error_scrub = B_FALSE ;
8474
- boolean_t is_pause = B_FALSE ;
8475
- boolean_t is_stop = B_FALSE ;
8476
- boolean_t is_txg_continue = B_FALSE ;
8477
- boolean_t scrub_all = B_FALSE ;
8477
+ struct zpool_scrub_option wait = {'w' , B_FALSE };
8478
+ struct zpool_scrub_option is_error_scrub = {'e' , B_FALSE };
8479
+ struct zpool_scrub_option is_pause = {'p' , B_FALSE };
8480
+ struct zpool_scrub_option is_stop = {'s' , B_FALSE };
8481
+ struct zpool_scrub_option is_txg_continue = {'C' , B_FALSE };
8482
+ struct zpool_scrub_option scrub_all = {'a' , B_FALSE };
8478
8483
8479
8484
/* check options */
8480
8485
while ((c = getopt (argc , argv , "aspweCE:S:" )) != -1 ) {
8481
8486
switch (c ) {
8482
8487
case 'a' :
8483
- scrub_all = B_TRUE ;
8488
+ scrub_all . enabled = B_TRUE ;
8484
8489
break ;
8485
8490
case 'e' :
8486
- is_error_scrub = B_TRUE ;
8491
+ is_error_scrub . enabled = B_TRUE ;
8487
8492
break ;
8488
8493
case 'E' :
8489
8494
/*
@@ -8493,19 +8498,19 @@ zpool_do_scrub(int argc, char **argv)
8493
8498
cb .cb_date_end = date_string_to_sec (optarg , B_TRUE );
8494
8499
break ;
8495
8500
case 's' :
8496
- is_stop = B_TRUE ;
8501
+ is_stop . enabled = B_TRUE ;
8497
8502
break ;
8498
8503
case 'S' :
8499
8504
cb .cb_date_start = date_string_to_sec (optarg , B_FALSE );
8500
8505
break ;
8501
8506
case 'p' :
8502
- is_pause = B_TRUE ;
8507
+ is_pause . enabled = B_TRUE ;
8503
8508
break ;
8504
8509
case 'w' :
8505
- wait = B_TRUE ;
8510
+ wait . enabled = B_TRUE ;
8506
8511
break ;
8507
8512
case 'C' :
8508
- is_txg_continue = B_TRUE ;
8513
+ is_txg_continue . enabled = B_TRUE ;
8509
8514
break ;
8510
8515
case '?' :
8511
8516
(void ) fprintf (stderr , gettext ("invalid option '%c'\n" ),
@@ -8514,37 +8519,42 @@ zpool_do_scrub(int argc, char **argv)
8514
8519
}
8515
8520
}
8516
8521
8517
- if (is_pause && is_stop ) {
8518
- (void ) fprintf (stderr , gettext ("invalid option "
8519
- "combination: -s and -p are mutually exclusive\n" ));
8520
- usage (B_FALSE );
8521
- } else if (is_pause && is_txg_continue ) {
8522
- (void ) fprintf (stderr , gettext ("invalid option "
8523
- "combination: -p and -C are mutually exclusive\n" ));
8524
- usage (B_FALSE );
8525
- } else if (is_stop && is_txg_continue ) {
8526
- (void ) fprintf (stderr , gettext ("invalid option "
8527
- "combination: -s and -C are mutually exclusive\n" ));
8528
- usage (B_FALSE );
8529
- } else if (is_error_scrub && is_txg_continue ) {
8530
- (void ) fprintf (stderr , gettext ("invalid option "
8531
- "combination: -e and -C are mutually exclusive\n" ));
8532
- usage (B_FALSE );
8533
- } else {
8534
- if (is_error_scrub )
8535
- cb .cb_type = POOL_SCAN_ERRORSCRUB ;
8536
-
8537
- if (is_pause ) {
8538
- cb .cb_scrub_cmd = POOL_SCRUB_PAUSE ;
8539
- } else if (is_stop ) {
8540
- cb .cb_type = POOL_SCAN_NONE ;
8541
- } else if (is_txg_continue ) {
8542
- cb .cb_scrub_cmd = POOL_SCRUB_FROM_LAST_TXG ;
8543
- } else {
8544
- cb .cb_scrub_cmd = POOL_SCRUB_NORMAL ;
8522
+ struct {
8523
+ struct zpool_scrub_option * op1 ;
8524
+ struct zpool_scrub_option * op2 ;
8525
+ } scrub_exclusive_options [] = {
8526
+ {& is_stop , & is_pause },
8527
+ {& is_stop , & is_txg_continue },
8528
+ {& is_pause , & is_txg_continue },
8529
+ {& is_error_scrub , & is_txg_continue },
8530
+ };
8531
+
8532
+ for (int i = 0 ; i < sizeof (scrub_exclusive_options ) /
8533
+ sizeof (scrub_exclusive_options [0 ]); i ++ ) {
8534
+ if (scrub_exclusive_options [i ].op1 -> enabled &&
8535
+ scrub_exclusive_options [i ].op2 -> enabled ) {
8536
+ (void ) fprintf (stderr , gettext ("invalid option "
8537
+ "combination: -%c and -%c are mutually "
8538
+ "exclusive\n" ),
8539
+ scrub_exclusive_options [i ].op1 -> name ,
8540
+ scrub_exclusive_options [i ].op2 -> name );
8541
+ usage (B_FALSE );
8545
8542
}
8546
8543
}
8547
8544
8545
+ if (is_error_scrub .enabled )
8546
+ cb .cb_type = POOL_SCAN_ERRORSCRUB ;
8547
+
8548
+ if (is_pause .enabled ) {
8549
+ cb .cb_scrub_cmd = POOL_SCRUB_PAUSE ;
8550
+ } else if (is_stop .enabled ) {
8551
+ cb .cb_type = POOL_SCAN_NONE ;
8552
+ } else if (is_txg_continue .enabled ) {
8553
+ cb .cb_scrub_cmd = POOL_SCRUB_FROM_LAST_TXG ;
8554
+ } else {
8555
+ cb .cb_scrub_cmd = POOL_SCRUB_NORMAL ;
8556
+ }
8557
+
8548
8558
if ((cb .cb_date_start != 0 || cb .cb_date_end != 0 ) &&
8549
8559
cb .cb_scrub_cmd != POOL_SCRUB_NORMAL ) {
8550
8560
(void ) fprintf (stderr , gettext ("invalid option combination: "
@@ -8558,7 +8568,7 @@ zpool_do_scrub(int argc, char **argv)
8558
8568
usage (B_FALSE );
8559
8569
}
8560
8570
8561
- if (wait && (cb .cb_type == POOL_SCAN_NONE ||
8571
+ if (wait . enabled && (cb .cb_type == POOL_SCAN_NONE ||
8562
8572
cb .cb_scrub_cmd == POOL_SCRUB_PAUSE )) {
8563
8573
(void ) fprintf (stderr , gettext ("invalid option combination: "
8564
8574
"-w cannot be used with -p or -s\n" ));
@@ -8568,15 +8578,15 @@ zpool_do_scrub(int argc, char **argv)
8568
8578
argc -= optind ;
8569
8579
argv += optind ;
8570
8580
8571
- if (argc < 1 && !scrub_all ) {
8581
+ if (argc < 1 && !scrub_all . enabled ) {
8572
8582
(void ) fprintf (stderr , gettext ("missing pool name argument\n" ));
8573
8583
usage (B_FALSE );
8574
8584
}
8575
8585
8576
8586
error = for_each_pool (argc , argv , B_TRUE , NULL , ZFS_TYPE_POOL ,
8577
8587
B_FALSE , scrub_callback , & cb );
8578
8588
8579
- if (wait && !error ) {
8589
+ if (wait . enabled && !error ) {
8580
8590
zpool_wait_activity_t act = ZPOOL_WAIT_SCRUB ;
8581
8591
error = for_each_pool (argc , argv , B_TRUE , NULL , ZFS_TYPE_POOL ,
8582
8592
B_FALSE , wait_callback , & act );
0 commit comments