diff options
Diffstat (limited to 'fs/nilfs2/alloc.c')
-rw-r--r-- | fs/nilfs2/alloc.c | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/fs/nilfs2/alloc.c b/fs/nilfs2/alloc.c index eed4d7b26249..741fd02e0444 100644 --- a/fs/nilfs2/alloc.c +++ b/fs/nilfs2/alloc.c | |||
@@ -398,6 +398,69 @@ nilfs_palloc_rest_groups_in_desc_block(const struct inode *inode, | |||
398 | } | 398 | } |
399 | 399 | ||
400 | /** | 400 | /** |
401 | * nilfs_palloc_count_desc_blocks - count descriptor blocks number | ||
402 | * @inode: inode of metadata file using this allocator | ||
403 | * @desc_blocks: descriptor blocks number [out] | ||
404 | */ | ||
405 | static int nilfs_palloc_count_desc_blocks(struct inode *inode, | ||
406 | unsigned long *desc_blocks) | ||
407 | { | ||
408 | unsigned long blknum; | ||
409 | int ret; | ||
410 | |||
411 | ret = nilfs_bmap_last_key(NILFS_I(inode)->i_bmap, &blknum); | ||
412 | if (likely(!ret)) | ||
413 | *desc_blocks = DIV_ROUND_UP( | ||
414 | blknum, NILFS_MDT(inode)->mi_blocks_per_desc_block); | ||
415 | return ret; | ||
416 | } | ||
417 | |||
418 | /** | ||
419 | * nilfs_palloc_mdt_file_can_grow - check potential opportunity for | ||
420 | * MDT file growing | ||
421 | * @inode: inode of metadata file using this allocator | ||
422 | * @desc_blocks: known current descriptor blocks count | ||
423 | */ | ||
424 | static inline bool nilfs_palloc_mdt_file_can_grow(struct inode *inode, | ||
425 | unsigned long desc_blocks) | ||
426 | { | ||
427 | return (nilfs_palloc_groups_per_desc_block(inode) * desc_blocks) < | ||
428 | nilfs_palloc_groups_count(inode); | ||
429 | } | ||
430 | |||
431 | /** | ||
432 | * nilfs_palloc_count_max_entries - count max number of entries that can be | ||
433 | * described by descriptor blocks count | ||
434 | * @inode: inode of metadata file using this allocator | ||
435 | * @nused: current number of used entries | ||
436 | * @nmaxp: max number of entries [out] | ||
437 | */ | ||
438 | int nilfs_palloc_count_max_entries(struct inode *inode, u64 nused, u64 *nmaxp) | ||
439 | { | ||
440 | unsigned long desc_blocks = 0; | ||
441 | u64 entries_per_desc_block, nmax; | ||
442 | int err; | ||
443 | |||
444 | err = nilfs_palloc_count_desc_blocks(inode, &desc_blocks); | ||
445 | if (unlikely(err)) | ||
446 | return err; | ||
447 | |||
448 | entries_per_desc_block = (u64)nilfs_palloc_entries_per_group(inode) * | ||
449 | nilfs_palloc_groups_per_desc_block(inode); | ||
450 | nmax = entries_per_desc_block * desc_blocks; | ||
451 | |||
452 | if (nused == nmax && | ||
453 | nilfs_palloc_mdt_file_can_grow(inode, desc_blocks)) | ||
454 | nmax += entries_per_desc_block; | ||
455 | |||
456 | if (nused > nmax) | ||
457 | return -ERANGE; | ||
458 | |||
459 | *nmaxp = nmax; | ||
460 | return 0; | ||
461 | } | ||
462 | |||
463 | /** | ||
401 | * nilfs_palloc_prepare_alloc_entry - prepare to allocate a persistent object | 464 | * nilfs_palloc_prepare_alloc_entry - prepare to allocate a persistent object |
402 | * @inode: inode of metadata file using this allocator | 465 | * @inode: inode of metadata file using this allocator |
403 | * @req: nilfs_palloc_req structure exchanged for the allocation | 466 | * @req: nilfs_palloc_req structure exchanged for the allocation |