]> git.karo-electronics.de Git - karo-tx-linux.git/blobdiff - drivers/md/dm.c
Merge branch 'cpus4096-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git...
[karo-tx-linux.git] / drivers / md / dm.c
index dd953b189f459288b576fedcd6b42a29931f76c9..51ba1db4b3e7e7abf59d6b183fc610e8bdc0db04 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Copyright (C) 2001, 2002 Sistina Software (UK) Limited.
- * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved.
+ * Copyright (C) 2004-2008 Red Hat, Inc. All rights reserved.
  *
  * This file is released under the GPL.
  */
@@ -167,6 +167,9 @@ struct mapped_device {
 
        /* forced geometry settings */
        struct hd_geometry geometry;
+
+       /* sysfs handle */
+       struct kobject kobj;
 };
 
 #define MIN_IOS 256
@@ -977,8 +980,6 @@ static int dm_any_congested(void *congested_data, int bdi_bits)
        struct mapped_device *md = congested_data;
        struct dm_table *map;
 
-       atomic_inc(&md->pending);
-
        if (!test_bit(DMF_BLOCK_IO, &md->flags)) {
                map = dm_get_table(md);
                if (map) {
@@ -987,10 +988,6 @@ static int dm_any_congested(void *congested_data, int bdi_bits)
                }
        }
 
-       if (!atomic_dec_return(&md->pending))
-               /* nudge anyone waiting on suspend queue */
-               wake_up(&md->wait);
-
        return r;
 }
 
@@ -1250,10 +1247,12 @@ static int __bind(struct mapped_device *md, struct dm_table *t)
 
        if (md->suspended_bdev)
                __set_size(md, size);
-       if (size == 0)
+
+       if (!size) {
+               dm_table_destroy(t);
                return 0;
+       }
 
-       dm_table_get(t);
        dm_table_event_callback(t, event_callback, md);
 
        write_lock(&md->map_lock);
@@ -1275,7 +1274,7 @@ static void __unbind(struct mapped_device *md)
        write_lock(&md->map_lock);
        md->map = NULL;
        write_unlock(&md->map_lock);
-       dm_table_put(map);
+       dm_table_destroy(map);
 }
 
 /*
@@ -1289,6 +1288,8 @@ int dm_create(int minor, struct mapped_device **result)
        if (!md)
                return -ENXIO;
 
+       dm_sysfs_init(md);
+
        *result = md;
        return 0;
 }
@@ -1364,6 +1365,7 @@ void dm_put(struct mapped_device *md)
                        dm_table_presuspend_targets(map);
                        dm_table_postsuspend_targets(map);
                }
+               dm_sysfs_exit(md);
                dm_table_put(map);
                __unbind(md);
                free_dev(md);
@@ -1703,6 +1705,27 @@ struct gendisk *dm_disk(struct mapped_device *md)
        return md->disk;
 }
 
+struct kobject *dm_kobject(struct mapped_device *md)
+{
+       return &md->kobj;
+}
+
+/*
+ * struct mapped_device should not be exported outside of dm.c
+ * so use this check to verify that kobj is part of md structure
+ */
+struct mapped_device *dm_get_from_kobject(struct kobject *kobj)
+{
+       struct mapped_device *md;
+
+       md = container_of(kobj, struct mapped_device, kobj);
+       if (&md->kobj != kobj)
+               return NULL;
+
+       dm_get(md);
+       return md;
+}
+
 int dm_suspended(struct mapped_device *md)
 {
        return test_bit(DMF_SUSPENDED, &md->flags);