From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44308) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1erLC3-0002MS-8S for guix-patches@gnu.org; Thu, 01 Mar 2018 05:12:08 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1erLBz-0001FA-7o for guix-patches@gnu.org; Thu, 01 Mar 2018 05:12:07 -0500 Received: from debbugs.gnu.org ([208.118.235.43]:58581) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1erLBz-0001F0-39 for guix-patches@gnu.org; Thu, 01 Mar 2018 05:12:03 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1erLBy-0007ls-UL for guix-patches@gnu.org; Thu, 01 Mar 2018 05:12:02 -0500 Subject: [bug#30629] Device mapper modalias Resent-Message-ID: From: ludo@gnu.org (Ludovic =?UTF-8?Q?Court=C3=A8s?=) References: <20180227141720.12513-1-ludo@gnu.org> <20180227222632.42bcf52c@scratchpost.org> <87tvu2w2vg.fsf@gnu.org> <20180228040227.4299790b@scratchpost.org> Date: Thu, 01 Mar 2018 11:11:11 +0100 In-Reply-To: <20180228040227.4299790b@scratchpost.org> (Danny Milosavljevic's message of "Wed, 28 Feb 2018 04:03:00 +0100") Message-ID: <87r2p46r7k.fsf@gnu.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+kyle=kyleam.com@gnu.org Sender: "Guix-patches" To: Danny Milosavljevic Cc: 30629@debbugs.gnu.org Danny Milosavljevic skribis: > To get target_type as root (warning: getting the table status loads the m= odule): > > #include > #include > #include > #include > #include > #include > #include > #include > #include > #include > #include > > static void xdm_init(struct dm_ioctl* header, unsigned dev, off_t datasta= rt, size_t allsize, unsigned flags) { > memset(header, 0, sizeof(header)); > header->version[0] =3D 4; > header->version[1] =3D 0; > header->version[2] =3D 0; > header->data_size =3D allsize; > header->data_start =3D datastart; > header->flags =3D flags; > header->dev =3D 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 =3D open("/dev/mapper/control", O_RDWR); > > // Retrieve dev major/minor > struct xdm_devicelist devicelist; > xdm_init(&devicelist.header, 0, offsetof(struct xdm_devicelist, i= tems), sizeof(devicelist), 0); > if (ioctl(controlfd, DM_LIST_DEVICES, &devicelist) =3D=3D -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(s= truct xdm_tablestatus, items), sizeof(tablestatus), DM_STATUS_TABLE_FLAG); > tablestatus.header.dev =3D devicelist.items[0].dev; > if (ioctl(controlfd, DM_TABLE_STATUS, &tablestatus) =3D=3D -1) { > perror("b"); > abort(); > } > assert(tablestatus.header.target_count =3D=3D 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=E2=80=99s not great. > Alternatively, there's even a dm-uevent.c for sysfs AND we have enabled i= t AND it's supposed > to report DM_TARGET - but I can't see it. Maybe it only does that for ev= ents 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=E2=80=99.