Re: [dm-devel] [PATCH v2 15/23] libmultipath: API for foreign multipath handling

2018-03-07 Thread Benjamin Marzinski
On Tue, Mar 06, 2018 at 12:14:59AM +0100, Martin Wilck wrote:
> Add an API for "foreign" multipaths. Foreign libraries are loaded
> from ${multipath_dir}/libforeign-*.so, as we do for checkers.
> 
> Refer to "foreign.h" for details about the API itself. Like we do for
> checkers, high-level multipath code isn't supposed to call the API directly,
> but rather the wrapper functions declared in "foreign.h".
> 
> This API is used only for displaying information and for logging. An 
> extension to
> other functionality (such as monitoring or administration) might be feasible,
> but is not planned.
> 
> Foreign libraries communicate with libmultipath through the API defined in
> "foreign.h". The foreign library can implement multipath maps, pathgroups,
> and paths as it likes, they just need to provide the simple interfaces
> defined in "generic.h" to libmultipath. These interfaces are used in 
> libmultipath's
> "print" implementation to convey various bits of information to users. By
> using the same interfaces for printing that libmultipath uses internally,
> foreign library implementations can focus on the technical side without
> worrying about output formatting compatibility.
> 

Reviewed-by: Benjamin Marzinski 

I don't think the foreign_lock is strictly necessary, since I can't see
any way of any for the readers to be running at the same time as the
writers, simply because the readers all happen in threads that have
either not been created yet, or have already been joined when the
writers run.  But the locking code all makes sense, and I'm fine with
it.

> Signed-off-by: Martin Wilck 
> ---
>  libmultipath/Makefile  |   2 +-
>  libmultipath/foreign.c | 602 
> +
>  libmultipath/foreign.h | 322 ++
>  3 files changed, 925 insertions(+), 1 deletion(-)
>  create mode 100644 libmultipath/foreign.c
>  create mode 100644 libmultipath/foreign.h
> 
> diff --git a/libmultipath/Makefile b/libmultipath/Makefile
> index 0099d9d6cc39..806aaa24f84e 100644
> --- a/libmultipath/Makefile
> +++ b/libmultipath/Makefile
> @@ -43,7 +43,7 @@ OBJS = memory.o parser.o vector.o devmapper.o callout.o \
>   switchgroup.o uxsock.o print.o alias.o log_pthread.o \
>   log.o configure.o structs_vec.o sysfs.o prio.o checkers.o \
>   lock.o waiter.o file.o wwids.o prioritizers/alua_rtpg.o prkey.o \
> - io_err_stat.o dm-generic.o generic.o
> + io_err_stat.o dm-generic.o generic.o foreign.o
>  
>  all: $(LIBS)
>  
> diff --git a/libmultipath/foreign.c b/libmultipath/foreign.c
> new file mode 100644
> index ..72171840e995
> --- /dev/null
> +++ b/libmultipath/foreign.c
> @@ -0,0 +1,602 @@
> +/*
> +  Copyright (c) 2018 Martin Wilck, SUSE Linux GmbH
> +
> +  This program is free software; you can redistribute it and/or
> +  modify it under the terms of the GNU General Public License
> +  as published by the Free Software Foundation; either version 2
> +  of the License, or (at your option) any later version.
> +
> +  This program is distributed in the hope that it will be useful,
> +  but WITHOUT ANY WARRANTY; without even the implied warranty of
> +  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> +  GNU General Public License for more details.
> +
> +  You should have received a copy of the GNU General Public License
> +  along with this program; if not, write to the Free Software
> +  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
> +  USA.
> +*/
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include "vector.h"
> +#include "debug.h"
> +#include "util.h"
> +#include "foreign.h"
> +#include "structs.h"
> +#include "structs_vec.h"
> +#include "print.h"
> +
> +static vector foreigns;
> +
> +/* This protects vector foreigns */
> +static pthread_rwlock_t foreign_lock = PTHREAD_RWLOCK_INITIALIZER;
> +
> +static void rdlock_foreigns(void)
> +{
> + pthread_rwlock_rdlock(_lock);
> +}
> +
> +static void wrlock_foreigns(void)
> +{
> + pthread_rwlock_wrlock(_lock);
> +}
> +
> +static void unlock_foreigns(void *unused)
> +{
> + pthread_rwlock_unlock(_lock);
> +}
> +
> +#define get_dlsym(foreign, sym, lbl) \
> + do {\
> + foreign->sym =  dlsym(foreign->handle, #sym);   \
> + if (foreign->sym == NULL) { \
> + condlog(0, "%s: symbol \"%s\" not found in \"%s\"", \
> + __func__, #sym, foreign->name); \
> + goto lbl;   \
> + }   \
> + } while(0)
> +
> +static void free_foreign(struct foreign *fgn)
> +{
> + struct context *ctx;
> +
> + if 

Re: [dm-devel] [PATCH v2 15/23] libmultipath: API for foreign multipath handling

2018-03-05 Thread Hannes Reinecke
On 03/06/2018 12:14 AM, Martin Wilck wrote:
> Add an API for "foreign" multipaths. Foreign libraries are loaded
> from ${multipath_dir}/libforeign-*.so, as we do for checkers.
> 
> Refer to "foreign.h" for details about the API itself. Like we do for
> checkers, high-level multipath code isn't supposed to call the API directly,
> but rather the wrapper functions declared in "foreign.h".
> 
> This API is used only for displaying information and for logging. An 
> extension to
> other functionality (such as monitoring or administration) might be feasible,
> but is not planned.
> 
> Foreign libraries communicate with libmultipath through the API defined in
> "foreign.h". The foreign library can implement multipath maps, pathgroups,
> and paths as it likes, they just need to provide the simple interfaces
> defined in "generic.h" to libmultipath. These interfaces are used in 
> libmultipath's
> "print" implementation to convey various bits of information to users. By
> using the same interfaces for printing that libmultipath uses internally,
> foreign library implementations can focus on the technical side without
> worrying about output formatting compatibility.
> 
> Signed-off-by: Martin Wilck 
> ---
>  libmultipath/Makefile  |   2 +-
>  libmultipath/foreign.c | 602 
> +
>  libmultipath/foreign.h | 322 ++
>  3 files changed, 925 insertions(+), 1 deletion(-)
>  create mode 100644 libmultipath/foreign.c
>  create mode 100644 libmultipath/foreign.h
> 
Reviewed-by: Hannes Reinecke 

Cheers,

Hannes
-- 
Dr. Hannes ReineckeTeamlead Storage & Networking
h...@suse.de   +49 911 74053 688
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg
GF: F. Imendörffer, J. Smithard, J. Guild, D. Upmanyu, G. Norton
HRB 21284 (AG Nürnberg)

--
dm-devel mailing list
dm-devel@redhat.com
https://www.redhat.com/mailman/listinfo/dm-devel