mdt.h 3.7 KB

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