@@ -100,6 +100,7 @@ static int zpool_do_split(int, char **);
100100
101101static int zpool_do_initialize (int , char * * );
102102static int zpool_do_scrub (int , char * * );
103+ static int zpool_do_rescrub (int , char * * );
103104static int zpool_do_resilver (int , char * * );
104105static int zpool_do_trim (int , char * * );
105106
@@ -157,6 +158,7 @@ typedef enum {
157158 HELP_REMOVE ,
158159 HELP_INITIALIZE ,
159160 HELP_SCRUB ,
161+ HELP_RESCRUB ,
160162 HELP_RESILVER ,
161163 HELP_TRIM ,
162164 HELP_STATUS ,
@@ -296,6 +298,7 @@ static zpool_command_t command_table[] = {
296298 { "initialize" , zpool_do_initialize , HELP_INITIALIZE },
297299 { "resilver" , zpool_do_resilver , HELP_RESILVER },
298300 { "scrub" , zpool_do_scrub , HELP_SCRUB },
301+ { "rescrub" , zpool_do_rescrub , HELP_RESCRUB },
299302 { "trim" , zpool_do_trim , HELP_TRIM },
300303 { NULL },
301304 { "import" , zpool_do_import , HELP_IMPORT },
@@ -382,6 +385,8 @@ get_usage(zpool_help_t idx)
382385 "[<device> ...]\n" ));
383386 case HELP_SCRUB :
384387 return (gettext ("\tscrub [-s | -p] <pool> ...\n" ));
388+ case HELP_RESCRUB :
389+ return (gettext ("\trescrub [-s | -p] <pool> ...\n" ));
385390 case HELP_RESILVER :
386391 return (gettext ("\tresilver <pool> ...\n" ));
387392 case HELP_TRIM :
@@ -6703,6 +6708,24 @@ scrub_callback(zpool_handle_t *zhp, void *data)
67036708 return (err != 0 );
67046709}
67056710
6711+ int
6712+ rescrub_callback (zpool_handle_t * zhp , void * data )
6713+ {
6714+ scrub_cbdata_t * cb = data ;
6715+ int err ;
6716+
6717+ /* Ignore faulted pools. */
6718+ if (zpool_get_state (zhp ) == POOL_STATE_UNAVAIL ) {
6719+ (void ) fprintf (stderr , gettext ("cannot rescrub '%s': pool is "
6720+ "currently unavailable\n" ), zpool_get_name (zhp ));
6721+ return (1 );
6722+ }
6723+
6724+ err = zpool_rescrub (zhp , cb -> cb_type , cb -> cb_scrub_cmd );
6725+
6726+ return (err != 0 );
6727+ }
6728+
67066729/*
67076730 * zpool scrub [-s | -p] <pool> ...
67086731 *
@@ -6754,6 +6777,62 @@ zpool_do_scrub(int argc, char **argv)
67546777 return (for_each_pool (argc , argv , B_TRUE , NULL , scrub_callback , & cb ));
67556778}
67566779
6780+ /*
6781+ * zpool rescrub [-s | -p] <pool> ...
6782+ *
6783+ * -s Stop. Stops any in-progress rescrub.
6784+ * -p Pause. Pause in-progress rescrub.
6785+ */
6786+ int
6787+ zpool_do_rescrub (int argc , char * * argv )
6788+ {
6789+ int c ;
6790+ scrub_cbdata_t cb ;
6791+
6792+ cb .cb_type = POOL_RESCRUB ;
6793+ cb .cb_scrub_cmd = POOL_RESCRUB_NORMAL ;
6794+
6795+ /* check options */
6796+ while ((c = getopt (argc , argv , "sp" )) != -1 ) {
6797+ switch (c ) {
6798+ case 's' :
6799+ if (cb .cb_scrub_cmd != POOL_RESCRUB_NORMAL ) {
6800+ (void ) fprintf (stderr , gettext ("invalid option"
6801+ " combination: -s and -p are mutually"
6802+ " exclusive\n" ));
6803+ usage (B_FALSE );
6804+ }
6805+ cb .cb_scrub_cmd = POOL_RESCRUB_STOP ;
6806+ break ;
6807+ case 'p' :
6808+ if (cb .cb_scrub_cmd != POOL_RESCRUB_NORMAL ) {
6809+ (void ) fprintf (stderr , gettext ("invalid option"
6810+ " combination: -s and -p are mutually"
6811+ " exclusive\n" ));
6812+ usage (B_FALSE );
6813+ }
6814+ cb .cb_scrub_cmd = POOL_RESCRUB_PAUSE ;
6815+ break ;
6816+ case '?' :
6817+ (void ) fprintf (stderr , gettext ("invalid option '%c'\n" ),
6818+ optopt );
6819+ usage (B_FALSE );
6820+ }
6821+ }
6822+
6823+ cb .cb_argc = argc ;
6824+ cb .cb_argv = argv ;
6825+ argc -= optind ;
6826+ argv += optind ;
6827+
6828+ if (argc < 1 ) {
6829+ (void ) fprintf (stderr , gettext ("missing pool name argument\n" ));
6830+ usage (B_FALSE );
6831+ }
6832+
6833+ return (for_each_pool (argc , argv , B_TRUE , NULL , rescrub_callback , & cb ));
6834+ }
6835+
67576836/*
67586837 * zpool resilver <pool> ...
67596838 *
0 commit comments