Skip to contentSkip to conversation

Split libmultipath and libmpathutil

PATCH In review [email protected] 2 participants 17 messages Aug 30, 2022 – Aug 31, 2022

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

v4 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. This program links to libmpathutil only. With patch 10, in interactive mode, "multipathd -k" just exec()s this 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 v3 -> v4 (suggested by Ben Marzinski, unless noted otherwise):
- 01/11: don't drop add_history() call if readline library is in use
- 01/11: remove key_generator from cli.h if unused
- 09/11: fix a defect detected by coverity
- 10/11: better error messages, and error out on negative timeout value
- 12/11: added, found by coverity

Changes v2->v3:
fix compilation errors on Alpine an CI errors.

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 (11):
.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
multipathd: fix use-after-free in handle_path_wwid_change()

 .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            | 123 +++++++++
 {libmultipath => libmpathutil}/log.c         |   0
 {libmultipath => libmpathutil}/log.h         |   0
 {libmultipath => libmpathutil}/log_pthread.c |   0
 {libmultipath => libmpathutil}/log_pthread.h |   0
 {libmultipath => libmpathutil}/msort.c       |   0
 {libmultipath => libmpathutil}/msort.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/emc_clariion.c         |   2 +-
 libmultipath/checkers/hp_sw.c                |   4 +-
 libmultipath/checkers/rdac.c                 |   2 +-
 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                            |  20 +-
 multipathd/multipathc.c                      | 276 +++++++++++++++++++
 multipathd/uxclnt.c                          | 108 +-------
 tests/Makefile                               |  12 +-
 55 files changed, 703 insertions(+), 396 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}/msort.c (100%)
 rename {libmultipath => libmpathutil}/msort.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 v4 1/12 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/cli.h    |  4 +++-
 multipathd/uxclnt.c | 49 +++++++++++++++++++++++++++++++++------------
 4 files changed, 43 insertions(+), 16 deletions(-)
Makefile.inc +2 -2
index ad7afd0..4b32fa7 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/cli.h +3 -1
index a6082ac..2a0c102 100644
@@ -151,6 +151,8 @@ 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);
+#if defined(USE_LIBREADLINE) || defined(USE_LIBEDIT)
+char *key_generator (const char * str, int state);
+#endif
 
 #endif /* _CLI_H_ */
multipathd/uxclnt.c +36 -13

77 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
maintainer Reviewed-by on v4 1/12
#2 lore raw

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

Quoted 11 lines · On Tue, Aug 30, 2022 at 09:27:02PM +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.

Quoted 140 lines
---
 Makefile.inc        |  4 ++--
 multipathd/cli.c    |  2 ++
 multipathd/cli.h    |  4 +++-
 multipathd/uxclnt.c | 49 +++++++++++++++++++++++++++++++++------------
 4 files changed, 43 insertions(+), 16 deletions(-)
Makefile.inc +2 -2
index ad7afd0..4b32fa7 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/cli.h +3 -1
index a6082ac..2a0c102 100644
@@ -151,6 +151,8 @@ 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);
+#if defined(USE_LIBREADLINE) || defined(USE_LIBEDIT)
+char *key_generator (const char * str, int state);
+#endif
 
 #endif /* _CLI_H_ */
multipathd/uxclnt.c +36 -13
index 251e7d7..deff565 100644
@@ -30,6 +30,7 @@
 #include "defaults.h"
 
 #include "vector.h"
+#include "util.h"
 #include "cli.h"
 #include "uxclnt.h"
 
@@ -77,35 +78,57 @@ 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;
+		if (ret != 0)
+			break;
 
 		print_reply(reply);
 
+#if defined(USE_LIBREADLINE) || defined(USE_LIBEDIT)
 		if (line && *line)
 			add_history(line);
-
-		free(line);
-		free(reply);
+#endif
 	}
 }
 
Signature · 1 line
2.37.1

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

#3 lore raw

PATCH v4 2/12 .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 v4 3/12 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 a70acab..01c7d26 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 v4 4/12 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 01c7d26..6e87a16 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 v4 5/12 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 v4 6/12 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        | 5 +++--
 libmultipath/checkers/directio.c      | 4 ++--
 libmultipath/checkers/emc_clariion.c  | 2 +-
 libmultipath/checkers/hp_sw.c         | 4 ++--
 libmultipath/checkers/rdac.c          | 2 +-
 libmultipath/checkers/tur.c           | 8 ++++----
 libmultipath/foreign/Makefile         | 4 ++--
 libmultipath/prioritizers/Makefile    | 6 ++++--
 libmultipath/prioritizers/alua_rtpg.c | 2 +-
 9 files changed, 20 insertions(+), 17 deletions(-)
libmultipath/checkers/Makefile +3 -2
index 8d8e45e..69de1ed 100644
@@ -1,11 +1,12 @@
 #
 # Copyright (C) 2003 Christophe Varoqui, <[email protected]>
 #
+TOPDIR = ../..
 include ../../Makefile.inc
 
-CPPFLAGS += -I..
+CPPFLAGS += -I$(multipathdir)
 CFLAGS += $(LIB_CFLAGS)
-LDFLAGS += -L.. -lmultipath
+LDFLAGS += -L$(multipathdir)
 LIBDEPS = -lmultipath -laio -lpthread -lrt
 
 # If you add or remove a checker also update multipath/multipath.conf.5
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/emc_clariion.c +1 -1
index aa636e7..04635b5 100644
@@ -11,7 +11,7 @@
 #include <sys/ioctl.h>
 #include <errno.h>
 
-#include "../libmultipath/sg_include.h"
+#include "sg_include.h"
 #include "libsg.h"
 #include "checkers.h"
 #include "debug.h"
libmultipath/checkers/hp_sw.c +2 -2
index 915918c..1ab7909 100644
@@ -13,8 +13,8 @@
 
 #include "checkers.h"
 
-#include "../libmultipath/sg_include.h"
-#include "../libmultipath/unaligned.h"
+#include "sg_include.h"
+#include "unaligned.h"
 
 #define TUR_CMD_LEN		6
 #define INQUIRY_CMDLEN		6
libmultipath/checkers/rdac.c +1 -1
index f7aaa30..9a3860f 100644
@@ -14,7 +14,7 @@
 #include "checkers.h"
 #include "debug.h"
 
-#include "../libmultipath/sg_include.h"
+#include "sg_include.h"
 
 #define INQUIRY_CMDLEN		6
 #define INQUIRY_CMD		0x12
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 v4 7/12 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 v4 8/12 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            | 123 +++++++++++++++++++
 {libmultipath => libmpathutil}/log.c         |   0
 {libmultipath => libmpathutil}/log.h         |   0
 {libmultipath => libmpathutil}/log_pthread.c |   0
 {libmultipath => libmpathutil}/log_pthread.h |   0
 {libmultipath => libmpathutil}/msort.c       |   0
 {libmultipath => libmpathutil}/msort.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               |   6 +-
 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                               |  12 +-
 38 files changed, 290 insertions(+), 84 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}/msort.c (100%)
 rename {libmultipath => libmpathutil}/msort.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 4b32fa7..6399beb 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 +123 -0

123 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/msort.c renamed from libmultipath/msort.c +0 -0
similarity index 100%
rename from libmultipath/msort.c
rename to libmpathutil/msort.c
libmpathutil/msort.h renamed from libmultipath/msort.h +0 -0
similarity index 100%
rename from libmultipath/msort.h
rename to libmpathutil/msort.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 6e87a16..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 msort.o
+	libsg.o valid.o
 
 OBJS := $(OBJS-O) $(OBJS-U)
 
libmultipath/checkers/Makefile +3 -3
index 69de1ed..c9a2c4c 100644
@@ -4,10 +4,10 @@
 TOPDIR = ../..
 include ../../Makefile.inc
 
-CPPFLAGS += -I$(multipathdir)
+CPPFLAGS +=  -I$(multipathdir) -I$(mpathutildir)
 CFLAGS += $(LIB_CFLAGS)
-LDFLAGS += -L$(multipathdir)
-LIBDEPS = -lmultipath -laio -lpthread -lrt
+LDFLAGS += -L$(multipathdir) -L$(mpathutildir)
+LIBDEPS = -lmultipath -lmpathutil -laio -lpthread -lrt
 
 # If you add or remove a checker also update multipath/multipath.conf.5
 LIBS= \
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 +6 -6
index 95a9990..9866962 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
@@ -69,9 +69,9 @@ mpathvalid-test_OBJDEPS := ../libmpathvalid/mpath_valid.o
 ifneq ($(DIO_TEST_DEV),)
 directio-test_LIBDEPS := -laio
 endif
-strbuf-test_OBJDEPS := ../libmultipath/strbuf.o
+strbuf-test_OBJDEPS := ../libmpathutil/strbuf.o
 sysfs-test_TESTDEPS := test-log.o
-sysfs-test_OBJDEPS := ../libmultipath/sysfs.o ../libmultipath/util.o
+sysfs-test_OBJDEPS := ../libmultipath/sysfs.o ../libmpathutil/util.o
 sysfs-test_LIBDEPS := -ludev -lpthread -ldl
 
 %.o: %.c
@@ -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 v4 9/12 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        |   7 +-
 multipathd/multipathc.c | 259 ++++++++++++++++++++++++++++++++++++++++
 multipathd/uxclnt.c     | 131 +-------------------
 6 files changed, 299 insertions(+), 253 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 -3
index 2a0c102..cb5bbe2 100644
@@ -151,8 +151,9 @@ void free_keys (vector vec);
 void free_handlers (void);
 int cli_init (void);
 void cli_exit(void);
-#if defined(USE_LIBREADLINE) || defined(USE_LIBEDIT)
-char *key_generator (const char * str, int state);
-#endif
+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 +259 -0

259 lines not on this page · raw message

multipathd/uxclnt.c +6 -125

153 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
maintainer Reviewed-by on v4 9/12
#11 lore raw

Re: [dm-devel] [PATCH v4 09/12] multipathc: add new interactive client program

Quoted 8 lines · On Tue, Aug 30, 2022 at 09:27:10PM +0200, [email protected] wrote:

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.

Quoted 8 lines

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.

Quoted 705 lines
---
 .gitignore              |   1 +
 multipathd/Makefile     |  24 ++--
 multipathd/cli.c        | 130 ++------------------
 multipathd/cli.h        |   7 +-
 multipathd/multipathc.c | 259 ++++++++++++++++++++++++++++++++++++++++
 multipathd/uxclnt.c     | 131 +-------------------
 6 files changed, 299 insertions(+), 253 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
index cc56950..d1bfeee 100644
@@ -11,12 +11,6 @@
 #include "parser.h"
 #include "util.h"
 #include "version.h"
-#ifdef USE_LIBEDIT
-#include <editline/readline.h>
-#endif
-#ifdef USE_LIBREADLINE
-#include <readline/readline.h>
-#endif
 
 #include "mpath_cmd.h"
 #include "cli.h"
@@ -26,6 +20,16 @@
 static vector keys;
 static vector handlers;
 
+vector get_keys(void)
+{
+	return keys;
+}
+
+vector get_handlers(void)
+{
+	return handlers;
+}
+
 static struct key *
 alloc_key (void)
 {
@@ -225,8 +229,7 @@ load_keys (void)
 	return 0;
 }
 
-static struct key *
-find_key (const char * str)
+struct key *find_key (const char * str)
 {
 	int i;
 	int len, klen;
@@ -323,8 +326,7 @@ out:
 	return r;
 }
 
-static uint64_t
-fingerprint(const struct _vector *vec)
+uint64_t fingerprint(const struct _vector *vec)
 {
 	int i;
 	uint64_t fp = 0;
@@ -458,111 +460,3 @@ void cli_exit(void)
 	free_keys(keys);
 	keys = NULL;
 }
-
-#if defined(USE_LIBREADLINE) || defined(USE_LIBEDIT)
-static int
-key_match_fingerprint (struct key * kw, uint64_t fp)
-{
-	if (!fp)
-		return 0;
-
-	return ((fp & kw->code) == kw->code);
-}
-
-/*
- * This is the readline completion handler
- */
-char *
-key_generator (const char * str, int state)
-{
-	static int index, len, has_param;
-	static uint64_t rlfp;
-	struct key * kw;
-	int i;
-	struct handler *h;
-	vector v = NULL;
-
-	if (!state) {
-		index = 0;
-		has_param = 0;
-		rlfp = 0;
-		len = strlen(str);
-		int r = get_cmdvec(rl_line_buffer, &v);
-		/*
-		 * If a word completion is in progress, we don't want
-		 * to take an exact keyword match in the fingerprint.
-		 * For ex "show map[tab]" would validate "map" and discard
-		 * "maps" as a valid candidate.
-		 */
-		if (v && len)
-			vector_del_slot(v, VECTOR_SIZE(v) - 1);
-		/*
-		 * Clean up the mess if we dropped the last slot of a 1-slot
-		 * vector
-		 */
-		if (v && !VECTOR_SIZE(v)) {
-			vector_free(v);
-			v = NULL;
-		}
-		/*
-		 * If last keyword takes a param, don't even try to guess
-		 */
-		if (r == EINVAL) {
-			has_param = 1;
-			return (strdup("(value)"));
-		}
-		/*
-		 * Compute a command fingerprint to find out possible completions.
-		 * Once done, the vector is useless. Free it.
-		 */
-		if (v) {
-			rlfp = fingerprint(v);
-			free_keys(v);
-		}
-	}
-	/*
-	 * No more completions for parameter placeholder.
-	 * Brave souls might try to add parameter completion by walking paths and
-	 * multipaths vectors.
-	 */
-	if (has_param)
-		return ((char *)NULL);
-	/*
-	 * Loop through keywords for completion candidates
-	 */
-	vector_foreach_slot_after (keys, kw, index) {
-		if (!strncmp(kw->str, str, len)) {
-			/*
-			 * Discard keywords already in the command line
-			 */
-			if (key_match_fingerprint(kw, rlfp)) {
-				struct key * curkw = find_key(str);
-				if (!curkw || (curkw != kw))
-					continue;
-			}
-			/*
-			 * Discard keywords making syntax errors.
-			 *
-			 * nfp is the candidate fingerprint we try to
-			 * validate against all known command fingerprints.
-			 */
-			uint64_t nfp = rlfp | kw->code;
-			vector_foreach_slot(handlers, h, i) {
-				if (!rlfp || ((h->fingerprint & nfp) == nfp)) {
-					/*
-					 * At least one full command is
-					 * possible with this keyword :
-					 * Consider it validated
-					 */
-					index++;
-					return (strdup(kw->str));
-				}
-			}
-		}
-	}
-	/*
-	 * No more candidates
-	 */
-	return ((char *)NULL);
-}
-#endif
multipathd/cli.h +4 -3
index 2a0c102..cb5bbe2 100644
@@ -151,8 +151,9 @@ void free_keys (vector vec);
 void free_handlers (void);
 int cli_init (void);
 void cli_exit(void);
-#if defined(USE_LIBREADLINE) || defined(USE_LIBEDIT)
-char *key_generator (const char * str, int state);
-#endif
+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 +259 -0
new file mode 100644
index 0000000..a4f9023
@@ -0,0 +1,259 @@
+/*
+ * Copyright (c) 2022 SUSE LLC
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+#include <string.h>
+#include <stdio.h>
+#include <stdbool.h>
+#include <unistd.h>
+#include <errno.h>
+#include <ctype.h>
+
+#include "mpath_cmd.h"
+#include "uxclnt.h"
+#include "vector.h"
+#include "uxsock.h"
+#include "util.h"
+#include "cli.h"
+
+#ifdef USE_LIBEDIT
+#include <editline/readline.h>
+#endif
+#ifdef USE_LIBREADLINE
+#include <readline/readline.h>
+#include <readline/history.h>
+#endif
+/*
+ * 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).
+ * 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
+ * Unfortunately, this change isn't reflected in the libedit version.
+ */
+#ifdef BROKEN_RL_COMPLETION_FUNC
+#define RL_COMP_ENTRY_CAST(x) ((int (*)(const char *, int)) (x))
+#else
+#define RL_COMP_ENTRY_CAST(x) (x)
+#endif
+
+#if defined(USE_LIBREADLINE) || defined(USE_LIBEDIT)
+static int
+key_match_fingerprint (struct key * kw, uint64_t fp)
+{
+	if (!fp)
+		return 0;
+
+	return ((fp & kw->code) == kw->code);
+}
+
+/*
+ * This is the readline completion handler
+ */
+char *
+key_generator (const char * str, int state)
+{
+	static int index, len, has_param;
+	static uint64_t rlfp;
+	struct key * kw;
+	int i;
+	struct handler *h;
+	vector v = NULL;
+	const vector keys = get_keys();
+	const vector handlers = get_handlers();
+
+	if (!state) {
+		index = 0;
+		has_param = 0;
+		rlfp = 0;
+		len = strlen(str);
+		int r = get_cmdvec(rl_line_buffer, &v);
+		/*
+		 * If a word completion is in progress, we don't want
+		 * to take an exact keyword match in the fingerprint.
+		 * For ex "show map[tab]" would validate "map" and discard
+		 * "maps" as a valid candidate.
+		 */
+		if (v && len)
+			vector_del_slot(v, VECTOR_SIZE(v) - 1);
+		/*
+		 * Clean up the mess if we dropped the last slot of a 1-slot
+		 * vector
+		 */
+		if (v && !VECTOR_SIZE(v)) {
+			vector_free(v);
+			v = NULL;
+		}
+		/*
+		 * If last keyword takes a param, don't even try to guess
+		 */
+		if (r == EINVAL) {
+			has_param = 1;
+			return (strdup("(value)"));
+		}
+		/*
+		 * Compute a command fingerprint to find out possible completions.
+		 * Once done, the vector is useless. Free it.
+		 */
+		if (v) {
+			rlfp = fingerprint(v);
+			free_keys(v);
+		}
+	}
+	/*
+	 * No more completions for parameter placeholder.
+	 * Brave souls might try to add parameter completion by walking paths and
+	 * multipaths vectors.
+	 */
+	if (has_param)
+		return ((char *)NULL);
+	/*
+	 * Loop through keywords for completion candidates
+	 */
+	vector_foreach_slot_after (keys, kw, index) {
+		if (!strncmp(kw->str, str, len)) {
+			/*
+			 * Discard keywords already in the command line
+			 */
+			if (key_match_fingerprint(kw, rlfp)) {
+				struct key * curkw = find_key(str);
+				if (!curkw || (curkw != kw))
+					continue;
+			}
+			/*
+			 * Discard keywords making syntax errors.
+			 *
+			 * nfp is the candidate fingerprint we try to
+			 * validate against all known command fingerprints.
+			 */
+			uint64_t nfp = rlfp | kw->code;
+			vector_foreach_slot(handlers, h, i) {
+				if (!rlfp || ((h->fingerprint & nfp) == nfp)) {
+					/*
+					 * At least one full command is
+					 * possible with this keyword :
+					 * Consider it validated
+					 */
+					index++;
+					return (strdup(kw->str));
+				}
+			}
+		}
+	}
+	/*
+	 * No more candidates
+	 */
+	return ((char *)NULL);
+}
+#endif
+
+static void print_reply(char *s)
+{
+	if (!s)
+		return;
+
+	if (isatty(1)) {
+		printf("%s", s);
+		return;
+	}
+	/* strip ANSI color markers */
+	while (*s != '\0') {
+		if ((*s == 0x1b) && (*(s+1) == '['))
+			while ((*s++ != 'm') && (*s != '\0')) {};
+		putchar(*s++);
+	}
+}
+
+static int need_quit(char *str, size_t len)
+{
+	char *ptr, *start;
+	size_t trimed_len = len;
+
+	for (ptr = str; trimed_len && isspace(*ptr);
+	     trimed_len--, ptr++)
+		;
+
+	start = ptr;
+
+	for (ptr = str + len - 1; trimed_len && isspace(*ptr);
+	     trimed_len--, ptr--)
+		;
+
+	if ((trimed_len == 4 && !strncmp(start, "exit", 4)) ||
+	    (trimed_len == 4 && !strncmp(start, "quit", 4)))
+		return 1;
+
+	return 0;
+}
+
+/*
+ * process the client
+ */
+static void process(int fd, unsigned int timeout)
+{
+
+#if defined(USE_LIBREADLINE) || defined(USE_LIBEDIT)
+	rl_readline_name = "multipathd";
+	rl_completion_entry_function = RL_COMP_ENTRY_CAST(key_generator);
+#endif
+
+	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;
+		ret = recv_packet(fd, &reply, timeout);
+		if (ret != 0)
+			break;
+
+		print_reply(reply);
+
+#if defined(USE_LIBREADLINE) || defined(USE_LIBEDIT)
+		if (line && *line)
+			add_history(line);
+#endif
+	}
+}
+
+int main (void)
+{
+	int fd = mpath_connect();
+
+	if (fd == -1)
+		return 1;
+
+	process(fd, DEFAULT_REPLY_TIMEOUT + 100);
+	mpath_disconnect(fd);
+	return 0;
+}
multipathd/uxclnt.c +6 -125
index deff565..c3ae5db 100644
@@ -5,133 +5,14 @@
  * Copyright (c) 2005 Benjamin Marzinski, Redhat
  */
 #include <stdio.h>
+#include <string.h>
 #include <stdlib.h>
-#include <unistd.h>
-#include <stdarg.h>
-#include <ctype.h>
-#include <fcntl.h>
 #include <errno.h>
-#include <sys/ioctl.h>
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <sys/un.h>
-#include <poll.h>
-
-#ifdef USE_LIBEDIT
-#include <editline/readline.h>
-#endif
-#ifdef USE_LIBREADLINE
-#include <readline/readline.h>
-#include <readline/history.h>
-#endif
 
 #include "mpath_cmd.h"
 #include "uxsock.h"
-#include "defaults.h"
-
-#include "vector.h"
-#include "util.h"
-#include "cli.h"
 #include "uxclnt.h"
 
-static void print_reply(char *s)
-{
-	if (!s)
-		return;
-
-	if (isatty(1)) {
-		printf("%s", s);
-		return;
-	}
-	/* strip ANSI color markers */
-	while (*s != '\0') {
-		if ((*s == 0x1b) && (*(s+1) == '['))
-			while ((*s++ != 'm') && (*s != '\0')) {};
-		putchar(*s++);
-	}
-}
-
-static int need_quit(char *str, size_t len)
-{
-	char *ptr, *start;
-	size_t trimed_len = len;
-
-	for (ptr = str; trimed_len && isspace(*ptr);
-	     trimed_len--, ptr++)
-		;
-
-	start = ptr;
-
-	for (ptr = str + len - 1; trimed_len && isspace(*ptr);
-	     trimed_len--, ptr--)
-		;
-
-	if ((trimed_len == 4 && !strncmp(start, "exit", 4)) ||
-	    (trimed_len == 4 && !strncmp(start, "quit", 4)))
-		return 1;
-
-	return 0;
-}
-
-/*
- * process the client
- */
-static void process(int fd, unsigned int timeout)
-{
-
-#if defined(USE_LIBREADLINE) || defined(USE_LIBEDIT)
-	rl_readline_name = "multipathd";
-	rl_completion_entry_function = key_generator;
-#endif
-
-	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;
-		ret = recv_packet(fd, &reply, timeout);
-		if (ret != 0)
-			break;
-
-		print_reply(reply);
-
-#if defined(USE_LIBREADLINE) || defined(USE_LIBEDIT)
-		if (line && *line)
-			add_history(line);
-#endif
-	}
-}
-
 static int process_req(int fd, char * inbuf, unsigned int timeout)
 {
 	char *reply;
@@ -163,14 +44,14 @@ int uxclnt(char * inbuf, unsigned int timeout)
 {
 	int fd, ret = 0;
 
+	if (!inbuf)
+		return 1;
 	fd = mpath_connect();
 	if (fd == -1)
-		exit(1);
+		return 1;
+
+	ret = process_req(fd, inbuf, timeout);
 
-	if (inbuf)
-		ret = process_req(fd, inbuf, timeout);
-	else
-		process(fd, timeout);
 	mpath_disconnect(fd);
 	return ret;
 }
Signature · 1 line
2.37.1

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

#12 lore raw

PATCH v4 10/12 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..66177cd 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: %m");
+				err = 1;
+			}
+		} else
+			err = uxclnt(s, uxsock_timeout + 100);
 		free_config(conf);
 		return err;
 	}
multipathd/multipathc.c +21 -4
index a4f9023..9d49655 100644
@@ -246,14 +246,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' || tmo < 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
maintainer Reviewed-by on v4 10/12
#13 lore raw

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

Quoted 9 lines · On Tue, Aug 30, 2022 at 09:27:11PM +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.

Quoted 95 lines
---
 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..66177cd 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: %m");
+				err = 1;
+			}
+		} else
+			err = uxclnt(s, uxsock_timeout + 100);
 		free_config(conf);
 		return err;
 	}
multipathd/multipathc.c +21 -4
index a4f9023..9d49655 100644
@@ -246,14 +246,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' || tmo < 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

#14 lore raw

PATCH v4 11/12 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
#15 lore raw

PATCH v4 12/12 multipathd: fix use-after-free in handle_path_wwid_change()

In reply to [email protected]

From: Martin Wilck <[email protected]>

Found by coverity (defect #380536).

Fixes b4eb57e ("libmultipath, multipathd: log failure setting sysfs attributes")
---
 multipathd/main.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
multipathd/main.c +3 -2
index 66177cd..2d0a7bc 100644
@@ -951,10 +951,12 @@ handle_path_wwid_change(struct path *pp, struct vectors *vecs)
 	struct udev_device *udd;
 	static const char add[] = "add";
 	ssize_t ret;
+	char dev[FILE_NAME_SIZE];
 
 	if (!pp || !pp->udev)
 		return;
 
+	strlcpy(dev, pp->dev, sizeof(dev));
 	udd = udev_device_ref(pp->udev);
 	if (!(ev_remove_path(pp, vecs, 1) & REMOVE_PATH_SUCCESS) && pp->mpp) {
 		pp->dmstate = PSTATE_FAILED;
@@ -965,8 +967,7 @@ handle_path_wwid_change(struct path *pp, struct vectors *vecs)
 	udev_device_unref(udd);
 	if (ret != sizeof(add) - 1)
 		log_sysfs_attr_set_value(1, ret,
-					 "%s: failed to trigger add event",
-					 pp->dev);
+					 "%s: failed to trigger add event", dev);
 }
 
 bool
Signature · 6 lines
2.37.1

--
dm-devel mailing list
[email protected]
https://listman.redhat.com/mailman/listinfo/dm-devel
maintainer Reviewed-by on v4 12/12
#16 lore raw

Re: [dm-devel] [PATCH v4 12/12] multipathd: fix use-after-free in handle_path_wwid_change()

Quoted 5 lines · On Tue, Aug 30, 2022 at 09:27:13PM +0200, [email protected] wrote:

From: Martin Wilck <[email protected]>

Found by coverity (defect #380536).

Fixes b4eb57e ("libmultipath, multipathd: log failure setting sysfs attributes")
Quoted 33 lines
---
 multipathd/main.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
multipathd/main.c +3 -2
index 66177cd..2d0a7bc 100644
@@ -951,10 +951,12 @@ handle_path_wwid_change(struct path *pp, struct vectors *vecs)
 	struct udev_device *udd;
 	static const char add[] = "add";
 	ssize_t ret;
+	char dev[FILE_NAME_SIZE];
 
 	if (!pp || !pp->udev)
 		return;
 
+	strlcpy(dev, pp->dev, sizeof(dev));
 	udd = udev_device_ref(pp->udev);
 	if (!(ev_remove_path(pp, vecs, 1) & REMOVE_PATH_SUCCESS) && pp->mpp) {
 		pp->dmstate = PSTATE_FAILED;
@@ -965,8 +967,7 @@ handle_path_wwid_change(struct path *pp, struct vectors *vecs)
 	udev_device_unref(udd);
 	if (ret != sizeof(add) - 1)
 		log_sysfs_attr_set_value(1, ret,
-					 "%s: failed to trigger add event",
-					 pp->dev);
+					 "%s: failed to trigger add event", dev);
 }
 
 bool
Signature · 1 line
2.37.1

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