1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25#include <linux/types.h>
26#include <linux/buffer_head.h>
27#include "nilfs.h"
28#include "mdt.h"
29#include "alloc.h"
30#include "ifile.h"
31
32
33
34
35
36
37struct nilfs_ifile_info {
38 struct nilfs_mdt_info mi;
39 struct nilfs_palloc_cache palloc_cache;
40};
41
42static inline struct nilfs_ifile_info *NILFS_IFILE_I(struct inode *ifile)
43{
44 return (struct nilfs_ifile_info *)NILFS_MDT(ifile);
45}
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65int nilfs_ifile_create_inode(struct inode *ifile, ino_t *out_ino,
66 struct buffer_head **out_bh)
67{
68 struct nilfs_palloc_req req;
69 int ret;
70
71 req.pr_entry_nr = 0;
72
73 req.pr_entry_bh = NULL;
74
75 ret = nilfs_palloc_prepare_alloc_entry(ifile, &req);
76 if (!ret) {
77 ret = nilfs_palloc_get_entry_block(ifile, req.pr_entry_nr, 1,
78 &req.pr_entry_bh);
79 if (ret < 0)
80 nilfs_palloc_abort_alloc_entry(ifile, &req);
81 }
82 if (ret < 0) {
83 brelse(req.pr_entry_bh);
84 return ret;
85 }
86 nilfs_palloc_commit_alloc_entry(ifile, &req);
87 mark_buffer_dirty(req.pr_entry_bh);
88 nilfs_mdt_mark_dirty(ifile);
89 *out_ino = (ino_t)req.pr_entry_nr;
90 *out_bh = req.pr_entry_bh;
91 return 0;
92}
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108int nilfs_ifile_delete_inode(struct inode *ifile, ino_t ino)
109{
110 struct nilfs_palloc_req req = {
111 .pr_entry_nr = ino, .pr_entry_bh = NULL
112 };
113 struct nilfs_inode *raw_inode;
114 void *kaddr;
115 int ret;
116
117 ret = nilfs_palloc_prepare_free_entry(ifile, &req);
118 if (!ret) {
119 ret = nilfs_palloc_get_entry_block(ifile, req.pr_entry_nr, 0,
120 &req.pr_entry_bh);
121 if (ret < 0)
122 nilfs_palloc_abort_free_entry(ifile, &req);
123 }
124 if (ret < 0) {
125 brelse(req.pr_entry_bh);
126 return ret;
127 }
128
129 kaddr = kmap_atomic(req.pr_entry_bh->b_page);
130 raw_inode = nilfs_palloc_block_get_entry(ifile, req.pr_entry_nr,
131 req.pr_entry_bh, kaddr);
132 raw_inode->i_flags = 0;
133 kunmap_atomic(kaddr);
134
135 mark_buffer_dirty(req.pr_entry_bh);
136 brelse(req.pr_entry_bh);
137
138 nilfs_palloc_commit_free_entry(ifile, &req);
139
140 return 0;
141}
142
143int nilfs_ifile_get_inode_block(struct inode *ifile, ino_t ino,
144 struct buffer_head **out_bh)
145{
146 struct super_block *sb = ifile->i_sb;
147 int err;
148
149 if (unlikely(!NILFS_VALID_INODE(sb, ino))) {
150 nilfs_error(sb, __func__, "bad inode number: %lu",
151 (unsigned long) ino);
152 return -EINVAL;
153 }
154
155 err = nilfs_palloc_get_entry_block(ifile, ino, 0, out_bh);
156 if (unlikely(err))
157 nilfs_warning(sb, __func__, "unable to read inode: %lu",
158 (unsigned long) ino);
159 return err;
160}
161
162
163
164
165
166
167
168
169
170int nilfs_ifile_read(struct super_block *sb, struct nilfs_root *root,
171 size_t inode_size, struct nilfs_inode *raw_inode,
172 struct inode **inodep)
173{
174 struct inode *ifile;
175 int err;
176
177 ifile = nilfs_iget_locked(sb, root, NILFS_IFILE_INO);
178 if (unlikely(!ifile))
179 return -ENOMEM;
180 if (!(ifile->i_state & I_NEW))
181 goto out;
182
183 err = nilfs_mdt_init(ifile, NILFS_MDT_GFP,
184 sizeof(struct nilfs_ifile_info));
185 if (err)
186 goto failed;
187
188 err = nilfs_palloc_init_blockgroup(ifile, inode_size);
189 if (err)
190 goto failed;
191
192 nilfs_palloc_setup_cache(ifile, &NILFS_IFILE_I(ifile)->palloc_cache);
193
194 err = nilfs_read_inode_common(ifile, raw_inode);
195 if (err)
196 goto failed;
197
198 unlock_new_inode(ifile);
199 out:
200 *inodep = ifile;
201 return 0;
202 failed:
203 iget_failed(ifile);
204 return err;
205}
206