]> git.kernelconcepts.de Git - karo-tx-linux.git/commitdiff
md: initialise ->writes_pending in personality modules.
authorNeilBrown <neilb@suse.com>
Mon, 5 Jun 2017 06:05:13 +0000 (16:05 +1000)
committerShaohua Li <shli@fb.com>
Mon, 5 Jun 2017 23:04:35 +0000 (16:04 -0700)
The new per-cpu counter for writes_pending is initialised in
md_alloc(), which is not called by dm-raid.
So dm-raid fails when md_write_start() is called.

Move the initialization to the personality modules
that need it.  This way it is always initialised when needed,
but isn't unnecessarily initialized (requiring memory allocation)
when the personality doesn't use writes_pending.

Reported-by: Heinz Mauelshagen <heinzm@redhat.com>
Fixes: 4ad23a976413 ("MD: use per-cpu counter for writes_pending")
Signed-off-by: NeilBrown <neilb@suse.com>
Signed-off-by: Shaohua Li <shli@fb.com>
drivers/md/md.c
drivers/md/md.h
drivers/md/raid1.c
drivers/md/raid10.c
drivers/md/raid5.c

index 212a6777ff3172dd9e20401dd7bf87ad5d2f7468..87edc342ccb3d5c51bb45313f1218f9839528917 100644 (file)
@@ -5174,6 +5174,18 @@ static void mddev_delayed_delete(struct work_struct *ws)
 
 static void no_op(struct percpu_ref *r) {}
 
+int mddev_init_writes_pending(struct mddev *mddev)
+{
+       if (mddev->writes_pending.percpu_count_ptr)
+               return 0;
+       if (percpu_ref_init(&mddev->writes_pending, no_op, 0, GFP_KERNEL) < 0)
+               return -ENOMEM;
+       /* We want to start with the refcount at zero */
+       percpu_ref_put(&mddev->writes_pending);
+       return 0;
+}
+EXPORT_SYMBOL_GPL(mddev_init_writes_pending);
+
 static int md_alloc(dev_t dev, char *name)
 {
        /*
@@ -5239,10 +5251,6 @@ static int md_alloc(dev_t dev, char *name)
        blk_queue_make_request(mddev->queue, md_make_request);
        blk_set_stacking_limits(&mddev->queue->limits);
 
-       if (percpu_ref_init(&mddev->writes_pending, no_op, 0, GFP_KERNEL) < 0)
-               goto abort;
-       /* We want to start with the refcount at zero */
-       percpu_ref_put(&mddev->writes_pending);
        disk = alloc_disk(1 << shift);
        if (!disk) {
                blk_cleanup_queue(mddev->queue);
index 11f15146ce5177de0468c706a5f82a037b42c132..0fa1de42c42bcb328276a42fc56809d53217a285 100644 (file)
@@ -648,6 +648,7 @@ extern void md_unregister_thread(struct md_thread **threadp);
 extern void md_wakeup_thread(struct md_thread *thread);
 extern void md_check_recovery(struct mddev *mddev);
 extern void md_reap_sync_thread(struct mddev *mddev);
+extern int mddev_init_writes_pending(struct mddev *mddev);
 extern void md_write_start(struct mddev *mddev, struct bio *bi);
 extern void md_write_inc(struct mddev *mddev, struct bio *bi);
 extern void md_write_end(struct mddev *mddev);
index af5056d568788a53f6c3a2456a353cba3bbfe35a..e1a7e3d4c5e4f17d0dedb4f171ad3bd47ff70022 100644 (file)
@@ -3063,6 +3063,8 @@ static int raid1_run(struct mddev *mddev)
                        mdname(mddev));
                return -EIO;
        }
+       if (mddev_init_writes_pending(mddev) < 0)
+               return -ENOMEM;
        /*
         * copy the already verified devices into our private RAID1
         * bookkeeping area. [whatever we allocate in run(),
index 4343d7ff9916bee9a9a399572c2bd3313723fa3a..797ed60abd5e27cd2f32d0f80d36c660ed1e4419 100644 (file)
@@ -3611,6 +3611,9 @@ static int raid10_run(struct mddev *mddev)
        int first = 1;
        bool discard_supported = false;
 
+       if (mddev_init_writes_pending(mddev) < 0)
+               return -ENOMEM;
+
        if (mddev->private == NULL) {
                conf = setup_conf(mddev);
                if (IS_ERR(conf))
index 722064689e822f3b876411f076921e244abbec2f..ec0f951ae19fbc8fa392306b7c6c45a38f3eb0e4 100644 (file)
@@ -7118,6 +7118,9 @@ static int raid5_run(struct mddev *mddev)
        long long min_offset_diff = 0;
        int first = 1;
 
+       if (mddev_init_writes_pending(mddev) < 0)
+               return -ENOMEM;
+
        if (mddev->recovery_cp != MaxSector)
                pr_notice("md/raid:%s: not clean -- starting background reconstruction\n",
                          mdname(mddev));