Skip to contentSkip to conversation

Split libmultipath and libmpathutil

PATCH Superseded [email protected] 2 participants 14 messages Aug 22, 2022 – Aug 29, 2022

Subsystems (2)

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v2 cover Split libmultipath and libmpathutil

From: Martin Wilck <[email protected]>

Following the recent discussions about the licensing conflict between parts of libmultipath and libreadline, here comes another series for cleaning up the situation further.

Patch 1 is a modified version of https://github.com/opensvc/multipath-tools/pull/41.
Patch 2-7 are minor cleanups in preparation of the library split.

In patch8, a part of libmultipath is split off into a new library, libmpathutil. This new library contains no GPL-2.0-only code, and is thus shipped under GPL-2.0-or-later license, which is compatible with libreadline. The bulk of the multipath-specific code, including the GPL-2.0-only files, remains in libmultipath, which is thus still shipped under
a GPL-2.0-only license.

A new command "multipathc" is created in patch 9 that is now the only part of the code that uses libreadline functionality, and links to libmpathutil only. With patch 10, in interactive mode, "multipathd -k" just exec()s t his new program.

This split makes it rather obvious that the part of the multipath-tools code that depended on libreadline is small. It is still possible to control whether a readline library is used at all. This is done with the READLINE make variable, which can be empty (in which case no readline library is needed), or have the value "libreadline", or "libedit".

Patch 11 is a minor fix for older versions of libreadline.

Changes v1(RFC) -> v2:
- added patches 03 and 11. Numbering changes accordingly
- added SPDX header to multipathc.c
- fix some compilation errors

Hannes Reinecke (1):
multipathd: replace libreadline with getline()

Martin Wilck (10):
.gitignore: ignore generated ABI files
libmultipath: move all reservation key functions to prkey.c
libmultipath: always set _GNU_SOURCE
multipath-tools: Makefile: fix dependencies for "install" target libmultipath checkers/prioritizers: search for includes in
libmultipath
libmultipath: remove weak attribute for {get,put}_multipath_config
libmultipath: split off libmpathutil
multipathc: add new interactive client program
multipathd: exec multipathc in interactive mode
multipathd: fix incompatible pointer type error with libedit

 .gitignore                                   |   3 +
 Makefile                                     |   8 +-
 Makefile.inc                                 |   5 +-
 libmpathpersist/Makefile                     |   6 +-
 libmpathutil/Makefile                        |  70 +++++
 {libmultipath => libmpathutil}/debug.c       |   0
 {libmultipath => libmpathutil}/debug.h       |   0
 libmpathutil/globals.c                       |  12 +
 libmpathutil/globals.h                       |  39 +++
 libmpathutil/libmpathutil.version            | 122 +++++++++
 {libmultipath => libmpathutil}/log.c         |   0
 {libmultipath => libmpathutil}/log.h         |   0
 {libmultipath => libmpathutil}/log_pthread.c |   0
 {libmultipath => libmpathutil}/log_pthread.h |   0
 {libmultipath => libmpathutil}/parser.c      |   0
 {libmultipath => libmpathutil}/parser.h      |   2 +-
 {libmultipath => libmpathutil}/strbuf.c      |   0
 {libmultipath => libmpathutil}/strbuf.h      |   0
 {libmultipath => libmpathutil}/time-util.c   |   0
 {libmultipath => libmpathutil}/time-util.h   |   0
 {libmultipath => libmpathutil}/util.c        |  32 ---
 {libmultipath => libmpathutil}/util.h        |   2 -
 {libmultipath => libmpathutil}/uxsock.c      |   0
 {libmultipath => libmpathutil}/uxsock.h      |   0
 {libmultipath => libmpathutil}/vector.c      |   0
 {libmultipath => libmpathutil}/vector.h      |   0
 libmpathvalid/Makefile                       |   6 +-
 libmultipath/Makefile                        |  17 +-
 libmultipath/checkers/Makefile               |   7 +-
 libmultipath/checkers/directio.c             |   4 +-
 libmultipath/checkers/tur.c                  |   8 +-
 libmultipath/config.c                        |   4 +-
 libmultipath/config.h                        |  14 +-
 libmultipath/dict.c                          |  16 +-
 libmultipath/dict.h                          |   2 -
 libmultipath/foreign/Makefile                |   6 +-
 libmultipath/libmultipath.version            |  41 ---
 libmultipath/prioritizers/Makefile           |   8 +-
 libmultipath/prioritizers/alua_rtpg.c        |   2 +-
 libmultipath/prkey.c                         |  49 +++-
 libmultipath/prkey.h                         |   3 +
 mpathpersist/Makefile                        |   4 +-
 multipath/Makefile                           |   6 +-
 multipathd/Makefile                          |  43 ++-
 multipathd/cli.c                             | 128 +--------
 multipathd/cli.h                             |   5 +-
 multipathd/main.c                            |  15 +-
 multipathd/multipathc.c                      | 271 +++++++++++++++++++
 multipathd/uxclnt.c                          | 108 +-------
 tests/Makefile                               |   8 +-
 50 files changed, 687 insertions(+), 389 deletions(-)
 create mode 100644 libmpathutil/Makefile
 rename {libmultipath => libmpathutil}/debug.c (100%)
 rename {libmultipath => libmpathutil}/debug.h (100%)
 create mode 100644 libmpathutil/globals.c
 create mode 100644 libmpathutil/globals.h
 create mode 100644 libmpathutil/libmpathutil.version
 rename {libmultipath => libmpathutil}/log.c (100%)
 rename {libmultipath => libmpathutil}/log.h (100%)
 rename {libmultipath => libmpathutil}/log_pthread.c (100%)
 rename {libmultipath => libmpathutil}/log_pthread.h (100%)
 rename {libmultipath => libmpathutil}/parser.c (100%)
 rename {libmultipath => libmpathutil}/parser.h (99%)
 rename {libmultipath => libmpathutil}/strbuf.c (100%)
 rename {libmultipath => libmpathutil}/strbuf.h (100%)
 rename {libmultipath => libmpathutil}/time-util.c (100%)
 rename {libmultipath => libmpathutil}/time-util.h (100%)
 rename {libmultipath => libmpathutil}/util.c (92%)
 rename {libmultipath => libmpathutil}/util.h (96%)
 rename {libmultipath => libmpathutil}/uxsock.c (100%)
 rename {libmultipath => libmpathutil}/uxsock.h (100%)
 rename {libmultipath => libmpathutil}/vector.c (100%)
 rename {libmultipath => libmpathutil}/vector.h (100%)
 create mode 100644 multipathd/multipathc.c
Signature · 6 lines
2.37.1

--
dm-devel mailing list
[email protected]
https://listman.redhat.com/mailman/listinfo/dm-devel
#1 lore raw

PATCH v2 1/11 multipathd: replace libreadline with getline()

From: Hannes Reinecke <[email protected]>

libreadline changed the license to be incompatible with multipath-tools usage, so replace it with a simple getline().

mwilck: Make this the default option via Makefile.inc; it is used if READLINE is unset. Compiling with READLINE=libreadline or READLINE=libedit remains possible.

---
 Makefile.inc        |  4 ++--
 multipathd/cli.c    |  2 ++
 multipathd/uxclnt.c | 50 ++++++++++++++++++++++++++++++---------------
 3 files changed, 38 insertions(+), 18 deletions(-)
Makefile.inc +2 -2
index ad7afd0..0653d21 100644
@@ -9,10 +9,10 @@
 # Uncomment to disable dmevents polling support
 # ENABLE_DMEVENTS_POLL = 0
 #
-# Readline library to use, libedit or libreadline
+# Readline library to use, libedit, libreadline, or empty
 # Caution: Using libreadline may make the multipathd binary undistributable,
 # see https://github.com/opensvc/multipath-tools/issues/36
-READLINE = libedit
+READLINE := 
 
 # List of scsi device handler modules to load on boot, e.g.
 # SCSI_DH_MODULES_PRELOAD := scsi_dh_alua scsi_dh_rdac
multipathd/cli.c +2 -0
index fa482a6..cc56950 100644
@@ -459,6 +459,7 @@ void cli_exit(void)
 	keys = NULL;
 }
 
+#if defined(USE_LIBREADLINE) || defined(USE_LIBEDIT)
 static int
 key_match_fingerprint (struct key * kw, uint64_t fp)
 {
@@ -564,3 +565,4 @@ key_generator (const char * str, int state)
 	 */
 	return ((char *)NULL);
 }
+#endif
multipathd/uxclnt.c +34 -16

75 lines not on this page · raw message

Signature · 6 lines
2.37.1

--
dm-devel mailing list
[email protected]
https://listman.redhat.com/mailman/listinfo/dm-devel
#2 lore raw

Re: [dm-devel] [PATCH v2 01/11] multipathd: replace libreadline with getline()

Quoted 22 lines · On Mon, Aug 22, 2022 at 10:41:09PM +0200, [email protected] wrote:

From: Hannes Reinecke <[email protected]>

libreadline changed the license to be incompatible with multipath-tools usage, so replace it with a simple getline().

mwilck: Make this the default option via Makefile.inc; it is used if READLINE is unset. Compiling with READLINE=libreadline or READLINE=libedit remains possible.

---
 Makefile.inc        |  4 ++--
 multipathd/cli.c    |  2 ++
 multipathd/uxclnt.c | 50 ++++++++++++++++++++++++++++++---------------
 3 files changed, 38 insertions(+), 18 deletions(-)
Makefile.inc +0 -0
index ad7afd0..0653d21 100644

Makefile.inc line 15

Quoted 9 lines
Makefile.inc +2 -2
@@ -9,10 +9,10 @@
 # Uncomment to disable dmevents polling support
 # ENABLE_DMEVENTS_POLL = 0
 #
-# Readline library to use, libedit or libreadline
+# Readline library to use, libedit, libreadline, or empty
 # Caution: Using libreadline may make the multipathd binary undistributable,
 # see https://github.com/opensvc/multipath-tools/issues/36
-READLINE = libedit
+READLINE := 

Trailing whitespace nitpick.

Quoted 16 lines
Makefile.inc +0 -0
 # List of scsi device handler modules to load on boot, e.g.
 # SCSI_DH_MODULES_PRELOAD := scsi_dh_alua scsi_dh_rdac
multipathd/cli.c +1 -0
index fa482a6..cc56950 100644
@@ -459,6 +459,7 @@ void cli_exit(void)
 	keys = NULL;
 }
 
+#if defined(USE_LIBREADLINE) || defined(USE_LIBEDIT)
 static int
 key_match_fingerprint (struct key * kw, uint64_t fp)
 {

multipathd/cli.c key_generator (const char * str, int state) · line 568

Quoted 4 lines
multipathd/cli.c +1 -0
@@ -564,3 +565,4 @@ key_generator (const char * str, int state)
 	 */
 	return ((char *)NULL);
 }
+#endif

It's kind of odd to not define key_generator(), but leave it defined in cli.h if no library is defined.

Quoted 68 lines
multipathd/uxclnt.c +32 -10
index 251e7d7..b817bea 100644
@@ -30,6 +30,7 @@
 #include "defaults.h"
 
 #include "vector.h"
+#include "util.h"
 #include "cli.h"
 #include "uxclnt.h"
 
@@ -77,35 +78,52 @@ static int need_quit(char *str, size_t len)
  */
 static void process(int fd, unsigned int timeout)
 {
-	char *line;
-	char *reply;
-	int ret;
 
-	cli_init();
+#if defined(USE_LIBREADLINE) || defined(USE_LIBEDIT)
 	rl_readline_name = "multipathd";
 	rl_completion_entry_function = key_generator;
-	while ((line = readline("multipathd> "))) {
-		size_t llen = strlen(line);
+#endif
 
-		if (!llen) {
-			free(line);
+	cli_init();
+	for(;;)
+	{
+		char *line __attribute__((cleanup(cleanup_charp))) = NULL;
+		char *reply __attribute__((cleanup(cleanup_charp))) = NULL;
+		ssize_t llen;
+		int ret;
+
+#if defined(USE_LIBREADLINE) || defined(USE_LIBEDIT)
+		line = readline("multipathd> ");
+		if (!line)
+			break;
+		llen = strlen(line);
+		if (!llen)
 			continue;
+#else
+		size_t lsize = 0;
+
+		fputs("multipathd> ", stdout);
+		errno = 0;
+		llen = getline(&line, &lsize, stdin);
+		if (llen == -1) {
+			if (errno != 0)
+				fprintf(stderr, "Error in getline: %m");
+			break;
 		}
+		if (!llen || !strcmp(line, "\n"))
+			continue;
+#endif
 
 		if (need_quit(line, llen))
 			break;
 
-		if (send_packet(fd, line) != 0) break;
+		if (send_packet(fd, line) != 0)
+			break;
 		ret = recv_packet(fd, &reply, timeout);
-		if (ret != 0) break;

multipathd/uxclnt.c static int need_quit(char *str, size_t len) · line 108

Quoted 10 lines
multipathd/uxclnt.c +2 -6
+		if (ret != 0)
+			break;
 
 		print_reply(reply);
-
-		if (line && *line)
-			add_history(line);
-
-		free(line);
-		free(reply);

Why drop add_history() support even if a library is defined?

-Ben

Quoted 5 lines
multipathd/uxclnt.c +0 -0
 	}
 }
 
Signature · 1 line
2.37.1

--
dm-devel mailing list
[email protected]
https://listman.redhat.com/mailman/listinfo/dm-devel

#3 lore raw

PATCH v2 2/11 .gitignore: ignore generated ABI files

In reply to [email protected]

From: Martin Wilck <[email protected]>

---
 .gitignore | 2 ++
 1 file changed, 2 insertions(+)
.gitignore +2 -0
index 8e09f95..b88608c 100644
@@ -32,3 +32,5 @@ tests/*.out
 tests/*.vgr
 libmultipath/nvme-ioctl.c
 libmultipath/nvme-ioctl.h
+*/*-nv.version
+reference-abi
Signature · 6 lines
2.37.1

--
dm-devel mailing list
[email protected]
https://listman.redhat.com/mailman/listinfo/dm-devel
#4 lore raw

PATCH v2 3/11 libmultipath: move all reservation key functions to prkey.c

In reply to [email protected]

From: Martin Wilck <[email protected]>

Also make parse_prkey() static, and avoid including libmpathpersist headers in libmultipath. The only exception is now prkey.c, where we pull in some public declarations from mpath_persist.h.

---
 libmultipath/Makefile |  2 +-
 libmultipath/dict.c   | 16 +-------------
 libmultipath/dict.h   |  2 --
 libmultipath/prkey.c  | 49 ++++++++++++++++++++++++++++++++++++++++++-
 libmultipath/prkey.h  |  3 +++
 libmultipath/util.c   | 32 ----------------------------
 libmultipath/util.h   |  2 --
 7 files changed, 53 insertions(+), 53 deletions(-)
libmultipath/Makefile +1 -1
index fb03200..033fc83 100644
@@ -8,7 +8,7 @@ DEVLIB = libmultipath.so
 LIBS = $(DEVLIB).$(SONAME)
 VERSION_SCRIPT := libmultipath.version
 
-CPPFLAGS += -I$(mpathcmddir) -I$(mpathpersistdir) -I$(nvmedir)
+CPPFLAGS += -I$(mpathcmddir) -I$(nvmedir)
 CFLAGS += $(LIB_CFLAGS)
 
 LIBDEPS += -lpthread -ldl -ldevmapper -ludev -L$(mpathcmddir) -lmpathcmd -lurcu -laio
libmultipath/dict.c +1 -15
index ad049cc..aa93fe4 100644
@@ -24,10 +24,10 @@
 #include <errno.h>
 #include <inttypes.h>
 #include <libudev.h>
-#include <mpath_persist.h>
 #include "mpath_cmd.h"
 #include "dict.h"
 #include "strbuf.h"
+#include "prkey.h"
 
 static void
 do_set_int(vector strvec, void *ptr, int min, int max, const char *file,
@@ -1404,20 +1404,6 @@ set_reservation_key(vector strvec, struct be64 *be64_ptr, uint8_t *flags_ptr,
 	return 0;
 }
 
-int
-print_reservation_key(struct strbuf *buff,
-		      struct be64 key, uint8_t flags, int source)
-{
-	char *flagstr = "";
-	if (source == PRKEY_SOURCE_NONE)
-		return 0;
-	if (source == PRKEY_SOURCE_FILE)
-		return append_strbuf_quoted(buff, "file");
-	if (flags & MPATH_F_APTPL_MASK)
-		flagstr = ":aptpl";
-	return print_strbuf(buff, "0x%" PRIx64 "%s", get_be64(key), flagstr);
-}
-
 static int
 def_reservation_key_handler(struct config *conf, vector strvec,
 			    const char *file, int line_nr)
libmultipath/dict.h +0 -2
index d80f990..15d9cba 100644
@@ -16,7 +16,5 @@ int print_pgpolicy(struct strbuf *buff, long v);
 int print_no_path_retry(struct strbuf *buff, long v);
 int print_undef_off_zero(struct strbuf *buff, long v);
 int print_dev_loss(struct strbuf *buff, unsigned long v);
-int print_reservation_key(struct strbuf *buff,
-			  struct be64 key, uint8_t flags, int source);
 int print_off_int_undef(struct strbuf *buff, long v);
 #endif /* _DICT_H */
libmultipath/prkey.c +48 -1

65 lines not on this page · raw message

libmultipath/prkey.h +3 -0
index 6739191..a16de10 100644
@@ -13,6 +13,9 @@
 "# prkey wwid\n" \
 "#\n"
 
+int print_reservation_key(struct strbuf *buff,
+			  struct be64 key, uint8_t flags, int source);
+int parse_prkey_flags(const char *ptr, uint64_t *prkey, uint8_t *flags);
 int set_prkey(struct config *conf, struct multipath *mpp, uint64_t prkey,
 	      uint8_t sa_flags);
 int get_prkey(struct config *conf, struct multipath *mpp, uint64_t *prkey,
libmultipath/util.c +0 -32
index e7e7d4c..6979e74 100644
@@ -13,7 +13,6 @@
 #include <unistd.h>
 #include <errno.h>
 #include <libudev.h>
-#include <mpath_persist.h>
 
 #include "util.h"
 #include "debug.h"
@@ -333,37 +332,6 @@ int get_linux_version_code(void)
 	return _linux_version_code;
 }
 
-int parse_prkey(const char *ptr, uint64_t *prkey)
-{
-	if (!ptr)
-		return 1;
-	if (*ptr == '0')
-		ptr++;
-	if (*ptr == 'x' || *ptr == 'X')
-		ptr++;
-	if (*ptr == '\0' || strlen(ptr) > 16)
-		return 1;
-	if (strlen(ptr) != strspn(ptr, "0123456789aAbBcCdDeEfF"))
-		return 1;
-	if (sscanf(ptr, "%" SCNx64 "", prkey) != 1)
-		return 1;
-	return 0;
-}
-
-int parse_prkey_flags(const char *ptr, uint64_t *prkey, uint8_t *flags)
-{
-	char *flagstr;
-
-	flagstr = strchr(ptr, ':');
-	*flags = 0;
-	if (flagstr) {
-		*flagstr++ = '\0';
-		if (strlen(flagstr) == 5 && strcmp(flagstr, "aptpl") == 0)
-			*flags = MPATH_F_APTPL_MASK;
-	}
-	return parse_prkey(ptr, prkey);
-}
-
 int safe_write(int fd, const void *buf, size_t count)
 {
 	while (count > 0) {
libmultipath/util.h +0 -2
index 5a44018..bede49d 100644
@@ -24,8 +24,6 @@ char *convert_dev(char *dev, int is_path_device);
 void setup_thread_attr(pthread_attr_t *attr, size_t stacksize, int detached);
 int systemd_service_enabled(const char *dev);
 int get_linux_version_code(void);
-int parse_prkey(const char *ptr, uint64_t *prkey);
-int parse_prkey_flags(const char *ptr, uint64_t *prkey, uint8_t *flags);
 int safe_write(int fd, const void *buf, size_t count);
 void set_max_fds(rlim_t max_fds);
 int should_exit(void);
Signature · 6 lines
2.37.1

--
dm-devel mailing list
[email protected]
https://listman.redhat.com/mailman/listinfo/dm-devel
#5 lore raw

PATCH v2 4/11 libmultipath: always set _GNU_SOURCE

In reply to [email protected]

From: Martin Wilck <[email protected]>

... not only if dm_task_no_flush is available. Also, look for includes under libmultipath but not under libmpathpersist.

---
 libmultipath/Makefile | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
libmultipath/Makefile +2 -2
index 033fc83..348af3f 100644
@@ -8,7 +8,7 @@ DEVLIB = libmultipath.so
 LIBS = $(DEVLIB).$(SONAME)
 VERSION_SCRIPT := libmultipath.version
 
-CPPFLAGS += -I$(mpathcmddir) -I$(nvmedir)
+CPPFLAGS += -I$(mpathcmddir) -I$(nvmedir) -D_GNU_SOURCE
 CFLAGS += $(LIB_CFLAGS)
 
 LIBDEPS += -lpthread -ldl -ldevmapper -ludev -L$(mpathcmddir) -lmpathcmd -lurcu -laio
@@ -23,7 +23,7 @@ ifdef SYSTEMD
 endif
 
 ifneq ($(call check_func,dm_task_no_flush,$(DEVMAPPER_INCDIR)/libdevmapper.h),0)
-	CPPFLAGS += -DLIBDM_API_FLUSH -D_GNU_SOURCE
+	CPPFLAGS += -DLIBDM_API_FLUSH
 endif
 
 ifneq ($(call check_func,dm_task_get_errno,$(DEVMAPPER_INCDIR)/libdevmapper.h),0)
Signature · 6 lines
2.37.1

--
dm-devel mailing list
[email protected]
https://listman.redhat.com/mailman/listinfo/dm-devel
#6 lore raw

PATCH v2 5/11 multipath-tools: Makefile: fix dependencies for "install" target

In reply to [email protected]

From: Martin Wilck <[email protected]>

subdir.install targets should depend on subdir targets. This is cleaner than just having "install" depend on "all".

---
 Makefile | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
Makefile +2 -2
index 82e0ea3..ffca586 100644
@@ -84,7 +84,7 @@ libmultipath/checkers.install \
 $(BUILDDIRS.clean):
 	$(MAKE) -C ${@:.clean=} clean
 
-$(BUILDDIRS:=.install):
+$(BUILDDIRS:=.install): $(BUILDDIRS)
 	$(MAKE) -C ${@:.install=} install
 
 $(BUILDDIRS:=.uninstall):
@@ -93,7 +93,7 @@ $(BUILDDIRS:=.uninstall):
 clean: $(BUILDDIRS.clean)
 	rm -rf abi abi.tar.gz abi-test compile_commands.json
 
-install: all $(BUILDDIRS:=.install)
+install: $(BUILDDIRS:=.install)
 uninstall: $(BUILDDIRS:=.uninstall)
 
 test-progs:	all
Signature · 6 lines
2.37.1

--
dm-devel mailing list
[email protected]
https://listman.redhat.com/mailman/listinfo/dm-devel
#7 lore raw

PATCH v2 6/11 libmultipath checkers/prioritizers: search for includes in libmultipath

In reply to [email protected]

From: Martin Wilck <[email protected]>

Set TOPDIR correctly rather than using hard-coded "../". Also remove duplicate -lmultipath in checkers makefile.

---
 libmultipath/checkers/Makefile        | 7 ++++---
 libmultipath/checkers/directio.c      | 4 ++--
 libmultipath/checkers/tur.c           | 8 ++++----
 libmultipath/foreign/Makefile         | 4 ++--
 libmultipath/prioritizers/Makefile    | 6 ++++--
 libmultipath/prioritizers/alua_rtpg.c | 2 +-
 6 files changed, 17 insertions(+), 14 deletions(-)
libmultipath/checkers/Makefile +4 -3
index 8d8e45e..e1d7904 100644
@@ -1,12 +1,13 @@
 #
 # Copyright (C) 2003 Christophe Varoqui, <[email protected]>
 #
+TOPDIR = ../..
 include ../../Makefile.inc
 
-CPPFLAGS += -I..
+CPPFLAGS += -I$(multipathdir)
 CFLAGS += $(LIB_CFLAGS)
-LDFLAGS += -L.. -lmultipath
-LIBDEPS = -lmultipath -laio -lpthread -lrt
+LDFLAGS += -L$(multipathdir) -lmultipath
+LIBDEPS = -laio -lpthread -lrt
 
 # If you add or remove a checker also update multipath/multipath.conf.5
 LIBS= \
libmultipath/checkers/directio.c +2 -2
index a326e37..2f3ece0 100644
@@ -15,8 +15,8 @@
 #include <libaio.h>
 
 #include "checkers.h"
-#include "../libmultipath/debug.h"
-#include "../libmultipath/time-util.h"
+#include "debug.h"
+#include "time-util.h"
 
 #define AIO_GROUP_SIZE 1024
 
libmultipath/checkers/tur.c +4 -4
index 1bcb757..551dc4f 100644
@@ -19,10 +19,10 @@
 
 #include "checkers.h"
 
-#include "../libmultipath/debug.h"
-#include "../libmultipath/sg_include.h"
-#include "../libmultipath/util.h"
-#include "../libmultipath/time-util.h"
+#include "debug.h"
+#include "sg_include.h"
+#include "util.h"
+#include "time-util.h"
 
 #define TUR_CMD_LEN 6
 #define HEAVY_CHECK_COUNT       10
libmultipath/foreign/Makefile +2 -2
index 42cea4d..3d4491a 100644
@@ -4,9 +4,9 @@
 TOPDIR=../..
 include ../../Makefile.inc
 
-CPPFLAGS += -I.. -I$(nvmedir)
+CPPFLAGS += -I$(multipathdir) -I$(nvmedir)
 CFLAGS += $(LIB_CFLAGS)
-LDFLAGS += -L..
+LDFLAGS += -L$(multipathdir)
 LIBDEPS = -lmultipath -ludev -lpthread -lrt
 
 LIBS = libforeign-nvme.so
libmultipath/prioritizers/Makefile +4 -2
index a5ab5e1..eb6f03b 100644
@@ -1,11 +1,13 @@
 #
 # Copyright (C) 2007 Christophe Varoqui, <[email protected]>
 #
+TOPDIR=../..
+
 include ../../Makefile.inc
 
-CPPFLAGS += -I..
+CPPFLAGS += -I$(multipathdir)
 CFLAGS += $(LIB_CFLAGS)
-LDFLAGS += -L..
+LDFLAGS += -L$(multipathdir)
 LIBDEPS = -lmultipath -lm -lpthread -lrt
 
 # If you add or remove a prioritizer also update multipath/multipath.conf.5
libmultipath/prioritizers/alua_rtpg.c +1 -1
index 4db13c2..2db9153 100644
@@ -27,7 +27,7 @@
 #include "../structs.h"
 #include "../prio.h"
 #include "../discovery.h"
-#include "../debug.h"
+#include "debug.h"
 #include "alua_rtpg.h"
 
 #define SENSE_BUFF_LEN  32
Signature · 6 lines
2.37.1

--
dm-devel mailing list
[email protected]
https://listman.redhat.com/mailman/listinfo/dm-devel
#8 lore raw

PATCH v2 7/11 libmultipath: remove weak attribute for {get, put}_multipath_config

In reply to [email protected]

From: Martin Wilck <[email protected]>

The "weak" attribute was set to make sure that these symbols are overridden by symbols of the same name in the main executable. This is unnecessary, as the standard ELF symbol resolution algorithm ensures this even without the "weak" attribute.

See ELF Specification, III.2 Dynamic Linking / Shared Object Dependencies:
"The dynamic linker examines the symbol tables with a breadth-first search. That is, it first looks at the symbol table of the executable program itself, then at the symbol tables of the DT_NEEDED entries (in order), then at the second level DT_NEEDED entries, and so on".

---
 libmultipath/config.c |  4 ++--
 libmultipath/config.h | 11 -----------
 2 files changed, 2 insertions(+), 13 deletions(-)
libmultipath/config.c +2 -2
index a2c79a4..5c5c072 100644
@@ -82,7 +82,7 @@ struct config *libmp_get_multipath_config(void)
 }
 
 struct config *get_multipath_config(void)
-	__attribute__((weak, alias("libmp_get_multipath_config")));
+	__attribute__((alias("libmp_get_multipath_config")));
 
 void libmp_put_multipath_config(void *conf __attribute__((unused)))
 {
@@ -90,7 +90,7 @@ void libmp_put_multipath_config(void *conf __attribute__((unused)))
 }
 
 void put_multipath_config(void *conf)
-	__attribute__((weak, alias("libmp_put_multipath_config")));
+	__attribute__((alias("libmp_put_multipath_config")));
 
 static int
 hwe_strmatch (const struct hwentry *hwe1, const struct hwentry *hwe2)
libmultipath/config.h +0 -11
index fdcdff0..2d00ad2 100644
@@ -303,17 +303,6 @@ void free_config (struct config * conf);
 int init_config(const char *file);
 void uninit_config(void);
 
-/*
- * libmultipath provides default implementations of
- * get_multipath_config() and put_multipath_config().
- * Applications using these should use init_config(file, NULL)
- * to load the configuration, rather than load_config(file).
- * Likewise, uninit_config() should be used for teardown, but
- * using free_config() for that is supported, too.
- * Applications can define their own {get,put}_multipath_config()
- * functions, which override the library-internal ones, but
- * could still call libmp_{get,put}_multipath_config().
- */
 struct config *libmp_get_multipath_config(void);
 struct config *get_multipath_config(void);
 void libmp_put_multipath_config(void *);
Signature · 6 lines
2.37.1

--
dm-devel mailing list
[email protected]
https://listman.redhat.com/mailman/listinfo/dm-devel
#9 lore raw

PATCH v2 8/11 libmultipath: split off libmpathutil

In reply to [email protected]

From: Martin Wilck <[email protected]>

Split libmultipath into two libraries: libmpathutil contains generic utilities that don't relate to device-mapper or multipath specifically. libmultipath retains multipath-specific code.

The reason for this change is that we'll create a small client program that takes over the role of "multipath -k", the interactive client. This way multipathd doesn't need to link against libreadline any more. The client only needs functionality from libmpathutil, which doesn't contain code that isn't compliant with GPL-3.0, and can thus be linked to libreadline without conflicts.

The new library contains weak implementations of {get,put}_multipath_config, which are meant to be superseded by libmultipath's implementation. In the interactive client, these functions aren't needed.

As we now have an ABI between libmpathutil and libmultipath, the ABI must be extended by adding functions from libmpathutil that are used internally by libmultipath.

---
 Makefile                                     |   4 +-
 Makefile.inc                                 |   1 +
 libmpathpersist/Makefile                     |   6 +-
 libmpathutil/Makefile                        |  70 +++++++++++
 {libmultipath => libmpathutil}/debug.c       |   0
 {libmultipath => libmpathutil}/debug.h       |   0
 libmpathutil/globals.c                       |  12 ++
 libmpathutil/globals.h                       |  39 ++++++
 libmpathutil/libmpathutil.version            | 122 +++++++++++++++++++
 {libmultipath => libmpathutil}/log.c         |   0
 {libmultipath => libmpathutil}/log.h         |   0
 {libmultipath => libmpathutil}/log_pthread.c |   0
 {libmultipath => libmpathutil}/log_pthread.h |   0
 {libmultipath => libmpathutil}/parser.c      |   0
 {libmultipath => libmpathutil}/parser.h      |   2 +-
 {libmultipath => libmpathutil}/strbuf.c      |   0
 {libmultipath => libmpathutil}/strbuf.h      |   0
 {libmultipath => libmpathutil}/time-util.c   |   0
 {libmultipath => libmpathutil}/time-util.h   |   0
 {libmultipath => libmpathutil}/util.c        |   0
 {libmultipath => libmpathutil}/util.h        |   0
 {libmultipath => libmpathutil}/uxsock.c      |   0
 {libmultipath => libmpathutil}/uxsock.h      |   0
 {libmultipath => libmpathutil}/vector.c      |   0
 {libmultipath => libmpathutil}/vector.h      |   0
 libmpathvalid/Makefile                       |   6 +-
 libmultipath/Makefile                        |  15 ++-
 libmultipath/checkers/Makefile               |   4 +-
 libmultipath/config.h                        |   3 +-
 libmultipath/foreign/Makefile                |   6 +-
 libmultipath/libmultipath.version            |  41 -------
 libmultipath/prioritizers/Makefile           |   6 +-
 mpathpersist/Makefile                        |   4 +-
 multipath/Makefile                           |   6 +-
 multipathd/Makefile                          |  12 +-
 tests/Makefile                               |   8 +-
 36 files changed, 286 insertions(+), 81 deletions(-)
 create mode 100644 libmpathutil/Makefile
 rename {libmultipath => libmpathutil}/debug.c (100%)
 rename {libmultipath => libmpathutil}/debug.h (100%)
 create mode 100644 libmpathutil/globals.c
 create mode 100644 libmpathutil/globals.h
 create mode 100644 libmpathutil/libmpathutil.version
 rename {libmultipath => libmpathutil}/log.c (100%)
 rename {libmultipath => libmpathutil}/log.h (100%)
 rename {libmultipath => libmpathutil}/log_pthread.c (100%)
 rename {libmultipath => libmpathutil}/log_pthread.h (100%)
 rename {libmultipath => libmpathutil}/parser.c (100%)
 rename {libmultipath => libmpathutil}/parser.h (99%)
 rename {libmultipath => libmpathutil}/strbuf.c (100%)
 rename {libmultipath => libmpathutil}/strbuf.h (100%)
 rename {libmultipath => libmpathutil}/time-util.c (100%)
 rename {libmultipath => libmpathutil}/time-util.h (100%)
 rename {libmultipath => libmpathutil}/util.c (100%)
 rename {libmultipath => libmpathutil}/util.h (100%)
 rename {libmultipath => libmpathutil}/uxsock.c (100%)
 rename {libmultipath => libmpathutil}/uxsock.h (100%)
 rename {libmultipath => libmpathutil}/vector.c (100%)
 rename {libmultipath => libmpathutil}/vector.h (100%)
Makefile +3 -1
index ffca586..5851149 100644
@@ -4,6 +4,7 @@
 
 LIB_BUILDDIRS := \
 	libmpathcmd \
+	libmpathutil \
 	libmultipath \
 	libmpathpersist \
 	libmpathvalid
@@ -72,7 +73,8 @@ compile_commands.json: Makefile Makefile.inc $(BUILDDIRS:=/Makefile)
 	$(MAKE) clean
 	bear -- $(MAKE)
 
-libmultipath libdmmp: libmpathcmd
+libmpathutil libdmmp: libmpathcmd
+libmultipath: libmpathutil
 libmpathpersist libmpathvalid multipath multipathd: libmultipath
 libmultipath/prioritizers libmultipath/checkers libmultipath/foreign: libmultipath
 mpathpersist multipathd:  libmpathpersist
Makefile.inc +1 -0
index 0653d21..58dcba9 100644
@@ -86,6 +86,7 @@ libudevdir	= $(prefix)/$(SYSTEMDPATH)/udev
 udevrulesdir	= $(libudevdir)/rules.d
 modulesloaddir  = $(prefix)/$(SYSTEMDPATH)/modules-load.d
 multipathdir	= $(TOPDIR)/libmultipath
+mpathutildir	= $(TOPDIR)/libmpathutil
 man8dir		= $(prefix)/usr/share/man/man8
 man5dir		= $(prefix)/usr/share/man/man5
 man3dir		= $(prefix)/usr/share/man/man3
libmpathpersist/Makefile +3 -3
index 9843d96..4e1717e 100644
@@ -5,10 +5,10 @@ DEVLIB = libmpathpersist.so
 LIBS = $(DEVLIB).$(SONAME)
 VERSION_SCRIPT:= libmpathpersist.version
 
-CFLAGS += $(LIB_CFLAGS) -I$(multipathdir) -I$(mpathpersistdir) -I$(mpathcmddir)
-LDFLAGS += -L$(multipathdir) -L$(mpathcmddir)
+CFLAGS += $(LIB_CFLAGS) -I$(multipathdir) -I$(mpathutildir) -I$(mpathpersistdir) -I$(mpathcmddir)
+LDFLAGS += -L$(multipathdir) -L$(mpathutildir) -L$(mpathcmddir)
 
-LIBDEPS += -lmultipath -lmpathcmd -ldevmapper -lpthread -ldl
+LIBDEPS += -lmultipath -lmpathutil -lmpathcmd -ldevmapper -lpthread -ldl
 
 OBJS = mpath_persist.o mpath_updatepr.o mpath_pr_ioctl.o mpath_persist_int.o
 
libmpathutil/Makefile new file +70 -0

70 lines not on this page · raw message

libmpathutil/debug.c renamed from libmultipath/debug.c +0 -0
similarity index 100%
rename from libmultipath/debug.c
rename to libmpathutil/debug.c
libmpathutil/debug.h renamed from libmultipath/debug.h +0 -0
similarity index 100%
rename from libmultipath/debug.h
rename to libmpathutil/debug.h
libmpathutil/globals.c new file +12 -0
new file mode 100644
index 0000000..0c9a5ba
@@ -0,0 +1,12 @@
+#include <stddef.h>
+#include <libudev.h>
+#include "globals.h"
+
+struct udev __attribute__((weak)) *udev;
+struct config __attribute__((weak)) *get_multipath_config(void)
+{
+	return NULL;
+}
+
+void __attribute__((weak)) put_multipath_config(void *p __attribute__((unused)))
+{}
libmpathutil/globals.h new file +39 -0
new file mode 100644
index 0000000..fab507e
@@ -0,0 +1,39 @@
+#ifndef _GLOBALS_H
+#define _GLOBALS_H
+
+struct config;
+
+/**
+ * extern variable: udev
+ *
+ * A &struct udev instance used by libmultipath. libmultipath expects
+ * a valid, initialized &struct udev in this variable.
+ * An application can define this variable itself, in which case
+ * the applications's instance will take precedence.
+ * The application can initialize and destroy this variable by
+ * calling libmultipath_init() and libmultipath_exit(), respectively,
+ * whether or not it defines the variable itself.
+ * An application can initialize udev with udev_new() before calling
+ * libmultipath_init(), e.g. if it has to make libudev calls before
+ * libmultipath calls. If an application wants to keep using the
+ * udev variable after calling libmultipath_exit(), it should have taken
+ * an additional reference on it beforehand. This is the case e.g.
+ * after initializing udev with udev_new().
+ */
+extern struct udev *udev;
+
+/*
+ * libmultipath provides default implementations of
+ * get_multipath_config() and put_multipath_config().
+ * Applications using these should use init_config(file, NULL)
+ * to load the configuration, rather than load_config(file).
+ * Likewise, uninit_config() should be used for teardown, but
+ * using free_config() for that is supported, too.
+ * Applications can define their own {get,put}_multipath_config()
+ * functions, which override the library-internal ones, but
+ * could still call libmp_{get,put}_multipath_config().
+ */
+void put_multipath_config(void *);
+struct config *get_multipath_config(void);
+
+#endif
libmpathutil/libmpathutil.version new file +122 -0

122 lines not on this page · raw message

libmpathutil/log.c renamed from libmultipath/log.c +0 -0
similarity index 100%
rename from libmultipath/log.c
rename to libmpathutil/log.c
libmpathutil/log.h renamed from libmultipath/log.h +0 -0
similarity index 100%
rename from libmultipath/log.h
rename to libmpathutil/log.h
libmpathutil/log_pthread.c renamed from libmultipath/log_pthread.c +0 -0
similarity index 100%
rename from libmultipath/log_pthread.c
rename to libmpathutil/log_pthread.c
libmpathutil/log_pthread.h renamed from libmultipath/log_pthread.h +0 -0
similarity index 100%
rename from libmultipath/log_pthread.h
rename to libmpathutil/log_pthread.h
libmpathutil/parser.c renamed from libmultipath/parser.c +0 -0
similarity index 100%
rename from libmultipath/parser.c
rename to libmpathutil/parser.c
libmpathutil/parser.h renamed from libmultipath/parser.h +1 -1
similarity index 99%
rename from libmultipath/parser.h
rename to libmpathutil/parser.h
index 11ea227..9d9d948 100644
@@ -33,8 +33,8 @@
 
 /* local includes */
 #include "vector.h"
-#include "config.h"
 struct strbuf;
+struct config;
 
 /* Global definitions */
 #define EOB  "}"
libmpathutil/strbuf.c renamed from libmultipath/strbuf.c +0 -0
similarity index 100%
rename from libmultipath/strbuf.c
rename to libmpathutil/strbuf.c
libmpathutil/strbuf.h renamed from libmultipath/strbuf.h +0 -0
similarity index 100%
rename from libmultipath/strbuf.h
rename to libmpathutil/strbuf.h
libmpathutil/time-util.c renamed from libmultipath/time-util.c +0 -0
similarity index 100%
rename from libmultipath/time-util.c
rename to libmpathutil/time-util.c
libmpathutil/time-util.h renamed from libmultipath/time-util.h +0 -0
similarity index 100%
rename from libmultipath/time-util.h
rename to libmpathutil/time-util.h
libmpathutil/util.c renamed from libmultipath/util.c +0 -0
similarity index 100%
rename from libmultipath/util.c
rename to libmpathutil/util.c
libmpathutil/util.h renamed from libmultipath/util.h +0 -0
similarity index 100%
rename from libmultipath/util.h
rename to libmpathutil/util.h
libmpathutil/uxsock.c renamed from libmultipath/uxsock.c +0 -0
similarity index 100%
rename from libmultipath/uxsock.c
rename to libmpathutil/uxsock.c
libmpathutil/uxsock.h renamed from libmultipath/uxsock.h +0 -0
similarity index 100%
rename from libmultipath/uxsock.h
rename to libmpathutil/uxsock.h
libmpathutil/vector.c renamed from libmultipath/vector.c +0 -0
similarity index 100%
rename from libmultipath/vector.c
rename to libmpathutil/vector.c
libmpathutil/vector.h renamed from libmultipath/vector.h +0 -0
similarity index 100%
rename from libmultipath/vector.h
rename to libmpathutil/vector.h
libmpathvalid/Makefile +3 -3
index 0a51925..5dbfb92 100644
@@ -5,11 +5,11 @@ DEVLIB = libmpathvalid.so
 LIBS = $(DEVLIB).$(SONAME)
 VERSION_SCRIPT := libmpathvalid.version
 
-CPPFLAGS += -I$(multipathdir) -I$(mpathcmddir)
+CPPFLAGS += -I$(multipathdir) -I$(mpathutildir) -I$(mpathcmddir)
 CFLAGS += $(LIB_CFLAGS)
 
-LIBDEPS += -lpthread -ldevmapper -ldl -L$(multipathdir) \
-	   -lmultipath -L$(mpathcmddir) -lmpathcmd -ludev
+LIBDEPS += -lpthread -ldevmapper -ldl -L$(multipathdir) -lmultipath \
+	   -L$(mpathutildir) -lmpathutil -L$(mpathcmddir) -lmpathcmd -ludev
 
 OBJS = mpath_valid.o
 
libmultipath/Makefile +7 -8
index 348af3f..3b60a52 100644
@@ -8,10 +8,10 @@ DEVLIB = libmultipath.so
 LIBS = $(DEVLIB).$(SONAME)
 VERSION_SCRIPT := libmultipath.version
 
-CPPFLAGS += -I$(mpathcmddir) -I$(nvmedir) -D_GNU_SOURCE
+CPPFLAGS += -I$(mpathutildir) -I$(mpathcmddir) -I$(nvmedir) -D_GNU_SOURCE
 CFLAGS += $(LIB_CFLAGS)
 
-LIBDEPS += -lpthread -ldl -ldevmapper -ludev -L$(mpathcmddir) -lmpathcmd -lurcu -laio
+LIBDEPS += -lpthread -ldl -ldevmapper -ludev -L$(mpathutildir) -lmpathutil -L$(mpathcmddir) -lmpathcmd -lurcu -laio
 
 ifdef SYSTEMD
 	CPPFLAGS += -DUSE_SYSTEMD=$(SYSTEMD)
@@ -56,15 +56,14 @@ OBJS-U := prio.o checkers.o foreign.o config.o
 OBJS-T := $(patsubst %.o,%-test.o,$(OBJS-U))
 
 # other object files
-OBJS-O := parser.o vector.o devmapper.o \
-	hwtable.o blacklist.o util.o dmparser.o \
+OBJS-O := devmapper.o hwtable.o blacklist.o dmparser.o \
 	structs.o discovery.o propsel.o dict.o \
-	pgpolicies.o debug.o defaults.o uevent.o time-util.o \
-	switchgroup.o uxsock.o print.o alias.o log_pthread.o \
-	log.o configure.o structs_vec.o sysfs.o \
+	pgpolicies.o defaults.o uevent.o \
+	switchgroup.o print.o alias.o \
+	configure.o structs_vec.o sysfs.o \
 	lock.o file.o wwids.o prioritizers/alua_rtpg.o prkey.o \
 	io_err_stat.o dm-generic.o generic.o nvme-lib.o \
-	libsg.o valid.o strbuf.o
+	libsg.o valid.o
 
 OBJS := $(OBJS-O) $(OBJS-U)
 
libmultipath/checkers/Makefile +2 -2
index e1d7904..cfc06e7 100644
@@ -4,9 +4,9 @@
 TOPDIR = ../..
 include ../../Makefile.inc
 
-CPPFLAGS += -I$(multipathdir)
+CPPFLAGS +=  -I$(multipathdir) -I$(mpathutildir)
 CFLAGS += $(LIB_CFLAGS)
-LDFLAGS += -L$(multipathdir) -lmultipath
+LDFLAGS += -L$(multipathdir) -L$(mpathutildir) -lmultipath -lmpathutil
 LIBDEPS = -laio -lpthread -lrt
 
 # If you add or remove a checker also update multipath/multipath.conf.5
libmultipath/config.h +1 -2
index 2d00ad2..8794746 100644
@@ -6,6 +6,7 @@
 #include <urcu.h>
 #include <inttypes.h>
 #include "byteorder.h"
+#include "globals.h"
 
 #define ORIGIN_DEFAULT 0
 #define ORIGIN_CONFIG  1
@@ -304,9 +305,7 @@ int init_config(const char *file);
 void uninit_config(void);
 
 struct config *libmp_get_multipath_config(void);
-struct config *get_multipath_config(void);
 void libmp_put_multipath_config(void *);
-void put_multipath_config(void *);
 
 int parse_uid_attrs(char *uid_attrs, struct config *conf);
 const char *get_uid_attribute_by_attrs(const struct config *conf,
libmultipath/foreign/Makefile +3 -3
index 3d4491a..d0232f2 100644
@@ -4,10 +4,10 @@
 TOPDIR=../..
 include ../../Makefile.inc
 
-CPPFLAGS += -I$(multipathdir) -I$(nvmedir)
+CPPFLAGS += -I$(multipathdir) -I$(mpathutildir) -I$(nvmedir)
 CFLAGS += $(LIB_CFLAGS)
-LDFLAGS += -L$(multipathdir)
-LIBDEPS = -lmultipath -ludev -lpthread -lrt
+LDFLAGS += -L$(multipathdir) -L$(mpathutildir)
+LIBDEPS = -lmultipath -lmpathutil -ludev -lpthread -lrt
 
 LIBS = libforeign-nvme.so
 
libmultipath/libmultipath.version +0 -41

143 lines not on this page · raw message

libmultipath/prioritizers/Makefile +3 -3
index eb6f03b..400f773 100644
@@ -5,10 +5,10 @@ TOPDIR=../..
 
 include ../../Makefile.inc
 
-CPPFLAGS += -I$(multipathdir)
+CPPFLAGS += -I$(multipathdir) -I$(mpathutildir)
 CFLAGS += $(LIB_CFLAGS)
-LDFLAGS += -L$(multipathdir)
-LIBDEPS = -lmultipath -lm -lpthread -lrt
+LDFLAGS += -L$(multipathdir) -L$(mpathutildir)
+LIBDEPS = -lmultipath -lmpathutil -lm -lpthread -lrt
 
 # If you add or remove a prioritizer also update multipath/multipath.conf.5
 LIBS = \
mpathpersist/Makefile +2 -2
index 2e4d483..2219c86 100644
@@ -1,11 +1,11 @@
 include ../Makefile.inc
 
-CPPFLAGS += -I$(multipathdir) -I$(mpathpersistdir)
+CPPFLAGS += -I$(multipathdir) -I$(mpathutildir) -I$(mpathpersistdir)
 CFLAGS += $(BIN_CFLAGS)
 LDFLAGS += $(BIN_LDFLAGS)
 
 LIBDEPS += -L$(mpathpersistdir) -lmpathpersist -L$(multipathdir) -lmultipath \
-	-L$(mpathcmddir) -lmpathcmd -lpthread -ldevmapper -ludev
+	-L$(mpathutildir) -lmpathutil -L$(mpathcmddir) -lmpathcmd -lpthread -ldevmapper -ludev
 
 EXEC = mpathpersist
 
multipath/Makefile +3 -3
index bcb0453..46b7553 100644
@@ -3,11 +3,11 @@
 #
 include ../Makefile.inc
 
-CPPFLAGS += -I$(multipathdir) -I$(mpathcmddir)
+CPPFLAGS += -I$(multipathdir) -I$(mpathutildir) -I$(mpathcmddir)
 CFLAGS += $(BIN_CFLAGS)
 LDFLAGS += $(BIN_LDFLAGS)
-LIBDEPS += -L$(multipathdir) -lmultipath -L$(mpathcmddir) -lmpathcmd \
-	-lpthread -ldevmapper -ldl -ludev
+LIBDEPS += -L$(multipathdir) -lmultipath -L$(mpathutildir) -lmpathutil \
+	-L$(mpathcmddir) -lmpathcmd -lpthread -ldevmapper -ldl -ludev
 
 EXEC = multipath
 
multipathd/Makefile +7 -5
index 95acd88..7128510 100644
@@ -15,14 +15,16 @@ endif
 #CPPFLAGS += -D_DEBUG_
 #CPPFLAGS += -DLOGDBG
 
-CPPFLAGS += -I$(multipathdir) -I$(mpathpersistdir) -I$(mpathcmddir) -I$(thirdpartydir) \
+CPPFLAGS += -I$(multipathdir) -I$(mpathutildir) -I$(mpathpersistdir) -I$(mpathcmddir) -I$(thirdpartydir) \
 	$(shell $(PKGCONFIG) --modversion liburcu 2>/dev/null | \
 		awk -F. '{ printf("-DURCU_VERSION=0x%06x", 256 * ( 256 * $$1 + $$2) + $$3); }')
 CFLAGS += $(BIN_CFLAGS)
 LDFLAGS += $(BIN_LDFLAGS)
+
+CLI_LIBDEPS :=  -L$(mpathutildir) -lmpathutil -L$(mpathcmddir) -lmpathcmd -ludev -ldl -lurcu -lpthread
 LIBDEPS += -L$(multipathdir) -lmultipath -L$(mpathpersistdir) -lmpathpersist \
-	   -L$(mpathcmddir) -lmpathcmd -ludev -ldl -lurcu -lpthread \
-	   -ldevmapper
+	   -ldevmapper $(CLI_LIBDEPS)
+
 
 ifeq ($(READLINE),libedit)
 CPPFLAGS += -DUSE_LIBEDIT
@@ -36,9 +38,9 @@ endif
 ifdef SYSTEMD
 	CPPFLAGS += -DUSE_SYSTEMD=$(SYSTEMD)
 	ifeq ($(shell test $(SYSTEMD) -gt 209 && echo 1), 1)
-		LIBDEPS += -lsystemd
+		CLI_LIBDEPS += -lsystemd
 	else
-		LIBDEPS += -lsystemd-daemon
+		CLI_LIBDEPS += -lsystemd-daemon
 	endif
 endif
 ifeq ($(ENABLE_DMEVENTS_POLL),0)
tests/Makefile +4 -4
index 95a9990..7d19b94 100644
@@ -11,9 +11,9 @@ TEST_MISSING_INITIALIZERS = $(shell \
 	|| echo -Wno-missing-field-initializers)
 W_MISSING_INITIALIZERS := $(call TEST_MISSING_INITIALIZERS)
 
-CPPFLAGS += -I$(multipathdir) -I$(mpathcmddir) -DTESTCONFDIR=\"$(TESTDIR)/conf.d\"
+CPPFLAGS += -I$(multipathdir) -I$(mpathutildir) -I$(mpathcmddir) -DTESTCONFDIR=\"$(TESTDIR)/conf.d\"
 CFLAGS += $(BIN_CFLAGS) -Wno-unused-parameter $(W_MISSING_INITIALIZERS)
-LIBDEPS += -L. -L$(mpathcmddir) -lmultipath -lmpathcmd -lcmocka
+LIBDEPS += -L. -L $(mpathutildir) -L$(mpathcmddir) -lmultipath -lmpathutil -lmpathcmd -lcmocka
 
 TESTS := uevent parser util dmevents hwtable blacklist unaligned vpd pgpolicy \
 	 alias directio valid devt mpathvalid strbuf sysfs
@@ -83,11 +83,11 @@ lib/libchecktur.so:
 
 %.out:	%-test lib/libchecktur.so
 	@echo == running $< ==
-	@LD_LIBRARY_PATH=.:$(mpathcmddir) ./$< >$@
+	@LD_LIBRARY_PATH=.:$(mpathutildir):$(mpathcmddir) ./$< >$@
 
 %.vgr:  %-test lib/libchecktur.so
 	@echo == running valgrind for $< ==
-	@LD_LIBRARY_PATH=.:$(mpathcmddir) \
+	@LD_LIBRARY_PATH=.:$(mpathutildir):$(mpathcmddir) \
 		valgrind --leak-check=full --error-exitcode=128 ./$< >$@ 2>&1
 
 OBJS = $(TESTS:%=%.o) $(HELPERS)
Signature · 6 lines
2.37.1

--
dm-devel mailing list
[email protected]
https://listman.redhat.com/mailman/listinfo/dm-devel
#10 lore raw

PATCH v2 9/11 multipathc: add new interactive client program

In reply to [email protected]

From: Martin Wilck <[email protected]>

Add a new small program, multipathc, that acts as interactive uxsock client for multipathd. multipathc is the only program that has an interactive mode and can thus link to either libreadline or libedit for command line history. All code depending on libreadline is moved from uxclnt.c and cli.c to multipathc.c.

This patch breaks multipathd's interactive mode. It will be restored in the next patch.

As multipathc doesn't link to libmultipath, it can link to libreadline without license conflict.

---
 .gitignore              |   1 +
 multipathd/Makefile     |  24 ++--
 multipathd/cli.c        | 130 ++------------------
 multipathd/cli.h        |   5 +-
 multipathd/multipathc.c | 254 ++++++++++++++++++++++++++++++++++++++++
 multipathd/uxclnt.c     | 126 +-------------------
 6 files changed, 293 insertions(+), 247 deletions(-)
 create mode 100644 multipathd/multipathc.c
.gitignore +1 -0
index b88608c..821c3e6 100644
@@ -13,6 +13,7 @@ cscope.out
 kpartx/kpartx
 multipath/multipath
 multipathd/multipathd
+multipathd/multipathc
 mpathpersist/mpathpersist
 abi.tar.gz
 abi
multipathd/Makefile +17 -7
index 7128510..19ab2e9 100644
@@ -27,12 +27,12 @@ LIBDEPS += -L$(multipathdir) -lmultipath -L$(mpathpersistdir) -lmpathpersist \
 
 
 ifeq ($(READLINE),libedit)
-CPPFLAGS += -DUSE_LIBEDIT
-LIBDEPS += -ledit
+RL_CPPFLAGS = -DUSE_LIBEDIT
+RL_LIBDEPS += -ledit
 endif
 ifeq ($(READLINE),libreadline)
-CPPFLAGS += -DUSE_LIBREADLINE
-LIBDEPS += -lreadline
+RL_CPPFLAGS += -DUSE_LIBREADLINE
+RL_LIBDEPS += -lreadline
 endif
 
 ifdef SYSTEMD
@@ -50,6 +50,8 @@ endif
 OBJS = main.o pidfile.o uxlsnr.o uxclnt.o cli.o cli_handlers.o waiter.o \
        dmevents.o init_unwinder.o
 
+CLI_OBJS = multipathc.o cli.o
+
 ifeq ($(FPIN_SUPPORT),1)
 OBJS += fpin_handlers.o
 endif
@@ -57,18 +59,26 @@ endif
 
 
 EXEC = multipathd
+CLI = multipathc
 
-all : $(EXEC)
+all : $(EXEC) $(CLI)
 
 $(EXEC): $(OBJS) $(multipathdir)/libmultipath.so $(mpathcmddir)/libmpathcmd.so
 	$(CC) $(CFLAGS) $(OBJS) $(LDFLAGS) -o $(EXEC) $(LIBDEPS)
 
+multipathc.o:	multipathc.c
+	$(CC) $(CPPFLAGS) $(RL_CPPFLAGS) $(CFLAGS) -Wno-unused-parameter -c -o $@ $<
+
+$(CLI):  $(CLI_OBJS)
+	$(CC) $(CFLAGS) $(CLI_OBJS) $(LDFLAGS) -o $@ $(CLI_LIBDEPS) $(RL_LIBDEPS)
+
 cli_handlers.o:	cli_handlers.c
 	$(CC) $(CPPFLAGS) $(CFLAGS) -Wno-unused-parameter -c -o $@ $<
 
 install:
 	$(INSTALL_PROGRAM) -d $(DESTDIR)$(bindir)
 	$(INSTALL_PROGRAM) -m 755 $(EXEC) $(DESTDIR)$(bindir)
+	$(INSTALL_PROGRAM) -m 755 $(CLI) $(DESTDIR)$(bindir)
 ifdef SYSTEMD
 	$(INSTALL_PROGRAM) -d $(DESTDIR)$(unitdir)
 	$(INSTALL_PROGRAM) -m 644 $(EXEC).service $(DESTDIR)$(unitdir)
@@ -78,13 +88,13 @@ endif
 	$(INSTALL_PROGRAM) -m 644 $(EXEC).8 $(DESTDIR)$(man8dir)
 
 uninstall:
-	$(RM) $(DESTDIR)$(bindir)/$(EXEC)
+	$(RM) $(DESTDIR)$(bindir)/$(EXEC) $(DESTDIR)$(bindir)/$(CLI)
 	$(RM) $(DESTDIR)$(man8dir)/$(EXEC).8
 	$(RM) $(DESTDIR)$(unitdir)/$(EXEC).service
 	$(RM) $(DESTDIR)$(unitdir)/$(EXEC).socket
 
 clean: dep_clean
-	$(RM) core *.o $(EXEC)
+	$(RM) core *.o $(EXEC) $(CLI)
 
 include $(wildcard $(OBJS:.o=.d))
 
multipathd/cli.c +12 -118

157 lines not on this page · raw message

multipathd/cli.h +4 -1
index a6082ac..cb5bbe2 100644
@@ -151,6 +151,9 @@ void free_keys (vector vec);
 void free_handlers (void);
 int cli_init (void);
 void cli_exit(void);
-char * key_generator (const char * str, int state);
+uint64_t fingerprint(const struct _vector *vec);
+vector get_keys(void);
+vector get_handlers(void);
+struct key *find_key (const char * str);
 
 #endif /* _CLI_H_ */
multipathd/multipathc.c new file +254 -0

254 lines not on this page · raw message

multipathd/uxclnt.c +5 -121

146 lines not on this page · raw message

Signature · 6 lines
2.37.1

--
dm-devel mailing list
[email protected]
https://listman.redhat.com/mailman/listinfo/dm-devel
#11 lore raw

PATCH v2 10/11 multipathd: exec multipathc in interactive mode

In reply to [email protected]

From: Martin Wilck <[email protected]>

A previous patch disabled interactive mode in multipathd, because uxclnt() would return immediately without an input command

With this patch, we reinstate interactive mode for "multipath -k", by just exec()ing the multipathc client.

---
 multipathd/Makefile     |  3 ++-
 multipathd/main.c       | 15 +++++++++++++--
 multipathd/multipathc.c | 25 +++++++++++++++++++++----
 3 files changed, 36 insertions(+), 7 deletions(-)
multipathd/Makefile +2 -1
index 19ab2e9..8a56304 100644
@@ -17,7 +17,8 @@ endif
 
 CPPFLAGS += -I$(multipathdir) -I$(mpathutildir) -I$(mpathpersistdir) -I$(mpathcmddir) -I$(thirdpartydir) \
 	$(shell $(PKGCONFIG) --modversion liburcu 2>/dev/null | \
-		awk -F. '{ printf("-DURCU_VERSION=0x%06x", 256 * ( 256 * $$1 + $$2) + $$3); }')
+		awk -F. '{ printf("-DURCU_VERSION=0x%06x", 256 * ( 256 * $$1 + $$2) + $$3); }') \
+	-DBINDIR='"$(bindir)"'
 CFLAGS += $(BIN_CFLAGS)
 LDFLAGS += $(BIN_LDFLAGS)
 
multipathd/main.c +13 -2
index 5a40894..63df643 100644
@@ -3616,7 +3616,7 @@ main (int argc, char *argv[])
 	extern char *optarg;
 	extern int optind;
 	int arg;
-	int err;
+	int err = 0;
 	int foreground = 0;
 	struct config *conf;
 	char *opt_k_arg = NULL;
@@ -3710,7 +3710,18 @@ main (int argc, char *argv[])
 			}
 			c += snprintf(c, s + CMDSIZE - c, "\n");
 		}
-		err = uxclnt(s, uxsock_timeout + 100);
+		if (!s) {
+			char tmo_buf[16];
+
+			snprintf(tmo_buf, sizeof(tmo_buf), "%d",
+				 uxsock_timeout + 100);
+			if (execl(BINDIR "/multipathc", "multipathc",
+				  tmo_buf, NULL) == -1) {
+				condlog(0, "ERROR: failed to execute multipathc");
+				err = 1;
+			}
+		} else
+			err = uxclnt(s, uxsock_timeout + 100);
 		free_config(conf);
 		return err;
 	}
multipathd/multipathc.c +21 -4
index 571a182..323bd78 100644
@@ -241,14 +241,31 @@ static void process(int fd, unsigned int timeout)
 	}
 }
 
-int main (void)
+int main (int argc, const char * const argv[])
 {
-	int fd = mpath_connect();
+	int fd;
+	int tmo = DEFAULT_REPLY_TIMEOUT + 100;
+	char *ep;
 
-	if (fd == -1)
+	if (argc > 2) {
+		fprintf(stderr, "Usage: %s [timeout]\n", argv[0]);
 		return 1;
+	}
+	if (argc == 2) {
+		tmo = strtol(argv[1], &ep, 10);
+		if (*argv[1] == '\0' || *ep != '\0') {
+			fprintf(stderr, "ERROR: invalid timeout value\n");
+			return 1;
+		}
+	}
 
-	process(fd, DEFAULT_REPLY_TIMEOUT + 100);
+	fd = mpath_connect();
+	if (fd == -1) {
+		fprintf(stderr, "ERROR: failed to connect to multipathd\n");
+		return 1;
+	}
+
+	process(fd, tmo);
 	mpath_disconnect(fd);
 	return 0;
 }
Signature · 6 lines
2.37.1

--
dm-devel mailing list
[email protected]
https://listman.redhat.com/mailman/listinfo/dm-devel
#12 lore raw

Re: [dm-devel] [PATCH v2 10/11] multipathd: exec multipathc in interactive mode

Quoted 45 lines · On Mon, Aug 22, 2022 at 10:41:18PM +0200, [email protected] wrote:

From: Martin Wilck <[email protected]>

A previous patch disabled interactive mode in multipathd, because uxclnt() would return immediately without an input command

With this patch, we reinstate interactive mode for "multipath -k", by just exec()ing the multipathc client.

---
 multipathd/Makefile     |  3 ++-
 multipathd/main.c       | 15 +++++++++++++--
 multipathd/multipathc.c | 25 +++++++++++++++++++++----
 3 files changed, 36 insertions(+), 7 deletions(-)
multipathd/Makefile +2 -1
index 19ab2e9..8a56304 100644
@@ -17,7 +17,8 @@ endif
 
 CPPFLAGS += -I$(multipathdir) -I$(mpathutildir) -I$(mpathpersistdir) -I$(mpathcmddir) -I$(thirdpartydir) \
 	$(shell $(PKGCONFIG) --modversion liburcu 2>/dev/null | \
-		awk -F. '{ printf("-DURCU_VERSION=0x%06x", 256 * ( 256 * $$1 + $$2) + $$3); }')
+		awk -F. '{ printf("-DURCU_VERSION=0x%06x", 256 * ( 256 * $$1 + $$2) + $$3); }') \
+	-DBINDIR='"$(bindir)"'
 CFLAGS += $(BIN_CFLAGS)
 LDFLAGS += $(BIN_LDFLAGS)
 
multipathd/main.c +1 -1
index 5a40894..63df643 100644
@@ -3616,7 +3616,7 @@ main (int argc, char *argv[])
 	extern char *optarg;
 	extern int optind;
 	int arg;
-	int err;
+	int err = 0;
 	int foreground = 0;
 	struct config *conf;
 	char *opt_k_arg = NULL;
@@ -3710,7 +3710,18 @@ main (int argc, char *argv[])
 			}
 			c += snprintf(c, s + CMDSIZE - c, "\n");

multipathd/main.c main (int argc, char *argv[]) · line 3720

Quoted 10 lines
multipathd/main.c +8 -1
 		}
-		err = uxclnt(s, uxsock_timeout + 100);
+		if (!s) {
+			char tmo_buf[16];
+
+			snprintf(tmo_buf, sizeof(tmo_buf), "%d",
+				 uxsock_timeout + 100);
+			if (execl(BINDIR "/multipathc", "multipathc",
+				  tmo_buf, NULL) == -1) {
+				condlog(0, "ERROR: failed to execute multipathc");

We should probably print the error code here.

Quoted 20 lines
multipathd/main.c +4 -0
+				err = 1;
+			}
+		} else
+			err = uxclnt(s, uxsock_timeout + 100);
 		free_config(conf);
 		return err;
 	}
multipathd/multipathc.c +2 -2
index 571a182..323bd78 100644
@@ -241,14 +241,31 @@ static void process(int fd, unsigned int timeout)
 	}
 }
 
-int main (void)
+int main (int argc, const char * const argv[])
 {
-	int fd = mpath_connect();
+	int fd;

multipathd/multipathc.c static void process(int fd, unsigned int timeout) · line 255

Quoted 10 lines
multipathd/multipathc.c +7 -1
+	int tmo = DEFAULT_REPLY_TIMEOUT + 100;
+	char *ep;
 
-	if (fd == -1)
+	if (argc > 2) {
+		fprintf(stderr, "Usage: %s [timeout]\n", argv[0]);
 		return 1;
+	}
+	if (argc == 2) {
+		tmo = strtol(argv[1], &ep, 10);

strtol() can return a negative number, but process() takes an unsigned int. We should probably either use strtoul() or check for negative tmo, and error.

-Ben

Quoted 19 lines
multipathd/multipathc.c +12 -1
+		if (*argv[1] == '\0' || *ep != '\0') {
+			fprintf(stderr, "ERROR: invalid timeout value\n");
+			return 1;
+		}
+	}
 
-	process(fd, DEFAULT_REPLY_TIMEOUT + 100);
+	fd = mpath_connect();
+	if (fd == -1) {
+		fprintf(stderr, "ERROR: failed to connect to multipathd\n");
+		return 1;
+	}
+
+	process(fd, tmo);
 	mpath_disconnect(fd);
 	return 0;
 }
Signature · 1 line
2.37.1

--
dm-devel mailing list
[email protected]
https://listman.redhat.com/mailman/listinfo/dm-devel

#13 lore raw

PATCH v2 11/11 multipathd: fix incompatible pointer type error with libedit

In reply to [email protected]

From: Martin Wilck <[email protected]>

Versions of libedit prior to 2016 were using a wrong prototype for rl_completion_entry_function in readline.h. Internally, libedit casts this to the correct type (char *)(*)(const char *, int) (aka CPFunction in libedit). So we simply cast to the wrong prototype here.

See http://cvsweb.netbsd.org/bsdweb.cgi/src/lib/libedit/readline/readline.h.diff?r1=1.34&r2=1.35

---
 multipathd/Makefile | 4 ++++
 1 file changed, 4 insertions(+)
multipathd/Makefile +4 -0
index 8a56304..28ebdc0 100644
@@ -34,6 +34,10 @@ endif
 ifeq ($(READLINE),libreadline)
 RL_CPPFLAGS += -DUSE_LIBREADLINE
 RL_LIBDEPS += -lreadline
+# See comment in uxclnt.c
+ifeq ($(shell sed -En 's/.*\<Function\s*\*rl_completion_entry_function;.*/yes/p' /usr/include/editline/readline.h),yes)
+RL_CPPFLAGS += -DBROKEN_RL_COMPLETION_FUNC
+endif
 endif
 
 ifdef SYSTEMD
Signature · 6 lines
2.37.1

--
dm-devel mailing list
[email protected]
https://listman.redhat.com/mailman/listinfo/dm-devel