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

[Minios-devel] [UNIKRAFT PATCH v2 04/16] plat/xen/drivers/blk: Init Xenbus Device



This patch introduces the Xenbus Device responsible for communication
between blkfront and backend through Xenstore.
Initial information like backend path/id, frontend path are introduced
as well.

Signed-off-by: Roxana Nicolescu <nicolescu.roxana1996@xxxxxxxxx>
---
 plat/xen/Makefile.uk               |   1 +
 plat/xen/drivers/blk/blkfront.c    |  13 ++++
 plat/xen/drivers/blk/blkfront.h    |   4 ++
 plat/xen/drivers/blk/blkfront_xb.h |  61 +++++++++++++++++++
 plat/xen/drivers/blk/blkfront_xs.c | 118 +++++++++++++++++++++++++++++++++++++
 5 files changed, 197 insertions(+)
 create mode 100644 plat/xen/drivers/blk/blkfront_xb.h
 create mode 100644 plat/xen/drivers/blk/blkfront_xs.c

diff --git a/plat/xen/Makefile.uk b/plat/xen/Makefile.uk
index 9fa92d1e..cb62bd60 100644
--- a/plat/xen/Makefile.uk
+++ b/plat/xen/Makefile.uk
@@ -109,4 +109,5 @@ LIBXENBLKFRONT_ASINCLUDES-y         += 
$(LIBXENPLAT_ASINCLUDES-y)
 LIBXENBLKFRONT_CFLAGS-y             += $(LIBXENPLAT_CFLAGS-y)
 LIBXENBLKFRONT_CINCLUDES-y          += $(LIBXENPLAT_CINCLUDES-y)
 LIBXENBLKFRONT_SRCS-y          += $(LIBXENPLAT_BASE)/drivers/blk/blkfront.c
+LIBXENBLKFRONT_SRCS-y          += $(LIBXENPLAT_BASE)/drivers/blk/blkfront_xs.c
 endif
diff --git a/plat/xen/drivers/blk/blkfront.c b/plat/xen/drivers/blk/blkfront.c
index e8aa6a9d..990cbdc9 100644
--- a/plat/xen/drivers/blk/blkfront.c
+++ b/plat/xen/drivers/blk/blkfront.c
@@ -43,6 +43,7 @@
 #include <uk/blkdev_driver.h>
 #include <xenbus/xenbus.h>
 #include "blkfront.h"
+#include "blkfront_xb.h"
 
 #define DRIVER_NAME            "xen-blkfront"
 
@@ -62,6 +63,7 @@ static void blkfront_unconfigure(struct uk_blkdev *blkdev)
        UK_ASSERT(blkdev != NULL);
        dev = to_blkfront(blkdev);
        uid = dev->uid;
+       blkfront_xb_fini(dev);
        uk_blkdev_drv_unregister(blkdev);
        uk_free(drv_allocator, dev);
 
@@ -86,7 +88,16 @@ static int blkfront_add_dev(struct xenbus_device *dev)
        if (!d)
                return -ENOMEM;
 
+       d->xendev = dev;
        d->blkdev.dev_ops = &blkfront_ops;
+
+       /* Xenbus initialization */
+       rc = blkfront_xb_init(d);
+       if (rc) {
+               uk_pr_err("Error initializing Xenbus data: %d\n", rc);
+               goto err_xenbus;
+       }
+
        rc = uk_blkdev_drv_register(&d->blkdev, drv_allocator, "blkdev");
        if (rc < 0) {
                uk_pr_err("Failed to register blkfront with libukblkdev %d",
@@ -100,6 +111,8 @@ static int blkfront_add_dev(struct xenbus_device *dev)
 out:
        return rc;
 err_register:
+       blkfront_xb_fini(d);
+err_xenbus:
        uk_free(drv_allocator, d);
        goto out;
 }
diff --git a/plat/xen/drivers/blk/blkfront.h b/plat/xen/drivers/blk/blkfront.h
index 2c542cca..a4550910 100644
--- a/plat/xen/drivers/blk/blkfront.h
+++ b/plat/xen/drivers/blk/blkfront.h
@@ -47,8 +47,12 @@
  * Structure used to describe the Blkfront device.
  */
 struct blkfront_dev {
+       /* Xenbus Device. */
+       struct xenbus_device *xendev;
        /* Blkdev Device. */
        struct uk_blkdev blkdev;
+       /* A specific number to the blkfront device. */
+       blkif_vdev_t    handle;
        /* The blkdev identifier */
        __u16 uid;
 };
diff --git a/plat/xen/drivers/blk/blkfront_xb.h 
b/plat/xen/drivers/blk/blkfront_xb.h
new file mode 100644
index 00000000..80e4a04b
--- /dev/null
+++ b/plat/xen/drivers/blk/blkfront_xb.h
@@ -0,0 +1,61 @@
+/* SPDX-License-Identifier: BSD-3-Clause */
+/*
+ * Authors: Roxana Nicolescu <nicolescu.roxana1996@xxxxxxxxx>
+ *
+ * Copyright (c) 2019, University Politehnica of Bucharest.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the copyright holder nor the names of its
+ *    contributors may be used to endorse or promote products derived from
+ *    this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ * THIS HEADER MAY NOT BE EXTRACTED OR MODIFIED IN ANY WAY.
+ */
+#ifndef __BLKFRONT_XB_H__
+#define __BLKFRONT_XB_H__
+
+/**
+ * Blkfront interface for xenstore operations.
+ *
+ * This header contains all the functions needed by the blkfront driver
+ * in order to access Xenstore data.
+ */
+
+#include "blkfront.h"
+
+/*
+ * Get initial info from the xenstore.
+ * Ex: backend path, handle.
+ *
+ * Return 0 on success, a negative errno value on error.
+ */
+int blkfront_xb_init(struct blkfront_dev *dev);
+
+/*
+ * It deallocates the xendev structure members allocated during initialization.
+ *
+ */
+void blkfront_xb_fini(struct blkfront_dev *dev);
+
+#endif /* __BLKFRONT_XB_H__ */
diff --git a/plat/xen/drivers/blk/blkfront_xs.c 
b/plat/xen/drivers/blk/blkfront_xs.c
new file mode 100644
index 00000000..652584dc
--- /dev/null
+++ b/plat/xen/drivers/blk/blkfront_xs.c
@@ -0,0 +1,118 @@
+/* SPDX-License-Identifier: BSD-3-Clause */
+/*
+ * Authors: Roxana Nicolescu <nicolescu.roxana1996@xxxxxxxxx>
+ *
+ * Copyright (c) 2019, University Politehnica of Bucharest.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the copyright holder nor the names of its
+ *    contributors may be used to endorse or promote products derived from
+ *    this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ * THIS HEADER MAY NOT BE EXTRACTED OR MODIFIED IN ANY WAY.
+ */
+#include <inttypes.h>
+#include <stdio.h>
+#include <string.h>
+#include <fcntl.h>
+#include <uk/errptr.h>
+#include <uk/print.h>
+#include <uk/assert.h>
+#include <xenbus/client.h>
+#include <xenbus/xs.h>
+#include "blkfront_xb.h"
+
+static int xs_read_backend_id(const char *nodename, domid_t *domid)
+{
+       char *path = NULL;
+       int value, err;
+
+       UK_ASSERT(nodename != NULL);
+
+       err = asprintf(&path, "%s/backend-id", nodename);
+       if (err <= 0) {
+               uk_pr_err("Failed to allocate and format path: %d.\n", err);
+               goto out;
+       }
+
+       err = xs_read_integer(XBT_NIL, path, &value);
+       if (err == 0)
+               *domid = (domid_t) value;
+
+out:
+       free(path);
+       return err;
+}
+
+int blkfront_xb_init(struct blkfront_dev *dev)
+{
+       struct xenbus_device *xendev;
+       char *nodename;
+       int err = 0;
+
+       UK_ASSERT(dev != NULL);
+       xendev = dev->xendev;
+
+       err = xs_read_backend_id(xendev->nodename, &xendev->otherend_id);
+       if (err)
+               goto out;
+
+       /* Get handle */
+       nodename = strrchr(xendev->nodename, '/');
+       if (!nodename) {
+               err = -EINVAL;
+               goto out;
+       }
+
+       dev->handle = strtoul(nodename + 1, NULL, 0);
+       if (!dev->handle) {
+               err = -EINVAL;
+               goto out;
+       }
+
+       /* Read otherend path */
+       xendev->otherend = xs_read(XBT_NIL, xendev->nodename, "backend");
+       if (PTRISERR(xendev->otherend)) {
+               uk_pr_err("Failed to read backend path: %d.\n", err);
+               err = PTR2ERR(xendev->otherend);
+               xendev->otherend = NULL;
+               goto out;
+       }
+
+out:
+       return err;
+}
+
+void blkfront_xb_fini(struct blkfront_dev *dev)
+{
+       struct xenbus_device *xendev;
+
+       UK_ASSERT(dev != NULL);
+
+       xendev = dev->xendev;
+       if (xendev->otherend) {
+               free(xendev->otherend);
+               xendev->otherend = NULL;
+       }
+}
-- 
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®.