***************
*** 333,339 ****
  	 * device if no resync is going on, or below the resync window.
  	 * We take the first readable disk when above the resync window.
  	 */
- 	if (conf->resync_mirrors && (this_sector + sectors >= conf->next_resync)) {
  		/* make sure that disk is operational */
  		new_disk = 0;
  		while (!conf->mirrors[new_disk].operational || conf->mirrors[new_disk].write_only) {
--- 333,339 ----
  	 * device if no resync is going on, or below the resync window.
  	 * We take the first readable disk when above the resync window.
  	 */
+ 	if (!conf->mddev->in_sync && (this_sector + sectors >= conf->next_resync)) {
  		/* make sure that disk is operational */
  		new_disk = 0;
  		while (!conf->mirrors[new_disk].operational || conf->mirrors[new_disk].write_only) {
***************
*** 652,657 ****
  	if (conf->barrier) BUG();
  	if (waitqueue_active(&conf->wait_idle)) BUG();
  	if (waitqueue_active(&conf->wait_resume)) BUG();
  }
  
  static int diskop(mddev_t *mddev, mdp_disk_t **d, int state)
--- 652,660 ----
  	if (conf->barrier) BUG();
  	if (waitqueue_active(&conf->wait_idle)) BUG();
  	if (waitqueue_active(&conf->wait_resume)) BUG();
+ 
+ 	mempool_destroy(conf->r1buf_pool);
+ 	conf->r1buf_pool = NULL;
  }
  
  static int diskop(mddev_t *mddev, mdp_disk_t **d, int state)
***************
*** 768,774 ****
  	 * Deactivate a spare disk:
  	 */
  	case DISKOP_SPARE_INACTIVE:
- 		close_sync(conf);
  		sdisk = conf->mirrors + spare_disk;
  		sdisk->operational = 0;
  		sdisk->write_only = 0;
--- 771,776 ----
  	 * Deactivate a spare disk:
  	 */
  	case DISKOP_SPARE_INACTIVE:
  		sdisk = conf->mirrors + spare_disk;
  		sdisk->operational = 0;
  		sdisk->write_only = 0;
***************
*** 781,787 ****
  	 * property)
  	 */
  	case DISKOP_SPARE_ACTIVE:
- 		close_sync(conf);
  		sdisk = conf->mirrors + spare_disk;
  		fdisk = conf->mirrors + failed_disk;
  
--- 783,788 ----
  	 * property)
  	 */
  	case DISKOP_SPARE_ACTIVE:
  		sdisk = conf->mirrors + spare_disk;
  		fdisk = conf->mirrors + failed_disk;
  
***************
*** 915,924 ****
  	}
  abort:
  	spin_unlock_irq(&conf->device_lock);
- 	if (state == DISKOP_SPARE_ACTIVE || state == DISKOP_SPARE_INACTIVE) {
- 		mempool_destroy(conf->r1buf_pool);
- 		conf->r1buf_pool = NULL;
- 	}
  
  	print_conf(conf);
  	return err;
--- 916,921 ----
  	}
  abort:
  	spin_unlock_irq(&conf->device_lock);
  
  	print_conf(conf);
  	return err;
***************
*** 1008,1014 ****
  			 * we read from here, no need to write
  			 */
  			continue;
- 		if (i < conf->raid_disks && !conf->resync_mirrors)
  			/*
  			 * don't need to write this we are just rebuilding
  			 */
--- 1005,1011 ----
  			 * we read from here, no need to write
  			 */
  			continue;
+ 		if (i < conf->raid_disks && mddev->in_sync)
  			/*
  			 * don't need to write this we are just rebuilding
  			 */
***************
*** 1113,1141 ****
  	spin_unlock_irqrestore(&retry_list_lock, flags);
  }
  
- /*
-  * Private kernel thread to reconstruct mirrors after an unclean
-  * shutdown.
-  */
- static void raid1syncd(void *data)
- {
- 	conf_t *conf = data;
- 	mddev_t *mddev = conf->mddev;
- 
- 	if (!conf->resync_mirrors)
- 		return;
- 	if (mddev->recovery_running != 2)
- 		return;
- 	if (!md_do_sync(mddev, NULL)) {
- 		/*
- 		 * Only if everything went Ok.
- 		 */
- 		conf->resync_mirrors = 0;
- 	}
- 
- 	close_sync(conf);
- 
- }
  
  static int init_resync(conf_t *conf)
  {
--- 1110,1115 ----
  	spin_unlock_irqrestore(&retry_list_lock, flags);
  }
  
  
  static int init_resync(conf_t *conf)
  {
***************
*** 1170,1178 ****
  	sector_t max_sector, nr_sectors;
  	int disk, partial;
  
- 	if (!sector_nr)
  		if (init_resync(conf))
  			return -ENOMEM;
  	/*
  	 * If there is non-resync activity waiting for us then
  	 * put in a delay to throttle resync.
--- 1144,1159 ----
  	sector_t max_sector, nr_sectors;
  	int disk, partial;
  
+ 	if (sector_nr == 0)
  		if (init_resync(conf))
  			return -ENOMEM;
+ 
+ 	max_sector = mddev->sb->size << 1;
+ 	if (sector_nr >= max_sector) {
+ 		close_sync(conf);
+ 		return 0;
+ 	}
+ 
  	/*
  	 * If there is non-resync activity waiting for us then
  	 * put in a delay to throttle resync.
***************
*** 1209,1218 ****
  	r1_bio->sector = sector_nr;
  	r1_bio->cmd = SPECIAL;
  
- 	max_sector = mddev->sb->size << 1;
- 	if (sector_nr >= max_sector)
- 		BUG();
- 
  	bio = r1_bio->master_bio;
  	nr_sectors = RESYNC_BLOCK_SIZE >> 9;
  	if (max_sector - sector_nr < nr_sectors)
--- 1190,1195 ----
  	r1_bio->sector = sector_nr;
  	r1_bio->cmd = SPECIAL;
  
  	bio = r1_bio->master_bio;
  	nr_sectors = RESYNC_BLOCK_SIZE >> 9;
  	if (max_sector - sector_nr < nr_sectors)
***************
*** 1295,1301 ****
  	mdp_disk_t *descriptor;
  	mdk_rdev_t *rdev;
  	struct list_head *tmp;
- 	int start_recovery = 0;
  
  	MOD_INC_USE_COUNT;
  
--- 1272,1277 ----
  	mdp_disk_t *descriptor;
  	mdk_rdev_t *rdev;
  	struct list_head *tmp;
  
  	MOD_INC_USE_COUNT;
  
***************
*** 1716,1736 ****
  		}
  	}
  
- 	if (!start_recovery && !(sb->state & (1 << MD_SB_CLEAN)) &&
- 						(conf->working_disks > 1)) {
- 		const char * name = "raid1syncd";
- 
- 		conf->resync_thread = md_register_thread(raid1syncd, conf, name);
- 		if (!conf->resync_thread) {
- 			printk(THREAD_ERROR, mdidx(mddev));
- 			goto out_free_conf;
- 		}
- 
- 		printk(START_RESYNC, mdidx(mddev));
- 		conf->resync_mirrors = 1;
- 		mddev->recovery_running = 2;
- 		md_wakeup_thread(conf->resync_thread);
- 	}
  
  	/*
  	 * Regenerate the "device is in sync with the raid set" bit for
--- 1688,1693 ----
  		}
  	}
  
  
  	/*
  	 * Regenerate the "device is in sync with the raid set" bit for
***************
*** 1770,1815 ****
  	return -EIO;
  }
  
- static int stop_resync(mddev_t *mddev)
- {
- 	conf_t *conf = mddev_to_conf(mddev);
- 
- 	if (conf->resync_thread) {
- 		if (conf->resync_mirrors) {
- 			md_interrupt_thread(conf->resync_thread);
- 
- 			printk(KERN_INFO "raid1: mirror resync was not fully finished, restarting next time.\n");
- 			return 1;
- 		}
- 		return 0;
- 	}
- 	return 0;
- }
- 
- static int restart_resync(mddev_t *mddev)
- {
- 	conf_t *conf = mddev_to_conf(mddev);
- 
- 	if (conf->resync_mirrors) {
- 		if (!conf->resync_thread) {
- 			MD_BUG();
- 			return 0;
- 		}
- 		mddev->recovery_running = 2;
- 		md_wakeup_thread(conf->resync_thread);
- 		return 1;
- 	}
- 	return 0;
- }
- 
  static int stop(mddev_t *mddev)
  {
  	conf_t *conf = mddev_to_conf(mddev);
  	int i;
  
  	md_unregister_thread(conf->thread);
- 	if (conf->resync_thread)
- 		md_unregister_thread(conf->resync_thread);
  	if (conf->r1bio_pool)
  		mempool_destroy(conf->r1bio_pool);
  	for (i = 0; i < MD_SB_DISKS; i++)
--- 1723,1734 ----
  	return -EIO;
  }
  
  static int stop(mddev_t *mddev)
  {
  	conf_t *conf = mddev_to_conf(mddev);
  	int i;
  
  	md_unregister_thread(conf->thread);
  	if (conf->r1bio_pool)
  		mempool_destroy(conf->r1bio_pool);
  	for (i = 0; i < MD_SB_DISKS; i++)
***************
*** 1830,1837 ****
  	status:		status,
  	error_handler:	error,
  	diskop:		diskop,
- 	stop_resync:	stop_resync,
- 	restart_resync:	restart_resync,
  	sync_request:	sync_request
  };
  
--- 1749,1754 ----
  	status:		status,
  	error_handler:	error,
  	diskop:		diskop,
  	sync_request:	sync_request
  };
  
