Block device locking (was Re: mkswap & swapon) ("
Fri, 20 Feb 1998 12:49:16 -0700

Perhaps what is needed is a device locking mechanism. I am not
refering to file locking; POSIX implementations should handle that.
I mean locking on device major and minor codes. Aside from the
link issues, you could also cause the same problem (and currently
have no way of correcting or working around it that I know of) if
you were to use mknod to create another device with the same
major and minor codes. For example, if the swap partition were
/dev/hda3, that block device has a major/minor of 3 and 3. One
could create another device for that major/minor with the command
'mknod ~/swap b 3 3' and get around any locking mechanism using
i_count and d_count. (And any other that I know of!)

Obviously, using mknod is not going to be as a common situation as
the ln issues will be. However, if you truely want to lock a device for
exclusive access, it must be absolute locking and that can only be
done by locking the major/minor codes.

Phil Burr

>1. swapon
>People complain to me that under recent kernels it is
>possible to do "swapon foo" on the same file twice,
>and twice some amount is added to the available swap.
>No, this is not a bug in the swapon which I maintain;
>it is a kernel bug present in 2.1.87 but not in 2.0.33.
>I wondered how to fix it but was not sure how to express
>the property of not being in use under the 2.1.* regime.
>In the good old days, testing i_count = 1 would suffice.
>Today, testing d_count = 1 is not enough, because two
>names can refer to the same file, and
> ln foo bar; swapon foo; swapon bar
>would succeed incorrectly.
>On the other hand, testing i_count = 1 is no good either.
>Indeed, i_count has become next to meaningless: there can
>always be dentries that refer to the inode. Thus,
> ln foo bar; swapon foo
>would fail because two dentries refer to the inode of foo.
>How does one express that a file is not in use?
>(In case anyone answers, cc to; I do not read linux-kernel.)

To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to