mirror of
https://passt.top/passt
synced 2025-02-09 20:51:27 +00:00
vhost-user: add VHOST_USER_SET_LOG_FD command
VHOST_USER_SET_LOG_FD is an optional message with an eventfd in ancillary data, it may be used to inform the front-end that the log has been modified. Signed-off-by: Laurent Vivier <lvivier@redhat.com>
This commit is contained in:
parent
12c90b9e03
commit
749a3db471
56
vhost_user.c
56
vhost_user.c
@ -504,6 +504,57 @@ static bool vu_set_mem_table_exec(struct vu_dev *vdev,
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* vu_close_log() - Close the logging file descriptor
|
||||||
|
* @vdev: vhost-user device
|
||||||
|
*/
|
||||||
|
static void vu_close_log(struct vu_dev *vdev)
|
||||||
|
{
|
||||||
|
if (vdev->log_call_fd != -1) {
|
||||||
|
close(vdev->log_call_fd);
|
||||||
|
vdev->log_call_fd = -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* vu_log_kick() - Inform the front-end that the log has been modified
|
||||||
|
* @vdev: vhost-user device
|
||||||
|
*/
|
||||||
|
/* cppcheck-suppress unusedFunction */
|
||||||
|
void vu_log_kick(const struct vu_dev *vdev)
|
||||||
|
{
|
||||||
|
if (vdev->log_call_fd != -1) {
|
||||||
|
int rc;
|
||||||
|
|
||||||
|
rc = eventfd_write(vdev->log_call_fd, 1);
|
||||||
|
if (rc == -1)
|
||||||
|
die_perror("vhost-user kick eventfd_write()");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* vu_set_log_fd_exec() -- Set the eventfd used to report logging update
|
||||||
|
* @vdev: vhost-user device
|
||||||
|
* @vmsg: vhost-user message
|
||||||
|
*
|
||||||
|
* Return: False as no reply is requested
|
||||||
|
*/
|
||||||
|
static bool vu_set_log_fd_exec(struct vu_dev *vdev,
|
||||||
|
struct vhost_user_msg *msg)
|
||||||
|
{
|
||||||
|
if (msg->fd_num != 1)
|
||||||
|
die("Invalid log_fd message");
|
||||||
|
|
||||||
|
if (vdev->log_call_fd != -1)
|
||||||
|
close(vdev->log_call_fd);
|
||||||
|
|
||||||
|
vdev->log_call_fd = msg->fds[0];
|
||||||
|
|
||||||
|
debug("Got log_call_fd: %d", vdev->log_call_fd);
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* vu_set_vring_num_exec() - Set the size of the queue (vring size)
|
* vu_set_vring_num_exec() - Set the size of the queue (vring size)
|
||||||
* @vdev: vhost-user device
|
* @vdev: vhost-user device
|
||||||
@ -864,8 +915,10 @@ void vu_init(struct ctx *c)
|
|||||||
.notification = true,
|
.notification = true,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
c->vdev->log_call_fd = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* vu_cleanup() - Reset vhost-user device
|
* vu_cleanup() - Reset vhost-user device
|
||||||
* @vdev: vhost-user device
|
* @vdev: vhost-user device
|
||||||
@ -909,6 +962,8 @@ void vu_cleanup(struct vu_dev *vdev)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
vdev->nregions = 0;
|
vdev->nregions = 0;
|
||||||
|
|
||||||
|
vu_close_log(vdev);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -929,6 +984,7 @@ static bool (*vu_handle[VHOST_USER_MAX])(struct vu_dev *vdev,
|
|||||||
[VHOST_USER_GET_QUEUE_NUM] = vu_get_queue_num_exec,
|
[VHOST_USER_GET_QUEUE_NUM] = vu_get_queue_num_exec,
|
||||||
[VHOST_USER_SET_OWNER] = vu_set_owner_exec,
|
[VHOST_USER_SET_OWNER] = vu_set_owner_exec,
|
||||||
[VHOST_USER_SET_MEM_TABLE] = vu_set_mem_table_exec,
|
[VHOST_USER_SET_MEM_TABLE] = vu_set_mem_table_exec,
|
||||||
|
[VHOST_USER_SET_LOG_FD] = vu_set_log_fd_exec,
|
||||||
[VHOST_USER_SET_VRING_NUM] = vu_set_vring_num_exec,
|
[VHOST_USER_SET_VRING_NUM] = vu_set_vring_num_exec,
|
||||||
[VHOST_USER_SET_VRING_ADDR] = vu_set_vring_addr_exec,
|
[VHOST_USER_SET_VRING_ADDR] = vu_set_vring_addr_exec,
|
||||||
[VHOST_USER_SET_VRING_BASE] = vu_set_vring_base_exec,
|
[VHOST_USER_SET_VRING_BASE] = vu_set_vring_base_exec,
|
||||||
|
@ -240,5 +240,6 @@ static inline bool vu_queue_started(const struct vu_virtq *vq)
|
|||||||
void vu_print_capabilities(void);
|
void vu_print_capabilities(void);
|
||||||
void vu_init(struct ctx *c);
|
void vu_init(struct ctx *c);
|
||||||
void vu_cleanup(struct vu_dev *vdev);
|
void vu_cleanup(struct vu_dev *vdev);
|
||||||
|
void vu_log_kick(const struct vu_dev *vdev);
|
||||||
void vu_control_handler(struct vu_dev *vdev, int fd, uint32_t events);
|
void vu_control_handler(struct vu_dev *vdev, int fd, uint32_t events);
|
||||||
#endif /* VHOST_USER_H */
|
#endif /* VHOST_USER_H */
|
||||||
|
2
virtio.h
2
virtio.h
@ -103,6 +103,7 @@ struct vu_dev_region {
|
|||||||
* @regions: Guest shared memory regions
|
* @regions: Guest shared memory regions
|
||||||
* @features: Vhost-user features
|
* @features: Vhost-user features
|
||||||
* @protocol_features: Vhost-user protocol features
|
* @protocol_features: Vhost-user protocol features
|
||||||
|
* @log_call_fd: Eventfd to report logging update
|
||||||
*/
|
*/
|
||||||
struct vu_dev {
|
struct vu_dev {
|
||||||
struct ctx *context;
|
struct ctx *context;
|
||||||
@ -111,6 +112,7 @@ struct vu_dev {
|
|||||||
struct vu_virtq vq[VHOST_USER_MAX_QUEUES];
|
struct vu_virtq vq[VHOST_USER_MAX_QUEUES];
|
||||||
uint64_t features;
|
uint64_t features;
|
||||||
uint64_t protocol_features;
|
uint64_t protocol_features;
|
||||||
|
int log_call_fd;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user