=head1 NAME

nbdkit-evil-filter - add random data corruption to reads

=head1 SYNOPSIS

 nbdkit --filter=evil PLUGIN [PLUGIN-ARGS...]
        evil=[cosmic-rays|stuck-bits|stuck-wires]
        [evil-probability=PROB] [evil-stuck-probability=PROB]
        [evil-seed=SEED]

=head1 DESCRIPTION

nbdkit-evil-filter is a Byzantine filter for L<nbdkit(1)> that
randomly corrupts data when reading from the underlying plugin.  This
can be used for testing filesystem checksums.  Note that it does not
change write operations, so the underlying plugin contains the correct
data.

L<nbdkit-error-filter(1)> is a related filter that injects hard errors
into the NBD protocol.

This filter has several modes, controlled using the C<evil=...>
parameter.  These are:

=over 4

=item C<evil=cosmic-rays>

Bits are flipped at random when reading data.  The probability that a
bit is flipped is controlled using the C<evil-probability> parameter,
defaulting to 1e-8 (on average 1 in every 100 million bits read is
flipped).

=item C<evil=stuck-bits>

This is the default mode.

Fixed bits in the backing file are stuck randomly high or low.  The
C<evil-probability> parameter controls the expected probability that a
particular bit is stuck, defaulting in this mode to 1e-8 (1 in 100
million).  C<evil-stuck-probability> controls the probability that a
stuck bit is read as its stuck value or its correct value, defaulting
to 100% (always read as a stuck bit).

=item C<evil=stuck-wires>

This is similar to C<stuck-bits> but instead of simulating bad backing
data, it simulates stuck wires along the data path (eg. in a
register).  The difference is that when reading, the stuck bit always
happens at the same position in the packet of data being read,
regardless of where on the underlying disk it is being read from.
C<evil-probability> controls the probability of a stuck wire,
defaulting in this mode to 1e-6 (1 in 1 million).
C<evil-stuck-probability> controls the probability that a stuck bit is
read as its stuck value or its correct value, defaulting to 100%
(always read as a stuck bit).

=back

=head1 EXAMPLES

Add some stuck bits to the backing file at random:

 nbdkit --filter=evil file disk.img

Cosmic rays will flip (on average) one in every 100 million bits
copied from the backing file over NBD:

 nbdkit --filter=evil file disk.img evil=cosmic-rays \
        --run 'nbdcopy $uri output.img'

=head1 NOTES

=head2 Extents

Plugins can be sparse.  This filter only corrupts bits in non-sparse
parts of the backing disk and it leaves sparse regions unchanged
(which is realistic behaviour).  If you wish to use this filter to
corrupt sparse regions, then combine this filter with
L<nbdkit-noextents-filter(1)>.  For example:

 nbdkit --filter=evil --filter=noextents memory 1G

=head2 Probability limited to [ 1e-12 .. 1/8 ]

The current implementation limits probabilities to the range
S<[ 1e-12 .. 1/8 ]>.  Values below this range are treated the same as
0%.  Values above this range are treated the same as 100%.

=head1 PARAMETERS

=over 4

=item B<evil=cosmic-rays>

=item B<evil=stuck-bits>

=item B<evil=stuck-wires>

Select the mode of evil.  See the L</DESCRIPTION> above.  The default
is C<stuck-bits>.

=item B<evil-probability=>N

=item B<evil-probability=>NB<:>M

=item B<evil-probability=>NB<%>

Set the probability for the mode.  You can either use a floating point
number between 0 and 1, eg. C<evil-probability=0.001> or
C<evil-probability=1e-6>.  Or you can write it as N in M, eg.
C<evil-probability=1:1000000> or C<evil-probability=3.33:100000>.  Or
you can write this as a percentage, eg. C<evil-probability=1%>.

The default probability depends on the mode.

=item B<evil-seed=>SEED

To make runs repeatable, use this to set a seed for the random number
generator.  Note that runs are repeatable only if you use the same
version of nbdkit, since in future we may change the algorithm.

The default is to choose a seed at random.

=item B<evil-stuck-probability=>N

=item B<evil-stuck-probability=>NB<:>M

=item B<evil-stuck-probability=>NB<%>

For the "stuck-*" modes, the probability that when reading a stuck bit
you will read the stuck bit or the correct value.  This defaults to 1
(ie. 100%) which means the bit is always stuck.  Setting it to 0.5 for
example will mean that half the time the bit appears stuck and half
the time you see the correct value.

=back

=head1 FILES

=over 4

=item F<$filterdir/nbdkit-evil-filter.so>

The filter.

Use C<nbdkit --dump-config> to find the location of C<$filterdir>.

=back

=head1 VERSION

C<nbdkit-evil-filter> first appeared in nbdkit 1.36.

=head1 SEE ALSO

L<nbdkit(1)>,
L<nbdkit-filter(3)>,
L<nbdkit-delay-filter(1)>,
L<nbdkit-noextents-filter(1)>,
L<nbdkit-error-filter(1)>,
L<nbdkit_parse_probability(3)>.

=head1 AUTHORS

Richard W.M. Jones

=head1 COPYRIGHT

Copyright Red Hat
