md: Fix stray --cluster-confirm crash
authorGoldwyn Rodrigues <rgoldwyn@suse.de>
Mon, 2 Mar 2015 16:55:49 +0000 (10:55 -0600)
committerNeilBrown <neilb@suse.de>
Fri, 20 Mar 2015 23:33:00 +0000 (10:33 +1100)
A --cluster-confirm without an --add (by another node) can
crash the kernel.

Fix it by guarding it using a state.

Signed-off-by: Goldwyn Rodrigues <rgoldwyn@suse.com>
Signed-off-by: NeilBrown <neilb@suse.de>
drivers/md/md-cluster.c
drivers/md/md-cluster.h
drivers/md/md.c

index 03e521a9ca7d67bc48052f5edd45e1a9a4222a11..96679b22cfc014751f54029c34222a6e343de236 100644 (file)
@@ -42,6 +42,10 @@ struct resync_info {
        __le64 hi;
 };
 
+/* md_cluster_info flags */
+#define                MD_CLUSTER_WAITING_FOR_NEWDISK          1
+
+
 struct md_cluster_info {
        /* dlm lock space and resources for clustered raid. */
        dlm_lockspace_t *lockspace;
@@ -61,6 +65,7 @@ struct md_cluster_info {
        struct dlm_lock_resource *no_new_dev_lockres;
        struct md_thread *recv_thread;
        struct completion newdisk_completion;
+       unsigned long state;
 };
 
 enum msg_type {
@@ -380,9 +385,11 @@ static void process_add_new_disk(struct mddev *mddev, struct cluster_msg *cmsg)
        snprintf(raid_slot, 16, "RAID_DISK=%d", cmsg->raid_slot);
        pr_info("%s:%d Sending kobject change with %s and %s\n", __func__, __LINE__, disk_uuid, raid_slot);
        init_completion(&cinfo->newdisk_completion);
+       set_bit(MD_CLUSTER_WAITING_FOR_NEWDISK, &cinfo->state);
        kobject_uevent_env(&disk_to_dev(mddev->gendisk)->kobj, KOBJ_CHANGE, envp);
        wait_for_completion_timeout(&cinfo->newdisk_completion,
                        NEW_DEV_TIMEOUT);
+       clear_bit(MD_CLUSTER_WAITING_FOR_NEWDISK, &cinfo->state);
 }
 
 
@@ -832,13 +839,19 @@ static int add_new_disk_finish(struct mddev *mddev)
        return ret;
 }
 
-static void new_disk_ack(struct mddev *mddev, bool ack)
+static int new_disk_ack(struct mddev *mddev, bool ack)
 {
        struct md_cluster_info *cinfo = mddev->cluster_info;
 
+       if (!test_bit(MD_CLUSTER_WAITING_FOR_NEWDISK, &cinfo->state)) {
+               pr_warn("md-cluster(%s): Spurious cluster confirmation\n", mdname(mddev));
+               return -EINVAL;
+       }
+
        if (ack)
                dlm_unlock_sync(cinfo->no_new_dev_lockres);
        complete(&cinfo->newdisk_completion);
+       return 0;
 }
 
 static struct md_cluster_operations cluster_ops = {
index 60d7e58964f58e2d3bb0d81854186bee611aad3a..7417133c4295dbd13c4e9f18facf8a84e9f97c53 100644 (file)
@@ -21,7 +21,7 @@ struct md_cluster_operations {
        int (*area_resyncing)(struct mddev *mddev, sector_t lo, sector_t hi);
        int (*add_new_disk_start)(struct mddev *mddev, struct md_rdev *rdev);
        int (*add_new_disk_finish)(struct mddev *mddev);
-       void (*new_disk_ack)(struct mddev *mddev, bool ack);
+       int (*new_disk_ack)(struct mddev *mddev, bool ack);
 };
 
 #endif /* _MD_CLUSTER_H */
index ae3432e57ccb1d1c74346d5b68ed2204e4f5f921..eb6f92e57ab6aac8f1d532f89cb06ad7f4942c6b 100644 (file)
@@ -5755,7 +5755,7 @@ static int add_new_disk(struct mddev *mddev, mdu_disk_info_t *info)
 
        if (mddev_is_clustered(mddev) &&
                !(info->state & ((1 << MD_DISK_CLUSTER_ADD) | (1 << MD_DISK_CANDIDATE)))) {
-               pr_err("%s: Cannot add to clustered mddev. Try --cluster-add\n",
+               pr_err("%s: Cannot add to clustered mddev.\n",
                               mdname(mddev));
                return -EINVAL;
        }
@@ -5853,7 +5853,11 @@ static int add_new_disk(struct mddev *mddev, mdu_disk_info_t *info)
                        if (info->state & (1 << MD_DISK_CANDIDATE)) {
                                /* Through --cluster-confirm */
                                set_bit(Candidate, &rdev->flags);
-                               md_cluster_ops->new_disk_ack(mddev, true);
+                               err = md_cluster_ops->new_disk_ack(mddev, true);
+                               if (err) {
+                                       export_rdev(rdev);
+                                       return err;
+                               }
                        } else if (info->state & (1 << MD_DISK_CLUSTER_ADD)) {
                                /* --add initiated by this node */
                                err = md_cluster_ops->add_new_disk_start(mddev, rdev);