Re: [dm-devel] [PATCH 2.6.19 5/5] fs: freeze_bdev with semaphorenot mutex

From: Eric Sandeen
Date: Tue Nov 07 2006 - 15:23:38 EST


Mike Snitzer wrote:
> On 11/7/06, Alasdair G Kergon <agk@xxxxxxxxxx> wrote:
>> From: Srinivasa Ds <srinivasa@xxxxxxxxxx>
>>
>> On debugging I found out that,"dmsetup suspend <device name>" calls
>> "freeze_bdev()",which locks "bd_mount_mutex" to make sure that no new mounts
>> happen on bdev until thaw_bdev() is called. This "thaw_bdev()" is getting
>> called when we resume the device through "dmsetup resume <device-name>".
>> Hence we have 2 processes,one of which locks "bd_mount_mutex"(dmsetup
>> suspend) and another(dmsetup resume) unlocks it.
>
> Srinivasa's description of the patch just speaks to how freeze_bdev
> and thaw_bdev are used by DM but completely skips justification for
> switching from mutex to semaphore. Why is it beneficial and/or
> necessary to use a semaphore instead of a mutex here?

Because mutexes are not supposed to be released by anything other than
the thread that took them, as enforced by the various checking code and
noted in the docs...

"The stricter mutex API means you cannot use mutexes the same way you
can use semaphores: e.g. they cannot be used from an interrupt context,
nor can they be unlocked from a different context that which acquired
it."

this particular resource can sometimes be locked & unlocked from 2
different userspace threads.

-Eric
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/