LCOV - code coverage report
Current view: top level - fs/jffs2 - malloc.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 0 129 0.0 %
Date: 2014-02-18 Functions: 0 23 0.0 %
Branches: 0 52 0.0 %

           Branch data     Line data    Source code
       1                 :            : /*
       2                 :            :  * JFFS2 -- Journalling Flash File System, Version 2.
       3                 :            :  *
       4                 :            :  * Copyright © 2001-2007 Red Hat, Inc.
       5                 :            :  *
       6                 :            :  * Created by David Woodhouse <dwmw2@infradead.org>
       7                 :            :  *
       8                 :            :  * For licensing information, see the file 'LICENCE' in this directory.
       9                 :            :  *
      10                 :            :  */
      11                 :            : 
      12                 :            : #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
      13                 :            : 
      14                 :            : #include <linux/kernel.h>
      15                 :            : #include <linux/slab.h>
      16                 :            : #include <linux/init.h>
      17                 :            : #include <linux/jffs2.h>
      18                 :            : #include "nodelist.h"
      19                 :            : 
      20                 :            : /* These are initialised to NULL in the kernel startup code.
      21                 :            :    If you're porting to other operating systems, beware */
      22                 :            : static struct kmem_cache *full_dnode_slab;
      23                 :            : static struct kmem_cache *raw_dirent_slab;
      24                 :            : static struct kmem_cache *raw_inode_slab;
      25                 :            : static struct kmem_cache *tmp_dnode_info_slab;
      26                 :            : static struct kmem_cache *raw_node_ref_slab;
      27                 :            : static struct kmem_cache *node_frag_slab;
      28                 :            : static struct kmem_cache *inode_cache_slab;
      29                 :            : #ifdef CONFIG_JFFS2_FS_XATTR
      30                 :            : static struct kmem_cache *xattr_datum_cache;
      31                 :            : static struct kmem_cache *xattr_ref_cache;
      32                 :            : #endif
      33                 :            : 
      34                 :          0 : int __init jffs2_create_slab_caches(void)
      35                 :            : {
      36                 :          0 :         full_dnode_slab = kmem_cache_create("jffs2_full_dnode",
      37                 :            :                                             sizeof(struct jffs2_full_dnode),
      38                 :            :                                             0, 0, NULL);
      39         [ #  # ]:          0 :         if (!full_dnode_slab)
      40                 :            :                 goto err;
      41                 :            : 
      42                 :          0 :         raw_dirent_slab = kmem_cache_create("jffs2_raw_dirent",
      43                 :            :                                             sizeof(struct jffs2_raw_dirent),
      44                 :            :                                             0, SLAB_HWCACHE_ALIGN, NULL);
      45         [ #  # ]:          0 :         if (!raw_dirent_slab)
      46                 :            :                 goto err;
      47                 :            : 
      48                 :          0 :         raw_inode_slab = kmem_cache_create("jffs2_raw_inode",
      49                 :            :                                            sizeof(struct jffs2_raw_inode),
      50                 :            :                                            0, SLAB_HWCACHE_ALIGN, NULL);
      51         [ #  # ]:          0 :         if (!raw_inode_slab)
      52                 :            :                 goto err;
      53                 :            : 
      54                 :          0 :         tmp_dnode_info_slab = kmem_cache_create("jffs2_tmp_dnode",
      55                 :            :                                                 sizeof(struct jffs2_tmp_dnode_info),
      56                 :            :                                                 0, 0, NULL);
      57         [ #  # ]:          0 :         if (!tmp_dnode_info_slab)
      58                 :            :                 goto err;
      59                 :            : 
      60                 :          0 :         raw_node_ref_slab = kmem_cache_create("jffs2_refblock",
      61                 :            :                                               sizeof(struct jffs2_raw_node_ref) * (REFS_PER_BLOCK + 1),
      62                 :            :                                               0, 0, NULL);
      63         [ #  # ]:          0 :         if (!raw_node_ref_slab)
      64                 :            :                 goto err;
      65                 :            : 
      66                 :          0 :         node_frag_slab = kmem_cache_create("jffs2_node_frag",
      67                 :            :                                            sizeof(struct jffs2_node_frag),
      68                 :            :                                            0, 0, NULL);
      69         [ #  # ]:          0 :         if (!node_frag_slab)
      70                 :            :                 goto err;
      71                 :            : 
      72                 :          0 :         inode_cache_slab = kmem_cache_create("jffs2_inode_cache",
      73                 :            :                                              sizeof(struct jffs2_inode_cache),
      74                 :            :                                              0, 0, NULL);
      75         [ #  # ]:          0 :         if (!inode_cache_slab)
      76                 :            :                 goto err;
      77                 :            : 
      78                 :            : #ifdef CONFIG_JFFS2_FS_XATTR
      79                 :          0 :         xattr_datum_cache = kmem_cache_create("jffs2_xattr_datum",
      80                 :            :                                              sizeof(struct jffs2_xattr_datum),
      81                 :            :                                              0, 0, NULL);
      82         [ #  # ]:          0 :         if (!xattr_datum_cache)
      83                 :            :                 goto err;
      84                 :            : 
      85                 :          0 :         xattr_ref_cache = kmem_cache_create("jffs2_xattr_ref",
      86                 :            :                                            sizeof(struct jffs2_xattr_ref),
      87                 :            :                                            0, 0, NULL);
      88         [ #  # ]:          0 :         if (!xattr_ref_cache)
      89                 :            :                 goto err;
      90                 :            : #endif
      91                 :            : 
      92                 :            :         return 0;
      93                 :            :  err:
      94                 :          0 :         jffs2_destroy_slab_caches();
      95                 :          0 :         return -ENOMEM;
      96                 :            : }
      97                 :            : 
      98                 :          0 : void jffs2_destroy_slab_caches(void)
      99                 :            : {
     100         [ #  # ]:          0 :         if(full_dnode_slab)
     101                 :          0 :                 kmem_cache_destroy(full_dnode_slab);
     102         [ #  # ]:          0 :         if(raw_dirent_slab)
     103                 :          0 :                 kmem_cache_destroy(raw_dirent_slab);
     104         [ #  # ]:          0 :         if(raw_inode_slab)
     105                 :          0 :                 kmem_cache_destroy(raw_inode_slab);
     106         [ #  # ]:          0 :         if(tmp_dnode_info_slab)
     107                 :          0 :                 kmem_cache_destroy(tmp_dnode_info_slab);
     108         [ #  # ]:          0 :         if(raw_node_ref_slab)
     109                 :          0 :                 kmem_cache_destroy(raw_node_ref_slab);
     110         [ #  # ]:          0 :         if(node_frag_slab)
     111                 :          0 :                 kmem_cache_destroy(node_frag_slab);
     112         [ #  # ]:          0 :         if(inode_cache_slab)
     113                 :          0 :                 kmem_cache_destroy(inode_cache_slab);
     114                 :            : #ifdef CONFIG_JFFS2_FS_XATTR
     115         [ #  # ]:          0 :         if (xattr_datum_cache)
     116                 :          0 :                 kmem_cache_destroy(xattr_datum_cache);
     117         [ #  # ]:          0 :         if (xattr_ref_cache)
     118                 :          0 :                 kmem_cache_destroy(xattr_ref_cache);
     119                 :            : #endif
     120                 :          0 : }
     121                 :            : 
     122                 :          0 : struct jffs2_full_dirent *jffs2_alloc_full_dirent(int namesize)
     123                 :            : {
     124                 :            :         struct jffs2_full_dirent *ret;
     125                 :          0 :         ret = kmalloc(sizeof(struct jffs2_full_dirent) + namesize, GFP_KERNEL);
     126                 :            :         dbg_memalloc("%p\n", ret);
     127                 :          0 :         return ret;
     128                 :            : }
     129                 :            : 
     130                 :          0 : void jffs2_free_full_dirent(struct jffs2_full_dirent *x)
     131                 :            : {
     132                 :            :         dbg_memalloc("%p\n", x);
     133                 :          0 :         kfree(x);
     134                 :          0 : }
     135                 :            : 
     136                 :          0 : struct jffs2_full_dnode *jffs2_alloc_full_dnode(void)
     137                 :            : {
     138                 :            :         struct jffs2_full_dnode *ret;
     139                 :          0 :         ret = kmem_cache_alloc(full_dnode_slab, GFP_KERNEL);
     140                 :            :         dbg_memalloc("%p\n", ret);
     141                 :          0 :         return ret;
     142                 :            : }
     143                 :            : 
     144                 :          0 : void jffs2_free_full_dnode(struct jffs2_full_dnode *x)
     145                 :            : {
     146                 :            :         dbg_memalloc("%p\n", x);
     147                 :          0 :         kmem_cache_free(full_dnode_slab, x);
     148                 :          0 : }
     149                 :            : 
     150                 :          0 : struct jffs2_raw_dirent *jffs2_alloc_raw_dirent(void)
     151                 :            : {
     152                 :            :         struct jffs2_raw_dirent *ret;
     153                 :          0 :         ret = kmem_cache_alloc(raw_dirent_slab, GFP_KERNEL);
     154                 :            :         dbg_memalloc("%p\n", ret);
     155                 :          0 :         return ret;
     156                 :            : }
     157                 :            : 
     158                 :          0 : void jffs2_free_raw_dirent(struct jffs2_raw_dirent *x)
     159                 :            : {
     160                 :            :         dbg_memalloc("%p\n", x);
     161                 :          0 :         kmem_cache_free(raw_dirent_slab, x);
     162                 :          0 : }
     163                 :            : 
     164                 :          0 : struct jffs2_raw_inode *jffs2_alloc_raw_inode(void)
     165                 :            : {
     166                 :            :         struct jffs2_raw_inode *ret;
     167                 :          0 :         ret = kmem_cache_alloc(raw_inode_slab, GFP_KERNEL);
     168                 :            :         dbg_memalloc("%p\n", ret);
     169                 :          0 :         return ret;
     170                 :            : }
     171                 :            : 
     172                 :          0 : void jffs2_free_raw_inode(struct jffs2_raw_inode *x)
     173                 :            : {
     174                 :            :         dbg_memalloc("%p\n", x);
     175                 :          0 :         kmem_cache_free(raw_inode_slab, x);
     176                 :          0 : }
     177                 :            : 
     178                 :          0 : struct jffs2_tmp_dnode_info *jffs2_alloc_tmp_dnode_info(void)
     179                 :            : {
     180                 :            :         struct jffs2_tmp_dnode_info *ret;
     181                 :          0 :         ret = kmem_cache_alloc(tmp_dnode_info_slab, GFP_KERNEL);
     182                 :            :         dbg_memalloc("%p\n",
     183                 :            :                 ret);
     184                 :          0 :         return ret;
     185                 :            : }
     186                 :            : 
     187                 :          0 : void jffs2_free_tmp_dnode_info(struct jffs2_tmp_dnode_info *x)
     188                 :            : {
     189                 :            :         dbg_memalloc("%p\n", x);
     190                 :          0 :         kmem_cache_free(tmp_dnode_info_slab, x);
     191                 :          0 : }
     192                 :            : 
     193                 :          0 : static struct jffs2_raw_node_ref *jffs2_alloc_refblock(void)
     194                 :            : {
     195                 :            :         struct jffs2_raw_node_ref *ret;
     196                 :            : 
     197                 :          0 :         ret = kmem_cache_alloc(raw_node_ref_slab, GFP_KERNEL);
     198         [ #  # ]:          0 :         if (ret) {
     199                 :            :                 int i = 0;
     200         [ #  # ]:          0 :                 for (i=0; i < REFS_PER_BLOCK; i++) {
     201                 :          0 :                         ret[i].flash_offset = REF_EMPTY_NODE;
     202                 :          0 :                         ret[i].next_in_ino = NULL;
     203                 :            :                 }
     204                 :          0 :                 ret[i].flash_offset = REF_LINK_NODE;
     205                 :          0 :                 ret[i].next_in_ino = NULL;
     206                 :            :         }
     207                 :          0 :         return ret;
     208                 :            : }
     209                 :            : 
     210                 :          0 : 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                 :          0 :         p = &jeb->last_node;
     219                 :          0 :         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 [ #  # ][ #  # ]:          0 :         if (ref && ref->flash_offset != REF_EMPTY_NODE)
     225                 :          0 :                 ref++;
     226                 :            : 
     227         [ #  # ]:          0 :         while (i) {
     228         [ #  # ]:          0 :                 if (!ref) {
     229                 :            :                         dbg_memalloc("Allocating new refblock linked from %p\n", p);
     230                 :          0 :                         ref = *p = jffs2_alloc_refblock();
     231         [ #  # ]:          0 :                         if (!ref)
     232                 :            :                                 return -ENOMEM;
     233                 :            :                 }
     234         [ #  # ]:          0 :                 if (ref->flash_offset == REF_LINK_NODE) {
     235                 :          0 :                         p = &ref->next_in_ino;
     236                 :          0 :                         ref = *p;
     237                 :          0 :                         continue;
     238                 :            :                 }
     239                 :          0 :                 i--;
     240                 :          0 :                 ref++;
     241                 :            :         }
     242                 :          0 :         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                 :          0 :         return 0;
     249                 :            : }
     250                 :            : 
     251                 :          0 : void jffs2_free_refblock(struct jffs2_raw_node_ref *x)
     252                 :            : {
     253                 :            :         dbg_memalloc("%p\n", x);
     254                 :          0 :         kmem_cache_free(raw_node_ref_slab, x);
     255                 :          0 : }
     256                 :            : 
     257                 :          0 : struct jffs2_node_frag *jffs2_alloc_node_frag(void)
     258                 :            : {
     259                 :            :         struct jffs2_node_frag *ret;
     260                 :          0 :         ret = kmem_cache_alloc(node_frag_slab, GFP_KERNEL);
     261                 :            :         dbg_memalloc("%p\n", ret);
     262                 :          0 :         return ret;
     263                 :            : }
     264                 :            : 
     265                 :          0 : void jffs2_free_node_frag(struct jffs2_node_frag *x)
     266                 :            : {
     267                 :            :         dbg_memalloc("%p\n", x);
     268                 :          0 :         kmem_cache_free(node_frag_slab, x);
     269                 :          0 : }
     270                 :            : 
     271                 :          0 : struct jffs2_inode_cache *jffs2_alloc_inode_cache(void)
     272                 :            : {
     273                 :            :         struct jffs2_inode_cache *ret;
     274                 :          0 :         ret = kmem_cache_alloc(inode_cache_slab, GFP_KERNEL);
     275                 :            :         dbg_memalloc("%p\n", ret);
     276                 :          0 :         return ret;
     277                 :            : }
     278                 :            : 
     279                 :          0 : void jffs2_free_inode_cache(struct jffs2_inode_cache *x)
     280                 :            : {
     281                 :            :         dbg_memalloc("%p\n", x);
     282                 :          0 :         kmem_cache_free(inode_cache_slab, x);
     283                 :          0 : }
     284                 :            : 
     285                 :            : #ifdef CONFIG_JFFS2_FS_XATTR
     286                 :          0 : struct jffs2_xattr_datum *jffs2_alloc_xattr_datum(void)
     287                 :            : {
     288                 :            :         struct jffs2_xattr_datum *xd;
     289                 :          0 :         xd = kmem_cache_zalloc(xattr_datum_cache, GFP_KERNEL);
     290                 :            :         dbg_memalloc("%p\n", xd);
     291                 :            : 
     292                 :          0 :         xd->class = RAWNODE_CLASS_XATTR_DATUM;
     293                 :          0 :         xd->node = (void *)xd;
     294                 :          0 :         INIT_LIST_HEAD(&xd->xindex);
     295                 :          0 :         return xd;
     296                 :            : }
     297                 :            : 
     298                 :          0 : void jffs2_free_xattr_datum(struct jffs2_xattr_datum *xd)
     299                 :            : {
     300                 :            :         dbg_memalloc("%p\n", xd);
     301                 :          0 :         kmem_cache_free(xattr_datum_cache, xd);
     302                 :          0 : }
     303                 :            : 
     304                 :          0 : struct jffs2_xattr_ref *jffs2_alloc_xattr_ref(void)
     305                 :            : {
     306                 :            :         struct jffs2_xattr_ref *ref;
     307                 :          0 :         ref = kmem_cache_zalloc(xattr_ref_cache, GFP_KERNEL);
     308                 :            :         dbg_memalloc("%p\n", ref);
     309                 :            : 
     310                 :          0 :         ref->class = RAWNODE_CLASS_XATTR_REF;
     311                 :          0 :         ref->node = (void *)ref;
     312                 :          0 :         return ref;
     313                 :            : }
     314                 :            : 
     315                 :          0 : void jffs2_free_xattr_ref(struct jffs2_xattr_ref *ref)
     316                 :            : {
     317                 :            :         dbg_memalloc("%p\n", ref);
     318                 :          0 :         kmem_cache_free(xattr_ref_cache, ref);
     319                 :          0 : }
     320                 :            : #endif

Generated by: LCOV version 1.9