libdmmp.h(3)

πŸ“¦
version 0.15.1 Β· 2 versions
, in alpine 3.22, alpine 3.23, alpine 3.24, arch rolling, fedora 43, fedora 44, nixos 26.05, nixpkgs unstable, opensuse-leap 16.0

πŸ’… libdmmp.h β€” the Device Mapper Multipath API πŸ’…

okay bestie, welcome to libdmmp.h(3) β€” yes, that's section 3, the Library Functions Manual, we're in the big leagues now ✨


🌸 NAME 🌸

libdmmp.h β€” the Device Mapper Multipath API. that's it, that's the vibe πŸ’–


πŸ¦‹ SYNOPSIS πŸ¦‹

#include <libdmmp/libdmmp.h>

✨ DESCRIPTION ✨

every single one of the public libdmmp functions ships with its own little man page, bestie. iconic behavior honestly. so if you wanna know the deets on how to actually use one, just run:

man 3 <function_name>

and the whole detailed usage is right there waiting for you πŸŽ€


πŸ‘‘ USAGE πŸ‘‘

so you wanna put libdmmp in your project? periodt. the way we suggest you do it is the pkg-config way, no cap:

  • drop this line into your configure.ac:
PKG_CHECK_MODULES([LIBDMMP], [libdmmp])
  • then add these lines into your Makefile.am:
foo_LDFLAGS += $(LIBDMMP_LIBS)
foo_CFLAGS += $(LIBDMMP_CFLAGS)

that's the whole setup, slay πŸ’…


🫢 LOG HANDLING 🫢

okay so logging, listen up. you can set the log handler function with dmmp_context_log_func_set(), and you can set the log priority with dmmp_context_log_priority_set(). two little besties doing two different jobs, we love that for them πŸ’œ

by default? the log priority is DMMP_LOG_PRIORITY_WARNING. and by default the log handler just prints the log straight to STDERR. the code for that default handler is listed below, in case you're feeling crafty and wanna build 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 < _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 πŸ“

here's a whole lil program, bestie. read it, run it, become the main character of your own multipath journey πŸ’–

#include <libdmmp/libdmmp.h>

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 < 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);
    exit(0);
}

πŸŽ€ LICENSE πŸŽ€

GPLv2+ β€” yeah bestie, that's the one, go forth and share the love (respectfully, per the license) πŸ’–


πŸ™ˆ BUG πŸ™ˆ

found a bug? don't be shy, don't suffer in silence. please report it to <dm-devel@lists.linux.dev> 🫢


and that's a wrap on libdmmp.h(3), the Device Mapper Multipath API page, born way back in January 2016 and still serving looks in the Library Functions Manual. mwah, go write some slay code πŸ’…βœ¨πŸ¦‹