Skip to contentSkip to conversation

Does dm avoid container/member loops?

DISCUSSION Neil Brown 2 participants 2 messages Oct 5, 2006 Device mapper

lore
Share & tools
lore

Neil Brown

author
#0 lore raw

Hi,
I came across an issue with md just recently that could affect dm and thought I would ask if dm does anything about it.

As both dm and md create a block device using other block devices as components, and as components can be added after creation, it is theoretically possible to create a loop.
e.g.
md0 is a raid0 containing md1 and md2
md0 could be hot-added as a spare to md1.

This can create obvious problems such as infinite recursion in called to issue_flush_fn (just as one example).

Presumably exactly the same sort of loop could be attempted with dm. Does dm do anything to detect or disable such loops?

This simplest general approach that I could think of is to add loop_detect_fn to 'struct request_queue' which takes a request_queue pointer and returns true (of there is a loop) or false. Then before (or maybe just after) you attach A as a member of B you call
A->loop_detect_fn(A, B)
And fail if the result is non-zero.

The default loop_detect_fn returns 0.
md and dm provide a loop_detect_fn something like:

    my_loop_detect(struct request_queue *me, struct request_queue *top)
    {
	rv = 0;
	if (me == top)
		return 1;
	lock access to list of components.
        for each component
		rv |= component->loop_detect_fn(component, top);
	unlock
	return rv;
     }

This would probably give lockdep a major headache, but should detect loops reliably, including loops involving both md and dm.

Thoughts?

Thanks,
NeilBrown

#1 lore raw
Quoted 3 lines · Neil Brown

As both dm and md create a block device using other block devices as components, and as components can be added after creation, it is theoretically possible to create a loop.

Userspace LVM2 code takes steps to catch the most likely cases:
exclusive open is required to create a PV;
device-mapper dependencies are checked for loops when adding a PV to a VG.

The general problem is harder as you also have to track through filesystems (losetup) etc.

Quoted 2 lines

This would probably give lockdep a major headache, but should detect loops reliably, including loops involving both md and dm.

I reckon the solution involves bd_claim* preventing loops in the device dependency tree.

Alasdair

Signature · 1 line
[email protected]