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-142603: don't delete old tapdisk logs

Don't delete old tapdisk logs as this is already done by
/opt/xensource/bin/delete_old_logs_by_space.

Signed-off-by: Thanos Makatos <thanos.makatos@citrix.com>
Reviewed-by: Mate Lakat <mate.lakat@citrix.com>
CA-142603: use correct tapdisk log rotation rules

Rotation of logs is performed by /opt/xensource/bin/rotate_logs_by_size
(and not by logrotate itself) and the rules for that are specified in
/etc/logrotate-xenserver.conf. That configuration files contains
contains the wrong rule for blktap (it doesn't send the HUP signal).
Also, we already specify a logrotate configuration file in
/etc/logrotate.d/blktap which was never used.

This patch includes it in /etc/logrotate-xenserver.conf. Also, log
size, log age, and other options must come from
/etc/logrotate-xenserver.conf itself so they are removed from
/etc/logrotate.d/blktap.

Signed-off-by: Thanos Makatos <thanos.makatos@citrix.com>
Reviewed-by: Mate Lakat <mate.lakat@citrix.com>
Merge branch 'CA-142603' into xs64bit

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

GitHub: closes #120 on xapi-project/blktap
CA-138629: install bugtool rules for tapdisk

Signed-off-by: Thanos Makatos <thanos.makatos@citrix.com>
Reviewed-by: Siddharth Vinothkumar <siddharth.vinothkumar@citrix.com>

GitHub: closes #119 on xapi-project/blktap
CA-136792: produce blkback-style stats

Produce I/O statistics in /dev/shm/vbd3-domid-devid. We use one file for
all seven counters as otherwise we're wasting too much memory. Stats are
updated once every five seconds as this is the same frequency the RRD
script reads this file.

Read/write latency stats are produced in
/dev/shm/vbd3-<domid>-<devid>/statistics along with the other stats, in
order to avoid using a separate file as this consumes additional memory
and we're already under heavy pressure to minimise tapdisk's memory
footprint.

In blkback, rd_usecs/wr_usecs stats are cleared each time the sysfs file
is read. In tapdisk it's impossible to tell when the file got read,
therefore we reset these stats right after updating /dev/shm.

Signed-off-by: Thanos Makatos <thanos.makatos@citrix.com>
Reviewed-by: Siddharth Vinothkumar <siddharth.vinothkumar@citrix.com>

GitHub: closes #97 on xapi-project/blktap
CA-136792: produce raw stats

Signed-off-by: Thanos Makatos <thanos.makatos@citrix.com>
CA-136792: make stats definition public

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