aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Levon <john.levon@nutanix.com>2021-02-05 11:23:39 +0000
committerGitHub <noreply@github.com>2021-02-05 11:23:39 +0000
commit687f2a333d7dd0aeed741c2781dd6ef151a22040 (patch)
treea4c70fb3d56df688ffad0f0eace143f6fe776652
parentd4055f08f2a2db79b080afd6483ff6b4b558c2b2 (diff)
downloadlibvfio-user-687f2a333d7dd0aeed741c2781dd6ef151a22040.zip
libvfio-user-687f2a333d7dd0aeed741c2781dd6ef151a22040.tar.gz
libvfio-user-687f2a333d7dd0aeed741c2781dd6ef151a22040.tar.bz2
use tran_sock_*() namespace (#308)
Rename (again!) all internal tran_sock APIs so it's very clear which cases are directly using them, perhaps when they shouldn't. Signed-off-by: John Levon <john.levon@nutanix.com> Reviewed-by: Thanos Makatos <thanos.makatos@nutanix.com>
-rw-r--r--lib/irq.c8
-rw-r--r--lib/libvfio-user.c19
-rw-r--r--lib/tran_sock.c132
-rw-r--r--lib/tran_sock.h83
-rw-r--r--samples/client.c108
-rw-r--r--test/CMakeLists.txt2
-rw-r--r--test/mocks.c10
-rw-r--r--test/unit-tests.c22
8 files changed, 194 insertions, 190 deletions
diff --git a/lib/irq.c b/lib/irq.c
index 0410926..36d7346 100644
--- a/lib/irq.c
+++ b/lib/irq.c
@@ -427,10 +427,10 @@ vfu_irq_message(vfu_ctx_t *vfu_ctx, uint32_t subindex)
}
irq_info.subindex = subindex;
- ret = vfu_msg(vfu_ctx->conn_fd, msg_id,
- VFIO_USER_VM_INTERRUPT,
- &irq_info, sizeof irq_info,
- NULL, NULL, 0);
+ ret = tran_sock_msg(vfu_ctx->conn_fd, msg_id,
+ VFIO_USER_VM_INTERRUPT,
+ &irq_info, sizeof irq_info,
+ NULL, NULL, 0);
if (ret < 0) {
/* FIXME should return -errno */
errno = -ret;
diff --git a/lib/libvfio-user.c b/lib/libvfio-user.c
index fce7923..98ddef3 100644
--- a/lib/libvfio-user.c
+++ b/lib/libvfio-user.c
@@ -932,8 +932,9 @@ process_request(vfu_ctx_t *vfu_ctx)
if (!(hdr.flags.no_reply)) {
// FIXME: SPEC: should the reply include the command? I'd say yes?
- ret = vfu_send_iovec(vfu_ctx->conn_fd, hdr.msg_id, true,
- 0, iovecs, nr_iovecs, fds_out, nr_fds_out, -ret);
+ ret = tran_sock_send_iovec(vfu_ctx->conn_fd, hdr.msg_id, true, 0,
+ iovecs, nr_iovecs, fds_out, nr_fds_out,
+ -ret);
if (unlikely(ret < 0)) {
vfu_log(vfu_ctx, LOG_ERR, "failed to complete command: %s",
strerror(-ret));
@@ -1149,7 +1150,7 @@ vfu_create_ctx(vfu_trans_t trans, const char *path, int flags, void *pvt,
vfu_ctx->fd = -1;
vfu_ctx->conn_fd = -1;
vfu_ctx->dev_type = dev_type;
- vfu_ctx->trans = &sock_transport_ops;
+ vfu_ctx->trans = &tran_sock_ops;
vfu_ctx->pvt = pvt;
vfu_ctx->flags = flags;
vfu_ctx->log_level = LOG_ERR;
@@ -1444,9 +1445,9 @@ vfu_dma_read(vfu_ctx_t *vfu_ctx, dma_sg_t *sg, void *data)
dma_send.addr = sg->dma_addr;
dma_send.count = sg->length;
- ret = vfu_msg(vfu_ctx->conn_fd, msg_id, VFIO_USER_DMA_READ,
- &dma_send, sizeof dma_send, NULL,
- dma_recv, recv_size);
+ ret = tran_sock_msg(vfu_ctx->conn_fd, msg_id, VFIO_USER_DMA_READ,
+ &dma_send, sizeof dma_send, NULL,
+ dma_recv, recv_size);
memcpy(data, dma_recv->data, sg->length); /* FIXME no need for memcpy */
free(dma_recv);
@@ -1470,9 +1471,9 @@ vfu_dma_write(vfu_ctx_t *vfu_ctx, dma_sg_t *sg, void *data)
dma_send->addr = sg->dma_addr;
dma_send->count = sg->length;
memcpy(dma_send->data, data, sg->length); /* FIXME no need to copy! */
- ret = vfu_msg(vfu_ctx->conn_fd, msg_id, VFIO_USER_DMA_WRITE,
- dma_send, send_size, NULL,
- &dma_recv, sizeof(dma_recv));
+ ret = tran_sock_msg(vfu_ctx->conn_fd, msg_id, VFIO_USER_DMA_WRITE,
+ dma_send, send_size, NULL,
+ &dma_recv, sizeof(dma_recv));
free(dma_send);
return ret;
diff --git a/lib/tran_sock.c b/lib/tran_sock.c
index aadbdd2..fe54736 100644
--- a/lib/tran_sock.c
+++ b/lib/tran_sock.c
@@ -71,7 +71,7 @@ recv_blocking(int sock, void *buf, size_t len, int flags)
}
static int
-init_sock(vfu_ctx_t *vfu_ctx)
+tran_sock_init(vfu_ctx_t *vfu_ctx)
{
struct sockaddr_un addr = { .sun_family = AF_UNIX };
int ret, unix_sock;
@@ -128,10 +128,10 @@ out:
}
int
-vfu_send_iovec(int sock, uint16_t msg_id, bool is_reply,
- enum vfio_user_command cmd,
- struct iovec *iovecs, size_t nr_iovecs,
- int *fds, int count, int err)
+tran_sock_send_iovec(int sock, uint16_t msg_id, bool is_reply,
+ enum vfio_user_command cmd,
+ struct iovec *iovecs, size_t nr_iovecs,
+ int *fds, int count, int err)
{
int ret;
struct vfio_user_header hdr = {.msg_id = msg_id};
@@ -195,9 +195,9 @@ vfu_send_iovec(int sock, uint16_t msg_id, bool is_reply,
}
int
-vfu_send(int sock, uint16_t msg_id, bool is_reply,
- enum vfio_user_command cmd,
- void *data, size_t data_len)
+tran_sock_send(int sock, uint16_t msg_id, bool is_reply,
+ enum vfio_user_command cmd,
+ void *data, size_t data_len)
{
/* [0] is for the header. */
struct iovec iovecs[2] = {
@@ -206,16 +206,17 @@ vfu_send(int sock, uint16_t msg_id, bool is_reply,
.iov_len = data_len
}
};
- return vfu_send_iovec(sock, msg_id, is_reply, cmd, iovecs,
- ARRAY_SIZE(iovecs), NULL, 0, 0);
+ return tran_sock_send_iovec(sock, msg_id, is_reply, cmd, iovecs,
+ ARRAY_SIZE(iovecs), NULL, 0, 0);
}
int
-vfu_send_error(int sock, uint16_t msg_id,
+tran_sock_send_error(int sock, uint16_t msg_id,
enum vfio_user_command cmd,
int error)
{
- return vfu_send_iovec(sock, msg_id, true, cmd, NULL, 0, NULL, 0, error);
+ return tran_sock_send_iovec(sock, msg_id, true, cmd,
+ NULL, 0, NULL, 0, error);
}
static int
@@ -274,9 +275,9 @@ get_msg(void *data, size_t len, int *fds, size_t *nr_fds, int sock_fd,
* better.
*/
int
-vfu_recv_fds(int sock, struct vfio_user_header *hdr, bool is_reply,
- uint16_t *msg_id, void *data, size_t *len, int *fds,
- size_t *nr_fds)
+tran_sock_recv_fds(int sock, struct vfio_user_header *hdr, bool is_reply,
+ uint16_t *msg_id, void *data, size_t *len, int *fds,
+ size_t *nr_fds)
{
int ret;
@@ -329,26 +330,27 @@ vfu_recv_fds(int sock, struct vfio_user_header *hdr, bool is_reply,
}
int
-vfu_recv(int sock, struct vfio_user_header *hdr, bool is_reply,
+tran_sock_recv(int sock, struct vfio_user_header *hdr, bool is_reply,
uint16_t *msg_id, void *data, size_t *len)
{
- return vfu_recv_fds(sock, hdr, is_reply, msg_id, data, len, NULL, NULL);
+ return tran_sock_recv_fds(sock, hdr, is_reply, msg_id,
+ data, len, NULL, NULL);
}
/*
- * Like vfu_recv(), but will automatically allocate reply data.
+ * Like tran_sock_recv(), but will automatically allocate reply data.
*
* FIXME: this does an unconstrained alloc of client-supplied data.
*/
int
-vfu_recv_alloc(int sock, struct vfio_user_header *hdr, bool is_reply,
- uint16_t *msg_id, void **datap, size_t *lenp)
+tran_sock_recv_alloc(int sock, struct vfio_user_header *hdr, bool is_reply,
+ uint16_t *msg_id, void **datap, size_t *lenp)
{
void *data;
size_t len;
int ret;
- ret = vfu_recv(sock, hdr, is_reply, msg_id, NULL, NULL);
+ ret = tran_sock_recv(sock, hdr, is_reply, msg_id, NULL, NULL);
if (ret != 0) {
return ret;
@@ -391,31 +393,31 @@ vfu_recv_alloc(int sock, struct vfio_user_header *hdr, bool is_reply,
* messages.
*/
int
-vfu_msg_iovec(int sock, uint16_t msg_id, enum vfio_user_command cmd,
- struct iovec *iovecs, size_t nr_iovecs,
- int *send_fds, size_t send_fd_count,
- struct vfio_user_header *hdr,
- void *recv_data, size_t recv_len,
- int *recv_fds, size_t *recv_fd_count)
+tran_sock_msg_iovec(int sock, uint16_t msg_id, enum vfio_user_command cmd,
+ struct iovec *iovecs, size_t nr_iovecs,
+ int *send_fds, size_t send_fd_count,
+ struct vfio_user_header *hdr,
+ void *recv_data, size_t recv_len,
+ int *recv_fds, size_t *recv_fd_count)
{
- int ret = vfu_send_iovec(sock, msg_id, false, cmd, iovecs, nr_iovecs,
- send_fds, send_fd_count, 0);
+ int ret = tran_sock_send_iovec(sock, msg_id, false, cmd, iovecs, nr_iovecs,
+ send_fds, send_fd_count, 0);
if (ret < 0) {
return ret;
}
if (hdr == NULL) {
hdr = alloca(sizeof *hdr);
}
- return vfu_recv_fds(sock, hdr, true, &msg_id, recv_data, &recv_len,
- recv_fds, recv_fd_count);
+ return tran_sock_recv_fds(sock, hdr, true, &msg_id, recv_data, &recv_len,
+ recv_fds, recv_fd_count);
}
int
-vfu_msg_fds(int sock, uint16_t msg_id, enum vfio_user_command cmd,
- void *send_data, size_t send_len,
- struct vfio_user_header *hdr,
- void *recv_data, size_t recv_len, int *recv_fds,
- size_t *recv_fd_count)
+tran_sock_msg_fds(int sock, uint16_t msg_id, enum vfio_user_command cmd,
+ void *send_data, size_t send_len,
+ struct vfio_user_header *hdr,
+ void *recv_data, size_t recv_len, int *recv_fds,
+ size_t *recv_fd_count)
{
/* [0] is for the header. */
struct iovec iovecs[2] = {
@@ -424,19 +426,19 @@ vfu_msg_fds(int sock, uint16_t msg_id, enum vfio_user_command cmd,
.iov_len = send_len
}
};
- return vfu_msg_iovec(sock, msg_id, cmd, iovecs, ARRAY_SIZE(iovecs),
- NULL, 0, hdr, recv_data, recv_len, recv_fds,
- recv_fd_count);
+ return tran_sock_msg_iovec(sock, msg_id, cmd, iovecs, ARRAY_SIZE(iovecs),
+ NULL, 0, hdr, recv_data, recv_len, recv_fds,
+ recv_fd_count);
}
int
-vfu_msg(int sock, uint16_t msg_id, enum vfio_user_command cmd,
- void *send_data, size_t send_len,
- struct vfio_user_header *hdr,
- void *recv_data, size_t recv_len)
+tran_sock_msg(int sock, uint16_t msg_id, enum vfio_user_command cmd,
+ void *send_data, size_t send_len,
+ struct vfio_user_header *hdr,
+ void *recv_data, size_t recv_len)
{
- return vfu_msg_fds(sock, msg_id, cmd, send_data, send_len, hdr, recv_data,
- recv_len, NULL, NULL);
+ return tran_sock_msg_fds(sock, msg_id, cmd, send_data, send_len, hdr,
+ recv_data, recv_len, NULL, NULL);
}
/*
@@ -455,8 +457,8 @@ vfu_msg(int sock, uint16_t msg_id, enum vfio_user_command cmd,
* available in newer library versions, so we don't use it.
*/
int
-vfu_parse_version_json(const char *json_str,
- int *client_max_fdsp, size_t *pgsizep)
+tran_parse_version_json(const char *json_str,
+ int *client_max_fdsp, size_t *pgsizep)
{
struct json_object *jo_caps = NULL;
struct json_object *jo_top = NULL;
@@ -529,8 +531,8 @@ recv_version(vfu_ctx_t *vfu_ctx, int sock, uint16_t *msg_idp,
*versionp = NULL;
- ret = vfu_recv_alloc(sock, &hdr, false, msg_idp,
- (void **)&cversion, &vlen);
+ ret = tran_sock_recv_alloc(sock, &hdr, false, msg_idp,
+ (void **)&cversion, &vlen);
if (ret < 0) {
vfu_log(vfu_ctx, LOG_ERR, "failed to receive version: %s",
@@ -572,8 +574,8 @@ recv_version(vfu_ctx_t *vfu_ctx, int sock, uint16_t *msg_idp,
goto out;
}
- ret = vfu_parse_version_json(json_str, &vfu_ctx->client_max_fds,
- &pgsize);
+ ret = tran_parse_version_json(json_str, &vfu_ctx->client_max_fds,
+ &pgsize);
if (ret < 0) {
/* No client-supplied strings in the log for release build. */
@@ -609,7 +611,7 @@ recv_version(vfu_ctx_t *vfu_ctx, int sock, uint16_t *msg_idp,
out:
if (ret != 0) {
// FIXME: spec, is it OK to just have the header?
- (void) vfu_send_error(sock, *msg_idp, hdr.cmd, ret);
+ (void) tran_sock_send_error(sock, *msg_idp, hdr.cmd, ret);
free(cversion);
cversion = NULL;
}
@@ -658,8 +660,8 @@ send_version(vfu_ctx_t *vfu_ctx, int sock, uint16_t msg_id,
/* Include the NUL. */
iovecs[2].iov_len = slen + 1;
- return vfu_send_iovec(sock, msg_id, true, VFIO_USER_VERSION,
- iovecs, ARRAY_SIZE(iovecs), NULL, 0, 0);
+ return tran_sock_send_iovec(sock, msg_id, true, VFIO_USER_VERSION,
+ iovecs, ARRAY_SIZE(iovecs), NULL, 0, 0);
}
static int
@@ -688,7 +690,7 @@ negotiate(vfu_ctx_t *vfu_ctx, int sock)
}
static int
-open_sock(vfu_ctx_t *vfu_ctx)
+tran_sock_attach(vfu_ctx_t *vfu_ctx)
{
int ret;
int conn_fd;
@@ -711,8 +713,8 @@ open_sock(vfu_ctx_t *vfu_ctx)
}
static int
-get_request_sock(vfu_ctx_t *vfu_ctx, struct vfio_user_header *hdr,
- int *fds, size_t *nr_fds)
+tran_sock_get_request(vfu_ctx_t *vfu_ctx, struct vfio_user_header *hdr,
+ int *fds, size_t *nr_fds)
{
int sock_flags = 0;
@@ -728,7 +730,7 @@ get_request_sock(vfu_ctx_t *vfu_ctx, struct vfio_user_header *hdr,
}
static void
-detach_sock(vfu_ctx_t *vfu_ctx)
+tran_sock_detach(vfu_ctx_t *vfu_ctx)
{
if (vfu_ctx->conn_fd != -1) {
(void) close(vfu_ctx->conn_fd);
@@ -737,7 +739,7 @@ detach_sock(vfu_ctx_t *vfu_ctx)
}
static void
-fini_sock(vfu_ctx_t *vfu_ctx)
+tran_sock_fini(vfu_ctx_t *vfu_ctx)
{
if (vfu_ctx->fd != -1) {
(void) close(vfu_ctx->fd);
@@ -745,12 +747,12 @@ fini_sock(vfu_ctx_t *vfu_ctx)
}
}
-struct transport_ops sock_transport_ops = {
- .init = init_sock,
- .attach = open_sock,
- .get_request = get_request_sock,
- .detach = detach_sock,
- .fini = fini_sock,
+struct transport_ops tran_sock_ops = {
+ .init = tran_sock_init,
+ .attach = tran_sock_attach,
+ .get_request = tran_sock_get_request,
+ .detach = tran_sock_detach,
+ .fini = tran_sock_fini
};
/* ex: set tabstop=4 shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/lib/tran_sock.h b/lib/tran_sock.h
index c4ed30c..9b37776 100644
--- a/lib/tran_sock.h
+++ b/lib/tran_sock.h
@@ -46,41 +46,40 @@
// FIXME: value?
#define VFIO_USER_CLIENT_MAX_FDS_LIMIT (1024)
-extern struct transport_ops sock_transport_ops;
+extern struct transport_ops tran_sock_ops;
/*
* Parse JSON supplied from the other side into the known parameters. Note: they
* will not be set if not found in the JSON.
*/
int
-vfu_parse_version_json(const char *json_str, int *client_max_fdsp,
- size_t *pgsizep);
+tran_parse_version_json(const char *json_str, int *client_max_fdsp,
+ size_t *pgsizep);
/*
* Send a message to the other end. The iovecs array should leave the first
* entry empty, as it will be used for the header.
*/
int
-vfu_send_iovec(int sock, uint16_t msg_id, bool is_reply,
- enum vfio_user_command cmd,
- struct iovec *iovecs, size_t nr_iovecs,
- int *fds, int count,
- int err);
+tran_sock_send_iovec(int sock, uint16_t msg_id, bool is_reply,
+ enum vfio_user_command cmd,
+ struct iovec *iovecs, size_t nr_iovecs,
+ int *fds, int count,
+ int err);
/*
* Send a message to the other end with the given data.
*/
int
-vfu_send(int sock, uint16_t msg_id, bool is_reply, enum vfio_user_command cmd,
- void *data, size_t data_len);
+tran_sock_send(int sock, uint16_t msg_id, bool is_reply,
+ enum vfio_user_command cmd, void *data, size_t data_len);
/*
* Send an empty reply back to the other end with the given errno.
*/
int
-vfu_send_error(int sock, uint16_t msg_id,
- enum vfio_user_command cmd,
- int error);
+tran_sock_send_error(int sock, uint16_t msg_id,
+ enum vfio_user_command cmd, int error);
/*
* Receive a message from the other end, and place the data into the given
@@ -88,17 +87,17 @@ vfu_send_error(int sock, uint16_t msg_id,
* size.
*/
int
-vfu_recv(int sock, struct vfio_user_header *hdr, bool is_reply,
- uint16_t *msg_id, void *data, size_t *len);
+tran_sock_recv(int sock, struct vfio_user_header *hdr, bool is_reply,
+ uint16_t *msg_id, void *data, size_t *len);
/*
- * Same as vfu_recv except it receives passed file descriptors. See vfu_msg on
- * the semantics of @fds and @nr_fds.
+ * Same as tran_sock_recv except it receives passed file descriptors. See
+ * tran_sock_msg on the semantics of @fds and @nr_fds.
*/
int
-vfu_recv_fds(int sock, struct vfio_user_header *hdr, bool is_reply,
- uint16_t *msg_id, void *data, size_t *len, int *fds,
- size_t *nr_fds);
+tran_sock_recv_fds(int sock, struct vfio_user_header *hdr, bool is_reply,
+ uint16_t *msg_id, void *data, size_t *len, int *fds,
+ size_t *nr_fds);
/*
* Receive a message from the other end, but automatically allocate a buffer for
@@ -106,8 +105,8 @@ vfu_recv_fds(int sock, struct vfio_user_header *hdr, bool is_reply,
* NULL.
*/
int
-vfu_recv_alloc(int sock, struct vfio_user_header *hdr, bool is_reply,
- uint16_t *msg_id, void **datap, size_t *lenp);
+tran_sock_recv_alloc(int sock, struct vfio_user_header *hdr, bool is_reply,
+ uint16_t *msg_id, void **datap, size_t *lenp);
/*
* Send and receive a message to the other end, using iovecs for the send. The
@@ -126,36 +125,36 @@ vfu_recv_alloc(int sock, struct vfio_user_header *hdr, bool is_reply,
* original value of @recv_fd_count.
*/
int
-vfu_msg_iovec(int sock, uint16_t msg_id,
- enum vfio_user_command cmd,
- struct iovec *iovecs, size_t nr_iovecs,
- int *send_fds, size_t send_fd_count,
- struct vfio_user_header *hdr,
- void *recv_data, size_t recv_len,
- int *recv_fds, size_t *recv_fd_count);
+tran_sock_msg_iovec(int sock, uint16_t msg_id,
+ enum vfio_user_command cmd,
+ struct iovec *iovecs, size_t nr_iovecs,
+ int *send_fds, size_t send_fd_count,
+ struct vfio_user_header *hdr,
+ void *recv_data, size_t recv_len,
+ int *recv_fds, size_t *recv_fd_count);
/*
* Send and receive a message to the other end. @hdr is filled with the reply
* header if non-NULL.
*/
int
-vfu_msg(int sock, uint16_t msg_id,
- enum vfio_user_command cmd,
- void *send_data, size_t send_len,
- struct vfio_user_header *hdr,
- void *recv_data, size_t recv_len);
+tran_sock_msg(int sock, uint16_t msg_id,
+ enum vfio_user_command cmd,
+ void *send_data, size_t send_len,
+ struct vfio_user_header *hdr,
+ void *recv_data, size_t recv_len);
/*
- * Same as vfu_msg excecpt that file descriptors can be received, see
- * vfu_msg_iovec for the semantics of @recv_fds and @recv_fd_count.
+ * Same as tran_sock_msg excecpt that file descriptors can be received, see
+ * tran_sock_msg_iovec for the semantics of @recv_fds and @recv_fd_count.
*/
int
-vfu_msg_fds(int sock, uint16_t msg_id,
- enum vfio_user_command cmd,
- void *send_data, size_t send_len,
- struct vfio_user_header *hdr,
- void *recv_data, size_t recv_len,
- int *recv_fds, size_t *recv_fd_count);
+tran_sock_msg_fds(int sock, uint16_t msg_id,
+ enum vfio_user_command cmd,
+ void *send_data, size_t send_len,
+ struct vfio_user_header *hdr,
+ void *recv_data, size_t recv_len,
+ int *recv_fds, size_t *recv_fd_count);
#endif /* LIB_VFIO_USER_TRAN_SOCK_H */
diff --git a/samples/client.c b/samples/client.c
index 7952e7d..1030b7b 100644
--- a/samples/client.c
+++ b/samples/client.c
@@ -120,8 +120,8 @@ send_version(int sock)
/* Include the NUL. */
iovecs[2].iov_len = slen + 1;
- ret = vfu_send_iovec(sock, msg_id, false, VFIO_USER_VERSION,
- iovecs, ARRAY_SIZE(iovecs), NULL, 0, 0);
+ ret = tran_sock_send_iovec(sock, msg_id, false, VFIO_USER_VERSION,
+ iovecs, ARRAY_SIZE(iovecs), NULL, 0, 0);
if (ret < 0) {
err(EXIT_FAILURE, "failed to send client version message");
@@ -136,7 +136,8 @@ recv_version(int sock, int *server_max_fds, size_t *pgsize)
size_t vlen;
int ret;
- ret = vfu_recv_alloc(sock, &hdr, true, NULL, (void **)&sversion, &vlen);
+ ret = tran_sock_recv_alloc(sock, &hdr, true, NULL,
+ (void **)&sversion, &vlen);
if (ret < 0) {
errx(EXIT_FAILURE, "failed to receive version: %s", strerror(-ret));
@@ -178,7 +179,7 @@ recv_version(int sock, int *server_max_fds, size_t *pgsize)
errx(EXIT_FAILURE, "ignoring invalid JSON from server");
}
- ret = vfu_parse_version_json(json_str, server_max_fds, pgsize);
+ ret = tran_parse_version_json(json_str, server_max_fds, pgsize);
if (ret < 0) {
errx(EXIT_FAILURE, "failed to parse server JSON \"%s\"", json_str);
@@ -198,8 +199,8 @@ negotiate(int sock, int *server_max_fds, size_t *pgsize)
static void
send_device_reset(int sock)
{
- int ret = vfu_msg(sock, 1, VFIO_USER_DEVICE_RESET,
- NULL, 0, NULL, NULL, 0);
+ int ret = tran_sock_msg(sock, 1, VFIO_USER_DEVICE_RESET,
+ NULL, 0, NULL, NULL, 0);
if (ret < 0) {
errx(EXIT_FAILURE, "failed to reset device: %s\n", strerror(-ret));
}
@@ -250,9 +251,9 @@ static void
do_get_device_region_info(int sock, struct vfio_region_info *region_info,
int *fds, size_t *nr_fds)
{
- int ret = vfu_msg_fds(sock, 0xabcd, VFIO_USER_DEVICE_GET_REGION_INFO,
- region_info, region_info->argsz, NULL,
- region_info, region_info->argsz, fds, nr_fds);
+ int ret = tran_sock_msg_fds(sock, 0xabcd, VFIO_USER_DEVICE_GET_REGION_INFO,
+ region_info, region_info->argsz, NULL,
+ region_info, region_info->argsz, fds, nr_fds);
if (ret < 0) {
errx(EXIT_FAILURE, "failed to get device region info: %s",
strerror(-ret));
@@ -367,11 +368,11 @@ get_device_info(int sock, struct vfio_device_info *dev_info)
dev_info->argsz = sizeof(*dev_info);
- ret = vfu_msg(sock, msg_id,
- VFIO_USER_DEVICE_GET_INFO,
- dev_info, sizeof(*dev_info),
- NULL,
- dev_info, sizeof(*dev_info));
+ ret = tran_sock_msg(sock, msg_id,
+ VFIO_USER_DEVICE_GET_INFO,
+ dev_info, sizeof(*dev_info),
+ NULL,
+ dev_info, sizeof(*dev_info));
if (ret < 0) {
errx(EXIT_FAILURE, "failed to get device info: %s", strerror(-ret));
@@ -400,11 +401,11 @@ configure_irqs(int sock)
.argsz = sizeof vfio_irq_info,
.index = i
};
- ret = vfu_msg(sock, msg_id,
- VFIO_USER_DEVICE_GET_IRQ_INFO,
- &vfio_irq_info, sizeof vfio_irq_info,
- NULL,
- &vfio_irq_info, sizeof vfio_irq_info);
+ ret = tran_sock_msg(sock, msg_id,
+ VFIO_USER_DEVICE_GET_IRQ_INFO,
+ &vfio_irq_info, sizeof vfio_irq_info,
+ NULL,
+ &vfio_irq_info, sizeof vfio_irq_info);
if (ret < 0) {
errx(EXIT_FAILURE, "failed to get %s info: %s", irq_to_str[i],
strerror(-ret));
@@ -431,10 +432,10 @@ configure_irqs(int sock)
iovecs[1].iov_base = &irq_set;
iovecs[1].iov_len = sizeof (irq_set);
- ret = vfu_msg_iovec(sock, msg_id, VFIO_USER_DEVICE_SET_IRQS,
- iovecs, ARRAY_SIZE(iovecs),
- &irq_fd, 1,
- NULL, NULL, 0, NULL, 0);
+ ret = tran_sock_msg_iovec(sock, msg_id, VFIO_USER_DEVICE_SET_IRQS,
+ iovecs, ARRAY_SIZE(iovecs),
+ &irq_fd, 1,
+ NULL, NULL, 0, NULL, 0);
if (ret < 0) {
errx(EXIT_FAILURE, "failed to send configure IRQs message: %s",
@@ -486,10 +487,10 @@ access_region(int sock, int region, bool is_write, uint64_t offset,
}
pthread_mutex_lock(&mutex);
- ret = vfu_msg_iovec(sock, msg_id--, op,
- send_iovecs, nr_send_iovecs,
- NULL, 0, NULL,
- recv_data, recv_data_len, NULL, 0);
+ ret = tran_sock_msg_iovec(sock, msg_id--, op,
+ send_iovecs, nr_send_iovecs,
+ NULL, 0, NULL,
+ recv_data, recv_data_len, NULL, 0);
pthread_mutex_unlock(&mutex);
if (ret != 0) {
warnx("failed to %s region %d %#lx-%#lx: %s",
@@ -507,7 +508,7 @@ access_region(int sock, int region, bool is_write, uint64_t offset,
}
/*
- * TODO we could avoid the memcpy if vfu_recv() received the
+ * TODO we could avoid the memcpy if tran_sock_msg_iovec() received the
* response into an iovec, but it's some work to implement it.
*/
if (!is_write) {
@@ -533,7 +534,8 @@ wait_for_irqs(int sock, int irq_fd)
printf("INTx triggered!\n");
size = sizeof(vfio_user_irq_info);
- ret = vfu_recv(sock, &hdr, false, &msg_id, &vfio_user_irq_info, &size);
+ ret = tran_sock_recv(sock, &hdr, false, &msg_id,
+ &vfio_user_irq_info, &size);
if (ret < 0) {
errx(EXIT_FAILURE, "failed to receive IRQ message: %s",
strerror(-ret));
@@ -548,7 +550,7 @@ wait_for_irqs(int sock, int irq_fd)
}
// Is a NULL iovec like this OK?
- ret = vfu_send(sock, msg_id, true, hdr.cmd, NULL, 0);
+ ret = tran_sock_send(sock, msg_id, true, hdr.cmd, NULL, 0);
if (ret < 0) {
errx(EXIT_FAILURE,
"failed to send reply for VFIO_USER_VM_INTERRUPT: %s",
@@ -591,7 +593,7 @@ handle_dma_write(int sock, struct vfio_user_dma_region *dma_regions,
uint16_t msg_id = 0xcafe;
void *data;
- ret = vfu_recv(sock, &hdr, false, &msg_id, &dma_access, &size);
+ ret = tran_sock_recv(sock, &hdr, false, &msg_id, &dma_access, &size);
if (ret < 0) {
errx(EXIT_FAILURE, "failed to receive DMA read: %s", strerror(-ret));
}
@@ -621,8 +623,8 @@ handle_dma_write(int sock, struct vfio_user_dma_region *dma_regions,
}
dma_access.count = 0;
- ret = vfu_send(sock, msg_id, true, VFIO_USER_DMA_WRITE,
- &dma_access, sizeof dma_access);
+ ret = tran_sock_send(sock, msg_id, true, VFIO_USER_DMA_WRITE,
+ &dma_access, sizeof dma_access);
if (ret < 0) {
errx(EXIT_FAILURE, "failed to send reply of DMA write: %s",
strerror(-ret));
@@ -641,7 +643,7 @@ handle_dma_read(int sock, struct vfio_user_dma_region *dma_regions,
uint16_t msg_id = 0xcafe;
void *data;
- ret = vfu_recv(sock, &hdr, false, &msg_id, &dma_access, &size);
+ ret = tran_sock_recv(sock, &hdr, false, &msg_id, &dma_access, &size);
if (ret < 0) {
errx(EXIT_FAILURE, "failed to recieve DMA read");
}
@@ -665,8 +667,8 @@ handle_dma_read(int sock, struct vfio_user_dma_region *dma_regions,
}
}
- ret = vfu_send(sock, msg_id, true, VFIO_USER_DMA_READ,
- response, response_sz);
+ ret = tran_sock_send(sock, msg_id, true, VFIO_USER_DMA_READ,
+ response, response_sz);
if (ret < 0) {
errx(EXIT_FAILURE, "failed to send reply of DMA write: %s",
strerror(-ret));
@@ -718,10 +720,10 @@ get_dirty_bitmaps(int sock, struct vfio_user_dma_region *dma_regions,
*/
dirty_bitmap.argsz = sizeof(dirty_bitmap) + ARRAY_SIZE(bitmaps) * sizeof(struct vfio_iommu_type1_dirty_bitmap_get);
dirty_bitmap.flags = VFIO_IOMMU_DIRTY_PAGES_FLAG_GET_BITMAP;
- ret = vfu_msg_iovec(sock, 0, VFIO_USER_DIRTY_PAGES,
- iovecs, ARRAY_SIZE(iovecs),
- NULL, 0,
- &hdr, data, ARRAY_SIZE(data), NULL, 0);
+ ret = tran_sock_msg_iovec(sock, 0, VFIO_USER_DIRTY_PAGES,
+ iovecs, ARRAY_SIZE(iovecs),
+ NULL, 0,
+ &hdr, data, ARRAY_SIZE(data), NULL, 0);
if (ret != 0) {
errx(EXIT_FAILURE, "failed to start dirty page logging: %s",
strerror(-ret));
@@ -1106,10 +1108,10 @@ map_dma_regions(int sock, int max_fds, struct vfio_user_dma_region *dma_regions,
iovecs[1].iov_base = dma_regions + (i * max_fds);
iovecs[1].iov_len = sizeof (*dma_regions) * max_fds;
- ret = vfu_msg_iovec(sock, 0x1234 + i, VFIO_USER_DMA_MAP,
- iovecs, ARRAY_SIZE(iovecs),
- dma_region_fds + (i * max_fds), max_fds,
- NULL, NULL, 0, NULL, 0);
+ ret = tran_sock_msg_iovec(sock, 0x1234 + i, VFIO_USER_DMA_MAP,
+ iovecs, ARRAY_SIZE(iovecs),
+ dma_region_fds + (i * max_fds), max_fds,
+ NULL, NULL, 0, NULL, 0);
if (ret < 0) {
errx(EXIT_FAILURE, "failed to map DMA regions: %s", strerror(-ret));
}
@@ -1235,9 +1237,9 @@ int main(int argc, char *argv[])
dirty_bitmap.argsz = sizeof dirty_bitmap;
dirty_bitmap.flags = VFIO_IOMMU_DIRTY_PAGES_FLAG_START;
- ret = vfu_msg(sock, 0, VFIO_USER_DIRTY_PAGES,
- &dirty_bitmap, sizeof dirty_bitmap,
- NULL, NULL, 0);
+ ret = tran_sock_msg(sock, 0, VFIO_USER_DIRTY_PAGES,
+ &dirty_bitmap, sizeof dirty_bitmap,
+ NULL, NULL, 0);
if (ret != 0) {
errx(EXIT_FAILURE, "failed to start dirty page logging: %s",
strerror(-ret));
@@ -1260,9 +1262,9 @@ int main(int argc, char *argv[])
dirty_bitmap.argsz = sizeof dirty_bitmap;
dirty_bitmap.flags = VFIO_IOMMU_DIRTY_PAGES_FLAG_STOP;
- ret = vfu_msg(sock, 0, VFIO_USER_DIRTY_PAGES,
- &dirty_bitmap, sizeof dirty_bitmap,
- NULL, NULL, 0);
+ ret = tran_sock_msg(sock, 0, VFIO_USER_DIRTY_PAGES,
+ &dirty_bitmap, sizeof dirty_bitmap,
+ NULL, NULL, 0);
if (ret != 0) {
errx(EXIT_FAILURE, "failed to stop dirty page logging: %s",
strerror(-ret));
@@ -1275,9 +1277,9 @@ int main(int argc, char *argv[])
*
* unmap the first group of the DMA regions
*/
- ret = vfu_msg(sock, 7, VFIO_USER_DMA_UNMAP,
- dma_regions, sizeof *dma_regions * server_max_fds,
- NULL, NULL, 0);
+ ret = tran_sock_msg(sock, 7, VFIO_USER_DMA_UNMAP,
+ dma_regions, sizeof *dma_regions * server_max_fds,
+ NULL, NULL, 0);
if (ret < 0) {
errx(EXIT_FAILURE, "failed to unmap DMA regions: %s", strerror(-ret));
}
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
index d51e153..2a339f0 100644
--- a/test/CMakeLists.txt
+++ b/test/CMakeLists.txt
@@ -50,7 +50,7 @@ target_link_libraries(unit-tests PUBLIC "-Wl,--wrap=device_is_stopped")
target_link_libraries(unit-tests PUBLIC "-Wl,--wrap=get_next_command")
target_link_libraries(unit-tests PUBLIC "-Wl,--wrap=exec_command")
target_link_libraries(unit-tests PUBLIC "-Wl,--wrap=close")
-target_link_libraries(unit-tests PUBLIC "-Wl,--wrap=vfu_send_iovec")
+target_link_libraries(unit-tests PUBLIC "-Wl,--wrap=tran_sock_send_iovec")
target_link_libraries(unit-tests PUBLIC "-Wl,--wrap=free")
target_link_libraries(unit-tests PUBLIC "-Wl,--wrap=process_request")
diff --git a/test/mocks.c b/test/mocks.c
index 7f7fc02..c38ec7b 100644
--- a/test/mocks.c
+++ b/test/mocks.c
@@ -129,10 +129,10 @@ __wrap_close(int fd)
}
int
-__wrap_vfu_send_iovec(int sock, uint16_t msg_id, bool is_reply,
- enum vfio_user_command cmd,
- struct iovec *iovecs, size_t nr_iovecs,
- int *fds, int count, int err)
+__wrap_tran_sock_send_iovec(int sock, uint16_t msg_id, bool is_reply,
+ enum vfio_user_command cmd,
+ struct iovec *iovecs, size_t nr_iovecs,
+ int *fds, int count, int err)
{
check_expected(sock);
check_expected(msg_id);
@@ -177,7 +177,7 @@ static struct function funcs[] = {
{.addr = &__wrap_get_next_command},
{.addr = &__wrap_exec_command},
{.addr = &__wrap_close},
- {.addr = &__wrap_vfu_send_iovec},
+ {.addr = &__wrap_tran_sock_send_iovec},
{.addr = &__wrap_free},
{.addr = &__wrap_process_request}
};
diff --git a/test/unit-tests.c b/test/unit-tests.c
index a4ead29..c989d91 100644
--- a/test/unit-tests.c
+++ b/test/unit-tests.c
@@ -378,17 +378,17 @@ test_process_command_free_passed_fds(void **state __attribute__((unused)))
expect_value(__wrap_close, fd, 0xcd);
will_return(__wrap_close, 0);
- patch(vfu_send_iovec);
- expect_value(__wrap_vfu_send_iovec, sock, vfu_ctx.conn_fd);
- expect_any(__wrap_vfu_send_iovec, msg_id);
- expect_value(__wrap_vfu_send_iovec, is_reply, true);
- expect_any(__wrap_vfu_send_iovec, cmd);
- expect_any(__wrap_vfu_send_iovec, iovecs);
- expect_any(__wrap_vfu_send_iovec, nr_iovecs);
- expect_any(__wrap_vfu_send_iovec, fds);
- expect_any(__wrap_vfu_send_iovec, count);
- expect_any(__wrap_vfu_send_iovec, err);
- will_return(__wrap_vfu_send_iovec, 0);
+ patch(tran_sock_send_iovec);
+ expect_value(__wrap_tran_sock_send_iovec, sock, vfu_ctx.conn_fd);
+ expect_any(__wrap_tran_sock_send_iovec, msg_id);
+ expect_value(__wrap_tran_sock_send_iovec, is_reply, true);
+ expect_any(__wrap_tran_sock_send_iovec, cmd);
+ expect_any(__wrap_tran_sock_send_iovec, iovecs);
+ expect_any(__wrap_tran_sock_send_iovec, nr_iovecs);
+ expect_any(__wrap_tran_sock_send_iovec, fds);
+ expect_any(__wrap_tran_sock_send_iovec, count);
+ expect_any(__wrap_tran_sock_send_iovec, err);
+ will_return(__wrap_tran_sock_send_iovec, 0);
assert_int_equal(0, process_request(&vfu_ctx));
}