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

[Minios-devel] [UNIKRAFT PATCH 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 | 57 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 57 insertions(+)

diff --git a/plat/drivers/virtio/virtio_blk.c b/plat/drivers/virtio/virtio_blk.c
index 296f99a8..91e8bf1c 100644
--- a/plat/drivers/virtio/virtio_blk.c
+++ b/plat/drivers/virtio/virtio_blk.c
@@ -19,21 +19,78 @@
  */
 /* 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 void virtio_blkdev_close(struct uk_blkdev *dev)
+{
+       struct virtio_blk_device *d;
+       __u16 uid;
+
+       UK_ASSERT(dev != NULL);
+       d = to_virtioblkdev(dev);
+       uid = d->uid;
+       uk_blkdev_drv_unregister(dev, a);
+       uk_free(a, d);
+
+       uk_pr_info(DRIVER_NAME": %"__PRIu16" closed\n", uid);
+}
+
+static const struct uk_blkdev_ops virtio_blkdev_ops = {
+               .dev_close = virtio_blkdev_close,
+};
+
 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;
+
+       vbdev->blkdev.dev_ops = &virtio_blkdev_ops;
+
+       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.11.0


_______________________________________________
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®.