@@ -94,6 +94,7 @@ static void rf_output_pmstat(int, int);
9494static void rf_pm_configure (int , int , char * , int []);
9595static void rf_simple_create (int , int , char * []);
9696static unsigned int xstrtouint (const char * );
97+ static void rf_scrub_begin (int , int , char * []);
9798
9899int verbose ;
99100
@@ -141,8 +142,12 @@ main(int argc,char *argv[])
141142 last_unit = 0 ;
142143 openmode = O_RDWR ; /* default to read/write */
143144
144- if (argc > 5 ) {
145- /* we have at least 5 args, so it might be a simplified config */
145+ if (argc > 5 || (argc > 2 && !strncmp (argv [2 ], "scrub" , 5 ))) {
146+
147+ /*
148+ * we have at least 5 args, so it might be a simplified config
149+ * for cases where we will be doing scrubbing, args may be less than 5
150+ */
146151
147152 strlcpy (name , argv [1 ], sizeof (name ));
148153 fd = opendisk (name , openmode , dev_name , sizeof (dev_name ), 0 );
@@ -168,6 +173,8 @@ main(int argc,char *argv[])
168173 strlcpy (autoconf , "yes" , sizeof (autoconf ));
169174 set_autoconfig (fd , raidID , autoconf );
170175
176+ } else if (strncmp (argv [2 ], "scrub" , 5 ) == 0 ) {
177+ rf_scrub_begin (fd , argc - 3 , & argv [3 ]);
171178 } else
172179 usage ();
173180
@@ -435,7 +442,6 @@ do_ioctl(int fd, unsigned long command, void *arg, const char *ioctl_name)
435442 err (1 , "ioctl (%s) failed" , ioctl_name );
436443}
437444
438-
439445static void
440446rf_configure (int fd , char * config_file , int force )
441447{
@@ -1227,6 +1233,67 @@ get_time_string(char *string, size_t len, int simple_time)
12271233
12281234}
12291235
1236+ static void
1237+ rf_scrub_begin (int fd , int argc , char * argv [])
1238+ {
1239+ int rate ;
1240+ int portion ;
1241+ RF_Scrub_t scrb ;
1242+ /* initialize default values for scrubbing */
1243+ scrb .rate = 2 * 1000 * 1000 ;
1244+ scrb .portion_begin = 0 ;
1245+ scrb .portion_end = 100 ;
1246+
1247+ for (int i = 0 ; i < argc ; i ++ )
1248+ {
1249+ if (strcmp (argv [i ], "rate" ) == 0 ) {
1250+ char * c ;
1251+ double bps = strtod (argv [++ i ], & c );
1252+ if (bps == 0 )
1253+ errx (1 , "invalid input rate" );
1254+
1255+ if (c != NULL ) {
1256+ if (!strcmp (c , "b" ))
1257+ ; /* do nothing */
1258+ else if (!strcmp (c , "Kb" ))
1259+ scrb .rate = bps * 1000 ;
1260+ else if (!strcmp (c , "Mb" ))
1261+ scrb .rate = bps * 1000 * 1000 ;
1262+ else if (!strcmp (c , "Gb" ))
1263+ scrb .rate = bps * 1000 * 1000 * 1000 ;
1264+ } else
1265+ errx (1 , "no scrubbing rate unit specified" );
1266+
1267+ }
1268+ else if (strcmp (argv [i ], "portion" ) == 0 ) {
1269+ if (argv [++ i ]) {
1270+ portion = atoi (argv [i ]); /* i increased */
1271+ if (portion >= 100 )
1272+ errx (1 , "begin scrubbing portion range should be less than 100 percent" );
1273+ scrb .portion_begin = portion ;
1274+ } else
1275+ errx (1 , "portion needs a lower to upper bound range" );
1276+
1277+
1278+ if (argv [++ i ]) {
1279+ portion = atoi (argv [i ]);
1280+ if (portion > 100 )
1281+ errx (1 , "scrubbing portion upper bound should not be more than 100 percent" );
1282+ scrb .portion_end = portion ;
1283+ } else
1284+ errx (1 , "no upper bound specified for portion range" );
1285+
1286+ if (scrb .portion_begin >= scrb .portion_end ) {
1287+ errx (1 , "upper bound must be greater than lower bound for scrub portions" );
1288+ }
1289+
1290+ }
1291+ }
1292+
1293+ do_ioctl (fd , RAIDFRAME_SCRUB , & scrb ,
1294+ "RAIDFRAME_COMPONENT_SCRUB" );
1295+ }
1296+
12301297/* Simplified RAID creation with a single command line... */
12311298static void
12321299rf_simple_create (int fd , int argc , char * argv [])
0 commit comments