Skip to contentSkip to conversation

True number of device openers in 2.5

DISCUSSION Andrey Borzenkov 2 participants 3 messages Jun 12, 2003 – Jun 17, 2003

lore
Share & tools
lore
#0 lore raw

For single-partition devices it is just bd_openers but I am more intersted in multi-partition case. Here I need to know about sum of opens for all partitions including the whole device. It appears that for a container bd_openers is incremented for every open of itself and for the _first_ open of partition and bd_part_count is incremented for every (including first) open of partition. So bdev->bd_contains->bd_openers + bdev->bd_contains->bd_part_count really gives an access (number of opened partitions but this is unknown otherwise).

Thank you

-andrey

#1 lore raw
Quoted 8 lines · Andrey Borzenkov

For single-partition devices it is just bd_openers but I am more intersted in multi-partition case. Here I need to know about sum of opens for all partitions including the whole device. It appears that for a container bd_openers is incremented for every open of itself and for the _first_ open of partition and bd_part_count is incremented for every (including first) open of partition. So bdev->bd_contains->bd_openers + bdev->bd_contains->bd_part_count really gives an access (number of opened partitions but this is unknown otherwise).

There is no way to get anything useful out of that. _Any_ kernel code that relies on such counters to tell if there's somebody else who might've accessed the thing does not account for the fact that fork() and dup() do not go beyond the struct file.

IOW, any place that does

	if (number of openers == 1)
		do something that breaks if IO is going on
is FUBAR.  Variant with
	if (number of openers == 0)
		block ->open()
		do something ...

will work, but it means that we are not triggering it from ioctl() on that device. And here we only care about zero/non-zero, so ->bd_openers on the entire disk will do just fine.

#2 lore raw
Quoted 15 lines · On Thursday 12 June 2003 20:37, [email protected] wrote:
Quoted 8 lines · Andrey Borzenkov

For single-partition devices it is just bd_openers but I am more intersted in multi-partition case. Here I need to know about sum of opens for all partitions including the whole device. It appears that for a container bd_openers is incremented for every open of itself and for the _first_ open of partition and bd_part_count is incremented for every (including first) open of partition. So bdev->bd_contains->bd_openers + bdev->bd_contains->bd_part_count really gives an access (number of opened partitions but this is unknown otherwise).

There is no way to get anything useful out of that. _Any_ kernel code that relies on such counters to tell if there's somebody else who might've accessed the thing does not account for the fact that fork() and dup() do not go beyond the struct file.

Quoted 4 lines

IOW, any place that does

	if (number of openers == 1)
		do something that breaks if IO is going on

is FUBAR. Variant with

Hmm ... this is exactly what EJECT ioctls for some removables do. ide-floppy and cdrom for sure. sd does not do it because it does not actually support atomic EJECT ioctl so far. I am not interested in anything more than that.

Quoted 6 lines
	if (number of openers == 0)
		block ->open()
		do something ...

will work, but it means that we are not triggering it from ioctl() on that device. And here we only care about zero/non-zero, so ->bd_openers on the entire disk will do just fine.

My concern is EJECT implemetation. So far EJECT was handled by individual drivers that used private usage counters to decide when drive was free. Now CDEJECT is moved into drivers/block/scsi_ioctl.c which means that at least for IDE and SCSI removables device driver is never entered here. I am looking for reliable method to detect busy device on block layer - and yes, the code is triggered from ioctl (mostly).

regards

-andrey