[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] Re: [Minios-devel] [UNIKRAFT PATCH 2/6] lib/ukblkdev: Blkdev registration
This patch looks fine. Reviewed-by: Simon Kuenzer <simon.kuenzer@xxxxxxxxx> On 29.05.19 10:33, Roxana Nicolescu wrote: This patch introduces the initial blkdev API supporting device registration. We introduce three header files for describing Unikraft's blkdev API: uk/blkdev_core.h - Core data type definitions uk/blkdev_driver.h - API for drivers uk/blkdev.h - API for block applications Signed-off-by: Roxana Nicolescu <nicolescu.roxana1996@xxxxxxxxx> --- lib/ukblkdev/Makefile.uk | 2 + lib/ukblkdev/blkdev.c | 133 ++++++++++++++++++++++++++++++++ lib/ukblkdev/exportsyms.uk | 6 ++ lib/ukblkdev/include/uk/blkdev.h | 128 ++++++++++++++++++++++++++++++ lib/ukblkdev/include/uk/blkdev_core.h | 98 +++++++++++++++++++++++ lib/ukblkdev/include/uk/blkdev_driver.h | 77 ++++++++++++++++++ 6 files changed, 444 insertions(+) create mode 100644 lib/ukblkdev/blkdev.c create mode 100644 lib/ukblkdev/exportsyms.uk create mode 100644 lib/ukblkdev/include/uk/blkdev.h create mode 100644 lib/ukblkdev/include/uk/blkdev_core.h create mode 100644 lib/ukblkdev/include/uk/blkdev_driver.h diff --git a/lib/ukblkdev/Makefile.uk b/lib/ukblkdev/Makefile.uk index 62c62045..b91417e2 100644 --- a/lib/ukblkdev/Makefile.uk +++ b/lib/ukblkdev/Makefile.uk @@ -2,3 +2,5 @@ $(eval $(call addlib_s,libukblkdev,$(CONFIG_LIBUKBLKDEV)))CINCLUDES-$(CONFIG_LIBUKBLKDEV) += -I$(LIBUKBLKDEV_BASE)/includeCXXINCLUDES-$(CONFIG_LIBUKBLKDEV) += -I$(LIBUKBLKDEV_BASE)/include + +LIBUKBLKDEV_SRCS-y += $(LIBUKBLKDEV_BASE)/blkdev.c diff --git a/lib/ukblkdev/blkdev.c b/lib/ukblkdev/blkdev.c new file mode 100644 index 00000000..dfacf1ca --- /dev/null +++ b/lib/ukblkdev/blkdev.c @@ -0,0 +1,133 @@ +/* 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. + */ +/* This is derived from uknetdev because of consistency reasons */ +#include <string.h> +#include <stdio.h> +#include <inttypes.h> +#include <uk/alloc.h> +#include <uk/assert.h> +#include <uk/bitops.h> +#include <uk/print.h> +#include <uk/plat/ctors.h> +#include <uk/refcount.h> +#include <uk/blkdev.h> + +struct uk_blkdev_list uk_blkdev_list = + UK_TAILQ_HEAD_INITIALIZER(uk_blkdev_list); + +static uint16_t blkdev_count; + +static struct uk_blkdev_data *_alloc_data(struct uk_alloc *a, + uint16_t blkdev_id, + const char *drv_name) +{ + struct uk_blkdev_data *data; + + data = uk_calloc(a, 1, sizeof(*data)); + if (!data) + return NULL; + + data->drv_name = drv_name; + data->state = UK_BLKDEV_UNCONFIGURED; + + /* This is the only place where we set the device ID; + * during the rest of the device's life time this ID is read-only + */ + *(DECONST(uint16_t *, &data->id)) = blkdev_id; + + return data; +} + +int uk_blkdev_drv_register(struct uk_blkdev *dev, struct uk_alloc *a, + const char *drv_name) +{ + UK_ASSERT(dev); + + /* Data must be unallocated. */ + UK_ASSERT(PTRISERR(dev->_data)); + + dev->_data = _alloc_data(a, blkdev_count, drv_name); + if (!dev->_data) + return -ENOMEM; + + UK_TAILQ_INSERT_TAIL(&uk_blkdev_list, dev, _list); + uk_pr_info("Registered blkdev%"PRIu16": %p (%s)\n", + blkdev_count, dev, drv_name); + dev->_data->state = UK_BLKDEV_UNCONFIGURED; + + return blkdev_count++; +} + +unsigned int uk_blkdev_count(void) +{ + return (unsigned int) blkdev_count; +} + +struct uk_blkdev *uk_blkdev_get(unsigned int id) +{ + struct uk_blkdev *blkdev; + + UK_TAILQ_FOREACH(blkdev, &uk_blkdev_list, _list) { + UK_ASSERT(blkdev->_data); + if (blkdev->_data->id == id) + return blkdev; + } + + return NULL; +} + +uint16_t uk_blkdev_id_get(struct uk_blkdev *dev) +{ + UK_ASSERT(dev); + UK_ASSERT(dev->_data); + + return dev->_data->id; +} + +const char *uk_blkdev_drv_name_get(struct uk_blkdev *dev) +{ + UK_ASSERT(dev); + UK_ASSERT(dev->_data); + + return dev->_data->drv_name; +} + +enum uk_blkdev_state uk_blkdev_state_get(struct uk_blkdev *dev) +{ + UK_ASSERT(dev); + UK_ASSERT(dev->_data); + + return dev->_data->state; +} diff --git a/lib/ukblkdev/exportsyms.uk b/lib/ukblkdev/exportsyms.uk new file mode 100644 index 00000000..34e22426 --- /dev/null +++ b/lib/ukblkdev/exportsyms.uk @@ -0,0 +1,6 @@ +uk_blkdev_drv_register +uk_blkdev_count +uk_blkdev_get +uk_blkdev_id_get +uk_blkdev_drv_name_get +uk_blkdev_state_get diff --git a/lib/ukblkdev/include/uk/blkdev.h b/lib/ukblkdev/include/uk/blkdev.h new file mode 100644 index 00000000..d678677f --- /dev/null +++ b/lib/ukblkdev/include/uk/blkdev.h @@ -0,0 +1,128 @@ +/* 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. + */ +/* This is derived from uknetdev because of consistency reasons */ +#ifndef __UK_BLKDEV__ +#define __UK_BLKDEV__ + +/** + * Unikraft Block API + * + * The Unikraft BLK API provides a generalized interface between Unikraft + * drivers and low-level application which needs communication with + * a block device. + * + * Most BLK API functions take as parameter a reference to the corresponding + * Unikraft Block Device (struct uk_blkdev) which can be obtained with a call + * to uk_blkdev_get(). The block app should store this reference and + * use it for all subsequent API calls. + * + * There are 4 states in which a block device can be found: + * - UK_BLKDEV_UNREGISTERED + * - UK_BLKDEV_UNCONFIGURED + * - UK_BLKDEV_CONFIGURED + * - UK_BLKDEV_RUNNING + */ + +#include <sys/types.h> +#include <stdint.h> +#include <stdio.h> +#include <errno.h> +#include <uk/list.h> +#include <uk/errptr.h> + +#include "blkdev_core.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * Get the number of available Unikraft Block devices. + * + * @return + * - (unsigned int): number of block devices. + */ +unsigned int uk_blkdev_count(void); + +/** + * Get a reference to a Unikraft Block Device, based on its ID. + * This reference should be saved by the application and used for subsequent + * API calls. + * + * @param id + * The identifier of the Unikraft block device to configure. + * @return + * - NULL: device not found in list + * - (struct uk_blkdev *): reference to be passed to API calls + */ +struct uk_blkdev *uk_blkdev_get(unsigned int id); + +/** + * Returns the id of a block device + * + * @param dev + * The Unikraft Block Device. + * @return + * - (>=0): Device ID + */ +uint16_t uk_blkdev_id_get(struct uk_blkdev *dev); + +/** + * Returns the driver name of a blkdev device. + * The name might be set to NULL. + * + * @param dev + * The Unikraft Block Device. + * @return + * - (NULL): if no name is defined. + * - (const char *): Reference to string if name is available. + */ +const char *uk_blkdev_drv_name_get(struct uk_blkdev *dev); + +/** + * Returns the current state of a blkdev device. + * + * @param dev + * The Unikraft Block Device. + * @return + * - (enum uk_blkdev_state): current device state + */ +enum uk_blkdev_state uk_blkdev_state_get(struct uk_blkdev *dev); + +#ifdef __cplusplus +} +#endif + +#endif /* __UK_BLKDEV__ */ diff --git a/lib/ukblkdev/include/uk/blkdev_core.h b/lib/ukblkdev/include/uk/blkdev_core.h new file mode 100644 index 00000000..3cccf87e --- /dev/null +++ b/lib/ukblkdev/include/uk/blkdev_core.h @@ -0,0 +1,98 @@ +/* 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. + */ +/* This is derived from uknetdev because of consistency reasons */ +#ifndef __UK_BLKDEV_CORE__ +#define __UK_BLKDEV_CORE__ + +#include <uk/list.h> +#include <uk/config.h> + +/** + * Unikraft block API common declarations. + * + * This header contains all API data types. Some of them are part of the + * public API and some are part of the internal API. + * + * The device data and operations are separated. This split allows the + * function pointer and driver data to be per-process, while the actual + * configuration data for the device is shared. + */ + +#ifdef __cplusplus +extern "C" { +#endif + +struct uk_blkdev; + +/** + * List with devices + */ +UK_TAILQ_HEAD(uk_blkdev_list, struct uk_blkdev); + +/** + * Enum to describe the possible states of an block device. + */ +enum uk_blkdev_state { + UK_BLKDEV_INVALID = 0, + UK_BLKDEV_UNCONFIGURED, + UK_BLKDEV_CONFIGURED, + UK_BLKDEV_RUNNING, +}; + +/** + * @internal + * libukblkdev internal data associated with each block device. + */ +struct uk_blkdev_data { + /* Device id identifier */ + const uint16_t id; + /* Device state */ + enum uk_blkdev_state state; + /* Name of device*/ + const char *drv_name; +}; + +struct uk_blkdev { + /* Pointer to API-internal state data. */ + struct uk_blkdev_data *_data; + /* Entry for list of block devices */ + UK_TAILQ_ENTRY(struct uk_blkdev) _list; +}; + +#ifdef __cplusplus +} +#endif + +#endif /* __UK_BLKDEV_CORE__ */ diff --git a/lib/ukblkdev/include/uk/blkdev_driver.h b/lib/ukblkdev/include/uk/blkdev_driver.h new file mode 100644 index 00000000..b72f52ab --- /dev/null +++ b/lib/ukblkdev/include/uk/blkdev_driver.h @@ -0,0 +1,77 @@ +/* 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. + */ +/* This is derived from uknetdev because of consistency reasons */ +#ifndef __UK_BLKDEV_DRIVER__ +#define __UK_BLKDEV_DRIVER__ + +#include <uk/blkdev_core.h> +#include <uk/assert.h> + +/** + * Unikraft block driver API. + * + * This header contains all API functions that are supposed to be called + * by a block device driver. + */ + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * Adds a Unikraft block device to the device list. + * This should be called whenever a driver adds a new found device. + * + * @param dev + * Struct to unikraft block device that shall be registered + * @param a + * Allocator to be use for libukblkdev private data (dev->_data) + * @param drv_name + * (Optional) driver name + * The memory for this string has to stay available as long as the + * device is registered. + * @return + * - (-ENOMEM): Allocation of private + * - (>=0): Block device ID on success + */ +int uk_blkdev_drv_register(struct uk_blkdev *dev, + struct uk_alloc *a, + const char *drv_name); + +#ifdef __cplusplus +} +#endif + +#endif /* __UK_BLKDEV_DRIVER__ */ _______________________________________________ Minios-devel mailing list Minios-devel@xxxxxxxxxxxxxxxxxxxx https://lists.xenproject.org/mailman/listinfo/minios-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |