diff options
author | John Levon <john.levon@nutanix.com> | 2020-11-27 14:48:07 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-11-27 14:48:07 +0000 |
commit | e94bd44d10d8019ea2c39356363a5743136bdb5d (patch) | |
tree | 93f71114f5e57682a5a5a1182f7c1e19ce963ff8 /samples | |
parent | 40ac852fec651f54a4be8905ab8bb6b25ddb64e2 (diff) | |
download | libvfio-user-e94bd44d10d8019ea2c39356363a5743136bdb5d.zip libvfio-user-e94bd44d10d8019ea2c39356363a5743136bdb5d.tar.gz libvfio-user-e94bd44d10d8019ea2c39356363a5743136bdb5d.tar.bz2 |
rename to libvfio-user (#128)
The muser name no longer reflects the implementation, and will just serve to
confuse. Bite the bullet now, and rename ourselves to reflect the actual
implementation.
Signed-off-by: John Levon <john.levon@nutanix.com>
Reviewed-by: Thanos Makatos <thanos.makatos@nutanix.com>
Reviewed-by: Swapnil Ingle <swapnil.ingle@nutanix.com>
Diffstat (limited to 'samples')
-rw-r--r-- | samples/CMakeLists.txt | 9 | ||||
-rw-r--r-- | samples/client.c | 157 | ||||
-rw-r--r-- | samples/gpio-pci-idio-16.c | 36 | ||||
-rwxr-xr-x | samples/gpio-pci-idio-16.py | 8 | ||||
-rw-r--r-- | samples/null.c | 26 | ||||
-rw-r--r-- | samples/server.c | 119 |
6 files changed, 178 insertions, 177 deletions
diff --git a/samples/CMakeLists.txt b/samples/CMakeLists.txt index 122a73a..3395c6c 100644 --- a/samples/CMakeLists.txt +++ b/samples/CMakeLists.txt @@ -29,13 +29,14 @@ # add_executable(server server.c) -target_link_libraries(server muser ssl crypto) +target_link_libraries(server vfio-user ssl crypto) + add_executable(client client.c - ../lib/tran_sock.c ../lib/migration.c) + ../lib/tran_sock.c ../lib/migration.c) target_link_libraries(client json-c) add_executable(null null.c) -target_link_libraries(null muser pthread) +target_link_libraries(null vfio-user pthread) add_executable(gpio-pci-idio-16 gpio-pci-idio-16.c) -target_link_libraries(gpio-pci-idio-16 muser) +target_link_libraries(gpio-pci-idio-16 vfio-user) diff --git a/samples/client.c b/samples/client.c index 4845c39..7002582 100644 --- a/samples/client.c +++ b/samples/client.c @@ -44,21 +44,22 @@ #include <libgen.h> #include "common.h" -#include "muser.h" +#include "libvfio-user.h" #include "tran_sock.h" #define CLIENT_MAX_FDS (32) static char *irq_to_str[] = { - [LM_DEV_INTX_IRQ] = "INTx", - [LM_DEV_MSI_IRQ] = "MSI", - [LM_DEV_MSIX_IRQ] = "MSI-X", - [LM_DEV_ERR_IRQ] = "ERR", - [LM_DEV_REQ_IRQ] = "REQ" + [VFU_DEV_INTX_IRQ] = "INTx", + [VFU_DEV_MSI_IRQ] = "MSI", + [VFU_DEV_MSIX_IRQ] = "MSI-X", + [VFU_DEV_ERR_IRQ] = "ERR", + [VFU_DEV_REQ_IRQ] = "REQ" }; void -lm_log(UNUSED lm_ctx_t *lm_ctx, UNUSED lm_log_lvl_t lvl, const char *fmt, ...) +vfu_log(UNUSED vfu_ctx_t *vfu_ctx, UNUSED vfu_log_lvl_t lvl, + const char *fmt, ...) { va_list ap; @@ -106,8 +107,8 @@ send_version(int sock) "}" "}", CLIENT_MAX_FDS, sysconf(_SC_PAGESIZE)); - cversion.major = LIB_MUSER_VFIO_USER_VERS_MJ; - cversion.minor = LIB_MUSER_VFIO_USER_VERS_MN; + cversion.major = LIB_VFIO_USER_MAJOR; + cversion.minor = LIB_VFIO_USER_MINOR; /* [0] is for the header. */ iovecs[1].iov_base = &cversion; @@ -116,8 +117,8 @@ send_version(int sock) /* Include the NUL. */ iovecs[2].iov_len = slen + 1; - ret = vfio_user_send_iovec(sock, msg_id, false, VFIO_USER_VERSION, - iovecs, ARRAY_SIZE(iovecs), NULL, 0, 0); + ret = vfu_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"); @@ -133,8 +134,8 @@ recv_version(int sock, int *server_max_fds, size_t *pgsize) size_t vlen; int ret; - ret = vfio_user_recv_alloc(sock, &hdr, true, &msg_id, - (void **)&sversion, &vlen); + ret = vfu_recv_alloc(sock, &hdr, true, &msg_id, + (void **)&sversion, &vlen); if (ret < 0) { errx(EXIT_FAILURE, "failed to receive version: %s", strerror(-ret)); @@ -153,17 +154,17 @@ recv_version(int sock, int *server_max_fds, size_t *pgsize) msg_id, vlen); } - if (sversion->major != LIB_MUSER_VFIO_USER_VERS_MJ) { + if (sversion->major != LIB_VFIO_USER_MAJOR) { errx(EXIT_FAILURE, "unsupported server major %hu (must be %hu)", - sversion->major, LIB_MUSER_VFIO_USER_VERS_MJ); + sversion->major, LIB_VFIO_USER_MAJOR); } /* * The server is supposed to tell us the minimum agreed version. */ - if (sversion->minor > LIB_MUSER_VFIO_USER_VERS_MN) { + if (sversion->minor > LIB_VFIO_USER_MINOR) { errx(EXIT_FAILURE, "unsupported server minor %hu (must be %hu)", - sversion->minor, LIB_MUSER_VFIO_USER_VERS_MN); + sversion->minor, LIB_VFIO_USER_MINOR); } *server_max_fds = 1; @@ -177,7 +178,7 @@ recv_version(int sock, int *server_max_fds, size_t *pgsize) errx(EXIT_FAILURE, "ignoring invalid JSON from server"); } - ret = vfio_user_parse_version_json(json_str, server_max_fds, pgsize); + ret = vfu_parse_version_json(json_str, server_max_fds, pgsize); if (ret < 0) { errx(EXIT_FAILURE, "failed to parse server JSON \"%s\"", json_str); @@ -197,8 +198,8 @@ negotiate(int sock, int *server_max_fds, size_t *pgsize) static void send_device_reset(int sock) { - int ret = vfio_user_msg(sock, 1, VFIO_USER_DEVICE_RESET, - NULL, 0, NULL, NULL, 0); + int ret = vfu_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)); } @@ -276,11 +277,11 @@ get_device_region_info(int sock, struct vfio_device_info *client_dev_info) region_info.argsz = sizeof(region_info); region_info.index = i; msg_id++; - ret = vfio_user_msg(sock, msg_id, - VFIO_USER_DEVICE_GET_REGION_INFO, - ®ion_info, sizeof region_info, - NULL, - ®ion_info, sizeof(region_info)); + ret = vfu_msg(sock, msg_id, + VFIO_USER_DEVICE_GET_REGION_INFO, + ®ion_info, sizeof region_info, + NULL, + ®ion_info, sizeof(region_info)); if (ret < 0) { errx(EXIT_FAILURE, "failed to get device region info: %s", strerror(-ret)); @@ -308,11 +309,11 @@ get_device_info(int sock, struct vfio_device_info *dev_info) dev_info->argsz = sizeof(*dev_info); - ret = vfio_user_msg(sock, msg_id, - VFIO_USER_DEVICE_GET_INFO, - dev_info, sizeof(*dev_info), - NULL, - dev_info, 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)); if (ret < 0) { errx(EXIT_FAILURE, "failed to get device info: %s", strerror(-ret)); @@ -331,16 +332,16 @@ configure_irqs(int sock) int irq_fd; int i, ret; - for (i = 0; i < LM_DEV_NUM_IRQS; i++) { /* TODO move body of loop into function */ + for (i = 0; i < VFU_DEV_NUM_IRQS; i++) { /* TODO move body of loop into function */ struct vfio_irq_info vfio_irq_info = { .argsz = sizeof vfio_irq_info, .index = i }; - ret = vfio_user_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 = 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); if (ret < 0) { errx(EXIT_FAILURE, "failed to get %s info: %s", irq_to_str[i], strerror(-ret)); @@ -367,10 +368,10 @@ configure_irqs(int sock) iovecs[1].iov_base = &irq_set; iovecs[1].iov_len = sizeof (irq_set); - ret = vfio_user_msg_iovec(sock, msg_id, VFIO_USER_DEVICE_SET_IRQS, - iovecs, ARRAY_SIZE(iovecs), - &irq_fd, 1, - NULL, NULL, 0); + ret = vfu_msg_iovec(sock, msg_id, VFIO_USER_DEVICE_SET_IRQS, + iovecs, ARRAY_SIZE(iovecs), + &irq_fd, 1, + NULL, NULL, 0); if (ret < 0) { errx(EXIT_FAILURE, "failed to send configure IRQs message: %s", @@ -416,10 +417,10 @@ access_region(int sock, int region, bool is_write, uint64_t offset, recv_data_len = sizeof(recv_data); } - ret = vfio_user_msg_iovec(sock, 0, op, - send_iovecs, nr_send_iovecs, - NULL, 0, NULL, - &recv_data, recv_data_len); + ret = vfu_msg_iovec(sock, 0, op, + send_iovecs, nr_send_iovecs, + NULL, 0, NULL, + &recv_data, recv_data_len); if (ret != 0) { warnx("failed to %s region %d %#lx-%#lx: %s", is_write ? "write to" : "read from", region, offset, @@ -434,7 +435,7 @@ access_region(int sock, int region, bool is_write, uint64_t offset, } /* - * TODO we could avoid the memcpy if _sed_vfio_user_recv received the + * TODO we could avoid the memcpy if vfu_recv() received the * response into an iovec, but it's some work to implement it. */ if (!is_write) { @@ -459,8 +460,8 @@ wait_for_irqs(int sock, int irq_fd) printf("INTx triggered!\n"); size = sizeof(vfio_user_irq_info); - ret = vfio_user_recv(sock, &hdr, false, &msg_id, - &vfio_user_irq_info, &size); + ret = vfu_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)); @@ -475,7 +476,7 @@ wait_for_irqs(int sock, int irq_fd) } // Is a NULL iovec like this OK? - ret = vfio_user_send(sock, msg_id, true, hdr.cmd, NULL, 0); + ret = vfu_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", @@ -490,14 +491,14 @@ access_bar0(int sock, int irq_fd, time_t *t) assert(t != NULL); - ret = access_region(sock, LM_PCI_DEV_BAR0_REGION_IDX, true, 0, t, sizeof *t); + ret = access_region(sock, VFU_PCI_DEV_BAR0_REGION_IDX, true, 0, t, sizeof *t); if (ret < 0) { errx(EXIT_FAILURE, "failed to write to BAR0: %s", strerror(-ret)); } printf("wrote to BAR0: %ld\n", *t); - ret = access_region(sock, LM_PCI_DEV_BAR0_REGION_IDX, false, 0, t, sizeof *t); + ret = access_region(sock, VFU_PCI_DEV_BAR0_REGION_IDX, false, 0, t, sizeof *t); if (ret < 0) { errx(EXIT_FAILURE, "failed to read from BAR0: %s", strerror(-ret)); } @@ -518,7 +519,7 @@ handle_dma_write(int sock, struct vfio_user_dma_region *dma_regions, uint16_t msg_id = 5; void *data; - ret = vfio_user_recv(sock, &hdr, false, &msg_id, &dma_access, &size); + ret = vfu_recv(sock, &hdr, false, &msg_id, &dma_access, &size); if (ret < 0) { errx(EXIT_FAILURE, "failed to receive DMA read: %s", strerror(-ret)); } @@ -548,8 +549,8 @@ handle_dma_write(int sock, struct vfio_user_dma_region *dma_regions, } dma_access.count = 0; - ret = vfio_user_send(sock, msg_id, true, VFIO_USER_DMA_WRITE, - &dma_access, sizeof dma_access); + ret = vfu_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)); @@ -568,7 +569,7 @@ handle_dma_read(int sock, struct vfio_user_dma_region *dma_regions, uint16_t msg_id = 6; void *data; - ret = vfio_user_recv(sock, &hdr, false, &msg_id, &dma_access, &size); + ret = vfu_recv(sock, &hdr, false, &msg_id, &dma_access, &size); if (ret < 0) { errx(EXIT_FAILURE, "failed to recieve DMA read"); } @@ -592,8 +593,8 @@ handle_dma_read(int sock, struct vfio_user_dma_region *dma_regions, } } - ret = vfio_user_send(sock, msg_id, true, VFIO_USER_DMA_READ, - response, response_sz); + ret = vfu_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)); @@ -645,10 +646,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 = vfio_user_msg_iovec(sock, 0, VFIO_USER_DIRTY_PAGES, - iovecs, ARRAY_SIZE(iovecs), - NULL, 0, - &hdr, data, ARRAY_SIZE(data)); + ret = vfu_msg_iovec(sock, 0, VFIO_USER_DIRTY_PAGES, + iovecs, ARRAY_SIZE(iovecs), + NULL, 0, + &hdr, data, ARRAY_SIZE(data)); if (ret != 0) { errx(EXIT_FAILURE, "failed to start dirty page logging: %s", strerror(-ret)); @@ -884,10 +885,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 = vfio_user_msg_iovec(sock, i, VFIO_USER_DMA_MAP, - iovecs, ARRAY_SIZE(iovecs), - dma_region_fds + (i * max_fds), max_fds, - NULL, NULL, 0); + ret = vfu_msg_iovec(sock, i, VFIO_USER_DMA_MAP, + iovecs, ARRAY_SIZE(iovecs), + dma_region_fds + (i * max_fds), max_fds, + NULL, NULL, 0); if (ret < 0) { errx(EXIT_FAILURE, "failed to map DMA regions: %s", strerror(-ret)); } @@ -911,7 +912,7 @@ int main(int argc, char *argv[]) void *migr_data; __u64 migr_data_len; char *path_to_server = NULL; - lm_pci_hdr_t config_space; + vfu_pci_hdr_t config_space; int migr_reg_index; while ((opt = getopt(argc, argv, "h")) != -1) { @@ -956,7 +957,7 @@ int main(int argc, char *argv[]) errx(EXIT_FAILURE, "could not find migration region"); } - ret = access_region(sock, LM_PCI_DEV_CFG_REGION_IDX, false, 0, &config_space, + ret = access_region(sock, VFU_PCI_DEV_CFG_REGION_IDX, false, 0, &config_space, sizeof config_space); if (ret < 0) { errx(EXIT_FAILURE, "failed to read PCI configuration space: %s\n", @@ -1010,9 +1011,9 @@ int main(int argc, char *argv[]) dirty_bitmap.argsz = sizeof dirty_bitmap; dirty_bitmap.flags = VFIO_IOMMU_DIRTY_PAGES_FLAG_START; - ret = vfio_user_msg(sock, 0, VFIO_USER_DIRTY_PAGES, - &dirty_bitmap, sizeof dirty_bitmap, - NULL, NULL, 0); + ret = vfu_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)); @@ -1026,7 +1027,7 @@ int main(int argc, char *argv[]) */ t = time(NULL) + 1; access_bar0(sock, irq_fd, &t); - + /* FIXME check that above took at least 1s */ handle_dma_io(sock, dma_regions, nr_dma_regions, dma_region_fds); @@ -1035,9 +1036,9 @@ int main(int argc, char *argv[]) dirty_bitmap.argsz = sizeof dirty_bitmap; dirty_bitmap.flags = VFIO_IOMMU_DIRTY_PAGES_FLAG_STOP; - ret = vfio_user_msg(sock, 0, VFIO_USER_DIRTY_PAGES, - &dirty_bitmap, sizeof dirty_bitmap, - NULL, NULL, 0); + ret = vfu_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)); @@ -1050,9 +1051,9 @@ int main(int argc, char *argv[]) * * unmap the first group of the DMA regions */ - ret = vfio_user_msg(sock, 7, VFIO_USER_DMA_UNMAP, - dma_regions, sizeof *dma_regions * server_max_fds, - NULL, NULL, 0); + ret = vfu_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)); } @@ -1064,7 +1065,7 @@ int main(int argc, char *argv[]) * TODO make this value a command line option. */ t = time(NULL) + 2; - ret = access_region(sock, LM_PCI_DEV_BAR0_REGION_IDX, true, 0, &t, sizeof t); + ret = access_region(sock, VFU_PCI_DEV_BAR0_REGION_IDX, true, 0, &t, sizeof t); if (ret < 0) { errx(EXIT_FAILURE, "failed to write to BAR0: %s", strerror(-ret)); } @@ -1104,7 +1105,7 @@ int main(int argc, char *argv[]) dma_region_fds + server_max_fds, nr_dma_regions - server_max_fds); - /* + /* * XXX reconfigure IRQs. * FIXME is this something the client needs to do? I would expect so since * it's the client that creates and provides the FD. Do we need to save some diff --git a/samples/gpio-pci-idio-16.c b/samples/gpio-pci-idio-16.c index 7572ce2..aabcf75 100644 --- a/samples/gpio-pci-idio-16.c +++ b/samples/gpio-pci-idio-16.c @@ -1,6 +1,4 @@ /* - * Userspace mediated device sample application - * * Copyright (c) 2019, Nutanix Inc. All rights reserved. * Author: Thanos Makatos <thanos@nutanix.com> * Swapnil Ingle <swapnil.ingle@nutanix.com> @@ -31,7 +29,9 @@ * */ -/* gpio-pci-idio-16 */ +/* + * gpio-pci-idio-16: a simple example server identifying as a GPIO PCI device. + */ #include <stdio.h> #include <err.h> @@ -42,11 +42,11 @@ #include <errno.h> #include "common.h" -#include "muser.h" +#include "libvfio-user.h" #include "tran_sock.h" static void -_log(UNUSED void *pvt, UNUSED lm_log_lvl_t lvl, char const *msg) +_log(UNUSED void *pvt, UNUSED vfu_log_lvl_t lvl, char const *msg) { fprintf(stderr, "gpio: %s\n", msg); } @@ -74,10 +74,10 @@ main(int argc, char *argv[]) bool verbose = false; char opt; struct sigaction act = { .sa_handler = _sa_handler }; - lm_ctx_t *lm_ctx; - lm_pci_hdr_id_t id = { .vid = 0x494F, .did = 0x0DC8 }; - lm_pci_hdr_ss_t ss = { .vid = 0x0, .sid = 0x0 }; - lm_pci_hdr_cc_t cc = { { 0 } }; + vfu_ctx_t *vfu_ctx; + vfu_pci_hdr_id_t id = { .vid = 0x494F, .did = 0x0DC8 }; + vfu_pci_hdr_ss_t ss = { .vid = 0x0, .sid = 0x0 }; + vfu_pci_hdr_cc_t cc = { { 0 } }; while ((opt = getopt(argc, argv, "v")) != -1) { switch (opt) { @@ -91,7 +91,7 @@ main(int argc, char *argv[]) } if (optind >= argc) { - errx(EXIT_FAILURE, "missing MUSER socket path"); + errx(EXIT_FAILURE, "missing vfio-user socket path"); } sigemptyset(&act.sa_mask); @@ -99,8 +99,8 @@ main(int argc, char *argv[]) err(EXIT_FAILURE, "failed to register signal handler"); } - lm_ctx = lm_create_ctx(LM_TRANS_SOCK, argv[optind], 0, NULL); - if (lm_ctx == NULL) { + vfu_ctx = vfu_create_ctx(VFU_TRANS_SOCK, argv[optind], 0, NULL); + if (vfu_ctx == NULL) { if (errno == EINTR) { printf("interrupted\n"); exit(EXIT_SUCCESS); @@ -108,25 +108,25 @@ main(int argc, char *argv[]) err(EXIT_FAILURE, "failed to initialize device emulation"); } - ret = lm_setup_log(lm_ctx, _log, verbose ? LM_DBG : LM_ERR); + ret = vfu_setup_log(vfu_ctx, _log, verbose ? VFU_DBG : VFU_ERR); if (ret < 0) { err(EXIT_FAILURE, "failed to setup log"); } - ret = lm_pci_setup_config_hdr(lm_ctx, id, ss, cc, false); + ret = vfu_pci_setup_config_hdr(vfu_ctx, id, ss, cc, false); if (ret < 0) { fprintf(stderr, "failed to setup pci header\n"); goto out; } - ret = lm_setup_region(lm_ctx, LM_PCI_DEV_BAR2_REGION_IDX, 0x100, &bar2_access, - LM_REG_FLAG_RW, NULL, NULL); + ret = vfu_setup_region(vfu_ctx, VFU_PCI_DEV_BAR2_REGION_IDX, 0x100, + &bar2_access, VFU_REG_FLAG_RW, NULL, NULL); if (ret < 0) { fprintf(stderr, "failed to setup region\n"); goto out; } - ret = lm_ctx_drive(lm_ctx); + ret = vfu_ctx_drive(vfu_ctx); if (ret != 0) { if (ret != -ENOTCONN && ret != -EINTR) { fprintf(stderr, "failed to realize device emulation\n"); @@ -136,7 +136,7 @@ main(int argc, char *argv[]) } out: - lm_ctx_destroy(lm_ctx); + vfu_ctx_destroy(vfu_ctx); return ret; } diff --git a/samples/gpio-pci-idio-16.py b/samples/gpio-pci-idio-16.py index c13c6ae..3c63bdd 100755 --- a/samples/gpio-pci-idio-16.py +++ b/samples/gpio-pci-idio-16.py @@ -1,3 +1,4 @@ +#!/usr/bin/python # # Copyright (c) 2019 Nutanix Inc. All rights reserved. # @@ -15,7 +16,7 @@ # * Neither the name of Nutanix nor the names of its contributors may be # used to endorse or promote products derived from this software without # specific prior written permission. -# +# # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE @@ -27,11 +28,10 @@ # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # -#!/usr/bin/python def bar2(pvt, buf, count, offset, is_write): if not is_write and int(offset) == 0: return int(input("enter new GPIO value: ")) -import muser -muser.run(vid=0x494F, did=0x0DC8, uuid="00000000-0000-0000-0000-000000000000", bar2=("rw", 0x100, bar2), intx=1) +import vfio_user +vfio_user.run(vid=0x494F, did=0x0DC8, uuid="00000000-0000-0000-0000-000000000000", bar2=("rw", 0x100, bar2), intx=1) diff --git a/samples/null.c b/samples/null.c index b633059..1998a08 100644 --- a/samples/null.c +++ b/samples/null.c @@ -1,6 +1,4 @@ /* - * Userspace mediated device sample application - * * Copyright (c) 2019, Nutanix Inc. All rights reserved. * Author: Thanos Makatos <thanos@nutanix.com> * Swapnil Ingle <swapnil.ingle@nutanix.com> @@ -41,19 +39,19 @@ #include <string.h> #include "common.h" -#include "muser.h" +#include "libvfio-user.h" #include "tran_sock.h" static void -null_log(UNUSED void *pvt, UNUSED lm_log_lvl_t lvl, char const *msg) +null_log(UNUSED void *pvt, UNUSED vfu_log_lvl_t lvl, char const *msg) { - fprintf(stderr, "muser: %s", msg); + fprintf(stderr, "null: %s", msg); } static void* null_drive(void *arg) { - lm_ctx_t *lm_ctx = (lm_ctx_t*)arg; + vfu_ctx_t *vfu_ctx = (vfu_ctx_t*)arg; int ret = pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL); if (ret != 0) { fprintf(stderr, "failed to enable cancel state: %s\n", strerror(ret)); @@ -65,7 +63,7 @@ static void* null_drive(void *arg) return NULL; } printf("starting device emulation\n"); - lm_ctx_drive(lm_ctx); + vfu_ctx_drive(vfu_ctx); return NULL; } @@ -75,20 +73,20 @@ int main(int argc, char **argv) pthread_t thread; if (argc != 2) { - errx(EXIT_FAILURE, "missing MUSER socket path"); + errx(EXIT_FAILURE, "missing vfio-user socket path"); } - lm_ctx_t *lm_ctx = lm_create_ctx(LM_TRANS_SOCK, argv[1], 0, NULL); - if (lm_ctx == NULL) { - err(EXIT_FAILURE, "failed to create libmuser context"); + vfu_ctx_t *vfu_ctx = vfu_create_ctx(VFU_TRANS_SOCK, argv[1], 0, NULL); + if (vfu_ctx == NULL) { + err(EXIT_FAILURE, "failed to create libvfio-user context"); } - ret = lm_setup_log(lm_ctx, null_log, LM_DBG); + ret = vfu_setup_log(vfu_ctx, null_log, VFU_DBG); if (ret < 0) { err(EXIT_FAILURE, "failed to setup log"); } - ret = pthread_create(&thread, NULL, null_drive, lm_ctx); + ret = pthread_create(&thread, NULL, null_drive, vfu_ctx); if (ret != 0) { errno = ret; err(EXIT_FAILURE, "failed to create pthread"); @@ -104,7 +102,7 @@ int main(int argc, char **argv) errno = ret; err(EXIT_FAILURE, "failed to create pthread"); } - lm_ctx_destroy(lm_ctx); + vfu_ctx_destroy(vfu_ctx); printf("device emulation stopped and cleaned up, press enter to exit\n"); if (getchar() == EOF) { diff --git a/samples/server.c b/samples/server.c index 2d8bd26..dd84f16 100644 --- a/samples/server.c +++ b/samples/server.c @@ -45,7 +45,7 @@ #include <sys/time.h> #include "common.h" -#include "muser.h" +#include "libvfio-user.h" #include "tran_sock.h" struct dma_regions { @@ -56,7 +56,7 @@ struct dma_regions { #define NR_DMA_REGIONS 96 struct server_data { - lm_ctx_t *lm_ctx; + vfu_ctx_t *vfu_ctx; time_t bar0; uint8_t *bar1; struct dma_regions regions[NR_DMA_REGIONS]; @@ -65,12 +65,12 @@ struct server_data { __u64 data_size; void *migr_data; size_t migr_data_len; - lm_migr_state_t state; + vfu_migr_state_t state; } migration; }; static void -_log(UNUSED void *pvt, UNUSED lm_log_lvl_t lvl, char const *msg) +_log(UNUSED void *pvt, UNUSED vfu_log_lvl_t lvl, char const *msg) { fprintf(stderr, "server: %s\n", msg); } @@ -79,10 +79,10 @@ static int arm_timer(struct server_data *server_data, time_t t) { struct itimerval new = {.it_value.tv_sec = t - time(NULL) }; - lm_log(server_data->lm_ctx, LM_DBG, - "arming timer to trigger in %ld seconds", new.it_value.tv_sec); + vfu_log(server_data->vfu_ctx, VFU_DBG, + "arming timer to trigger in %ld seconds", new.it_value.tv_sec); if (setitimer(ITIMER_REAL, &new, NULL) != 0) { - lm_log(server_data->lm_ctx, LM_ERR, "failed to arm timer: %m"); + vfu_log(server_data->vfu_ctx, VFU_ERR, "failed to arm timer: %m"); return -errno; } return 0; @@ -95,14 +95,14 @@ bar0_access(void *pvt, char * const buf, size_t count, loff_t offset, struct server_data *server_data = pvt; if (count != sizeof(time_t) || offset != 0) { - lm_log(server_data->lm_ctx, LM_ERR, "bad BAR0 access %#lx-%#lx", - offset, offset + count - 1); + vfu_log(server_data->vfu_ctx, VFU_ERR, "bad BAR0 access %#lx-%#lx", + offset, offset + count - 1); errno = EINVAL; return -1; } if (is_write) { - if (server_data->migration.state == LM_MIGR_STATE_RUNNING) { + if (server_data->migration.state == VFU_MIGR_STATE_RUNNING) { int ret = arm_timer(server_data, *(time_t*)buf); if (ret < 0) { return ret; @@ -188,7 +188,7 @@ void get_md5sum(unsigned char *buf, int len, unsigned char *md5sum) * sparsely memory mappable. We should also have a test where the server does * DMA directly on the client memory. */ -static void do_dma_io(lm_ctx_t *lm_ctx, struct server_data *server_data) +static void do_dma_io(vfu_ctx_t *vfu_ctx, struct server_data *server_data) { int count = 4096; unsigned char buf[count]; @@ -196,10 +196,10 @@ static void do_dma_io(lm_ctx_t *lm_ctx, struct server_data *server_data) int i, ret; dma_sg_t sg; - assert(lm_ctx != NULL); + assert(vfu_ctx != NULL); - ret = lm_addr_to_sg(lm_ctx, server_data->regions[0].addr, count, &sg, - 1, PROT_WRITE); + ret = vfu_addr_to_sg(vfu_ctx, server_data->regions[0].addr, count, &sg, + 1, PROT_WRITE); if (ret < 0) { errx(EXIT_FAILURE, "failed to map %#lx-%#lx: %s\n", server_data->regions[0].addr, @@ -210,17 +210,17 @@ static void do_dma_io(lm_ctx_t *lm_ctx, struct server_data *server_data) get_md5sum(buf, count, md5sum1); printf("%s: WRITE addr %#lx count %d\n", __func__, server_data->regions[0].addr, count); - ret = lm_dma_write(lm_ctx, &sg, buf); + ret = vfu_dma_write(vfu_ctx, &sg, buf); if (ret < 0) { - errx(EXIT_FAILURE, "lm_dma_write failed: %s\n", strerror(-ret)); + errx(EXIT_FAILURE, "vfu_dma_write failed: %s\n", strerror(-ret)); } memset(buf, 0, count); printf("%s: READ addr %#lx count %d\n", __func__, server_data->regions[0].addr, count); - ret = lm_dma_read(lm_ctx, &sg, buf); + ret = vfu_dma_read(vfu_ctx, &sg, buf); if (ret < 0) { - errx(EXIT_FAILURE, "lm_dma_read failed: %s\n", strerror(-ret)); + errx(EXIT_FAILURE, "vfu_dma_read failed: %s\n", strerror(-ret)); } get_md5sum(buf, count, md5sum2); for(i = 0; i < MD5_DIGEST_LENGTH; i++) { @@ -246,7 +246,7 @@ static int device_reset(UNUSED void *pvt) } static int -migration_device_state_transition(void *pvt, lm_migr_state_t state) +migration_device_state_transition(void *pvt, vfu_migr_state_t state) { int ret; struct server_data *server_data = pvt; @@ -254,16 +254,16 @@ migration_device_state_transition(void *pvt, lm_migr_state_t state) printf("migration: transition to device state %d\n", state); switch (state) { - case LM_MIGR_STATE_STOP_AND_COPY: + case VFU_MIGR_STATE_STOP_AND_COPY: /* TODO must be less than size of data region in migration region */ server_data->migration.pending_bytes = sysconf(_SC_PAGESIZE); break; - case LM_MIGR_STATE_STOP: + case VFU_MIGR_STATE_STOP: assert(server_data->migration.pending_bytes == 0); break; - case LM_MIGR_STATE_RESUME: + case VFU_MIGR_STATE_RESUME: break; - case LM_MIGR_STATE_RUNNING: + case VFU_MIGR_STATE_RUNNING: ret = arm_timer(server_data, server_data->bar0); if (ret < 0) { return ret; @@ -303,9 +303,9 @@ migration_read_data(void *pvt, void *buf, __u64 size, __u64 offset) struct server_data *server_data = pvt; if (server_data->migration.data_size < size) { - lm_log(server_data->lm_ctx, LM_ERR, - "invalid migration data read %#llx-%#llx", - offset, offset + size - 1); + vfu_log(server_data->vfu_ctx, VFU_ERR, + "invalid migration data read %#llx-%#llx", + offset, offset + size - 1); return -EINVAL; } @@ -328,8 +328,8 @@ migration_write_data(void *pvt, void *data, __u64 size, __u64 offset) assert(data != NULL); if (offset + size > server_data->migration.migr_data_len) { - lm_log(server_data->lm_ctx, LM_ERR, - "invalid write %#llx-%#llx", offset, offset + size - 1); + vfu_log(server_data->vfu_ctx, VFU_ERR, + "invalid write %#llx-%#llx", offset, offset + size - 1); } memcpy(server_data->migration.migr_data + offset, data, size); @@ -347,9 +347,9 @@ migration_data_written(void *pvt, __u64 count, __u64 offset) assert(server_data != NULL); if (offset + count > server_data->migration.migr_data_len) { - lm_log(server_data->lm_ctx, LM_ERR, - "bad migration data range %#llx-%#llx", - offset, offset + count - 1); + vfu_log(server_data->vfu_ctx, VFU_ERR, + "bad migration data range %#llx-%#llx", + offset, offset + count - 1); return -EINVAL; } @@ -377,15 +377,15 @@ int main(int argc, char *argv[]) .migration = { /* one page so that we can memory map it */ .migr_data_len = sysconf(_SC_PAGESIZE), - .state = LM_MIGR_STATE_RUNNING + .state = VFU_MIGR_STATE_RUNNING } }; int nr_sparse_areas = 2, size = 1024, i; - struct lm_sparse_mmap_areas *sparse_areas; - lm_ctx_t *lm_ctx; - lm_pci_hdr_id_t id = {.raw = 0xdeadbeef}; - lm_pci_hdr_ss_t ss = {.raw = 0xcafebabe}; - lm_pci_hdr_cc_t cc = {.pi = 0xab, .scc = 0xcd, .bcc = 0xef}; + struct vfu_sparse_mmap_areas *sparse_areas; + vfu_ctx_t *vfu_ctx; + vfu_pci_hdr_id_t id = {.raw = 0xdeadbeef}; + vfu_pci_hdr_ss_t ss = {.raw = 0xcafebabe}; + vfu_pci_hdr_cc_t cc = {.pi = 0xab, .scc = 0xcd, .bcc = 0xef}; while ((opt = getopt(argc, argv, "v")) != -1) { switch (opt) { @@ -398,7 +398,7 @@ int main(int argc, char *argv[]) } if (optind >= argc) { - errx(EXIT_FAILURE, "missing MUSER socket path"); + errx(EXIT_FAILURE, "missing vfio-user socket path"); } /* coverity[NEGATIVE_RETURNS] */ @@ -408,7 +408,7 @@ int main(int argc, char *argv[]) } sparse_areas = calloc(1, sizeof(*sparse_areas) + - (nr_sparse_areas * sizeof(struct lm_mmap_area))); + (nr_sparse_areas * sizeof(struct vfu_mmap_area))); if (sparse_areas == NULL) { err(EXIT_FAILURE, "MMAP sparse areas ENOMEM"); } @@ -422,50 +422,51 @@ int main(int argc, char *argv[]) err(EXIT_FAILURE, "failed to register signal handler"); } - server_data.lm_ctx = lm_ctx = lm_create_ctx(LM_TRANS_SOCK, argv[optind], 0, - &server_data); - if (lm_ctx == NULL) { + server_data.vfu_ctx = vfu_ctx = vfu_create_ctx(VFU_TRANS_SOCK, argv[optind], + 0, &server_data); + if (vfu_ctx == NULL) { err(EXIT_FAILURE, "failed to initialize device emulation\n"); } - ret = lm_setup_log(lm_ctx, _log, verbose ? LM_DBG : LM_ERR); + ret = vfu_setup_log(vfu_ctx, _log, verbose ? VFU_DBG : VFU_ERR); if (ret < 0) { err(EXIT_FAILURE, "failed to setup log"); } - ret = lm_pci_setup_config_hdr(lm_ctx, id, ss, cc, false); + ret = vfu_pci_setup_config_hdr(vfu_ctx, id, ss, cc, false); if (ret < 0) { err(EXIT_FAILURE, "failed to setup PCI header"); } - ret = lm_setup_region(lm_ctx, LM_PCI_DEV_BAR0_REGION_IDX, sizeof(time_t), - &bar0_access, LM_REG_FLAG_RW, NULL, NULL); + ret = vfu_setup_region(vfu_ctx, VFU_PCI_DEV_BAR0_REGION_IDX, sizeof(time_t), + &bar0_access, VFU_REG_FLAG_RW, NULL, NULL); if (ret < 0) { err(EXIT_FAILURE, "failed to setup BAR0 region"); } - ret = lm_setup_region(lm_ctx, LM_PCI_DEV_BAR1_REGION_IDX, sysconf(_SC_PAGESIZE), - &bar1_access, LM_REG_FLAG_RW, sparse_areas, map_area); + ret = vfu_setup_region(vfu_ctx, VFU_PCI_DEV_BAR1_REGION_IDX, + sysconf(_SC_PAGESIZE), &bar1_access, + VFU_REG_FLAG_RW, sparse_areas, map_area); if (ret < 0) { err(EXIT_FAILURE, "failed to setup BAR1 region"); } - ret = lm_setup_device_reset_cb(lm_ctx, &device_reset); + ret = vfu_setup_device_reset_cb(vfu_ctx, &device_reset); if (ret < 0) { err(EXIT_FAILURE, "failed to setup device reset callbacks"); } - ret = lm_setup_device_dma_cb(lm_ctx, &map_dma, &unmap_dma); + ret = vfu_setup_device_dma_cb(vfu_ctx, &map_dma, &unmap_dma); if (ret < 0) { err(EXIT_FAILURE, "failed to setup device DMA callbacks"); } - ret = lm_setup_device_nr_irqs(lm_ctx, LM_DEV_INTX_IRQ, 1); + ret = vfu_setup_device_nr_irqs(vfu_ctx, VFU_DEV_INTX_IRQ, 1); if (ret < 0) { err(EXIT_FAILURE, "failed to setup irq counts"); } - lm_migration_t migration = { + vfu_migration_t migration = { .size = server_data.migration.migr_data_len, .mmap_areas = sparse_areas, .callbacks = { @@ -478,7 +479,7 @@ int main(int argc, char *argv[]) } }; - ret = lm_setup_device_migration(lm_ctx, &migration); + ret = vfu_setup_device_migration(vfu_ctx, &migration); if (ret < 0) { err(EXIT_FAILURE, "failed to setup device migration"); } @@ -490,18 +491,18 @@ int main(int argc, char *argv[]) } do { - ret = lm_ctx_drive(lm_ctx); + ret = vfu_ctx_drive(vfu_ctx); if (ret == -EINTR) { if (irq_triggered) { irq_triggered = false; - lm_irq_trigger(lm_ctx, 0); + vfu_irq_trigger(vfu_ctx, 0); - ret = lm_irq_message(lm_ctx, 0); + ret = vfu_irq_message(vfu_ctx, 0); if (ret < 0) { - err(EXIT_FAILURE, "lm_irq_message() failed"); + err(EXIT_FAILURE, "vfu_irq_message() failed"); } - do_dma_io(lm_ctx, &server_data); + do_dma_io(vfu_ctx, &server_data); ret = 0; } } @@ -512,7 +513,7 @@ int main(int argc, char *argv[]) strerror(-ret)); } - lm_ctx_destroy(lm_ctx); + vfu_ctx_destroy(vfu_ctx); free(server_data.bar1); free(sparse_areas); return EXIT_SUCCESS; |