summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Makefile4
-rw-r--r--adapter.c60
-rw-r--r--vhost_user_blk.c13
-rw-r--r--vhost_user_blk.h3
-rw-r--r--virtio_loopback.c5
-rw-r--r--virtio_loopback.h5
6 files changed, 70 insertions, 20 deletions
diff --git a/Makefile b/Makefile
index 3d18b6a..3d5db06 100644
--- a/Makefile
+++ b/Makefile
@@ -20,8 +20,8 @@
#CFLAGS := -Wall -Wextra -Werror
#CFLAGS := -Wall -Wextra -Wno-unused-variable -Wno-unused-function
-CFLAGS := -Wno-unused-variable -Wno-unused-function
-CFLAGS =
+CFLAGS := -Wno-unused-variable -Wno-unused-function -D_GNU_SOURCE
+CFLAGS = -D_GNU_SOURCE -O2
CC ?=
ifeq ($(ARCH), arm64)
diff --git a/adapter.c b/adapter.c
index e74da5f..d5f8d64 100644
--- a/adapter.c
+++ b/adapter.c
@@ -124,17 +124,18 @@ void client(char *sock_path)
len = sizeof(client_sockaddr);
rc = connect(client_sock, (struct sockaddr *) &client_sockaddr, len);
if (rc == -1) {
- DBG("CONNECT ERROR\n");
+ printf("CONNECT ERROR: Check the \"-s\" parameter\n");
close(client_sock);
exit(1);
}
-
}
static void help_args(void)
{
printf("Run example:\n\t./adapter -s /path_to_socket/rng.sock\n"
"\t\t -d device_name\n"
+ "\t\t [ -qn number of queues ]\n"
+ "\t\t [ -qs size of queues ]\n"
"The 'device_name' can be one of the following:\n"
"\tvrng, vhurng, vhublk, vhuinput\n");
}
@@ -148,7 +149,6 @@ int find_arg(int argc, char **argv, char *str)
return i + 1;
}
}
- printf("You have not specified parameter \"%s\"\n", str);
return -1;
}
@@ -181,24 +181,65 @@ bool check_vhu_device(char *str)
return false;
}
+void get_queue_num_size_args(int argc, char **argv,
+ int *eval_queue_num, int *eval_queue_size)
+{
+ int queue_num, queue_size, queue_num_id, queue_size_id;
+
+ if (argc < 9) {
+ return;
+ }
+
+ queue_num_id = find_arg(argc, argv, "-qn");
+ queue_size_id = find_arg(argc, argv, "-qs");
+
+ /* Check if both qs ans qn exist */
+ if (queue_num_id < 0 || queue_size_id < 0) {
+ return;
+ }
+
+ queue_num = atoi(argv[queue_num_id]);
+ queue_size = atoi(argv[queue_size_id]);
+
+ /* Evaluate number of queues */
+ if (queue_num <= 0 || queue_num > 16) {
+ return;
+ }
+
+ /* Evaluate queues' size */
+ if (queue_size <= 0 || queue_size > 1024) {
+ return;
+ }
+
+ *eval_queue_num = queue_num;
+ *eval_queue_size = queue_size;
+}
+
+
int main(int argc, char **argv)
{
int socket_idx, device_idx, device_id;
bool vhost_user_enabled;
+ /* Assign default queue num and size */
+ int queue_num = 1, queue_size = 1024;
/*
* Check if the user has provided all the required arguments.
* If not, print the help messages.
*/
+ if (argc < 5) {
+ goto error_args;
+ }
+
device_idx = find_arg(argc, argv, "-d");
if (device_idx < 0) {
+ printf("You have not specified parameter \"-d\"\n");
goto error_args;
}
/* Validate the argumetns */
-
device_id = val_device_arg(argv[device_idx]);
if (device_id == 0) {
@@ -214,6 +255,7 @@ int main(int argc, char **argv)
socket_idx = find_arg(argc, argv, "-s");
if ((socket_idx < 0) && (vhost_user_enabled)) {
+ printf("You have not specified parameter \"-s\"\n");
goto error_args;
}
@@ -232,16 +274,18 @@ int main(int argc, char **argv)
/* Initialize the virtio/vhost-user device */
switch (device_id) {
case 1:
- virtio_rng_realize(); /* <-- Enable that for simple rng */
+ virtio_rng_realize();
break;
case 2:
- vhost_user_rng_realize(); /* <-- Enable that for vhost-user-rng */
+ vhost_user_rng_realize();
break;
case 3:
- vhost_user_blk_realize(); /* <-- Enable that for vhost-user-blk */
+ 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:
- /* Enable that for vhost-user-rng */
vhost_user_input_init(global_vdev);
virtio_input_device_realize();
break;
diff --git a/vhost_user_blk.c b/vhost_user_blk.c
index f92d1c7..a8e4c13 100644
--- a/vhost_user_blk.c
+++ b/vhost_user_blk.c
@@ -47,6 +47,8 @@
#define REALIZE_CONNECTION_RETRIES 3
+static uint64_t vhost_user_blk_get_features(VirtIODevice *vdev,
+ uint64_t features);
static int vhost_user_blk_start(VirtIODevice *vdev)
{
@@ -223,7 +225,7 @@ static int vhost_user_blk_connect(VirtIODevice *vdev)
vhost_dev_init(s->vhost_dev);
/* Pass the new obtained features */
- global_vdev->host_features = global_vdev->vhublk->vhost_dev->features;
+ global_vdev->host_features = s->vhost_dev->features;
/* Disable VIRTIO_RING_F_INDIRECT_DESC, to be supported in future release */
global_vdev->host_features &= ~(1ULL << VIRTIO_RING_F_INDIRECT_DESC);
@@ -468,7 +470,7 @@ void print_config(uint8_t *config)
DBG("uint8_t unused1[3]: %u\n", config_strct->unused1[2]);
}
-void vhost_user_blk_realize(void)
+void vhost_user_blk_realize(int queue_num, int queue_size)
{
int retries;
int i, ret;
@@ -487,12 +489,13 @@ void vhost_user_blk_realize(void)
vhost_user_blk_init(global_vdev);
- global_vdev->vhublk->config_wce = 1;
+ global_vdev->vhublk->config_wce = 0;
+
/* FIXME: We temporarily hardcoded the vrtqueues number */
- global_vdev->vhublk->num_queues = 1;
+ global_vdev->vhublk->num_queues = queue_num;
/* FIXME: We temporarily hardcoded the vrtqueues size */
- global_vdev->vhublk->queue_size = 128;
+ global_vdev->vhublk->queue_size = queue_size;
/* NOTE: global_vdev->vqs == vhublk->virtqs */
global_vdev->vqs = (VirtQueue **)malloc(sizeof(VirtQueue *)
diff --git a/vhost_user_blk.h b/vhost_user_blk.h
index 33e140a..3b09f75 100644
--- a/vhost_user_blk.h
+++ b/vhost_user_blk.h
@@ -54,7 +54,6 @@ struct VHostUserBlk {
bool started_vu;
};
-
-void vhost_user_blk_realize(void);
+void vhost_user_blk_realize(int queue_num, int queue_size);
#endif /* VHOST_USER_BLK */
diff --git a/virtio_loopback.c b/virtio_loopback.c
index 174e263..1e40136 100644
--- a/virtio_loopback.c
+++ b/virtio_loopback.c
@@ -1327,7 +1327,8 @@ void virtio_loopback_update_irq(VirtIODevice *vdev)
DBG("Trigger interrupt (ioctl)\n");
DBG("Interrupt counter: %d\n", int_count++);
- (void)pthread_create(&my_thread_id, NULL, my_notify, NULL);
+ //(void)pthread_create(&my_thread_id, NULL, my_notify, NULL);
+ (void) ioctl(fd, IRQ, &irq_num);
}
@@ -1768,6 +1769,8 @@ void virtio_loopback_write(VirtIODevice *vdev, uint64_t offset,
uint64_t desc_addr;
uint32_t vqs_size = get_vqs_max_size(global_vdev);
+ ioctl(fd, SHARE_VQS, &vdev->queue_sel);
+
desc_addr = (uint64_t)mmap(NULL, vqs_size,
PROT_READ | PROT_WRITE,
MAP_SHARED, fd, 0);
diff --git a/virtio_loopback.h b/virtio_loopback.h
index 1fdb7db..e581d92 100644
--- a/virtio_loopback.h
+++ b/virtio_loopback.h
@@ -149,7 +149,8 @@
#define VIRT_VENDOR 0x554D4551 /* 'QEMU' */
#define VIRTQUEUE_MAX_SIZE 1024
-#define VIRTIO_QUEUE_MAX 1024
+#define VIRTIO_QUEUE_MAX VIRTQUEUE_MAX_SIZE
+
#define VIRTIO_NO_VECTOR 0xffff
#define TYPE_VIRTIO_DEVICE "virtio-device"
@@ -163,7 +164,7 @@
#define START_LOOPBACK _IOC(_IOC_WRITE, 'k', 3, \
sizeof(virtio_device_info_struct_t))
#define IRQ _IOC(_IOC_WRITE, 'k', 4, sizeof(int))
-#define SHARE_VQS _IOC(_IOC_WRITE, 'k', 5, 0)
+#define SHARE_VQS _IOC(_IOC_WRITE, 'k', 5, sizeof(uint32_t))
#define SHARE_BUF _IOC(_IOC_WRITE, 'k', 6, sizeof(uint64_t))
#define USED_INFO _IOC(_IOC_WRITE, 'k', 7, 0)
#define DATA_INFO _IOC(_IOC_WRITE, 'k', 8, 0)