1

Thinking about student projects to advise; I'm an OK C develepor and C++ developer/architect. Not done much Linux kernel development beyond "write your first module".

The thing I want to rudimentarily implement (before advising students doing it properly as a team project) is:

  • Take existing block device, say /dev/sda
  • add second block device, say /dev/fec0, which implements wrapper around first, providing error-correction on read and writing data + error coding information on write

This implies that the size of fec0 is smaller than that of sda. Also, note that this is somewhat different to the RAID5 approach, as there's no split of parity data to secondary data groups or similar.

Now, I'm trying to get an overview of how to do this. It's clear that it will be necessary, aside from implementing the block device interface itself, to implement a control interface to define things like "use /dev/sda to create fec0", "shut down fec0".

The questions that arise are:

  • Is there a preferred framework to integrate this into? Goal is finding the sensible place to put this. To mind come:
    • dmraid and
    • lvm2, or
    • just a plain block device driver
  • How to implement control interfacing?
    • Specific ioctls?
    • /sys/* pseudofile interface?
    • framework-specific ways?
Marcus Müller
  • 34,677
  • 4
  • 53
  • 94
  • just a suggestion, but a) the framework should be the same as the one that you're wrapping over b) kernel.org can get you started on ioclts and sysfs – secret squirrel Aug 01 '20 at 08:34
  • @secretsquirrel thanks! a) but I'm not "wrapping a framework", I'm wrapping an arbitrary block device. b) I know what ioctls and sysfs are – I'm wondering what a good choice for controlling this kind of function is. – Marcus Müller Aug 01 '20 at 08:35
  • lol OK badly worded: so, the framework should depend on the subsystem; kernel.org has some pointers as to when and why you should or shouldn't use ioctls etc. Although "input output control" and "system file system", "config file system" are kind of self explanatory; Linux is very plain and literal when it comes to naming. – secret squirrel Aug 01 '20 at 08:48
  • @secretsquirrel ha! Well, I must also admit I might have badly worded my comment: I'm not even sure which subsystem I should be working in. Storage? Is that even a subsystem or way too meta? EDAC (doesn't seem like it, but maybe?)? MTD? Or maybe the intent is better represented as VFS with but a single file (the error-correct block dev)? Where does DM/Raid even live? – Marcus Müller Aug 01 '20 at 09:41
  • raid is in the drivers/md subsystem, I guess it depends in how much pain you want to inflict on your students: a wrapper over a single block device should be in block, as by definition md is multiple device, IMO. But if you want them to handle multiple devices then md. – secret squirrel Aug 01 '20 at 10:06
  • Hm, really sounds like it should be in block; for the time being, it'd be single-device (or multiple-physical-devices-represented-as-one via dm or lvm); but I've got to admit putting it into drivers/md would be advantageous for autodetection and extensibility reasons. Hm. – Marcus Müller Aug 01 '20 at 10:57
  • @secretsquirrel care to put your comments into an answer so that I have something to work/upvote/accept? – Marcus Müller Aug 01 '20 at 10:57
  • Stack Overflow is a **bad place** for "where to start" sort of questions. And given question post just illustrates that: 1. Several questions are asked at once. 2. The question "Is there a preferred framework...?" is mostly a *recommendation* or *opinion-based* one. 3. The question "How to implement control interfacing?" is also an *opinion-based* one. – Tsyvarev Aug 01 '20 at 11:46
  • 1
    @Tsyarev, point taken, which is why I kept it to comments..but I put in an answer in the end, thanks Marcus Muller ;) I didn't see the question as a "where to start", but rather "which implementation is better" and there are solid technical references that keep responses from being opinion based. – secret squirrel Aug 01 '20 at 11:56

1 Answers1

1

For the first part of your question, I'd suggest you have two choices: the block subsystem or the md (multiple device) subsystem. I think the most useful thing I could do would be to point you in the direction of some references so you can decide what fits best. If you want to account for logical volumes then see here for the lvm-raid man page which sits in both the md and dm subsystems. If you just want to restrict yourself to RAID functionality, then see here for the md driver man page. But if you want to keep it simple and just make a wrapper over a simple block device, perhaps emulating some aspects of lvm and raid, then add a driver to the block subsystem.

Your choice would affect the second part of your question, too. Single block devices commonly provide lots of ioctls; md drivers make a lot of use of the sysfs interface. Hope that's helpful.

secret squirrel
  • 802
  • 9
  • 13