!conf->mirrors[i].rdev->in_sync) { 
!test_bit(In_sync, &conf->mirrors[i].rdev->flags)) { 
static sector_t sync_request(mddev_t *mddev, sector_t sector_nr, int *skipped, int go_faster){	conf_t *conf = mddev_to_conf(mddev);	r10bio_t *r10_bio;	struct bio *biolist = NULL, *bio;	sector_t max_sector, nr_sectors;	int disk;	int i;	sector_t sectors_skipped = 0;	int chunks_skipped = 0;	if (!conf->r10buf_pool)		if (init_resync(conf))			return 0; skipped:	max_sector = mddev->size << 1;	if (test_bit(MD_RECOVERY_SYNC, &mddev->recovery))		max_sector = mddev->resync_max_sectors;	if (sector_nr >= max_sector) {		close_sync(conf);		*skipped = 1;		return sectors_skipped;	}	if (chunks_skipped >= conf->raid_disks) {		/* if there has been nothing to do on any drive,		 * then there is nothing to do at all..		 */		*skipped = 1;		return (max_sector - sector_nr) + sectors_skipped;	}	/* make sure whole request will fit in a chunk - if chunks	 * are meaningful	 */	if (conf->near_copies < conf->raid_disks &&	    max_sector > (sector_nr | conf->chunk_mask))		max_sector = (sector_nr | conf->chunk_mask) + 1;	/*	 * If there is non-resync activity waiting for us then	 * put in a delay to throttle resync.	 */	if (!go_faster && waitqueue_active(&conf->wait_resume))		msleep_interruptible(1000);	device_barrier(conf, sector_nr + RESYNC_SECTORS);	/* Again, very different code for resync and recovery.	 * Both must result in an r10bio with a list of bios that	 * have bi_end_io, bi_sector, bi_bdev set,	 * and bi_private set to the r10bio.	 * For recovery, we may actually create several r10bios	 * with 2 bios in each, that correspond to the bios in the main one.	 * In this case, the subordinate r10bios link back through a	 * borrowed master_bio pointer, and the counter in the master	 * includes a ref from each subordinate.	 */	/* First, we decide what to do and set ->bi_end_io	 * To end_sync_read if we want to read, and	 * end_sync_write if we will want to write.	 */	if (!test_bit(MD_RECOVERY_SYNC, &mddev->recovery)) {		/* recovery... the complicated one */		int i, j, k;		r10_bio = NULL;		for (i=0 ; i<conf->raid_disks; i++)			if (conf->mirrors[i].rdev &&			    !conf->mirrors[i].rdev->in_sync) {				/* want to reconstruct this device */				r10bio_t *rb2 = r10_bio;				r10_bio = mempool_alloc(conf->r10buf_pool, GFP_NOIO);				spin_lock_irq(&conf->resync_lock);				conf->nr_pending++;				if (rb2) conf->barrier++;				spin_unlock_irq(&conf->resync_lock);				atomic_set(&r10_bio->remaining, 0);				r10_bio->master_bio = (struct bio*)rb2;				if (rb2)					atomic_inc(&rb2->remaining);				r10_bio->mddev = mddev;				set_bit(R10BIO_IsRecover, &r10_bio->state);				r10_bio->sector = raid10_find_virt(conf, sector_nr, i);				raid10_find_phys(conf, r10_bio);				for (j=0; j<conf->copies;j++) {					int d = r10_bio->devs[j].devnum;					if (conf->mirrors[d].rdev &&					    conf->mirrors[d].rdev->in_sync) {						/* This is where we read from */						bio = r10_bio->devs[0].bio;						bio->bi_next = biolist;						biolist = bio;						bio->bi_private = r10_bio;						bio->bi_end_io = end_sync_read;						bio->bi_rw = 0;						bio->bi_sector = r10_bio->devs[j].addr +							conf->mirrors[d].rdev->data_offset;						bio->bi_bdev = conf->mirrors[d].rdev->bdev;						atomic_inc(&conf->mirrors[d].rdev->nr_pending);						atomic_inc(&r10_bio->remaining);						/* and we write to 'i' */						for (k=0; k<conf->copies; k++)							if (r10_bio->devs[k].devnum == i)								break;						bio = r10_bio->devs[1].bio;						bio->bi_next = biolist;						biolist = bio;						bio->bi_private = r10_bio;						bio->bi_end_io = end_sync_write;						bio->bi_rw = 1;						bio->bi_sector = r10_bio->devs[k].addr +							conf->mirrors[i].rdev->data_offset;						bio->bi_bdev = conf->mirrors[i].rdev->bdev;						r10_bio->devs[0].devnum = d;						r10_bio->devs[1].devnum = i;						break;					}				}				if (j == conf->copies) {					/* Cannot recover, so abort the recovery */					put_buf(r10_bio);					r10_bio = rb2;					if (!test_and_set_bit(MD_RECOVERY_ERR, &mddev->recovery))						printk(KERN_INFO "raid10: %s: insufficient working devices for recovery.\n",						       mdname(mddev));					break;				}			}		if (biolist == NULL) {			while (r10_bio) {				r10bio_t *rb2 = r10_bio;				r10_bio = (r10bio_t*) rb2->master_bio;				rb2->master_bio = NULL;				put_buf(rb2);			}			goto giveup;		}	} else {		/* resync. Schedule a read for every block at this virt offset */		int count = 0;		r10_bio = mempool_alloc(conf->r10buf_pool, GFP_NOIO);		spin_lock_irq(&conf->resync_lock);		conf->nr_pending++;		spin_unlock_irq(&conf->resync_lock);		r10_bio->mddev = mddev;		atomic_set(&r10_bio->remaining, 0);		r10_bio->master_bio = NULL;		r10_bio->sector = sector_nr;		set_bit(R10BIO_IsSync, &r10_bio->state);		raid10_find_phys(conf, r10_bio);		r10_bio->sectors = (sector_nr | conf->chunk_mask) - sector_nr +1;		for (i=0; i<conf->copies; i++) {			int d = r10_bio->devs[i].devnum;			bio = r10_bio->devs[i].bio;			bio->bi_end_io = NULL;			if (conf->mirrors[d].rdev == NULL ||			    conf->mirrors[d].rdev->faulty)				continue;			atomic_inc(&conf->mirrors[d].rdev->nr_pending);			atomic_inc(&r10_bio->remaining);			bio->bi_next = biolist;			biolist = bio;			bio->bi_private = r10_bio;			bio->bi_end_io = end_sync_read;			bio->bi_rw = 0;			bio->bi_sector = r10_bio->devs[i].addr +				conf->mirrors[d].rdev->data_offset;			bio->bi_bdev = conf->mirrors[d].rdev->bdev;			count++;		}		if (count < 2) {			for (i=0; i<conf->copies; i++) {				int d = r10_bio->devs[i].devnum;				if (r10_bio->devs[i].bio->bi_end_io)					rdev_dec_pending(conf->mirrors[d].rdev, mddev);			}			put_buf(r10_bio);			biolist = NULL;			goto giveup;		}	}	for (bio = biolist; bio ; bio=bio->bi_next) {		bio->bi_flags &= ~(BIO_POOL_MASK - 1);		if (bio->bi_end_io)			bio->bi_flags |= 1 << BIO_UPTODATE;		bio->bi_vcnt = 0;		bio->bi_idx = 0;		bio->bi_phys_segments = 0;		bio->bi_hw_segments = 0;		bio->bi_size = 0;	}	nr_sectors = 0;	do {		struct page *page;		int len = PAGE_SIZE;		disk = 0;		if (sector_nr + (len>>9) > max_sector)			len = (max_sector - sector_nr) << 9;		if (len == 0)			break;		for (bio= biolist ; bio ; bio=bio->bi_next) {			page = bio->bi_io_vec[bio->bi_vcnt].bv_page;			if (bio_add_page(bio, page, len, 0) == 0) {				/* stop here */				struct bio *bio2;				bio->bi_io_vec[bio->bi_vcnt].bv_page = page;				for (bio2 = biolist; bio2 && bio2 != bio; bio2 = bio2->bi_next) {					/* remove last page from this bio */					bio2->bi_vcnt--;					bio2->bi_size -= len;					bio2->bi_flags &= ~(1<< BIO_SEG_VALID);				}				goto bio_full;			}			disk = i;		}		nr_sectors += len>>9;		sector_nr += len>>9;	} while (biolist->bi_vcnt < RESYNC_PAGES); bio_full:	r10_bio->sectors = nr_sectors;	while (biolist) {		bio = biolist;		biolist = biolist->bi_next;		bio->bi_next = NULL;		r10_bio = bio->bi_private;		r10_bio->sectors = nr_sectors;		if (bio->bi_end_io == end_sync_read) {			md_sync_acct(bio->bi_bdev, nr_sectors);			generic_make_request(bio);		}	}	if (sectors_skipped)		/* pretend they weren't skipped, it makes		 * no important difference in this case		 */		md_done_sync(mddev, sectors_skipped, 1);	return sectors_skipped + nr_sectors; giveup:	/* There is nowhere to write, so all non-sync	 * drives must be failed, so try the next chunk...	 */	{	sector_t sec = max_sector - sector_nr;	sectors_skipped += sec;	chunks_skipped ++;	sector_nr = max_sector;	goto skipped;	}}
10457	/local/tlutelli/issta_data/temp/c/2005_temp/2005/10457/b2d444d7ad975d555bb919601bcdc0e58975a40e/raid10.c/clean/drivers/md/raid10.c