CA-125489: Wait for the hotplug scripts before initialising

This patch addresses a race condition where the back-end switches to the
InitWait state too soon and the kernel thinks the hotplug script have
run. XAPI waits for these hotplug scripts to run, which never happens,
and the domain is never actually started. We address this issue by
ensuring that the back-end doesn't respond to front-end state changes
unless the hotplug-status XenStore key receives the value "connected".

Signed-off-by: Thanos Makatos <thanos.makatos@citrix.com>
Reviewed-by: Chandrika Srinivasan <chandrika.srinivasan@citrix.com>
CP-7398: Review core blktap3 changes

Signed-off-by: Thanos Makatos <thanos.makatos@citrix.com>
Reviewed-by: Chandrika Srinivasan <chandrika.srinivasan@citrix.com>
Reviewed-by: Keith Petley <keith.petley@citrix.com>
CP-7355: Set correct XenStore permissions

Signed-off-by: Thanos Makatos <thanos.makatos@citrix.com>
Acked-by: David Vrabel <david.vrabel@citrix.com>
CA-125605: Refuse to close VBD if there's a ring connection

Signed-off-by: Thanos Makatos <thanos.makatos@citrix.com>
Reviewed-by: Chandrika Srinivasan <chandrika.srinivasan@citrix.com>
CA-125867: Disconnect tapdisk from the ring on device removal

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

Signed-off-by: Thanos Makatos <thanos.makatos@citrix.com>
Reviewed-by: Chandrika Srinivasan <chandrika.srinivasan@citrix.com>
CA-125917: drain queue when closing

When tapdisk receives a CLOSE command, it must try to empty the ring request
queue, exactly as it does for the blktap2 request queue.

In addition, this patch introduces some minor code improvements.

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

Signed-off-by: Thanos Makatos <thanos.makatos@citrix.com>
Reviewed-by: Felipe Franciosi <felipe.franciosi@citrix.com>
CA-125917: fix drain queue when closing

tapdisk_control_close_image waits for the Xenbus to disconnect, but this
can never happen because only a tapdisk_control_xenblkif_disconnect
message can do this, and that cannot be executed because the current
tap-ctl close command is still pending. The solution is to have tap-ctl
close to try and disconnect from the ring if necessary.

Signed-off-by: Thanos Makatos <thanos.makatos@citrix.com>
Reviewed-by: Chandrika Srinivasan <chandrika.srinivasan@citrix.com>
CA-126092: Retry tap-ctl close till it succeeds or times out

If tapdisk is busy processing another command (like disconnect
from ring), an EBUSY status is sent back to the tap-ctl close
command. In this commit, we wait and retry the tap-ctl close
command till tapdisk responds. The wait is timed out at 120 seconds
which is tapdisk's timeout for command completion.

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

Periodic merge from blktap2 (https://github.com/xapi-project/blktap) to
ensure we're kept in sync.

Conflicts:
	.gitignore

Signed-off-by: Thanos Makatos <thanos.makatos@citrix.com>
CA-125978: drain Xenbus queue on ring disconnection

Signed-off-by: Thanos Makatos <thanos.makatos@citrix.com>
Reviewed-by: Chandrika Srinivasan <chandrika.srinivasan@citrix.com>
CA-126092: Refresh message structure before retrying tap-ctl close

Signed-off-by: Chandrika Srinivasan <chandrika.srinivasan@citrix.com>
Reviewed-by: Thanos Makatos <thanos.makatos@citrix.com>
CP-7356: Use revised grant-copy implementation

Signed-off-by: Thanos Makatos <thanos.makatos@citrix.com>
Reviewed-by: David Vrabel <david.vrabel@citrix.com>
CAR-96/CP-6171: Parametrise back-end name.

Parametrise the back-end name in tapback so it can coexist with blkback.

Signed-off-by: Thanos Makatos <thanos.makatos@citrix.com>
Reviewed-by: Chandrika Srinivasan <chandrika.srinivasan@citrix.com>
CAR-96/CA-127467: Retry pause/unpause on EBUSY

Signed-off-by: Thanos Makatos <thanos.makatos@citrix.com>
Reviewed-by: Chandrika Srinivasan <chandrika.srinivasan@citrix.com>
CAR-96: Use correct sign when reporting tap-ctl-open errors

Signed-off-by: Thanos Makatos <thanos.makatos@citrix.com>
CAR-96/CA-126139: Add checks when reading XenStore watch

This patch won't fix the bug in CA-126139, but it might help debugging.

Signed-off-by: Thanos Makatos <thanos.makatos@citrix.com>
CAR-96/CA-127667: warn when disconnecting paused VBD with pending reqs

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