aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorJohn Levon <john.levon@nutanix.com>2021-01-04 16:22:48 +0000
committerGitHub <noreply@github.com>2021-01-04 16:22:48 +0000
commit13f1cd8893fad76359c0f1b5232827ad095d1987 (patch)
treefcc0cfb307d262a4f25df722a906971d62b7ba3f /include
parentdd8fb3c0b178e18d7cdbf23e213f9c2045d77a33 (diff)
downloadlibvfio-user-13f1cd8893fad76359c0f1b5232827ad095d1987.zip
libvfio-user-13f1cd8893fad76359c0f1b5232827ad095d1987.tar.gz
libvfio-user-13f1cd8893fad76359c0f1b5232827ad095d1987.tar.bz2
pass vfu_ctx_t to callbacks (#222)
It's easy (with the new vfu_get_private()) to go from a vfu_ctx to the private pointer, but not the reverse; pass the ctx into all the callbacks. Signed-off-by: John Levon <john.levon@nutanix.com> Reviewed-by: Thanos Makatos <thanos.makatos@nutanix.com>
Diffstat (limited to 'include')
-rw-r--r--include/libvfio-user.h51
1 files changed, 32 insertions, 19 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;