CA-128503: remove erroneous ASSERTs

Signed-off-by: Thanos Makatos <thanos.makatos@citrix.com>
Reviewed-by: Chandrika Srinivasan <chandrika.srinivasan@citrix.com>
CA-128503: use size of structure instead size of ptr for memcpy

Signed-off-by: Thanos Makatos <thanos.makatos@citrix.com>
Reviewed-by: Chandrika Srinivasan <chandrika.srinivasan@citrix.com>
CA-128503: don't use memory after free

Signed-off-by: Thanos Makatos <thanos.makatos@citrix.com>
Reviewed-by: Chandrika Srinivasan <chandrika.srinivasan@citrix.com>
CA-128503: rationalise error code sign

Signed-off-by: Thanos Makatos <thanos.makatos@citrix.com>
Reviewed-by: Chandrika Srinivasan <chandrika.srinivasan@citrix.com>
CA-128503: sanitise input from XenStore

Signed-off-by: Thanos Makatos <thanos.makatos@citrix.com>
Reviewed-by: Chandrika Srinivasan <chandrika.srinivasan@citrix.com>
CA-128503: don't use uninitialised variable

Signed-off-by: Thanos Makatos <thanos.makatos@citrix.com>
Reviewed-by: Chandrika Srinivasan <chandrika.srinivasan@citrix.com>
CA-128503: don't pass -ve to strerror for reporting gcopy errors

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

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

GitHub: closes #77 on xapi-project/blktap
CA-130606: move PAGE_XXX symbols into libtapdisk

Symbols PAGE_MASK, PAGE_SIZE, and PAGE_SHIFT are defined in tapdisk2.c
which is not compiled into libtapdisk, hence these symbols do not get
defined in the library and that obviously doesn't link.

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

GitHub: closes #78 on xapi-project/blktap
CA-128872: suspend ring operation on VBD pause

Pausing the VBD without suspending the operation of the ring leads to
requests being extracted from the ring but not being submitted as the
VBD is paused. The problem in that behaviour is that in SXM tapdisk is
paused before it is closed, so there are requests trapped in tapdisk.
Suspending the operation of the ring when pausing the VBD ensures the
ring is flushed and no requests are extracted from the ring while the
VBD is paused.

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

GitHub: closes #76 on xapi-project/blktap
CP-7800: revert fixes for tap-ctl race conditions

This revert the commits that fix the tap-ctl race conditions use retries
and timeouts, as that issue is properly fixed by CP-7800. The following
commits are reverted:
 * 0e3b72eb: "CAR-96/CA-128039: don't use uninitialised vars when checking for
             timeout"
 * 0e3dee2d: "CAR-96/CA-128039: don't check error field if for disk_info"
 * 7a99303a: "CAR-96/CA-128039: retry tap-ctl-info on EBUSY"
 * 9a9ca3b4: "CAR-96/CA-128039: correctly set error code when timing out"
 * a0046e5f: "CAR-96/CA-128039: retry connect to/disconnect from on EBUSY"
 * da6784c5: "CAR-96/CA-128039: fix tap_ctl_connect/disconnect_xenblkif error
              handling"
 * e1816cea: "Revert "CAR-96/CA-7800: mask conflicting commands instead of
             retrying""
 * ad30ba6b: "CAR-96/CA-7800: mask conflicting commands instead of retrying"

Signed-off-by: Thanos Makatos <thanos.makatos@citrix.com>
Reviewed-by: Chandrika Srinivasan <chandrika.srinivasan@citrix.com>
CP-7800: Include PID in tap-ctl log messages

This is not directly related to fixing the issue, but while debugging
the bug (using multiple, concurrent tap-ctl commands) we ran into the problem
of not being able to tell which tap-ctl is which.

Signed-off-by: Thanos Makatos <thanos.makatos@citrix.com>
Reviewed-by: Chandrika Srinivasan <chandrika.srinivasan@citrix.com>
CP-7800: mask conflicting commands instead of retrying

The Storage Manager and tapback might concurrently issue exclusive
commands to tapdisk. tapdisk is not designed to handle concurrent
commands and if this occurs it fails the other command with EBUSY. We
address this issue by masking the event associated with the command that
would be rejecting while tapdisk is busy servicing the first command, and
unmasking it when the first command has finished.

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

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

GitHub: closes #73 on xapi-project/blktap
CA-128035: don't probe all domains unnecessarily

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

GitHub: closes #74 on xapi-project/blktap
CP-8081: fix 64-bit build error

Minor changes (mostly printf format specifiers) due to slightly
different types in 64-bit build.

Signed-off-by: David Vrabel <david.vrabel@citrix.com>
Reviewed-by: Thanos Makatos <thanos.makatos@citrix.com>

GitHub: closes #75 on xapi-project/blktap
CA-136104: Adding better kernel version detection: http://lists.xen.org/archives/html/xen-devel/2013-12/msg01185.html

This prevents the failing on the call to io_setup with EINVAL. Tapdisk
currently detects kernel version for eventfd by looking for 'x.y.z',
which fails on the newer kernel versions.

Credit goes to James Harper from
http://lists.xen.org/archives/html/xen-devel/2013-12/msg01185.html

Signed-off-by: Antony Messerli <antony@mes.ser.li>
Reviewed-by: Thanos Makatos <thanos.makatos@citrix.com>

GitHub: closes #79 on xapi-project/blktap
CA-130898: use 32-bit protocol with guest if omitted

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

(cherry picked from commit 6c86a979700ca4ff1e16fdcc44b3ff2ea4baddda)

GitHub: closes #84 on xapi-project/blktap