alloc.h 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /* SPDX-License-Identifier: GPL-2.0+ */
  2. /*
  3. * alloc.h - persistent object (dat entry/disk inode) allocator/deallocator
  4. *
  5. * Copyright (C) 2006-2008 Nippon Telegraph and Telephone Corporation.
  6. *
  7. * Originally written by Koji Sato.
  8. * Two allocators were unified by Ryusuke Konishi and Amagai Yoshiji.
  9. */
  10. #ifndef _NILFS_ALLOC_H
  11. #define _NILFS_ALLOC_H
  12. #include <linux/types.h>
  13. #include <linux/buffer_head.h>
  14. #include <linux/fs.h>
  15. /**
  16. * nilfs_palloc_entries_per_group - get the number of entries per group
  17. * @inode: inode of metadata file using this allocator
  18. *
  19. * The number of entries per group is defined by the number of bits
  20. * that a bitmap block can maintain.
  21. */
  22. static inline unsigned long
  23. nilfs_palloc_entries_per_group(const struct inode *inode)
  24. {
  25. return 1UL << (inode->i_blkbits + 3 /* log2(8 = CHAR_BITS) */);
  26. }
  27. int nilfs_palloc_init_blockgroup(struct inode *, unsigned int);
  28. int nilfs_palloc_get_entry_block(struct inode *, __u64, int,
  29. struct buffer_head **);
  30. void *nilfs_palloc_block_get_entry(const struct inode *, __u64,
  31. const struct buffer_head *, void *);
  32. int nilfs_palloc_count_max_entries(struct inode *, u64, u64 *);
  33. /**
  34. * nilfs_palloc_req - persistent allocator request and reply
  35. * @pr_entry_nr: entry number (vblocknr or inode number)
  36. * @pr_desc_bh: buffer head of the buffer containing block group descriptors
  37. * @pr_bitmap_bh: buffer head of the buffer containing a block group bitmap
  38. * @pr_entry_bh: buffer head of the buffer containing translation entries
  39. */
  40. struct nilfs_palloc_req {
  41. __u64 pr_entry_nr;
  42. struct buffer_head *pr_desc_bh;
  43. struct buffer_head *pr_bitmap_bh;
  44. struct buffer_head *pr_entry_bh;
  45. };
  46. int nilfs_palloc_prepare_alloc_entry(struct inode *,
  47. struct nilfs_palloc_req *);
  48. void nilfs_palloc_commit_alloc_entry(struct inode *,
  49. struct nilfs_palloc_req *);
  50. void nilfs_palloc_abort_alloc_entry(struct inode *, struct nilfs_palloc_req *);
  51. void nilfs_palloc_commit_free_entry(struct inode *, struct nilfs_palloc_req *);
  52. int nilfs_palloc_prepare_free_entry(struct inode *, struct nilfs_palloc_req *);
  53. void nilfs_palloc_abort_free_entry(struct inode *, struct nilfs_palloc_req *);
  54. int nilfs_palloc_freev(struct inode *, __u64 *, size_t);
  55. #define nilfs_set_bit_atomic ext2_set_bit_atomic
  56. #define nilfs_clear_bit_atomic ext2_clear_bit_atomic
  57. #define nilfs_find_next_zero_bit find_next_zero_bit_le
  58. #define nilfs_find_next_bit find_next_bit_le
  59. /**
  60. * struct nilfs_bh_assoc - block offset and buffer head association
  61. * @blkoff: block offset
  62. * @bh: buffer head
  63. */
  64. struct nilfs_bh_assoc {
  65. unsigned long blkoff;
  66. struct buffer_head *bh;
  67. };
  68. /**
  69. * struct nilfs_palloc_cache - persistent object allocator cache
  70. * @lock: cache protecting lock
  71. * @prev_desc: blockgroup descriptors cache
  72. * @prev_bitmap: blockgroup bitmap cache
  73. * @prev_entry: translation entries cache
  74. */
  75. struct nilfs_palloc_cache {
  76. spinlock_t lock;
  77. struct nilfs_bh_assoc prev_desc;
  78. struct nilfs_bh_assoc prev_bitmap;
  79. struct nilfs_bh_assoc prev_entry;
  80. };
  81. void nilfs_palloc_setup_cache(struct inode *inode,
  82. struct nilfs_palloc_cache *cache);
  83. void nilfs_palloc_clear_cache(struct inode *inode);
  84. void nilfs_palloc_destroy_cache(struct inode *inode);
  85. #endif /* _NILFS_ALLOC_H */