mutex_lock(&mddev->open_mutex);
        if ((mddev->pers && atomic_read(&mddev->openers) > !!bdev) ||
            mddev->sync_thread ||
-           test_bit(MD_RECOVERY_RUNNING, &mddev->recovery) ||
-           (bdev && !test_bit(MD_STILL_CLOSED, &mddev->flags))) {
+           test_bit(MD_RECOVERY_RUNNING, &mddev->recovery)) {
                printk("md: %s still in use.\n",mdname(mddev));
                if (did_freeze) {
                        clear_bit(MD_RECOVERY_FROZEN, &mddev->recovery);
        if ((mddev->pers && atomic_read(&mddev->openers) > !!bdev) ||
            mddev->sysfs_active ||
            mddev->sync_thread ||
-           test_bit(MD_RECOVERY_RUNNING, &mddev->recovery) ||
-           (bdev && !test_bit(MD_STILL_CLOSED, &mddev->flags))) {
+           test_bit(MD_RECOVERY_RUNNING, &mddev->recovery)) {
                printk("md: %s still in use.\n",mdname(mddev));
                mutex_unlock(&mddev->open_mutex);
                if (did_freeze) {
                        err = -EBUSY;
                        goto out;
                }
-               set_bit(MD_STILL_CLOSED, &mddev->flags);
+               set_bit(MD_CLOSING, &mddev->flags);
                mutex_unlock(&mddev->open_mutex);
                sync_blockdev(bdev);
        }
        if ((err = mutex_lock_interruptible(&mddev->open_mutex)))
                goto out;
 
+       if (test_bit(MD_CLOSING, &mddev->flags)) {
+               mutex_unlock(&mddev->open_mutex);
+               return -ENODEV;
+       }
+
        err = 0;
        atomic_inc(&mddev->openers);
-       clear_bit(MD_STILL_CLOSED, &mddev->flags);
        mutex_unlock(&mddev->open_mutex);
 
        check_disk_change(bdev);
 
 #define MD_CHANGE_PENDING 2    /* switch from 'clean' to 'active' in progress */
 #define MD_UPDATE_SB_FLAGS (1 | 2 | 4) /* If these are set, md_update_sb needed */
 #define MD_ARRAY_FIRST_USE 3    /* First use of array, needs initialization */
-#define MD_STILL_CLOSED        4       /* If set, then array has not been opened since
-                                * md_ioctl checked on it.
-                                */
+#define MD_CLOSING     4       /* If set, we are closing the array, do not open
+                                * it then */
 #define MD_JOURNAL_CLEAN 5     /* A raid with journal is already clean */
 #define MD_HAS_JOURNAL 6       /* The raid array has journal feature set */
 #define MD_RELOAD_SB   7       /* Reload the superblock because another node