md: factor out init code for an mddev
authorNeilBrown <neilb@suse.de>
Thu, 1 Apr 2010 04:55:30 +0000 (15:55 +1100)
committerNeilBrown <neilb@suse.de>
Tue, 18 May 2010 05:27:55 +0000 (15:27 +1000)
This is a simple factorisation that makes mddev_find easier to read.

Signed-off-by: NeilBrown <neilb@suse.de>
drivers/md/md.c

index 2e05b0c2515d2a5d57d6585c06aca0eb9c85cf60..d3579fc9efedd3afd4392fc75b7d4f5fa39d86b4 100644 (file)
@@ -416,6 +416,27 @@ static void mddev_put(mddev_t *mddev)
        spin_unlock(&all_mddevs_lock);
 }
 
+static void mddev_init(mddev_t *mddev)
+{
+       mutex_init(&mddev->open_mutex);
+       mutex_init(&mddev->reconfig_mutex);
+       mutex_init(&mddev->bitmap_info.mutex);
+       INIT_LIST_HEAD(&mddev->disks);
+       INIT_LIST_HEAD(&mddev->all_mddevs);
+       init_timer(&mddev->safemode_timer);
+       atomic_set(&mddev->active, 1);
+       atomic_set(&mddev->openers, 0);
+       atomic_set(&mddev->active_io, 0);
+       spin_lock_init(&mddev->write_lock);
+       atomic_set(&mddev->flush_pending, 0);
+       init_waitqueue_head(&mddev->sb_wait);
+       init_waitqueue_head(&mddev->recovery_wait);
+       mddev->reshape_position = MaxSector;
+       mddev->resync_min = 0;
+       mddev->resync_max = MaxSector;
+       mddev->level = LEVEL_NONE;
+}
+
 static mddev_t * mddev_find(dev_t unit)
 {
        mddev_t *mddev, *new = NULL;
@@ -482,23 +503,7 @@ static mddev_t * mddev_find(dev_t unit)
        else
                new->md_minor = MINOR(unit) >> MdpMinorShift;
 
-       mutex_init(&new->open_mutex);
-       mutex_init(&new->reconfig_mutex);
-       mutex_init(&new->bitmap_info.mutex);
-       INIT_LIST_HEAD(&new->disks);
-       INIT_LIST_HEAD(&new->all_mddevs);
-       init_timer(&new->safemode_timer);
-       atomic_set(&new->active, 1);
-       atomic_set(&new->openers, 0);
-       atomic_set(&new->active_io, 0);
-       spin_lock_init(&new->write_lock);
-       atomic_set(&new->flush_pending, 0);
-       init_waitqueue_head(&new->sb_wait);
-       init_waitqueue_head(&new->recovery_wait);
-       new->reshape_position = MaxSector;
-       new->resync_min = 0;
-       new->resync_max = MaxSector;
-       new->level = LEVEL_NONE;
+       mddev_init(new);
 
        goto retry;
 }