Skip to content

Commit

Permalink
multipath-tools: Introducing multipath C API
Browse files Browse the repository at this point in the history
Features:

 * Use mpath_cmd.h for IPC connection and use output of 'show maps json'.
 * Library user guide will be 'man 3 libdmmp.h'.
 * Every public function has its own manpage in section 3 which is
   generated by linux 'kernel-doc' tool.

Usage:

    make -j5
    sudo make install \
            bindir=/usr/sbin/ \
            syslibdir=/usr/lib64/ \
            libdir=/usr/lib64/multipath \
            rcdir=/etc/rc.d/init.d \
            unitdir=/usr/lib/systemd/system \
            includedir=/usr/include
    make -C libdmmp check
    make -C libdmmp speed_test

    man libdmmp.h
    man dmmp_mpath_array_get
    man <dmmp function name>

Performance:

 * 10k scsi_debug sdX with 2 disks per mpath (i7-6820HQ 16GiB RAM):
   $ make -C libdmmp speed_test
   Got 5000 mpath
   real 3.22
   user 0.15
   sys 0.01

Misc:
 * Developer note is libdmmp/DEV_NOTES.

Signed-off-by: Gris Ge <fge@redhat.com>
  • Loading branch information
cathay4t committed Feb 24, 2017
1 parent ea43671 commit c3b39f3
Show file tree
Hide file tree
Showing 20 changed files with 5,421 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Expand Up @@ -12,3 +12,7 @@ mpathpersist/mpathpersist
.nfs*
*.swp
*.patch
libdmmp/docs/man/*.3.gz
libdmmp/*.so.*
libdmmp/test/libdmmp_test
libdmmp/test/libdmmp_speed_test
1 change: 1 addition & 0 deletions Makefile
Expand Up @@ -30,6 +30,7 @@ BUILDDIRS = \
libmultipath/prioritizers \
libmultipath/checkers \
libmpathpersist \
libdmmp \
multipath \
multipathd \
mpathpersist \
Expand Down
3 changes: 3 additions & 0 deletions Makefile.inc
Expand Up @@ -55,6 +55,9 @@ unitdir = $(prefix)/$(SYSTEMDPATH)/systemd/system
mpathpersistdir = $(TOPDIR)/libmpathpersist
mpathcmddir = $(TOPDIR)/libmpathcmd
thirdpartydir = $(TOPDIR)/third-party
libdmmpdir = $(TOPDIR)/libdmmp
includedir = $(prefix)/usr/include
pkgconfdir = $(prefix)/usr/share/pkgconfig

GZIP = gzip -9 -c
RM = rm -f
Expand Down
41 changes: 41 additions & 0 deletions libdmmp/DEV_NOTES
@@ -0,0 +1,41 @@
== Planed features ==
* Expose all properties used by /usr/bin/multipath

== Code style ==
* Keep things as simple as possible.
* Linux Kernel code style.
* Don't use typedef.
* Don't use enum.
* We are not smarter than API user, so don't create wrapping function like:

```
dmmp_mpath_search_by_id(struct dmmp_context *ctx,
struct dmmp_mpath **dmmp_mp,
uint32_t dmmp_mp_count, const char *id)

dmmp_path_group_id_search(struct dmmp_mpath *dmmp_mp,
const char *blk_name)
```
* The performance is the same for query single mpath and query all mpaths,
so no `dmmp_mpath_of_wwid(struct dmmp_context *ctx, const char *wwid)` yet.

== Naming scheme ==
* Public constants should be named as `DMMP_XXX_YYY`.
* Public functions should be named as `dmmp_<noun>_<verb>`.
* Private constants should be named as `_DMMP_XXX_YYY`.
* Private functions should be named as `_dmmp_<noun>_<verb>`.

== Code Layout ==
* libdmmp_private.h
Internal functions or macros.
* libdmmp.c
Handling multipathd IPC and generate dmmp_context and
dmmp_mpath_array_get().
* libdmmp_mp.c
For `struct dmmp_mpath`
* libdmmp_pg.c
For `struct dmmp_path_group`
* libdmmp_path.c
For `struct dmmp_path`
* libdmmp_misc.c
Misc functions.
84 changes: 84 additions & 0 deletions libdmmp/Makefile
@@ -0,0 +1,84 @@
# Makefile
#
# Copyright (C) 2015 - 2016 Red Hat, Inc.
# Gris Ge <fge@redhat.com>
#
include ../Makefile.inc

LIBDMMP_VERSION=0.1.0
SONAME=$(LIBDMMP_VERSION)
DEVLIB = libdmmp.so
LIBS = $(DEVLIB).$(SONAME)
LIBDEPS = -pthread
PKGFILE = libdmmp.pc
EXTRA_MAN_FILES = libdmmp.h.3
HEADERS = libdmmp/libdmmp.h
OBJS = libdmmp.o libdmmp_mp.o libdmmp_pg.o libdmmp_path.o libdmmp_misc.o

CFLAGS += -fvisibility=hidden -I$(libdmmpdir) -I$(mpathcmddir) \
$(shell pkg-config --cflags json-c)
LDFLAGS += $(shell pkg-config --libs json-c) -L$(mpathcmddir) -lmpathcmd

all: $(LIBS) doc

$(LIBS): $(OBJS)
$(CC) $(LDFLAGS) $(SHARED_FLAGS) \
-Wl,-soname=$@ $(CFLAGS) -o $@ $(OBJS) $(LIBDEPS)
$(LN) $@ $(DEVLIB)

install:
$(INSTALL_PROGRAM) -m 755 $(LIBS) $(DESTDIR)$(syslibdir)/$(LIBS)
$(INSTALL_PROGRAM) -m 644 -D \
$(HEADERS) $(DESTDIR)/$(includedir)/$(HEADERS)
$(LN) $(LIBS) $(DESTDIR)/$(syslibdir)/$(DEVLIB)
$(INSTALL_PROGRAM) -m 644 -D \
$(PKGFILE).in $(DESTDIR)/$(pkgconfdir)/$(PKGFILE)
perl -i -pe 's|__VERSION__|$(LIBDMMP_VERSION)|g' \
$(DESTDIR)/$(pkgconfdir)/$(PKGFILE)
perl -i -pe 's|__LIBDIR__|$(syslibdir)|g' \
$(DESTDIR)/$(pkgconfdir)/$(PKGFILE)
perl -i -pe 's|__INCLUDEDIR__|$(includedir)|g' \
$(DESTDIR)/$(pkgconfdir)/$(PKGFILE)
@for file in docs/man/*.3.gz; do \
$(INSTALL_PROGRAM) -m 644 -D \
$$file \
$(DESTDIR)/$(man3dir)/ || exit $?; \
done

uninstall:
$(RM) $(DESTDIR)$(syslibdir)/$(LIBS)
$(RM) $(DESTDIR)$(includedir)/$(HEADERS)
$(RM) $(DESTDIR)/$(syslibdir)/$(DEVLIB)
@for file in $(DESTDIR)/$(man3dir)/dmmp_*; do \
$(RM) $$file; \
done
$(RM) $(DESTDIR)$(man3dir)/libdmmp.h*

clean:
$(RM) core *.a *.o *.gz *.so *.so.*
$(RM) docs/man/*.3.gz
$(MAKE) -C test clean

check: all
$(MAKE) -C test check

speed_test: all
$(MAKE) -C test speed_test

doc: docs/man/$(EXTRA_MAN_FILES).gz

TEMPFILE := $(shell mktemp)

docs/man/$(EXTRA_MAN_FILES).gz: $(HEADERS)
@for file in $(EXTRA_MAN_FILES); do \
$(INSTALL_PROGRAM) -v -m 644 -D docs/$$file docs/man/$$file; \
done
cat $(HEADERS) | \
perl docs/doc-preclean.pl > $(TEMPFILE)
perl docs/kernel-doc -man $(TEMPFILE) | \
perl docs/split-man.pl docs/man
-rm -f $(TEMPFILE)
@for file in docs/man/*.3; do \
gzip -f $$file; \
done
find docs/man -type f -name \*[0-9].gz
28 changes: 28 additions & 0 deletions libdmmp/docs/doc-preclean.pl
@@ -0,0 +1,28 @@
#!/usr/bin/perl
# Copyright (C) 2016 Red Hat, Inc.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# Author: Gris Ge <fge@redhat.com>

use strict;

my @REMOVE_KEY_LIST=("DMMP_DLL_EXPORT");

while (<>) {
for my $key (@REMOVE_KEY_LIST) {
(s/$key//g);
}
print;
}

0 comments on commit c3b39f3

Please sign in to comment.