Skip to contentSkip to conversation

DMF_FREEING flag checking

DISCUSSION Mai N 2 participants 3 messages Mar 10, 2008 Device mapper

lore
Share & tools
lore

Mai N

author
#0 lore raw

Hi,

I think we need to check, in __get_uuid_cell() , DMF_FREEING flag, to cover the race condition that we are trying to get the device while others is freeing (or have freed) it, same check is needed in __get_name_cell()...

I noticed that the latest code does NOT check for this, does anyone know the reason for this? Or this is a potential bug?

static struct hash_cell *__get_uuid_cell(const char *str) {
+ struct mapped_device *md = NULL;

list_for_each_entry (hc, _uuid_buckets + h, uuid_list)
+ md = hc->md;
+ if ((!strcmp(hc->uuid, str)) &&
+ (md) && (!(test_bit(DMF_FREEING, &md->flags)))) {

- if (!strcmp(hc->uuid, str)) {
dm_get(hc->md);
}

Thanks for the information
Mai

---------------------------------
Looking for last minute shopping deals? Find them fast with Yahoo! Search.

#1 lore raw
Quoted 4 lines · Mai N

I think we need to check, in __get_uuid_cell() , DMF_FREEING flag, to cover the race condition that we are trying to get the device while others is freeing (or have freed) it, same check is needed in __get_name_cell()...

I don't ever recall any bug reports that could be ascribed to this. But I agree that it's not immediately obvious the code is correct.

So we need to find code paths that would cause a race, or write a test program to demonstrate it.

Quoted 4 lines

static struct hash_cell *__get_uuid_cell(const char *str) {
+ struct mapped_device *md = NULL;

Quoted 8 lines

list_for_each_entry (hc, _uuid_buckets + h, uuid_list)
+ md = hc->md;
+ if ((!strcmp(hc->uuid, str)) &&
+ (md) && (!(test_bit(DMF_FREEING, &md->flags)))) {

- if (!strcmp(hc->uuid, str)) {
dm_get(hc->md);
}

The fix would be need to be within dm.c to ensure dm_get() can't succeed while the final dm_put() is underway. The question is, are there any *actual* code paths which could lead to that happening, where existing locking/serialisation is inadequate?

Alasdair

Signature · 1 line
[email protected]
#2 lore raw
Quoted 3 lines · Alasdair G Kergon

The question is, are there any
*actual* code paths which could lead to that happening, where existing locking/serialisation is inadequate?

The final dm_put that triggers the deletion (md->holders dropping to 0) is in __hash_remove() while holding _hash_lock - so I don't think the dm_get() calls you mention can run in parallel.

There are other dm_get() calls outside _hash_lock, but I think the argument is that the code paths containing them can't be reached if the final dm_put() has started - they all require something to have the device open.

Alasdair

Signature · 1 line
[email protected]