@@ -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,26 @@ 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+ /*
6718+ * Ignore faulted pools.
6719+ */
6720+ if (zpool_get_state (zhp ) == POOL_STATE_UNAVAIL ) {
6721+ (void ) fprintf (stderr , gettext ("cannot rescrub '%s': pool is "
6722+ "currently unavailable\n" ), zpool_get_name (zhp ));
6723+ return (1 );
6724+ }
6725+
6726+ err = zpool_rescrub (zhp , cb -> cb_type , cb -> cb_scrub_cmd );
6727+
6728+ return (err != 0 );
6729+ }
6730+
67066731/*
67076732 * zpool scrub [-s | -p] <pool> ...
67086733 *
@@ -6754,6 +6779,62 @@ zpool_do_scrub(int argc, char **argv)
67546779 return (for_each_pool (argc , argv , B_TRUE , NULL , scrub_callback , & cb ));
67556780}
67566781
6782+ /*
6783+ * zpool rescrub [-s | -p] <pool> ...
6784+ *
6785+ * -s Stop. Stops any in-progress rescrub.
6786+ * -p Pause. Pause in-progress rescrub.
6787+ */
6788+ int
6789+ zpool_do_rescrub (int argc , char * * argv )
6790+ {
6791+ int c ;
6792+ scrub_cbdata_t cb ;
6793+
6794+ cb .cb_type = POOL_RESCRUB ;
6795+ cb .cb_scrub_cmd = POOL_RESCRUB_NORMAL ;
6796+
6797+ /* check options */
6798+ while ((c = getopt (argc , argv , "sp" )) != -1 ) {
6799+ switch (c ) {
6800+ case 's' :
6801+ if (cb .cb_scrub_cmd != POOL_RESCRUB_NORMAL ) {
6802+ (void ) fprintf (stderr , gettext ("invalid option"
6803+ " combination: -s and -p are mutually"
6804+ " exclusive\n" ));
6805+ usage (B_FALSE );
6806+ }
6807+ cb .cb_scrub_cmd = POOL_RESCRUB_STOP ;
6808+ break ;
6809+ case 'p' :
6810+ if (cb .cb_scrub_cmd != POOL_RESCRUB_NORMAL ) {
6811+ (void ) fprintf (stderr , gettext ("invalid option"
6812+ " combination: -s and -p are mutually"
6813+ " exclusive\n" ));
6814+ usage (B_FALSE );
6815+ }
6816+ cb .cb_scrub_cmd = POOL_RESCRUB_PAUSE ;
6817+ break ;
6818+ case '?' :
6819+ (void ) fprintf (stderr , gettext ("invalid option '%c'\n" ),
6820+ optopt );
6821+ usage (B_FALSE );
6822+ }
6823+ }
6824+
6825+ cb .cb_argc = argc ;
6826+ cb .cb_argv = argv ;
6827+ argc -= optind ;
6828+ argv += optind ;
6829+
6830+ if (argc < 1 ) {
6831+ (void ) fprintf (stderr , gettext ("missing pool name argument\n" ));
6832+ usage (B_FALSE );
6833+ }
6834+
6835+ return (for_each_pool (argc , argv , B_TRUE , NULL , rescrub_callback , & cb ));
6836+ }
6837+
67576838/*
67586839 * zpool resilver <pool> ...
67596840 *
0 commit comments