[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] Re: [Minios-devel] [UNIKRAFT PATCH v3 2/8] lib/uk9p: Add 9P transport registration
Thanks for the changes. If you are okay I will add an assertion on your default transport setter while upstreaming... you can see it inline. Reviewed-by: Simon Kuenzer <simon.kuenzer@xxxxxxxxx> On 05.09.19 14:14, Cristian Banu wrote: This patch introduces the 9P transport registration and lookup API. Transports are communication channels such as virtio by using the virtio-9p device, or xen rings. Those are the default transports for the KVM and Xen platforms respectively. However, in the future one might have multiple available transports for the same platform by supporting TCP or RDMA. Signed-off-by: Cristian Banu <cristb@xxxxxxxxx> --- lib/uk9p/9pdev_trans.c | 82 ++++++++++++++++++++++++++++++ lib/uk9p/Makefile.uk | 2 + lib/uk9p/exportsyms.uk | 4 ++ lib/uk9p/include/uk/9pdev_trans.h | 102 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 190 insertions(+) create mode 100644 lib/uk9p/9pdev_trans.c create mode 100644 lib/uk9p/exportsyms.uk create mode 100644 lib/uk9p/include/uk/9pdev_trans.h diff --git a/lib/uk9p/9pdev_trans.c b/lib/uk9p/9pdev_trans.c new file mode 100644 index 000000000000..081dac85df33 --- /dev/null +++ b/lib/uk9p/9pdev_trans.c @@ -0,0 +1,82 @@ +/* SPDX-License-Identifier: BSD-3-Clause */ +/* + * Authors: Cristian Banu <cristb@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 <errno.h> +#include <string.h> +#include <uk/config.h> +#include <uk/list.h> +#include <uk/assert.h> +#include <uk/9pdev_trans.h> + +static UK_LIST_HEAD(uk_9pdev_trans_list); + +static struct uk_9pdev_trans *uk_9pdev_trans_saved_default; + +int uk_9pdev_trans_register(struct uk_9pdev_trans *trans) +{ + UK_ASSERT(trans); + UK_ASSERT(trans->name); + UK_ASSERT(trans->a); + + uk_list_add_tail(&trans->_list, &uk_9pdev_trans_list); + + if (!uk_9pdev_trans_saved_default) + uk_9pdev_trans_saved_default = trans; + + uk_pr_info("Registered transport %s\n", trans->name); + + return 0; +} + +struct uk_9pdev_trans *uk_9pdev_trans_by_name(const char *name) +{ + struct uk_9pdev_trans *t; + + uk_list_for_each_entry(t, &uk_9pdev_trans_list, _list) { + if (!strcmp(t->name, name)) + return t; + } + + return NULL; +} + +struct uk_9pdev_trans *uk_9pdev_trans_get_default(void) +{ + return uk_9pdev_trans_saved_default; +} + +void uk_9pdev_trans_set_default(struct uk_9pdev_trans *trans) +{ I would add an assertion here to check that trans is never NULL: UK_ASSERT(trans); + uk_9pdev_trans_saved_default = trans; +} diff --git a/lib/uk9p/Makefile.uk b/lib/uk9p/Makefile.uk index fa754440598c..b1071a0e7d3c 100644 --- a/lib/uk9p/Makefile.uk +++ b/lib/uk9p/Makefile.uk @@ -2,3 +2,5 @@ $(eval $(call addlib_s,libuk9p,$(CONFIG_LIBUK9P)))CINCLUDES-$(CONFIG_LIBUK9P) += -I$(LIBUK9P_BASE)/includeCXXINCLUDES-$(CONFIG_LIBUK9P) += -I$(LIBUK9P_BASE)/include + +LIBUK9P_SRCS-y += $(LIBUK9P_BASE)/9pdev_trans.c diff --git a/lib/uk9p/exportsyms.uk b/lib/uk9p/exportsyms.uk new file mode 100644 index 000000000000..46f400825af8 --- /dev/null +++ b/lib/uk9p/exportsyms.uk @@ -0,0 +1,4 @@ +uk_9pdev_trans_register +uk_9pdev_trans_by_name +uk_9pdev_trans_get_default +uk_9pdev_trans_set_default diff --git a/lib/uk9p/include/uk/9pdev_trans.h b/lib/uk9p/include/uk/9pdev_trans.h new file mode 100644 index 000000000000..a648dbfba927 --- /dev/null +++ b/lib/uk9p/include/uk/9pdev_trans.h @@ -0,0 +1,102 @@ +/* SPDX-License-Identifier: BSD-3-Clause */ +/* + * Authors: Cristian Banu <cristb@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 __UK_9PDEV_TRANS__ +#define __UK_9PDEV_TRANS__ + +#include <stdbool.h> +#include <uk/config.h> + +#ifdef __cplusplus +extern "C" { +#endif + +/** A structure used to describe a transport. */ +struct uk_9pdev_trans { + /* + * Transport name (e.g. "virtio", "xen"). This field is reserved for + * future use, when multiple transport options are available on the + * same platform, such as RDMA or TCP, in addition to the platform + * specific transport. + */ + const char *name; + /* Allocator used for devices which use this transport layer. */ + struct uk_alloc *a; + /* @internal Entry in the list of available transports. */ + struct uk_list_head _list; +}; + +/** + * Adds a transport to the available transports list for Unikraft 9P Devices. + * This should be called once per driver (once for virtio, once for xen, etc.). + * + * @param trans + * Pointer to the transport structure. + * @return + * - (0): Successful. + * - (< 0): Failed to register the transport layer. + */ +int uk_9pdev_trans_register(struct uk_9pdev_trans *trans); + +/** + * Looks up a transport layer by its name. + * + * @param name + * The transport layer name. + * @return + * The 9P transport with the given name, or NULL if missing. + */ +struct uk_9pdev_trans *uk_9pdev_trans_by_name(const char *name); + +/** + * Gets the default transport layer. + * + * @return + * The default 9P transport, or NULL if missing. + */ +struct uk_9pdev_trans *uk_9pdev_trans_get_default(void); + +/** + * Sets the default transport layer. + * + * @param trans + * The default 9P transport. + */ +void uk_9pdev_trans_set_default(struct uk_9pdev_trans *trans); + +#ifdef __cplusplus +} +#endif + +#endif /* __UK_9PDEV_TRANS__ */ _______________________________________________ Minios-devel mailing list Minios-devel@xxxxxxxxxxxxxxxxxxxx https://lists.xenproject.org/mailman/listinfo/minios-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |