summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichele Paolino <m.paolino@virtualopensystems.com>2024-05-31 15:22:05 +0000
committerMichele Paolino <m.paolino@virtualopensystems.com>2024-06-03 13:59:48 +0000
commit9982da4e9ee4f920c51af694ca813a69979e58e8 (patch)
tree745e501a8ee65e8e871b2e055c62c295ca2d507a
parentc6ee7a5bec9cfc7b5e0c6bb064d2e4d195b60557 (diff)
New adapter version: code refactoringsalmon_18.90.0salmon/18.90.018.90.0
Small code refactoring and optimizations v2: with copyright fixes Bug-AGL: SPEC-4834 Change-Id: Icaee8121f367b21bbdb874a3bc5fc327c5a1ded1 Signed-off-by: Michele Paolino <m.paolino@virtualopensystems.com>
-rw-r--r--Makefile7
-rw-r--r--adapter.c51
-rw-r--r--adapter.h53
-rw-r--r--vhost_loopback.c19
-rw-r--r--vhost_user_blk.c97
-rw-r--r--vhost_user_can.c33
-rw-r--r--vhost_user_can.h4
-rw-r--r--vhost_user_console.c33
-rw-r--r--vhost_user_console.h4
-rw-r--r--vhost_user_gpio.c30
-rw-r--r--vhost_user_gpio.h4
-rw-r--r--vhost_user_input.c18
-rw-r--r--vhost_user_input.h29
-rw-r--r--vhost_user_loopback.c211
-rw-r--r--vhost_user_loopback.h4
-rw-r--r--vhost_user_rng.c48
-rw-r--r--vhost_user_rng.h2
-rw-r--r--vhost_user_sound.c38
-rw-r--r--vhost_user_sound.h4
-rw-r--r--virtio_input.c101
-rw-r--r--virtio_loopback.c45
-rw-r--r--virtio_loopback.h6
-rw-r--r--virtio_rng.c9
-rw-r--r--virtio_rng.h2
24 files changed, 510 insertions, 342 deletions
diff --git a/Makefile b/Makefile
index ae3cf79..33af630 100644
--- a/Makefile
+++ b/Makefile
@@ -18,10 +18,9 @@
# Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-#CFLAGS := -Wall -Wextra -Werror
-#CFLAGS := -Wall -Wextra -Wno-unused-variable -Wno-unused-function
-CFLAGS := -Wno-unused-variable -Wno-unused-function -D_GNU_SOURCE
-CFLAGS = -D_GNU_SOURCE -O2
+#CFLAGS := -Wno-unused-variable -Wno-unused-function -D_GNU_SOURCE
+CFLAGS = -D_GNU_SOURCE -O2 -Wall -Wextra -Werror
+
CC ?=
ifeq ($(ARCH), arm64)
diff --git a/adapter.c b/adapter.c
index ebf3171..c944e1d 100644
--- a/adapter.c
+++ b/adapter.c
@@ -1,5 +1,5 @@
/*
- * Copyright 2022-2023 Virtual Open Systems SAS
+ * Copyright 2022-2024 Virtual Open Systems SAS
*
* Authors:
* Timos Ampelikiotis <t.ampelikiotis@virtualopensystems.com>
@@ -41,24 +41,7 @@
#include <sys/un.h>
/* Project header files */
-#include "virtio_loopback.h"
-#include "vhost_user_loopback.h"
-#include "virtio_rng.h"
-#include "vhost_user_rng.h"
-#include "vhost_user_blk.h"
-#include "vhost_user_input.h"
-#include "vhost_user_gpio.h"
-#include "vhost_user_sound.h"
-#include "vhost_user_can.h"
-#include "vhost_user_console.h"
-
-
-#ifdef DEBUG
-#define DBG(...) printf("adapter: " __VA_ARGS__)
-#else
-#define DBG(...)
-#endif /* DEBUG */
-
+#include "adapter.h"
/* Global variables */
int client_sock;
@@ -66,7 +49,6 @@ struct vhost_dev *dev;
struct adapter_dev *adev;
struct vhost_user *vudev;
-
void vhost_user_adapter_init(void)
{
@@ -99,7 +81,6 @@ void vhost_user_adapter_init(void)
adev->vbus = global_vbus;
}
-
void client(char *sock_path)
{
int rc, len;
@@ -159,11 +140,7 @@ int find_arg(int argc, char **argv, char *str)
int val_device_arg(char *str)
{
- char *adapter_devices[] = {"vrng", "vhurng", "vhublk", "vhuinput",
- "vhusnd", "vhugpio", "vhucan", "vhuconsole"};
- char *vhu_devices[] = {"vhurng", "vhublk", "vhuinput", "vhusnd",
- "vhugpio", "vhucan", "vhuconsole"};
- int adapter_devices_num = 8, i;
+ int adapter_devices_num = ADAPTER_DEVS, i;
for (i = 0; i < adapter_devices_num; i++) {
if (!strcmp(adapter_devices[i], str)) {
@@ -176,9 +153,7 @@ int val_device_arg(char *str)
bool check_vhu_device(char *str)
{
- char *vhu_devices[] = {"vhurng", "vhublk", "vhuinput", "vhusnd",
- "vhugpio", "vhucan", "vhuconsole"};
- int vhu_devices_num = 7, i;
+ int vhu_devices_num = VHU_DEVS, i;
for (i = 0; i < vhu_devices_num; i++) {
if (!strcmp(vhu_devices[i], str)) {
@@ -276,36 +251,38 @@ int main(int argc, char **argv)
/* Initialize the adapter data structures */
vhost_user_adapter_init();
+ /* Get queue number and size from arguments */
+ get_queue_num_size_args(argc, argv, &queue_num, &queue_size);
+
/* Initialize the virtio/vhost-user device */
/* TODO: Switch numbers with name defs */
switch (device_id) {
case 1:
- virtio_rng_realize();
+ virtio_rng_realize(queue_num, queue_size);
break;
case 2:
- vhost_user_rng_realize();
+ vhost_user_rng_realize(queue_num, queue_size);
break;
case 3:
- get_queue_num_size_args(argc, argv, &queue_num, &queue_size);
printf("Running vhublk with num %d and size %d\n",
queue_num, queue_size);
vhost_user_blk_realize(queue_num, queue_size);
break;
case 4:
vhost_user_input_init(global_vdev);
- virtio_input_device_realize();
+ virtio_input_device_realize(queue_num, queue_size);
break;
case 5:
- vus_device_realize();
+ vus_device_realize(queue_num, queue_size);
break;
case 6:
- vu_gpio_device_realize();
+ vu_gpio_device_realize(queue_num, queue_size);
break;
case 7:
- vhost_user_can_realize();
+ vhost_user_can_realize(queue_num, queue_size);
break;
case 8:
- vhost_user_console_realize();
+ vhost_user_console_realize(queue_num, queue_size);
break;
default:
exit(1);
diff --git a/adapter.h b/adapter.h
new file mode 100644
index 0000000..67a64df
--- /dev/null
+++ b/adapter.h
@@ -0,0 +1,53 @@
+/*
+ *
+ * Copyright (c) 2022-2024 Virtual Open Systems SAS.
+ *
+ * Author:
+ * Timos Ampelikiotis <t.ampelikiotis@virtualopensystems.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#ifndef ADAPTER
+#define ADAPTER
+
+/* Project header files */
+#include "virtio_loopback.h"
+#include "vhost_user_loopback.h"
+#include "virtio_rng.h"
+#include "vhost_user_rng.h"
+#include "vhost_user_blk.h"
+#include "vhost_user_input.h"
+#include "vhost_user_gpio.h"
+#include "vhost_user_sound.h"
+#include "vhost_user_can.h"
+#include "vhost_user_console.h"
+
+#ifdef DEBUG
+#define DBG(...) printf("adapter: " __VA_ARGS__)
+#else
+#define DBG(...)
+#endif /* DEBUG */
+
+#define VHU_DEVS 8
+#define ADAPTER_DEVS (VHU_DEVS + 1)
+
+const char *adapter_devices[] = {"vrng", "vhurng", "vhublk", "vhuinput",
+ "vhusnd", "vhugpio", "vhucan",
+ "vhuconsole" };
+const char *vhu_devices[] = {"vhurng", "vhublk", "vhuinput", "vhusnd",
+ "vhugpio", "vhucan", "vhuconsole"};
+
+#endif /* ADAPTER */
diff --git a/vhost_loopback.c b/vhost_loopback.c
index e29707e..5fd3b05 100644
--- a/vhost_loopback.c
+++ b/vhost_loopback.c
@@ -68,7 +68,8 @@
*/
int vhost_dev_enable_notifiers(struct vhost_dev *hdev, VirtIODevice *vdev)
{
- int i, r, e;
+ unsigned int i;
+ int r;
/*
* We will pass the notifiers to the kernel, make sure that QEMU
@@ -224,7 +225,6 @@ static int vhost_virtqueue_start(struct vhost_dev *dev,
struct vhost_virtqueue *vq,
unsigned idx)
{
- VirtioBus *vbus = vdev->vbus;
uint64_t s, l, a;
int r;
@@ -240,21 +240,21 @@ static int vhost_virtqueue_start(struct vhost_dev *dev,
a = virtio_queue_get_desc_addr(vdev, idx);
if (a == 0) {
/* Queue might not be ready for start */
- DBG("Error: Queue (%d) might not be ready for start\n", idx);
+ DBG("Warn: Queue (%d) might not be ready for start\n", idx);
return 0;
}
vq->num = state.num = virtio_queue_get_num(vdev, idx);
r = vhost_user_set_vring_num(dev, &state);
- if (r) {
+ if (r < 0) {
DBG("vhost_set_vring_num failed\n");
return r;
}
state.num = virtio_queue_get_last_avail_idx(vdev, idx);
r = vhost_user_set_vring_base(dev, &state);
- if (r) {
+ if (r < 0) {
DBG("vhost_set_vring_base failed\n");
return r;
}
@@ -300,7 +300,7 @@ static int vhost_virtqueue_start(struct vhost_dev *dev,
file.fd = event_notifier_get_fd(virtio_queue_get_host_notifier(vvq));
r = vhost_user_set_vring_kick(&file);
- if (r) {
+ if (r < 0) {
DBG("vhost_set_vring_kick failed\n");
return r;
}
@@ -350,7 +350,8 @@ static int vhost_dev_set_vring_enable(struct vhost_dev *hdev, int enable)
/* Host notifiers must be enabled at this point. */
int vhost_dev_start(struct vhost_dev *hdev, VirtIODevice *vdev, bool vrings)
{
- int i, r;
+ unsigned int i;
+ int r;
hdev->started = true;
hdev->vdev = vdev;
@@ -444,9 +445,9 @@ int vhost_dev_set_inflight(struct vhost_dev *dev,
if (inflight->addr) {
r = vhost_user_set_inflight_fd(dev, inflight);
- if (r) {
+ if (r < 0) {
DBG("vhost_set_inflight_fd failed\n");
- return -1;
+ return r;
}
}
diff --git a/vhost_user_blk.c b/vhost_user_blk.c
index d182a74..f0ae3d4 100644
--- a/vhost_user_blk.c
+++ b/vhost_user_blk.c
@@ -54,7 +54,8 @@ static int vhost_user_blk_start(VirtIODevice *vdev)
{
VHostUserBlk *s = vdev->vhublk;
VirtioBus *k = vdev->vbus;
- int i, ret;
+ unsigned int i;
+ int ret;
DBG("vhost_user_blk_start\n");
@@ -102,7 +103,7 @@ static int vhost_user_blk_start(VirtIODevice *vdev)
DBG("After vhost_dev_set_inflight\n");
- ret = vhost_dev_start(s->vhost_dev, vdev, false);
+ ret = vhost_dev_start(s->vhost_dev, vdev, true);
if (ret < 0) {
DBG("Error starting vhost\n");
return ret;
@@ -110,6 +111,7 @@ static int vhost_user_blk_start(VirtIODevice *vdev)
s->started_vu = true;
+
DBG("vhost_virtqueue_mask\n");
/*
* guest_notifier_mask/pending not used yet, so just unmask
@@ -125,11 +127,6 @@ static int vhost_user_blk_start(VirtIODevice *vdev)
}
-static void vhost_user_blk_stop(VirtIODevice *vdev)
-{
- DBG("Not yet implemented\n");
-}
-
static int vhost_user_blk_handle_config_change(struct vhost_dev *dev)
{
int ret;
@@ -156,12 +153,10 @@ static int vhost_user_blk_handle_config_change(struct vhost_dev *dev)
return 0;
}
-
const VhostDevConfigOps blk_ops = {
.vhost_dev_config_notifier = vhost_user_blk_handle_config_change,
};
-
static uint64_t vhost_user_blk_get_features(VirtIODevice *vdev,
uint64_t features)
{
@@ -205,7 +200,6 @@ static uint64_t vhost_user_blk_get_features(VirtIODevice *vdev,
static int vhost_user_blk_connect(VirtIODevice *vdev)
{
VHostUserBlk *s = vdev->vhublk;
- int ret = 0;
DBG("vhost_user_blk_connect(...)\n");
@@ -213,6 +207,7 @@ static int vhost_user_blk_connect(VirtIODevice *vdev)
DBG("s->connected\n");
return 0;
}
+
s->connected = true;
s->vhost_dev->num_queues = s->num_queues;
s->vhost_dev->nvqs = s->num_queues;
@@ -220,6 +215,8 @@ static int vhost_user_blk_connect(VirtIODevice *vdev)
s->vhost_dev->vq_index = 0;
s->vhost_dev->backend_features = 0;
+ DBG("s->vhost_dev->nvqs: %d\n", s->vhost_dev->nvqs);
+
vhost_dev_set_config_notifier(s->vhost_dev, &blk_ops);
vhost_dev_init(s->vhost_dev);
@@ -235,34 +232,39 @@ static int vhost_user_blk_connect(VirtIODevice *vdev)
DBG("After init global_vdev->host_features: 0x%lx\n",
global_vdev->host_features);
- /* Restore vhost state */
- if (virtio_device_started(vdev, vdev->status)) {
- ret = vhost_user_blk_start(vdev);
- if (ret < 0) {
- DBG("vhost_user_blk_start failed\n");
- return ret;
- }
- }
-
DBG("vhost_user_blk_connect return successfully!\n");
return 0;
}
-static void vhost_user_blk_disconnect(VirtIODevice *dev)
-{
- DBG("vhost_user_blk_disconnect not yet implemented\n");
-}
-
-static void vhost_user_blk_chr_closed_bh(void *opaque)
-{
- DBG("vhost_user_blk_chr_closed_bh not yet implemented\n");
-}
-
-static void vhost_user_blk_event(void *opaque)
-{
- DBG("vhost_user_blk_event not yet implemented");
-}
+/*
+ * These functions will be used in the future:
+ *
+ * static void vhost_user_blk_stop(VirtIODevice *vdev)
+ * {
+ * DBG("Not yet implemented\n");
+ * (void)vdev;
+ * }
+ *
+ * static void vhost_user_blk_disconnect(VirtIODevice *dev)
+ * {
+ * DBG("vhost_user_blk_disconnect not yet implemented\n");
+ * (void)dev;
+ * }
+ *
+ * static void vhost_user_blk_chr_closed_bh(void *opaque)
+ * {
+ * DBG("vhost_user_blk_chr_closed_bh not yet implemented\n");
+ * (void)opaque;
+ * }
+ *
+ * static void vhost_user_blk_event(void *opaque)
+ * {
+ * DBG("vhost_user_blk_event not yet implemented");
+ * (void)opaque;
+ * }
+ *
+ */
static int vhost_user_blk_realize_connect(VHostUserBlk *s)
{
@@ -287,24 +289,34 @@ static int vhost_user_blk_realize_connect(VHostUserBlk *s)
return ret;
}
+ if (global_vdev->vhublk->config_wce != s->blkcfg.wce) {
+ s->blkcfg.wce = global_vdev->vhublk->config_wce;
+
+ ret = vhost_dev_set_config(s->vhost_dev, (uint8_t *)&s->blkcfg.wce,
+ offsetof(struct virtio_blk_config, wce),
+ sizeof(s->blkcfg.wce),
+ VHOST_SET_CONFIG_TYPE_MASTER);
+ if (ret < 0) {
+ DBG("set device config space failed\n");
+ return ret;
+ }
+ }
+
return 0;
}
-
static void vhost_user_blk_device_unrealize(VirtIODevice *vdev)
{
DBG("vhost_user_blk_device_unrealize not yet implemented\n");
+ (void)vdev;
}
static void vhost_user_blk_reset(VirtIODevice *vdev)
{
DBG("vhost_user_blk_reset not yet implemented\n");
+ (void)vdev;
}
-static void vhost_user_blk_set_config(VirtIODevice *vdev,
- const uint8_t *config);
-
-
static void vhost_user_blk_update_config(VirtIODevice *vdev, uint8_t *config)
{
VHostUserBlk *s = vdev->vhublk;
@@ -334,7 +346,7 @@ static void vhost_user_blk_set_config(VirtIODevice *vdev, const uint8_t *config)
offsetof(struct virtio_blk_config, wce),
sizeof(blkcfg->wce),
VHOST_SET_CONFIG_TYPE_MASTER);
- if (ret) {
+ if (ret < 0) {
DBG("set device config space failed\n");
return;
}
@@ -382,6 +394,7 @@ static void print_config_blk(uint8_t *config_data)
struct virtio_blk_config *config_strct =
(struct virtio_blk_config *)config_data;
+ (void)config_strct;
DBG("uint64_t capacity: %llu\n", config_strct->capacity);
DBG("uint32_t size_max: %u\n", config_strct->size_max);
DBG("uint32_t seg_max: %u\n", config_strct->seg_max);
@@ -444,7 +457,7 @@ void vhost_user_blk_init(VirtIODevice *vdev)
VHostUserBlk *vhublk = (VHostUserBlk *)malloc(sizeof(VHostUserBlk));
vdev->vhublk = vhublk;
- vdev->nvqs = &dev->nvqs;
+ vdev->nvqs = (int *)&dev->nvqs;
vhublk->parent = vdev;
vhublk->virtqs = vdev->vqs;
vhublk->vhost_dev = dev;
@@ -460,6 +473,8 @@ static void vhost_user_blk_handle_output(VirtIODevice *vdev, VirtQueue *vq)
* however virtio's cleanup path can call this.
*/
DBG("vhost_user_blk_handle_output not yet implemented\n");
+ (void)vdev;
+ (void)vq;
}
void vhost_user_blk_realize(int queue_num, int queue_size)
@@ -483,8 +498,8 @@ void vhost_user_blk_realize(int queue_num, int queue_size)
global_vdev->vhublk->config_wce = 1;
+ global_vdev->vhublk->vhost_dev->nvqs = queue_num;
global_vdev->vhublk->num_queues = queue_num;
-
global_vdev->vhublk->queue_size = queue_size;
/* NOTE: global_vdev->vqs == vhublk->virtqs */
diff --git a/vhost_user_can.c b/vhost_user_can.c
index 8a1b1ae..251eba0 100644
--- a/vhost_user_can.c
+++ b/vhost_user_can.c
@@ -5,7 +5,7 @@
* https://github.com/OpenSynergy/qemu/tree/virtio-can-spec-rfc-v3
*
* Copyright (C) 2021-2023 OpenSynergy GmbH
- * Copyright (c) 2023 Virtual Open Systems SAS.
+ * Copyright (c) 2023-2024 Virtual Open Systems SAS.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -73,7 +73,7 @@ static void vhost_user_can_start(VirtIODevice *vdev)
VHostUserCan *vhucan = vdev->vhucan;
VirtioBus *k = vdev->vbus;
int ret;
- int i;
+ unsigned int i;
DBG("vhost_user_can_start(...)\n");
@@ -111,9 +111,6 @@ static void vhost_user_can_start(VirtIODevice *vdev)
vhost_virtqueue_mask(vhucan->vhost_dev, vdev, i, false);
}
- /* Wait a bit for the vrings to be set in vhost-user-device */
- sleep(1);
-
return;
err_guest_notifiers:
@@ -125,6 +122,7 @@ err_host_notifiers:
static void vhost_user_can_stop(VirtIODevice *vdev)
{
DBG("vhost_user_can_stop: not yet implemented\n");
+ (void)vdev;
}
static void vhost_user_can_set_status(VirtIODevice *vdev, uint8_t status)
@@ -162,6 +160,8 @@ static void vhost_user_can_can_handle_output(VirtIODevice *vdev, VirtQueue *vq)
* however virtio's cleanup path can call this.
*/
DBG("vhost_user_can_can_handle_output: Not yet implemented!\n");
+ (void)vdev;
+ (void)vq;
}
/*
@@ -199,12 +199,14 @@ const VhostDevConfigOps can_config_ops = {
static void vhost_user_can_init(VirtIODevice *vdev);
-void vhost_user_can_realize()
+void vhost_user_can_realize(int queue_num, int queue_size)
{
VirtIODevice *vdev = global_vdev;
int ret;
DBG("vhost_user_can_device_realize\n");
+ (void)queue_num;
+ (void)queue_size;
/* This needs to be added */
proxy = (VirtIOMMIOProxy *)malloc(sizeof(VirtIOMMIOProxy));
@@ -272,22 +274,27 @@ vhost_dev_init_failed:
static void vhost_user_can_device_unrealize(VirtIODevice *vdev)
{
DBG("vhost_user_blk_device_unrealize not yet implemented\n");
+ (void)vdev;
}
-static struct vhost_dev *vhost_user_can_get_vhost(VirtIODevice *vdev)
-{
- VHostUserCan *vhucan = vdev->vhucan;
- return vhucan->vhost_dev;
-}
+/* This funciton might be useful in the future
+ *
+ * static struct vhost_dev *vhost_user_can_get_vhost(VirtIODevice *vdev)
+ * {
+ * VHostUserCan *vhucan = vdev->vhucan;
+ * return vhucan->vhost_dev;
+ * }
+ *
+ */
static void print_config_can(uint8_t *config_data)
{
struct virtio_can_config *config_strct =
(struct virtio_can_config *)config_data;
+ (void)config_strct;
DBG("print_config_can:\n");
- /* # of available physical jacks */
DBG("\tuint16_t status: %u\n", config_strct->status);
}
@@ -312,7 +319,7 @@ static void vhost_user_can_init(VirtIODevice *vdev)
VHostUserCan *vhucan = (VHostUserCan *)malloc(sizeof(VHostUserCan));
vdev->vhucan = vhucan;
- vdev->nvqs = &vdev->vhdev->nvqs;
+ vdev->nvqs = (int *)&vdev->vhdev->nvqs;
vhucan->parent = vdev;
vhucan->virtqs = vdev->vqs;
vhucan->vhost_dev = vdev->vhdev;
diff --git a/vhost_user_can.h b/vhost_user_can.h
index 6e2e5d5..4f37b85 100644
--- a/vhost_user_can.h
+++ b/vhost_user_can.h
@@ -5,7 +5,7 @@
* https://github.com/OpenSynergy/qemu/tree/virtio-can-spec-rfc-v3
*
* Copyright (C) 2021-2023 OpenSynergy GmbH
- * Copyright (c) 2023 Virtual Open Systems SAS.
+ * Copyright (c) 2023-2024 Virtual Open Systems SAS.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -52,6 +52,6 @@ typedef struct VHostUserCan {
bool support_can_fd;
} VHostUserCan;
-void vhost_user_can_realize(void);
+void vhost_user_can_realize(int queue_num, int queue_size);
#endif /* VHOST_USER_CAN */
diff --git a/vhost_user_console.c b/vhost_user_console.c
index 8552b91..2997b8d 100644
--- a/vhost_user_console.c
+++ b/vhost_user_console.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2023 Virtual Open Systems SAS.
+ * Copyright (c) 2023-2024 Virtual Open Systems SAS.
*
* This work is licensed under the terms of the GNU GPL, version 2 or
* (at your option) any later version. See the COPYING file in the
@@ -47,8 +47,8 @@ static void vhost_user_console_start(VirtIODevice *vdev)
{
VHostUserConsole *vhuconsole = vdev->vhuconsole;
VirtioBus *k = vdev->vbus;
+ unsigned int i;
int ret;
- int i;
DBG("vhost_user_console_start(...)\n");
@@ -86,9 +86,6 @@ static void vhost_user_console_start(VirtIODevice *vdev)
vhost_virtqueue_mask(vhuconsole->vhost_dev, vdev, i, false);
}
- /* Wait a bit for the vrings to be set in vhost-user-device */
- sleep(1);
-
return;
err_guest_notifiers:
@@ -100,6 +97,7 @@ err_host_notifiers:
static void vhost_user_console_stop(VirtIODevice *vdev)
{
DBG("vhost_user_console_stop: not yet implemented\n");
+ (void)vdev;
}
static void vhost_user_console_set_status(VirtIODevice *vdev, uint8_t status)
@@ -137,6 +135,8 @@ static void vhost_user_console_handle_output(VirtIODevice *vdev, VirtQueue *vq)
* however virtio's cleanup path console call this.
*/
DBG("vhost_user_console_handle_output: Not yet implemented!\n");
+ (void)vdev;
+ (void)vq;
}
static int vhost_user_console_config_change(struct vhost_dev *dev)
@@ -162,12 +162,14 @@ const VhostDevConfigOps console_config_ops = {
static void vhost_user_console_init(VirtIODevice *vdev);
-void vhost_user_console_realize()
+void vhost_user_console_realize(int queue_num, int queue_size)
{
VirtIODevice *vdev = global_vdev;
int ret;
DBG("vhost_user_console_device_realize\n");
+ (void)queue_num;
+ (void)queue_size;
/* This needs to be added */
proxy = (VirtIOMMIOProxy *)malloc(sizeof(VirtIOMMIOProxy));
@@ -240,19 +242,26 @@ vhost_dev_init_failed:
static void vhost_user_console_device_unrealize(VirtIODevice *vdev)
{
DBG("vhost_user_blk_device_unrealize not yet implemented\n");
+ (void)vdev;
}
-static struct vhost_dev *vhost_user_console_get_vhost(VirtIODevice *vdev)
-{
- VHostUserConsole *vhuconsole = vdev->vhuconsole;
- return vhuconsole->vhost_dev;
-}
+/*
+ * This function might be useful in the future:
+ *
+ * static struct vhost_dev *vhost_user_console_get_vhost(VirtIODevice *vdev)
+ * {
+ * VHostUserConsole *vhuconsole = vdev->vhuconsole;
+ * return vhuconsole->vhost_dev;
+ * }
+ *
+ */
static void print_config_console(uint8_t *config_data)
{
struct virtio_console_config *config_strct =
(struct virtio_console_config *)config_data;
+ (void)config_strct;
DBG("print_config_console:\n");
DBG("\tuint16_t cols: %u\n", config_strct->cols);
DBG("\tuint16_t rows: %u\n", config_strct->rows);
@@ -283,7 +292,7 @@ static void vhost_user_console_init(VirtIODevice *vdev)
VHostUserConsole *vhuconsole =
(VHostUserConsole *)malloc(sizeof(VHostUserConsole));
vdev->vhuconsole = vhuconsole;
- vdev->nvqs = &vdev->vhdev->nvqs;
+ vdev->nvqs = (int *)&vdev->vhdev->nvqs;
vhuconsole->parent = vdev;
vhuconsole->virtqs = vdev->vqs;
vhuconsole->vhost_dev = vdev->vhdev;
diff --git a/vhost_user_console.h b/vhost_user_console.h
index 93646c8..e0e40e0 100644
--- a/vhost_user_console.h
+++ b/vhost_user_console.h
@@ -1,6 +1,6 @@
/*
*
- * Copyright (c) 2023 Virtual Open Systems SAS.
+ * Copyright (c) 2023-2024 Virtual Open Systems SAS.
*
* This work is licensed under the terms of the GNU GPL, version 2 or
* (at your option) any later version. See the COPYING file in the
@@ -65,6 +65,6 @@ typedef struct VHostUserConsole {
VirtQueue *ctrl_tx_vq;
} VHostUserConsole;
-void vhost_user_console_realize(void);
+void vhost_user_console_realize(int queue_num, int queue_size);
#endif /* VHOST_USER_CONSOLE */
diff --git a/vhost_user_gpio.c b/vhost_user_gpio.c
index 6049bd5..66417ae 100644
--- a/vhost_user_gpio.c
+++ b/vhost_user_gpio.c
@@ -3,7 +3,7 @@
*
* Copyright (c) 2022 Viresh Kumar <viresh.kumar@linaro.org>
*
- * Copyright (c) 2023 Virtual Open Systems SAS.
+ * Copyright (c) 2023-2024 Virtual Open Systems SAS.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -56,6 +56,7 @@ static void vu_gpio_get_config(VirtIODevice *vdev, uint8_t *config)
VHostUserGPIO *gpio = dev->vdev->vhugpio;
DBG("vu_gpio_get_config()\n");
+ (void)vdev;
memcpy(config, &gpio->config, sizeof(gpio->config));
}
@@ -79,7 +80,8 @@ static int vu_gpio_start(VirtIODevice *vdev)
{
VirtioBus *k = vdev->vbus;
VHostUserGPIO *gpio = vdev->vhugpio;
- int ret, i;
+ unsigned int i;
+ int ret;
DBG("vu_gpio_start()\n");
@@ -135,6 +137,7 @@ out_with_err_host_notifiers:
static void vu_gpio_stop(VirtIODevice *vdev)
{
DBG("vu_gpio_stop() not yet implemented\n");
+ (void)vdev;
}
static void vu_gpio_set_status(VirtIODevice *vdev, uint8_t status)
@@ -177,6 +180,8 @@ static void vu_gpio_handle_output(VirtIODevice *vdev, VirtQueue *vq)
* however virtio's cleanup path can call this.
*/
DBG("vu_gpio_handle_output not yet implemented\n");
+ (void)vdev;
+ (void)vq;
}
static void vu_gpio_guest_notifier_mask(VirtIODevice *vdev, int idx, bool mask)
@@ -191,12 +196,13 @@ static void vu_gpio_guest_notifier_mask(VirtIODevice *vdev, int idx, bool mask)
static void do_vhost_user_cleanup(VirtIODevice *vdev, VHostUserGPIO *gpio)
{
DBG("do_vhost_user_cleanup() not yet implemented\n");
+ (void)vdev;
+ (void)gpio;
}
static int vu_gpio_connect(VirtIODevice *vdev)
{
VHostUserGPIO *gpio = vdev->vhugpio;
- int ret;
DBG("vu_gpio_connect()\n");
@@ -259,6 +265,7 @@ static int vu_gpio_realize_connect(VHostUserGPIO *gpio)
static void vu_gpio_device_unrealize(VirtIODevice *vdev)
{
DBG("vu_gpio_device_unrealize() not yet implemented\n");
+ (void)vdev;
}
static void print_config_gpio(uint8_t *config_data)
@@ -266,6 +273,7 @@ static void print_config_gpio(uint8_t *config_data)
struct virtio_gpio_config *config =
(struct virtio_gpio_config *)config_data;
+ (void)config;
DBG("ngpio: %hu\n", config->ngpio);
DBG("gpio_names_size: %u\n", config->gpio_names_size);
}
@@ -298,7 +306,7 @@ void vu_gpio_init(VirtIODevice *vdev)
}
vdev->vhugpio = vhugpio;
- vdev->nvqs = &dev->nvqs;
+ vdev->nvqs = (int *)&dev->nvqs;
vhugpio->parent = vdev;
vhugpio->vhost_dev = dev;
@@ -310,12 +318,13 @@ out:
}
/* TODO: Add queue_num, queue_size as parameters */
-void vu_gpio_device_realize()
+void vu_gpio_device_realize(int queue_num, int queue_size)
{
int retries, ret;
- int i;
DBG("vu_gpio_device_realize()\n");
+ (void)queue_num;
+ (void)queue_size;
/* This needs to be added */
proxy = (VirtIOMMIOProxy *)malloc(sizeof(VirtIOMMIOProxy));
@@ -368,9 +377,12 @@ void vu_gpio_device_realize()
return;
- /* TODO: Fix the following considering also do_vhost_user_cleanup() */
-out_with_cmd_vq:
- /* free(global_vdev->vhugpio->command_vq); */
+ /*
+ * TODO: Fix the following considering also do_vhost_user_cleanup()
+ *
+ * out_with_cmd_vq:
+ * free(global_vdev->vhugpio->command_vq);
+ */
out_with_dev:
free(global_vdev->vhugpio);
out_with_proxy:
diff --git a/vhost_user_gpio.h b/vhost_user_gpio.h
index 4477ba7..6d80446 100644
--- a/vhost_user_gpio.h
+++ b/vhost_user_gpio.h
@@ -1,7 +1,7 @@
/*
* Based on virtio-gpio.h of QEMU project
*
- * Copyright (c) 2023 Virtual Open Systems SAS.
+ * Copyright (c) 2023-2024 Virtual Open Systems SAS.
*
* This work is licensed under the terms of the GNU GPL, version 2 or
* (at your option) any later version. See the COPYING file in the
@@ -32,6 +32,6 @@ struct VHostUserGPIO {
bool started_vu;
};
-void vu_gpio_device_realize();
+void vu_gpio_device_realize(int queue_num, int queue_size);
#endif /* VHOST_USER_GPIO */
diff --git a/vhost_user_input.c b/vhost_user_input.c
index 9cb2164..5cb4ca6 100644
--- a/vhost_user_input.c
+++ b/vhost_user_input.c
@@ -29,6 +29,8 @@
static int vhost_input_config_change(struct vhost_dev *dev)
{
DBG("vhost-user-input: unhandled backend config change\n");
+ (void)dev;
+
return -1;
}
@@ -40,8 +42,6 @@ static void vhost_input_change_active(VirtIOInput *vinput)
{
DBG("vhost_input_change_active(...)\n");
- VhostUserInput *vhuinput = global_vdev->vhuinput;
-
if (vinput->active) {
vhost_user_backend_start(global_vdev);
} else {
@@ -77,7 +77,7 @@ static void vhost_input_set_config(VirtIODevice *vdev,
ret = vhost_dev_set_config(vhi->vhost_dev, config_data,
0, sizeof(virtio_input_config),
VHOST_SET_CONFIG_TYPE_MASTER);
- if (ret) {
+ if (ret < 0) {
DBG("vhost_input_set_config failed\n");
return;
}
@@ -96,7 +96,9 @@ static void print_config_input(uint8_t *config_data)
{
struct virtio_input_config *config_strct =
(struct virtio_input_config *)config_data;
+
DBG("print_config_input: Not yet implemented\n");
+ (void)config_strct;
}
static void vhost_input_class_init(VirtIODevice *vdev)
@@ -130,7 +132,7 @@ void vhost_user_input_init(VirtIODevice *vdev)
vdev->vinput->input_class = input_class;
vdev->vhuinput = vhuinput;
- vdev->nvqs = &dev->nvqs;
+ vdev->nvqs = (int*)&dev->nvqs;
vhuinput->vdev = vdev;
vhuinput->vhost_dev = dev;
vhuinput->vdev_input = vinput;
@@ -149,11 +151,13 @@ void vhost_user_input_init(VirtIODevice *vdev)
}
-void vhost_user_input_realize()
+void vhost_user_input_realize(int queue_num, int queue_size)
{
int nvqs = 2; /* qemu choice: 2 */
DBG("vhost_user_input_realize()\n");
+ (void)queue_num;
+ (void)queue_size;
vhost_dev_set_config_notifier(global_vdev->vhuinput->vhost_dev,
&config_ops);
@@ -181,7 +185,8 @@ void vhost_user_input_realize()
void vhost_user_backend_start(VirtIODevice *vdev)
{
VirtioBus *k = vdev->vbus;
- int ret, i;
+ unsigned int i;
+ int ret;
DBG("vhost_user_backend_start(...)\n");
@@ -232,4 +237,5 @@ void vhost_user_backend_start(VirtIODevice *vdev)
void vhost_user_backend_stop(VirtIODevice *vdev)
{
DBG("vhost_user_backend_stop() not yet implemented\n");
+ (void)vdev;
}
diff --git a/vhost_user_input.h b/vhost_user_input.h
index 741006e..23f4ddd 100644
--- a/vhost_user_input.h
+++ b/vhost_user_input.h
@@ -146,39 +146,12 @@ typedef struct VhostUserInput {
*/
#define KEY_G 34
-static struct virtio_input_config virtio_keyboard_config[] = {
- {
- .select = VIRTIO_INPUT_CFG_ID_NAME,
- .size = sizeof(VIRTIO_ID_NAME_KEYBOARD),
- .u.string = VIRTIO_ID_NAME_KEYBOARD,
- },{
- .select = VIRTIO_INPUT_CFG_ID_DEVIDS,
- .size = sizeof(struct virtio_input_devids),
- .u.ids = {
- .bustype = (BUS_VIRTUAL),
- .vendor = (0x0627), /* same we use for usb hid devices */
- .product = (0x0001),
- .version = (0x0001),
- },
- },{
- .select = VIRTIO_INPUT_CFG_EV_BITS,
- .subsel = EV_KEY,
- .size = 1,
- .u.bitmap = {
- KEY_G,
- },
- },
- {}, /* End of list */
-};
-
void vhost_user_backend_start(VirtIODevice *vdev);
void vhost_user_backend_stop(VirtIODevice *vdev);
-
void virtio_input_init_config(VirtIOInput *vinput,
virtio_input_config *config);
void virtio_input_class_init(VirtIODevice *vdev);
-void virtio_input_device_realize();
-
+void virtio_input_device_realize(int queue_num, int queue_size);
void vhost_user_input_init(VirtIODevice *vdev);
void vhost_user_input_realize();
diff --git a/vhost_user_loopback.c b/vhost_user_loopback.c
index 31830ae..1d52f05 100644
--- a/vhost_user_loopback.c
+++ b/vhost_user_loopback.c
@@ -84,7 +84,7 @@ void vmsg_close_fds(VhostUserMsg *vmsg)
}
-bool vu_message_write(int conn_fd, VhostUserMsg *vmsg)
+static int vu_message_write(int conn_fd, VhostUserMsg *vmsg)
{
int rc;
uint8_t *p = (uint8_t *)vmsg;
@@ -134,16 +134,10 @@ bool vu_message_write(int conn_fd, VhostUserMsg *vmsg)
} while (rc < 0 && (errno == EINTR || errno == EAGAIN));
}
- if (rc <= 0) {
- DBG("Error while writing\n");
- return false;
- }
-
- return true;
+ return rc;
}
-
-bool vu_message_read(int conn_fd, VhostUserMsg *vmsg)
+static int vu_message_read(int conn_fd, VhostUserMsg *vmsg)
{
char control[CMSG_SPACE(VHOST_MEMORY_BASELINE_NREGIONS * sizeof(int))] = {};
struct iovec iov = {
@@ -201,12 +195,9 @@ bool vu_message_read(int conn_fd, VhostUserMsg *vmsg)
}
}
- return true;
-
fail:
vmsg_close_fds(vmsg);
-
- return false;
+ return rc;
}
int vhost_user_set_owner(void)
@@ -314,13 +305,14 @@ int enforce_reply(const VhostUserMsg *msg)
int vhost_user_set_u64(int request, uint64_t u64, bool wait_for_reply)
{
+ int ret = 0;
+
VhostUserMsg msg = {
.request = request,
.flags = VHOST_USER_VERSION,
.payload.u64 = u64,
.size = sizeof(msg.payload.u64),
};
- int ret;
print_vhost_user_messages(request);
DBG("\tSet value: 0x%lx\n", u64);
@@ -343,7 +335,7 @@ int vhost_user_set_u64(int request, uint64_t u64, bool wait_for_reply)
return enforce_reply(&msg);
}
- return 0;
+ return ret;
}
int vhost_user_set_features(struct vhost_dev *dev,
@@ -420,8 +412,7 @@ int vhost_setup_slave_channel(struct vhost_dev *dev)
}
ret = vu_message_write(client_sock, &msg);
- if (!ret) {
- DBG("Go out\n");
+ if (ret < 0) {
goto out;
}
@@ -450,9 +441,48 @@ int vhost_user_get_vq_index(struct vhost_dev *dev, int idx)
*
* assert(idx >= dev->vq_index && idx < dev->vq_index + (int)dev->nvqs);
*/
+ (void)dev;
return idx;
}
+static int vhost_user_write_sync(VhostUserMsg *msg,
+ bool wait_for_reply)
+{
+ int ret;
+
+ if (wait_for_reply) {
+ bool reply_supported = virtio_has_feature(dev->protocol_features,
+ VHOST_USER_PROTOCOL_F_REPLY_ACK);
+ if (reply_supported) {
+ msg->flags |= VHOST_USER_NEED_REPLY_MASK;
+ }
+ }
+
+ ret = vu_message_write(client_sock, msg);
+ if (ret < 0) {
+ return ret;
+ }
+
+ if (wait_for_reply) {
+ uint64_t dummy;
+ DBG("Wait for reply\n");
+
+ if (msg->flags & VHOST_USER_NEED_REPLY_MASK) {
+ return process_message_reply(msg);
+ }
+
+ /*
+ * We need to wait for a reply but the backend does not
+ * support replies for the command we just sent.
+ * Send VHOST_USER_GET_FEATURES which makes all backends
+ * send a reply.
+ */
+ return vhost_user_get_features(&dummy);
+ }
+
+ return 0;
+}
+
int vhost_set_vring_file(VhostUserRequest request,
struct vhost_vring_file *file)
{
@@ -465,6 +495,7 @@ int vhost_set_vring_file(VhostUserRequest request,
.size = sizeof(msg.payload.u64),
};
+
if (ioeventfd_enabled() && file->fd > 0) {
fds[fd_num++] = file->fd;
} else {
@@ -483,7 +514,7 @@ int vhost_set_vring_file(VhostUserRequest request,
msg.fd_num = fd_num;
memcpy(msg.fds, &fds, fd_num * sizeof(int));
- return !vu_message_write(client_sock, &msg);
+ return vu_message_write(client_sock, &msg);
}
int vhost_user_set_vring_kick(struct vhost_vring_file *file)
@@ -500,7 +531,8 @@ int vhost_user_set_vring_call(struct vhost_vring_file *file)
static int vhost_set_vring(struct vhost_dev *dev,
unsigned long int request,
- struct vhost_vring_state *ring)
+ struct vhost_vring_state *ring,
+ bool wait_for_reply)
{
VhostUserMsg msg = {
.request = request,
@@ -508,58 +540,36 @@ static int vhost_set_vring(struct vhost_dev *dev,
.payload.state = *ring,
.size = sizeof(msg.payload.state),
};
+ (void)dev;
- return !vu_message_write(client_sock, &msg);
+ return vhost_user_write_sync(&msg, wait_for_reply);
}
int vhost_user_set_vring_num(struct vhost_dev *dev,
struct vhost_vring_state *ring)
{
- return vhost_set_vring(dev, VHOST_USER_SET_VRING_NUM, ring);
+ return vhost_set_vring(dev, VHOST_USER_SET_VRING_NUM, ring, false);
}
int vhost_user_set_vring_base(struct vhost_dev *dev,
struct vhost_vring_state *ring)
{
- return vhost_set_vring(dev, VHOST_USER_SET_VRING_BASE, ring);
+ return vhost_set_vring(dev, VHOST_USER_SET_VRING_BASE, ring, false);
}
int vhost_user_set_vring_addr(struct vhost_dev *dev,
struct vhost_vring_addr *addr)
{
- int ret;
VhostUserMsg msg = {
.request = VHOST_USER_SET_VRING_ADDR,
.flags = VHOST_USER_VERSION,
.payload.addr = *addr,
.size = sizeof(msg.payload.addr),
};
+ (void)dev;
- bool reply_supported = virtio_has_feature(dev->protocol_features,
- VHOST_USER_PROTOCOL_F_REPLY_ACK);
-
- /*
- * wait for a reply if logging is enabled to make sure
- * backend is actually logging changes
- */
- bool wait_for_reply = addr->flags & (1 << VHOST_VRING_F_LOG);
-
- if (reply_supported && wait_for_reply) {
- msg.flags |= VHOST_USER_NEED_REPLY_MASK;
- }
-
- ret = vu_message_write(client_sock, &msg);
- if (ret < 0) {
- DBG("Fail vhost_user_set_vring_addr\n");
- return ret;
- }
-
- if (wait_for_reply) {
- return enforce_reply(&msg);
- }
-
- return 0;
+ return vhost_user_write_sync(&msg, true);
}
@@ -580,7 +590,7 @@ int vhost_virtqueue_init(struct vhost_dev *dev,
file.fd = event_notifier_get_wfd(&vq->masked_notifier);
r = vhost_user_set_vring_call(&file);
- if (r) {
+ if (r < 0) {
DBG("vhost_set_vring_call failed\n");
return r;
}
@@ -615,13 +625,13 @@ int vhost_user_get_config(struct vhost_dev *dev, uint8_t *config,
DBG("vu_message_write return: %d\n", ret);
if (ret < 0) {
DBG("vhost_get_config failed\n");
- return -1;
+ return ret;
}
ret = vu_message_read(client_sock, &msg);
if (ret < 0) {
DBG("vhost_get_config failed\n");
- return -1;
+ return ret;
}
if (msg.request != VHOST_USER_GET_CONFIG) {
@@ -795,7 +805,7 @@ int vhost_user_set_inflight_fd(struct vhost_dev *dev,
msg.fd_num = 1;
memcpy(msg.fds, &inflight->fd, msg.fd_num * sizeof(int));
- return !vu_message_write(client_sock, &msg); /* Returns true or false*/
+ return vu_message_write(client_sock, &msg);
}
@@ -807,7 +817,10 @@ static MemoryRegion *vhost_user_get_mr_data(struct vhost_memory_region *reg,
{
MemoryRegion *mr;
+ (void)reg;
+ mr = (MemoryRegion *)malloc(sizeof(MemoryRegion));
*offset = 0;
+ /* TODO: Dublicate the file descriptor to driscriminate the mmap calls from the driver */
*fd = loopback_fd;
return mr;
@@ -830,7 +843,8 @@ static int vhost_user_fill_set_mem_table_msg(struct vhost_user *u,
int *fds, size_t *fd_num,
bool track_ramblocks)
{
- int i, fd;
+ uint32_t i;
+ int fd;
ram_addr_t offset;
MemoryRegion *mr;
struct vhost_memory_region *reg;
@@ -894,18 +908,22 @@ static void scrub_shadow_regions(struct vhost_dev *dev,
struct vhost_user *u = adev->vudev;
bool found[VHOST_USER_MAX_RAM_SLOTS] = {};
struct vhost_memory_region *reg, *shadow_reg;
- int i, j, fd, add_idx = 0, rm_idx = 0, fd_num = 0;
+ int fd, add_idx = 0, rm_idx = 0, fd_num = 0;
+ uint32_t i, j;
ram_addr_t offset;
MemoryRegion *mr;
bool matching;
+ (void)mr;
+ (void)shadow_pcb;
+ (void)track_ramblocks;
/*
* Find memory regions present in our shadow state which are not in
* the device's current memory state.
*
* Mark regions in both the shadow and device state as "found".
*/
- for (i = 0; i < u->num_shadow_regions; i++) {
+ for (i = 0; i < (uint32_t)u->num_shadow_regions; i++) {
shadow_reg = &u->shadow_regions[i];
matching = false;
@@ -972,12 +990,14 @@ static int send_remove_regions(struct vhost_dev *dev,
int nr_rem_reg, VhostUserMsg *msg,
bool reply_supported)
{
- struct vhost_user *u = adev->vudev;
struct vhost_memory_region *shadow_reg;
- int i, fd, shadow_reg_idx, ret;
+ int i, fd, shadow_reg_idx, ret = 0;
ram_addr_t offset;
VhostUserMemoryRegion region_buffer;
+ (void)ret;
+ (void)dev;
+ (void)shadow_reg_idx;
/*
* The regions in remove_reg appear in the same order they do in the
* shadow table. Therefore we can minimize memory copies by iterating
@@ -999,8 +1019,9 @@ static int send_remove_regions(struct vhost_dev *dev,
msg->fd_num = 1;
memcpy(msg->fds, &loopback_fd, sizeof(int));
- if (vu_message_write(client_sock, msg) < 0) {
- return -1;
+ ret = vu_message_write(client_sock, msg);
+ if (ret < 0) {
+ return ret;
}
if (reply_supported) {
@@ -1018,7 +1039,7 @@ static int send_remove_regions(struct vhost_dev *dev,
}
- return 0;
+ return ret;
}
static int send_add_regions(struct vhost_dev *dev,
@@ -1027,13 +1048,18 @@ static int send_add_regions(struct vhost_dev *dev,
bool reply_supported, bool track_ramblocks)
{
struct vhost_user *u = adev->vudev;
- int i, fd, ret, reg_idx, reg_fd_idx;
+ int i, fd, ret = 0, reg_idx, reg_fd_idx;
struct vhost_memory_region *reg;
MemoryRegion *mr;
ram_addr_t offset;
- VhostUserMsg msg_reply;
VhostUserMemoryRegion region_buffer;
+ (void)dev;
+ (void)shadow_pcb;
+ (void)mr;
+ (void)ret;
+ (void)reg_fd_idx;
+
for (i = 0; i < nr_add_reg; i++) {
reg = add_reg[i].region;
reg_idx = add_reg[i].reg_idx;
@@ -1052,9 +1078,10 @@ static int send_add_regions(struct vhost_dev *dev,
msg->fd_num = 1;
memcpy(msg->fds, &loopback_fd, sizeof(int));
- if (vu_message_write(client_sock, msg) < 0) {
+ ret = vu_message_write(client_sock, msg);
+ if (ret < 0) {
DBG("send_add_regions -> write failed\n");
- return -1;
+ return ret;
}
if (reply_supported) {
@@ -1074,7 +1101,7 @@ static int send_add_regions(struct vhost_dev *dev,
}
}
- return 0;
+ return ret;
}
static int vhost_user_add_remove_regions(struct vhost_dev *dev,
@@ -1127,6 +1154,9 @@ static int vhost_user_set_mem_table_postcopy(struct vhost_dev *dev,
bool reply_supported,
bool config_mem_slots)
{
+ (void)dev;
+ (void)reply_supported;
+ (void)config_mem_slots;
DBG("vhost_user_set_mem_table_postcopy(...) not yet implemented\n");
return 0;
}
@@ -1140,12 +1170,12 @@ int vhost_user_set_mem_table(struct vhost_dev *dev)
{
int fds[VHOST_MEMORY_BASELINE_NREGIONS];
size_t fd_num = 0;
+ int ret = 0;
bool reply_supported = virtio_has_feature(dev->protocol_features,
VHOST_USER_PROTOCOL_F_REPLY_ACK);
bool config_mem_slots =
virtio_has_feature(dev->protocol_features,
VHOST_USER_PROTOCOL_F_CONFIGURE_MEM_SLOTS);
- int ret;
struct vhost_user *u = adev->vudev;
bool do_postcopy = false;
@@ -1185,17 +1215,18 @@ int vhost_user_set_mem_table(struct vhost_dev *dev)
msg.fd_num = fd_num;
memcpy(msg.fds, fds, fd_num * sizeof(int));
- if (vu_message_write(client_sock, &msg) < 0) {
+ ret = vu_message_write(client_sock, &msg);
+ if (ret < 0) {
DBG("vhost_user_set_mem_table failed write msg\n");
- return -1;
+ return ret;
}
if (reply_supported) {
- return process_message_reply(&msg);
+ ret = process_message_reply(&msg);
}
}
- return 0;
+ return ret;
}
@@ -1205,6 +1236,7 @@ void print_mem_table(struct vhost_dev *dev)
struct vhost_memory_region *cur_vmr;
int i;
+ (void)cur_vmr;
DBG("print_mem_table:\n");
for (i = 0; i < dev->n_mem_sections; i++) {
@@ -1286,24 +1318,25 @@ int last_avail = -1;
void find_add_new_reg(struct vhost_dev *dev)
{
int sglist_elem_num;
- int i;
+ uint64_t i, j;
+ (void)sglist_elem_num;
DBG("Total nvqs: %d\n", dev->nvqs);
- for (int i = 0; i < dev->nvqs; i++) {
+ for (i = 0; (unsigned int)i < dev->nvqs; i++) {
VRing *vring = &dev->vdev->vq[i].vring;
uint64_t vring_num = vring->num;
- DBG("For vq[%d]:\n", i);
- DBG("vqs[%u] hpa 0x%lx\n", i, vring_phys_addrs[i]);
- DBG("vq[%d].vring.num: %ld\n", i, vring_num);
+ DBG("For vq[%lu]:\n", i);
+ DBG("vqs[%lu] hpa 0x%lx\n", i, vring_phys_addrs[i]);
+ DBG("vq[%lu].vring.num: %ld\n", i, vring_num);
DBG("We got avail buf: %d\n",
((VRingAvail *)(dev->vdev->vq[i].vring.avail))->idx);
int avail_diff = ((VRingAvail *)(dev->vdev->vq[i].vring.avail))->idx
- last_avail;
- for (int j = 0; j < vring_num; j++) {
+ for (j = 0; j < vring_num; j++) {
uint64_t desc_addr = dev->vdev->vq[i].vring.desc;
VRingDesc desc_p = ((VRingDesc *)desc_addr)[j];
@@ -1318,10 +1351,10 @@ void find_add_new_reg(struct vhost_dev *dev)
break;
}
- DBG("desc[%u] 0x%lx\n", j, desc_addr);
- DBG("desc[%u].addr 0x%lx\n", j, sg_addr);
- DBG("desc[%u].len 0x%lu\n", j, sg_len);
- DBG("desc[%u].flags 0x%u\n", j, desc_p.flags);
+ DBG("desc[%lu] 0x%lx\n", j, desc_addr);
+ DBG("desc[%lu].addr 0x%lx\n", j, sg_addr);
+ DBG("desc[%lu].len 0x%lu\n", j, sg_len);
+ DBG("desc[%lu].flags 0x%u\n", j, desc_p.flags);
if (!find_reg(dev, sg_addr, sg_len)) {
vhost_add_reg(dev, sg_addr, sg_len);
@@ -1338,14 +1371,8 @@ void find_add_new_reg(struct vhost_dev *dev)
void vhost_commit_init_vqs(struct vhost_dev *dev)
{
- MemoryRegionSection *old_sections;
- int n_old_sections;
- uint64_t log_size;
size_t regions_size;
- int r;
- int i;
- bool changed = false;
- int sglist_elem_num;
+ unsigned int i;
dev->n_mem_sections = dev->nvqs;
@@ -1462,7 +1489,7 @@ int vhost_user_backend_init(struct vhost_dev *vhdev)
vhdev->max_queues = 1;
}
- if (vhdev->num_queues && vhdev->max_queues < vhdev->num_queues) {
+ if (vhdev->num_queues && vhdev->max_queues < (uint64_t)vhdev->num_queues) {
DBG("The maximum number of queues supported by the "
"backend is %ld\n", vhdev->max_queues);
return -EINVAL;
@@ -1592,7 +1619,8 @@ void vhost_dev_init(struct vhost_dev *vhdev)
int vhost_user_set_vring_enable(struct vhost_dev *dev, int enable)
{
- int i;
+ unsigned int i;
+ int ret;
DBG("vhost_user_set_vring_enable:\n");
if (!virtio_has_feature(dev->features, VHOST_USER_F_PROTOCOL_FEATURES)) {
@@ -1601,13 +1629,12 @@ int vhost_user_set_vring_enable(struct vhost_dev *dev, int enable)
}
for (i = 0; i < dev->nvqs; ++i) {
- int ret;
struct vhost_vring_state state = {
.index = dev->vq_index + i,
.num = enable,
};
- ret = vhost_set_vring(dev, VHOST_USER_SET_VRING_ENABLE, &state);
+ ret = vhost_set_vring(dev, VHOST_USER_SET_VRING_ENABLE, &state, true);
if (ret < 0) {
/*
* Restoring the previous state is likely infeasible, as well as
@@ -1623,6 +1650,7 @@ int vhost_user_set_vring_enable(struct vhost_dev *dev, int enable)
static int vhost_user_set_status(struct vhost_dev *dev, uint8_t status)
{
+ (void)dev;
return vhost_user_set_u64(VHOST_USER_SET_STATUS, status, false);
}
@@ -1631,6 +1659,7 @@ static int vhost_user_get_status(struct vhost_dev *dev, uint8_t *status)
uint64_t value;
int ret;
+ (void)dev;
ret = vhost_user_get_u64(VHOST_USER_GET_STATUS, &value);
if (ret < 0) {
return ret;
@@ -1668,7 +1697,7 @@ int vhost_user_dev_start(struct vhost_dev *dev, bool started)
}
/* Set device status only for last queue pair */
- if (dev->vq_index + dev->nvqs != dev->vq_index_end) {
+ if (dev->vq_index + dev->nvqs != (unsigned int)dev->vq_index_end) {
return 0;
}
diff --git a/vhost_user_loopback.h b/vhost_user_loopback.h
index 8aa7e05..4a868c6 100644
--- a/vhost_user_loopback.h
+++ b/vhost_user_loopback.h
@@ -120,7 +120,7 @@ struct vhost_dev {
};
-#define VHOST_USER_MAX_RAM_SLOTS 8
+#define VHOST_USER_MAX_RAM_SLOTS 16
typedef uint64_t ram_addr_t;
typedef struct RAMBlock RAMBlock;
@@ -912,8 +912,6 @@ bool vu_queue_avail_bytes(VuDev *dev, VuVirtq *vq, unsigned int in_bytes,
bool vhost_user_one_time_request(VhostUserRequest request);
void vmsg_close_fds(VhostUserMsg *vmsg);
-bool vu_message_write(int conn_fd, VhostUserMsg *vmsg);
-bool vu_message_read(int conn_fd, VhostUserMsg *vmsg);
int vhost_user_set_owner(void);
int process_message_reply(const VhostUserMsg *msg);
int vhost_user_get_u64(int request, uint64_t *u64);
diff --git a/vhost_user_rng.c b/vhost_user_rng.c
index c727636..96eb13e 100644
--- a/vhost_user_rng.c
+++ b/vhost_user_rng.c
@@ -77,25 +77,27 @@ static void vu_rng_start(VirtIODevice *vdev)
* everything here. virtio-pci will do the right thing by
* enabling/disabling irqfd.
*/
- for (i = 0; i < rng->vhost_dev->nvqs; i++) {
+ for (i = 0; i < (int)rng->vhost_dev->nvqs; i++) {
vhost_virtqueue_mask(rng->vhost_dev, vdev, i, false);
}
-
- /* Wait a bit for the vrings to be set in vhost-user-device */
- sleep(1);
-
-}
-
-/* TODO: We need to implement this function in a future release */
-static void vu_rng_stop(VirtIODevice *vdev)
-{
- VHostUserRNG *rng = vdev->vhrng;
}
+/* To be used in future release
+ *
+ * static void vu_rng_stop(VirtIODevice *vdev)
+ * {
+ * DBG("vu_rng_stop is not yet implemented\n");
+ * (void)vdev;
+ * }
+ *
+ */
static uint64_t vu_rng_get_features(VirtIODevice *vdev,
uint64_t requested_features)
{
+ DBG("vu_rng_get_features is not yet implemented\n");
+ (void)vdev;
+
/* No feature bits used yet */
return requested_features;
}
@@ -105,7 +107,13 @@ static void vu_rng_guest_notifier_mask(VirtIODevice *vdev, int idx, bool mask)
{
VHostUserRNG *rng = vdev->vhrng;
- /* vhost_virtqueue_mask(&rng->vhost_dev, vdev, idx, mask); */
+ DBG("vu_rng_guest_notifier_mask is not yet implemented\n");
+ (void)vdev;
+ (void)idx;
+ (void)mask;
+ (void)rng;
+
+ /* ADD: vhost_virtqueue_mask(&rng->vhost_dev, vdev, idx, mask); */
}
/* TODO: We need to implement this function in a future release */
@@ -113,7 +121,12 @@ static bool vu_rng_guest_notifier_pending(VirtIODevice *vdev, int idx)
{
VHostUserRNG *rng = vdev->vhrng;
- /* return vhost_virtqueue_pending(&rng->vhost_dev, idx); */
+ DBG("vu_rng_guest_notifier_pending is not yet implemented\n");
+ (void)vdev;
+ (void)idx;
+ (void)rng;
+
+ /* ADD: return vhost_virtqueue_pending(&rng->vhost_dev, idx); */
return 1;
}
@@ -151,7 +164,7 @@ void vhost_user_rng_init(VirtIODevice *vdev)
{
VHostUserRNG *vhrng = (VHostUserRNG *)malloc(sizeof(VHostUserRNG));
vdev->vhrng = vhrng;
- vdev->nvqs = &dev->nvqs;
+ vdev->nvqs = (int *)&dev->nvqs;
vhrng->parent = vdev;
vhrng->req_vq = vdev->vq;
vhrng->vhost_dev = dev;
@@ -162,6 +175,8 @@ void vhost_user_rng_init(VirtIODevice *vdev)
static void vu_rng_handle_output(VirtIODevice *vdev, VirtQueue *vq)
{
+ (void)vdev;
+ (void)vq;
/*
* Not normally called; it's the daemon that handles the queue;
* however virtio's cleanup path can call this.
@@ -170,8 +185,11 @@ static void vu_rng_handle_output(VirtIODevice *vdev, VirtQueue *vq)
}
-void vhost_user_rng_realize(void)
+void vhost_user_rng_realize(int queue_num, int queue_size)
{
+ (void)queue_num;
+ (void)queue_size;
+
/* Initiliaze virtio_dev data structures */
virtio_dev_init(global_vdev, "virtio-rng", 4, 0);
diff --git a/vhost_user_rng.h b/vhost_user_rng.h
index 69b5916..4627c50 100644
--- a/vhost_user_rng.h
+++ b/vhost_user_rng.h
@@ -39,6 +39,6 @@ typedef struct VHostUserRNG {
bool connected;
} VHostUserRNG;
-void vhost_user_rng_realize(void);
+void vhost_user_rng_realize(int queue_num, int queue_size);
#endif /* VHOST_USER_RNG */
diff --git a/vhost_user_sound.c b/vhost_user_sound.c
index c444feb..42b424b 100644
--- a/vhost_user_sound.c
+++ b/vhost_user_sound.c
@@ -3,7 +3,7 @@
*
* Copyright 2020 Red Hat, Inc.
*
- * Copyright (c) 2023 Virtual Open Systems SAS.
+ * Copyright (c) 2023-2024 Virtual Open Systems SAS.
*
* This work is licensed under the terms of the GNU GPL, version 2 or
* (at your option) any later version. See the COPYING file in the
@@ -62,7 +62,7 @@ static void vus_start(VirtIODevice *vdev)
VHostUserSound *vhusnd = vdev->vhusnd;
VirtioBus *k = vdev->vbus;
int ret;
- int i;
+ unsigned int i;
DBG("vus_start(...)\n");
@@ -91,9 +91,6 @@ static void vus_start(VirtIODevice *vdev)
goto err_guest_notifiers;
}
- /* Wait a bit before the vrings be set in vhost-user-device */
- sleep(1);
-
/*
* guest_notifier_mask/pending not used yet, so just unmask
* everything here. virtio-pci will do the right thing by
@@ -103,9 +100,6 @@ static void vus_start(VirtIODevice *vdev)
vhost_virtqueue_mask(vhusnd->vhost_dev, vdev, i, false);
}
- /* Wait a bit for the vrings to be set in vhost-user-device */
- sleep(1);
-
return;
err_guest_notifiers:
@@ -117,6 +111,7 @@ err_host_notifiers:
static void vus_stop(VirtIODevice *vdev)
{
DBG("vus_stop: not yet implemented\n");
+ (void)vdev;
}
static void vus_set_status(VirtIODevice *vdev, uint8_t status)
@@ -152,6 +147,8 @@ static void vus_snd_handle_output(VirtIODevice *vdev, VirtQueue *vq)
* Not normally called; it's the daemon that handles the queue;
* however virtio's cleanup path can call this.
*/
+ (void)vdev;
+ (void)vq;
}
/*
@@ -189,12 +186,14 @@ const VhostDevConfigOps snd_config_ops = {
static void vhost_user_snd_init(VirtIODevice *vdev);
-void vus_device_realize()
+void vus_device_realize(int queue_num, int queue_size)
{
VirtIODevice *vdev = global_vdev;
int ret;
DBG("vus_device_realize\n");
+ (void)queue_num;
+ (void)queue_size;
/* This needs to be added */
proxy = (VirtIOMMIOProxy *)malloc(sizeof(VirtIOMMIOProxy));
@@ -261,21 +260,28 @@ vhost_dev_init_failed:
static void vus_device_unrealize(VirtIODevice *vdev)
{
DBG("vhost_user_blk_device_unrealize not yet implemented\n");
+ (void)vdev;
}
-static struct vhost_dev *vus_get_vhost(VirtIODevice *vdev)
-{
- VHostUserSound *vhusnd = vdev->vhusnd;
- return vhusnd->vhost_dev;
-}
+/*
+ * This will be might be useful in the future
+ *
+ * static struct vhost_dev *vus_get_vhost(VirtIODevice *vdev)
+ * {
+ * VHostUserSound *vhusnd = vdev->vhusnd;
+ * return vhusnd->vhost_dev;
+ * }
+ *
+ */
static void print_config_snd(uint8_t *config_data)
{
struct virtio_snd_config *config_strct =
(struct virtio_snd_config *)config_data;
- DBG("print_config_snd:\n");
+ (void)config_strct;
+ DBG("print_config_snd:\n");
/* # of available physical jacks */
DBG("\tuint32_t jacks: %u\n", config_strct->jacks);
/* # of available PCM streams */
@@ -306,7 +312,7 @@ static void vhost_user_snd_init(VirtIODevice *vdev)
VHostUserSound *vhusnd = (VHostUserSound *)malloc(sizeof(VHostUserSound));
vdev->vhusnd = vhusnd;
- vdev->nvqs = &vdev->vhdev->nvqs;
+ vdev->nvqs = (int *)&vdev->vhdev->nvqs;
vhusnd->parent = vdev;
vhusnd->virtqs = vdev->vqs;
vhusnd->vhost_dev = vdev->vhdev;
diff --git a/vhost_user_sound.h b/vhost_user_sound.h
index c2dc73f..a31c082 100644
--- a/vhost_user_sound.h
+++ b/vhost_user_sound.h
@@ -3,7 +3,7 @@
*
* Copyright 2020 Red Hat, Inc.
*
- * Copyright (c) 2023 Virtual Open Systems SAS.
+ * Copyright (c) 2023-2024 Virtual Open Systems SAS.
*
* This work is licensed under the terms of the GNU GPL, version 2 or
* (at your option) any later version. See the COPYING file in the
@@ -35,6 +35,6 @@ typedef struct VHostUserSound {
/*< public >*/
} VHostUserSound;
-void vus_device_realize(void);
+void vus_device_realize(int queue_num, int queue_size);
#endif /* VHOST_USER_BLK */
diff --git a/virtio_input.c b/virtio_input.c
index c0993ea..668abe6 100644
--- a/virtio_input.c
+++ b/virtio_input.c
@@ -29,15 +29,47 @@
/* ----------------------------------------------------------------- */
+/*
+ * Example struct for keyboard
+ */
+static struct virtio_input_config virtio_keyboard_config[] = {
+ {
+ .select = VIRTIO_INPUT_CFG_ID_NAME,
+ .size = sizeof(VIRTIO_ID_NAME_KEYBOARD),
+ .u.string = VIRTIO_ID_NAME_KEYBOARD,
+ },{
+ .select = VIRTIO_INPUT_CFG_ID_DEVIDS,
+ .size = sizeof(struct virtio_input_devids),
+ .u.ids = {
+ .bustype = (BUS_VIRTUAL),
+ .vendor = (0x0627), /* same we use for usb hid devices */
+ .product = (0x0001),
+ .version = (0x0001),
+ },
+ },{
+ .select = VIRTIO_INPUT_CFG_EV_BITS,
+ .subsel = EV_KEY,
+ .size = 1,
+ .u.bitmap = {
+ KEY_G,
+ },
+ },
+ {}, /* End of list */
+};
+
+
void virtio_input_send(VirtIOInput *vinput, virtio_input_event *event)
{
DBG("virtio_input_send() not yet implemeted\n");
+ (void)vinput;
+ (void)event;
}
static void virtio_input_handle_evt(VirtIODevice *vdev, VirtQueue *vq)
{
- DBG("virtio_input_handle_evt(...)\n");
- /* nothing */
+ DBG("virtio_input_handle_evt(...) not yet implemeted\n");
+ (void)vdev;
+ (void)vq;
}
static void virtio_input_handle_sts(VirtIODevice *vdev, VirtQueue *vq)
@@ -49,6 +81,7 @@ static void virtio_input_handle_sts(VirtIODevice *vdev, VirtQueue *vq)
int len;
DBG("virtio_input_handle_sts(...)\n");
+ (void)vq;
for (;;) {
elem = virtqueue_pop(vinput->sts, sizeof(VirtQueueElement));
@@ -166,6 +199,9 @@ static void virtio_input_set_config(VirtIODevice *vdev,
static uint64_t virtio_input_get_features(VirtIODevice *vdev, uint64_t f)
{
DBG("virtio_input_get_features(...)\n");
+ (void)vdev;
+ (void)f;
+
return f;
}
@@ -202,22 +238,40 @@ static void virtio_input_reset(VirtIODevice *vdev)
}
}
-static int virtio_input_post_load(void *opaque, int version_id)
-{
- VirtIOInput *vinput = global_vdev->vinput;
- VirtIOInputClass *vic = global_vdev->vinput->input_class;
- VirtIODevice *vdev = global_vdev;
-
- DBG("virtio_input_post_load(...)\n");
-
- vinput->active = vdev->status & VIRTIO_CONFIG_S_DRIVER_OK;
- if (vic->change_active) {
- vic->change_active(vinput);
- }
- return 0;
-}
+/*
+ * Functions which might be used in the future:
+ *
+ * static int virtio_input_post_load(void *opaque, int version_id)
+ * {
+ * VirtIOInput *vinput = global_vdev->vinput;
+ * VirtIOInputClass *vic = global_vdev->vinput->input_class;
+ * VirtIODevice *vdev = global_vdev;
+ *
+ * DBG("virtio_input_post_load(...)\n");
+ * (void)opaque;
+ * (void)version_id;
+ *
+ * vinput->active = vdev->status & VIRTIO_CONFIG_S_DRIVER_OK;
+ * if (vic->change_active) {
+ * vic->change_active(vinput);
+ * }
+ * return 0;
+ * }
+ *
+ * static void virtio_input_finalize(VirtIODevice *vdev)
+ * {
+ * DBG("virtio_input_finalize not yet implemented");
+ * (void)vdev;
+ * }
+ *
+ * static void virtio_input_device_unrealize(VirtIODevice *vdev)
+ * {
+ * DBG("virtio_input_device_unrealize not yet implemented");
+ * (void)vdev;
+ * }
+ */
-void virtio_input_device_realize()
+void virtio_input_device_realize(int queue_num, int queue_size)
{
VirtIODevice *vdev = global_vdev;
struct VirtIOInputClass *vic = vdev->vinput->input_class;
@@ -225,6 +279,8 @@ void virtio_input_device_realize()
VirtIOInputConfig *cfg;
DBG("virtio_input_device_realize(...)\n");
+ (void)queue_num;
+ (void)queue_size;
/* This needs to be added */
proxy = (VirtIOMMIOProxy *)malloc(sizeof(VirtIOMMIOProxy));
@@ -259,17 +315,6 @@ void virtio_input_device_realize()
DBG("global_vdev->guest_features: 0x%lx\n", global_vdev->guest_features);
}
-static void virtio_input_finalize(VirtIODevice *vdev)
-{
- DBG("virtio_input_finalize not yet implemented");
-}
-
-static void virtio_input_device_unrealize(VirtIODevice *vdev)
-{
- DBG("virtio_input_device_unrealize not yet implemented");
-}
-
-
void virtio_input_class_init(VirtIODevice *vdev)
{
vdev->vdev_class = (VirtioDeviceClass *)malloc(sizeof(VirtioDeviceClass));
diff --git a/virtio_loopback.c b/virtio_loopback.c
index 8b57589..5457f20 100644
--- a/virtio_loopback.c
+++ b/virtio_loopback.c
@@ -118,6 +118,8 @@ bool virtio_device_started(VirtIODevice *vdev, uint8_t status)
DBG("virtio_device_started: %d\n", status & VIRTIO_CONFIG_S_DRIVER_OK);
DBG("status: %d\n", status);
+ (void)vdev;
+
return status & VIRTIO_CONFIG_S_DRIVER_OK;
}
@@ -535,7 +537,18 @@ static bool virtqueue_map_desc(VirtIODevice *vdev, unsigned int *p_num_sg,
unsigned int max_num_sg, bool is_write,
uint64_t pa, size_t sz)
{
- DBG("Not implemented\n");
+ (void)vdev;
+ (void)p_num_sg;
+ (void)addr;
+ (void)iov;
+ (void)max_num_sg;
+ (void)is_write;
+ (void)pa;
+ (void)sz;
+
+ DBG("virtqueue_map_desc: Not implemented\n");
+
+ return true;
}
static void *virtqueue_alloc_element(size_t sz, unsigned out_num,
@@ -567,7 +580,6 @@ static void *virtqueue_alloc_element(size_t sz, unsigned out_num,
void *virtqueue_split_pop(VirtQueue *vq, size_t sz)
{
unsigned int i, head, max;
- int64_t len;
VirtIODevice *vdev = vq->vdev;
VirtQueueElement *elem = NULL;
unsigned out_num, in_num, elem_entries;
@@ -684,9 +696,10 @@ bool virtqueue_get_head(VirtQueue *vq, unsigned int idx,
uint32_t get_vqs_max_size(VirtIODevice *vdev)
{
- uint32_t vq_max_size = VIRTQUEUE_MAX_SIZE;
uint32_t total_size, temp_size, total_p2 = 1;
- int i, log_res = 0;
+ int log_res = 0;
+
+ (void)vdev;
total_size = VIRTQUEUE_MAX_SIZE * sizeof(VRingDesc);
total_size += offsetof(VRingAvail, ring) +
@@ -737,6 +750,8 @@ int virtqueue_num_heads(VirtQueue *vq, unsigned int idx)
int virtqueue_split_read_next_desc(VirtIODevice *vdev, VRingDesc *desc,
unsigned int max, unsigned int *next)
{
+ (void)vdev;
+
/* If this descriptor says it doesn't chain, we're done. */
if (!(desc->flags & VRING_DESC_F_NEXT)) {
return VIRTQUEUE_READ_DESC_DONE;
@@ -762,7 +777,6 @@ static void virtqueue_split_get_avail_bytes(VirtQueue *vq,
VirtIODevice *vdev = vq->vdev;
unsigned int max, idx;
unsigned int total_bufs, in_total, out_total;
- int64_t len = 0;
int rc;
idx = vq->last_avail_idx;
@@ -1012,7 +1026,6 @@ void *loopback_event_select(void *_e)
{
int retval;
fd_set rfds;
- int s;
EventNotifier *e = (EventNotifier *)_e;
int rfd = e->rfd;
VirtQueue *vq = container_of(e, VirtQueue, guest_notifier);
@@ -1023,15 +1036,13 @@ void *loopback_event_select(void *_e)
FD_SET(rfd, &rfds);
while (1) {
-
retval = select(rfd + 1, &rfds, NULL, NULL, NULL);
-
if (retval == -1) {
DBG("select() error. Exiting...\n");
exit(1);
}
- if (retval > 0) {
+ if (retval > 0) {
if (pthread_mutex_lock(&interrupt_lock) != 0) {
printf("[ERROR] Locking failed\n");
exit(1);
@@ -1055,6 +1066,7 @@ void event_notifier_set_handler(EventNotifier *e,
{
int ret;
pthread_t thread_id;
+ (void)handler;
if (e->wfd > 0) {
ret = pthread_create(&thread_id, NULL, loopback_event_select,
@@ -1092,7 +1104,6 @@ EventNotifier *virtio_queue_get_guest_notifier(VirtQueue *vq)
int virtio_loopback_set_guest_notifier(VirtIODevice *vdev, int n, bool assign,
bool with_irqfd)
{
- VirtioDeviceClass *vdc = vdev->vdev_class;
VirtQueue *vq = virtio_get_queue(vdev, n);
EventNotifier *notifier = virtio_queue_get_guest_notifier(vq);
@@ -1219,7 +1230,6 @@ static int int_count;
void virtio_loopback_update_irq(VirtIODevice *vdev)
{
int level, irq_num = 44;
- pthread_t my_thread_id;
if (!vdev) {
return;
@@ -1480,10 +1490,11 @@ static uint64_t virtio_loopback_read(VirtIODevice *vdev, uint64_t offset,
}
} else {
/* TODO: To be implemented */
+ return 0;
}
case VIRTIO_MMIO_QUEUE_NUM_MAX:
- /* TODO: To be implemented */
- return VIRTQUEUE_MAX_SIZE;
+ DBG("Return queue_size = %d\n", vdev->vq[vdev->queue_sel].vring.num);
+ return vdev->vq[vdev->queue_sel].vring.num;
case VIRTIO_MMIO_QUEUE_PFN:
if (!proxy->legacy) {
DBG("VIRTIO_MMIO_QUEUE_PFN: read from legacy register (0x%lx) "
@@ -1500,6 +1511,8 @@ static uint64_t virtio_loopback_read(VirtIODevice *vdev, uint64_t offset,
return 0;
}
/* TODO: To be implemented */
+ DBG("VIRTIO_MMIO_QUEUE_READY: Not implemented case\n");
+ return 0;
case VIRTIO_MMIO_INTERRUPT_STATUS:
return vdev->isr;
case VIRTIO_MMIO_STATUS:
@@ -1946,6 +1959,7 @@ void virtio_dev_init(VirtIODevice *vdev, const char *name,
static bool virtio_loopback_ioeventfd_enabled(VirtIODevice *d)
{
+ (void)d;
return (proxy->flags & VIRTIO_IOMMIO_FLAG_USE_IOEVENTFD) != 0;
}
@@ -1954,6 +1968,10 @@ static int virtio_loopback_ioeventfd_assign(VirtIOMMIOProxy *d,
EventNotifier *notifier,
int n, bool assign)
{
+ (void)d;
+ (void)notifier;
+ (void)n;
+ (void)assign;
return 0;
}
@@ -1983,7 +2001,6 @@ int virtio_loopback_start(void)
efd_data_t info;
pthread_t thread_id;
int ret = -1;
- int flags;
fd = open("/dev/loopback", O_RDWR);
if (fd < 0) {
diff --git a/virtio_loopback.h b/virtio_loopback.h
index 2ece0f9..c348a19 100644
--- a/virtio_loopback.h
+++ b/virtio_loopback.h
@@ -16,7 +16,7 @@
*
* 3) vhost.h of QEMU project
*
- * Copyright 2022-2023 Virtual Open Systems SAS.
+ * Copyright 2022-2024 Virtual Open Systems SAS.
*
* This work is licensed under the terms of the GNU GPL, version 2. See
* the COPYING file in the top-level directory.
@@ -148,7 +148,7 @@
#define VIRT_VERSION_LEGACY 1
#define VIRT_VENDOR 0x554D4551 /* 'QEMU' */
-#define VIRTQUEUE_MAX_SIZE 64
+#define VIRTQUEUE_MAX_SIZE 1024
#define VIRTIO_QUEUE_MAX VIRTQUEUE_MAX_SIZE
#define VIRTIO_NO_VECTOR 0xffff
@@ -536,7 +536,7 @@ typedef struct VirtioDeviceClass {
void (*set_config)(VirtIODevice *vdev, const uint8_t *config);
void (*reset)(VirtIODevice *vdev);
void (*set_status)(VirtIODevice *vdev, uint8_t val);
- void (*realize)(void);
+ void (*realize)(int queue_num, int queue_size);
void (*unrealize)(VirtIODevice *vdev);
/*
* For transitional devices, this is a bitmap of features
diff --git a/virtio_rng.c b/virtio_rng.c
index 6a5b24b..f230b23 100644
--- a/virtio_rng.c
+++ b/virtio_rng.c
@@ -64,8 +64,7 @@ void chr_read(VirtIORNG *vrng, const void *buf, size_t size)
{
VirtIODevice *vdev = vrng->parent_obj;
VirtQueueElement *elem;
- size_t len;
- int offset;
+ size_t len, offset;
if (!is_guest_ready(vrng)) {
return;
@@ -136,6 +135,7 @@ void virtio_rng_process(VirtIORNG *vrng)
void handle_input(VirtIODevice *vdev, VirtQueue *vq)
{
+ (void)vq;
virtio_rng_process(vdev->vrng);
}
@@ -159,8 +159,11 @@ void virtio_rng_init(VirtIODevice *vdev)
}
-void virtio_rng_realize(void)
+void virtio_rng_realize(int queue_num, int queue_size)
{
+ (void)queue_num;
+ (void)queue_size;
+
/* prepare procy and virtio dev*/
proxy = (VirtIOMMIOProxy *)malloc(sizeof(VirtIOMMIOProxy));
diff --git a/virtio_rng.h b/virtio_rng.h
index cf35c29..4264b45 100644
--- a/virtio_rng.h
+++ b/virtio_rng.h
@@ -49,7 +49,7 @@ size_t get_request_size(VirtQueue *vq, unsigned quota);
void virtio_rng_set_status(VirtIODevice *vdev, uint8_t status);
void virtio_rng_process(VirtIORNG *vrng);
void chr_read(VirtIORNG *vrng, const void *buf, size_t size);
-void virtio_rng_realize(void);
+void virtio_rng_realize(int queue_num, int queue_size);
void virtio_rng_init(VirtIODevice *vdev);
#endif /* VIRTIO_RNG */