diff options
author | Daniel De Graaf <dgdegra@tycho.nsa.gov> | 2011-01-06 16:28:43 -0500 |
---|---|---|
committer | Daniel De Graaf <dgdegra@tycho.nsa.gov> | 2011-01-06 16:28:43 -0500 |
commit | 8f3f9c00b2a9a21f5f984c77d14ce37035949653 (patch) | |
tree | 4cc5dab27a0f3e8aa31bbe3d7b14274cf673a385 | |
parent | ead1f8185140252f07b0006e5882aa54f5ca08c2 (diff) |
Add VCHAN_DEBUG for strace debugging of vchan apps
-rw-r--r-- | vchan/io.c | 22 |
1 files changed, 22 insertions, 0 deletions
@@ -25,6 +25,10 @@ #include <sys/ioctl.h> #include <unistd.h> +// allow vchan data to be easily observed in strace() by doing a +// writev() to FD -1 with the data being read/written. +#define VCHAN_DEBUG 1 + static uint32_t rd_prod(struct libvchan *ctrl) { return ctrl->read.shr->prod; @@ -102,6 +106,15 @@ static int do_send(struct libvchan *ctrl, const void *data, size_t size) { int real_idx = wr_prod(ctrl) & (wr_ring_size(ctrl) - 1); int avail_contig = wr_ring_size(ctrl) - real_idx; + if (VCHAN_DEBUG) { + char metainfo[32]; + struct iovec iov[2]; + iov[0].iov_base = metainfo; + iov[0].iov_len = snprintf(metainfo, 32, "vchan wr %d/%d", ctrl->other_domain_id, ctrl->device_number); + iov[1].iov_base = data; + iov[1].iov_len = size; + writev(-1, iov, 2); + } if (avail_contig > size) avail_contig = size; memcpy(wr_ring(ctrl) + real_idx, data, avail_contig); @@ -148,6 +161,15 @@ static int do_recv(struct libvchan *ctrl, void *data, size_t size) memcpy(data + avail_contig, rd_ring(ctrl), size - avail_contig); } rd_cons(ctrl) += size; + if (VCHAN_DEBUG) { + char metainfo[32]; + struct iovec iov[2]; + iov[0].iov_base = metainfo; + iov[0].iov_len = snprintf(metainfo, 32, "vchan rd %d/%d", ctrl->other_domain_id, ctrl->device_number); + iov[1].iov_base = data; + iov[1].iov_len = size; + writev(-1, iov, 2); + } if (do_notify(ctrl) < 0) return -1; return size; |