while (blist) { struct bio *b = blist; blist = blist->bi_next; b->bi_next = NULL; generic_make_request(b);  md_write_end(mddev); }
void md_check_recovery(mddev_t *mddev){	mdk_rdev_t *rdev;	struct list_head *rtmp;	if (mddev->bitmap)		bitmap_daemon_work(mddev->bitmap);	if (mddev->ro)		return;	if (signal_pending(current)) {		if (mddev->pers->sync_request) {			printk(KERN_INFO "md: %s in immediate safe mode\n",			       mdname(mddev));			mddev->safemode = 2;		}		flush_signals(current);	}	if ( ! (		mddev->sb_dirty ||		test_bit(MD_RECOVERY_NEEDED, &mddev->recovery) ||		test_bit(MD_RECOVERY_DONE, &mddev->recovery) ||		mddev->write_list.head ||		(mddev->safemode == 1) ||		(mddev->safemode == 2 && ! atomic_read(&mddev->writes_pending)		 && !mddev->in_sync && mddev->recovery_cp == MaxSector)		))		return;	if (mddev_trylock(mddev)==0) {		int spares =0;		struct bio *blist;		spin_lock(&mddev->write_lock);		if (mddev->safemode && !atomic_read(&mddev->writes_pending) &&		    !mddev->in_sync && mddev->recovery_cp == MaxSector) {			mddev->in_sync = 1;			mddev->sb_dirty = 1;		}		if (mddev->safemode == 1)			mddev->safemode = 0;		blist = bio_list_get(&mddev->write_list);		spin_unlock(&mddev->write_lock);		if (mddev->sb_dirty)			md_update_sb(mddev);		while (blist) {			struct bio *b = blist;			blist = blist->bi_next;			b->bi_next = NULL;			generic_make_request(b);			/* we already counted this, so need to un-count */			md_write_end(mddev);		}		if (test_bit(MD_RECOVERY_RUNNING, &mddev->recovery) &&		    !test_bit(MD_RECOVERY_DONE, &mddev->recovery)) {			/* resync/recovery still happening */			clear_bit(MD_RECOVERY_NEEDED, &mddev->recovery);			goto unlock;		}		if (mddev->sync_thread) {			/* resync has finished, collect result */			md_unregister_thread(mddev->sync_thread);			mddev->sync_thread = NULL;			if (!test_bit(MD_RECOVERY_ERR, &mddev->recovery) &&			    !test_bit(MD_RECOVERY_INTR, &mddev->recovery)) {				/* success...*/				/* activate any spares */				mddev->pers->spare_active(mddev);			}			md_update_sb(mddev);			/* if array is no-longer degraded, then any saved_raid_disk			 * information must be scrapped			 */			if (!mddev->degraded)				ITERATE_RDEV(mddev,rdev,rtmp)					rdev->saved_raid_disk = -1;			mddev->recovery = 0;			/* flag recovery needed just to double check */			set_bit(MD_RECOVERY_NEEDED, &mddev->recovery);			goto unlock;		}		if (mddev->recovery)			/* probably just the RECOVERY_NEEDED flag */			mddev->recovery = 0;		/* no recovery is running.		 * remove any failed drives, then		 * add spares if possible.		 * Spare are also removed and re-added, to allow		 * the personality to fail the re-add.		 */		ITERATE_RDEV(mddev,rdev,rtmp)			if (rdev->raid_disk >= 0 &&			    (rdev->faulty || ! rdev->in_sync) &&			    atomic_read(&rdev->nr_pending)==0) {				if (mddev->pers->hot_remove_disk(mddev, rdev->raid_disk)==0)					rdev->raid_disk = -1;			}		if (mddev->degraded) {			ITERATE_RDEV(mddev,rdev,rtmp)				if (rdev->raid_disk < 0				    && !rdev->faulty) {					if (mddev->pers->hot_add_disk(mddev,rdev))						spares++;					else						break;				}		}		if (!spares && (mddev->recovery_cp == MaxSector )) {			/* nothing we can do ... */			goto unlock;		}		if (mddev->pers->sync_request) {			set_bit(MD_RECOVERY_RUNNING, &mddev->recovery);			if (!spares)				set_bit(MD_RECOVERY_SYNC, &mddev->recovery);			mddev->sync_thread = md_register_thread(md_do_sync,								mddev,								"%s_resync");			if (!mddev->sync_thread) {				printk(KERN_ERR "%s: could not start resync"					" thread...\n", 					mdname(mddev));				/* leave the spares where they are, it shouldn't hurt */				mddev->recovery = 0;			} else {				md_wakeup_thread(mddev->sync_thread);			}		}	unlock:		mddev_unlock(mddev);	}}