]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
xfs_repair: replace custom block allocation lists with list_heads
authorJosef 'Jeff' Sipek <jeffpc@josefsipek.net>
Fri, 25 Sep 2009 19:26:23 +0000 (14:26 -0500)
committerEric Sandeen <sandeen@redhat.com>
Fri, 25 Sep 2009 19:26:23 +0000 (14:26 -0500)
The previous implementation of the linked lists was buggy,
and leaked memory.

Cc: sandeen@sandeen.net
Signed-off-by: Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
Reviewed-by: Eric Sandeen <sandeen@sandeen.net>
repair/incore.c
repair/incore.h
repair/incore_ext.c

index 84626c91206b1f2e13c5d277e4158a1508180b81..27604e27c9c9b9b49bc039b03dfba376499c4aa3 100644 (file)
 #include "err_protos.h"
 #include "threads.h"
 
-/*
- * push a block allocation record onto list.  assumes list
- * if set to NULL if empty.
- */
-void
-record_allocation(ba_rec_t *addr, ba_rec_t *list)
-{
-       addr->next = list;
-       list = addr;
-
-       return;
-}
-
-void
-free_allocations(ba_rec_t *list)
-{
-       ba_rec_t *current = list;
-
-       while (list != NULL)  {
-               list = list->next;
-               free(current);
-               current = list;
-       }
-
-       return;
-}
-
 /* ba bmap setupstuff.  setting/getting state is in incore.h  */
 
 void
index 1f0f45a9bec2c22149a2e818e362f477cbeda451..a22ef0fb06b20008623503015f67e4c267a989e0 100644 (file)
  * is spread out in separate files.
  */
 
-/*
- * block allocation lists
- */
-typedef struct ba_rec  {
-       void            *addr;
-       struct ba_rec   *next;
-} ba_rec_t;
-
-void                   record_allocation(ba_rec_t *addr, ba_rec_t *list);
-void                   free_allocations(ba_rec_t *list);
-
 /*
  * block bit map defs -- track state of each filesystem block.
  * ba_bmap is an array of bitstrings declared in the globals.h file.
index a2acbf4a6c6f072d8c21db2e2660d8d88212046e..d0b8cdc4ba20a2a78326d201c7bcda66e3966968 100644 (file)
  * paranoia -- account for any weird padding, 64/32-bit alignment, etc.
  */
 typedef struct extent_alloc_rec  {
-       ba_rec_t                alloc_rec;
+       struct list_head        list;
        extent_tree_node_t      extents[ALLOC_NUM_EXTS];
 } extent_alloc_rec_t;
 
 typedef struct rt_extent_alloc_rec  {
-       ba_rec_t                alloc_rec;
+       struct list_head        list;
        rt_extent_tree_node_t   extents[ALLOC_NUM_EXTS];
 } rt_extent_alloc_rec_t;
 
@@ -89,8 +89,8 @@ static avltree_desc_t **extent_bcnt_ptrs;     /*
 /*
  * list of allocated "blocks" for easy freeing later
  */
-static ba_rec_t                *ba_list;
-static ba_rec_t                *rt_ba_list;
+static struct list_head        ba_list;
+static struct list_head        rt_ba_list;
 
 /*
  * locks.
@@ -120,7 +120,7 @@ mk_extent_tree_nodes(xfs_agblock_t new_startblock,
                        do_error(
                        _("couldn't allocate new extent descriptors.\n"));
 
-               record_allocation(&rec->alloc_rec, ba_list);
+               list_add(&rec->list, &ba_list);
 
                new = &rec->extents[0];
 
@@ -678,7 +678,7 @@ mk_rt_extent_tree_nodes(xfs_drtbno_t new_startblock,
                        do_error(
                        _("couldn't allocate new extent descriptors.\n"));
 
-               record_allocation(&rec->alloc_rec, rt_ba_list);
+               list_add(&rec->list, &rt_ba_list);
 
                new = &rec->extents[0];
 
@@ -755,12 +755,15 @@ release_rt_extent_tree()
 void
 free_rt_dup_extent_tree(xfs_mount_t *mp)
 {
+       rt_extent_alloc_rec_t *cur, *tmp;
+
        ASSERT(mp->m_sb.sb_rblocks != 0);
 
-       free_allocations(rt_ba_list);
+       list_for_each_entry_safe(cur, tmp, &rt_ba_list, list)
+               free(cur);
+
        free(rt_ext_tree_ptr);
 
-       rt_ba_list = NULL;
        rt_ext_tree_ptr = NULL;
 
        return;
@@ -895,8 +898,8 @@ incore_ext_init(xfs_mount_t *mp)
        int i;
        xfs_agnumber_t agcount = mp->m_sb.sb_agcount;
 
-       ba_list = NULL;
-       rt_ba_list = NULL;
+       list_head_init(&ba_list);
+       list_head_init(&rt_ba_list);
        pthread_mutex_init(&ext_flist_lock, NULL);
        pthread_mutex_init(&rt_ext_tree_lock, NULL);
        pthread_mutex_init(&rt_ext_flist_lock, NULL);
@@ -954,9 +957,11 @@ incore_ext_init(xfs_mount_t *mp)
 void
 incore_ext_teardown(xfs_mount_t *mp)
 {
+       extent_alloc_rec_t *cur, *tmp;
        xfs_agnumber_t i;
 
-       free_allocations(ba_list);
+       list_for_each_entry_safe(cur, tmp, &ba_list, list)
+               free(cur);
 
        for (i = 0; i < mp->m_sb.sb_agcount; i++)  {
                free(extent_tree_ptrs[i]);