1ae98043fSRyusuke Konishi /* SPDX-License-Identifier: GPL-2.0+ */
25eb563f5SRyusuke Konishi /*
394ee1d91SRyusuke Konishi * NILFS meta data file prototype and definitions
45eb563f5SRyusuke Konishi *
55eb563f5SRyusuke Konishi * Copyright (C) 2005-2008 Nippon Telegraph and Telephone Corporation.
65eb563f5SRyusuke Konishi *
74b420ab4SRyusuke Konishi * Written by Ryusuke Konishi.
85eb563f5SRyusuke Konishi */
95eb563f5SRyusuke Konishi
105eb563f5SRyusuke Konishi #ifndef _NILFS_MDT_H
115eb563f5SRyusuke Konishi #define _NILFS_MDT_H
125eb563f5SRyusuke Konishi
135eb563f5SRyusuke Konishi #include <linux/buffer_head.h>
145eb563f5SRyusuke Konishi #include <linux/blockgroup_lock.h>
155eb563f5SRyusuke Konishi #include "nilfs.h"
165eb563f5SRyusuke Konishi #include "page.h"
175eb563f5SRyusuke Konishi
18f5974c8fSVyacheslav Dubeyko /**
19f5974c8fSVyacheslav Dubeyko * struct nilfs_shadow_map - shadow mapping of meta data file
20f5974c8fSVyacheslav Dubeyko * @bmap_store: shadow copy of bmap state
21*6e211930SRyusuke Konishi * @inode: holder of page caches used in shadow mapping
22f5974c8fSVyacheslav Dubeyko * @frozen_buffers: list of frozen buffers
23f5974c8fSVyacheslav Dubeyko */
24ebdfed4dSRyusuke Konishi struct nilfs_shadow_map {
25ebdfed4dSRyusuke Konishi struct nilfs_bmap_store bmap_store;
26*6e211930SRyusuke Konishi struct inode *inode;
27ebdfed4dSRyusuke Konishi struct list_head frozen_buffers;
28ebdfed4dSRyusuke Konishi };
29ebdfed4dSRyusuke Konishi
305eb563f5SRyusuke Konishi /**
315eb563f5SRyusuke Konishi * struct nilfs_mdt_info - on-memory private data of meta data files
325eb563f5SRyusuke Konishi * @mi_sem: reader/writer semaphore for meta data operations
335eb563f5SRyusuke Konishi * @mi_bgl: per-blockgroup locking
345eb563f5SRyusuke Konishi * @mi_entry_size: size of an entry
355eb563f5SRyusuke Konishi * @mi_first_entry_offset: offset to the first entry
365eb563f5SRyusuke Konishi * @mi_entries_per_block: number of entries in a block
37db38d5adSRyusuke Konishi * @mi_palloc_cache: persistent object allocator cache
38ebdfed4dSRyusuke Konishi * @mi_shadow: shadow of bmap and page caches
395eb563f5SRyusuke Konishi * @mi_blocks_per_group: number of blocks in a group
405eb563f5SRyusuke Konishi * @mi_blocks_per_desc_block: number of blocks per descriptor block
415eb563f5SRyusuke Konishi */
425eb563f5SRyusuke Konishi struct nilfs_mdt_info {
435eb563f5SRyusuke Konishi struct rw_semaphore mi_sem;
445eb563f5SRyusuke Konishi struct blockgroup_lock *mi_bgl;
450c6c44cbSRyusuke Konishi unsigned int mi_entry_size;
460c6c44cbSRyusuke Konishi unsigned int mi_first_entry_offset;
475eb563f5SRyusuke Konishi unsigned long mi_entries_per_block;
48db38d5adSRyusuke Konishi struct nilfs_palloc_cache *mi_palloc_cache;
49ebdfed4dSRyusuke Konishi struct nilfs_shadow_map *mi_shadow;
505eb563f5SRyusuke Konishi unsigned long mi_blocks_per_group;
515eb563f5SRyusuke Konishi unsigned long mi_blocks_per_desc_block;
525eb563f5SRyusuke Konishi };
535eb563f5SRyusuke Konishi
NILFS_MDT(const struct inode * inode)545eb563f5SRyusuke Konishi static inline struct nilfs_mdt_info *NILFS_MDT(const struct inode *inode)
555eb563f5SRyusuke Konishi {
565eb563f5SRyusuke Konishi return inode->i_private;
575eb563f5SRyusuke Konishi }
585eb563f5SRyusuke Konishi
nilfs_is_metadata_file_inode(const struct inode * inode)592d19961dSRyusuke Konishi static inline int nilfs_is_metadata_file_inode(const struct inode *inode)
602d19961dSRyusuke Konishi {
612d19961dSRyusuke Konishi return inode->i_private != NULL;
622d19961dSRyusuke Konishi }
632d19961dSRyusuke Konishi
645eb563f5SRyusuke Konishi /* Default GFP flags using highmem */
6571baba4bSMel Gorman #define NILFS_MDT_GFP (__GFP_RECLAIM | __GFP_IO | __GFP_HIGHMEM)
665eb563f5SRyusuke Konishi
675eb563f5SRyusuke Konishi int nilfs_mdt_get_block(struct inode *, unsigned long, int,
685eb563f5SRyusuke Konishi void (*init_block)(struct inode *,
695eb563f5SRyusuke Konishi struct buffer_head *, void *),
705eb563f5SRyusuke Konishi struct buffer_head **);
71fa33915cSRyusuke Konishi int nilfs_mdt_find_block(struct inode *inode, unsigned long start,
72fa33915cSRyusuke Konishi unsigned long end, unsigned long *blkoff,
73fa33915cSRyusuke Konishi struct buffer_head **out_bh);
745eb563f5SRyusuke Konishi int nilfs_mdt_delete_block(struct inode *, unsigned long);
755eb563f5SRyusuke Konishi int nilfs_mdt_forget_block(struct inode *, unsigned long);
765eb563f5SRyusuke Konishi int nilfs_mdt_fetch_dirty(struct inode *);
775eb563f5SRyusuke Konishi
78f1e89c86SRyusuke Konishi int nilfs_mdt_init(struct inode *inode, gfp_t gfp_mask, size_t objsz);
792d19961dSRyusuke Konishi void nilfs_mdt_clear(struct inode *inode);
802d19961dSRyusuke Konishi void nilfs_mdt_destroy(struct inode *inode);
812d19961dSRyusuke Konishi
820c6c44cbSRyusuke Konishi void nilfs_mdt_set_entry_size(struct inode *, unsigned int, unsigned int);
835eb563f5SRyusuke Konishi
84ebdfed4dSRyusuke Konishi int nilfs_mdt_setup_shadow_map(struct inode *inode,
85ebdfed4dSRyusuke Konishi struct nilfs_shadow_map *shadow);
86ebdfed4dSRyusuke Konishi int nilfs_mdt_save_to_shadow_map(struct inode *inode);
87ebdfed4dSRyusuke Konishi void nilfs_mdt_restore_from_shadow_map(struct inode *inode);
88ebdfed4dSRyusuke Konishi void nilfs_mdt_clear_shadow_map(struct inode *inode);
89b1f6a4f2SRyusuke Konishi int nilfs_mdt_freeze_buffer(struct inode *inode, struct buffer_head *bh);
90b1f6a4f2SRyusuke Konishi struct buffer_head *nilfs_mdt_get_frozen_buffer(struct inode *inode,
91b1f6a4f2SRyusuke Konishi struct buffer_head *bh);
925eb563f5SRyusuke Konishi
nilfs_mdt_mark_dirty(struct inode * inode)935eb563f5SRyusuke Konishi static inline void nilfs_mdt_mark_dirty(struct inode *inode)
945eb563f5SRyusuke Konishi {
955eb563f5SRyusuke Konishi if (!test_bit(NILFS_I_DIRTY, &NILFS_I(inode)->i_state))
965eb563f5SRyusuke Konishi set_bit(NILFS_I_DIRTY, &NILFS_I(inode)->i_state);
975eb563f5SRyusuke Konishi }
985eb563f5SRyusuke Konishi
nilfs_mdt_clear_dirty(struct inode * inode)995eb563f5SRyusuke Konishi static inline void nilfs_mdt_clear_dirty(struct inode *inode)
1005eb563f5SRyusuke Konishi {
1015eb563f5SRyusuke Konishi clear_bit(NILFS_I_DIRTY, &NILFS_I(inode)->i_state);
1025eb563f5SRyusuke Konishi }
1035eb563f5SRyusuke Konishi
nilfs_mdt_cno(struct inode * inode)1045eb563f5SRyusuke Konishi static inline __u64 nilfs_mdt_cno(struct inode *inode)
1055eb563f5SRyusuke Konishi {
1060ef28f9aSRyusuke Konishi return ((struct the_nilfs *)inode->i_sb->s_fs_info)->ns_cno;
1075eb563f5SRyusuke Konishi }
1085eb563f5SRyusuke Konishi
1090de6d6b9SRyusuke Konishi static inline spinlock_t *
nilfs_mdt_bgl_lock(struct inode * inode,unsigned int block_group)1100de6d6b9SRyusuke Konishi nilfs_mdt_bgl_lock(struct inode *inode, unsigned int block_group)
1110de6d6b9SRyusuke Konishi {
1120de6d6b9SRyusuke Konishi return bgl_lock_ptr(NILFS_MDT(inode)->mi_bgl, block_group);
1130de6d6b9SRyusuke Konishi }
1145eb563f5SRyusuke Konishi
1155eb563f5SRyusuke Konishi #endif /* _NILFS_MDT_H */
116