Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0+ */
0002 /*
0003  * NILFS meta data file prototype and definitions
0004  *
0005  * Copyright (C) 2005-2008 Nippon Telegraph and Telephone Corporation.
0006  *
0007  * Written by Ryusuke Konishi.
0008  */
0009 
0010 #ifndef _NILFS_MDT_H
0011 #define _NILFS_MDT_H
0012 
0013 #include <linux/buffer_head.h>
0014 #include <linux/blockgroup_lock.h>
0015 #include "nilfs.h"
0016 #include "page.h"
0017 
0018 /**
0019  * struct nilfs_shadow_map - shadow mapping of meta data file
0020  * @bmap_store: shadow copy of bmap state
0021  * @inode: holder of page caches used in shadow mapping
0022  * @frozen_buffers: list of frozen buffers
0023  */
0024 struct nilfs_shadow_map {
0025     struct nilfs_bmap_store bmap_store;
0026     struct inode *inode;
0027     struct list_head frozen_buffers;
0028 };
0029 
0030 /**
0031  * struct nilfs_mdt_info - on-memory private data of meta data files
0032  * @mi_sem: reader/writer semaphore for meta data operations
0033  * @mi_bgl: per-blockgroup locking
0034  * @mi_entry_size: size of an entry
0035  * @mi_first_entry_offset: offset to the first entry
0036  * @mi_entries_per_block: number of entries in a block
0037  * @mi_palloc_cache: persistent object allocator cache
0038  * @mi_shadow: shadow of bmap and page caches
0039  * @mi_blocks_per_group: number of blocks in a group
0040  * @mi_blocks_per_desc_block: number of blocks per descriptor block
0041  */
0042 struct nilfs_mdt_info {
0043     struct rw_semaphore mi_sem;
0044     struct blockgroup_lock *mi_bgl;
0045     unsigned int        mi_entry_size;
0046     unsigned int        mi_first_entry_offset;
0047     unsigned long       mi_entries_per_block;
0048     struct nilfs_palloc_cache *mi_palloc_cache;
0049     struct nilfs_shadow_map *mi_shadow;
0050     unsigned long       mi_blocks_per_group;
0051     unsigned long       mi_blocks_per_desc_block;
0052 };
0053 
0054 static inline struct nilfs_mdt_info *NILFS_MDT(const struct inode *inode)
0055 {
0056     return inode->i_private;
0057 }
0058 
0059 static inline int nilfs_is_metadata_file_inode(const struct inode *inode)
0060 {
0061     return inode->i_private != NULL;
0062 }
0063 
0064 /* Default GFP flags using highmem */
0065 #define NILFS_MDT_GFP      (__GFP_RECLAIM | __GFP_IO | __GFP_HIGHMEM)
0066 
0067 int nilfs_mdt_get_block(struct inode *, unsigned long, int,
0068             void (*init_block)(struct inode *,
0069                        struct buffer_head *, void *),
0070             struct buffer_head **);
0071 int nilfs_mdt_find_block(struct inode *inode, unsigned long start,
0072              unsigned long end, unsigned long *blkoff,
0073              struct buffer_head **out_bh);
0074 int nilfs_mdt_delete_block(struct inode *, unsigned long);
0075 int nilfs_mdt_forget_block(struct inode *, unsigned long);
0076 int nilfs_mdt_fetch_dirty(struct inode *);
0077 
0078 int nilfs_mdt_init(struct inode *inode, gfp_t gfp_mask, size_t objsz);
0079 void nilfs_mdt_clear(struct inode *inode);
0080 void nilfs_mdt_destroy(struct inode *inode);
0081 
0082 void nilfs_mdt_set_entry_size(struct inode *, unsigned int, unsigned int);
0083 
0084 int nilfs_mdt_setup_shadow_map(struct inode *inode,
0085                    struct nilfs_shadow_map *shadow);
0086 int nilfs_mdt_save_to_shadow_map(struct inode *inode);
0087 void nilfs_mdt_restore_from_shadow_map(struct inode *inode);
0088 void nilfs_mdt_clear_shadow_map(struct inode *inode);
0089 int nilfs_mdt_freeze_buffer(struct inode *inode, struct buffer_head *bh);
0090 struct buffer_head *nilfs_mdt_get_frozen_buffer(struct inode *inode,
0091                         struct buffer_head *bh);
0092 
0093 static inline void nilfs_mdt_mark_dirty(struct inode *inode)
0094 {
0095     if (!test_bit(NILFS_I_DIRTY, &NILFS_I(inode)->i_state))
0096         set_bit(NILFS_I_DIRTY, &NILFS_I(inode)->i_state);
0097 }
0098 
0099 static inline void nilfs_mdt_clear_dirty(struct inode *inode)
0100 {
0101     clear_bit(NILFS_I_DIRTY, &NILFS_I(inode)->i_state);
0102 }
0103 
0104 static inline __u64 nilfs_mdt_cno(struct inode *inode)
0105 {
0106     return ((struct the_nilfs *)inode->i_sb->s_fs_info)->ns_cno;
0107 }
0108 
0109 static inline spinlock_t *
0110 nilfs_mdt_bgl_lock(struct inode *inode, unsigned int block_group)
0111 {
0112     return bgl_lock_ptr(NILFS_MDT(inode)->mi_bgl, block_group);
0113 }
0114 
0115 #endif /* _NILFS_MDT_H */