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

Re: [Minios-devel] [UNIKRAFT/REDIS PATCH v2 4/4] Provide main() function if configured to do so



Same remarks as in the 2/4 patch.

Reviewed-by: Stefan Teodorescu <stefanl.teodorescu@xxxxxxxxx>

On Sun, Nov 17, 2019 at 9:21 AM Costin Lupu <costin.lup@xxxxxxxxx> wrote:
>
> We add config options for enabling a main() function provided by our Redis 
> glue
> code. This supports running both the server and the client. Given that a VM 
> may
> run as a Redis server but can also be a client to another Redis server, a
> Redis-on-Unikraft instance can run with both server and client enabled.
> Moreover, we can even connect the client to the local server.
>
> Signed-off-by: Costin Lupu <costin.lupu@xxxxxxxxx>
> ---
>  Config.uk   |  18 ++++++++
>  Makefile.uk |   2 +
>  main.c      | 118 ++++++++++++++++++++++++++++++++++++++++++++++++++++
>  3 files changed, 138 insertions(+)
>  create mode 100644 main.c
>
> diff --git a/Config.uk b/Config.uk
> index 754c4a1..f31e14a 100644
> --- a/Config.uk
> +++ b/Config.uk
> @@ -18,6 +18,10 @@ config LIBREDIS_COMMON
>         select LIBPOSIX_LIBDL
>         select LIBLWIP
>         select LWIP_IPV6
> +# hidden
> +config LIBREDIS_MAIN_FUNCTION
> +       bool
> +       default n
>
>  config LIBREDIS_SERVER
>         bool "Redis server"
> @@ -28,6 +32,13 @@ config LIBREDIS_SERVER
>         help
>                 Build the Redis server library.
>
> +       if LIBREDIS_SERVER
> +               config LIBREDIS_SERVER_MAIN_FUNCTION
> +                       bool "Provide main function"
> +                       default n
> +                       select LIBREDIS_MAIN_FUNCTION
> +       endif
> +
>  config LIBREDIS_CLIENT
>         bool "Redis client"
>         default n
> @@ -36,6 +47,13 @@ config LIBREDIS_CLIENT
>         help
>                 Build the Redis client library.
>
> +       if LIBREDIS_CLIENT
> +               config LIBREDIS_CLIENT_MAIN_FUNCTION
> +                       bool "Provide main function"
> +                       default n
> +                       select LIBREDIS_MAIN_FUNCTION
> +       endif
> +
>  config LIBREDIS_LUA
>         bool "Use internal Lua implementation"
>         default n
> diff --git a/Makefile.uk b/Makefile.uk
> index 35287ba..0c3ec7d 100644
> --- a/Makefile.uk
> +++ b/Makefile.uk
> @@ -154,6 +154,8 @@ LIBREDIS_COMMON_SRCS-y += $(LIBREDIS_SRC)/release.c
>  LIBREDIS_COMMON_SRCS-y += $(LIBREDIS_SRC)/siphash.c
>  LIBREDIS_COMMON_SRCS-y += $(LIBREDIS_SRC)/zmalloc.c
>
> +LIBREDIS_COMMON_SRCS-$(CONFIG_LIBREDIS_MAIN_FUNCTION) += 
> $(LIBREDIS_BASE)/main.c|unikraft
> +
>  
> ################################################################################
>  # Redis server
>  
> ################################################################################
> diff --git a/main.c b/main.c
> new file mode 100644
> index 0000000..1ec7630
> --- /dev/null
> +++ b/main.c
> @@ -0,0 +1,118 @@
> +/* SPDX-License-Identifier: BSD-3-Clause */
> +/*
> + * Authors: Costin Lupu <costin.lupu@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 <uk/config.h>
> +#include <stdlib.h>
> +#include <pthread.h>
> +#include <unistd.h>
> +
> +struct arg_wrapper {
> +       int argc;
> +       char **argv;
> +};
> +
> +
> +/*
> + * Server thread
> + */
> +#if CONFIG_LIBREDIS_SERVER_MAIN_FUNCTION
> +extern int redis_server_main(int argc, char *argv[]);
> +
> +void *server_thread_fn(void *arg)
> +{
> +       long rc;
> +       struct arg_wrapper *aw = arg;
> +
> +       rc = redis_server_main(aw->argc, aw->argv);
> +       return (void *) rc;
> +}
> +#endif
> +
> +/*
> + * Client thread
> + */
> +#if CONFIG_LIBREDIS_CLIENT_MAIN_FUNCTION
> +extern int redis_client_main(int argc, char *argv[]);
> +
> +void *client_thread_fn(void *arg)
> +{
> +       long rc;
> +       struct arg_wrapper *aw = arg;
> +
> +       /* Wait for environment to be ready */
> +       sleep(2);
> +
> +       rc = redis_client_main(aw->argc, aw->argv);
> +       return (void *) rc;
> +}
> +#endif
> +
> +int main(int argc, char *argv[])
> +{
> +       int rc, _rc;
> +       struct arg_wrapper aw;
> +#if CONFIG_LIBREDIS_SERVER_MAIN_FUNCTION
> +       pthread_t thread_server;
> +#endif
> +#if CONFIG_LIBREDIS_CLIENT_MAIN_FUNCTION
> +       pthread_t thread_client;
> +#endif
> +
> +       aw.argc = argc;
> +       aw.argv = argv;
> +
> +       /* Start server */
> +#if CONFIG_LIBREDIS_SERVER_MAIN_FUNCTION
> +       rc = pthread_create(&thread_server, NULL, server_thread_fn, &aw);
> +       if (rc)
> +               goto out;
> +#endif
> +
> +       /* Start client and wait for it to end */
> +#if CONFIG_LIBREDIS_CLIENT_MAIN_FUNCTION
> +       rc = pthread_create(&thread_client, NULL, client_thread_fn, &aw);
> +       if (rc == 0)
> +               rc = pthread_join(thread_client, NULL);
> +#endif
> +
> +       /* Wait for server to end */
> +#if CONFIG_LIBREDIS_SERVER_MAIN_FUNCTION
> +       _rc = pthread_join(thread_server, NULL);
> +       if (_rc && !rc)
> +               rc = _rc;
> +out:
> +#endif
> +
> +       return rc;
> +}
> --
> 2.20.1
>
>
> _______________________________________________
> Minios-devel mailing list
> Minios-devel@xxxxxxxxxxxxxxxxxxxx
> https://lists.xenproject.org/mailman/listinfo/minios-devel

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