1 Device-mapper to libdevmapper protocol
5 1) Device mapper device in a POV of LVM it is an Logical Volume.
6 Logical Volume is virtual block device is made from logical blocks.
7 These blocks are mapped to real device blocks with algorithm called
10 Functions available to dm device:
11 create, remove, list, status of device.
13 2) device mapper target is function which defines how are Logical blocks
14 mapped to physical. There are many targets linear, stripe, mirror etc.
16 Functions available to dm device:
17 list available targets. They can be added with module in linux.
20 Every device-mapper device consits from one or more tables. Table specify
21 Start, length of logical blocks and target which is used to map them to
24 {start} {length} {target} | {device} {target parameters}
26 after | are target specific parameters listed.
28 Functions available to dm device:
29 load, unload, table_status.
32 List of available ioct calls
58 sends libdevmapper ioctl protocol version to kernel and ask for kernel version.
59 If major and minor numbers are good we can continue.
68 This ioctl will remove all DM devices/tables from DM driver.
74 out: List of structures describing all devices created in driver.
77 List all devices created in driver. (linux use struct dm_name_list)
80 Kernel driver will place list of struct dm_name_list behind
81 struct dm_ioctl in userspace. Kernel driver will list through
82 the all devices and copyout info about them.
86 in: struct dm-ioctl(name/uuid)
91 Create device in dm driver, with specified name/uuid(uuid is prefered).
92 (linux use struct dm_name_list)
96 in: struct dm-ioctl(name/uuid)
101 Remove device from dm driver list, also remove device tables.
105 in: struct dm-ioctl(name/uuid) and string found after dm-ioctl struct in buffer
110 Rename device from name to string.
113 Kernel driver will find device with name from struct dm_ioctl-name/uuid.
114 Change name of selected device to string foun behind struc dm_ioctl header
119 in: dm-ioctl(name/uuid)
124 Suspend all io's on device, after this ioctl. Already started io's will be done.
125 Newer can't be started.
129 in: dm-ioctl(name/uuid)
131 out: dm-ioctl (minor,open_count,target_count)
134 Return status info about selected device
137 Kernel driver will find device with name from struct dm_ioctl-name/uuid.
138 Change values minor,open_count,target_count in dm_ioctl struct for
143 in: dm-ioctl(name/uuid)
148 Wait for device event to happen.
152 in: dm-ioctl(name/uuid),table specification
157 Load table to selected device. Table is loaded to unused slot and than switched.
158 (linux use struct dm_target_spec)
161 Kernel driver will find device with name from struct dm_ioctl-name/uuid.
162 Table is added to the inactive slot. Every device can have more than one
163 table loaded. Tables are stored in SLIST. This ioctl also open physical
164 device spedcified in table and add it to dm_device specific pdev list.
168 in: dm-ioctl(name/uuid)
173 Remove table from unused slot.
177 in: dm-ioctl(name/uuid)
179 out: list of dependiences devices
182 Return set of device dependiences e.g. mirror device for mirror target etc..
186 in: dm-ioctl(name/uuid)
188 out: list of used tables from selected devices (linux use struct dm_target_spec)
191 List all tables in active slot in device with name name/uuid.
194 Kernel driver will find device with name from struct dm_ioctl-name/uuid.
195 DM driver will copyout dm_target_spec structures behidn struct dm_ioctl.
201 out: list of all targets in device-mapper driver (linux use struct dm_target_versions)
204 List all available targets to libdevmapper.
207 Kernel driver will copy out known target versions.
211 in: message to driver (linux use struct dm_target_msg)
216 Send message to kernel driver target.
219 16) DM_DEV_SET_GEOMETRY
222 Set geometry of device-mapper driver.
225 NetBSD device-mapper driver implementation
227 device-mapper devices -> devs dm_dev.c
229 This entity is created with DM_DEV_CREATE ioctl, and stores info
230 about every device in device mapper driver. It has two slots for
231 active and inactive table, list of active physical devices added
232 to this device and list of upcalled devices (for targets which use
233 more than one physical device e.g. mirror, snapshot etc..).
235 device-mapper physical devices -> pdevs dm_pdev.c
237 This structure contains opened device VNODES. Because I physical
238 device can be found in more than one table loaded to different
239 dm devices. When device is destroyed I decrement all reference
240 counters for all added pdevs (I remove pdevs with ref_cnt == 0).
242 device-mapper tables -> table dm_table.c, dm_ioctl.c
244 Table describe how is dm device made. What blocks are mapped with
245 what target. In our implementation every table contains pointer to
246 target specific config data. These config_data are allocated in
247 DM_TABLE_LOAD function with target_init routine. Every table
248 contains pointer to used target.
250 device-mapper targets -> target dm_target.c
252 Target describes mapping of logical blocks to physical. It has
253 function pointers to function which does init, strategy, destroy,
256 P.S I want to thank reinod@ for great help and guidance :).
260 Desing of new device-mapper ioctl interface
262 Basic architecture of device-mapper -> libdevmapper ioctl interface is this.
263 Libdevmapper allocate buffer with size of data_size. At the start of this buffer
264 dm-ioctl structure is placed. any aditional information from/to kernel are placed
265 behind end (start of data part is pointed with data_start var.) of dm-ioctl struct.
267 Kernel driver then after ioctl call have to copyin data from userspace to kernel.
268 When kernel driver want to send data back to user space library it must copyout
271 1) In Linux device-mapper ioctl interface implementation there are these ioctls.
290 * means implemented in current version of NetBSD device-mapper.
292 1a) struct dm_ioctl based ioctl calls
293 These ioctl calls communicate only with basic dm_ioctl structure.
302 uint32_t version[3]; /* device-mapper kernel/userspace version */
303 uint32_t data_size; /* total size of data passed in
304 * including this struct */
306 uint32_t data_start; /* offset to start of data
307 * relative to start of this struct */
309 uint32_t target_count; /* in/out */ /* This should be set when DM_TABLE_STATUS is called */
310 int32_t open_count; /* device open count */
311 uint32_t flags; /* information flags */
312 uint32_t event_nr; /* event counters not implemented */
315 uint64_t dev; /* dev_t */
317 char name[DM_NAME_LEN]; /* device name */
318 char uuid[DM_UUID_LEN]; /* unique identifier for
319 * the block device */
321 void *user_space_addr; /*this is needed for netbsd
322 because they differently
323 implement ioctl syscall*/
326 As SOC task I want to replace this structure with proplib dict. Proplib dict
327 basic structure should be:
329 Note: I don't need data_star, data_size and use_space_addr. They are needed
330 for current implementation.
336 <key>target_count</key>
339 <key>open_count</key>
359 <!-- ioctl specific data -->
363 1b) DM_LIST_VERSIONS ioctl
365 This ioctl is used to get list of supported targets from kernel. Target
366 define mapping of Logical blocks to physical blocks on real device.
367 There are linear, zero, error, mirror, snapshot, multipath etc... targets.
369 For every target kernel driver should copyout this structure to userspace.
373 struct dm_target_versions {
380 Because I need more then on dm_target_version I will need one major proplib
381 dictionary to store children dictionaries with target data.
395 This ioctl is used to list all devices defined in kernel driver.
399 struct dm_name_list {
401 uint32_t next; /* offset to the next record from
402 the _start_ of this */
406 Again because I can have more than one device in kernel driver I need one parent
407 dictionary and more children dictionaries.
412 <integer>...</integer>
420 This ioctl is called when libdevmapper want to rename device-mapper device.
421 Libdevmapper library appends null terminated string to dm_ioctl struct in
429 2c) DM_DEV_CREATE, DM_DEV_REMOVE, DM_DEV_STATUS
430 Modify only dm_ioctl structure so I don't need to specify new structures.
433 3a) DM_TABLE_LOAD, DM_TABLE_STATUS
434 DM_TABLE_LOAD ioctl loads table to device. DM_TABLE_STATUS send info about
435 every table for selected device to userspace. Table is different for every
436 target basic table structure is this
438 {start} {length} {target} {additional information}
443 0 100 linear /dev/wdba 384
447 struct dm_target_spec {
448 uint64_t sector_start;
450 int32_t status; /* used when reading from kernel only */
454 char target_type[DM_MAX_TYPE_NAME];
457 * Parameter string starts immediately after this object.
458 * Be careful to add padding after string to ensure correct
459 * alignment of subsequent dm_target_spec.
464 <key>sector_start</key>
465 <integer>...</integer>
468 <integer>...</integer>
470 <key>target_type</key>
473 <key>aditional info</key>