Commit 7ba6ef67 authored by Nir Soffer's avatar Nir Soffer
Browse files

examples: copy-libev.c: Fix error handling

This example failed to check the *error parameter to the completion and
extent callbacks.

- If the source NBD server failed a read, we wrote stale data from the
  request buffer to the destination image, corrupting the
  image.

- If the destination NBD server failed a write or zero command, we
  ignored the error, leaving previous content on the destination image,
  corrupting the image.

- Error in the extents callbacks were ignored. I'm not sure if this was
  a real problem, but it is a very bad example.

In all cases, the copy would end with zero exit code creating a
corrupted image.

Fixed by failing the copy if read, write, zero commands completed with
non-zero *error parameter.

If an extent callback completed with non-zero *error, we log the error
and abort the callback, leaving the extents array as NULL. If extents
completion callback completed with non-zero *error we don't need to
check it, since we already handle a NULL extents array by disabling
can_extents.

Here is an example failure:

$ ./copy-libev nbd+unix:///?socket=/tmp/src.sock nbd+unix:///?socket=/tmp/dst.sock


copy-libev: r0: read failed: Input/output error

$ echo $?
1

Signed-off-by: default avatarNir Soffer <nsoffer@redhat.com>
parent 7b8bd5d0
Pipeline #457758486 failed with stages
in 14 minutes and 41 seconds
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment