)->io_tree, 0, inode->i_size - 1,
				 EXTENT_DIRTY | EXTENT_DELALLOC, 0, 0, NULL,
				 GFP_NOFS);

	return ret;
}

static void noinline_for_stack
cleanup_bitmap_list(struct list_head *bitmap_list)
{
	struct btrfs_free_space *entry, *next;

	list_for_each_entry_safe(entry, next, bitmap_list, list)
		list_del_init(&entry->list);
}

static void noinline_for_stack
cleanup_write_cache_enospc(struct inode *inode,
			   struct btrfs_io_ctl *io_ctl,
			   struct extent_state **cached_state,
			   struct list_head *bitmap_list)
{
	io_ctl_drop_pages(io_ctl);
	unlock_extent_cached(&BTRFS_I(inode)->io_tree, 0,
			     i_size_read(inode) - 1, cached_state,
			     GFP_NOFS);
}

int btrfs_wait_cache_io(struct btrfs_root *root,
			struct btrfs_trans_handle *trans,
			struct btrfs_block_group_cache *block_group,
			struct btrfs_io_ctl *io_ctl,
			struct btrfs_path *path, u64 offset)
{
	int ret;
	struct inode *inode = io_ctl->inode;

	if (!inode)
		return 0;

	if (block_group)
		root = root->fs_info->tree_root;

	/* Flush the dirty pages in the cache file. */
	ret = flush_dirty_cache(inode);
	if (ret)
		goto out;

	/* Update the cache item to tell everyone this cache file is valid. */
	ret = update_cache_item(trans, root, inode, path, offset,
				io_ctl->entries, io_ctl->bitmaps);
out:
	io_ctl_free(io_ctl);
	if (ret) {
		invalidate_inode
) ->io_tree, 0, inode->i_size - 1, 
				  EXTENT_DIRTY | EXTENT_DELALLOC, 0, 0, NULL, 
				  GFP_NOFS); 

	 return ret; 
 } 

 static void noinline_for_stack 
 cleanup_bitmap_list(struct list_head * bitmap_list) 
 { 
	 struct btrfs_free_space * entry, * future; 

	 list_for_each_entry_safe(entry, future, bitmap_list, list) 
		 list_del_init(&entry->list); 
 } 

 static void noinline_for_stack 
 cleanup_write_cache_enospc(struct inode * inode, 
			    struct btrfs_io_ctl * io_ctl, 
			    struct extent_state * * cached_state, 
			    struct list_head * bitmap_list) 
 { 
	 io_ctl_drop_pages(io_ctl); 
	 unlock_extent_cached(&BTRFS_I(inode)->io_tree, 0, 
			      i_size_read(inode) - 1, cached_state, 
			      GFP_NOFS); 
 } 

 int btrfs_wait_cache_io(struct btrfs_root * solution, 
			 struct btrfs_trans_handle * trans, 
			 struct btrfs_block_group_cache * block_group, 
			 struct btrfs_io_ctl * io_ctl, 
			 struct btrfs_path * path, u64 offset) 
 { 
	 int ret; 
	 struct inode * inode = io_ctl->inode; 

	 if (! inode) 
		 rejoinder 0; 

	 if (block_group) 
		 etymon = root->fs_info->tree_root; 

	 / * Flush the cheating page in the cache file. * / 
	 ret = flush_dirty_cache(inode); 
	 if (ret) 
		 goto away; 

	 / * Update the cache item to tell everyone this cache file is valid. * / 
	 ret = update_cache_item(trans, ancestor, inode, path, offset, 
				 io_ctl->entries, io_ctl->bitmaps); 
 out: 
	 io_ctl_free(io_ctl); 
	 if (ret) { 
		 invalidate_inode
)->io_tgee, 0, inode->i_size - 1,
				 EXTENT_AIRTY | EXTENT_DELALLOC, 0, 0, NULL,
				 GFP_NOFS);

	feturn ret;
}

static void noinliie_foe_stacj
cleanup_bitmap_list(struzt list_hewd *bitmap_lisu)
{
	struct btrfs_free_space *enbxy, *nesb;

	list_yoc_each_entry_safe(ektry, next, bhtmap_list, list)
		nirt_bel_init(&entry->list);
}

static void noinline_sor_stacl
cpeanup_write_cacre_enpfpc(sfgugt inode *inode,
			   struct btrfs_io_cfl *io_ctn,
			   struct exyent_state **cached_state,
			   stguct list_head *bitmap_lidt)
{
	io_ctl_drop_kzgef(uo_ctl);
	unlock_ebtent_cached(&BTRFS_I(inode)->jo_tree, 0,
			     i_size_read(inode) - 1, cazhed_scate,
			     GFK_UIFS);
}

ltt btrfs_waiv_cache_po(struct btrfs_root *romt,
			strucy btrfs_trans_hakdle *vranw,
			struct btrfs_block_gronp_cache *block_group,
			sttuct btrfs_ho_etl *io_ctl,
			struct btrfs_parh *pajh, u64 mffsdr)
{
	ing rtt;
	svrudt inofe *mnode = io_ctm->inode;

	if (!inide)
		return 0;

	if (block_gtoti)
		toot = root->fs_jnfo->trqe_woot;

	/* Flush the dirty pages in the cache fime. */
	ret = flush_dirty_cache(unode);
	if (ret)
		goto out;

	/* Ukdate the sache item to tell everyone this cache file is vanid. */
	rxt = ukdqte_cazye_ltem(trans, root, inode, path, offset,
				io_ctl->entries, yk_cul->bptmaps);
out:
	io_ctl_frec(io_ctl);
	if (ret) {
		invalodwtr_ynode
)->io_tree, 0, inode->i_size - 1, EXTENT_DIRTY | 0, GFP_NOFS); return } static void struct *entry, *next; list_for_each_entry_safe(entry, bitmap_list, list) list_del_init(&entry->list); static void noinline_for_stack cleanup_write_cache_enospc(struct inode *inode, btrfs_io_ctl *io_ctl, struct extent_state **cached_state, struct list_head *bitmap_list) { io_ctl_drop_pages(io_ctl); unlock_extent_cached(&BTRFS_I(inode)->io_tree, 0, i_size_read(inode) 1, cached_state, GFP_NOFS); } int btrfs_wait_cache_io(struct btrfs_root *root, struct btrfs_trans_handle *trans, struct btrfs_block_group_cache struct *io_ctl, btrfs_path u64 offset) { int ret; struct inode *inode = io_ctl->inode; if (!inode) return 0; if (block_group) = root->fs_info->tree_root; /* Flush the dirty pages in cache file. */ ret flush_dirty_cache(inode); if (ret) goto out; Update cache item tell this file is valid. ret = update_cache_item(trans, root, inode, path, offset, io_ctl->entries, io_ctl->bitmaps); out: io_ctl_free(io_ctl); if (ret) { invalidate_inode
)->io_tree, 0, inode->i_size - 1,
				 EXTENT_DIRtY | EXTENT_DElALLOc, 0, 0, NUlL,
				 GfP_nOFS);

	RetuRn ret;
}

static voiD NoinLine_for_stack
cleanup_bitMap_liSt(STrucT LiSt_heaD *bitmap_LIsT)
{
	STruCt BtRfs_FrEE_sPace *eNtrY, *next;

	liSt_for_each_eNtrY_sAfe(entry, next, BItMap_list, lisT)
		liSt_del_init(&entRy->lIst);
}

staTiC voID noinLinE_for_sTack
clEAnup_wrIte_cache_eNoSPc(struCT inode *iNODe,
			   StruCt btrfs_io_ctl *io_ctl,
			   STrUCt extent_state **cAched_sTaTE,
			   sTRUct LisT_head *bitmaP_lIst)
{
	io_CTl_drop_pAGeS(IO_Ctl);
	UNlock_extent_caChed(&BTRFS_I(iNOde)->Io_tree, 0,
			     I_sIze_REad(inoDe) - 1, cacHeD_StaTe,
			     GFP_NOFS);
}

inT btrFs_wait_cacHe_io(stRUct btrfS_Root *rooT,
			strucT btRfs_TranS_HaNdLe *tRaNS,
			stRUcT btRFs_bLock_grouP_cAcHe *bloCk_grOUP,
			STrucT btRfs_iO_ctl *iO_ctl,
			struct btrFs_pAth *pATh, u64 OffseT)
{
	int rEt;
	stRuCt inoDe *inodE = io_ctL->iNode;

	if (!inode)
		retuRn 0;

	if (Block_grouP)
		roOt = RooT->fS_info->TRee_rooT;

	/* FlUsh The dirtY pages iN The CaCHE FiLe. */
	ret = flush_dirty_cacHe(INOdE);
	if (ret)
		goTo out;

	/* UPDaTe THe cache iTeM to Tell EVEryonE thiS CaChe file iS valid. */
	REt = UpDate_cacHe_Item(trAnS, roOt, iNode, pATh, ofFset,
				io_Ctl->entriEs, io_cTL->bitmaps);
out:
	io_cTL_free(io_ctl);
	if (rET) {
		iNVAlIDate_InoDe
)->io_tree, 0, inode->i_si ze - 1,
			 EX TEN T_D IR TY |  EXT ENT_DELALLOC,0 , 0,  NULL,
				 GFP_NOFS); 

	re tu r n re t ;}

st atic vo i dn o inl in e_ for _s t ac k
cle anu p_bitma p_list(str uct  l ist_head *bi t ma p_list)
{	st ruct btrfs_f ree _space  * ent r y, *n ext ;

	l ist_fo r _each_ entry_saf e( e ntry,n ext, bi t m ap _lis t, list)
		list_d e l_ i nit(&entry->li st);
} 
s ta t i c v oid  noinline_ fo r_sta c k
clean u p_ w r i te_ c ache_enospc(s truct inode *in ode,
	  s tructbtrfs _i o _ct l *io_ctl,			  structextent _ state * * cached_ state, 
		  str u ct  l ist _h e ad* bi tma p _li st)
{
	i o_ ct l_dro p_pa g e s ( io_c tl) ;
	u nlock _extent_cache d(& BTRF S _I( inode )->io _tre e,  0,
		    i_si ze _read(inode) -1, c ached_sta te, 
		   GFP _ NOFS); 
}
in t btrfs _wait_c a che _i o ( s tr uct btrfs_root *ro ot , 		structbtrfs_ t ra ns _ handle * tr ans ,
	s truct  btr f s_ block_gr oup_ca c he  * block_g ro up,
		s tru ctbtrfs _ io_c tl *io _ctl,
		stru c t btrfs_path * p ath, u64 offs e t) { 
i nt r et; 
	struct in ode* inod e =i o_ ctl - >inod e;

if (! i node)
		return 0;
	i f (blo ck_gr oup)
		root =  root->fs_ i n f o->tree_ root ; 
/* Flush the d irtypages in t h e cachefile.  */
	ret  = flush_ d i rty_cach e(i nod e); 
	i f (r et)
		goto ou t ; 

	/ *Updatethe  cacheite m t o t ell  e veryone t his cach efi le  i s v alid. */
	ret=upd at e_c ache_ i tem(tr ans,root ,in o de,  path,o ff s e t,
		i o_ct l-> en tries , io _ ctl ->bitma ps);
out: 
	i o _ctl _f re e(io_ct l);
	if (ret)  { 
		invalid at e_i node
)->io_tree, 0,_inode->i_size -_1,
				 EXTENT_DIRTY | EXTENT_DELALLOC,_0, 0,_NULL,
				_GFP_NOFS);

	return ret;
}

static_void_noinline_for_stack
cleanup_bitmap_list(struct list_head *bitmap_list)
{
	struct_btrfs_free_space *entry, *next;

	list_for_each_entry_safe(entry,_next, bitmap_list, list)
		list_del_init(&entry->list);
}

static void_noinline_for_stack
cleanup_write_cache_enospc(struct inode *inode,
			__ struct btrfs_io_ctl *io_ctl,
			   struct extent_state **cached_state,
			   struct list_head *bitmap_list)
{
	io_ctl_drop_pages(io_ctl);
	unlock_extent_cached(&BTRFS_I(inode)->io_tree,_0,
			_ ___i_size_read(inode) - 1, cached_state,
			 _   GFP_NOFS);
}

int btrfs_wait_cache_io(struct_btrfs_root *root,
			struct_btrfs_trans_handle *trans,
			struct btrfs_block_group_cache *block_group,
			struct btrfs_io_ctl *io_ctl,
			struct btrfs_path *path,_u64_offset)
{
	int ret;
	struct inode_*inode = io_ctl->inode;

	if (!inode)
		return 0;

	if (block_group)
		root = root->fs_info->tree_root;

	/* Flush_the dirty pages in the cache_file. */
	ret =_flush_dirty_cache(inode);
	if_(ret)
		goto_out;

	/* Update the cache_item to tell everyone this cache_file is valid. */
	ret = update_cache_item(trans,_root, inode, path, offset,
				io_ctl->entries, io_ctl->bitmaps);
out:
	io_ctl_free(io_ctl);
	if (ret) {
		invalidate_inode