Systemd/extras/multipath/devmap_name.c
christophe.varoqui@free.fr cbb576b91d [PATCH] more udev-016/extras/multipath
> Hello,
>
> incremental to udev-016/extras/multipath,
>
> * don't rely on the linux symlink in the udev/klibc dir since
>   udev build doesn't use it anymore. This corrects build breakage
> * remove make_dm_node fn & call. Rely on udev for this.
>
> The first patch is to be applied.
> The second is conditioned by udev dealing correctly with devmap names.
>
> For this I can suggest a CALLOUT rule like this :
> KERNEL="dm-[0-9]*", PROGRAM="/tmp/name_devmap %M %m", NAME="%k",
> SYMLINK="%c"
>
> With name_devmap like :
> #!/bin/sh
> /usr/sbin/dmsetup ls|/bin/grep "$1, $2"|/usr/bin/awk '{print $1}'
>

ok I coded the suggested tool.
it works with the following rule :
KERNEL="dm-[0-9]*", PROGRAM="/sbin/devmap_name %M %m", NAME="%k", SYMLINK="%c"

I don't know if it's right to keep this tools packaged with multipath because
it's widely more general.

Maybe Joe should merge it in the device-mapper package or provide the
functionnality through dmsetup ?
2005-04-26 21:32:27 -07:00

61 lines
1.8 KiB
C

#include "libdevmapper/libdevmapper.h"
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <linux/kdev_t.h>
static void usage(char * progname) {
fprintf(stderr, "usage : %s major minor\n", progname);
exit(1);
}
int main(int argc, char **argv)
{
int r = 0;
struct dm_names *names;
unsigned next = 0;
int major, minor;
/* sanity check */
if (argc != 3)
usage(argv[0]);
major = atoi(argv[1]);
minor = atoi(argv[2]);
struct dm_task *dmt;
if (!(dmt = dm_task_create(DM_DEVICE_LIST)))
return 0;
if (!dm_task_run(dmt))
goto out;
if (!(names = dm_task_get_names(dmt)))
goto out;
if (!names->dev) {
printf("No devices found\n");
goto out;
}
do {
names = (void *) names + next;
if ((int) MAJOR(names->dev) == major &&
(int) MINOR(names->dev) == minor) {
printf("%s\n", names->name);
goto out;
}
next = names->next;
} while (next);
/* No correspondance found */
r = 1;
out:
dm_task_destroy(dmt);
return r;
}