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

Re: [Minios-devel] [UNIKRAFT PATCH v3 05/17] plat/xen/drivers/blk: Init Xenbus Device



Reviewed-by: Costin Lupu <costin.lupu@xxxxxxxxx>

On 10/30/19 5:54 PM, Roxana Nicolescu wrote:
> 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    |  16 ++++
>  plat/xen/drivers/blk/blkfront.h    |   4 +
>  plat/xen/drivers/blk/blkfront_xb.h |  60 +++++++++++++++
>  plat/xen/drivers/blk/blkfront_xs.c | 119 +++++++++++++++++++++++++++++
>  5 files changed, 200 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 73b98f29..2a8cdbf6 100644
> --- a/plat/xen/Makefile.uk
> +++ b/plat/xen/Makefile.uk
> @@ -120,6 +120,7 @@ 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
>  
>  ifeq ($(CONFIG_XEN_9PFRONT),y)
> diff --git a/plat/xen/drivers/blk/blkfront.c b/plat/xen/drivers/blk/blkfront.c
> index d3677ea4..09302f45 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"
>  
> @@ -53,6 +54,10 @@
>  
>  static struct uk_alloc *drv_allocator;
>  
> +
> +/**
> + * Assign callbacks to uk_blkdev
> + */
>  static int blkfront_add_dev(struct xenbus_device *dev)
>  {
>       struct blkfront_dev *d = NULL;
> @@ -64,6 +69,15 @@ static int blkfront_add_dev(struct xenbus_device *dev)
>       if (!d)
>               return -ENOMEM;
>  
> +     d->xendev = dev;
> +
> +     /* 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",
> @@ -77,6 +91,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..f00ed41b 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;
> +     /* Blkfront device number from Xenstore path. */
> +     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..7b62dbeb
> --- /dev/null
> +++ b/plat/xen/drivers/blk/blkfront_xb.h
> @@ -0,0 +1,60 @@
> +/* 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..366c069b
> --- /dev/null
> +++ b/plat/xen/drivers/blk/blkfront_xs.c
> @@ -0,0 +1,119 @@
> +/* 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.
> + */
> +#define _GNU_SOURCE /* for asprintf() */
> +#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;
> +     }
> +}
> 

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