if (last_check + window > j || j == max_sectors) 
 if (last_check + window > io_sectors || j == max_sectors) 
static void md_do_sync(mddev_t *mddev){	mddev_t *mddev2;	unsigned int currspeed = 0,		 window;	sector_t max_sectors,j;	unsigned long mark[SYNC_MARKS];	sector_t mark_cnt[SYNC_MARKS];	int last_mark,m;	struct list_head *tmp;	sector_t last_check;	/* just incase thread restarts... */	if (test_bit(MD_RECOVERY_DONE, &mddev->recovery))		return;	/* we overload curr_resync somewhat here.	 * 0 == not engaged in resync at all	 * 2 == checking that there is no conflict with another sync	 * 1 == like 2, but have yielded to allow conflicting resync to	 *		commense	 * other == active in resync - this many blocks	 *	 * Before starting a resync we must have set curr_resync to	 * 2, and then checked that every "conflicting" array has curr_resync	 * less than ours.  When we find one that is the same or higher	 * we wait on resync_wait.  To avoid deadlock, we reduce curr_resync	 * to 1 if we choose to yield (based arbitrarily on address of mddev structure).	 * This will mean we have to start checking from the beginning again.	 *	 */	do {		mddev->curr_resync = 2;	try_again:		if (signal_pending(current)) {			flush_signals(current);			goto skip;		}		ITERATE_MDDEV(mddev2,tmp) {			printk(".");			if (mddev2 == mddev)				continue;			if (mddev2->curr_resync && 			    match_mddev_units(mddev,mddev2)) {				DEFINE_WAIT(wq);				if (mddev < mddev2 && mddev->curr_resync == 2) {					/* arbitrarily yield */					mddev->curr_resync = 1;					wake_up(&resync_wait);				}				if (mddev > mddev2 && mddev->curr_resync == 1)					/* no need to wait here, we can wait the next					 * time 'round when curr_resync == 2					 */					continue;				prepare_to_wait(&resync_wait, &wq, TASK_INTERRUPTIBLE);				if (!signal_pending(current)				    && mddev2->curr_resync >= mddev->curr_resync) {					printk(KERN_INFO "md: delaying resync of %s"					       " until %s has finished resync (they"					       " share one or more physical units)\n",					       mdname(mddev), mdname(mddev2));					mddev_put(mddev2);					schedule();					finish_wait(&resync_wait, &wq);					goto try_again;				}				finish_wait(&resync_wait, &wq);			}		}	} while (mddev->curr_resync < 2);	if (test_bit(MD_RECOVERY_SYNC, &mddev->recovery))		/* resync follows the size requested by the personality,		 * which default to physical size, but can be virtual size		 */		max_sectors = mddev->resync_max_sectors;	else		/* recovery follows the physical size of devices */		max_sectors = mddev->size << 1;	printk(KERN_INFO "md: syncing RAID array %s\n", mdname(mddev));	printk(KERN_INFO "md: minimum _guaranteed_ reconstruction speed:"		" %d KB/sec/disc.\n", sysctl_speed_limit_min);	printk(KERN_INFO "md: using maximum available idle IO bandwith "	       "(but not more than %d KB/sec) for reconstruction.\n",	       sysctl_speed_limit_max);	is_mddev_idle(mddev); /* this also initializes IO event counters */	if (test_bit(MD_RECOVERY_SYNC, &mddev->recovery))		j = mddev->recovery_cp;	else		j = 0;	for (m = 0; m < SYNC_MARKS; m++) {		mark[m] = jiffies;		mark_cnt[m] = j;	}	last_mark = 0;	mddev->resync_mark = mark[last_mark];	mddev->resync_mark_cnt = mark_cnt[last_mark];	/*	 * Tune reconstruction:	 */	window = 32*(PAGE_SIZE/512);	printk(KERN_INFO "md: using %dk window, over a total of %llu blocks.\n",		window/2,(unsigned long long) max_sectors/2);	atomic_set(&mddev->recovery_active, 0);	init_waitqueue_head(&mddev->recovery_wait);	last_check = 0;	if (j>2) {		printk(KERN_INFO 			"md: resuming recovery of %s from checkpoint.\n",			mdname(mddev));		mddev->curr_resync = j;	}	while (j < max_sectors) {		int sectors;		sectors = mddev->pers->sync_request(mddev, j, currspeed < sysctl_speed_limit_min);		if (sectors < 0) {			set_bit(MD_RECOVERY_ERR, &mddev->recovery);			goto out;		}		atomic_add(sectors, &mddev->recovery_active);		j += sectors;		if (j>1) mddev->curr_resync = j;		if (last_check + window > j || j == max_sectors)			continue;		last_check = j;		if (test_bit(MD_RECOVERY_INTR, &mddev->recovery) ||		    test_bit(MD_RECOVERY_ERR, &mddev->recovery))			break;	repeat:		if (time_after_eq(jiffies, mark[last_mark] + SYNC_MARK_STEP )) {			/* step marks */			int next = (last_mark+1) % SYNC_MARKS;			mddev->resync_mark = mark[next];			mddev->resync_mark_cnt = mark_cnt[next];			mark[next] = jiffies;			mark_cnt[next] = j - atomic_read(&mddev->recovery_active);			last_mark = next;		}		if (signal_pending(current)) {			/*			 * got a signal, exit.			 */			printk(KERN_INFO 				"md: md_do_sync() got signal ... exiting\n");			flush_signals(current);			set_bit(MD_RECOVERY_INTR, &mddev->recovery);			goto out;		}		/*		 * this loop exits only if either when we are slower than		 * the 'hard' speed limit, or the system was IO-idle for		 * a jiffy.		 * the system might be non-idle CPU-wise, but we only care		 * about not overloading the IO subsystem. (things like an		 * e2fsck being done on the RAID array should execute fast)		 */		mddev->queue->unplug_fn(mddev->queue);		cond_resched();		currspeed = ((unsigned long)(j-mddev->resync_mark_cnt))/2/((jiffies-mddev->resync_mark)/HZ +1) +1;		if (currspeed > sysctl_speed_limit_min) {			if ((currspeed > sysctl_speed_limit_max) ||					!is_mddev_idle(mddev)) {				msleep_interruptible(250);				goto repeat;			}		}	}	printk(KERN_INFO "md: %s: sync done.\n",mdname(mddev));	/*	 * this also signals 'finished resyncing' to md_stop	 */ out:	mddev->queue->unplug_fn(mddev->queue);	wait_event(mddev->recovery_wait, !atomic_read(&mddev->recovery_active));	/* tell personality that we are finished */	mddev->pers->sync_request(mddev, max_sectors, 1);	if (!test_bit(MD_RECOVERY_ERR, &mddev->recovery) &&	    mddev->curr_resync > 2 &&	    mddev->curr_resync >= mddev->recovery_cp) {		if (test_bit(MD_RECOVERY_INTR, &mddev->recovery)) {			printk(KERN_INFO 				"md: checkpointing recovery of %s.\n",				mdname(mddev));			mddev->recovery_cp = mddev->curr_resync;		} else			mddev->recovery_cp = MaxSector;	} skip:	mddev->curr_resync = 0;	wake_up(&resync_wait);	set_bit(MD_RECOVERY_DONE, &mddev->recovery);	md_wakeup_thread(mddev->thread);}
4520	/local/tlutelli/issta_data/temp/c/2005_temp/2005/4520/57afd89f98a990747445f01c458ecae64263b2f8/md.c/buggy/drivers/md/md.c