---
name: "rte_vhost.h"
section: "3"
platform: "linux"
package: "dpdk-doc"
version: "24.11.4-0+deb13u1"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/rte_vhost.h"
---

# rte\_vhost.h(3)

## NAME

rte\_vhost.h

## SYNOPSIS

`#include <stdbool.h>`\
 `#include <stdint.h>`\
 `#include <sys/eventfd.h>`\
 `#include <rte_compat.h>`\
 `#include <rte_memory.h>`\
 `#include <rte_mempool.h>`\
 `#include <linux/vhost.h>`\
 `#include <linux/virtio_ring.h>`\
 `#include <linux/virtio_net.h>`\

### Data Structures

struct **rte\_vhost\_mem\_region**\
 struct **rte\_vhost\_memory**\
 struct **rte\_vhost\_user\_extern\_ops**\
 struct **rte\_vhost\_device\_ops**\
 struct **rte\_vhost\_power\_monitor\_cond**\
 struct **rte\_vhost\_stat**\
 struct **rte\_vhost\_stat\_name**\

### Macros

\#define **VHOST\_USER\_PROTOCOL\_F\_MQ**   0\
 \#define **VHOST\_USER\_F\_PROTOCOL\_FEATURES**   30\
 \#define **RTE\_VHOST\_STATS\_NAME\_SIZE**   64\

### Typedefs

**typedef** enum **rte\_vhost\_msg\_result**(\* **rte\_vhost\_msg\_handle**) (int vid, void \*msg)\

### Enumerations

enum **rte\_vhost\_msg\_result** \

### Functions

static **\_\_rte\_always\_inline** uint64\_t **rte\_vhost\_va\_from\_guest\_pa** (struct **rte\_vhost\_memory** \*mem, uint64\_t gpa, uint64\_t \*len)\
 void **rte\_vhost\_log\_write** (int vid, uint64\_t addr, uint64\_t len)\
 void **rte\_vhost\_log\_used\_vring** (int vid, uint16\_t vring\_idx, uint64\_t offset, uint64\_t len)\
 \_\_rte\_experimental void **rte\_vhost\_notify\_guest** (int vid, uint16\_t queue\_id)\
 int **rte\_vhost\_driver\_register** (const char \*path, uint64\_t flags)\
 int **rte\_vhost\_driver\_attach\_vdpa\_device** (const char \*path, struct rte\_vdpa\_device \*dev)\
 int **rte\_vhost\_driver\_detach\_vdpa\_device** (const char \*path)\
 struct rte\_vdpa\_device \* **rte\_vhost\_driver\_get\_vdpa\_device** (const char \*path)\
 int **rte\_vhost\_driver\_get\_vdpa\_dev\_type** (const char \*path, uint32\_t \*type)\
 int **rte\_vhost\_driver\_set\_features** (const char \*path, uint64\_t features)\
 int **rte\_vhost\_driver\_enable\_features** (const char \*path, uint64\_t features)\
 int **rte\_vhost\_driver\_disable\_features** (const char \*path, uint64\_t features)\
 int **rte\_vhost\_driver\_get\_features** (const char \*path, uint64\_t \*features)\
 int **rte\_vhost\_driver\_set\_protocol\_features** (const char \*path, uint64\_t protocol\_features)\
 int **rte\_vhost\_driver\_get\_protocol\_features** (const char \*path, uint64\_t \*protocol\_features)\
 int **rte\_vhost\_driver\_get\_queue\_num** (const char \*path, uint32\_t \*queue\_num)\
 int **rte\_vhost\_driver\_set\_max\_queue\_num** (const char \*path, uint32\_t max\_queue\_pairs)\
 int **rte\_vhost\_get\_negotiated\_features** (int vid, uint64\_t \*features)\
 int **rte\_vhost\_get\_negotiated\_protocol\_features** (int vid, uint64\_t \*protocol\_features)\
 int **rte\_vhost\_driver\_start** (const char \*path)\
 int **rte\_vhost\_get\_mtu** (int vid, uint16\_t \*mtu)\
 int **rte\_vhost\_get\_numa\_node** (int vid)\
 uint16\_t **rte\_vhost\_get\_vring\_num** (int vid)\
 int **rte\_vhost\_get\_ifname** (int vid, char \*buf, size\_t len)\
 uint16\_t **rte\_vhost\_avail\_entries** (int vid, uint16\_t queue\_id)\
 uint16\_t **rte\_vhost\_enqueue\_burst** (int vid, uint16\_t queue\_id, struct **rte\_mbuf** \*\*pkts, uint16\_t count)\
 uint16\_t **rte\_vhost\_dequeue\_burst** (int vid, uint16\_t queue\_id, struct **rte\_mempool** \*mbuf\_pool, struct **rte\_mbuf** \*\*pkts, uint16\_t count)\
 int **rte\_vhost\_get\_mem\_table** (int vid, struct **rte\_vhost\_memory** \*\*mem)\
 int **rte\_vhost\_get\_vhost\_vring** (int vid, uint16\_t vring\_idx, struct rte\_vhost\_vring \*vring)\
 int **rte\_vhost\_get\_vhost\_ring\_inflight** (int vid, uint16\_t vring\_idx, struct rte\_vhost\_ring\_inflight \*vring)\
 int **rte\_vhost\_set\_inflight\_desc\_split** (int vid, uint16\_t vring\_idx, uint16\_t idx)\
 int **rte\_vhost\_set\_inflight\_desc\_packed** (int vid, uint16\_t vring\_idx, uint16\_t head, uint16\_t last, uint16\_t \*inflight\_entry)\
 int **rte\_vhost\_set\_last\_inflight\_io\_split** (int vid, uint16\_t vring\_idx, uint16\_t idx)\
 int **rte\_vhost\_set\_last\_inflight\_io\_packed** (int vid, uint16\_t vring\_idx, uint16\_t head)\
 int **rte\_vhost\_clr\_inflight\_desc\_split** (int vid, uint16\_t vring\_idx, uint16\_t last\_used\_idx, uint16\_t idx)\
 int **rte\_vhost\_clr\_inflight\_desc\_packed** (int vid, uint16\_t vring\_idx, uint16\_t head)\
 int **rte\_vhost\_vring\_call** (int vid, uint16\_t vring\_idx)\
 int **rte\_vhost\_vring\_call\_nonblock** (int vid, uint16\_t vring\_idx)\
 uint32\_t **rte\_vhost\_rx\_queue\_count** (int vid, uint16\_t qid)\
 int **rte\_vhost\_get\_monitor\_addr** (int vid, uint16\_t queue\_id, struct **rte\_vhost\_power\_monitor\_cond** \*pmc)\
 int **rte\_vhost\_get\_log\_base** (int vid, uint64\_t \*log\_base, uint64\_t \*log\_size)\
 int **rte\_vhost\_get\_vring\_base** (int vid, uint16\_t queue\_id, uint16\_t \*last\_avail\_idx, uint16\_t \*last\_used\_idx)\
 int **rte\_vhost\_get\_vring\_base\_from\_inflight** (int vid, uint16\_t queue\_id, uint16\_t \*last\_avail\_idx, uint16\_t \*last\_used\_idx)\
 int **rte\_vhost\_set\_vring\_base** (int vid, uint16\_t queue\_id, uint16\_t last\_avail\_idx, uint16\_t last\_used\_idx)\
 int **rte\_vhost\_extern\_callback\_register** (int vid, struct **rte\_vhost\_user\_extern\_ops** const \*const ops, void \*ctx)\
 struct rte\_vdpa\_device \* **rte\_vhost\_get\_vdpa\_device** (int vid)\
 int **rte\_vhost\_backend\_config\_change** (int vid, bool need\_reply)\
 int **rte\_vhost\_vring\_stats\_get\_names** (int vid, uint16\_t queue\_id, struct **rte\_vhost\_stat\_name** \*name, unsigned int size)\
 int **rte\_vhost\_vring\_stats\_get** (int vid, uint16\_t queue\_id, struct **rte\_vhost\_stat** \*stats, unsigned int n)\
 int **rte\_vhost\_vring\_stats\_reset** (int vid, uint16\_t queue\_id)\

## Detailed Description

Interface to vhost-user

Definition in file **rte\_vhost.h**.

## Macro Definition Documentation

### #define VHOST\_USER\_PROTOCOL\_F\_MQ 0

Protocol features.

Definition at line **65** of file **rte\_vhost.h**.

### #define VHOST\_USER\_F\_PROTOCOL\_FEATURES 30

Indicate whether protocol features negotiation is supported.

Definition at line **118** of file **rte\_vhost.h**.

### #define RTE\_VHOST\_STATS\_NAME\_SIZE 64

Maximum name length for the statistics counters

Definition at line **337** of file **rte\_vhost.h**.

## Typedef Documentation

### typedef enum rte\_vhost\_msg\_result(\* rte\_vhost\_msg\_handle) (int vid, void \*msg)

Function prototype for the vhost backend to handle specific vhost user messages.

**Parameters**

*vid* vhost device id \
 *msg* Message pointer.

**Returns**

RTE\_VHOST\_MSG\_RESULT\_OK on success, RTE\_VHOST\_MSG\_RESULT\_REPLY on success with reply, RTE\_VHOST\_MSG\_RESULT\_ERR on failure, RTE\_VHOST\_MSG\_RESULT\_NOT\_HANDLED if message was not handled.

Definition at line **1** of file **rte\_vhost.h**.

## Enumeration Type Documentation

### enum rte\_vhost\_msg\_result

Possible results of the vhost user message handling callbacks

Definition at line **237** of file **rte\_vhost.h**.

## Function Documentation

### static \_\_rte\_always\_inline uint64\_t rte\_vhost\_va\_from\_guest\_pa (struct rte\_vhost\_memory \* mem, uint64\_t gpa, uint64\_t \* len)` [static]`

Convert guest physical address to host virtual address

**Parameters**

*mem* the guest memory regions \
 *gpa* the guest physical address for querying \
 *len* the size of the requested area to map, updated with actual size mapped

**Returns**

the host virtual address on success, 0 on failure

Definition at line **375** of file **rte\_vhost.h**.

### void rte\_vhost\_log\_write (int vid, uint64\_t addr, uint64\_t len)

Log the memory write start with given address.

This function only need be invoked when the live migration starts. Therefore, we won't need call it at all in the most of time. For making the performance impact be minimum, it's suggested to do a check before calling it:

```
   if (unlikely(RTE_VHOST_NEED_LOG(features)))
           rte_vhost_log_write(vid, addr, len);
```

**Parameters**

*vid* vhost device ID \
 *addr* the starting address for write (in guest physical address space) \
 *len* the length to write

### void rte\_vhost\_log\_used\_vring (int vid, uint16\_t vring\_idx, uint64\_t offset, uint64\_t len)

Log the used ring update start at given offset.

Same as rte\_vhost\_log\_write, it's suggested to do a check before calling it:

```
   if (unlikely(RTE_VHOST_NEED_LOG(features)))
           rte_vhost_log_used_vring(vid, vring_idx, offset, len);
```

**Parameters**

*vid* vhost device ID \
 *vring\_idx* the vring index \
 *offset* the offset inside the used ring \
 *len* the length to write

### \_\_rte\_experimental void rte\_vhost\_notify\_guest (int vid, uint16\_t queue\_id)

**Warning**

**EXPERIMENTAL:** this API may change, or be removed, without prior notice.

Inject the offloaded interrupt into the vhost device's queue.

**See also**

guest\_notify vhost device operation

**Parameters**

*vid* vhost device ID \
 *queue\_id* virtio queue index

### int rte\_vhost\_driver\_register (const char \* path, uint64\_t flags)

Register vhost driver. path could be different for multiple instance support.

### int rte\_vhost\_driver\_attach\_vdpa\_device (const char \* path, struct rte\_vdpa\_device \* dev)

Set the vdpa device id, enforce single connection per socket

**Parameters**

*path* The vhost-user socket file path \
 *dev* vDPA device pointer

**Returns**

0 on success, -1 on failure

### int rte\_vhost\_driver\_detach\_vdpa\_device (const char \* path)

Unset the vdpa device id

**Parameters**

*path* The vhost-user socket file path

**Returns**

0 on success, -1 on failure

### struct rte\_vdpa\_device \* rte\_vhost\_driver\_get\_vdpa\_device (const char \* path)

Get the device id

**Parameters**

*path* The vhost-user socket file path

**Returns**

vDPA device pointer, NULL on failure

### int rte\_vhost\_driver\_get\_vdpa\_dev\_type (const char \* path, uint32\_t \* type)

Get the device type of the vdpa device.

**Parameters**

*path* The vhost-user socket file path \
 *type* the device type of the vdpa device

**Returns**

0 on success, -1 on failure

### int rte\_vhost\_driver\_set\_features (const char \* path, uint64\_t features)

Set the feature bits the vhost-user driver supports.

**Parameters**

*path* The vhost-user socket file path \
 *features* Supported features

**Returns**

0 on success, -1 on failure

### int rte\_vhost\_driver\_enable\_features (const char \* path, uint64\_t features)

Enable vhost-user driver features.

Note that

- •

  the param features should be a subset of the feature bits provided by **rte\_vhost\_driver\_set\_features()**.

- •

  it must be invoked before vhost-user negotiation starts.

**Parameters**

*path* The vhost-user socket file path \
 *features* Features to enable

**Returns**

0 on success, -1 on failure

### int rte\_vhost\_driver\_disable\_features (const char \* path, uint64\_t features)

Disable vhost-user driver features.

The two notes at **rte\_vhost\_driver\_enable\_features()** also apply here.

**Parameters**

*path* The vhost-user socket file path \
 *features* Features to disable

**Returns**

0 on success, -1 on failure

### int rte\_vhost\_driver\_get\_features (const char \* path, uint64\_t \* features)

Get the feature bits before feature negotiation.

**Parameters**

*path* The vhost-user socket file path \
 *features* A pointer to store the queried feature bits

**Returns**

0 on success, -1 on failure

### int rte\_vhost\_driver\_set\_protocol\_features (const char \* path, uint64\_t protocol\_features)

Set the protocol feature bits before feature negotiation.

**Parameters**

*path* The vhost-user socket file path \
 *protocol\_features* Supported protocol features

**Returns**

0 on success, -1 on failure

### int rte\_vhost\_driver\_get\_protocol\_features (const char \* path, uint64\_t \* protocol\_features)

Get the protocol feature bits before feature negotiation.

**Parameters**

*path* The vhost-user socket file path \
 *protocol\_features* A pointer to store the queried protocol feature bits

**Returns**

0 on success, -1 on failure

### int rte\_vhost\_driver\_get\_queue\_num (const char \* path, uint32\_t \* queue\_num)

Get the queue number bits before feature negotiation.

**Parameters**

*path* The vhost-user socket file path \
 *queue\_num* A pointer to store the queried queue number bits

**Returns**

0 on success, -1 on failure

### int rte\_vhost\_driver\_set\_max\_queue\_num (const char \* path, uint32\_t max\_queue\_pairs)

Set the maximum number of queue pairs supported by the device. The value set is ignored for Vhost-user backends. It is only taken into account with VDUSE backends.

**Parameters**

*path* The vhost-user socket file path \
 *max\_queue\_pairs* The maximum number of queue pairs

**Returns**

0 on success, -1 on failure

### int rte\_vhost\_get\_negotiated\_features (int vid, uint64\_t \* features)

Get the feature bits after negotiation

**Parameters**

*vid* Vhost device ID \
 *features* A pointer to store the queried feature bits

**Returns**

0 on success, -1 on failure

### int rte\_vhost\_get\_negotiated\_protocol\_features (int vid, uint64\_t \* protocol\_features)

Get the protocol feature bits after negotiation

**Parameters**

*vid* Vhost device ID \
 *protocol\_features* A pointer to store the queried protocol feature bits

**Returns**

0 on success, -1 on failure

### int rte\_vhost\_driver\_start (const char \* path)

Start the vhost-user driver.

This function triggers the vhost-user negotiation.

**Parameters**

*path* The vhost-user socket file path

**Returns**

0 on success, -1 on failure

### int rte\_vhost\_get\_mtu (int vid, uint16\_t \* mtu)

Get the MTU value of the device if set in QEMU.

**Parameters**

*vid* virtio-net device ID \
 *mtu* The variable to store the MTU value

**Returns**

0: success -EAGAIN: device not yet started -ENOTSUP: device does not support MTU feature

### int rte\_vhost\_get\_numa\_node (int vid)

Get the numa node from which the virtio net device's memory is allocated.

**Parameters**

*vid* vhost device ID

**Returns**

The numa node, -1 on failure

### uint16\_t rte\_vhost\_get\_vring\_num (int vid)

Get the number of vrings the device supports.

**Parameters**

*vid* vhost device ID

**Returns**

The number of vrings, 0 on failure

### int rte\_vhost\_get\_ifname (int vid, char \* buf, size\_t len)

Get the virtio net device's ifname, which is the vhost-user socket file path.

**Parameters**

*vid* vhost device ID \
 *buf* The buffer to stored the queried ifname \
 *len* The length of buf

**Returns**

0 on success, -1 on failure

### uint16\_t rte\_vhost\_avail\_entries (int vid, uint16\_t queue\_id)

Get how many avail entries are left in the queue

**Parameters**

*vid* vhost device ID \
 *queue\_id* virtio queue index

**Returns**

num of avail entries left

### uint16\_t rte\_vhost\_enqueue\_burst (int vid, uint16\_t queue\_id, struct rte\_mbuf \*\* pkts, uint16\_t count)

This function adds buffers to the virtio devices RX virtqueue. Buffers can be received from the physical port or from another virtual device. A packet count is returned to indicate the number of packets that were successfully added to the RX queue.

**Parameters**

*vid* vhost device ID \
 *queue\_id* virtio queue index in mq case \
 *pkts* array to contain packets to be enqueued \
 *count* packets num to be enqueued

**Returns**

num of packets enqueued

### uint16\_t rte\_vhost\_dequeue\_burst (int vid, uint16\_t queue\_id, struct rte\_mempool \* mbuf\_pool, struct rte\_mbuf \*\* pkts, uint16\_t count)

This function gets guest buffers from the virtio device TX virtqueue, construct host mbufs, copies guest buffer content to host mbufs and store them in pkts to be processed.

**Parameters**

*vid* vhost device ID \
 *queue\_id* virtio queue index in mq case \
 *mbuf\_pool* mbuf\_pool where host mbuf is allocated. \
 *pkts* array to contain packets to be dequeued \
 *count* packets num to be dequeued

**Returns**

num of packets dequeued

### int rte\_vhost\_get\_mem\_table (int vid, struct rte\_vhost\_memory \*\* mem)

Get guest mem table: a list of memory regions.

An rte\_vhost\_vhost\_memory object will be allocated internally, to hold the guest memory regions. Application should free it at destroy\_device() callback.

**Parameters**

*vid* vhost device ID \
 *mem* To store the returned mem regions

**Returns**

0 on success, -1 on failure

### int rte\_vhost\_get\_vhost\_vring (int vid, uint16\_t vring\_idx, struct rte\_vhost\_vring \* vring)

Get guest vring info, including the vring address, vring size, etc.

**Parameters**

*vid* vhost device ID \
 *vring\_idx* vring index \
 *vring* the structure to hold the requested vring info

**Returns**

0 on success, -1 on failure

### int rte\_vhost\_get\_vhost\_ring\_inflight (int vid, uint16\_t vring\_idx, struct rte\_vhost\_ring\_inflight \* vring)

Get guest inflight vring info, including inflight ring and resubmit list.

**Parameters**

*vid* vhost device ID \
 *vring\_idx* vring index \
 *vring* the structure to hold the requested inflight vring info

**Returns**

0 on success, -1 on failure

### int rte\_vhost\_set\_inflight\_desc\_split (int vid, uint16\_t vring\_idx, uint16\_t idx)

Set split inflight descriptor.

This function save descriptors that has been consumed in available ring

**Parameters**

*vid* vhost device ID \
 *vring\_idx* vring index \
 *idx* inflight entry index

**Returns**

0 on success, -1 on failure

### int rte\_vhost\_set\_inflight\_desc\_packed (int vid, uint16\_t vring\_idx, uint16\_t head, uint16\_t last, uint16\_t \* inflight\_entry)

Set packed inflight descriptor and get corresponding inflight entry

This function save descriptors that has been consumed

**Parameters**

*vid* vhost device ID \
 *vring\_idx* vring index \
 *head* head of descriptors \
 *last* last of descriptors \
 *inflight\_entry* corresponding inflight entry

**Returns**

0 on success, -1 on failure

### int rte\_vhost\_set\_last\_inflight\_io\_split (int vid, uint16\_t vring\_idx, uint16\_t idx)

Save the head of list that the last batch of used descriptors.

**Parameters**

*vid* vhost device ID \
 *vring\_idx* vring index \
 *idx* descriptor entry index

**Returns**

0 on success, -1 on failure

### int rte\_vhost\_set\_last\_inflight\_io\_packed (int vid, uint16\_t vring\_idx, uint16\_t head)

Update the inflight free\_head, used\_idx and used\_wrap\_counter.

This function will update status first before updating descriptors to used

**Parameters**

*vid* vhost device ID \
 *vring\_idx* vring index \
 *head* head of descriptors

**Returns**

0 on success, -1 on failure

### int rte\_vhost\_clr\_inflight\_desc\_split (int vid, uint16\_t vring\_idx, uint16\_t last\_used\_idx, uint16\_t idx)

Clear the split inflight status.

**Parameters**

*vid* vhost device ID \
 *vring\_idx* vring index \
 *last\_used\_idx* last used idx of used ring \
 *idx* inflight entry index

**Returns**

0 on success, -1 on failure

### int rte\_vhost\_clr\_inflight\_desc\_packed (int vid, uint16\_t vring\_idx, uint16\_t head)

Clear the packed inflight status.

**Parameters**

*vid* vhost device ID \
 *vring\_idx* vring index \
 *head* inflight entry index

**Returns**

0 on success, -1 on failure

### int rte\_vhost\_vring\_call (int vid, uint16\_t vring\_idx)

Notify the guest that used descriptors have been added to the vring. This function acts as a memory barrier.

**Parameters**

*vid* vhost device ID \
 *vring\_idx* vring index

**Returns**

0 on success, -1 on failure

### int rte\_vhost\_vring\_call\_nonblock (int vid, uint16\_t vring\_idx)

Notify the guest that used descriptors have been added to the vring. This function acts as a memory barrier. This function will return -EAGAIN when vq's access lock is held by other thread, user should try again later.

**Parameters**

*vid* vhost device ID \
 *vring\_idx* vring index

**Returns**

0 on success, -1 on failure, -EAGAIN for another retry

### uint32\_t rte\_vhost\_rx\_queue\_count (int vid, uint16\_t qid)

Get vhost RX queue avail count.

**Parameters**

*vid* vhost device ID \
 *qid* virtio queue index in mq case

**Returns**

num of desc available

### int rte\_vhost\_get\_monitor\_addr (int vid, uint16\_t queue\_id, struct rte\_vhost\_power\_monitor\_cond \* pmc)

Get power monitor address of the vhost device

**Parameters**

*vid* vhost device ID \
 *queue\_id* vhost queue ID \
 *pmc* power monitor condition

**Returns**

0 on success, -1 on failure

### int rte\_vhost\_get\_log\_base (int vid, uint64\_t \* log\_base, uint64\_t \* log\_size)

Get log base and log size of the vhost device

**Parameters**

*vid* vhost device ID \
 *log\_base* vhost log base \
 *log\_size* vhost log size

**Returns**

0 on success, -1 on failure

### int rte\_vhost\_get\_vring\_base (int vid, uint16\_t queue\_id, uint16\_t \* last\_avail\_idx, uint16\_t \* last\_used\_idx)

Get last\_avail/used\_idx of the vhost virtqueue

**Parameters**

*vid* vhost device ID \
 *queue\_id* vhost queue index \
 *last\_avail\_idx* vhost last\_avail\_idx to get \
 *last\_used\_idx* vhost last\_used\_idx to get

**Returns**

0 on success, -1 on failure

### int rte\_vhost\_get\_vring\_base\_from\_inflight (int vid, uint16\_t queue\_id, uint16\_t \* last\_avail\_idx, uint16\_t \* last\_used\_idx)

Get last\_avail/last\_used of the vhost virtqueue

This function is designed for the reconnection and it's specific for the packed ring as we can get the two parameters from the inflight queueregion

**Parameters**

*vid* vhost device ID \
 *queue\_id* vhost queue index \
 *last\_avail\_idx* vhost last\_avail\_idx to get \
 *last\_used\_idx* vhost last\_used\_idx to get

**Returns**

0 on success, -1 on failure

### int rte\_vhost\_set\_vring\_base (int vid, uint16\_t queue\_id, uint16\_t last\_avail\_idx, uint16\_t last\_used\_idx)

Set last\_avail/used\_idx of the vhost virtqueue

**Parameters**

*vid* vhost device ID \
 *queue\_id* vhost queue index \
 *last\_avail\_idx* last\_avail\_idx to set \
 *last\_used\_idx* last\_used\_idx to set

**Returns**

0 on success, -1 on failure

### int rte\_vhost\_extern\_callback\_register (int vid, struct rte\_vhost\_user\_extern\_ops const \*const ops, void \* ctx)

Register external message handling callbacks

**Parameters**

*vid* vhost device ID \
 *ops* virtio external callbacks to register \
 *ctx* additional context passed to the callbacks

**Returns**

0 on success, -1 on failure

### struct rte\_vdpa\_device \* rte\_vhost\_get\_vdpa\_device (int vid)

Get vdpa device id for vhost device.

**Parameters**

*vid* vhost device id

**Returns**

vDPA device pointer on success, NULL on failure

### int rte\_vhost\_backend\_config\_change (int vid, bool need\_reply)

Notify the guest that should get virtio configuration space from backend.

**Parameters**

*vid* vhost device ID \
 *need\_reply* wait for the frontend response the status of this operation

**Returns**

0 on success, \< 0 on failure

### int rte\_vhost\_vring\_stats\_get\_names (int vid, uint16\_t queue\_id, struct rte\_vhost\_stat\_name \* name, unsigned int size)

Retrieve names of statistics of a Vhost virtqueue.

There is an assumption that 'stat\_names' and 'stats' arrays are matched by array index: stats\_names\[i\].name =\> stats\[i\].value

**Parameters**

*vid* vhost device ID \
 *queue\_id* vhost queue index \
 *name* array of at least size elements to be filled. If set to NULL, the function returns the required number of elements. \
 *size* The number of elements in stats\_names array.

**Returns**

- •

  Success if greater than 0 and lower or equal to *size*. The return value indicates the number of elements filled in the *names* array.

- •

  Failure if greater than *size*. The return value indicates the number of elements the *names* array that should be given to succeed.

- •

  Failure if lower than 0. The device ID or queue ID is invalid or

- •

  statistics collection is not enabled.

### int rte\_vhost\_vring\_stats\_get (int vid, uint16\_t queue\_id, struct rte\_vhost\_stat \* stats, unsigned int n)

Retrieve statistics of a Vhost virtqueue.

There is an assumption that 'stat\_names' and 'stats' arrays are matched by array index: stats\_names\[i\].name =\> stats\[i\].value

**Parameters**

*vid* vhost device ID \
 *queue\_id* vhost queue index \
 *stats* A pointer to a table of structure of type **rte\_vhost\_stat** to be filled with virtqueue statistics ids and values. \
 *n* The number of elements in stats array.

**Returns**

- •

  Success if greater than 0 and lower or equal to *n*. The return value indicates the number of elements filled in the *stats* array.

- •

  Failure if greater than *n*. The return value indicates the number of elements the *stats* array that should be given to succeed.

- •

  Failure if lower than 0. The device ID or queue ID is invalid, or statistics collection is not enabled.

### int rte\_vhost\_vring\_stats\_reset (int vid, uint16\_t queue\_id)

Reset statistics of a Vhost virtqueue.

**Parameters**

*vid* vhost device ID \
 *queue\_id* vhost queue index

**Returns**

- •

  Success if 0. Statistics have been reset.

- •

  Failure if lower than 0. The device ID or queue ID is invalid, or statistics collection is not enabled.

## Author

Generated automatically by Doxygen for DPDK from the source code.
