This source file includes following definitions.
- nilfs_gccache_submit_read_data
- nilfs_gccache_submit_read_node
- nilfs_gccache_wait_and_mark_dirty
- nilfs_init_gcinode
- nilfs_remove_all_gcinodes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 #include <linux/buffer_head.h>
25 #include <linux/mpage.h>
26 #include <linux/hash.h>
27 #include <linux/slab.h>
28 #include <linux/swap.h>
29 #include "nilfs.h"
30 #include "btree.h"
31 #include "btnode.h"
32 #include "page.h"
33 #include "mdt.h"
34 #include "dat.h"
35 #include "ifile.h"
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58 int nilfs_gccache_submit_read_data(struct inode *inode, sector_t blkoff,
59 sector_t pbn, __u64 vbn,
60 struct buffer_head **out_bh)
61 {
62 struct buffer_head *bh;
63 int err;
64
65 bh = nilfs_grab_buffer(inode, inode->i_mapping, blkoff, 0);
66 if (unlikely(!bh))
67 return -ENOMEM;
68
69 if (buffer_uptodate(bh))
70 goto out;
71
72 if (pbn == 0) {
73 struct the_nilfs *nilfs = inode->i_sb->s_fs_info;
74
75 err = nilfs_dat_translate(nilfs->ns_dat, vbn, &pbn);
76 if (unlikely(err)) {
77 brelse(bh);
78 goto failed;
79 }
80 }
81
82 lock_buffer(bh);
83 if (buffer_uptodate(bh)) {
84 unlock_buffer(bh);
85 goto out;
86 }
87
88 if (!buffer_mapped(bh)) {
89 bh->b_bdev = inode->i_sb->s_bdev;
90 set_buffer_mapped(bh);
91 }
92 bh->b_blocknr = pbn;
93 bh->b_end_io = end_buffer_read_sync;
94 get_bh(bh);
95 submit_bh(REQ_OP_READ, 0, bh);
96 if (vbn)
97 bh->b_blocknr = vbn;
98 out:
99 err = 0;
100 *out_bh = bh;
101
102 failed:
103 unlock_page(bh->b_page);
104 put_page(bh->b_page);
105 return err;
106 }
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126 int nilfs_gccache_submit_read_node(struct inode *inode, sector_t pbn,
127 __u64 vbn, struct buffer_head **out_bh)
128 {
129 int ret;
130
131 ret = nilfs_btnode_submit_block(&NILFS_I(inode)->i_btnode_cache,
132 vbn ? : pbn, pbn, REQ_OP_READ, 0,
133 out_bh, &pbn);
134 if (ret == -EEXIST)
135 ret = 0;
136 return ret;
137 }
138
139 int nilfs_gccache_wait_and_mark_dirty(struct buffer_head *bh)
140 {
141 wait_on_buffer(bh);
142 if (!buffer_uptodate(bh)) {
143 struct inode *inode = bh->b_page->mapping->host;
144
145 nilfs_msg(inode->i_sb, KERN_ERR,
146 "I/O error reading %s block for GC (ino=%lu, vblocknr=%llu)",
147 buffer_nilfs_node(bh) ? "node" : "data",
148 inode->i_ino, (unsigned long long)bh->b_blocknr);
149 return -EIO;
150 }
151 if (buffer_dirty(bh))
152 return -EEXIST;
153
154 if (buffer_nilfs_node(bh) && nilfs_btree_broken_node_block(bh)) {
155 clear_buffer_uptodate(bh);
156 return -EIO;
157 }
158 mark_buffer_dirty(bh);
159 return 0;
160 }
161
162 int nilfs_init_gcinode(struct inode *inode)
163 {
164 struct nilfs_inode_info *ii = NILFS_I(inode);
165
166 inode->i_mode = S_IFREG;
167 mapping_set_gfp_mask(inode->i_mapping, GFP_NOFS);
168 inode->i_mapping->a_ops = &empty_aops;
169
170 ii->i_flags = 0;
171 nilfs_bmap_init_gc(ii->i_bmap);
172
173 return 0;
174 }
175
176
177
178
179 void nilfs_remove_all_gcinodes(struct the_nilfs *nilfs)
180 {
181 struct list_head *head = &nilfs->ns_gc_inodes;
182 struct nilfs_inode_info *ii;
183
184 while (!list_empty(head)) {
185 ii = list_first_entry(head, struct nilfs_inode_info, i_dirty);
186 list_del_init(&ii->i_dirty);
187 truncate_inode_pages(&ii->vfs_inode.i_data, 0);
188 nilfs_btnode_cache_clear(&ii->i_btnode_cache);
189 iput(&ii->vfs_inode);
190 }
191 }