diff options
Diffstat (limited to 'fs/jffs2/malloc.c')
-rw-r--r-- | fs/jffs2/malloc.c | 127 |
1 files changed, 120 insertions, 7 deletions
diff --git a/fs/jffs2/malloc.c b/fs/jffs2/malloc.c index 036cbd11c004..4889d0700c0e 100644 --- a/fs/jffs2/malloc.c +++ b/fs/jffs2/malloc.c | |||
@@ -26,6 +26,10 @@ static kmem_cache_t *tmp_dnode_info_slab; | |||
26 | static kmem_cache_t *raw_node_ref_slab; | 26 | static kmem_cache_t *raw_node_ref_slab; |
27 | static kmem_cache_t *node_frag_slab; | 27 | static kmem_cache_t *node_frag_slab; |
28 | static kmem_cache_t *inode_cache_slab; | 28 | static kmem_cache_t *inode_cache_slab; |
29 | #ifdef CONFIG_JFFS2_FS_XATTR | ||
30 | static kmem_cache_t *xattr_datum_cache; | ||
31 | static kmem_cache_t *xattr_ref_cache; | ||
32 | #endif | ||
29 | 33 | ||
30 | int __init jffs2_create_slab_caches(void) | 34 | int __init jffs2_create_slab_caches(void) |
31 | { | 35 | { |
@@ -53,8 +57,8 @@ int __init jffs2_create_slab_caches(void) | |||
53 | if (!tmp_dnode_info_slab) | 57 | if (!tmp_dnode_info_slab) |
54 | goto err; | 58 | goto err; |
55 | 59 | ||
56 | raw_node_ref_slab = kmem_cache_create("jffs2_raw_node_ref", | 60 | raw_node_ref_slab = kmem_cache_create("jffs2_refblock", |
57 | sizeof(struct jffs2_raw_node_ref), | 61 | sizeof(struct jffs2_raw_node_ref) * (REFS_PER_BLOCK + 1), |
58 | 0, 0, NULL, NULL); | 62 | 0, 0, NULL, NULL); |
59 | if (!raw_node_ref_slab) | 63 | if (!raw_node_ref_slab) |
60 | goto err; | 64 | goto err; |
@@ -68,8 +72,24 @@ int __init jffs2_create_slab_caches(void) | |||
68 | inode_cache_slab = kmem_cache_create("jffs2_inode_cache", | 72 | inode_cache_slab = kmem_cache_create("jffs2_inode_cache", |
69 | sizeof(struct jffs2_inode_cache), | 73 | sizeof(struct jffs2_inode_cache), |
70 | 0, 0, NULL, NULL); | 74 | 0, 0, NULL, NULL); |
71 | if (inode_cache_slab) | 75 | if (!inode_cache_slab) |
72 | return 0; | 76 | goto err; |
77 | |||
78 | #ifdef CONFIG_JFFS2_FS_XATTR | ||
79 | xattr_datum_cache = kmem_cache_create("jffs2_xattr_datum", | ||
80 | sizeof(struct jffs2_xattr_datum), | ||
81 | 0, 0, NULL, NULL); | ||
82 | if (!xattr_datum_cache) | ||
83 | goto err; | ||
84 | |||
85 | xattr_ref_cache = kmem_cache_create("jffs2_xattr_ref", | ||
86 | sizeof(struct jffs2_xattr_ref), | ||
87 | 0, 0, NULL, NULL); | ||
88 | if (!xattr_ref_cache) | ||
89 | goto err; | ||
90 | #endif | ||
91 | |||
92 | return 0; | ||
73 | err: | 93 | err: |
74 | jffs2_destroy_slab_caches(); | 94 | jffs2_destroy_slab_caches(); |
75 | return -ENOMEM; | 95 | return -ENOMEM; |
@@ -91,6 +111,12 @@ void jffs2_destroy_slab_caches(void) | |||
91 | kmem_cache_destroy(node_frag_slab); | 111 | kmem_cache_destroy(node_frag_slab); |
92 | if(inode_cache_slab) | 112 | if(inode_cache_slab) |
93 | kmem_cache_destroy(inode_cache_slab); | 113 | kmem_cache_destroy(inode_cache_slab); |
114 | #ifdef CONFIG_JFFS2_FS_XATTR | ||
115 | if (xattr_datum_cache) | ||
116 | kmem_cache_destroy(xattr_datum_cache); | ||
117 | if (xattr_ref_cache) | ||
118 | kmem_cache_destroy(xattr_ref_cache); | ||
119 | #endif | ||
94 | } | 120 | } |
95 | 121 | ||
96 | struct jffs2_full_dirent *jffs2_alloc_full_dirent(int namesize) | 122 | struct jffs2_full_dirent *jffs2_alloc_full_dirent(int namesize) |
@@ -164,15 +190,65 @@ void jffs2_free_tmp_dnode_info(struct jffs2_tmp_dnode_info *x) | |||
164 | kmem_cache_free(tmp_dnode_info_slab, x); | 190 | kmem_cache_free(tmp_dnode_info_slab, x); |
165 | } | 191 | } |
166 | 192 | ||
167 | struct jffs2_raw_node_ref *jffs2_alloc_raw_node_ref(void) | 193 | struct jffs2_raw_node_ref *jffs2_alloc_refblock(void) |
168 | { | 194 | { |
169 | struct jffs2_raw_node_ref *ret; | 195 | struct jffs2_raw_node_ref *ret; |
196 | |||
170 | ret = kmem_cache_alloc(raw_node_ref_slab, GFP_KERNEL); | 197 | ret = kmem_cache_alloc(raw_node_ref_slab, GFP_KERNEL); |
171 | dbg_memalloc("%p\n", ret); | 198 | if (ret) { |
199 | int i = 0; | ||
200 | for (i=0; i < REFS_PER_BLOCK; i++) { | ||
201 | ret[i].flash_offset = REF_EMPTY_NODE; | ||
202 | ret[i].next_in_ino = NULL; | ||
203 | } | ||
204 | ret[i].flash_offset = REF_LINK_NODE; | ||
205 | ret[i].next_in_ino = NULL; | ||
206 | } | ||
172 | return ret; | 207 | return ret; |
173 | } | 208 | } |
174 | 209 | ||
175 | void jffs2_free_raw_node_ref(struct jffs2_raw_node_ref *x) | 210 | int jffs2_prealloc_raw_node_refs(struct jffs2_sb_info *c, |
211 | struct jffs2_eraseblock *jeb, int nr) | ||
212 | { | ||
213 | struct jffs2_raw_node_ref **p, *ref; | ||
214 | int i = nr; | ||
215 | |||
216 | dbg_memalloc("%d\n", nr); | ||
217 | |||
218 | p = &jeb->last_node; | ||
219 | ref = *p; | ||
220 | |||
221 | dbg_memalloc("Reserving %d refs for block @0x%08x\n", nr, jeb->offset); | ||
222 | |||
223 | /* If jeb->last_node is really a valid node then skip over it */ | ||
224 | if (ref && ref->flash_offset != REF_EMPTY_NODE) | ||
225 | ref++; | ||
226 | |||
227 | while (i) { | ||
228 | if (!ref) { | ||
229 | dbg_memalloc("Allocating new refblock linked from %p\n", p); | ||
230 | ref = *p = jffs2_alloc_refblock(); | ||
231 | if (!ref) | ||
232 | return -ENOMEM; | ||
233 | } | ||
234 | if (ref->flash_offset == REF_LINK_NODE) { | ||
235 | p = &ref->next_in_ino; | ||
236 | ref = *p; | ||
237 | continue; | ||
238 | } | ||
239 | i--; | ||
240 | ref++; | ||
241 | } | ||
242 | jeb->allocated_refs = nr; | ||
243 | |||
244 | dbg_memalloc("Reserved %d refs for block @0x%08x, last_node is %p (%08x,%p)\n", | ||
245 | nr, jeb->offset, jeb->last_node, jeb->last_node->flash_offset, | ||
246 | jeb->last_node->next_in_ino); | ||
247 | |||
248 | return 0; | ||
249 | } | ||
250 | |||
251 | void jffs2_free_refblock(struct jffs2_raw_node_ref *x) | ||
176 | { | 252 | { |
177 | dbg_memalloc("%p\n", x); | 253 | dbg_memalloc("%p\n", x); |
178 | kmem_cache_free(raw_node_ref_slab, x); | 254 | kmem_cache_free(raw_node_ref_slab, x); |
@@ -205,3 +281,40 @@ void jffs2_free_inode_cache(struct jffs2_inode_cache *x) | |||
205 | dbg_memalloc("%p\n", x); | 281 | dbg_memalloc("%p\n", x); |
206 | kmem_cache_free(inode_cache_slab, x); | 282 | kmem_cache_free(inode_cache_slab, x); |
207 | } | 283 | } |
284 | |||
285 | #ifdef CONFIG_JFFS2_FS_XATTR | ||
286 | struct jffs2_xattr_datum *jffs2_alloc_xattr_datum(void) | ||
287 | { | ||
288 | struct jffs2_xattr_datum *xd; | ||
289 | xd = kmem_cache_alloc(xattr_datum_cache, GFP_KERNEL); | ||
290 | dbg_memalloc("%p\n", xd); | ||
291 | |||
292 | memset(xd, 0, sizeof(struct jffs2_xattr_datum)); | ||
293 | xd->class = RAWNODE_CLASS_XATTR_DATUM; | ||
294 | INIT_LIST_HEAD(&xd->xindex); | ||
295 | return xd; | ||
296 | } | ||
297 | |||
298 | void jffs2_free_xattr_datum(struct jffs2_xattr_datum *xd) | ||
299 | { | ||
300 | dbg_memalloc("%p\n", xd); | ||
301 | kmem_cache_free(xattr_datum_cache, xd); | ||
302 | } | ||
303 | |||
304 | struct jffs2_xattr_ref *jffs2_alloc_xattr_ref(void) | ||
305 | { | ||
306 | struct jffs2_xattr_ref *ref; | ||
307 | ref = kmem_cache_alloc(xattr_ref_cache, GFP_KERNEL); | ||
308 | dbg_memalloc("%p\n", ref); | ||
309 | |||
310 | memset(ref, 0, sizeof(struct jffs2_xattr_ref)); | ||
311 | ref->class = RAWNODE_CLASS_XATTR_REF; | ||
312 | return ref; | ||
313 | } | ||
314 | |||
315 | void jffs2_free_xattr_ref(struct jffs2_xattr_ref *ref) | ||
316 | { | ||
317 | dbg_memalloc("%p\n", ref); | ||
318 | kmem_cache_free(xattr_ref_cache, ref); | ||
319 | } | ||
320 | #endif | ||