Skip to content

Commit f5e91a8

Browse files
committed
zinject: separate match counts for delay injections
It turns out we can count a matching delay injection handler earlier, by counting it once we decide its worth considering if it has a spare lane for this IO. With that in hand, it becomes useful to show separate match and inject counts, as well as the frequency, so update the output and the test to show all that. Sponsored-by: Klara, Inc. Sponsored-by: Wasabi Technology, Inc. Suggested-by: Alexander Motin <[email protected]> Signed-off-by: Rob Norris <[email protected]>
1 parent 2a71f9c commit f5e91a8

File tree

3 files changed

+27
-20
lines changed

3 files changed

+27
-20
lines changed

cmd/zinject/zinject.c

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -484,19 +484,25 @@ print_delay_handler(int id, const char *pool, zinject_record_t *record,
484484
return (0);
485485

486486
if (*count == 0) {
487-
(void) printf("%3s %-15s %-15s %-15s %-16s %-6s\n",
488-
"ID", "POOL", "DELAY (ms)", "LANES", "GUID", "INJECT");
489-
(void) printf("--- --------------- --------------- "
490-
"--------------- ---------------- ------\n");
487+
(void) printf("%3s %-15s %-16s %-10s %-5s %-9s "
488+
"%-6s %-6s\n",
489+
"ID", "POOL", "GUID", "DELAY (ms)", "LANES", "FREQ",
490+
"MATCH", "INJECT");
491+
(void) printf("--- --------------- ---------------- "
492+
"---------- ----- --------- "
493+
"------ ------\n");
491494
}
492495

493496
*count += 1;
494497

495-
(void) printf("%3d %-15s %-15llu %-15llu %llx %6lu\n", id, pool,
498+
double freq = record->zi_freq == 0 ? 100.0f :
499+
(((double)record->zi_freq) / ZI_PERCENTAGE_MAX) * 100.0f;
500+
501+
(void) printf("%3d %-15s %llx %10llu %5llu %8.4f%% "
502+
"%6lu %6lu\n", id, pool, (u_longlong_t)record->zi_guid,
496503
(u_longlong_t)NSEC2MSEC(record->zi_timer),
497504
(u_longlong_t)record->zi_nlanes,
498-
(u_longlong_t)record->zi_guid,
499-
record->zi_inject_count);
505+
freq, record->zi_match_count, record->zi_inject_count);
500506

501507
return (0);
502508
}

module/zfs/zio_inject.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -631,9 +631,6 @@ zio_handle_io_delay(zio_t *zio)
631631
if (handler->zi_record.zi_cmd != ZINJECT_DELAY_IO)
632632
continue;
633633

634-
if (!freq_triggered(handler->zi_record.zi_freq))
635-
continue;
636-
637634
if (vd->vdev_guid != handler->zi_record.zi_guid)
638635
continue;
639636

@@ -658,6 +655,12 @@ zio_handle_io_delay(zio_t *zio)
658655
ASSERT3U(handler->zi_record.zi_nlanes, >,
659656
handler->zi_next_lane);
660657

658+
handler->zi_record.zi_match_count++;
659+
660+
/* Limit the use of this handler if requested */
661+
if (!freq_triggered(handler->zi_record.zi_freq))
662+
continue;
663+
661664
/*
662665
* We want to issue this IO to the lane that will become
663666
* idle the soonest, so we compare the soonest this
@@ -730,7 +733,6 @@ zio_handle_io_delay(zio_t *zio)
730733
min_handler->zi_next_lane = (min_handler->zi_next_lane + 1) %
731734
min_handler->zi_record.zi_nlanes;
732735

733-
min_handler->zi_record.zi_match_count++;
734736
min_handler->zi_record.zi_inject_count++;
735737

736738
}

tests/zfs-tests/tests/functional/cli_root/zinject/zinject_counts.ksh

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -116,20 +116,19 @@ function test_object_injection
116116
done
117117
}
118118

119-
# Test delay injections, by injecting delays and writing. Note that there
120-
# is no frequency option for these, and match counts are not reqported, so
121-
# we only look for the inject count in the last column.
119+
# Test delay injections, by injecting delays and writing
122120
function test_delay_injection
123121
{
124-
log_must zinject -d $DISK1 -D 50:1 $TESTPOOL
122+
for freq in 100 50 ; do
123+
log_must zinject -d $DISK1 -D 50:1 -f $freq $TESTPOOL
125124

126-
log_must dd if=/dev/urandom of=/$TESTPOOL/file bs=1M count=1
127-
zpool sync
125+
log_must dd if=/dev/urandom of=/$TESTPOOL/file bs=1M count=1
126+
zpool sync
128127

129-
typeset -i match=($(zinject | grep -oE ' [0-9]+$'))
130-
log_must test $match -gt 0
128+
log_must check_count_freq $freq
131129

132-
log_must zinject -c all
130+
log_must zinject -c all
131+
done
133132
}
134133

135134
# Disable cache, to ensure reads induce IO

0 commit comments

Comments
 (0)