|
|
d88bf6 |
From c146b5840bbd7ad89c8a8de6192590ad0595a977 Mon Sep 17 00:00:00 2001
|
|
|
d88bf6 |
From: Benjamin Marzinski <bmarzins@redhat.com>
|
|
|
d88bf6 |
Date: Thu, 7 Apr 2016 18:19:58 -0500
|
|
|
d88bf6 |
Subject: [PATCH] Add libmpathcmd library and use it internally
|
|
|
d88bf6 |
|
|
|
d88bf6 |
Other programs would like to communicate with multipathd to issue
|
|
|
d88bf6 |
command or check status. Instead of having them exec multipathd,
|
|
|
d88bf6 |
I've pulled the code that sends commands and receives replies from
|
|
|
d88bf6 |
multipathd into its own library. I've made the multipath tools use
|
|
|
d88bf6 |
this library internally as well.
|
|
|
d88bf6 |
|
|
|
d88bf6 |
Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
|
|
|
d88bf6 |
---
|
|
|
d88bf6 |
Makefile | 1
|
|
|
d88bf6 |
Makefile.inc | 2
|
|
|
d88bf6 |
libmpathcmd/Makefile | 32 +++++++
|
|
|
d88bf6 |
libmpathcmd/mpath_cmd.c | 178 +++++++++++++++++++++++++++++++++++++++
|
|
|
d88bf6 |
libmpathcmd/mpath_cmd.h | 125 +++++++++++++++++++++++++++
|
|
|
d88bf6 |
libmpathpersist/Makefile | 5 -
|
|
|
d88bf6 |
libmpathpersist/mpath_updatepr.c | 30 +++---
|
|
|
d88bf6 |
libmultipath/Makefile | 4
|
|
|
d88bf6 |
libmultipath/config.c | 1
|
|
|
d88bf6 |
libmultipath/configure.c | 10 +-
|
|
|
d88bf6 |
libmultipath/uxsock.c | 88 +++----------------
|
|
|
d88bf6 |
libmultipath/uxsock.h | 6 -
|
|
|
d88bf6 |
mpathpersist/Makefile | 2
|
|
|
d88bf6 |
multipath/Makefile | 5 -
|
|
|
d88bf6 |
multipathd/Makefile | 4
|
|
|
d88bf6 |
multipathd/uxclnt.c | 13 +-
|
|
|
d88bf6 |
multipathd/uxlsnr.c | 9 -
|
|
|
d88bf6 |
17 files changed, 401 insertions(+), 114 deletions(-)
|
|
|
d88bf6 |
create mode 100644 libmpathcmd/Makefile
|
|
|
d88bf6 |
create mode 100644 libmpathcmd/mpath_cmd.c
|
|
|
d88bf6 |
create mode 100644 libmpathcmd/mpath_cmd.h
|
|
|
d88bf6 |
|
|
|
d88bf6 |
Index: multipath-tools-130222/Makefile
|
|
|
d88bf6 |
===================================================================
|
|
|
d88bf6 |
--- multipath-tools-130222.orig/Makefile
|
|
|
d88bf6 |
+++ multipath-tools-130222/Makefile
|
|
|
d88bf6 |
@@ -20,6 +20,7 @@ export KRNLSRC
|
|
|
d88bf6 |
export KRNLOBJ
|
|
|
d88bf6 |
|
|
|
d88bf6 |
BUILDDIRS = \
|
|
|
d88bf6 |
+ libmpathcmd \
|
|
|
d88bf6 |
libmultipath \
|
|
|
d88bf6 |
libmultipath/prioritizers \
|
|
|
d88bf6 |
libmultipath/checkers \
|
|
|
d88bf6 |
Index: multipath-tools-130222/Makefile.inc
|
|
|
d88bf6 |
===================================================================
|
|
|
d88bf6 |
--- multipath-tools-130222.orig/Makefile.inc
|
|
|
d88bf6 |
+++ multipath-tools-130222/Makefile.inc
|
|
|
d88bf6 |
@@ -34,6 +34,8 @@ syslibdir = $(prefix)/usr/$(LIB)
|
|
|
d88bf6 |
libdir = $(prefix)/usr/$(LIB)/multipath
|
|
|
d88bf6 |
unitdir = $(prefix)/lib/systemd/system
|
|
|
d88bf6 |
mpathpersistdir = $(TOPDIR)/libmpathpersist
|
|
|
d88bf6 |
+includedir = $(prefix)/usr/include
|
|
|
d88bf6 |
+mpathcmddir = $(TOPDIR)/libmpathcmd
|
|
|
d88bf6 |
|
|
|
d88bf6 |
GZIP = /bin/gzip -9 -c
|
|
|
d88bf6 |
INSTALL_PROGRAM = install
|
|
|
d88bf6 |
Index: multipath-tools-130222/libmpathcmd/Makefile
|
|
|
d88bf6 |
===================================================================
|
|
|
d88bf6 |
--- /dev/null
|
|
|
d88bf6 |
+++ multipath-tools-130222/libmpathcmd/Makefile
|
|
|
d88bf6 |
@@ -0,0 +1,32 @@
|
|
|
d88bf6 |
+# Makefile
|
|
|
d88bf6 |
+#
|
|
|
d88bf6 |
+include ../Makefile.inc
|
|
|
d88bf6 |
+
|
|
|
d88bf6 |
+SONAME=0
|
|
|
d88bf6 |
+DEVLIB = libmpathcmd.so
|
|
|
d88bf6 |
+LIBS = $(DEVLIB).$(SONAME)
|
|
|
d88bf6 |
+
|
|
|
d88bf6 |
+CFLAGS += -fPIC
|
|
|
d88bf6 |
+
|
|
|
d88bf6 |
+OBJS = mpath_cmd.o
|
|
|
d88bf6 |
+
|
|
|
d88bf6 |
+all: $(LIBS)
|
|
|
d88bf6 |
+
|
|
|
d88bf6 |
+$(LIBS): $(OBJS)
|
|
|
d88bf6 |
+ $(CC) $(LDFLAGS) $(SHARED_FLAGS) -Wl,-soname=$@ $(CFLAGS) -o $@ $(OBJS) $(LIBDEPS)
|
|
|
d88bf6 |
+ ln -sf $@ $(DEVLIB)
|
|
|
d88bf6 |
+
|
|
|
d88bf6 |
+install: $(LIBS)
|
|
|
d88bf6 |
+ $(INSTALL_PROGRAM) -d $(DESTDIR)$(syslibdir)
|
|
|
d88bf6 |
+ $(INSTALL_PROGRAM) -m 755 $(LIBS) $(DESTDIR)$(syslibdir)/$(LIBS)
|
|
|
d88bf6 |
+ ln -sf $(LIBS) $(DESTDIR)$(syslibdir)/$(DEVLIB)
|
|
|
d88bf6 |
+ $(INSTALL_PROGRAM) -d $(DESTDIR)$(includedir)
|
|
|
d88bf6 |
+ $(INSTALL_PROGRAM) -m 644 mpath_cmd.h $(DESTDIR)$(includedir)
|
|
|
d88bf6 |
+
|
|
|
d88bf6 |
+uninstall:
|
|
|
d88bf6 |
+ rm -f $(DESTDIR)$(syslibdir)/$(LIBS)
|
|
|
d88bf6 |
+ rm -f $(DESTDIR)$(syslibdir)/$(DEVLIB)
|
|
|
d88bf6 |
+ rm -f $(DESTDIR)$(includedir)/mpath_cmd.h
|
|
|
d88bf6 |
+
|
|
|
d88bf6 |
+clean:
|
|
|
d88bf6 |
+ rm -f core *.a *.o *.gz *.so *.so.*
|
|
|
d88bf6 |
Index: multipath-tools-130222/libmpathcmd/mpath_cmd.c
|
|
|
d88bf6 |
===================================================================
|
|
|
d88bf6 |
--- /dev/null
|
|
|
d88bf6 |
+++ multipath-tools-130222/libmpathcmd/mpath_cmd.c
|
|
|
d88bf6 |
@@ -0,0 +1,178 @@
|
|
|
d88bf6 |
+#include <stdlib.h>
|
|
|
d88bf6 |
+#include <unistd.h>
|
|
|
d88bf6 |
+#include <stdio.h>
|
|
|
d88bf6 |
+#include <sys/types.h>
|
|
|
d88bf6 |
+#include <sys/socket.h>
|
|
|
d88bf6 |
+#include <sys/un.h>
|
|
|
d88bf6 |
+#include <poll.h>
|
|
|
d88bf6 |
+#include <string.h>
|
|
|
d88bf6 |
+#include <errno.h>
|
|
|
d88bf6 |
+
|
|
|
d88bf6 |
+#include "mpath_cmd.h"
|
|
|
d88bf6 |
+
|
|
|
d88bf6 |
+/*
|
|
|
d88bf6 |
+ * keep reading until its all read
|
|
|
d88bf6 |
+ */
|
|
|
d88bf6 |
+static ssize_t read_all(int fd, void *buf, size_t len, unsigned int timeout)
|
|
|
d88bf6 |
+{
|
|
|
d88bf6 |
+ size_t total = 0;
|
|
|
d88bf6 |
+ ssize_t n;
|
|
|
d88bf6 |
+ int ret;
|
|
|
d88bf6 |
+ struct pollfd pfd;
|
|
|
d88bf6 |
+
|
|
|
d88bf6 |
+ while (len) {
|
|
|
d88bf6 |
+ pfd.fd = fd;
|
|
|
d88bf6 |
+ pfd.events = POLLIN;
|
|
|
d88bf6 |
+ ret = poll(&pfd, 1, timeout);
|
|
|
d88bf6 |
+ if (!ret) {
|
|
|
d88bf6 |
+ errno = ETIMEDOUT;
|
|
|
d88bf6 |
+ return -1;
|
|
|
d88bf6 |
+ } else if (ret < 0) {
|
|
|
d88bf6 |
+ if (errno == EINTR)
|
|
|
d88bf6 |
+ continue;
|
|
|
d88bf6 |
+ return -1;
|
|
|
d88bf6 |
+ } else if (!(pfd.revents & POLLIN))
|
|
|
d88bf6 |
+ continue;
|
|
|
d88bf6 |
+ n = read(fd, buf, len);
|
|
|
d88bf6 |
+ if (n < 0) {
|
|
|
d88bf6 |
+ if ((errno == EINTR) || (errno == EAGAIN))
|
|
|
d88bf6 |
+ continue;
|
|
|
d88bf6 |
+ return -1;
|
|
|
d88bf6 |
+ }
|
|
|
d88bf6 |
+ if (!n)
|
|
|
d88bf6 |
+ return total;
|
|
|
d88bf6 |
+ buf = n + (char *)buf;
|
|
|
d88bf6 |
+ len -= n;
|
|
|
d88bf6 |
+ total += n;
|
|
|
d88bf6 |
+ }
|
|
|
d88bf6 |
+ return total;
|
|
|
d88bf6 |
+}
|
|
|
d88bf6 |
+
|
|
|
d88bf6 |
+/*
|
|
|
d88bf6 |
+ * keep writing until it's all sent
|
|
|
d88bf6 |
+ */
|
|
|
d88bf6 |
+static size_t write_all(int fd, const void *buf, size_t len)
|
|
|
d88bf6 |
+{
|
|
|
d88bf6 |
+ size_t total = 0;
|
|
|
d88bf6 |
+
|
|
|
d88bf6 |
+ while (len) {
|
|
|
d88bf6 |
+ ssize_t n = write(fd, buf, len);
|
|
|
d88bf6 |
+ if (n < 0) {
|
|
|
d88bf6 |
+ if ((errno == EINTR) || (errno == EAGAIN))
|
|
|
d88bf6 |
+ continue;
|
|
|
d88bf6 |
+ return total;
|
|
|
d88bf6 |
+ }
|
|
|
d88bf6 |
+ if (!n)
|
|
|
d88bf6 |
+ return total;
|
|
|
d88bf6 |
+ buf = n + (char *)buf;
|
|
|
d88bf6 |
+ len -= n;
|
|
|
d88bf6 |
+ total += n;
|
|
|
d88bf6 |
+ }
|
|
|
d88bf6 |
+ return total;
|
|
|
d88bf6 |
+}
|
|
|
d88bf6 |
+
|
|
|
d88bf6 |
+/*
|
|
|
d88bf6 |
+ * connect to a unix domain socket
|
|
|
d88bf6 |
+ */
|
|
|
d88bf6 |
+int mpath_connect(void)
|
|
|
d88bf6 |
+{
|
|
|
d88bf6 |
+ int fd, len;
|
|
|
d88bf6 |
+ struct sockaddr_un addr;
|
|
|
d88bf6 |
+
|
|
|
d88bf6 |
+ memset(&addr, 0, sizeof(addr));
|
|
|
d88bf6 |
+ addr.sun_family = AF_LOCAL;
|
|
|
d88bf6 |
+ addr.sun_path[0] = '\0';
|
|
|
d88bf6 |
+ len = strlen(DEFAULT_SOCKET) + 1 + sizeof(sa_family_t);
|
|
|
d88bf6 |
+ strncpy(&addr.sun_path[1], DEFAULT_SOCKET, len);
|
|
|
d88bf6 |
+
|
|
|
d88bf6 |
+ fd = socket(AF_LOCAL, SOCK_STREAM, 0);
|
|
|
d88bf6 |
+ if (fd == -1)
|
|
|
d88bf6 |
+ return -1;
|
|
|
d88bf6 |
+
|
|
|
d88bf6 |
+ if (connect(fd, (struct sockaddr *)&addr, len) == -1) {
|
|
|
d88bf6 |
+ close(fd);
|
|
|
d88bf6 |
+ return -1;
|
|
|
d88bf6 |
+ }
|
|
|
d88bf6 |
+
|
|
|
d88bf6 |
+ return fd;
|
|
|
d88bf6 |
+}
|
|
|
d88bf6 |
+
|
|
|
d88bf6 |
+int mpath_disconnect(int fd)
|
|
|
d88bf6 |
+{
|
|
|
d88bf6 |
+ return close(fd);
|
|
|
d88bf6 |
+}
|
|
|
d88bf6 |
+
|
|
|
d88bf6 |
+ssize_t mpath_recv_reply_len(int fd, unsigned int timeout)
|
|
|
d88bf6 |
+{
|
|
|
d88bf6 |
+ size_t len;
|
|
|
d88bf6 |
+ ssize_t ret;
|
|
|
d88bf6 |
+
|
|
|
d88bf6 |
+ ret = read_all(fd, &len, sizeof(len), timeout);
|
|
|
d88bf6 |
+ if (ret < 0)
|
|
|
d88bf6 |
+ return ret;
|
|
|
d88bf6 |
+ if (ret != sizeof(len)) {
|
|
|
d88bf6 |
+ errno = EIO;
|
|
|
d88bf6 |
+ return -1;
|
|
|
d88bf6 |
+ }
|
|
|
d88bf6 |
+ return len;
|
|
|
d88bf6 |
+}
|
|
|
d88bf6 |
+
|
|
|
d88bf6 |
+int mpath_recv_reply_data(int fd, char *reply, size_t len,
|
|
|
d88bf6 |
+ unsigned int timeout)
|
|
|
d88bf6 |
+{
|
|
|
d88bf6 |
+ ssize_t ret;
|
|
|
d88bf6 |
+
|
|
|
d88bf6 |
+ ret = read_all(fd, reply, len, timeout);
|
|
|
d88bf6 |
+ if (ret < 0)
|
|
|
d88bf6 |
+ return ret;
|
|
|
d88bf6 |
+ if (ret != len) {
|
|
|
d88bf6 |
+ errno = EIO;
|
|
|
d88bf6 |
+ return -1;
|
|
|
d88bf6 |
+ }
|
|
|
d88bf6 |
+ reply[len - 1] = '\0';
|
|
|
d88bf6 |
+ return 0;
|
|
|
d88bf6 |
+}
|
|
|
d88bf6 |
+
|
|
|
d88bf6 |
+int mpath_recv_reply(int fd, char **reply, unsigned int timeout)
|
|
|
d88bf6 |
+{
|
|
|
d88bf6 |
+ int err;
|
|
|
d88bf6 |
+ ssize_t len;
|
|
|
d88bf6 |
+
|
|
|
d88bf6 |
+ *reply = NULL;
|
|
|
d88bf6 |
+ len = mpath_recv_reply_len(fd, timeout);
|
|
|
d88bf6 |
+ if (len <= 0)
|
|
|
d88bf6 |
+ return -1;
|
|
|
d88bf6 |
+ *reply = malloc(len);
|
|
|
d88bf6 |
+ if (!*reply)
|
|
|
d88bf6 |
+ return -1;
|
|
|
d88bf6 |
+ err = mpath_recv_reply_data(fd, *reply, len, timeout);
|
|
|
d88bf6 |
+ if (err) {
|
|
|
d88bf6 |
+ free(*reply);
|
|
|
d88bf6 |
+ *reply = NULL;
|
|
|
d88bf6 |
+ return -1;
|
|
|
d88bf6 |
+ }
|
|
|
d88bf6 |
+ return 0;
|
|
|
d88bf6 |
+}
|
|
|
d88bf6 |
+
|
|
|
d88bf6 |
+int mpath_send_cmd(int fd, const char *cmd)
|
|
|
d88bf6 |
+{
|
|
|
d88bf6 |
+ size_t len;
|
|
|
d88bf6 |
+
|
|
|
d88bf6 |
+ if (cmd != NULL)
|
|
|
d88bf6 |
+ len = strlen(cmd) + 1;
|
|
|
d88bf6 |
+ else
|
|
|
d88bf6 |
+ len = 0;
|
|
|
d88bf6 |
+ if (write_all(fd, &len, sizeof(len)) != sizeof(len))
|
|
|
d88bf6 |
+ return -1;
|
|
|
d88bf6 |
+ if (len && write_all(fd, cmd, len) != len)
|
|
|
d88bf6 |
+ return -1;
|
|
|
d88bf6 |
+ return 0;
|
|
|
d88bf6 |
+}
|
|
|
d88bf6 |
+
|
|
|
d88bf6 |
+int mpath_process_cmd(int fd, const char *cmd, char **reply,
|
|
|
d88bf6 |
+ unsigned int timeout)
|
|
|
d88bf6 |
+{
|
|
|
d88bf6 |
+ if (mpath_send_cmd(fd, cmd) != 0)
|
|
|
d88bf6 |
+ return -1;
|
|
|
d88bf6 |
+ return mpath_recv_reply(fd, reply, timeout);
|
|
|
d88bf6 |
+}
|
|
|
d88bf6 |
Index: multipath-tools-130222/libmpathcmd/mpath_cmd.h
|
|
|
d88bf6 |
===================================================================
|
|
|
d88bf6 |
--- /dev/null
|
|
|
d88bf6 |
+++ multipath-tools-130222/libmpathcmd/mpath_cmd.h
|
|
|
d88bf6 |
@@ -0,0 +1,125 @@
|
|
|
d88bf6 |
+/*
|
|
|
d88bf6 |
+ * Copyright (C) 2015 Red Hat, Inc.
|
|
|
d88bf6 |
+ *
|
|
|
d88bf6 |
+ * This file is part of the device-mapper multipath userspace tools.
|
|
|
d88bf6 |
+ *
|
|
|
d88bf6 |
+ * This program is free software; you can redistribute it and/or
|
|
|
d88bf6 |
+ * modify it under the terms of the GNU Lesser General Public License
|
|
|
d88bf6 |
+ * as published by the Free Software Foundation; either version 2
|
|
|
d88bf6 |
+ * of the License, or (at your option) any later version.
|
|
|
d88bf6 |
+ *
|
|
|
d88bf6 |
+ * This program is distributed in the hope that it will be useful,
|
|
|
d88bf6 |
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
d88bf6 |
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
d88bf6 |
+ * GNU Lesser General Public License for more details.
|
|
|
d88bf6 |
+ *
|
|
|
d88bf6 |
+ * You should have received a copy of the GNU Lesser General Public
|
|
|
d88bf6 |
+ * License along with this program; if not, write to the Free Software
|
|
|
d88bf6 |
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
|
|
d88bf6 |
+ * USA.
|
|
|
d88bf6 |
+ */
|
|
|
d88bf6 |
+
|
|
|
d88bf6 |
+#ifndef LIB_MPATH_CMD_H
|
|
|
d88bf6 |
+#define LIB_MPATH_CMD_H
|
|
|
d88bf6 |
+
|
|
|
d88bf6 |
+#ifdef __cpluscplus
|
|
|
d88bf6 |
+extern "C" {
|
|
|
d88bf6 |
+#endif
|
|
|
d88bf6 |
+
|
|
|
d88bf6 |
+#define DEFAULT_SOCKET "/org/kernel/linux/storage/multipathd"
|
|
|
d88bf6 |
+#define DEFAULT_REPLY_TIMEOUT 10000
|
|
|
d88bf6 |
+
|
|
|
d88bf6 |
+
|
|
|
d88bf6 |
+/*
|
|
|
d88bf6 |
+ * DESCRIPTION:
|
|
|
d88bf6 |
+ * Connect to the running multipathd daemon. On systems with the
|
|
|
d88bf6 |
+ * multipathd.socket systemd unit file installed, this command will
|
|
|
d88bf6 |
+ * start multipathd if it is not already running. This function
|
|
|
d88bf6 |
+ * must be run before any of the others in this library
|
|
|
d88bf6 |
+ *
|
|
|
d88bf6 |
+ * RETURNS:
|
|
|
d88bf6 |
+ * A file descriptor on success. -1 on failure (with errno set).
|
|
|
d88bf6 |
+ */
|
|
|
d88bf6 |
+int mpath_connect(void);
|
|
|
d88bf6 |
+
|
|
|
d88bf6 |
+
|
|
|
d88bf6 |
+/*
|
|
|
d88bf6 |
+ * DESCRIPTION:
|
|
|
d88bf6 |
+ * Disconnect from the multipathd daemon. This function must be
|
|
|
d88bf6 |
+ * run after after processing all the multipath commands.
|
|
|
d88bf6 |
+ *
|
|
|
d88bf6 |
+ * RETURNS:
|
|
|
d88bf6 |
+ * 0 on success. -1 on failure (with errno set).
|
|
|
d88bf6 |
+ */
|
|
|
d88bf6 |
+int mpath_disconnect(int fd);
|
|
|
d88bf6 |
+
|
|
|
d88bf6 |
+
|
|
|
d88bf6 |
+/*
|
|
|
d88bf6 |
+ * DESCRIPTION
|
|
|
d88bf6 |
+ * Send multipathd a command and return the reply. This function
|
|
|
d88bf6 |
+ * does the same as calling mpath_send_cmd() and then
|
|
|
d88bf6 |
+ * mpath_recv_reply()
|
|
|
d88bf6 |
+ *
|
|
|
d88bf6 |
+ * RETURNS:
|
|
|
d88bf6 |
+ * 0 on successs, and reply will either be NULL (if there was no
|
|
|
d88bf6 |
+ * reply data), or point to the reply string, which must be freed by
|
|
|
d88bf6 |
+ * the caller. -1 on failure (with errno set).
|
|
|
d88bf6 |
+ */
|
|
|
d88bf6 |
+int mpath_process_cmd(int fd, const char *cmd, char **reply,
|
|
|
d88bf6 |
+ unsigned int timeout);
|
|
|
d88bf6 |
+
|
|
|
d88bf6 |
+
|
|
|
d88bf6 |
+/*
|
|
|
d88bf6 |
+ * DESCRIPTION:
|
|
|
d88bf6 |
+ * Send a command to multipathd
|
|
|
d88bf6 |
+ *
|
|
|
d88bf6 |
+ * RETURNS:
|
|
|
d88bf6 |
+ * 0 on success. -1 on failure (with errno set)
|
|
|
d88bf6 |
+ */
|
|
|
d88bf6 |
+int mpath_send_cmd(int fd, const char *cmd);
|
|
|
d88bf6 |
+
|
|
|
d88bf6 |
+
|
|
|
d88bf6 |
+/*
|
|
|
d88bf6 |
+ * DESCRIPTION:
|
|
|
d88bf6 |
+ * Return a reply from multipathd for a previously sent command.
|
|
|
d88bf6 |
+ * This is equivalent to calling mpath_recv_reply_len(), allocating
|
|
|
d88bf6 |
+ * a buffer of the appropriate size, and then calling
|
|
|
d88bf6 |
+ * mpath_recv_reply_data() with that buffer.
|
|
|
d88bf6 |
+ *
|
|
|
d88bf6 |
+ * RETURNS:
|
|
|
d88bf6 |
+ * 0 on success, and reply will either be NULL (if there was no
|
|
|
d88bf6 |
+ * reply data), or point to the reply string, which must be freed by
|
|
|
d88bf6 |
+ * the caller, -1 on failure (with errno set).
|
|
|
d88bf6 |
+ */
|
|
|
d88bf6 |
+int mpath_recv_reply(int fd, char **reply, unsigned int timeout);
|
|
|
d88bf6 |
+
|
|
|
d88bf6 |
+
|
|
|
d88bf6 |
+/*
|
|
|
d88bf6 |
+ * DESCRIPTION:
|
|
|
d88bf6 |
+ * Return the size of the upcoming reply data from the sent multipath
|
|
|
d88bf6 |
+ * command. This must be called before calling mpath_recv_reply_data().
|
|
|
d88bf6 |
+ *
|
|
|
d88bf6 |
+ * RETURNS:
|
|
|
d88bf6 |
+ * The required size of the reply data buffer on success. -1 on
|
|
|
d88bf6 |
+ * failure (with errno set).
|
|
|
d88bf6 |
+ */
|
|
|
d88bf6 |
+ssize_t mpath_recv_reply_len(int fd, unsigned int timeout);
|
|
|
d88bf6 |
+
|
|
|
d88bf6 |
+
|
|
|
d88bf6 |
+/*
|
|
|
d88bf6 |
+ * DESCRIPTION:
|
|
|
d88bf6 |
+ * Return the reply data from the sent multipath command.
|
|
|
d88bf6 |
+ * mpath_recv_reply_len must be called first. reply must point to a
|
|
|
d88bf6 |
+ * buffer of len size.
|
|
|
d88bf6 |
+ *
|
|
|
d88bf6 |
+ * RETURNS:
|
|
|
d88bf6 |
+ * 0 on success, and reply will contain the reply data string. -1
|
|
|
d88bf6 |
+ * on failure (with errno set).
|
|
|
d88bf6 |
+ */
|
|
|
d88bf6 |
+int mpath_recv_reply_data(int fd, char *reply, size_t len,
|
|
|
d88bf6 |
+ unsigned int timeout);
|
|
|
d88bf6 |
+
|
|
|
d88bf6 |
+#ifdef __cplusplus
|
|
|
d88bf6 |
+}
|
|
|
d88bf6 |
+#endif
|
|
|
d88bf6 |
+#endif /* LIB_MPATH_CMD_H */
|
|
|
d88bf6 |
Index: multipath-tools-130222/libmpathpersist/Makefile
|
|
|
d88bf6 |
===================================================================
|
|
|
d88bf6 |
--- multipath-tools-130222.orig/libmpathpersist/Makefile
|
|
|
d88bf6 |
+++ multipath-tools-130222/libmpathpersist/Makefile
|
|
|
d88bf6 |
@@ -10,8 +10,9 @@ DEVLIB = libmpathpersist.so
|
|
|
d88bf6 |
LIBS = $(DEVLIB).$(SONAME)
|
|
|
d88bf6 |
|
|
|
d88bf6 |
|
|
|
d88bf6 |
-CFLAGS += -fPIC -I$(multipathdir) -I$(mpathpersistdir)
|
|
|
d88bf6 |
-LIBDEPS += -lpthread -ldevmapper -ldl -L$(multipathdir) -lmultipath
|
|
|
d88bf6 |
+CFLAGS += -fPIC -I$(multipathdir) -I$(mpathpersistdir) -I$(mpathcmddir)
|
|
|
d88bf6 |
+LIBDEPS += -lpthread -ldevmapper -ldl -L$(multipathdir) -lmultipath \
|
|
|
d88bf6 |
+ -L$(mpathcmddir) -lmpathcmd
|
|
|
d88bf6 |
|
|
|
d88bf6 |
OBJS = mpath_persist.o mpath_updatepr.o mpath_pr_ioctl.o
|
|
|
d88bf6 |
|
|
|
d88bf6 |
Index: multipath-tools-130222/libmpathpersist/mpath_updatepr.c
|
|
|
d88bf6 |
===================================================================
|
|
|
d88bf6 |
--- multipath-tools-130222.orig/libmpathpersist/mpath_updatepr.c
|
|
|
d88bf6 |
+++ multipath-tools-130222/libmpathpersist/mpath_updatepr.c
|
|
|
d88bf6 |
@@ -12,9 +12,9 @@
|
|
|
d88bf6 |
#include <sys/poll.h>
|
|
|
d88bf6 |
#include <errno.h>
|
|
|
d88bf6 |
#include <debug.h>
|
|
|
d88bf6 |
+#include <mpath_cmd.h>
|
|
|
d88bf6 |
+#include <uxsock.h>
|
|
|
d88bf6 |
#include "memory.h"
|
|
|
d88bf6 |
-#include "../libmultipath/uxsock.h"
|
|
|
d88bf6 |
-#include "../libmultipath/defaults.h"
|
|
|
d88bf6 |
|
|
|
d88bf6 |
unsigned long mem_allocated; /* Total memory used in Bytes */
|
|
|
d88bf6 |
|
|
|
d88bf6 |
@@ -23,10 +23,9 @@ int update_prflag(char * arg1, char * ar
|
|
|
d88bf6 |
int fd;
|
|
|
d88bf6 |
char str[64];
|
|
|
d88bf6 |
char *reply;
|
|
|
d88bf6 |
- size_t len;
|
|
|
d88bf6 |
int ret = 0;
|
|
|
d88bf6 |
|
|
|
d88bf6 |
- fd = ux_socket_connect(DEFAULT_SOCKET);
|
|
|
d88bf6 |
+ fd = mpath_connect();
|
|
|
d88bf6 |
if (fd == -1) {
|
|
|
d88bf6 |
condlog (0, "ux socket connect error");
|
|
|
d88bf6 |
return 1 ;
|
|
|
d88bf6 |
@@ -34,18 +33,23 @@ int update_prflag(char * arg1, char * ar
|
|
|
d88bf6 |
|
|
|
d88bf6 |
snprintf(str,sizeof(str),"map %s %s", arg1, arg2);
|
|
|
d88bf6 |
condlog (2, "%s: pr flag message=%s", arg1, str);
|
|
|
d88bf6 |
- send_packet(fd, str, strlen(str) + 1);
|
|
|
d88bf6 |
- recv_packet(fd, &reply, &len;;
|
|
|
d88bf6 |
-
|
|
|
d88bf6 |
- condlog (2, "%s: message=%s reply=%s", arg1, str, reply);
|
|
|
d88bf6 |
- if (!reply || strncmp(reply,"ok", 2) == 0)
|
|
|
d88bf6 |
- ret = -1;
|
|
|
d88bf6 |
- else if (strncmp(reply, "fail", 4) == 0)
|
|
|
d88bf6 |
+ send_packet(fd, str);
|
|
|
d88bf6 |
+ ret = recv_packet(fd, &reply);
|
|
|
d88bf6 |
+ if (ret < 0) {
|
|
|
d88bf6 |
+ condlog(2, "%s: message=%s recv error=%d", arg1, str, errno);
|
|
|
d88bf6 |
ret = -2;
|
|
|
d88bf6 |
- else{
|
|
|
d88bf6 |
- ret = atoi(reply);
|
|
|
d88bf6 |
+ } else {
|
|
|
d88bf6 |
+ condlog (2, "%s: message=%s reply=%s", arg1, str, reply);
|
|
|
d88bf6 |
+ if (!reply || strncmp(reply,"ok", 2) == 0)
|
|
|
d88bf6 |
+ ret = -1;
|
|
|
d88bf6 |
+ else if (strncmp(reply, "fail", 4) == 0)
|
|
|
d88bf6 |
+ ret = -2;
|
|
|
d88bf6 |
+ else{
|
|
|
d88bf6 |
+ ret = atoi(reply);
|
|
|
d88bf6 |
+ }
|
|
|
d88bf6 |
}
|
|
|
d88bf6 |
|
|
|
d88bf6 |
free(reply);
|
|
|
d88bf6 |
+ mpath_disconnect(fd);
|
|
|
d88bf6 |
return ret;
|
|
|
d88bf6 |
}
|
|
|
d88bf6 |
Index: multipath-tools-130222/libmultipath/Makefile
|
|
|
d88bf6 |
===================================================================
|
|
|
d88bf6 |
--- multipath-tools-130222.orig/libmultipath/Makefile
|
|
|
d88bf6 |
+++ multipath-tools-130222/libmultipath/Makefile
|
|
|
d88bf6 |
@@ -7,8 +7,8 @@ include ../Makefile.inc
|
|
|
d88bf6 |
SONAME=0
|
|
|
d88bf6 |
DEVLIB = libmultipath.so
|
|
|
d88bf6 |
LIBS = $(DEVLIB).$(SONAME)
|
|
|
d88bf6 |
-LIBDEPS = -lpthread -ldl -ldevmapper -ludev
|
|
|
d88bf6 |
-CFLAGS += -fPIC
|
|
|
d88bf6 |
+LIBDEPS = -lpthread -ldl -ldevmapper -ludev -L$(mpathcmddir) -lmpathcmd
|
|
|
d88bf6 |
+CFLAGS += -fPIC -I$(mpathcmddir)
|
|
|
d88bf6 |
|
|
|
d88bf6 |
OBJS = memory.o parser.o vector.o devmapper.o \
|
|
|
d88bf6 |
hwtable.o blacklist.o util.o dmparser.o config.o \
|
|
|
d88bf6 |
Index: multipath-tools-130222/libmultipath/config.c
|
|
|
d88bf6 |
===================================================================
|
|
|
d88bf6 |
--- multipath-tools-130222.orig/libmultipath/config.c
|
|
|
d88bf6 |
+++ multipath-tools-130222/libmultipath/config.c
|
|
|
d88bf6 |
@@ -25,6 +25,7 @@
|
|
|
d88bf6 |
#include "prio.h"
|
|
|
d88bf6 |
#include "devmapper.h"
|
|
|
d88bf6 |
#include "version.h"
|
|
|
d88bf6 |
+#include "mpath_cmd.h"
|
|
|
d88bf6 |
|
|
|
d88bf6 |
static int
|
|
|
d88bf6 |
hwe_strmatch (struct hwentry *hwe1, struct hwentry *hwe2)
|
|
|
d88bf6 |
Index: multipath-tools-130222/libmultipath/configure.c
|
|
|
d88bf6 |
===================================================================
|
|
|
d88bf6 |
--- multipath-tools-130222.orig/libmultipath/configure.c
|
|
|
d88bf6 |
+++ multipath-tools-130222/libmultipath/configure.c
|
|
|
d88bf6 |
@@ -14,6 +14,7 @@
|
|
|
d88bf6 |
#include <errno.h>
|
|
|
d88bf6 |
#include <libdevmapper.h>
|
|
|
d88bf6 |
#include <libudev.h>
|
|
|
d88bf6 |
+#include <mpath_cmd.h>
|
|
|
d88bf6 |
|
|
|
d88bf6 |
#include "checkers.h"
|
|
|
d88bf6 |
#include "vector.h"
|
|
|
d88bf6 |
@@ -752,16 +753,15 @@ check_daemon(void)
|
|
|
d88bf6 |
{
|
|
|
d88bf6 |
int fd;
|
|
|
d88bf6 |
char *reply;
|
|
|
d88bf6 |
- size_t len;
|
|
|
d88bf6 |
int ret = 0;
|
|
|
d88bf6 |
|
|
|
d88bf6 |
- fd = ux_socket_connect(DEFAULT_SOCKET);
|
|
|
d88bf6 |
+ fd = mpath_connect();
|
|
|
d88bf6 |
if (fd == -1)
|
|
|
d88bf6 |
return 0;
|
|
|
d88bf6 |
|
|
|
d88bf6 |
- if (send_packet(fd, "show daemon", 12) != 0)
|
|
|
d88bf6 |
+ if (send_packet(fd, "show daemon") != 0)
|
|
|
d88bf6 |
goto out;
|
|
|
d88bf6 |
- if (recv_packet(fd, &reply, &len) != 0)
|
|
|
d88bf6 |
+ if (recv_packet(fd, &reply) != 0)
|
|
|
d88bf6 |
goto out;
|
|
|
d88bf6 |
|
|
|
d88bf6 |
if (strstr(reply, "shutdown"))
|
|
|
d88bf6 |
@@ -772,7 +772,7 @@ check_daemon(void)
|
|
|
d88bf6 |
out_free:
|
|
|
d88bf6 |
FREE(reply);
|
|
|
d88bf6 |
out:
|
|
|
d88bf6 |
- close(fd);
|
|
|
d88bf6 |
+ mpath_disconnect(fd);
|
|
|
d88bf6 |
return ret;
|
|
|
d88bf6 |
}
|
|
|
d88bf6 |
|
|
|
d88bf6 |
Index: multipath-tools-130222/libmultipath/uxsock.c
|
|
|
d88bf6 |
===================================================================
|
|
|
d88bf6 |
--- multipath-tools-130222.orig/libmultipath/uxsock.c
|
|
|
d88bf6 |
+++ multipath-tools-130222/libmultipath/uxsock.c
|
|
|
d88bf6 |
@@ -16,37 +16,10 @@
|
|
|
d88bf6 |
#include <sys/poll.h>
|
|
|
d88bf6 |
#include <signal.h>
|
|
|
d88bf6 |
#include <errno.h>
|
|
|
d88bf6 |
+#include <mpath_cmd.h>
|
|
|
d88bf6 |
|
|
|
d88bf6 |
#include "memory.h"
|
|
|
d88bf6 |
#include "uxsock.h"
|
|
|
d88bf6 |
-
|
|
|
d88bf6 |
-/*
|
|
|
d88bf6 |
- * connect to a unix domain socket
|
|
|
d88bf6 |
- */
|
|
|
d88bf6 |
-int ux_socket_connect(const char *name)
|
|
|
d88bf6 |
-{
|
|
|
d88bf6 |
- int fd, len;
|
|
|
d88bf6 |
- struct sockaddr_un addr;
|
|
|
d88bf6 |
-
|
|
|
d88bf6 |
- memset(&addr, 0, sizeof(addr));
|
|
|
d88bf6 |
- addr.sun_family = AF_LOCAL;
|
|
|
d88bf6 |
- addr.sun_path[0] = '\0';
|
|
|
d88bf6 |
- len = strlen(name) + 1 + sizeof(sa_family_t);
|
|
|
d88bf6 |
- strncpy(&addr.sun_path[1], name, len);
|
|
|
d88bf6 |
-
|
|
|
d88bf6 |
- fd = socket(AF_LOCAL, SOCK_STREAM, 0);
|
|
|
d88bf6 |
- if (fd == -1) {
|
|
|
d88bf6 |
- return -1;
|
|
|
d88bf6 |
- }
|
|
|
d88bf6 |
-
|
|
|
d88bf6 |
- if (connect(fd, (struct sockaddr *)&addr, len) == -1) {
|
|
|
d88bf6 |
- close(fd);
|
|
|
d88bf6 |
- return -1;
|
|
|
d88bf6 |
- }
|
|
|
d88bf6 |
-
|
|
|
d88bf6 |
- return fd;
|
|
|
d88bf6 |
-}
|
|
|
d88bf6 |
-
|
|
|
d88bf6 |
/*
|
|
|
d88bf6 |
* create a unix domain socket and start listening on it
|
|
|
d88bf6 |
* return a file descriptor open on the socket
|
|
|
d88bf6 |
@@ -102,32 +75,9 @@ size_t write_all(int fd, const void *buf
|
|
|
d88bf6 |
}
|
|
|
d88bf6 |
|
|
|
d88bf6 |
/*
|
|
|
d88bf6 |
- * keep reading until its all read
|
|
|
d88bf6 |
- */
|
|
|
d88bf6 |
-size_t read_all(int fd, void *buf, size_t len)
|
|
|
d88bf6 |
-{
|
|
|
d88bf6 |
- size_t total = 0;
|
|
|
d88bf6 |
-
|
|
|
d88bf6 |
- while (len) {
|
|
|
d88bf6 |
- ssize_t n = read(fd, buf, len);
|
|
|
d88bf6 |
- if (n < 0) {
|
|
|
d88bf6 |
- if ((errno == EINTR) || (errno == EAGAIN))
|
|
|
d88bf6 |
- continue;
|
|
|
d88bf6 |
- return total;
|
|
|
d88bf6 |
- }
|
|
|
d88bf6 |
- if (!n)
|
|
|
d88bf6 |
- return total;
|
|
|
d88bf6 |
- buf = n + (char *)buf;
|
|
|
d88bf6 |
- len -= n;
|
|
|
d88bf6 |
- total += n;
|
|
|
d88bf6 |
- }
|
|
|
d88bf6 |
- return total;
|
|
|
d88bf6 |
-}
|
|
|
d88bf6 |
-
|
|
|
d88bf6 |
-/*
|
|
|
d88bf6 |
* send a packet in length prefix format
|
|
|
d88bf6 |
*/
|
|
|
d88bf6 |
-int send_packet(int fd, const char *buf, size_t len)
|
|
|
d88bf6 |
+int send_packet(int fd, const char *buf)
|
|
|
d88bf6 |
{
|
|
|
d88bf6 |
int ret = 0;
|
|
|
d88bf6 |
sigset_t set, old;
|
|
|
d88bf6 |
@@ -137,10 +87,7 @@ int send_packet(int fd, const char *buf,
|
|
|
d88bf6 |
sigaddset(&set, SIGPIPE);
|
|
|
d88bf6 |
pthread_sigmask(SIG_BLOCK, &set, &old;;
|
|
|
d88bf6 |
|
|
|
d88bf6 |
- if (write_all(fd, &len, sizeof(len)) != sizeof(len))
|
|
|
d88bf6 |
- ret = -1;
|
|
|
d88bf6 |
- if (!ret && write_all(fd, buf, len) != len)
|
|
|
d88bf6 |
- ret = -1;
|
|
|
d88bf6 |
+ ret = mpath_send_cmd(fd, buf);
|
|
|
d88bf6 |
|
|
|
d88bf6 |
/* And unblock it again */
|
|
|
d88bf6 |
pthread_sigmask(SIG_SETMASK, &old, NULL);
|
|
|
d88bf6 |
@@ -151,25 +98,24 @@ int send_packet(int fd, const char *buf,
|
|
|
d88bf6 |
/*
|
|
|
d88bf6 |
* receive a packet in length prefix format
|
|
|
d88bf6 |
*/
|
|
|
d88bf6 |
-int recv_packet(int fd, char **buf, size_t *len)
|
|
|
d88bf6 |
+int recv_packet(int fd, char **buf)
|
|
|
d88bf6 |
{
|
|
|
d88bf6 |
- if (read_all(fd, len, sizeof(*len)) != sizeof(*len)) {
|
|
|
d88bf6 |
- (*buf) = NULL;
|
|
|
d88bf6 |
- *len = 0;
|
|
|
d88bf6 |
- return -1;
|
|
|
d88bf6 |
- }
|
|
|
d88bf6 |
- if (len == 0) {
|
|
|
d88bf6 |
- (*buf) = NULL;
|
|
|
d88bf6 |
- return 0;
|
|
|
d88bf6 |
- }
|
|
|
d88bf6 |
- (*buf) = MALLOC(*len);
|
|
|
d88bf6 |
+ int err;
|
|
|
d88bf6 |
+ ssize_t len;
|
|
|
d88bf6 |
+ unsigned int timeout = DEFAULT_REPLY_TIMEOUT;
|
|
|
d88bf6 |
+
|
|
|
d88bf6 |
+ *buf = NULL;
|
|
|
d88bf6 |
+ len = mpath_recv_reply_len(fd, timeout);
|
|
|
d88bf6 |
+ if (len <= 0)
|
|
|
d88bf6 |
+ return len;
|
|
|
d88bf6 |
+ (*buf) = MALLOC(len);
|
|
|
d88bf6 |
if (!*buf)
|
|
|
d88bf6 |
- return -1;
|
|
|
d88bf6 |
- if (read_all(fd, *buf, *len) != *len) {
|
|
|
d88bf6 |
+ return -ENOMEM;
|
|
|
d88bf6 |
+ err = mpath_recv_reply_data(fd, *buf, len, timeout);
|
|
|
d88bf6 |
+ if (err) {
|
|
|
d88bf6 |
FREE(*buf);
|
|
|
d88bf6 |
(*buf) = NULL;
|
|
|
d88bf6 |
- *len = 0;
|
|
|
d88bf6 |
- return -1;
|
|
|
d88bf6 |
+ return err;
|
|
|
d88bf6 |
}
|
|
|
d88bf6 |
return 0;
|
|
|
d88bf6 |
}
|
|
|
d88bf6 |
Index: multipath-tools-130222/libmultipath/uxsock.h
|
|
|
d88bf6 |
===================================================================
|
|
|
d88bf6 |
--- multipath-tools-130222.orig/libmultipath/uxsock.h
|
|
|
d88bf6 |
+++ multipath-tools-130222/libmultipath/uxsock.h
|
|
|
d88bf6 |
@@ -1,7 +1,5 @@
|
|
|
d88bf6 |
/* some prototypes */
|
|
|
d88bf6 |
-int ux_socket_connect(const char *name);
|
|
|
d88bf6 |
int ux_socket_listen(const char *name);
|
|
|
d88bf6 |
-int send_packet(int fd, const char *buf, size_t len);
|
|
|
d88bf6 |
-int recv_packet(int fd, char **buf, size_t *len);
|
|
|
d88bf6 |
+int send_packet(int fd, const char *buf);
|
|
|
d88bf6 |
+int recv_packet(int fd, char **buf);
|
|
|
d88bf6 |
size_t write_all(int fd, const void *buf, size_t len);
|
|
|
d88bf6 |
-size_t read_all(int fd, void *buf, size_t len);
|
|
|
d88bf6 |
Index: multipath-tools-130222/mpathpersist/Makefile
|
|
|
d88bf6 |
===================================================================
|
|
|
d88bf6 |
--- multipath-tools-130222.orig/mpathpersist/Makefile
|
|
|
d88bf6 |
+++ multipath-tools-130222/mpathpersist/Makefile
|
|
|
d88bf6 |
@@ -5,7 +5,7 @@ include ../Makefile.inc
|
|
|
d88bf6 |
OBJS = main.o
|
|
|
d88bf6 |
|
|
|
d88bf6 |
CFLAGS += -I$(multipathdir) -I$(mpathpersistdir)
|
|
|
d88bf6 |
-LDFLAGS += -lpthread -ldevmapper -L$(mpathpersistdir) -lmpathpersist -L$(multipathdir) -lmultipath -ludev
|
|
|
d88bf6 |
+LDFLAGS += -lpthread -ldevmapper -L$(mpathpersistdir) -lmpathpersist -L$(multipathdir) -L$(mpathcmddir) -lmpathcmd -lmultipath -ludev
|
|
|
d88bf6 |
|
|
|
d88bf6 |
EXEC = mpathpersist
|
|
|
d88bf6 |
|
|
|
d88bf6 |
Index: multipath-tools-130222/multipath/Makefile
|
|
|
d88bf6 |
===================================================================
|
|
|
d88bf6 |
--- multipath-tools-130222.orig/multipath/Makefile
|
|
|
d88bf6 |
+++ multipath-tools-130222/multipath/Makefile
|
|
|
d88bf6 |
@@ -6,8 +6,9 @@ include ../Makefile.inc
|
|
|
d88bf6 |
|
|
|
d88bf6 |
OBJS = main.o
|
|
|
d88bf6 |
|
|
|
d88bf6 |
-CFLAGS += -fPIC -I$(multipathdir)
|
|
|
d88bf6 |
-LDFLAGS += -lpthread -ldevmapper -ldl -L$(multipathdir) -lmultipath -ludev
|
|
|
d88bf6 |
+CFLAGS += -I$(multipathdir) -I$(mpathcmddir)
|
|
|
d88bf6 |
+LDFLAGS += -lpthread -ldevmapper -ldl -L$(multipathdir) -lmultipath -ludev \
|
|
|
d88bf6 |
+ -L$(mpathcmddir) -lmpathcmd
|
|
|
d88bf6 |
|
|
|
d88bf6 |
EXEC = multipath
|
|
|
d88bf6 |
|
|
|
d88bf6 |
Index: multipath-tools-130222/multipathd/Makefile
|
|
|
d88bf6 |
===================================================================
|
|
|
d88bf6 |
--- multipath-tools-130222.orig/multipathd/Makefile
|
|
|
d88bf6 |
+++ multipath-tools-130222/multipathd/Makefile
|
|
|
d88bf6 |
@@ -5,10 +5,10 @@ include ../Makefile.inc
|
|
|
d88bf6 |
#
|
|
|
d88bf6 |
# basic flags setting
|
|
|
d88bf6 |
#
|
|
|
d88bf6 |
-CFLAGS += -fPIE -DPIE -I$(multipathdir) -I$(mpathpersistdir)
|
|
|
d88bf6 |
+CFLAGS += -fPIE -DPIE -I$(multipathdir) -I$(mpathpersistdir) -I$(mpathcmddir)
|
|
|
d88bf6 |
LDFLAGS += -lpthread -ldevmapper -lreadline -ludev -ldl \
|
|
|
d88bf6 |
-L$(multipathdir) -lmultipath -L$(mpathpersistdir) -lmpathpersist \
|
|
|
d88bf6 |
- -Wl,-z,now -pie
|
|
|
d88bf6 |
+ -L$(mpathcmddir) -lmpathcmd -Wl,-z,now -pie
|
|
|
d88bf6 |
|
|
|
d88bf6 |
#
|
|
|
d88bf6 |
# debuging stuff
|
|
|
d88bf6 |
Index: multipath-tools-130222/multipathd/uxclnt.c
|
|
|
d88bf6 |
===================================================================
|
|
|
d88bf6 |
--- multipath-tools-130222.orig/multipathd/uxclnt.c
|
|
|
d88bf6 |
+++ multipath-tools-130222/multipathd/uxclnt.c
|
|
|
d88bf6 |
@@ -17,6 +17,7 @@
|
|
|
d88bf6 |
#include <readline/readline.h>
|
|
|
d88bf6 |
#include <readline/history.h>
|
|
|
d88bf6 |
|
|
|
d88bf6 |
+#include <mpath_cmd.h>
|
|
|
d88bf6 |
#include <uxsock.h>
|
|
|
d88bf6 |
#include <memory.h>
|
|
|
d88bf6 |
#include <defaults.h>
|
|
|
d88bf6 |
@@ -49,7 +50,6 @@ static void process(int fd)
|
|
|
d88bf6 |
rl_readline_name = "multipathd";
|
|
|
d88bf6 |
rl_completion_entry_function = key_generator;
|
|
|
d88bf6 |
while ((line = readline("multipathd> "))) {
|
|
|
d88bf6 |
- size_t len;
|
|
|
d88bf6 |
size_t llen = strlen(line);
|
|
|
d88bf6 |
|
|
|
d88bf6 |
if (!llen) {
|
|
|
d88bf6 |
@@ -61,8 +61,8 @@ static void process(int fd)
|
|
|
d88bf6 |
if (!strncmp(line, "quit", 4) && llen == 4)
|
|
|
d88bf6 |
break;
|
|
|
d88bf6 |
|
|
|
d88bf6 |
- if (send_packet(fd, line, llen + 1) != 0) break;
|
|
|
d88bf6 |
- if (recv_packet(fd, &reply, &len) != 0) break;
|
|
|
d88bf6 |
+ if (send_packet(fd, line) != 0) break;
|
|
|
d88bf6 |
+ if (recv_packet(fd, &reply) != 0) break;
|
|
|
d88bf6 |
|
|
|
d88bf6 |
print_reply(reply);
|
|
|
d88bf6 |
|
|
|
d88bf6 |
@@ -77,13 +77,12 @@ static void process(int fd)
|
|
|
d88bf6 |
static void process_req(int fd, char * inbuf)
|
|
|
d88bf6 |
{
|
|
|
d88bf6 |
char *reply;
|
|
|
d88bf6 |
- size_t len;
|
|
|
d88bf6 |
|
|
|
d88bf6 |
- if (send_packet(fd, inbuf, strlen(inbuf) + 1) != 0) {
|
|
|
d88bf6 |
+ if (send_packet(fd, inbuf) != 0) {
|
|
|
d88bf6 |
printf("cannot send packet\n");
|
|
|
d88bf6 |
return;
|
|
|
d88bf6 |
}
|
|
|
d88bf6 |
- if (recv_packet(fd, &reply, &len) != 0)
|
|
|
d88bf6 |
+ if (recv_packet(fd, &reply) != 0)
|
|
|
d88bf6 |
printf("error receiving packet\n");
|
|
|
d88bf6 |
else {
|
|
|
d88bf6 |
printf("%s", reply);
|
|
|
d88bf6 |
@@ -98,7 +97,7 @@ int uxclnt(char * inbuf)
|
|
|
d88bf6 |
{
|
|
|
d88bf6 |
int fd;
|
|
|
d88bf6 |
|
|
|
d88bf6 |
- fd = ux_socket_connect(DEFAULT_SOCKET);
|
|
|
d88bf6 |
+ fd = mpath_connect();
|
|
|
d88bf6 |
if (fd == -1) {
|
|
|
d88bf6 |
perror("ux_socket_connect");
|
|
|
d88bf6 |
exit(1);
|
|
|
d88bf6 |
Index: multipath-tools-130222/multipathd/uxlsnr.c
|
|
|
d88bf6 |
===================================================================
|
|
|
d88bf6 |
--- multipath-tools-130222.orig/multipathd/uxlsnr.c
|
|
|
d88bf6 |
+++ multipath-tools-130222/multipathd/uxlsnr.c
|
|
|
d88bf6 |
@@ -29,6 +29,7 @@
|
|
|
d88bf6 |
#include <structs_vec.h>
|
|
|
d88bf6 |
#include <uxsock.h>
|
|
|
d88bf6 |
#include <defaults.h>
|
|
|
d88bf6 |
+#include <mpath_cmd.h>
|
|
|
d88bf6 |
|
|
|
d88bf6 |
#include "main.h"
|
|
|
d88bf6 |
#include "cli.h"
|
|
|
d88bf6 |
@@ -108,7 +109,6 @@ void * uxsock_listen(int (*uxsock_trigge
|
|
|
d88bf6 |
void * trigger_data)
|
|
|
d88bf6 |
{
|
|
|
d88bf6 |
int ux_sock;
|
|
|
d88bf6 |
- size_t len;
|
|
|
d88bf6 |
int rlen;
|
|
|
d88bf6 |
char *inbuf;
|
|
|
d88bf6 |
char *reply;
|
|
|
d88bf6 |
@@ -171,16 +171,15 @@ void * uxsock_listen(int (*uxsock_trigge
|
|
|
d88bf6 |
struct client *next = c->next;
|
|
|
d88bf6 |
|
|
|
d88bf6 |
if (polls[i].revents & POLLIN) {
|
|
|
d88bf6 |
- if (recv_packet(c->fd, &inbuf, &len) != 0) {
|
|
|
d88bf6 |
+ if (recv_packet(c->fd, &inbuf) != 0) {
|
|
|
d88bf6 |
dead_client(c);
|
|
|
d88bf6 |
} else {
|
|
|
d88bf6 |
- inbuf[len - 1] = 0;
|
|
|
d88bf6 |
condlog(4, "Got request [%s]", inbuf);
|
|
|
d88bf6 |
uxsock_trigger(inbuf, &reply, &rlen,
|
|
|
d88bf6 |
trigger_data);
|
|
|
d88bf6 |
if (reply) {
|
|
|
d88bf6 |
- if (send_packet(c->fd, reply,
|
|
|
d88bf6 |
- rlen) != 0) {
|
|
|
d88bf6 |
+ if (send_packet(c->fd,
|
|
|
d88bf6 |
+ reply) != 0) {
|
|
|
d88bf6 |
dead_client(c);
|
|
|
d88bf6 |
}
|
|
|
d88bf6 |
condlog(4, "Reply [%d bytes]",
|