[Tux3] Nontrivial example of ddlink usage

Daniel Phillips phillips at phunq.net
Thu Feb 26 00:26:02 PST 2009


This is a nontrivial example of ddlink usage, to implement the syntax of dmsetup, but using a considerably more compact and extensible kernel interface with better error reporting.

The do_create function provides the main device mapper functionality, that is creating a device that is composed of several underlying devices called targets.  Each target is specified by a set of strings, the first of which is the target type and rest being string parameters passed to the target's create method.

This ddlink interface employs both writes to the ddlink and ioctls on the ddlink.  Initially, an ioctl declares that a new device will be created and specifies the number of targets that it will be composed of along with some fixed data such as permissions.  (The ddsetup kernel code is perfectly capable of counting the number of targets itself, but the device mapper kernel code wants to know the final number of targets before creating any of them, for no apparent reason.)

For each target, the variable parameters (strings) are written to the ddlink one at a time, including the target name, followed by an ioctl that passes some fixed fields (sector offset and sector size, the former having no apparent purpose).  The ioctl creates the target internally and remembers it as internal ddsetup state.  After all the targets are created, the name of the new device is written to the ddlink and a final ioctl creates the device.

An error may be detected at any point in this somewhat complex process, in which case the ddsetup error handler reads the ddlink to obtain a detailed error message.

This is by no means the only way that the ddsetup interface could have been constructed using ddlink.  For example, instead of ioctling the ddlink, command codes could be written to the ddlink, either separate from or together with the string parameters.  However, a combination of writes and ioctls seemed to yield the simplest, easiest to read and modify userspace code.  The compactness and clarity of the example speaks for itself, at least I think so.  It would be instructive to compare this ddsetup.c code to the existing dmsetup and libdevmapper code that currently implements these interfaces.

Regards,

Daniel
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ddsetup.c
Type: text/x-csrc
Size: 7430 bytes
Desc: not available
URL: <http://phunq.net/pipermail/tux3/attachments/20090226/7355b2c9/attachment-0001.c>
-------------- next part --------------
_______________________________________________
Tux3 mailing list
Tux3 at tux3.org
http://mailman.tux3.org/cgi-bin/mailman/listinfo/tux3


More information about the Tux3 mailing list