UbuntuWiki:UdevDeviceMapper
文章出处: |
{{#if: | {{{2}}} | https://wiki.ubuntu.com/UdevDeviceMapper }} |
点击翻译: |
English {{#ifexist: {{#if: UbuntuWiki:UdevDeviceMapper | UbuntuWiki:UdevDeviceMapper | {{#if: | :}}UbuntuWiki:UdevDeviceMapper}}/af | • {{#if: UbuntuWiki:UdevDeviceMapper|Afrikaans| [[::UbuntuWiki:UdevDeviceMapper/af|Afrikaans]]}}|}} {{#ifexist: {{#if: UbuntuWiki:UdevDeviceMapper | UbuntuWiki:UdevDeviceMapper | {{#if: | :}}UbuntuWiki:UdevDeviceMapper}}/ar | • {{#if: UbuntuWiki:UdevDeviceMapper|العربية| [[::UbuntuWiki:UdevDeviceMapper/ar|العربية]]}}|}} {{#ifexist: {{#if: UbuntuWiki:UdevDeviceMapper | UbuntuWiki:UdevDeviceMapper | {{#if: | :}}UbuntuWiki:UdevDeviceMapper}}/az | • {{#if: UbuntuWiki:UdevDeviceMapper|azərbaycanca| [[::UbuntuWiki:UdevDeviceMapper/az|azərbaycanca]]}}|}} {{#ifexist: {{#if: UbuntuWiki:UdevDeviceMapper | UbuntuWiki:UdevDeviceMapper | {{#if: | :}}UbuntuWiki:UdevDeviceMapper}}/bcc | • {{#if: UbuntuWiki:UdevDeviceMapper|جهلسری بلوچی| [[::UbuntuWiki:UdevDeviceMapper/bcc|جهلسری بلوچی]]}}|}} {{#ifexist: {{#if: UbuntuWiki:UdevDeviceMapper | UbuntuWiki:UdevDeviceMapper | {{#if: | :}}UbuntuWiki:UdevDeviceMapper}}/bg | • {{#if: UbuntuWiki:UdevDeviceMapper|български| [[::UbuntuWiki:UdevDeviceMapper/bg|български]]}}|}} {{#ifexist: {{#if: UbuntuWiki:UdevDeviceMapper | UbuntuWiki:UdevDeviceMapper | {{#if: | :}}UbuntuWiki:UdevDeviceMapper}}/br | • {{#if: UbuntuWiki:UdevDeviceMapper|brezhoneg| [[::UbuntuWiki:UdevDeviceMapper/br|brezhoneg]]}}|}} {{#ifexist: {{#if: UbuntuWiki:UdevDeviceMapper | UbuntuWiki:UdevDeviceMapper | {{#if: | :}}UbuntuWiki:UdevDeviceMapper}}/ca | • {{#if: UbuntuWiki:UdevDeviceMapper|català| [[::UbuntuWiki:UdevDeviceMapper/ca|català]]}}|}} {{#ifexist: {{#if: UbuntuWiki:UdevDeviceMapper | UbuntuWiki:UdevDeviceMapper | {{#if: | :}}UbuntuWiki:UdevDeviceMapper}}/cs | • {{#if: UbuntuWiki:UdevDeviceMapper|čeština| [[::UbuntuWiki:UdevDeviceMapper/cs|čeština]]}}|}} {{#ifexist: {{#if: UbuntuWiki:UdevDeviceMapper | UbuntuWiki:UdevDeviceMapper | {{#if: | :}}UbuntuWiki:UdevDeviceMapper}}/de | • {{#if: UbuntuWiki:UdevDeviceMapper|Deutsch| [[::UbuntuWiki:UdevDeviceMapper/de|Deutsch]]}}|}} {{#ifexist: {{#if: UbuntuWiki:UdevDeviceMapper | UbuntuWiki:UdevDeviceMapper | {{#if: | :}}UbuntuWiki:UdevDeviceMapper}}/el | • {{#if: UbuntuWiki:UdevDeviceMapper|Ελληνικά| [[::UbuntuWiki:UdevDeviceMapper/el|Ελληνικά]]}}|}} {{#ifexist: {{#if: UbuntuWiki:UdevDeviceMapper | UbuntuWiki:UdevDeviceMapper | {{#if: | :}}UbuntuWiki:UdevDeviceMapper}}/es | • {{#if: UbuntuWiki:UdevDeviceMapper|español| [[::UbuntuWiki:UdevDeviceMapper/es|español]]}}|}} {{#ifexist: {{#if: UbuntuWiki:UdevDeviceMapper | UbuntuWiki:UdevDeviceMapper | {{#if: | :}}UbuntuWiki:UdevDeviceMapper}}/fa | • {{#if: UbuntuWiki:UdevDeviceMapper|فارسی| [[::UbuntuWiki:UdevDeviceMapper/fa|فارسی]]}}|}} {{#ifexist: {{#if: UbuntuWiki:UdevDeviceMapper | UbuntuWiki:UdevDeviceMapper | {{#if: | :}}UbuntuWiki:UdevDeviceMapper}}/fi | • {{#if: UbuntuWiki:UdevDeviceMapper|suomi| [[::UbuntuWiki:UdevDeviceMapper/fi|suomi]]}}|}} {{#ifexist: {{#if: UbuntuWiki:UdevDeviceMapper | UbuntuWiki:UdevDeviceMapper | {{#if: | :}}UbuntuWiki:UdevDeviceMapper}}/fr | • {{#if: UbuntuWiki:UdevDeviceMapper|français| [[::UbuntuWiki:UdevDeviceMapper/fr|français]]}}|}} {{#ifexist: {{#if: UbuntuWiki:UdevDeviceMapper | UbuntuWiki:UdevDeviceMapper | {{#if: | :}}UbuntuWiki:UdevDeviceMapper}}/gu | • {{#if: UbuntuWiki:UdevDeviceMapper|ગુજરાતી| [[::UbuntuWiki:UdevDeviceMapper/gu|ગુજરાતી]]}}|}} {{#ifexist: {{#if: UbuntuWiki:UdevDeviceMapper | UbuntuWiki:UdevDeviceMapper | {{#if: | :}}UbuntuWiki:UdevDeviceMapper}}/he | • {{#if: UbuntuWiki:UdevDeviceMapper|עברית| [[::UbuntuWiki:UdevDeviceMapper/he|עברית]]}}|}} {{#ifexist: {{#if: UbuntuWiki:UdevDeviceMapper | UbuntuWiki:UdevDeviceMapper | {{#if: | :}}UbuntuWiki:UdevDeviceMapper}}/hu | • {{#if: UbuntuWiki:UdevDeviceMapper|magyar| [[::UbuntuWiki:UdevDeviceMapper/hu|magyar]]}}|}} {{#ifexist: {{#if: UbuntuWiki:UdevDeviceMapper | UbuntuWiki:UdevDeviceMapper | {{#if: | :}}UbuntuWiki:UdevDeviceMapper}}/id | • {{#if: UbuntuWiki:UdevDeviceMapper|Bahasa Indonesia| [[::UbuntuWiki:UdevDeviceMapper/id|Bahasa Indonesia]]}}|}} {{#ifexist: {{#if: UbuntuWiki:UdevDeviceMapper | UbuntuWiki:UdevDeviceMapper | {{#if: | :}}UbuntuWiki:UdevDeviceMapper}}/it | • {{#if: UbuntuWiki:UdevDeviceMapper|italiano| [[::UbuntuWiki:UdevDeviceMapper/it|italiano]]}}|}} {{#ifexist: {{#if: UbuntuWiki:UdevDeviceMapper | UbuntuWiki:UdevDeviceMapper | {{#if: | :}}UbuntuWiki:UdevDeviceMapper}}/ja | • {{#if: UbuntuWiki:UdevDeviceMapper|日本語| [[::UbuntuWiki:UdevDeviceMapper/ja|日本語]]}}|}} {{#ifexist: {{#if: UbuntuWiki:UdevDeviceMapper | UbuntuWiki:UdevDeviceMapper | {{#if: | :}}UbuntuWiki:UdevDeviceMapper}}/ko | • {{#if: UbuntuWiki:UdevDeviceMapper|한국어| [[::UbuntuWiki:UdevDeviceMapper/ko|한국어]]}}|}} {{#ifexist: {{#if: UbuntuWiki:UdevDeviceMapper | UbuntuWiki:UdevDeviceMapper | {{#if: | :}}UbuntuWiki:UdevDeviceMapper}}/ksh | • {{#if: UbuntuWiki:UdevDeviceMapper|Ripoarisch| [[::UbuntuWiki:UdevDeviceMapper/ksh|Ripoarisch]]}}|}} {{#ifexist: {{#if: UbuntuWiki:UdevDeviceMapper | UbuntuWiki:UdevDeviceMapper | {{#if: | :}}UbuntuWiki:UdevDeviceMapper}}/mr | • {{#if: UbuntuWiki:UdevDeviceMapper|मराठी| [[::UbuntuWiki:UdevDeviceMapper/mr|मराठी]]}}|}} {{#ifexist: {{#if: UbuntuWiki:UdevDeviceMapper | UbuntuWiki:UdevDeviceMapper | {{#if: | :}}UbuntuWiki:UdevDeviceMapper}}/ms | • {{#if: UbuntuWiki:UdevDeviceMapper|Bahasa Melayu| [[::UbuntuWiki:UdevDeviceMapper/ms|Bahasa Melayu]]}}|}} {{#ifexist: {{#if: UbuntuWiki:UdevDeviceMapper | UbuntuWiki:UdevDeviceMapper | {{#if: | :}}UbuntuWiki:UdevDeviceMapper}}/nl | • {{#if: UbuntuWiki:UdevDeviceMapper|Nederlands| [[::UbuntuWiki:UdevDeviceMapper/nl|Nederlands]]}}|}} {{#ifexist: {{#if: UbuntuWiki:UdevDeviceMapper | UbuntuWiki:UdevDeviceMapper | {{#if: | :}}UbuntuWiki:UdevDeviceMapper}}/no | • {{#if: UbuntuWiki:UdevDeviceMapper|norsk| [[::UbuntuWiki:UdevDeviceMapper/no|norsk]]}}|}} {{#ifexist: {{#if: UbuntuWiki:UdevDeviceMapper | UbuntuWiki:UdevDeviceMapper | {{#if: | :}}UbuntuWiki:UdevDeviceMapper}}/oc | • {{#if: UbuntuWiki:UdevDeviceMapper|occitan| [[::UbuntuWiki:UdevDeviceMapper/oc|occitan]]}}|}} {{#ifexist: {{#if: UbuntuWiki:UdevDeviceMapper | UbuntuWiki:UdevDeviceMapper | {{#if: | :}}UbuntuWiki:UdevDeviceMapper}}/pl | • {{#if: UbuntuWiki:UdevDeviceMapper|polski| [[::UbuntuWiki:UdevDeviceMapper/pl|polski]]}}|}} {{#ifexist: {{#if: UbuntuWiki:UdevDeviceMapper | UbuntuWiki:UdevDeviceMapper | {{#if: | :}}UbuntuWiki:UdevDeviceMapper}}/pt | • {{#if: UbuntuWiki:UdevDeviceMapper|português| [[::UbuntuWiki:UdevDeviceMapper/pt|português]]}}|}} {{#ifexist: {{#if: UbuntuWiki:UdevDeviceMapper | UbuntuWiki:UdevDeviceMapper | {{#if: | :}}UbuntuWiki:UdevDeviceMapper}}/ro | • {{#if: UbuntuWiki:UdevDeviceMapper|română| [[::UbuntuWiki:UdevDeviceMapper/ro|română]]}}|}} {{#ifexist: {{#if: UbuntuWiki:UdevDeviceMapper | UbuntuWiki:UdevDeviceMapper | {{#if: | :}}UbuntuWiki:UdevDeviceMapper}}/ru | • {{#if: UbuntuWiki:UdevDeviceMapper|русский| [[::UbuntuWiki:UdevDeviceMapper/ru|русский]]}}|}} {{#ifexist: {{#if: UbuntuWiki:UdevDeviceMapper | UbuntuWiki:UdevDeviceMapper | {{#if: | :}}UbuntuWiki:UdevDeviceMapper}}/si | • {{#if: UbuntuWiki:UdevDeviceMapper|සිංහල| [[::UbuntuWiki:UdevDeviceMapper/si|සිංහල]]}}|}} {{#ifexist: {{#if: UbuntuWiki:UdevDeviceMapper | UbuntuWiki:UdevDeviceMapper | {{#if: | :}}UbuntuWiki:UdevDeviceMapper}}/sq | • {{#if: UbuntuWiki:UdevDeviceMapper|shqip| [[::UbuntuWiki:UdevDeviceMapper/sq|shqip]]}}|}} {{#ifexist: {{#if: UbuntuWiki:UdevDeviceMapper | UbuntuWiki:UdevDeviceMapper | {{#if: | :}}UbuntuWiki:UdevDeviceMapper}}/sr | • {{#if: UbuntuWiki:UdevDeviceMapper|српски / srpski| [[::UbuntuWiki:UdevDeviceMapper/sr|српски / srpski]]}}|}} {{#ifexist: {{#if: UbuntuWiki:UdevDeviceMapper | UbuntuWiki:UdevDeviceMapper | {{#if: | :}}UbuntuWiki:UdevDeviceMapper}}/sv | • {{#if: UbuntuWiki:UdevDeviceMapper|svenska| [[::UbuntuWiki:UdevDeviceMapper/sv|svenska]]}}|}} {{#ifexist: {{#if: UbuntuWiki:UdevDeviceMapper | UbuntuWiki:UdevDeviceMapper | {{#if: | :}}UbuntuWiki:UdevDeviceMapper}}/th | • {{#if: UbuntuWiki:UdevDeviceMapper|ไทย| [[::UbuntuWiki:UdevDeviceMapper/th|ไทย]]}}|}} {{#ifexist: {{#if: UbuntuWiki:UdevDeviceMapper | UbuntuWiki:UdevDeviceMapper | {{#if: | :}}UbuntuWiki:UdevDeviceMapper}}/tr | • {{#if: UbuntuWiki:UdevDeviceMapper|Türkçe| [[::UbuntuWiki:UdevDeviceMapper/tr|Türkçe]]}}|}} {{#ifexist: {{#if: UbuntuWiki:UdevDeviceMapper | UbuntuWiki:UdevDeviceMapper | {{#if: | :}}UbuntuWiki:UdevDeviceMapper}}/vi | • {{#if: UbuntuWiki:UdevDeviceMapper|Tiếng Việt| [[::UbuntuWiki:UdevDeviceMapper/vi|Tiếng Việt]]}}|}} {{#ifexist: {{#if: UbuntuWiki:UdevDeviceMapper | UbuntuWiki:UdevDeviceMapper | {{#if: | :}}UbuntuWiki:UdevDeviceMapper}}/yue | • {{#if: UbuntuWiki:UdevDeviceMapper|粵語| [[::UbuntuWiki:UdevDeviceMapper/yue|粵語]]}}|}} {{#ifexist: {{#if: UbuntuWiki:UdevDeviceMapper | UbuntuWiki:UdevDeviceMapper | {{#if: | :}}UbuntuWiki:UdevDeviceMapper}}/zh | • {{#if: UbuntuWiki:UdevDeviceMapper|中文| [[::UbuntuWiki:UdevDeviceMapper/zh|中文]]}}|}} {{#ifexist: {{#if: UbuntuWiki:UdevDeviceMapper | UbuntuWiki:UdevDeviceMapper | {{#if: | :}}UbuntuWiki:UdevDeviceMapper}}/zh-hans | • {{#if: UbuntuWiki:UdevDeviceMapper|中文(简体)| [[::UbuntuWiki:UdevDeviceMapper/zh-hans|中文(简体)]]}}|}} {{#ifexist: {{#if: UbuntuWiki:UdevDeviceMapper | UbuntuWiki:UdevDeviceMapper | {{#if: | :}}UbuntuWiki:UdevDeviceMapper}}/zh-hant | • {{#if: UbuntuWiki:UdevDeviceMapper|中文(繁體)| [[::UbuntuWiki:UdevDeviceMapper/zh-hant|中文(繁體)]]}}|}} |
{{#ifeq:UbuntuWiki:UdevDeviceMapper|:UbuntuWiki:UdevDeviceMapper|请不要直接编辑翻译本页,本页将定期与来源同步。}} |
{{#ifexist: :UbuntuWiki:UdevDeviceMapper/zh | | {{#ifexist: UbuntuWiki:UdevDeviceMapper/zh | | {{#ifeq: {{#titleparts:UbuntuWiki:UdevDeviceMapper|1|-1|}} | zh | | }} }} }} {{#ifeq: {{#titleparts:UbuntuWiki:UdevDeviceMapper|1|-1|}} | zh | | }}
Please check the status of this specification in Launchpad before editing it. If it is Approved, contact the Assignee or another knowledgeable person before making changes.
- Launchpad entry: udev-device-mapper
- Packages affected: udev, dmsetup
Summary
This specification details how to make udev and device-mapper play nicely together, in particular ensuring that udev events are issued for device-mapper blocks and that UUIDs are correctly exported and do not conflict.
Rationale
device-mapper is used by several server systems, such as LVM and RAID, to create block devices from partial parts or combinations of other block devices. In order to support event-based mounting of these filesystems, we need reliable events from the block subsystem and no race conditions.
Use cases
- Fabio uses a combination of LVM and RAID for his root filesystem, he would like this to continue to be supported.
- Martin uses a cryptographically encrypted USB disk, the block device of which is exposed by device mapper. When he inserts it, he'd like it to be mounted normally with HAL and pmount, without failing due to race conditions.
Scope
The scope of this specification is limited to the interaction between udev and device-mapper; other specifications will address similar concerns with LVM, EVMS, RAID, etc.
Design
dmsetup (via libdevmapper) currently creates the `/dev/mapper/NAME` device nodes itself, after requesting the map with the DM_DEV_CREATE ioctl. This ioctl causes a `dm-N` block device to be created, and the appropriate `/block/dm-N` uevent issued.
udev receives only the major/minor number of the device in the uevent, however fortunately this can be looked up to obtain the proper name; and thus the `/dev/mapper/NAME` created instead. This device name is then passed to HAL and upstart as normal.
The NAME, and thus the device path, consitutes a unique identifier; there is no need for UUID or LABEL support for these block devices. We will continue to ignore them.
While the current arrangements mean that the device node is guaranteed to exist when dmsetup returns, the device isn't guaranteed to exist when udev is run; and there's actually a race between udev creating the block device and dmsetup creating it.
Instead we will create the device in udev as normal, and dmsetup (actually libdevmapper) will be modified to, if the system is using udev, create the device in /dev/.static/dev (or /.dev) instead, and wait until the device is created (or a timeout is reached). The logic for deciding whether the system is using udev, and which directory to use, will be the same as that used in /dev/MAKEDEV.
When using udev, libdevmapper and the udev script will rendezvous as follows. libdevmapper will (when doing device create, rename or remove):
- open and F_GETLKW /dev/mapper/name,lock; fstat; if nlink==0 close and retry
- mkfifo /dev/mapper/name,rendezvous 600
- open /dev/mapper/name,rendezvous O_RDWR
- call the DM ioctl
- select(readfds=[/dev/mapper/name,rendezvous], 5 seconds)
- unlink and close /dev/mapper/name,rendezvous
- release the lock: unlink /dev/mapper/name,lock; close
and udev scripts will:
- call dmname to determine the device name
- create the device node in /dev
- call dmname --poke-libdevmapper which will open /dev/mapper/name,rendezvous O_RDWR, write(,"\0",1), close
- do other stuff which depends on the device
If libdevmapper detects udev, it will stat /lib/udev/.udev-device-mapper-rendezvous to see if the udev supports the protocol above. If it doesn't it will leave out the steps involving the rendezvous fifo.
Implementation
- Write a small udev helper to obtain the name of a device map from the major/minor number.
- Replace the existing "do not create" udev rule for `dm-[0-9]*` with one that uses that helper to name it, and sets the name, e.g.
KERNEL=="dm-[0-9]*", IMPORT{program}="dmname %M %m", NAME="mapper/$result"
- Patch libdevmapper to spin and timeout until the device is created, instead of creating it itself.
Unresolved issues
The kernel side of the device-mapper system could do with properly kobjectifying, so that information can be obtained through sysfs instead of ioctl. Not essential, and not necessary.
Renaming or reloading devices produces no uevents, however since whatever we did with the event (ie. mounted the block device) will already have happened, it's probably fine. If not, programs should remove and add anyway to ensure things are unmounted and mounted differently.