CA-140343: Fix error sign

Incorrect error sign shows "Unknown error 18446744073709551614"
Fixed error sign to get more meaningful error string.

Signed-off-by: Chandrika Srinivasan <chandrika.srinivasan@citrix.com>
Reviewed-by: Siddharth Vinothkumar <siddharth.vinothkumar@citrix.com>

GitHub: closes #117 on xapi-project/blktap
CP-9457: write tapdisk PID in kthread-pid

This imitates blkback, allowing other components to use the process ID
of the application responsible for the data path as they please, e.g.
the toolstack using ionice(1) for QoS.

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

GitHub: closes #121 on xapi-project/blktap
CA-142264: use errno as the error for the gant-copy ioctl

And improve error reporting.

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

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

Signed-off-by: Thanos Makatos <thanos.makatos@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>
CA-141611: documentation and debug

Signed-off-by: Thanos Makatos <thanos.makatos@citrix.com>
CA-141611: make ring suspension idempotent

This allows stack-able ring suspensions. This is important as a ring might
be suspended by a barrier operation but must be suspended again by a pause
operation.

Also, when trying to pause the VBD, tapdisk_vbd_quiesce_queue() might
fail with EAGAIN and the caller can keep trying, this leads to
suspending the same ring multiple times but only resuming it once.

Signed-off-by: Thanos Makatos <thanos.makatos@citrix.com>
CA-141611: don't access freed rings

If tapdisk_xenblkif_complete_request() is recursively called on a dead ring
and one of its nested calls free the ring, the outer call will attempt to
access the freed ring. We protect against cases like this by tracking our
depth.

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

Signed-off-by: Thanos Makatos <thanos.makatos@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>
CA-141611: documentation

Signed-off-by: Thanos Makatos <thanos.makatos@citrix.com>
CA-141611: suspend/resume blindly

Signed-off-by: Thanos Makatos <thanos.makatos@citrix.com>
CA-141611: support for write I/O barriers

This patch adds support for write I/O barriers in blktap3. Write I/O barriers
are implemented at the shared ring level. Although this is not the right
place to implement them (the ring is simply a mechanism to push requests
and responses), it is far simpler to do so than in any other layer in
tapdisk.

Barriers are implemented by having the function that takes requests off
the ring break as soon as a barrier request is encountered. We then
disable the event associated with the event channel notifications and
wait until all pending requests that have been submitted prior to the
barrier have completed. Once they have, we continue processing requests
in the ring.

After a barrier completes, instead of explicitly calling the function
that processes the ring, we schedule the execution of an event similar to the
one that handles ring notifications. We do this for two reasons: first,
it is possible that a malicious guest queues barriers one at a time,
leading to tapdisk recursively calling the function that processes the
ring exhausting stack space. Second, processing the rest of the requests
this way is far simpler than any other approach as it fits well in the
current model.

When a barrier completes, we explicitly set final to 1 when calling
tapdisk_xenio_ctx_process_ring(). We do so because if the barrier was
the last request in the ring we would not call
RING_FINAL_CHECK_FOR_REQUESTS to re-enable notifications.

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

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

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