libdmmp.h(3) Library Functions Manual libdmmp.h(3)

# [NAME](#NAME)

libdmmp.h - Device Mapper Multipath API.

# [SYNOPSIS](#SYNOPSIS)

#include &lt;libdmmp/libdmmp.h&gt;

# [DESCRIPTION](#DESCRIPTION)

All the libdmmp public functions ships its own man pages. Use 'man 3 &lt;function\_name&gt;' to check the detail usage.

# [USAGE](#USAGE)

To use libdmmp in your project, we suggest to use the 'pkg-config' way:

\* Add this line into your configure.ac:

PKG\_CHECK\_MODULES(\[LIBDMMP], \[libdmmp])

\* Add these lines into your Makefile.am:

foo\_LDFLAGS += $(LIBDMMP\_LIBS)  
foo\_CFLAGS += $(LIBDMMP\_CFLAGS)

# [LOG HANDLING](#LOG_HANDLING)

The log handler function could be set via 'dmmp\_context\_log\_func\_set()'. The log priority could be set via 'dmmp\_context\_log\_priority\_set()'.

By default, the log priorities is 'DMMP\_LOG\_PRIORITY\_WARNING'. By default, the log handler is print log to STDERR, and its code is listed below in case you want to create your own log handler.

static int \_DMMP\_LOG\_STRERR\_ALIGN\_WIDTH = 80;

static void \_log\_stderr(struct dmmp\_context \*ctx,  
enum dmmp\_log\_priority priority,  
const char \*file, int line,  
const char \*func\_name,  
const char \*format, va\_list args)  
{  
int printed\_bytes = 0;

printed\_bytes += fprintf(stderr, "libdmmp %s: ",  
dmmp\_log\_priority\_str(priority));  
printed\_bytes += vfprintf(stderr, format, args);  
userdata = dmmp\_context\_userdata\_get(ctx);  
if (userdata != NULL)  
fprintf(stderr, "(with user data at memory address %p)",  
userdata);

if (printed\_bytes &lt; \_DMMP\_LOG\_STRERR\_ALIGN\_WIDTH) {  
fprintf(stderr, "%\*s # %s:%s():%d0,  
\_DMMP\_LOG\_STRERR\_ALIGN\_WIDTH - printed\_bytes, "", file,  
func\_name, line);  
} else {  
fprintf(stderr, " # %s:%s():%d0, file, func\_name, line);  
}  
}

# [SAMPLE CODE](#SAMPLE_CODE)

#include &lt;libdmmp/libdmmp.h&gt;

int main(int argc, char \*argv\[]) {  
struct dmmp\_context \*ctx = NULL;  
struct dmmp\_mpath \*\*dmmp\_mps = NULL;  
struct dmmp\_path\_group \*\*dmmp\_pgs = NULL;  
struct dmmp\_path \*\*dmmp\_ps = NULL;  
uint32\_t dmmp\_mp\_count = 0;  
uint32\_t dmmp\_pg\_count = 0;  
uint32\_t dmmp\_p\_count = 0;  
const char \*name = NULL;  
const char \*wwid = NULL;  
uint32\_t i = 0;  
int rc = DMMP\_OK;

ctx = dmmp\_context\_new();  
dmmp\_context\_log\_priority\_set(ctx, DMMP\_LOG\_PRIORITY\_DEBUG);  
// By default, log will be printed to STDERR, you could  
// change that via dmmp\_context\_log\_func\_set()  
rc = dmmp\_mpath\_array\_get(ctx, &dmmp\_mps, &dmmp\_mp\_count);  
if (rc != DMMP\_OK) {  
printf("dmmp\_mpath\_array\_get() failed with %d: %s", rc,  
dmmp\_strerror(rc));  
goto out;  
}  
for (i = 0; i &lt; dmmp\_mp\_count; ++i) {  
name = dmmp\_mpath\_name\_get(dmmp\_mps\[i]);  
wwid = dmmp\_mpath\_wwid\_get(dmmp\_mps\[i]);  
printf("dmmp\_mpath\_array\_get(): Got mpath: %s %s0, name,  
wwid);  
// You could use dmmp\_path\_group\_array\_get() to retrieve  
// path group information and then invoke dmmp\_path\_array\_get()  
// for path information.  
}

out:  
dmmp\_context\_free(ctx);  
dmmp\_mpath\_array\_free(dmmp\_mps, dmmp\_mp\_count);  
if (rc != DMMP\_OK)  
[exit(1)](/man/os/multipath-tools/exit.1);  
exit(0);  
}

# [LICENSE](#LICENSE)

GPLv2+

# [BUG](#BUG)

Please report bug to &lt;dm-devel@lists.linux.dev&gt;

January 2016 Device Mapper Multipath API - libdmmp Manual

---

Document: libdmmp.h(3) from multipath-tools 0.15.1-r0 (Chainguard OS)
Source: https://github.com/opensvc/multipath-tools
