#include <sys/types.h>
#include <sys/stat.h>
+#include <rte_string_fns.h>
#include <rte_eal_memconfig.h>
#include "vhost.h"
int
virtio_user_start_device(struct virtio_user_dev *dev)
{
- struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
uint64_t features;
int ret;
* replaced when we get proper supports from the
* memory subsystem in the future.
*/
- rte_rwlock_read_lock(&mcfg->memory_hotplug_lock);
+ rte_mcfg_mem_read_lock();
pthread_mutex_lock(&dev->mutex);
if (is_vhost_user_by_type(dev->path) && dev->vhostfd < 0)
dev->started = true;
pthread_mutex_unlock(&dev->mutex);
- rte_rwlock_read_unlock(&mcfg->memory_hotplug_lock);
+ rte_mcfg_mem_read_unlock();
return 0;
error:
pthread_mutex_unlock(&dev->mutex);
- rte_rwlock_read_unlock(&mcfg->memory_hotplug_lock);
+ rte_mcfg_mem_read_unlock();
/* TODO: free resource here or caller to check */
return -1;
}
static inline void
parse_mac(struct virtio_user_dev *dev, const char *mac)
{
- int i, r;
- uint32_t tmp[ETHER_ADDR_LEN];
+ struct rte_ether_addr tmp;
if (!mac)
return;
- r = sscanf(mac, "%x:%x:%x:%x:%x:%x", &tmp[0],
- &tmp[1], &tmp[2], &tmp[3], &tmp[4], &tmp[5]);
- if (r == ETHER_ADDR_LEN) {
- for (i = 0; i < ETHER_ADDR_LEN; ++i)
- dev->mac_addr[i] = (uint8_t)tmp[i];
+ if (rte_ether_unformat_addr(mac, &tmp) == 0) {
+ memcpy(dev->mac_addr, &tmp, RTE_ETHER_ADDR_LEN);
dev->mac_specified = 1;
} else {
/* ignore the wrong mac, use random mac */
int
virtio_user_dev_init(struct virtio_user_dev *dev, char *path, int queues,
int cq, int queue_size, const char *mac, char **ifname,
- int mrg_rxbuf, int in_order, int packed_vq)
+ int server, int mrg_rxbuf, int in_order, int packed_vq)
{
pthread_mutex_init(&dev->mutex, NULL);
- snprintf(dev->path, PATH_MAX, "%s", path);
+ strlcpy(dev->path, path, PATH_MAX);
dev->started = 0;
dev->max_queue_pairs = queues;
dev->queue_pairs = 1; /* mq disabled by default */
dev->queue_size = queue_size;
+ dev->is_server = server;
dev->mac_specified = 0;
dev->frontend_features = 0;
dev->unsupported_features = ~VIRTIO_USER_SUPPORTED_FEATURES;
static inline int
desc_is_avail(struct vring_packed_desc *desc, bool wrap_counter)
{
- return wrap_counter == !!(desc->flags & VRING_DESC_F_AVAIL(1)) &&
- wrap_counter != !!(desc->flags & VRING_DESC_F_USED(1));
+ uint16_t flags = desc->flags;
+
+ return wrap_counter == !!(flags & VRING_PACKED_DESC_F_AVAIL) &&
+ wrap_counter != !!(flags & VRING_PACKED_DESC_F_USED);
}
static uint32_t
{
struct virtio_user_queue *vq = &dev->packed_queues[queue_idx];
struct vring_packed *vring = &dev->packed_vrings[queue_idx];
- uint16_t n_descs;
+ uint16_t n_descs, flags;
while (desc_is_avail(&vring->desc[vq->used_idx],
vq->used_wrap_counter)) {
n_descs = virtio_user_handle_ctrl_msg_packed(dev, vring,
vq->used_idx);
+ flags = VRING_DESC_F_WRITE;
+ if (vq->used_wrap_counter)
+ flags |= VRING_PACKED_DESC_F_AVAIL_USED;
+
rte_smp_wmb();
- vring->desc[vq->used_idx].flags =
- VRING_DESC_F_WRITE |
- VRING_DESC_F_AVAIL(vq->used_wrap_counter) |
- VRING_DESC_F_USED(vq->used_wrap_counter);
+ vring->desc[vq->used_idx].flags = flags;
vq->used_idx += n_descs;
if (vq->used_idx >= dev->queue_size) {