device-mapper: fix mirror log type module ref count

From: Alasdair G Kergon
Date: Fri Jan 21 2005 - 13:00:17 EST


Fix module reference counting for mirror log type.

Signed-Off-By: Alasdair G Kergon <agk@xxxxxxxxxx>
--- diff/drivers/md/dm-log.c 2005-01-12 15:21:22.000000000 +0000
+++ source/drivers/md/dm-log.c 2005-01-12 18:55:17.000000000 +0000
@@ -17,9 +17,6 @@

int dm_register_dirty_log_type(struct dirty_log_type *type)
{
- if (!try_module_get(type->module))
- return -EINVAL;
-
spin_lock(&_lock);
type->use_count = 0;
list_add(&type->list, &_log_types);
@@ -34,10 +31,8 @@

if (type->use_count)
DMWARN("Attempt to unregister a log type that is still in use");
- else {
+ else
list_del(&type->list);
- module_put(type->module);
- }

spin_unlock(&_lock);

@@ -51,6 +46,10 @@
spin_lock(&_lock);
list_for_each_entry (type, &_log_types, list)
if (!strcmp(type_name, type->name)) {
+ if (!type->use_count && !try_module_get(type->module)){
+ spin_unlock(&_lock);
+ return NULL;
+ }
type->use_count++;
spin_unlock(&_lock);
return type;
@@ -63,7 +62,8 @@
static void put_type(struct dirty_log_type *type)
{
spin_lock(&_lock);
- type->use_count--;
+ if (!--type->use_count)
+ module_put(type->module);
spin_unlock(&_lock);
}

-
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/