CA-140334: don't complain when tapdisk control socket doesn't exist

tapdisks may be destroyed at any time by the SM, therefore their control
socket might disappear abruptly. This is expected and complaining about
innocuous errors like that complicates debugging.

Signed-off-by: Thanos Makatos <thanos.makatos@citrix.com>
Reviewed-by: Germano Percossi <germano.percossi@citrix.com>

GitHub: closes #101 on xapi-project/blktap
CA-135774: Properly log when low memory handler is not available

Use EPRINTF rather than ERR when logging if the low memory handler is not
available because it is initialized before ERR logging is set up.

Signed-off-by: Ross Lagerwall <ross.lagerwall@citrix.com>
Reviewed-by: Germano Percossi <germano.percossi@citrix.com>

GitHub: closes #112 on xapi-project/blktap
CA-141740: don't overwrite requests not yet submitted

When submitting requests we use a sub-array of the free requests. This
is problematic because if one request fails (e.g. because the grant-copy
failed while serving a write request) we immediately complete the
request, and completing the requests means that we put it back on the
part of the array designated to hold free requests. However, putting
back the request overwrites part of the sub-array designated to the
not-yet-submitted requests, which leads to corruption.

Operating on a copy of the sub-array of the requests to be submitted
addresses the issue.

Signed-off-by: Thanos Makatos <thanos.makatos@citrix.com>
Reviewed-by: Mate Lakat <mate.lakat@citrix.com>

GitHub: closes #115 on xapi-project/blktap
CA-137990 & CA-140031: allow ring disconnection with pending requests

This patch allows disconnecting from the ring even though there are
pending requests. This allows the front-end to close and re-open then
ring when necessary (e.g. I/O is slow and the front-end is told to reset
itself) without having to wait for these requests to complete, as
cancelling requests is not supported by Xenbus.

Rings with pending requests aren't immediately destroyed (that's
impossible), but are marked as dead. Requests completing against dead
rings are cleaned up and the last pending requests truly destroys the
ring. There can be multiple dead rings. When closing the VBD we have to
wait for all pending requests against all dead rings to complete.

Finally, we maintain a list of active rings, as there can be multiple
rings against the same VBD (e.g. multiple VMs using the same ISO). It is
unknown how this worked so far.

Minor improvements are introduced.

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

GitHub: closes #114 on xapi-project/blktap
CA-139733: Stop vhd false alarm

Stop complaining the primary footer is invalid during storage motion
since the backup one will be read.  Warning messages when reading backup
one is kept.

Signed-off-by: Kaifeng Zhu <kaifeng.zhu@citrix.com>
Reviewed-by: Siddharth Vinothkumar <siddharth.vinothkumar@citrix.com>

GitHub: closes #109 on xapi-project/blktap
Revert "CA-139733: Stop vhd false alarm" to fix build.

This reverts commit f7db191b347c8a730cf816d752641a9f71bcbeb9.

Signed-off-by: Chandrika Srinivasan <chandrika.srinivasan@citrix.com>
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: support for write I/O barriers

This patch adds support for write I/O barriers. While write I/O barriers
are not strictly required for a guest VM to operate, lack thereof leads
to Linux guests crashing when live-migrating from a host that supports
barriers to one that does not.

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