@@ -242,6 +242,35 @@ err_to_str(int err)
242
242
return ("[unknown]" );
243
243
}
244
244
245
+ static const char * const iotypestrtable [ZINJECT_IOTYPES ] = {
246
+ [ZINJECT_IOTYPE_NULL ] = "null" ,
247
+ [ZINJECT_IOTYPE_READ ] = "read" ,
248
+ [ZINJECT_IOTYPE_WRITE ] = "write" ,
249
+ [ZINJECT_IOTYPE_FREE ] = "free" ,
250
+ [ZINJECT_IOTYPE_CLAIM ] = "claim" ,
251
+ [ZINJECT_IOTYPE_FLUSH ] = "flush" ,
252
+ [ZINJECT_IOTYPE_TRIM ] = "trim" ,
253
+ [ZINJECT_IOTYPE_ALL ] = "all" ,
254
+ };
255
+
256
+ static zinject_iotype_t
257
+ str_to_iotype (const char * arg )
258
+ {
259
+ for (uint_t iotype = 0 ; iotype < ZINJECT_IOTYPES ; iotype ++ )
260
+ if (iotypestrtable [iotype ] != NULL &&
261
+ strcasecmp (iotypestrtable [iotype ], arg ) == 0 )
262
+ return (iotype );
263
+ return (ZINJECT_IOTYPES );
264
+ }
265
+
266
+ static const char *
267
+ iotype_to_str (zinject_iotype_t iotype )
268
+ {
269
+ if (iotype >= ZINJECT_IOTYPES || iotypestrtable [iotype ] == NULL )
270
+ return ("[unknown]" );
271
+ return (iotypestrtable [iotype ]);
272
+ }
273
+
245
274
/*
246
275
* Print usage message.
247
276
*/
@@ -435,10 +464,6 @@ static int
435
464
print_device_handler (int id , const char * pool , zinject_record_t * record ,
436
465
void * data )
437
466
{
438
- static const char * iotypestr [] = {
439
- "null" , "read" , "write" , "free" , "claim" , "flush" , "trim" , "all" ,
440
- };
441
-
442
467
int * count = data ;
443
468
444
469
if (record -> zi_guid == 0 || record -> zi_func [0 ] != '\0' )
@@ -465,7 +490,7 @@ print_device_handler(int id, const char *pool, zinject_record_t *record,
465
490
466
491
(void ) printf ("%3d %-15s %llx %-5s %-10s %8.4f%% "
467
492
"%6lu %6lu\n" , id , pool , (u_longlong_t )record -> zi_guid ,
468
- iotypestr [ record -> zi_iotype ] , err_to_str (record -> zi_error ),
493
+ iotype_to_str ( record -> zi_iotype ) , err_to_str (record -> zi_error ),
469
494
freq , record -> zi_match_count , record -> zi_inject_count );
470
495
471
496
return (0 );
@@ -866,7 +891,7 @@ main(int argc, char **argv)
866
891
int quiet = 0 ;
867
892
int error = 0 ;
868
893
int domount = 0 ;
869
- int io_type = ZIO_TYPES ;
894
+ int io_type = ZINJECT_IOTYPE_ALL ;
870
895
int action = VDEV_STATE_UNKNOWN ;
871
896
err_type_t type = TYPE_INVAL ;
872
897
err_type_t label = TYPE_INVAL ;
@@ -1060,19 +1085,8 @@ main(int argc, char **argv)
1060
1085
}
1061
1086
break ;
1062
1087
case 'T' :
1063
- if (strcasecmp (optarg , "read" ) == 0 ) {
1064
- io_type = ZIO_TYPE_READ ;
1065
- } else if (strcasecmp (optarg , "write" ) == 0 ) {
1066
- io_type = ZIO_TYPE_WRITE ;
1067
- } else if (strcasecmp (optarg , "free" ) == 0 ) {
1068
- io_type = ZIO_TYPE_FREE ;
1069
- } else if (strcasecmp (optarg , "claim" ) == 0 ) {
1070
- io_type = ZIO_TYPE_CLAIM ;
1071
- } else if (strcasecmp (optarg , "flush" ) == 0 ) {
1072
- io_type = ZIO_TYPE_FLUSH ;
1073
- } else if (strcasecmp (optarg , "all" ) == 0 ) {
1074
- io_type = ZIO_TYPES ;
1075
- } else {
1088
+ io_type = str_to_iotype (optarg );
1089
+ if (io_type == ZINJECT_IOTYPES ) {
1076
1090
(void ) fprintf (stderr , "invalid I/O type "
1077
1091
"'%s': must be 'read', 'write', 'free', "
1078
1092
"'claim', 'flush' or 'all'\n" , optarg );
@@ -1194,7 +1208,7 @@ main(int argc, char **argv)
1194
1208
}
1195
1209
1196
1210
if (error == EILSEQ &&
1197
- (record .zi_freq == 0 || io_type != ZIO_TYPE_READ )) {
1211
+ (record .zi_freq == 0 || io_type != ZINJECT_IOTYPE_READ )) {
1198
1212
(void ) fprintf (stderr , "device corrupt errors require "
1199
1213
"io type read and a frequency value\n" );
1200
1214
libzfs_fini (g_zfs );
@@ -1209,9 +1223,9 @@ main(int argc, char **argv)
1209
1223
1210
1224
if (record .zi_nlanes ) {
1211
1225
switch (io_type ) {
1212
- case ZIO_TYPE_READ :
1213
- case ZIO_TYPE_WRITE :
1214
- case ZIO_TYPES :
1226
+ case ZINJECT_IOTYPE_READ :
1227
+ case ZINJECT_IOTYPE_WRITE :
1228
+ case ZINJECT_IOTYPE_ALL :
1215
1229
break ;
1216
1230
default :
1217
1231
(void ) fprintf (stderr , "I/O type for a delay "
0 commit comments