[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Minios-devel] [UNIKRAFT PATCH v2 02/12] plat/drivers: Register virtio-blk with libukblkdev



This patch registers virtio-blk with libukblkdev.

Signed-off-by: Roxana Nicolescu <nicolescu.roxana1996@xxxxxxxxx>
---
 plat/drivers/virtio/virtio_blk.c | 37 ++++++++++++++++++++++++++++++++
 1 file changed, 37 insertions(+)

diff --git a/plat/drivers/virtio/virtio_blk.c b/plat/drivers/virtio/virtio_blk.c
index 296f99a8..884f86d9 100644
--- a/plat/drivers/virtio/virtio_blk.c
+++ b/plat/drivers/virtio/virtio_blk.c
@@ -19,21 +19,58 @@
  */
 /* Taken and adapted from virtio-net because of consistency reason. */
 
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <uk/print.h>
+#include <errno.h>
+#include <fcntl.h>
 #include <virtio/virtio_bus.h>
 #include <virtio/virtio_ids.h>
+#include <uk/blkdev.h>
+#include <uk/blkdev_driver.h>
 
 #define DRIVER_NAME            "virtio-blk"
 
+#define to_virtioblkdev(bdev) \
+       __containerof(bdev, struct virtio_blk_device, blkdev)
+
+
 static struct uk_alloc *a;
 static const char *drv_name = DRIVER_NAME;
 
+struct virtio_blk_device {
+       /* Pointer to Unikraft Block Device */
+       struct uk_blkdev blkdev;
+       /* The blkdevice identifier */
+       __u16 uid;
+};
+
 static int virtio_blk_add_dev(struct virtio_dev *vdev)
 {
+       struct virtio_blk_device *vbdev;
        int rc = 0;
 
        UK_ASSERT(vdev != NULL);
 
+       vbdev = uk_calloc(a, 1, sizeof(*vbdev));
+       if (!vbdev)
+               return -ENOMEM;
+
+       rc = uk_blkdev_drv_register(&vbdev->blkdev, a, drv_name);
+       if (rc < 0) {
+               uk_pr_err("Failed to register virtio_blk device: %d\n", rc);
+               goto err_out;
+       }
+
+       vbdev->uid = rc;
+       uk_pr_info("Virtio-blk device registered with libukblkdev\n");
+
+out:
        return rc;
+err_out:
+       uk_free(a, vbdev);
+       goto out;
 }
 
 static int virtio_blk_drv_init(struct uk_alloc *drv_allocator)
-- 
2.17.1


_______________________________________________
Minios-devel mailing list
Minios-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/minios-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.