aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/libvfio-user.h51
-rw-r--r--lib/libvfio-user.c23
-rw-r--r--lib/migration.c59
-rw-r--r--lib/migration.h4
-rw-r--r--samples/client.c2
-rw-r--r--samples/gpio-pci-idio-16.c6
-rw-r--r--samples/null.c2
-rw-r--r--samples/server.c79
8 files changed, 121 insertions, 105 deletions
diff --git a/include/libvfio-user.h b/include/libvfio-user.h
index a39b5f4..d33ef59 100644
--- a/include/libvfio-user.h
+++ b/include/libvfio-user.h
@@ -153,13 +153,19 @@ void
vfu_destroy_ctx(vfu_ctx_t *vfu_ctx);
/**
+ * Return the private pointer given to vfu_create_ctx().
+ */
+void *
+vfu_get_private(vfu_ctx_t *vfu_ctx);
+
+/**
* Callback function signature for log function
- * @pvt: private pointer
+ * @vfu_ctx: the libvfio-user context
* @level: log level as defined in syslog(3)
* @vfu_log_fn_t: typedef for log function.
* @msg: message
*/
-typedef void (vfu_log_fn_t) (void *pvt, int level, const char *msg);
+typedef void (vfu_log_fn_t)(vfu_ctx_t *vfu_ctx, int level, const char *msg);
/**
* Log to the logging function configured for this context.
@@ -193,7 +199,7 @@ vfu_mmap(vfu_ctx_t * vfu_ctx, off_t offset, size_t length);
* Prototype for region access callback. When a region is accessed, libvfio-user
* calls the previously registered callback with the following arguments:
*
- * @pvt: private data originally passed by vfu_create_ctx()
+ * @vfu_ctx: the libvfio-user context
* @buf: buffer containing the data to be written or data to be read into
* @count: number of bytes being read or written
* @offset: byte offset within the region
@@ -201,8 +207,9 @@ vfu_mmap(vfu_ctx_t * vfu_ctx, off_t offset, size_t length);
*
* @returns the number of bytes read or written, or a negative integer on error
*/
-typedef ssize_t (vfu_region_access_cb_t) (void *pvt, char *buf, size_t count,
- loff_t offset, bool is_write);
+typedef ssize_t (vfu_region_access_cb_t)(vfu_ctx_t *vfu_ctx, char *buf,
+ size_t count, loff_t offset,
+ bool is_write);
#define VFU_REGION_FLAG_READ (1 << 0)
#define VFU_REGION_FLAG_WRITE (1 << 1)
@@ -257,9 +264,8 @@ vfu_setup_region(vfu_ctx_t *vfu_ctx, int region_idx, size_t size,
/*
* Callback function that is called when the guest resets the device.
- * @pvt: private pointer
*/
-typedef int (vfu_reset_cb_t) (void *pvt);
+typedef int (vfu_reset_cb_t)(vfu_ctx_t *vfu_ctx);
/**
* Setup device reset callback.
@@ -271,21 +277,25 @@ vfu_setup_device_reset_cb(vfu_ctx_t *vfu_ctx, vfu_reset_cb_t *reset);
/*
* Function that is called when the guest maps a DMA region. Optional.
- * @pvt: private pointer
+ *
+ * @vfu_ctx: the libvfio-user context
* @iova: iova address
* @len: length
*/
-typedef void (vfu_map_dma_cb_t) (void *pvt, uint64_t iova, uint64_t len);
+typedef void (vfu_map_dma_cb_t)(vfu_ctx_t *vfu_ctx,
+ uint64_t iova, uint64_t len);
/*
* Function that is called when the guest unmaps a DMA region. The device
* must release all references to that region before the callback returns.
* This is required if you want to be able to access guest memory.
- * @pvt: private pointer
+ *
+ * @vfu_ctx: the libvfio-user context
* @iova: iova address
* @len: length
*/
-typedef int (vfu_unmap_dma_cb_t) (void *pvt, uint64_t iova, uint64_t len);
+typedef int (vfu_unmap_dma_cb_t)(vfu_ctx_t *vfu_ctx,
+ uint64_t iova, uint64_t len);
/**
* Setup device DMA map/unmap callbacks. This will also enable bookkeeping of
@@ -325,9 +335,9 @@ vfu_setup_device_nr_irqs(vfu_ctx_t *vfu_ctx, enum vfu_dev_irq_type type,
*/
/**
* Migration callback function.
- * @pvt: private pointer
+ * @vfu_ctx: the libvfio-user context
*/
-typedef int (vfu_migration_callback_t)(void *pvt);
+typedef int (vfu_migration_callback_t)(vfu_ctx_t *vfu_ctx);
typedef enum {
VFU_MIGR_STATE_STOP,
@@ -342,7 +352,7 @@ typedef struct {
/* migration state transition callback */
/* TODO rename to vfu_migration_state_transition_callback */
/* FIXME maybe we should create a single callback and pass the state? */
- int (*transition)(void *pvt, vfu_migr_state_t state);
+ int (*transition)(vfu_ctx_t *vfu_ctx, vfu_migr_state_t state);
/* Callbacks for saving device state */
@@ -353,14 +363,14 @@ typedef struct {
* (e.g. migration data can be discarded). If the function returns 0 then
* migration has finished and this function won't be called again.
*/
- __u64 (*get_pending_bytes)(void *pvt);
+ __u64 (*get_pending_bytes)(vfu_ctx_t *vfu_ctx);
/*
* Function that is called to instruct the device to prepare migration data.
* The function must return only after migration data are available at the
* specified offset.
*/
- int (*prepare_data)(void *pvt, __u64 *offset, __u64 *size);
+ int (*prepare_data)(vfu_ctx_t *vfu_ctx, __u64 *offset, __u64 *size);
/*
* Function that is called to read migration data. offset and size can
@@ -370,7 +380,8 @@ typedef struct {
*
* Does this mean that reading data_offset/data_size updates the values?
*/
- size_t (*read_data)(void *pvt, void *buf, __u64 count, __u64 offset);
+ size_t (*read_data)(vfu_ctx_t *vfu_ctx, void *buf,
+ __u64 count, __u64 offset);
/* Callbacks for restoring device state */
@@ -378,10 +389,12 @@ typedef struct {
* Function that is called when client has written some previously stored
* device state.
*/
- int (*data_written)(void *pvt, __u64 count, __u64 offset);
+ int (*data_written)(vfu_ctx_t *vfu_ctx,
+ __u64 count, __u64 offset);
/* Fuction that is called for writing previously stored device state. */
- size_t (*write_data)(void *pvt, void *buf, __u64 count, __u64 offset);
+ size_t (*write_data)(vfu_ctx_t *vfu_ctx, void *buf,
+ __u64 count, __u64 offset);
} vfu_migration_callbacks_t;
diff --git a/lib/libvfio-user.c b/lib/libvfio-user.c
index 7f0bb0b..104e618 100644
--- a/lib/libvfio-user.c
+++ b/lib/libvfio-user.c
@@ -73,7 +73,7 @@ vfu_log(vfu_ctx_t *vfu_ctx, int level, const char *fmt, ...)
va_start(ap, fmt);
vsnprintf(buf, sizeof buf, fmt, ap);
va_end(ap);
- vfu_ctx->log(vfu_ctx->pvt, level, buf);
+ vfu_ctx->log(vfu_ctx, level, buf);
errno = _errno;
}
@@ -367,8 +367,7 @@ do_access(vfu_ctx_t *vfu_ctx, char *buf, uint8_t count, uint64_t pos, bool is_wr
vfu_ctx->reg_info[idx].size);
return -EINVAL;
}
- return handle_migration_region_access(vfu_ctx, vfu_ctx->pvt,
- vfu_ctx->migration,
+ return handle_migration_region_access(vfu_ctx, vfu_ctx->migration,
buf, count, offset, is_write);
}
@@ -379,8 +378,7 @@ do_access(vfu_ctx_t *vfu_ctx, char *buf, uint8_t count, uint64_t pos, bool is_wr
* callback NULL in vfu_create_ctx.
*/
if (vfu_ctx->reg_info[idx].fn != NULL) {
- return vfu_ctx->reg_info[idx].fn(vfu_ctx->pvt, buf, count, offset,
- is_write);
+ return vfu_ctx->reg_info[idx].fn(vfu_ctx, buf, count, offset, is_write);
}
vfu_log(vfu_ctx, LOG_ERR, "no callback for region %d", idx);
@@ -622,7 +620,7 @@ handle_dma_map_or_unmap(vfu_ctx_t *vfu_ctx, uint32_t size, bool map,
ret = dma_controller_remove_region(vfu_ctx->dma,
dma_regions[i].addr,
dma_regions[i].size,
- vfu_ctx->unmap_dma, vfu_ctx->pvt);
+ vfu_ctx->unmap_dma, vfu_ctx);
if (ret < 0) {
vfu_log(vfu_ctx, LOG_INFO,
"failed to remove DMA region %#lx-%#lx: %s",
@@ -640,8 +638,7 @@ handle_dma_map_or_unmap(vfu_ctx_t *vfu_ctx, uint32_t size, bool map,
return ret;
}
if (vfu_ctx->map_dma != NULL) {
- vfu_ctx->map_dma(vfu_ctx->pvt, dma_regions[i].addr,
- dma_regions[i].size);
+ vfu_ctx->map_dma(vfu_ctx, dma_regions[i].addr, dma_regions[i].size);
}
}
return ret;
@@ -652,7 +649,7 @@ handle_device_reset(vfu_ctx_t *vfu_ctx)
{
vfu_log(vfu_ctx, LOG_DEBUG, "Device reset called by client");
if (vfu_ctx->reset != NULL) {
- return vfu_ctx->reset(vfu_ctx->pvt);
+ return vfu_ctx->reset(vfu_ctx);
}
return 0;
}
@@ -1288,6 +1285,14 @@ vfu_destroy_ctx(vfu_ctx_t *vfu_ctx)
// FIXME: Maybe close any open irq efds? Unmap stuff?
}
+void *
+vfu_get_private(vfu_ctx_t *vfu_ctx)
+{
+ assert(vfu_ctx != NULL);
+
+ return vfu_ctx->pvt;
+}
+
int
vfu_attach_ctx(vfu_ctx_t *vfu_ctx)
{
diff --git a/lib/migration.c b/lib/migration.c
index a33722a..29c667b 100644
--- a/lib/migration.c
+++ b/lib/migration.c
@@ -123,9 +123,8 @@ _migr_state_transition_is_valid(__u32 from, __u32 to)
}
static ssize_t
-handle_device_state(vfu_ctx_t *vfu_ctx, void *pvt,
- struct migration *migr, __u32 *device_state,
- bool is_write) {
+handle_device_state(vfu_ctx_t *vfu_ctx, struct migration *migr,
+ __u32 *device_state, bool is_write) {
int ret;
@@ -152,10 +151,10 @@ handle_device_state(vfu_ctx_t *vfu_ctx, void *pvt,
switch (*device_state) {
case VFIO_DEVICE_STATE_STOP:
- ret = migr->callbacks.transition(pvt, VFU_MIGR_STATE_STOP);
+ ret = migr->callbacks.transition(vfu_ctx, VFU_MIGR_STATE_STOP);
break;
case VFIO_DEVICE_STATE_RUNNING:
- ret = migr->callbacks.transition(pvt, VFU_MIGR_STATE_RUNNING);
+ ret = migr->callbacks.transition(vfu_ctx, VFU_MIGR_STATE_RUNNING);
break;
case VFIO_DEVICE_STATE_SAVING:
/*
@@ -164,13 +163,14 @@ handle_device_state(vfu_ctx_t *vfu_ctx, void *pvt,
* the migration region? E.g. Access to any other region should be
* failed? This might be a good question to send to LKML.
*/
- ret = migr->callbacks.transition(pvt, VFU_MIGR_STATE_STOP_AND_COPY);
+ ret = migr->callbacks.transition(vfu_ctx,
+ VFU_MIGR_STATE_STOP_AND_COPY);
break;
case VFIO_DEVICE_STATE_RUNNING | VFIO_DEVICE_STATE_SAVING:
- ret = migr->callbacks.transition(pvt, VFU_MIGR_STATE_PRE_COPY);
+ ret = migr->callbacks.transition(vfu_ctx, VFU_MIGR_STATE_PRE_COPY);
break;
case VFIO_DEVICE_STATE_RESUMING:
- ret = migr->callbacks.transition(pvt, VFU_MIGR_STATE_RESUME);
+ ret = migr->callbacks.transition(vfu_ctx, VFU_MIGR_STATE_RESUME);
break;
default:
assert(false);
@@ -189,7 +189,7 @@ handle_device_state(vfu_ctx_t *vfu_ctx, void *pvt,
// FIXME: no need to use __u* type variants
static ssize_t
-handle_pending_bytes(void *pvt, struct migration *migr,
+handle_pending_bytes(vfu_ctx_t *vfu_ctx, struct migration *migr,
__u64 *pending_bytes, bool is_write)
{
assert(migr != NULL);
@@ -204,7 +204,7 @@ handle_pending_bytes(void *pvt, struct migration *migr,
return 0;
}
- *pending_bytes = migr->callbacks.get_pending_bytes(pvt);
+ *pending_bytes = migr->callbacks.get_pending_bytes(vfu_ctx);
switch (migr->iter.state) {
case VFIO_USER_MIGR_ITER_STATE_INITIAL:
@@ -241,8 +241,8 @@ handle_pending_bytes(void *pvt, struct migration *migr,
*/
static ssize_t
-handle_data_offset_when_saving(vfu_ctx_t *vfu_ctx, void *pvt,
- struct migration *migr, bool is_write)
+handle_data_offset_when_saving(vfu_ctx_t *vfu_ctx, struct migration *migr,
+ bool is_write)
{
int ret = 0;
@@ -255,7 +255,7 @@ handle_data_offset_when_saving(vfu_ctx_t *vfu_ctx, void *pvt,
switch (migr->iter.state) {
case VFIO_USER_MIGR_ITER_STATE_STARTED:
- ret = migr->callbacks.prepare_data(pvt, &migr->iter.offset,
+ ret = migr->callbacks.prepare_data(vfu_ctx, &migr->iter.offset,
&migr->iter.size);
if (ret < 0) {
return ret;
@@ -276,7 +276,7 @@ handle_data_offset_when_saving(vfu_ctx_t *vfu_ctx, void *pvt,
}
static ssize_t
-handle_data_offset(vfu_ctx_t *vfu_ctx, void *pvt, struct migration *migr,
+handle_data_offset(vfu_ctx_t *vfu_ctx, struct migration *migr,
__u64 *offset, bool is_write)
{
int ret;
@@ -287,7 +287,7 @@ handle_data_offset(vfu_ctx_t *vfu_ctx, void *pvt, struct migration *migr,
switch (migr->info.device_state) {
case VFIO_DEVICE_STATE_SAVING:
case VFIO_DEVICE_STATE_RUNNING | VFIO_DEVICE_STATE_SAVING:
- ret = handle_data_offset_when_saving(vfu_ctx, pvt, migr, is_write);
+ ret = handle_data_offset_when_saving(vfu_ctx, migr, is_write);
break;
case VFIO_DEVICE_STATE_RESUMING:
if (is_write) {
@@ -334,7 +334,7 @@ handle_data_size_when_saving(vfu_ctx_t *vfu_ctx, struct migration *migr,
}
static ssize_t
-handle_data_size_when_resuming(void *pvt, struct migration *migr,
+handle_data_size_when_resuming(vfu_ctx_t *vfu_ctx, struct migration *migr,
__u64 size, bool is_write)
{
int ret = 0;
@@ -342,7 +342,7 @@ handle_data_size_when_resuming(void *pvt, struct migration *migr,
assert(migr != NULL);
if (is_write) {
- ret = migr->callbacks.data_written(pvt, size, migr->info.data_offset);
+ ret = migr->callbacks.data_written(vfu_ctx, size, migr->info.data_offset);
migr->info.data_size = size;
migr->info.data_offset += size;
}
@@ -350,7 +350,7 @@ handle_data_size_when_resuming(void *pvt, struct migration *migr,
}
static ssize_t
-handle_data_size(vfu_ctx_t *vfu_ctx, void *pvt, struct migration *migr,
+handle_data_size(vfu_ctx_t *vfu_ctx, struct migration *migr,
__u64 *size, bool is_write)
{
int ret;
@@ -364,7 +364,7 @@ handle_data_size(vfu_ctx_t *vfu_ctx, void *pvt, struct migration *migr,
ret = handle_data_size_when_saving(vfu_ctx, migr, is_write);
break;
case VFIO_DEVICE_STATE_RESUMING:
- ret = handle_data_size_when_resuming(pvt, migr, *size, is_write);
+ ret = handle_data_size_when_resuming(vfu_ctx, migr, *size, is_write);
break;
default:
/* TODO improve error message */
@@ -380,8 +380,8 @@ handle_data_size(vfu_ctx_t *vfu_ctx, void *pvt, struct migration *migr,
}
static ssize_t
-handle_region_access_registers(vfu_ctx_t *vfu_ctx, void *pvt,
- struct migration *migr, char *buf, size_t count,
+handle_region_access_registers(vfu_ctx_t *vfu_ctx, struct migration *migr,
+ char *buf, size_t count,
loff_t pos, bool is_write)
{
int ret;
@@ -395,7 +395,7 @@ handle_region_access_registers(vfu_ctx_t *vfu_ctx, void *pvt,
"bad device_state access size %ld", count);
return -EINVAL;
}
- ret = handle_device_state(vfu_ctx, pvt, migr, (__u32*)buf, is_write);
+ ret = handle_device_state(vfu_ctx, migr, (__u32*)buf, is_write);
break;
case offsetof(struct vfio_device_migration_info, pending_bytes):
if (count != sizeof(migr->info.pending_bytes)) {
@@ -403,7 +403,7 @@ handle_region_access_registers(vfu_ctx_t *vfu_ctx, void *pvt,
"bad pending_bytes access size %ld", count);
return -EINVAL;
}
- ret = handle_pending_bytes(pvt, migr, (__u64*)buf, is_write);
+ ret = handle_pending_bytes(vfu_ctx, migr, (__u64*)buf, is_write);
break;
case offsetof(struct vfio_device_migration_info, data_offset):
if (count != sizeof(migr->info.data_offset)) {
@@ -411,7 +411,7 @@ handle_region_access_registers(vfu_ctx_t *vfu_ctx, void *pvt,
"bad data_offset access size %ld", count);
return -EINVAL;
}
- ret = handle_data_offset(vfu_ctx, pvt, migr, (__u64*)buf, is_write);
+ ret = handle_data_offset(vfu_ctx, migr, (__u64*)buf, is_write);
break;
case offsetof(struct vfio_device_migration_info, data_size):
if (count != sizeof(migr->info.data_size)) {
@@ -419,7 +419,7 @@ handle_region_access_registers(vfu_ctx_t *vfu_ctx, void *pvt,
"bad data_size access size %ld", count);
return -EINVAL;
}
- ret = handle_data_size(vfu_ctx, pvt, migr, (__u64*)buf, is_write);
+ ret = handle_data_size(vfu_ctx, migr, (__u64*)buf, is_write);
break;
default:
vfu_log(vfu_ctx, LOG_ERR, "bad migration region register offset %#lx",
@@ -430,8 +430,7 @@ handle_region_access_registers(vfu_ctx_t *vfu_ctx, void *pvt,
}
ssize_t
-handle_migration_region_access(vfu_ctx_t *vfu_ctx, void *pvt,
- struct migration *migr,
+handle_migration_region_access(vfu_ctx_t *vfu_ctx, struct migration *migr,
char *buf, size_t count,
loff_t pos, bool is_write)
{
@@ -441,14 +440,14 @@ handle_migration_region_access(vfu_ctx_t *vfu_ctx, void *pvt,
assert(buf != NULL);
if (pos + count <= sizeof(struct vfio_device_migration_info)) {
- ret = handle_region_access_registers(vfu_ctx, pvt, migr, buf,
+ ret = handle_region_access_registers(vfu_ctx, migr, buf,
count, pos, is_write);
} else {
pos -= sizeof(struct vfio_device_migration_info);
if (is_write) {
- ret = migr->callbacks.write_data(pvt, buf, count, pos);
+ ret = migr->callbacks.write_data(vfu_ctx, buf, count, pos);
} else {
- ret = migr->callbacks.read_data(pvt, buf, count, pos);
+ ret = migr->callbacks.read_data(vfu_ctx, buf, count, pos);
}
}
diff --git a/lib/migration.h b/lib/migration.h
index 05ed0de..6978828 100644
--- a/lib/migration.h
+++ b/lib/migration.h
@@ -47,8 +47,8 @@ struct migration *
init_migration(const vfu_migration_t * const vfu_migr, int *err);
ssize_t
-handle_migration_region_access(vfu_ctx_t *vfu_ctx, void *pvt,
- struct migration *migr, char *buf, size_t count,
+handle_migration_region_access(vfu_ctx_t *vfu_ctx, struct migration *migr,
+ char *buf, size_t count,
loff_t pos, bool is_write);
bool
diff --git a/samples/client.c b/samples/client.c
index e59f66d..7568afe 100644
--- a/samples/client.c
+++ b/samples/client.c
@@ -1127,7 +1127,7 @@ int main(int argc, char *argv[])
* Normally the client would now send the device state to the destination
* client and then exit. We don't demonstrate how this works as this is a
* client implementation detail. Instead, the client starts the destination
- * server and then applies the mgiration data.
+ * server and then applies the migration data.
*/
if (asprintf(&path_to_server, "%s/server", dirname(argv[0])) == -1) {
err(EXIT_FAILURE, "failed to asprintf");
diff --git a/samples/gpio-pci-idio-16.c b/samples/gpio-pci-idio-16.c
index e31db6d..08f2cca 100644
--- a/samples/gpio-pci-idio-16.c
+++ b/samples/gpio-pci-idio-16.c
@@ -46,14 +46,14 @@
#include "tran_sock.h"
static void
-_log(UNUSED void *pvt, UNUSED int level, char const *msg)
+_log(vfu_ctx_t *vfu_ctx UNUSED, UNUSED int level, char const *msg)
{
fprintf(stderr, "gpio: %s\n", msg);
}
ssize_t
-bar2_access(UNUSED void *pvt, char * const buf, size_t count, loff_t offset,
- const bool is_write)
+bar2_access(vfu_ctx_t *vfu_ctx UNUSED, char * const buf,
+ size_t count, loff_t offset, const bool is_write)
{
static char n;
diff --git a/samples/null.c b/samples/null.c
index 3438f5f..23d727a 100644
--- a/samples/null.c
+++ b/samples/null.c
@@ -43,7 +43,7 @@
#include "tran_sock.h"
static void
-null_log(UNUSED void *pvt, UNUSED int level, char const *msg)
+null_log(vfu_ctx_t *vfu_ctx UNUSED, UNUSED int level, char const *msg)
{
fprintf(stderr, "null: %s", msg);
}
diff --git a/samples/server.c b/samples/server.c
index 7860f86..88b9591 100644
--- a/samples/server.c
+++ b/samples/server.c
@@ -56,7 +56,6 @@ struct dma_regions {
#define NR_DMA_REGIONS 96
struct server_data {
- vfu_ctx_t *vfu_ctx;
time_t bar0;
uint8_t *bar1;
struct dma_regions regions[NR_DMA_REGIONS];
@@ -70,32 +69,32 @@ struct server_data {
};
static void
-_log(UNUSED void *pvt, UNUSED int level, char const *msg)
+_log(vfu_ctx_t *vfu_ctx UNUSED, UNUSED int level, char const *msg)
{
fprintf(stderr, "server: %s\n", msg);
}
static int
-arm_timer(struct server_data *server_data, time_t t)
+arm_timer(vfu_ctx_t *vfu_ctx, time_t t)
{
struct itimerval new = {.it_value.tv_sec = t - time(NULL) };
- vfu_log(server_data->vfu_ctx, LOG_DEBUG,
- "arming timer to trigger in %ld seconds", new.it_value.tv_sec);
+ vfu_log(vfu_ctx, LOG_DEBUG, "arming timer to trigger in %ld seconds",
+ new.it_value.tv_sec);
if (setitimer(ITIMER_REAL, &new, NULL) != 0) {
- vfu_log(server_data->vfu_ctx, LOG_ERR, "failed to arm timer: %m");
+ vfu_log(vfu_ctx, LOG_ERR, "failed to arm timer: %m");
return -errno;
}
return 0;
}
ssize_t
-bar0_access(void *pvt, char * const buf, size_t count, loff_t offset,
+bar0_access(vfu_ctx_t *vfu_ctx, char * const buf, size_t count, loff_t offset,
const bool is_write)
{
- struct server_data *server_data = pvt;
+ struct server_data *server_data = vfu_get_private(vfu_ctx);
if (count != sizeof(time_t) || offset != 0) {
- vfu_log(server_data->vfu_ctx, LOG_ERR, "bad BAR0 access %#lx-%#lx",
+ vfu_log(vfu_ctx, LOG_ERR, "bad BAR0 access %#lx-%#lx",
offset, offset + count - 1);
errno = EINVAL;
return -1;
@@ -103,7 +102,7 @@ bar0_access(void *pvt, char * const buf, size_t count, loff_t offset,
if (is_write) {
if (server_data->migration.state == VFU_MIGR_STATE_RUNNING) {
- int ret = arm_timer(server_data, *(time_t*)buf);
+ int ret = arm_timer(vfu_ctx, *(time_t*)buf);
if (ret < 0) {
return ret;
}
@@ -118,8 +117,9 @@ bar0_access(void *pvt, char * const buf, size_t count, loff_t offset,
}
ssize_t
-bar1_access(UNUSED void *pvt, UNUSED char * const buf, UNUSED size_t count,
- UNUSED loff_t offset, UNUSED const bool is_write)
+bar1_access(vfu_ctx_t *vfu_ctx UNUSED, UNUSED char * const buf,
+ UNUSED size_t count, UNUSED loff_t offset,
+ UNUSED const bool is_write)
{
assert(false);
@@ -138,9 +138,10 @@ static void _sa_handler(int signum)
errno = _errno;
}
-static void map_dma(void *pvt, uint64_t iova, uint64_t len)
+static void
+map_dma(vfu_ctx_t *vfu_ctx, uint64_t iova, uint64_t len)
{
- struct server_data *server_data = pvt;
+ struct server_data *server_data = vfu_get_private(vfu_ctx);
int idx;
for (idx = 0; idx < NR_DMA_REGIONS; idx++) {
@@ -156,9 +157,10 @@ static void map_dma(void *pvt, uint64_t iova, uint64_t len)
server_data->regions[idx].len = len;
}
-static int unmap_dma(void *pvt, uint64_t iova, uint64_t len)
+static int
+unmap_dma(vfu_ctx_t *vfu_ctx, uint64_t iova, uint64_t len)
{
- struct server_data *server_data = pvt;
+ struct server_data *server_data = vfu_get_private(vfu_ctx);
int idx;
for (idx = 0; idx < NR_DMA_REGIONS; idx++) {
@@ -232,7 +234,7 @@ static void do_dma_io(vfu_ctx_t *vfu_ctx, struct server_data *server_data)
}
}
-static int device_reset(UNUSED void *pvt)
+static int device_reset(vfu_ctx_t *vfu_ctx UNUSED)
{
printf("device reset callback\n");
@@ -240,10 +242,10 @@ static int device_reset(UNUSED void *pvt)
}
static int
-migration_device_state_transition(void *pvt, vfu_migr_state_t state)
+migration_device_state_transition(vfu_ctx_t *vfu_ctx, vfu_migr_state_t state)
{
+ struct server_data *server_data = vfu_get_private(vfu_ctx);
int ret;
- struct server_data *server_data = pvt;
printf("migration: transition to device state %d\n", state);
@@ -258,7 +260,7 @@ migration_device_state_transition(void *pvt, vfu_migr_state_t state)
case VFU_MIGR_STATE_RESUME:
break;
case VFU_MIGR_STATE_RUNNING:
- ret = arm_timer(server_data, server_data->bar0);
+ ret = arm_timer(vfu_ctx, server_data->bar0);
if (ret < 0) {
return ret;
}
@@ -271,9 +273,9 @@ migration_device_state_transition(void *pvt, vfu_migr_state_t state)
}
static __u64
-migration_get_pending_bytes(void *pvt)
+migration_get_pending_bytes(vfu_ctx_t *vfu_ctx)
{
- struct server_data *server_data = pvt;
+ struct server_data *server_data = vfu_get_private(vfu_ctx);
if (server_data->migration.data_size > 0) {
assert(server_data->migration.data_size <= server_data->migration.pending_bytes);
server_data->migration.pending_bytes -= server_data->migration.data_size;
@@ -282,9 +284,9 @@ migration_get_pending_bytes(void *pvt)
}
static int
-migration_prepare_data(void *pvt, __u64 *offset, __u64 *size)
+migration_prepare_data(vfu_ctx_t *vfu_ctx, __u64 *offset, __u64 *size)
{
- struct server_data *server_data = pvt;
+ struct server_data *server_data = vfu_get_private(vfu_ctx);
*offset = 0;
*size = server_data->migration.data_size = MIN(server_data->migration.pending_bytes, server_data->migration.migr_data_len / 4);
@@ -292,13 +294,12 @@ migration_prepare_data(void *pvt, __u64 *offset, __u64 *size)
}
static size_t
-migration_read_data(void *pvt, void *buf, __u64 size, __u64 offset)
+migration_read_data(vfu_ctx_t *vfu_ctx, void *buf, __u64 size, __u64 offset)
{
- struct server_data *server_data = pvt;
+ struct server_data *server_data = vfu_get_private(vfu_ctx);
if (server_data->migration.data_size < size) {
- vfu_log(server_data->vfu_ctx, LOG_ERR,
- "invalid migration data read %#llx-%#llx",
+ vfu_log(vfu_ctx, LOG_ERR, "invalid migration data read %#llx-%#llx",
offset, offset + size - 1);
return -EINVAL;
}
@@ -314,16 +315,16 @@ migration_read_data(void *pvt, void *buf, __u64 size, __u64 offset)
}
static size_t
-migration_write_data(void *pvt, void *data, __u64 size, __u64 offset)
+migration_write_data(vfu_ctx_t *vfu_ctx, void *data, __u64 size, __u64 offset)
{
- struct server_data *server_data = pvt;
+ struct server_data *server_data = vfu_get_private(vfu_ctx);
assert(server_data != NULL);
assert(data != NULL);
if (offset + size > server_data->migration.migr_data_len) {
- vfu_log(server_data->vfu_ctx, LOG_ERR,
- "invalid write %#llx-%#llx", offset, offset + size - 1);
+ vfu_log(vfu_ctx, LOG_ERR, "invalid write %#llx-%#llx",
+ offset, offset + size - 1);
}
memcpy(server_data->migration.migr_data + offset, data, size);
@@ -333,16 +334,15 @@ migration_write_data(void *pvt, void *data, __u64 size, __u64 offset)
static int
-migration_data_written(void *pvt, __u64 count, __u64 offset)
+migration_data_written(vfu_ctx_t *vfu_ctx, __u64 count, __u64 offset)
{
+ struct server_data *server_data = vfu_get_private(vfu_ctx);
int ret;
- struct server_data *server_data = pvt;
assert(server_data != NULL);
if (offset + count > server_data->migration.migr_data_len) {
- vfu_log(server_data->vfu_ctx, LOG_ERR,
- "bad migration data range %#llx-%#llx",
+ vfu_log(vfu_ctx, LOG_ERR, "bad migration data range %#llx-%#llx",
offset, offset + count - 1);
return -EINVAL;
}
@@ -351,7 +351,7 @@ migration_data_written(void *pvt, __u64 count, __u64 offset)
/* apply device state */
/* FIXME must arm timer only after device is resumed!!! */
- ret = bar0_access(pvt, server_data->migration.migr_data,
+ ret = bar0_access(vfu_ctx, server_data->migration.migr_data,
sizeof server_data->bar0, 0, true);
if (ret < 0) {
return ret;
@@ -405,9 +405,8 @@ int main(int argc, char *argv[])
err(EXIT_FAILURE, "failed to register signal handler");
}
- server_data.vfu_ctx = vfu_ctx = vfu_create_ctx(VFU_TRANS_SOCK, argv[optind],
- 0, &server_data,
- VFU_DEV_TYPE_PCI);
+ vfu_ctx = vfu_create_ctx(VFU_TRANS_SOCK, argv[optind], 0, &server_data,
+ VFU_DEV_TYPE_PCI);
if (vfu_ctx == NULL) {
err(EXIT_FAILURE, "failed to initialize device emulation\n");
}