Lines Matching refs:block_rsv

104 				    struct btrfs_block_rsv *block_rsv,  in block_rsv_release_bytes()  argument
108 struct btrfs_space_info *space_info = block_rsv->space_info; in block_rsv_release_bytes()
112 spin_lock(&block_rsv->lock); in block_rsv_release_bytes()
114 num_bytes = block_rsv->size; in block_rsv_release_bytes()
115 qgroup_to_release = block_rsv->qgroup_rsv_size; in block_rsv_release_bytes()
117 block_rsv->size -= num_bytes; in block_rsv_release_bytes()
118 if (block_rsv->reserved >= block_rsv->size) { in block_rsv_release_bytes()
119 num_bytes = block_rsv->reserved - block_rsv->size; in block_rsv_release_bytes()
120 block_rsv->reserved = block_rsv->size; in block_rsv_release_bytes()
121 block_rsv->full = true; in block_rsv_release_bytes()
125 if (block_rsv->qgroup_rsv_reserved >= block_rsv->qgroup_rsv_size) { in block_rsv_release_bytes()
126 qgroup_to_release = block_rsv->qgroup_rsv_reserved - in block_rsv_release_bytes()
127 block_rsv->qgroup_rsv_size; in block_rsv_release_bytes()
128 block_rsv->qgroup_rsv_reserved = block_rsv->qgroup_rsv_size; in block_rsv_release_bytes()
132 spin_unlock(&block_rsv->lock); in block_rsv_release_bytes()
193 struct btrfs_block_rsv *block_rsv; in btrfs_alloc_block_rsv() local
195 block_rsv = kmalloc(sizeof(*block_rsv), GFP_NOFS); in btrfs_alloc_block_rsv()
196 if (!block_rsv) in btrfs_alloc_block_rsv()
199 btrfs_init_metadata_block_rsv(fs_info, block_rsv, type); in btrfs_alloc_block_rsv()
200 return block_rsv; in btrfs_alloc_block_rsv()
213 struct btrfs_block_rsv *block_rsv, u64 num_bytes, in btrfs_block_rsv_add() argument
221 ret = btrfs_reserve_metadata_bytes(fs_info, block_rsv, num_bytes, flush); in btrfs_block_rsv_add()
223 btrfs_block_rsv_add_bytes(block_rsv, num_bytes, true); in btrfs_block_rsv_add()
228 int btrfs_block_rsv_check(struct btrfs_block_rsv *block_rsv, int min_factor) in btrfs_block_rsv_check() argument
233 if (!block_rsv) in btrfs_block_rsv_check()
236 spin_lock(&block_rsv->lock); in btrfs_block_rsv_check()
237 num_bytes = div_factor(block_rsv->size, min_factor); in btrfs_block_rsv_check()
238 if (block_rsv->reserved >= num_bytes) in btrfs_block_rsv_check()
240 spin_unlock(&block_rsv->lock); in btrfs_block_rsv_check()
246 struct btrfs_block_rsv *block_rsv, u64 min_reserved, in btrfs_block_rsv_refill() argument
252 if (!block_rsv) in btrfs_block_rsv_refill()
255 spin_lock(&block_rsv->lock); in btrfs_block_rsv_refill()
257 if (block_rsv->reserved >= num_bytes) in btrfs_block_rsv_refill()
260 num_bytes -= block_rsv->reserved; in btrfs_block_rsv_refill()
261 spin_unlock(&block_rsv->lock); in btrfs_block_rsv_refill()
266 ret = btrfs_reserve_metadata_bytes(fs_info, block_rsv, num_bytes, flush); in btrfs_block_rsv_refill()
268 btrfs_block_rsv_add_bytes(block_rsv, num_bytes, false); in btrfs_block_rsv_refill()
276 struct btrfs_block_rsv *block_rsv, u64 num_bytes, in btrfs_block_rsv_release() argument
287 if (block_rsv == delayed_rsv) in btrfs_block_rsv_release()
289 else if (block_rsv != global_rsv && !btrfs_block_rsv_full(delayed_rsv)) in btrfs_block_rsv_release()
292 if (target && block_rsv->space_info != target->space_info) in btrfs_block_rsv_release()
295 return block_rsv_release_bytes(fs_info, block_rsv, target, num_bytes, in btrfs_block_rsv_release()
299 int btrfs_block_rsv_use_bytes(struct btrfs_block_rsv *block_rsv, u64 num_bytes) in btrfs_block_rsv_use_bytes() argument
303 spin_lock(&block_rsv->lock); in btrfs_block_rsv_use_bytes()
304 if (block_rsv->reserved >= num_bytes) { in btrfs_block_rsv_use_bytes()
305 block_rsv->reserved -= num_bytes; in btrfs_block_rsv_use_bytes()
306 if (block_rsv->reserved < block_rsv->size) in btrfs_block_rsv_use_bytes()
307 block_rsv->full = false; in btrfs_block_rsv_use_bytes()
310 spin_unlock(&block_rsv->lock); in btrfs_block_rsv_use_bytes()
314 void btrfs_block_rsv_add_bytes(struct btrfs_block_rsv *block_rsv, in btrfs_block_rsv_add_bytes() argument
317 spin_lock(&block_rsv->lock); in btrfs_block_rsv_add_bytes()
318 block_rsv->reserved += num_bytes; in btrfs_block_rsv_add_bytes()
320 block_rsv->size += num_bytes; in btrfs_block_rsv_add_bytes()
321 else if (block_rsv->reserved >= block_rsv->size) in btrfs_block_rsv_add_bytes()
322 block_rsv->full = true; in btrfs_block_rsv_add_bytes()
323 spin_unlock(&block_rsv->lock); in btrfs_block_rsv_add_bytes()
353 struct btrfs_block_rsv *block_rsv = &fs_info->global_block_rsv; in btrfs_update_global_block_rsv() local
354 struct btrfs_space_info *sinfo = block_rsv->space_info; in btrfs_update_global_block_rsv()
394 spin_lock(&block_rsv->lock); in btrfs_update_global_block_rsv()
396 block_rsv->size = min_t(u64, num_bytes, SZ_512M); in btrfs_update_global_block_rsv()
398 if (block_rsv->reserved < block_rsv->size) { in btrfs_update_global_block_rsv()
399 num_bytes = block_rsv->size - block_rsv->reserved; in btrfs_update_global_block_rsv()
402 block_rsv->reserved = block_rsv->size; in btrfs_update_global_block_rsv()
403 } else if (block_rsv->reserved > block_rsv->size) { in btrfs_update_global_block_rsv()
404 num_bytes = block_rsv->reserved - block_rsv->size; in btrfs_update_global_block_rsv()
407 block_rsv->reserved = block_rsv->size; in btrfs_update_global_block_rsv()
411 block_rsv->full = (block_rsv->reserved == block_rsv->size); in btrfs_update_global_block_rsv()
413 if (block_rsv->size >= sinfo->total_bytes) in btrfs_update_global_block_rsv()
415 spin_unlock(&block_rsv->lock); in btrfs_update_global_block_rsv()
428 root->block_rsv = &fs_info->delayed_refs_rsv; in btrfs_init_root_block_rsv()
433 root->block_rsv = &fs_info->global_block_rsv; in btrfs_init_root_block_rsv()
436 root->block_rsv = &fs_info->chunk_block_rsv; in btrfs_init_root_block_rsv()
439 root->block_rsv = NULL; in btrfs_init_root_block_rsv()
480 struct btrfs_block_rsv *block_rsv = NULL; in get_block_rsv() local
486 block_rsv = trans->block_rsv; in get_block_rsv()
488 if (!block_rsv) in get_block_rsv()
489 block_rsv = root->block_rsv; in get_block_rsv()
491 if (!block_rsv) in get_block_rsv()
492 block_rsv = &fs_info->empty_block_rsv; in get_block_rsv()
494 return block_rsv; in get_block_rsv()
502 struct btrfs_block_rsv *block_rsv; in btrfs_use_block_rsv() local
507 block_rsv = get_block_rsv(trans, root); in btrfs_use_block_rsv()
509 if (unlikely(block_rsv->size == 0)) in btrfs_use_block_rsv()
512 ret = btrfs_block_rsv_use_bytes(block_rsv, blocksize); in btrfs_use_block_rsv()
514 return block_rsv; in btrfs_use_block_rsv()
516 if (block_rsv->failfast) in btrfs_use_block_rsv()
519 if (block_rsv->type == BTRFS_BLOCK_RSV_GLOBAL && !global_updated) { in btrfs_use_block_rsv()
529 if (block_rsv->type != BTRFS_BLOCK_RSV_DELREFS && in btrfs_use_block_rsv()
537 block_rsv->type, ret); in btrfs_use_block_rsv()
540 ret = btrfs_reserve_metadata_bytes(fs_info, block_rsv, blocksize, in btrfs_use_block_rsv()
543 return block_rsv; in btrfs_use_block_rsv()
549 if (block_rsv->type != BTRFS_BLOCK_RSV_GLOBAL && in btrfs_use_block_rsv()
550 block_rsv->space_info == global_rsv->space_info) { in btrfs_use_block_rsv()