Skip to content

Commit 3daee86

Browse files
committed
initial stage of userland scrubbing requirements
1 parent e1c7460 commit 3daee86

File tree

5 files changed

+88
-10
lines changed

5 files changed

+88
-10
lines changed

sbin/raidctl/raidctl.c

Lines changed: 69 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ static void rf_output_pmstat(int, int);
9494
static void rf_pm_configure(int, int, char *, int[]);
9595
static void rf_simple_create(int, int, char *[]);
9696
static unsigned int xstrtouint(const char *);
97+
static void rf_scrub_begin(int, int, char *[]);
9798

9899
int 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-
439445
static void
440446
rf_configure(int fd, char *config_file, int force)
441447
{
@@ -1227,6 +1233,66 @@ 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+
if (argc == i + 1)
1251+
errx(1, "scrubbing rate unspecified");
1252+
1253+
char *c;
1254+
double bps = strtod(argv[++i], &c);
1255+
if (bps == 0)
1256+
errx(1, "invalid input rate");
1257+
1258+
if (c != NULL) {
1259+
if (!strcmp(c, "B"))
1260+
; /* do nothing */
1261+
else if (!strcmp(c, "KB"))
1262+
scrb.rate = bps * 1000;
1263+
else if (!strcmp(c, "MB"))
1264+
scrb.rate = bps * 1000 * 1000;
1265+
else if (!strcmp(c, "GB"))
1266+
scrb.rate = bps * 1000 * 1000 * 1000;
1267+
} else
1268+
errx(1, "no scrubbing rate unit specified");
1269+
1270+
}
1271+
else if (strcmp(argv[i], "portion") == 0) {
1272+
if (argc <= i + 2) /* do argc check once */
1273+
errx(1, "portion needs a lower to upper bound range");
1274+
1275+
portion = atoi(argv[++i]); /* i increased */
1276+
if (portion >= 100)
1277+
errx(1, "begin scrubbing portion range should be less than 100 percent");
1278+
scrb.portion_begin = portion;
1279+
1280+
portion = atoi(argv[++i]);
1281+
if (portion > 100)
1282+
errx(1, "scrubbing portion upper bound should not be more than 100 percent");
1283+
scrb.portion_end = portion;
1284+
1285+
if (scrb.portion_begin >= scrb.portion_end) {
1286+
errx(1, "upper bound must be greater than lower bound for scrub portions");
1287+
}
1288+
1289+
}
1290+
}
1291+
1292+
do_ioctl(fd, RAIDFRAME_SCRUB, &scrb,
1293+
"RAIDFRAME_COMPONENT_SCRUB");
1294+
}
1295+
12301296
/* Simplified RAID creation with a single command line... */
12311297
static void
12321298
rf_simple_create(int fd, int argc, char *argv[])

sys/dev/raidframe/raidframeio.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,5 +135,6 @@
135135
#define RAIDFRAME_GET_INFO _IOWR('r', 42, RF_DeviceConfig_t *) /* get configuration */
136136
#define RAIDFRAME_CONFIGURE _IOW ('r', 43, void *) /* configure the driver */
137137
#define RAIDFRAME_RESCAN _IO ('r', 44)
138+
#define RAIDFRAME_SCRUB _IOW('r', 45, RF_Scrub_t *)
138139
#endif /* !_RF_RAIDFRAMEIO_H_ */
139140

sys/dev/raidframe/raidframevar.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@ typedef struct RF_CallbackValueDesc_s RF_CallbackValueDesc_t;
215215
typedef struct RF_ChunkDesc_s RF_ChunkDesc_t;
216216
typedef struct RF_CommonLogData_s RF_CommonLogData_t;
217217
typedef struct RF_Config_s RF_Config_t;
218+
typedef struct RF_Scrub_s RF_Scrub_t;
218219
typedef struct RF_CumulativeStats_s RF_CumulativeStats_t;
219220
typedef struct RF_DagHeader_s RF_DagHeader_t;
220221
typedef struct RF_DagList_s RF_DagList_t;
@@ -351,6 +352,13 @@ struct RF_Config_s {
351352
*/
352353
};
353354

355+
/* introduce a scrub components containing scrub rate and portion to scrub */
356+
struct RF_Scrub_s {
357+
uint64_t rate;
358+
int portion_begin;
359+
int portion_end;
360+
};
361+
354362
typedef RF_uint32 RF_ReconReqFlags_t;
355363
/* flags that can be put in the rf_recon_req structure */
356364
#define RF_FDFLAGS_NONE 0x0 /* just fail the disk */
@@ -386,7 +394,7 @@ enum RF_DiskStatus_e {
386394
rf_ds_reconstructing, /* reconstruction ongoing */
387395
rf_ds_dist_spared, /* reconstruction complete to distributed
388396
* spare space, dead disk not yet replaced */
389-
rf_ds_spared, /* reconstruction complete, dead disk not
397+
rf_ds_spared, /* reconstruction complete, dead disk not
390398
yet replaced */
391399
rf_ds_spare, /* an available spare disk */
392400
rf_ds_used_spare, /* a spare which has been used, and hence is

sys/dev/raidframe/rf_driver.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ rf_Configure(RF_Raid_t *raidPtr, RF_Config_t *cfgPtr, RF_AutoConfig_t *ac)
363363
DO_RAID_INIT_CONFIGURE(rf_ConfigureReconstruction);
364364
DO_RAID_INIT_CONFIGURE(rf_ConfigureDiskQueueSystem);
365365
DO_RAID_INIT_CONFIGURE(rf_ConfigurePSStatus);
366-
366+
367367
DO_RAID_INIT_CONFIGURE(rf_ConfigureEngine);
368368
DO_RAID_INIT_CONFIGURE(rf_ConfigureStripeLocks);
369369

@@ -386,8 +386,8 @@ rf_Configure(RF_Raid_t *raidPtr, RF_Config_t *cfgPtr, RF_AutoConfig_t *ac)
386386
DO_RAID_INIT_CONFIGURE(rf_ConfigureLayout);
387387

388388

389-
390-
389+
390+
391391
/* Initialize per-RAID PSS bits */
392392
rf_InitPSStatus(raidPtr);
393393

@@ -562,7 +562,7 @@ rf_ShutdownRDFreeList(void *arg)
562562
RF_Raid_t *raidPtr;
563563

564564
raidPtr = (RF_Raid_t *) arg;
565-
565+
566566
pool_destroy(&raidPtr->pools.rad);
567567
}
568568

@@ -708,9 +708,9 @@ rf_DoAccess(RF_Raid_t * raidPtr, RF_IoType_t type, RF_RaidAddr_t raidAddress, RF
708708
RF_ETIMER_START(desc->tracerec.tot_timer);
709709
#endif
710710

711-
if (raidPtr->parity_map != NULL &&
711+
if (raidPtr->parity_map != NULL &&
712712
type == RF_IO_TYPE_WRITE)
713-
rf_paritymap_begin(raidPtr->parity_map, raidAddress,
713+
rf_paritymap_begin(raidPtr->parity_map, raidAddress,
714714
numBlocks);
715715

716716
rf_ContinueRaidAccess(desc);

sys/dev/raidframe/rf_netbsdkintf.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1611,6 +1611,9 @@ raidioctl(dev_t dev, u_long cmd, void *data, int flag, struct lwp *l)
16111611
return retcode;
16121612
return rf_construct(rs, k_cfg);
16131613

1614+
case RAIDFRAME_COMPONENT_SCRUB:
1615+
/* think about kernel later */
1616+
16141617
/* shutdown the system */
16151618
case RAIDFRAME_SHUTDOWN:
16161619

0 commit comments

Comments
 (0)