From: ludo@gnu.org (Ludovic Courtès)
To: Danny Milosavljevic <dannym@scratchpost.org>
Cc: 30629@debbugs.gnu.org
Subject: [bug#30629] Device mapper modalias
Date: Thu, 01 Mar 2018 11:11:11 +0100 [thread overview]
Message-ID: <87r2p46r7k.fsf@gnu.org> (raw)
In-Reply-To: <20180228040227.4299790b@scratchpost.org> (Danny Milosavljevic's message of "Wed, 28 Feb 2018 04:03:00 +0100")
Danny Milosavljevic <dannym@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’.
next prev parent reply other threads:[~2018-03-01 10:12 UTC|newest]
Thread overview: 43+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-02-27 14:17 [bug#30629] [PATCH 0/5] Detect missing modules in the initrd Ludovic Courtès
2018-02-27 14:22 ` Ludovic Courtès
2018-02-27 14:22 ` [bug#30629] [PATCH 1/5] Add (guix glob) Ludovic Courtès
2018-02-27 21:45 ` Marius Bakke
2018-02-28 11:25 ` Danny Milosavljevic
2018-03-01 9:57 ` Ludovic Courtès
2018-03-01 10:11 ` Danny Milosavljevic
2018-03-01 14:29 ` Danny Milosavljevic
2018-02-27 14:22 ` [bug#30629] [PATCH 2/5] linux-modules: Add 'device-module-aliases' and related procedures Ludovic Courtès
2018-02-27 19:33 ` Danny Milosavljevic
2018-02-27 20:55 ` Ludovic Courtès
2018-02-27 21:58 ` Danny Milosavljevic
2018-02-27 21:24 ` Ludovic Courtès
2018-02-27 14:22 ` [bug#30629] [PATCH 3/5] linux-initrd: Separate file system module logic Ludovic Courtès
2018-03-01 14:31 ` Danny Milosavljevic
2018-02-27 14:22 ` [bug#30629] [PATCH 4/5] system: Add 'initrd-modules' field Ludovic Courtès
2018-03-01 18:39 ` Danny Milosavljevic
2018-02-27 14:22 ` [bug#30629] [PATCH 5/5] guix system: Check for the lack of modules in the initrd Ludovic Courtès
2018-03-02 12:39 ` Danny Milosavljevic
2018-02-27 21:29 ` [bug#30629] [PATCH 0/5] Detect missing " Danny Milosavljevic
2018-02-27 21:15 ` Ludovic Courtès
2018-02-27 22:50 ` Danny Milosavljevic
2018-02-27 23:13 ` [bug#30638] [WIP v2] linux-initrd: Make modprobe pure-Guile Danny Milosavljevic
2018-02-27 23:17 ` Danny Milosavljevic
2018-02-28 11:47 ` [bug#30638] [WIP v3] " Danny Milosavljevic
2018-02-28 12:05 ` [bug#30638] [WIP v4] " Danny Milosavljevic
2018-02-28 11:36 ` [bug#30629] [PATCH 0/5] Detect missing modules in the initrd Danny Milosavljevic
2018-03-01 10:05 ` Ludovic Courtès
2018-03-01 10:11 ` Danny Milosavljevic
2018-03-01 11:46 ` Danny Milosavljevic
2018-03-01 13:39 ` Ludovic Courtès
2018-03-01 13:54 ` Danny Milosavljevic
2018-03-02 12:56 ` bug#30629: " Ludovic Courtès
2018-03-02 17:50 ` [bug#30629] " Danny Milosavljevic
2018-03-02 18:16 ` Danny Milosavljevic
2018-03-03 8:42 ` Ludovic Courtès
2018-03-01 13:55 ` Danny Milosavljevic
2018-03-01 21:20 ` Ludovic Courtès
2018-03-02 11:42 ` Danny Milosavljevic
2018-02-28 3:03 ` [bug#30629] Device mapper modalias Danny Milosavljevic
2018-03-01 8:56 ` Danny Milosavljevic
2018-03-01 10:11 ` Ludovic Courtès [this message]
2018-03-07 18:56 ` Danny Milosavljevic
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://guix.gnu.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87r2p46r7k.fsf@gnu.org \
--to=ludo@gnu.org \
--cc=30629@debbugs.gnu.org \
--cc=dannym@scratchpost.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/guix.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).