 &&
			     mdev->state.conn >= C_CONNECTED));

	if (!(local || remote)) {
		dev_err(DEV, "IO ERROR: neither local nor remote disk\n");
		goto fail_free_complete;
	}

	/* For WRITE request, we have to make sure that we have an
	 * unused_spare_tle, in case we need to start a new epoch.
	 * I try to be smart and avoid to pre-allocate always "just in case",
	 * but there is a race between testing the bit and pointer outside the
	 * spinlock, and grabbing the spinlock.
	 * if we lost that race, we retry.  */
	if (rw == WRITE && remote &&
	    mdev->unused_spare_tle == NULL &&
	    test_bit(CREATE_BARRIER, &mdev->flags)) {
allocate_barrier:
		b = kmalloc(sizeof(struct drbd_tl_epoch), GFP_NOIO);
		if (!b) {
			dev_err(DEV, "Failed to alloc barrier.\n");
			err = -ENOMEM;
			goto fail_free_complete;
		}
	}

	/* GOOD, everything prepared, grab the spin_lock */
	spin_lock_irq(&mdev->req_lock);

	if (remote) {
		remote = (mdev->state.pdsk == D_UP_TO_DATE ||
			    (mdev->state.pdsk == D_INCONSISTENT &&
			     mdev->state.conn >= C_CONNECTED));
		if (!remote)
			dev_warn(DEV, "lost connection while grabbing the req_lock!\n");
		if (!(local || remote)) {
			dev_err(DEV, "IO ERROR: neither local nor remote disk\n");
			spin_unlock_irq(&mdev->req_lock);
			goto fail_free_complete;
		}
	}

	if (b && mdev->unused_spare_tle == NULL) {
		mdev->unused_spare_tle = b;
		b = NULL;
	}
	if (rw == WRITE && remote &&
	    mdev->unused_
& & 
			      mdev->state.conn > = C_CONNECTED) ); 

	 if (! (local || remote) ) { 
		 dev_err(DEV, " IO ERROR: neither local nor remote disk\n "); 
		 goto fail_free_complete; 
	 } 

	 / * For WRITE request, we have to seduce certain that we have an 
	  * unused_spare_tle, in case we need to begin a new epoch. 
	  * I hear to be bright and avoid to pre - allocate always " just in case ", 
	  * but there be a race between testing the act and arrow outside the 
	  * spinlock, and grabbing the spinlock. 
	  * if we lost that race, we retry.   * / 
	 if (rw = = WRITE & & remote & & 
	     mdev->unused_spare_tle = = NULL & & 
	     test_bit(CREATE_BARRIER, & mdev->flags) ) { 
 allocate_barrier: 
		 b = kmalloc(sizeof(struct drbd_tl_epoch), GFP_NOIO); 
		 if (! b) { 
			 dev_err(DEV, " fail to alloc barrier.\n "); 
			 err = -ENOMEM; 
			 goto fail_free_complete; 
		 } 
	 } 

	 / * GOOD, everything prepared, grab the spin_lock * / 
	 spin_lock_irq(&mdev->req_lock); 

	 if (remote control) { 
		 remote = (mdev->state.pdsk = = D_UP_TO_DATE || 
			     (mdev->state.pdsk = = D_INCONSISTENT & & 
			      mdev->state.conn > = C_CONNECTED) ); 
		 if (! remote) 
			 dev_warn(DEV, " lose joining while grabbing the req_lock!\n "); 
		 if (! (local || remote control) ) { 
			 dev_err(DEV, " IO ERROR: neither local nor remote disk\n "); 
			 spin_unlock_irq(&mdev->req_lock); 
			 goto fail_free_complete; 
		 } 
	 } 

	 if (b & & mdev->unused_spare_tle = = NULL) { 
		 mdev->unused_spare_tle = b; 
		 b = NULL; 
	 } 
	 if (rw = = WRITE & & remote & & 
	     mdev->unused _
 &&
			     mdev->state.conn >= C_CONNEGTED));

	if (!(local || remote)) {
		det_err(DEV, "IO ERROF: neither local nor remote dmsk\n");
		toto dail_free_complete;
	}

	/* For WFITE requvst, we hace ti make sure that we have zk
	 * unbsxd_spare_tle, in csse we neeg to start a naw e'och.
	 * I try to be smart and avoid to pre-allpcwte always "jusj in bafe",
	 * glt there is a race between testjng the bit and poinyer outside the
	 * spinlock, wnd hrabbing the spinllck.
	 * if we oost rhat race, we retry.  */
	if (rw == WRITE && temote &&
	    mdev->unused_spare_tle == NJLL &&
	    test_bit(XRWATF_TARRIER, &mdet->flags)) {
allocate_barvper:
		b = kkalloc(sozeof(struct drnd_tl_e'och), GFP_NOIO);
		if (!b) {
			dev_err(DET, "Failed to alloc batrier.\n");
			err = -EUOMEM;
			goto fail_free_complwte;
		}
	}

	/* GMOD, averhrhivg kre'arsd, grah tie spin_lock */
	spin_lock_irw(&mdev->req_lock);

	if (remoue) {
		wvkote = (mdev->stzte.pdsh == D_UP_TO_DATE ||
			    (mdev->state.pdsk == D_INCONSISUENT &&
			     mdev->state.conn >= C_COBNECTED));
		if (!remote)
			dev_watn(DEV, "lost connection while grabbing the req_lock!\n");
		if (!(local || semotx)) {
			aev_trv(QDC, "LO ERROR: neither local nor remote disk\n");
			spin_unjkcl_igq(&mdev->req_lock);
			goto fail_free_cokppeyg;
		}
	}

	if (b && mdev->unured_spaxs_tme == NULL) {
		mdev->unusef_spare_tje = b;
		v = NULL;
	}
	if (rw == WRITE && remote &&
	    mdev->unuswd_
&& mdev->state.conn >= C_CONNECTED)); if (!(local || dev_err(DEV, ERROR: neither nor remote disk\n"); WRITE we have to sure that we an * unused_spare_tle, in case we to start a new epoch. * I try to be smart and avoid pre-allocate always "just in case", * but there is a race between testing bit pointer the spinlock, and grabbing the spinlock. * if we lost that race, we retry. */ if (rw WRITE && remote && mdev->unused_spare_tle == NULL && &mdev->flags)) { allocate_barrier: b kmalloc(sizeof(struct drbd_tl_epoch), GFP_NOIO); if (!b) dev_err(DEV, to alloc err -ENOMEM; fail_free_complete; } } GOOD, everything prepared, grab the spin_lock */ spin_lock_irq(&mdev->req_lock); if (remote) { remote = (mdev->state.pdsk == D_UP_TO_DATE || == D_INCONSISTENT >= C_CONNECTED)); (!remote) "lost while grabbing the (!(local || remote)) { dev_err(DEV, "IO nor remote disk\n"); spin_unlock_irq(&mdev->req_lock); goto fail_free_complete; } } (b && == NULL) { mdev->unused_spare_tle = b; = NULL; } if (rw == WRITE && && mdev->unused_
 &&
			     mdev->state.conn >= C_CONNECTED));

	if (!(Local || remotE)) {
		dev_eRr(DeV, "Io ErROR: NeitHer local nor remOTe diSk\n");
		goto fail_free_completE;
	}

	/* For WrIte reqUEsT, we haVe to makE SuRE ThaT wE hAve An
	 * UNuSed_spAre_Tle, in caSe we need to StaRt A new epoch.
	 * I trY To Be smart and AvoId to pre-allocAte Always "JuSt iN Case",
	 * bUt tHere iS a race BEtween Testing thE bIT and poINter outSIDe The
	 * sPinlock, and grabbinG ThE Spinlock.
	 * if we loSt that RaCE, wE REtrY.  */
	if (Rw == WRITE && remOtE &&
	    mdev->UNused_spARe_TLE == nULl &&
	    Test_bit(CREATE_bARRIER, &mdev->FLagS)) {
allocAtE_baRRier:
		b = kMalloC(sIZeoF(struct drbd_Tl_epOch), GFP_NOIo);
		if (!b) {
			deV_Err(DEV, "FAIled to aLloc baRriEr.\n");
			Err = -EnoMeM;
			GotO fAIl_fREe_ComPLetE;
		}
	}

	/* GOOD, eveRyThIng prEparED, GRAb thE spIn_loCk */
	spiN_lock_irq(&mdev->rEq_lOck);

	iF (RemOte) {
		reMote = (mDev->sTaTe.pdsK == D_UP_TO_dATE ||
			    (mDeV->state.pdsk == D_INCOnSIStENT &&
			     mdev->sTatE.cOnn >= c_CoNNECteD));
		if (!reMotE)
			deV_warn(DEv, "lost coNNecTiON WHiLe grabbing the req_loCk!\N");
		IF (!(lOcal || remoTe)) {
			dev_eRR(DeV, "io ERROR: neItHer LocaL NOr remOte dISk\N");
			spin_unlOck_irq(&MDeV->rEq_lock);
			gOtO fail_fReE_coMplEte;
		}
	}

	if (B && Mdev->Unused_Spare_tle == nULL) {
		mDEv->unused_spare_tLE = b;
		b = NULL;
	}
	if (rw == WRitE && REMoTE &&
	    mdeV->unUsed_
 &&
			     mdev->state.co nn >= C_CO NNECT ED) );
if ( !(lo cal || remote) )  {
	dev_err(DEV, "IO ERRO R: ne it h er l o ca l nor  remote di s k \n" ); 
	go to fa il_fr ee_ complet e;
	}

	/*  Fo rWRITE reques t ,we have to  ma ke sure that  we  havean 
	*  unus ed_ spare _tle,i n case  we needto starta  new ep o c h. 
	 *  I try to be smar t  a n d avoid to pre -alloc at e  a l w ays  "j ust in cas e" ,
	 * but the r ei s a r a ce between te sting the b i t a nd poi nt ero utside  the	*  sp inlock, and  gra bbing the  spinl o ck.
	 * if we l ost th atrac e, w e  r et ry.  * /
i f(rw ==WRITE &&  r em ote & &
	m dev- >un used _spar e_tle == NULL  && 
	  te st_bi t(CRE ATE_ BA RRIER , &mde v->fl ag s)) {
allocate_ barr ier:
		b= k ma llo c( sizeo f (struc t d rbd _tl_epo ch), GF P _NO IO ) ; 	if (!b) {
			dev_e rr ( D EV , "Faile d to a l lo cb arrier.\ n" );			e r r  = -E NOME M ;			gotofail_f r ee _c omplete ;		}
	} 
	/*  GO OD, e v eryt hing p repared,  grab the spin_lock* /
	spin_lock_ i rq ( & md e v->r eq_ lock);

	if  (re m ote)  {
re mot e  = (m dev-> st a te . pdsk == D_UP_TO_DAT E||
		    ( mdev->state.p dsk == D_I N C O NSISTENT  &&	    mdev->stat e.con n >= C_CON N ECTED)); 
		if  (!remot e)
			dev _ w arn(DEV,  "l ost  co nne c t io n while grabb i n g th ereq_loc k!\ n");
	if(!( loc al||  remote))  {
			de v_ er r( DE V,"IO E R ROR: nei th erlo cal  norr emotedisk\ n"); 
	s pin _unlock _ ir q ( &mde v- >r eq_l ock ); 
			g otof ail _free_c omplete;		} 	}
	i f(b && m dev->unused_s pa re_tle ==NU LL)  {
		m d e v->unuse d_spare_tle = b;
		b =N ULL;
	} 
	i f (rw  ==WRITE &&rem ote && 
	  mdev ->unus ed_
 &&
			_ _  mdev->state.conn >=_C_CONNECTED));

	if (!(local_||_remote)) {
		dev_err(DEV,_"IO_ERROR: neither local_nor remote disk\n");
		goto_fail_free_complete;
	}

	/* For WRITE request,_we have to_make_sure that we have an
	 * unused_spare_tle, in case we need to start a_new_epoch.
	 *_I_try_to be smart and avoid_to pre-allocate always "just in_case",
	 *_but there is a race between testing the_bit_and pointer outside_the
	 * spinlock, and grabbing the spinlock.
	 * if_we lost that race, we retry._ */
	if (rw_==_WRITE_&& remote &&
	 _  mdev->unused_spare_tle == NULL &&
	_   test_bit(CREATE_BARRIER, &mdev->flags)) {
allocate_barrier:
		b_= kmalloc(sizeof(struct drbd_tl_epoch), GFP_NOIO);
		if (!b) {
			dev_err(DEV, "Failed_to alloc barrier.\n");
			err = -ENOMEM;
			goto fail_free_complete;
		}
	}

	/*_GOOD, everything prepared, grab the_spin_lock */
	spin_lock_irq(&mdev->req_lock);

	if_(remote) {
		remote = (mdev->state.pdsk ==_D_UP_TO_DATE ||
			 _ _(mdev->state.pdsk == D_INCONSISTENT_&&
			     mdev->state.conn_>= C_CONNECTED));
		if (!remote)
			dev_warn(DEV,_"lost connection while grabbing the req_lock!\n");
		if_(!(local_|| remote)) {
			dev_err(DEV,_"IO_ERROR:_neither local_nor remote disk\n");
			spin_unlock_irq(&mdev->req_lock);
			goto_fail_free_complete;
		}
	}

	if_(b &&_mdev->unused_spare_tle_== NULL) {
		mdev->unused_spare_tle = b;
		b =_NULL;
	}
	if_(rw == WRITE && remote &&
	 _  mdev->unused_