* Check if it if we can balance. We can balance on the whole 
* Check if we can balance. We can balance on the whole 
static int read_balance(conf_t *conf, r1bio_t *r1_bio){	const unsigned long this_sector = r1_bio->sector;	int new_disk = conf->last_used, disk = new_disk;	const int sectors = r1_bio->sectors;	sector_t new_distance, current_distance;	mdk_rdev_t *new_rdev, *rdev;	rcu_read_lock();	/*	 * Check if it if we can balance. We can balance on the whole	 * device if no resync is going on, or below the resync window.	 * We take the first readable disk when above the resync window.	 */ retry:	if (conf->mddev->recovery_cp < MaxSector &&	    (this_sector + sectors >= conf->next_resync)) {		/* Choose the first operation device, for consistancy */		new_disk = 0;		while ((new_rdev=conf->mirrors[new_disk].rdev) == NULL ||		       !new_rdev->in_sync) {			new_disk++;			if (new_disk == conf->raid_disks) {				new_disk = -1;				break;			}		}		goto rb_out;	}	/* make sure the disk is operational */	while ((new_rdev=conf->mirrors[new_disk].rdev) == NULL ||	       !new_rdev->in_sync) {		if (new_disk <= 0)			new_disk = conf->raid_disks;		new_disk--;		if (new_disk == disk) {			new_disk = -1;			goto rb_out;		}	}	disk = new_disk;	/* now disk == new_disk == starting point for search */	/*	 * Don't change to another disk for sequential reads:	 */	if (conf->next_seq_sect == this_sector)		goto rb_out;	if (this_sector == conf->mirrors[new_disk].head_position)		goto rb_out;	current_distance = abs(this_sector - conf->mirrors[disk].head_position);	/* Find the disk whose head is closest */	do {		if (disk <= 0)			disk = conf->raid_disks;		disk--;		if ((rdev=conf->mirrors[disk].rdev) == NULL ||		    !rdev->in_sync)			continue;		if (!atomic_read(&rdev->nr_pending)) {			new_disk = disk;			new_rdev = rdev;			break;		}		new_distance = abs(this_sector - conf->mirrors[disk].head_position);		if (new_distance < current_distance) {			current_distance = new_distance;			new_disk = disk;			new_rdev = rdev;		}	} while (disk != conf->last_used);rb_out:	if (new_disk >= 0) {		conf->next_seq_sect = this_sector + sectors;		conf->last_used = new_disk;		atomic_inc(&new_rdev->nr_pending);		if (!new_rdev->in_sync) {			/* cannot risk returning a device that failed			 * before we inc'ed nr_pending			 */			atomic_dec(&new_rdev->nr_pending);			goto retry;		}	}	rcu_read_unlock();	return new_disk;}
10457	/local/tlutelli/issta_data/temp/c/2005_temp/2005/10457/8ddf9efe6708f3674f0ddfeb6425fd27bea109a2/raid1.c/buggy/drivers/md/raid1.c