GNU Linux-libre 4.14.332-gnu1
[releases.git] / fs / nilfs2 / mdt.h
1 /*
2  * mdt.h - NILFS meta data file prototype and definitions
3  *
4  * Copyright (C) 2005-2008 Nippon Telegraph and Telephone Corporation.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * Written by Ryusuke Konishi.
17  */
18
19 #ifndef _NILFS_MDT_H
20 #define _NILFS_MDT_H
21
22 #include <linux/buffer_head.h>
23 #include <linux/blockgroup_lock.h>
24 #include "nilfs.h"
25 #include "page.h"
26
27 /**
28  * struct nilfs_shadow_map - shadow mapping of meta data file
29  * @bmap_store: shadow copy of bmap state
30  * @inode: holder of page caches used in shadow mapping
31  * @frozen_buffers: list of frozen buffers
32  */
33 struct nilfs_shadow_map {
34         struct nilfs_bmap_store bmap_store;
35         struct inode *inode;
36         struct list_head frozen_buffers;
37 };
38
39 /**
40  * struct nilfs_mdt_info - on-memory private data of meta data files
41  * @mi_sem: reader/writer semaphore for meta data operations
42  * @mi_bgl: per-blockgroup locking
43  * @mi_entry_size: size of an entry
44  * @mi_first_entry_offset: offset to the first entry
45  * @mi_entries_per_block: number of entries in a block
46  * @mi_palloc_cache: persistent object allocator cache
47  * @mi_shadow: shadow of bmap and page caches
48  * @mi_blocks_per_group: number of blocks in a group
49  * @mi_blocks_per_desc_block: number of blocks per descriptor block
50  */
51 struct nilfs_mdt_info {
52         struct rw_semaphore     mi_sem;
53         struct blockgroup_lock *mi_bgl;
54         unsigned int            mi_entry_size;
55         unsigned int            mi_first_entry_offset;
56         unsigned long           mi_entries_per_block;
57         struct nilfs_palloc_cache *mi_palloc_cache;
58         struct nilfs_shadow_map *mi_shadow;
59         unsigned long           mi_blocks_per_group;
60         unsigned long           mi_blocks_per_desc_block;
61 };
62
63 static inline struct nilfs_mdt_info *NILFS_MDT(const struct inode *inode)
64 {
65         return inode->i_private;
66 }
67
68 static inline int nilfs_is_metadata_file_inode(const struct inode *inode)
69 {
70         return inode->i_private != NULL;
71 }
72
73 /* Default GFP flags using highmem */
74 #define NILFS_MDT_GFP      (__GFP_RECLAIM | __GFP_IO | __GFP_HIGHMEM)
75
76 int nilfs_mdt_get_block(struct inode *, unsigned long, int,
77                         void (*init_block)(struct inode *,
78                                            struct buffer_head *, void *),
79                         struct buffer_head **);
80 int nilfs_mdt_find_block(struct inode *inode, unsigned long start,
81                          unsigned long end, unsigned long *blkoff,
82                          struct buffer_head **out_bh);
83 int nilfs_mdt_delete_block(struct inode *, unsigned long);
84 int nilfs_mdt_forget_block(struct inode *, unsigned long);
85 int nilfs_mdt_fetch_dirty(struct inode *);
86
87 int nilfs_mdt_init(struct inode *inode, gfp_t gfp_mask, size_t objsz);
88 void nilfs_mdt_clear(struct inode *inode);
89 void nilfs_mdt_destroy(struct inode *inode);
90
91 void nilfs_mdt_set_entry_size(struct inode *, unsigned int, unsigned int);
92
93 int nilfs_mdt_setup_shadow_map(struct inode *inode,
94                                struct nilfs_shadow_map *shadow);
95 int nilfs_mdt_save_to_shadow_map(struct inode *inode);
96 void nilfs_mdt_restore_from_shadow_map(struct inode *inode);
97 void nilfs_mdt_clear_shadow_map(struct inode *inode);
98 int nilfs_mdt_freeze_buffer(struct inode *inode, struct buffer_head *bh);
99 struct buffer_head *nilfs_mdt_get_frozen_buffer(struct inode *inode,
100                                                 struct buffer_head *bh);
101
102 static inline void nilfs_mdt_mark_dirty(struct inode *inode)
103 {
104         if (!test_bit(NILFS_I_DIRTY, &NILFS_I(inode)->i_state))
105                 set_bit(NILFS_I_DIRTY, &NILFS_I(inode)->i_state);
106 }
107
108 static inline void nilfs_mdt_clear_dirty(struct inode *inode)
109 {
110         clear_bit(NILFS_I_DIRTY, &NILFS_I(inode)->i_state);
111 }
112
113 static inline __u64 nilfs_mdt_cno(struct inode *inode)
114 {
115         return ((struct the_nilfs *)inode->i_sb->s_fs_info)->ns_cno;
116 }
117
118 static inline spinlock_t *
119 nilfs_mdt_bgl_lock(struct inode *inode, unsigned int block_group)
120 {
121         return bgl_lock_ptr(NILFS_MDT(inode)->mi_bgl, block_group);
122 }
123
124 #endif /* _NILFS_MDT_H */