GNU bug report logs - #30629
[PATCH 0/5] Detect missing modules in the initrd

Previous Next

Package: guix-patches;

Reported by: Ludovic Courtès <ludo <at> gnu.org>

Date: Tue, 27 Feb 2018 14:18:01 UTC

Severity: normal

Tags: patch

Done: ludo <at> gnu.org (Ludovic Courtès)

Bug is archived. No further changes may be made.

Full log


Message #71 received at 30629 <at> debbugs.gnu.org (full text, mbox):

From: ludo <at> gnu.org (Ludovic Courtès)
To: Danny Milosavljevic <dannym <at> scratchpost.org>
Cc: 30629 <at> debbugs.gnu.org
Subject: Re: Device mapper modalias
Date: Thu, 01 Mar 2018 11:11:11 +0100
Danny Milosavljevic <dannym <at> scratchpost.org> skribis:

> To get target_type as root (warning: getting the table status loads the module):
>
> #include <sys/sysmacros.h>
> #include <stdio.h>
> #include <stdlib.h>
> #include <stddef.h>
> #include <assert.h>
> #include <linux/dm-ioctl.h>
> #include <sys/types.h>
> #include <sys/stat.h>
> #include <sys/ioctl.h>
> #include <fcntl.h>
> #include <string.h>
>
> static void xdm_init(struct dm_ioctl* header, unsigned dev, off_t datastart, size_t allsize, unsigned flags) {
>         memset(header, 0, sizeof(header));
>         header->version[0] = 4;
>         header->version[1] = 0;
>         header->version[2] = 0;
>         header->data_size = allsize;
>         header->data_start = datastart;
>         header->flags = flags;
>         header->dev = dev;
> }
>
> struct xdm_devicelist {
>         struct dm_ioctl header;
>         struct dm_name_list items[100];
> };
>
> struct xdm_tablestatus {
>         struct dm_ioctl header;
>         struct dm_target_spec items[100];
> };
>
> int main() {
>         int controlfd;
>         controlfd = open("/dev/mapper/control", O_RDWR);
>
> 	// Retrieve dev major/minor
>         struct xdm_devicelist devicelist;
>         xdm_init(&devicelist.header, 0, offsetof(struct xdm_devicelist, items), sizeof(devicelist), 0);
>         if (ioctl(controlfd, DM_LIST_DEVICES, &devicelist) == -1)
>                 abort();
>         printf("devicelist %s %u\n", devicelist.items[0].name, (unsigned) devicelist.items[0].dev);
>
> 	// Get target_type of that device
>         struct xdm_tablestatus tablestatus;
>         xdm_init(&tablestatus.header, devicelist.items[0].dev, offsetof(struct xdm_tablestatus, items), sizeof(tablestatus), DM_STATUS_TABLE_FLAG);
>         tablestatus.header.dev = devicelist.items[0].dev;
>         if (ioctl(controlfd, DM_TABLE_STATUS, &tablestatus) == -1) {
>                 perror("b");
>                 abort();
>         }
>         assert(tablestatus.header.target_count == 1);
>         printf("target_type %s\n", tablestatus.items[0].target_type); // prints "crypto", hence we should modprobe "dm-crypto".

Is this target_type/module name mapping always correct?

If so, we could always implement this DM_TABLE_STATUS ioctl and use it,
although if it loads modules as a side effect that’s not great.

> Alternatively, there's even a dm-uevent.c for sysfs AND we have enabled it AND it's supposed
> to report DM_TARGET - but I can't see it.  Maybe it only does that for events and not for state.

Hmm.

> Alternatively, there's also this:
>
> $ udevadm info -q all /dev/dm-0
>
> ... which has quite a lot of the info, but not the module name.

Hmm!  So how do other distros do?  There must be a way to get the module
name no?

Thanks for investigating!

Ludo’.




This bug report was last modified 7 years and 127 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.