mdt.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /* SPDX-License-Identifier: GPL-2.0+ */
  2. /*
  3. * NILFS meta data file prototype and definitions
  4. *
  5. * Copyright (C) 2005-2008 Nippon Telegraph and Telephone Corporation.
  6. *
  7. * Written by Ryusuke Konishi.
  8. */
  9. #ifndef _NILFS_MDT_H
  10. #define _NILFS_MDT_H
  11. #include <linux/buffer_head.h>
  12. #include <linux/blockgroup_lock.h>
  13. #include "nilfs.h"
  14. #include "page.h"
  15. /**
  16. * struct nilfs_shadow_map - shadow mapping of meta data file
  17. * @bmap_store: shadow copy of bmap state
  18. * @inode: holder of page caches used in shadow mapping
  19. * @frozen_buffers: list of frozen buffers
  20. */
  21. struct nilfs_shadow_map {
  22. struct nilfs_bmap_store bmap_store;
  23. struct inode *inode;
  24. struct list_head frozen_buffers;
  25. };
  26. /**
  27. * struct nilfs_mdt_info - on-memory private data of meta data files
  28. * @mi_sem: reader/writer semaphore for meta data operations
  29. * @mi_bgl: per-blockgroup locking
  30. * @mi_entry_size: size of an entry
  31. * @mi_first_entry_offset: offset to the first entry
  32. * @mi_entries_per_block: number of entries in a block
  33. * @mi_palloc_cache: persistent object allocator cache
  34. * @mi_shadow: shadow of bmap and page caches
  35. * @mi_blocks_per_group: number of blocks in a group
  36. * @mi_blocks_per_desc_block: number of blocks per descriptor block
  37. */
  38. struct nilfs_mdt_info {
  39. struct rw_semaphore mi_sem;
  40. struct blockgroup_lock *mi_bgl;
  41. unsigned int mi_entry_size;
  42. unsigned int mi_first_entry_offset;
  43. unsigned long mi_entries_per_block;
  44. struct nilfs_palloc_cache *mi_palloc_cache;
  45. struct nilfs_shadow_map *mi_shadow;
  46. unsigned long mi_blocks_per_group;
  47. unsigned long mi_blocks_per_desc_block;
  48. };
  49. static inline struct nilfs_mdt_info *NILFS_MDT(const struct inode *inode)
  50. {
  51. return inode->i_private;
  52. }
  53. static inline int nilfs_is_metadata_file_inode(const struct inode *inode)
  54. {
  55. return inode->i_private != NULL;
  56. }
  57. /* Default GFP flags using highmem */
  58. #define NILFS_MDT_GFP (__GFP_RECLAIM | __GFP_IO | __GFP_HIGHMEM)
  59. int nilfs_mdt_get_block(struct inode *, unsigned long, int,
  60. void (*init_block)(struct inode *,
  61. struct buffer_head *, void *),
  62. struct buffer_head **);
  63. int nilfs_mdt_find_block(struct inode *inode, unsigned long start,
  64. unsigned long end, unsigned long *blkoff,
  65. struct buffer_head **out_bh);
  66. int nilfs_mdt_delete_block(struct inode *, unsigned long);
  67. int nilfs_mdt_forget_block(struct inode *, unsigned long);
  68. int nilfs_mdt_fetch_dirty(struct inode *);
  69. int nilfs_mdt_init(struct inode *inode, gfp_t gfp_mask, size_t objsz);
  70. void nilfs_mdt_clear(struct inode *inode);
  71. void nilfs_mdt_destroy(struct inode *inode);
  72. void nilfs_mdt_set_entry_size(struct inode *, unsigned int, unsigned int);
  73. int nilfs_mdt_setup_shadow_map(struct inode *inode,
  74. struct nilfs_shadow_map *shadow);
  75. int nilfs_mdt_save_to_shadow_map(struct inode *inode);
  76. void nilfs_mdt_restore_from_shadow_map(struct inode *inode);
  77. void nilfs_mdt_clear_shadow_map(struct inode *inode);
  78. int nilfs_mdt_freeze_buffer(struct inode *inode, struct buffer_head *bh);
  79. struct buffer_head *nilfs_mdt_get_frozen_buffer(struct inode *inode,
  80. struct buffer_head *bh);
  81. static inline void nilfs_mdt_mark_dirty(struct inode *inode)
  82. {
  83. if (!test_bit(NILFS_I_DIRTY, &NILFS_I(inode)->i_state))
  84. set_bit(NILFS_I_DIRTY, &NILFS_I(inode)->i_state);
  85. }
  86. static inline void nilfs_mdt_clear_dirty(struct inode *inode)
  87. {
  88. clear_bit(NILFS_I_DIRTY, &NILFS_I(inode)->i_state);
  89. }
  90. static inline __u64 nilfs_mdt_cno(struct inode *inode)
  91. {
  92. return ((struct the_nilfs *)inode->i_sb->s_fs_info)->ns_cno;
  93. }
  94. static inline spinlock_t *
  95. nilfs_mdt_bgl_lock(struct inode *inode, unsigned int block_group)
  96. {
  97. return bgl_lock_ptr(NILFS_MDT(inode)->mi_bgl, block_group);
  98. }
  99. #endif /* _NILFS_MDT_H */