CA-142264: use errno as the error for the grant-copy ioctl

And improve error reporting.

Signed-off-by: Thanos Makatos <thanos.makatos@citrix.com>
Reviewed-by: Chandrika Srinivasan <chandrika.srinivasan@citrix.com>
CP-9459: don't retry request on EFAULT

Signed-off-by: Thanos Makatos <thanos.makatos@citrix.com>
Reviewed-by: Chandrika Srinivasan <chandrika.srinivasan@citrix.com>
CA-142434: don't double free request buffer

Signed-off-by: Thanos Makatos <thanos.makatos@citrix.com>
Reviewed-by: Chandrika Srinivasan <chandrika.srinivasan@citrix.com>
CA-141611: documentation and debug

Signed-off-by: Thanos Makatos <thanos.makatos@citrix.com>
Reviewed-by: Chandrika Srinivasan <chandrika.srinivasan@citrix.com>
CA-141611: simplify ring suspend/resume interface

Signed-off-by: Thanos Makatos <thanos.makatos@citrix.com>
Reviewed-by: Chandrika Srinivasan <chandrika.srinivasan@citrix.com>
CA-141611: use accessor for determining whether there are pending requests

Signed-off-by: Thanos Makatos <thanos.makatos@citrix.com>
Reviewed-by: Chandrika Srinivasan <chandrika.srinivasan@citrix.com>
CA-141611: allow negative time outs to indicate infinity

Allow negative time outs in order to set an event's deadline to infinity.

Signed-off-by: Thanos Makatos <thanos.makatos@citrix.com>
Reviewed-by: Chandrika Srinivasan <chandrika.srinivasan@citrix.com>
CA-141611: check ring unmap return value

Signed-off-by: Thanos Makatos <thanos.makatos@citrix.com>
Reviewed-by: Chandrika Srinivasan <chandrika.srinivasan@citrix.com>
CA-141611: introduce check ring event

This patch introduces the check ring event. This allows scheduling an
event for checking the ring for new requests independent of event
channel notifications.

Signed-off-by: Thanos Makatos <thanos.makatos@citrix.com>
Signed-off-by: Mate Lakat <mate.lakat@citrix.com>
Reviewed-by: Chandrika Srinivasan <chandrika.srinivasan@citrix.com>
CA-141611: break on barrier request

This patch introduces part of write I/O barrier functionality. When we
check the ring for requests, if we encounter a barrier request we
immediately stop extracting requests from the ring and mask the event
associated with checking the ring in order to avoid submitting new I/O
requests.

Signed-off-by: Thanos Makatos <thanos.makatos@citrix.com>
Signed-off-by: Mate Lakat <mate.lakat@citrix.com>
Reviewed-by: Chandrika Srinivasan <chandrika.srinivasan@citrix.com>
CA-141611: complete barrier when all pending requests complete

This patch adds the rest of the functionality required for write I/O
barriers. When a request completes, we check whether there is a pending
barrier request and if so we complete it and schedule the event that
checks the ring for requests.

Signed-off-by: Thanos Makatos <thanos.makatos@citrix.com>
Signed-off-by: Mate Lakat <mate.lakat@citrix.com>
Reviewed-by: Chandrika Srinivasan <chandrika.srinivasan@citrix.com>
CA-144705: use correct depth when destroying dead rings

Take care when completing a barrier request of dead ring because the
completion function is recursively called.

Signed-off-by: Thanos Makatos <thanos.makatos@citrix.com>
Reviewed-by: Chandrika Srinivasan <chandrika.srinivasan@citrix.com>
CA-141611: advertise write I/O barriers in Xenbus

blkback advertises I/O write barriers for CD-ROM devices as well, and so
do we.

Signed-off-by: Thanos Makatos <thanos.makatos@citrix.com>
Reviewed-by: Chandrika Srinivasan <chandrika.srinivasan@citrix.com>
CA-141611: command line option to enable/disable write I/O barrier support

This can be useful for globally disabling write I/O barriers for
whatever reason (e.g. debugging).

Signed-off-by: Thanos Makatos <thanos.makatos@citrix.com>
Reviewed-by: Mate Lakat <mate.lakat@citrix.com>
CA-141611: move parsing of the request to a separate function

Signed-off-by: Thanos Makatos <thanos.makatos@citrix.com>
Reviewed-by: Mate Lakat <mate.lakat@citrix.com>
CA-141611: write I/O barriers might contain data

Write I/O barriers might contain data to be written, so they must be
treated as a special kind of write. Write I/O barriers carrying data are
simply submitted as a write request, the only difference is the
completion path where the completion callback can be called up to two
times: (a) one for the I/O completion and (b) one when the last pending
non-barrier request completes, in case the I/O completion for the
barrier occurred before that. Otherwise, the I/O completion will proceed
with completing the barrier request.

Signed-off-by: Thanos Makatos <thanos.makatos@citrix.com>
Signed-off-by: Felipe Franciosi <felipe.franciosi@citrix.com>
Reviewed-by: Mate Lakat <mate.lakat@citrix.com>
Merge branch 'CA-141611' (support for write I/O barriers) into xs64bit

Signed-off-by: Thanos Makatos <thanos.makatos@citrix.com>