libgfs2: Make in-core rgrps use rbtree
PATCH 56/56 libgfs2: Make in-core rgrps use rbtree
From 7a26516c6e3ed7e8fc87d48112171630f6db7677 Mon Sep 17 00:00:00 2001
From: Bob Peterson <[email protected]>
Date: Thu, 25 Aug 2011 11:09:25 -0500
Subject: [PATCH 56/56] libgfs2: Make in-core rgrps use rbtree
This patch changes the in-core structure used for resource groups from a linked list to an rbtree.
rhbz#675723
--- gfs2/convert/gfs2_convert.c | 61 ++++++------ gfs2/edit/extended.c | 2 +- gfs2/edit/hexedit.c | 56 ++++++------ gfs2/edit/hexedit.h | 4 +- gfs2/edit/savemeta.c | 26 +++--- gfs2/fsck/initialize.c | 26 +++--- gfs2/fsck/lost_n_found.c | 12 +- gfs2/fsck/main.c | 9 +- gfs2/fsck/metawalk.c | 2 +- gfs2/fsck/pass1.c | 10 +- gfs2/fsck/pass5.c | 11 +- gfs2/fsck/rgrepair.c | 219 ++++++++++++++++--------------------------- gfs2/libgfs2/fs_bits.c | 4 +- gfs2/libgfs2/fs_geometry.c | 53 ++++++----- gfs2/libgfs2/fs_ops.c | 16 ++-- gfs2/libgfs2/libgfs2.h | 34 ++++--- gfs2/libgfs2/rgrp.c | 98 ++++++++++---------- gfs2/libgfs2/structures.c | 26 +++--- gfs2/libgfs2/super.c | 27 ++--- gfs2/mkfs/main_grow.c | 62 +++++++------ gfs2/mkfs/main_mkfs.c | 6 +- 21 files changed, 361 insertions(+), 403 deletions(-)
gfs2/convert/gfs2_convert.c +31 -30
@@ -174,7 +174,7 @@ void print_it(const char *label, const char *fmt, const char *fmt2, ...)/* Fixes all unallocated metadata bitmap states (which are */ /* valid in gfs1 but invalid in gfs2). */ /* ------------------------------------------------------------------------- */ -static void convert_bitmaps (struct gfs2_sbd *sdp,struct rgrp_list *rg) +static void convert_bitmaps (struct gfs2_sbd *sdp,struct rgrp_tree *rg) {uint32_t blk;int x, y;
@@ -202,16 +202,18 @@ static void convert_bitmaps(struct gfs2_sbd *sdp, struct rgrp_list *rg)/* ------------------------------------------------------------------------- */ static int convert_rgs (struct gfs2_sbd *sbp) { -struct rgrp_list *rgd; -osi_list_t *tmp; +struct rgrp_tree *rgd; +struct osi_node *n, *next =NULL ;struct gfs1_rgrp *rgd1;int rgs =0 ;/* --------------------------------- */ /* Now convert its rgs into gfs2 rgs */ /* --------------------------------- */ - osi_list_foreach(tmp, &sbp->rglist) { - rgd = osi_list_entry(tmp, struct rgrp_list, list); +for (n =osi_first (&sbp->rgtree); n; n = next) { + next =osi_next (n); + rgd = (struct rgrp_tree *)n; + rgd1 = (struct gfs1_rgrp *)&rgd->rg;/* recast as gfs1 structure */ /* rg_freemeta is a gfs1 structure, so libgfs2 doesn't know to */ /* convert from be to cpu. We must do it now. */
@@ -986,8 +988,8 @@ static int adjust_inode(struct gfs2_sbd *sbp, struct gfs2_buffer_head *bh)/* ------------------------------------------------------------------------- */ static int inode_renumber (struct gfs2_sbd *sbp,uint64_t root_inode_addr,osi_list_t *cdpn_to_fix) { -struct rgrp_list *rgd; -osi_list_t *tmp; +struct rgrp_tree *rgd; +struct osi_node *n, *next =NULL ;uint64_t block;struct gfs2_buffer_head *bh;int first;
@@ -1002,9 +1004,10 @@ static int inode_renumber(struct gfs2_sbd *sbp, uint64_t root_inode_addr, osi_li/* ---------------------------------------------------------------- */ /* Traverse the resource groups to figure out where the inodes are. */ /* ---------------------------------------------------------------- */ - osi_list_foreach(tmp, &sbp->rglist) { +for (n =osi_first (&sbp->rgtree); n; n = next) { + next =osi_next (n); + rgd = (struct rgrp_tree *)n; rgs_processed++; - rgd = osi_list_entry(tmp, struct rgrp_list, list); first =1 ;while (1 ) {/* for all inodes in the resource group */ gettimeofday (&tv,NULL );
@@ -1509,7 +1512,7 @@ static int init(struct gfs2_sbd *sbp) sbp->dinodes_alloced =0 ;/* dinodes allocated - total them up later */ sbp->sd_sb.sb_bsize =GFS2_DEFAULT_BSIZE ; sbp->bsize = sbp->sd_sb.sb_bsize; -osi_list_init (&sbp->rglist); + sbp->rgtree.osi_node =NULL ;if (compute_constants (sbp)) {log_crit (_ ("Error: Bad constants (1)\n" ));exit (-1 );
@@ -1737,9 +1740,10 @@ static int journ_space_to_rg(struct gfs2_sbd *sdp)int error =0 ;int j, x;struct gfs1_jindex *jndx; -struct rgrp_list *rgd, *rgdhigh; -osi_list_t *tmp; +struct rgrp_tree *rgd, *rgdhigh; +struct osi_node *n, *next =NULL ;struct gfs2_meta_header mh; +uint64_t ri_addr; mh.mh_magic =GFS2_MAGIC ; mh.mh_type =GFS2_METATYPE_RB ;
@@ -1757,8 +1761,9 @@ static int journ_space_to_rg(struct gfs2_sbd *sdp)by jadd. gfs_grow adds rgs out of order, so we can't count on them being in ascending order. */ rgdhigh =NULL ; - osi_list_foreach(tmp, &sdp->rglist) { - rgd = osi_list_entry(tmp, struct rgrp_list, list); +for (n =osi_first (&sdp->rgtree); n; n = next) { + next =osi_next (n); + rgd = (struct rgrp_tree *)n;if (rgd->ri.ri_addr < jndx->ji_addr && ((rgdhigh ==NULL ) || (rgd->ri.ri_addr > rgdhigh->ri.ri_addr)))
@@ -1771,15 +1776,12 @@ static int journ_space_to_rg(struct gfs2_sbd *sdp)log_crit (_ ("Error: No suitable rg found for journal.\n" ));return -1 ; } + ri_addr = jndx->ji_addr;/* Allocate a new rgd entry which includes rg and ri. */ + rgd =rgrp_insert (&sdp->rgtree, ri_addr);/* convert the gfs1 rgrp into a new gfs2 rgrp */ - rgd =malloc (sizeof (struct rgrp_list )); -if (!rgd) { -log_crit (_ ("Error: unable to allocate memory for rg conversion.\n" )); -return -1 ; - } -memset (rgd,0 ,sizeof (struct rgrp_list )); - size = jndx->ji_nsegment *be32_to_cpu (raw_gfs1_ondisk_sb.sb_seg_size); + size = jndx->ji_nsegment * +be32_to_cpu (raw_gfs1_ondisk_sb.sb_seg_size); rgd->rg.rg_header.mh_magic =GFS2_MAGIC ; rgd->rg.rg_header.mh_type =GFS2_METATYPE_RG ; rgd->rg.rg_header.mh_format =GFS2_FORMAT_RG ;
@@ -1822,9 +1824,6 @@ static int journ_space_to_rg(struct gfs2_sbd *sdp)else gfs2_rgrp_out (&rgd->rg, rgd->bh[x]); } -/* Add the new gfs2 rg to our list: We'll output the rg index later. */ -osi_list_add_prev ((osi_list_t *)&rgd->list, - (osi_list_t *)&sdp->rglist); }/* for each journal */ return error; }/* journ_space_to_rg */
@@ -2001,16 +2000,17 @@ static int check_fit(struct gfs2_sbd *sdp)/* build_rindex() */ { -osi_list_t *tmp, *head; +struct osi_node *n, *next =NULL ;unsigned int rg_count =0 ; blks_need++;/* creationg of 'rindex' disk inode */ /* find the total # of rindex entries, gives size of rindex inode */ -for (head = &sdp->rglist, tmp = head->next; tmp != head; - tmp = tmp->next) +for (n =osi_first (&sdp->rgtree); n; n = next) { + next =osi_next (n); rg_count++; - blks_need += -total_file_blocks (sdp, rg_count *sizeof (struct gfs2_rindex ),1 ); + } + blks_need +=total_file_blocks (sdp, rg_count * +sizeof (struct gfs2_rindex ),1 ); }/* build_quota() */ blks_need++;/* quota inode block and uid=gid=0 quota - total 1 block */
@@ -2207,6 +2207,7 @@ int main(int argc, char **argv)/* ---------------------------------------------- */ if (!error) {int jreduce =0 ; +/* Now we've got to treat it as a gfs2 file system */ if (compute_constants (&sb2)) {log_crit (_ ("Error: Bad constants (1)\n" ));
@@ -2294,7 +2295,7 @@ int main(int argc, char **argv)fsync (sb2.device_fd);/* write the buffers to disk */ /* Now free all the in memory */ -gfs2_rgrp_free (&sb2.rglist); +gfs2_rgrp_free (&sb2.rgtree);log_notice (_ ("Committing changes to disk.\n" ));fflush (stdout);/* Set filesystem type in superblock to gfs2. We do this at the */
gfs2/edit/extended.c +1 -1
@@ -662,7 +662,7 @@ int display_extended(void)return -1 ; else if (display_indirect(indirect, indirect_blocks, 0, 0) == 0) return -1; - else if (block_is_rglist()) { + else if (block_is_rgtree()) {if (sbd.gfs1) tmp_bh =bread (&sbd, sbd1->sb_rindex_di.no_addr);else
gfs2/edit/hexedit.c +29 -27
194 lines not on this page · raw message
gfs2/edit/hexedit.h +2 -2
@@ -111,11 +111,11 @@ extern int indirect_blocks; /* count of indirect blocks */extern enum dsp_mode dmode;/* ------------------------------------------------------------------------ */ -/* block_is_rglist - there's no such block as the rglist. This is a */ +/* block_is_rgtree - there's no such block as the rglist. This is a */ /* special case meant to parse the rindex and follow the */ /* blocks to the real rgs. */ /* ------------------------------------------------------------------------ */ -static inline int block_is_rglist (void ) +static inline int block_is_rgtree (void ) {if (block ==RGLIST_DUMMY_BLOCK )return TRUE;
gfs2/edit/savemeta.c +14 -12
@@ -589,7 +589,7 @@ static void get_journal_inode_blocks(void) } } -static int next_rg_freemeta (struct gfs2_sbd *sdp,struct rgrp_list *rgd, +static int next_rg_freemeta (struct gfs2_sbd *sdp,struct rgrp_tree *rgd,uint64_t *nrfblock,int first) {struct gfs2_bitmap *bits =NULL ;
@@ -631,11 +631,10 @@ static int next_rg_freemeta(struct gfs2_sbd *sdp, struct rgrp_list *rgd,void savemeta (char *out_fn,int saveoption,int gziplevel) {int slow, ret; -osi_list_t *tmp;int rgcount;uint64_t jindex_block;struct gfs2_buffer_head *lbh; -struct rgrp_list *last_rgd, *prev_rgd; +struct rgrp_tree *last_rgd, *prev_rgd;struct metafd mfd; slow = (saveoption ==1 );
@@ -661,7 +660,7 @@ void savemeta(char *out_fn, int saveoption, int gziplevel) (unsigned long long)sbd.device.length << GFS2_BASIC_BLOCK_SHIFT);exit (-1 ); } -osi_list_init (&sbd.rglist); + sbd.rgtree.osi_node =NULL ;if (!sbd.gfs1) sbd.sd_sb.sb_bsize =GFS2_DEFAULT_BSIZE ;if (compute_constants (&sbd)) {
@@ -702,6 +701,7 @@ void savemeta(char *out_fn, int saveoption, int gziplevel)if (!slow) {int sane;uint64_t fssize; +struct osi_node *n;printf ("Reading resource groups..." );fflush (stdout);
@@ -709,10 +709,10 @@ void savemeta(char *out_fn, int saveoption, int gziplevel) slow =gfs1_ri_update (&sbd,0 , &rgcount,0 ); else slow =ri_update (&sbd,0 , &rgcount, &sane); - last_rgd =osi_list_entry (sbd.rglist.prev, - struct rgrp_list, list); - prev_rgd =osi_list_entry (last_rgd->list.prev, - struct rgrp_list, list); + n =osi_last (&sbd.rgtree); + last_rgd = (struct rgrp_tree *)n; + n =osi_prev (n); + prev_rgd = (struct rgrp_tree *)n; fssize = last_rgd->ri.ri_addr + (last_rgd->ri.ri_addr - prev_rgd->ri.ri_addr); last_fs_block = fssize;
@@ -723,6 +723,8 @@ void savemeta(char *out_fn, int saveoption, int gziplevel) }get_journal_inode_blocks ();if (!slow) { +struct osi_node *n, *next =NULL ; +/* Save off the superblock */ save_block (sbd.device_fd, &mfd,0x10 * (4096 / sbd.bsize));/* If this is gfs1, save off the rindex because it's not
@@ -744,12 +746,12 @@ void savemeta(char *out_fn, int saveoption, int gziplevel) } }/* Walk through the resource groups saving everything within */ -for (tmp = sbd.rglist.next; tmp != &sbd.rglist; - tmp = tmp->next){ -struct rgrp_list *rgd; +for (n =osi_first (&sbd.rgtree); n; n = next) {int first; +struct rgrp_tree *rgd; - rgd = osi_list_entry(tmp, struct rgrp_list, list); + next =osi_next (n); + rgd = (struct rgrp_tree *)n; slow =gfs2_rgrp_read (&sbd, rgd);if (slow)continue ;
gfs2/fsck/initialize.c +13 -13
@@ -110,7 +110,7 @@ static void gfs2_inodetree_free(void)static void empty_super_block (struct gfs2_sbd *sdp) {log_info (_ ("Freeing buffers.\n" )); -gfs2_rgrp_free (&sdp->rglist); +gfs2_rgrp_free (&sdp->rgtree);if (bl)gfs2_bmap_destroy (sdp, bl);
@@ -131,10 +131,9 @@ static void empty_super_block(struct gfs2_sbd *sdp)*/ static int set_block_ranges (struct gfs2_sbd *sdp) { - -struct rgrp_list *rgd; +struct osi_node *n, *next =NULL ; +struct rgrp_tree *rgd;struct gfs2_rindex *ri; -osi_list_t *tmp;char buf[sdp->sd_sb.sb_bsize];uint64_t rmax =0 ;uint64_t rmin =0 ;
@@ -142,9 +141,9 @@ static int set_block_ranges(struct gfs2_sbd *sdp)log_info (_ ("Setting block ranges...\n" )); -for (tmp = sdp->rglist.next; tmp != &sdp->rglist; tmp = tmp->next) - { - rgd = osi_list_entry(tmp, struct rgrp_list, list); +for (n =osi_first (&sdp->rgtree); n; n = next) { + next =osi_next (n); + rgd = (struct rgrp_tree *)n; ri = &rgd->ri;if (ri->ri_data0 + ri->ri_data && ri->ri_data0 + ri->ri_data -1 > rmax)
@@ -191,7 +190,7 @@ static int set_block_ranges(struct gfs2_sbd *sdp)/** * check_rgrp_integrity - verify a rgrp free block count against the bitmap */ -static void check_rgrp_integrity (struct gfs2_sbd *sdp,struct rgrp_list *rgd, +static void check_rgrp_integrity (struct gfs2_sbd *sdp,struct rgrp_tree *rgd,int *fixit,int *this_rg_fixed,int *this_rg_bad) {
@@ -320,17 +319,18 @@ static void check_rgrp_integrity(struct gfs2_sbd *sdp, struct rgrp_list *rgd,*/ static int check_rgrps_integrity (struct gfs2_sbd *sdp) { +struct osi_node *n, *next =NULL ;int rgs_good =0 , rgs_bad =0 , rgs_fixed =0 ;int was_bad =0 , was_fixed =0 , error =0 ; -osi_list_t *tmp; -struct rgrp_list *rgd; +struct rgrp_tree *rgd;int reclaim_unlinked =0 ;log_info (_ ("Checking the integrity of all resource groups.\n" )); -for (tmp = sdp->rglist.next; tmp != &sdp->rglist; tmp = tmp->next) { +for (n =osi_first (&sdp->rgtree); n; n = next) { + next =osi_next (n); + rgd = (struct rgrp_tree *)n;if (fsck_abort)return 0 ; - rgd = osi_list_entry(tmp, struct rgrp_list, list);check_rgrp_integrity (sdp, rgd, &reclaim_unlinked, &was_fixed, &was_bad);if (was_fixed)
@@ -1224,7 +1224,7 @@ static int fill_super_block(struct gfs2_sbd *sdp)***************** First, initialize all lists ********************** ********************************************************************/ log_info (_ ("Initializing lists...\n" )); -osi_list_init (&sdp->rglist); + sdp->rgtree.osi_node =NULL ;/******************************************************************** ************ next, read in on-disk SB and set constants **********
gfs2/fsck/lost_n_found.c +6 -6
@@ -89,8 +89,8 @@ static void add_dotdot(struct gfs2_inode *ip)static uint64_t find_free_blk (struct gfs2_sbd *sdp) { -osi_list_t *tmp, *head; -struct rgrp_list *rl =NULL ; +struct osi_node *n, *next =NULL ; +struct rgrp_tree *rl =NULL ;struct gfs2_rindex *ri;struct gfs2_rgrp *rg;unsigned int block, bn =0 , x =0 , y =0 ;
@@ -98,14 +98,14 @@ static uint64_t find_free_blk(struct gfs2_sbd *sdp)struct gfs2_buffer_head *bh;memset (&rg,0 ,sizeof (rg)); -for (head = &sdp->rglist, tmp = head->next; tmp != head; - tmp = tmp->next) { - rl = osi_list_entry(tmp, struct rgrp_list, list); +for (n =osi_first (&sdp->rgtree); n; n = next) { + next =osi_next (n); + rl = (struct rgrp_tree *)n;if (rl->rg.rg_free)break ; } -if (tmp == head) +if (n ==NULL )return 0 ; ri = &rl->ri;
gfs2/fsck/main.c +5 -4
@@ -149,8 +149,8 @@ static void interrupt(int sig)static void check_statfs (struct gfs2_sbd *sdp) { -osi_list_t *tmp; -struct rgrp_list *rgd; +struct osi_node *n, *next =NULL ; +struct rgrp_tree *rgd;struct gfs2_rindex *ri;struct gfs2_statfs_change sc;char buf[sizeof (struct gfs2_statfs_change )];
@@ -171,8 +171,9 @@ static void check_statfs(struct gfs2_sbd *sdp) sdp->blks_alloced =0 ; sdp->dinodes_alloced =0 ; -for (tmp = sdp->rglist.next; tmp != &sdp->rglist; tmp = tmp->next) { - rgd = osi_list_entry(tmp, struct rgrp_list, list); +for (n =osi_first (&sdp->rgtree); n; n = next) { + next =osi_next (n); + rgd = (struct rgrp_tree *)n; ri = &rgd->ri; sdp->blks_total += ri->ri_data; sdp->blks_alloced += (ri->ri_data - rgd->rg.rg_free);
gfs2/fsck/metawalk.c +1 -1
@@ -31,7 +31,7 @@ int check_n_fix_bitmap(struct gfs2_sbd *sdp, uint64_t blk, enum gfs2_mark_block new_blockmap_state) {int old_bitmap_state, new_bitmap_state; -struct rgrp_list *rgd; +struct rgrp_tree *rgd; rgd =gfs2_blk2rgrpd (sdp, blk);
gfs2/fsck/pass1.c +5 -5
@@ -1534,10 +1534,10 @@ static int check_system_inodes(struct gfs2_sbd *sdp)*/ int pass1 (struct gfs2_sbd *sdp) { +struct osi_node *n, *next =NULL ;struct gfs2_buffer_head *bh; -osi_list_t *tmp;uint64_t block; -struct rgrp_list *rgd; +struct rgrp_tree *rgd;int first;uint64_t i;uint64_t rg_count =0 ;
@@ -1562,11 +1562,11 @@ int pass1(struct gfs2_sbd *sdp)* uses the rg bitmaps, so maybe that's the best way to start * things - we can change the method later if necessary. */ -for (tmp = sdp->rglist.next; tmp != &sdp->rglist; - tmp = tmp->next, rg_count++) { +for (n =osi_first (&sdp->rgtree); n; n = next) { + next =osi_next (n);log_debug (_ ("Checking metadata in Resource Group #%llu\n" ), (unsigned long long )rg_count); - rgd = osi_list_entry(tmp, struct rgrp_list, list); + rgd = (struct rgrp_tree *)n;for (i =0 ; i < rgd->ri.ri_length; i++) { log_debug( _("rgrp block %lld (0x%llx) " "is now marked as 'rgrp data'\n"),
gfs2/fsck/pass5.c +6 -5
@@ -195,7 +195,7 @@ static int check_block_status(struct gfs2_sbd *sdp, char *buffer,return 0 ; } -static void update_rgrp (struct gfs2_sbd *sdp,struct rgrp_list *rgp, +static void update_rgrp (struct gfs2_sbd *sdp,struct rgrp_tree *rgp,uint32_t *count) {uint32_t i;
@@ -280,18 +280,19 @@ static void update_rgrp(struct gfs2_sbd *sdp, struct rgrp_list *rgp,*/ int pass5 (struct gfs2_sbd *sdp) { -osi_list_t *tmp; -struct rgrp_list *rgp =NULL ; +struct osi_node *n, *next =NULL ; +struct rgrp_tree *rgp =NULL ;uint32_t count[5 ];uint64_t rg_count =0 ;/* Reconcile RG bitmaps with fsck bitmap */ -for (tmp = sdp->rglist.next; tmp != &sdp->rglist; tmp = tmp->next){ +for (n =osi_first (&sdp->rgtree); n; n = next) { + next =osi_next (n);if (skip_this_pass || fsck_abort)/* if asked to skip the rest */ return FSCK_OK ;log_info (_ ("Verifying Resource Group #%llu\n" ), (unsigned long long )rg_count);memset (count,0 ,sizeof (count)); - rgp = osi_list_entry(tmp, struct rgrp_list, list); + rgp = (struct rgrp_tree *)n; rg_count++;/* Compare the bitmaps and report the differences */
gfs2/fsck/rgrepair.c +82 -137
446 lines not on this page · raw message
gfs2/libgfs2/fs_bits.c +2 -2
@@ -177,7 +177,7 @@ int gfs2_set_bitmap(struct gfs2_sbd *sdp, uint64_t blkno, int state)int buf;uint32_t rgrp_block;struct gfs2_bitmap *bits =NULL ; -struct rgrp_list *rgd; +struct rgrp_tree *rgd;unsigned char *byte, cur_state;unsigned int bit;
@@ -225,7 +225,7 @@ int gfs2_set_bitmap(struct gfs2_sbd *sdp, uint64_t blkno, int state)* Returns: state on success, -1 on error */ int gfs2_get_bitmap (struct gfs2_sbd *sdp,uint64_t blkno, -struct rgrp_list *rgd) +struct rgrp_tree *rgd) {int i, val;uint32_t rgrp_block;
gfs2/libgfs2/fs_geometry.c +27 -26
107 lines not on this page · raw message
gfs2/libgfs2/fs_ops.c +8 -8
@@ -116,8 +116,8 @@ void inode_put(struct gfs2_inode **ip_in)static uint64_t blk_alloc_i (struct gfs2_sbd *sdp,unsigned int type) { -osi_list_t *tmp, *head; -struct rgrp_list *rl =NULL ; +struct osi_node *n, *next =NULL ; +struct rgrp_tree *rl =NULL ;struct gfs2_rindex *ri;struct gfs2_rgrp *rg;unsigned int block, bn =0 , x =0 , y =0 ;
@@ -125,14 +125,14 @@ static uint64_t blk_alloc_i(struct gfs2_sbd *sdp, unsigned int type)struct gfs2_buffer_head *bh;memset (&rg,0 ,sizeof (rg)); -for (head = &sdp->rglist, tmp = head->next; tmp != head; - tmp = tmp->next) { - rl = osi_list_entry(tmp, struct rgrp_list, list); +for (n =osi_first (&sdp->rgtree); n; n = next) { + next =osi_next (n); + rl = (struct rgrp_tree *)n;if (rl->rg.rg_free)break ; } -if (tmp == head) +if (n ==NULL )die ("out of space\n" ); ri = &rl->ri;
@@ -1753,7 +1753,7 @@ int gfs2_lookupi(struct gfs2_inode *dip, const char *filename, int len,*/ void gfs2_free_block (struct gfs2_sbd *sdp,uint64_t block) { -struct rgrp_list *rgd; +struct rgrp_tree *rgd;/* Adjust the free space count for the freed block */ rgd =gfs2_blk2rgrpd (sdp, block);/* find the rg for indir block */
@@ -1778,7 +1778,7 @@ int gfs2_freedi(struct gfs2_sbd *sdp, uint64_t diblock)struct gfs2_buffer_head *bh, *nbh;int h, head_size;uint64_t *ptr, block; -struct rgrp_list *rgd; +struct rgrp_tree *rgd;uint32_t height;osi_list_t metalist[GFS2_MAX_META_HEIGHT ];osi_list_t *cur_list, *next_list, *tmp;
gfs2/libgfs2/libgfs2.h +19 -15
@@ -17,6 +17,7 @@#include <linux/gfs2_ondisk.h> #include "osi_list.h" +#include "osi_tree.h" __BEGIN_DECLS
@@ -97,8 +98,8 @@ struct gfs2_bitmapuint32_t bi_len;/* The number of bytes in this block */ }; -struct rgrp_list { -osi_list_t list; +struct rgrp_tree { +struct osi_node node;uint64_t start;/* The offset of the beginning of this resource group */ uint64_t length;/* The length of this resource group */
@@ -224,7 +225,8 @@ struct gfs2_sbd {uint64_t orig_rgrps;uint64_t rgrps;uint64_t new_rgrps; -osi_list_t rglist; +struct osi_root rgtree; +struct osi_root rgcalc;unsigned int orig_journals;
@@ -324,7 +326,7 @@ extern unsigned long gfs2_bitfit(const unsigned char *buffer, unsigned long goal, unsigned char old_state);/* functions with blk #'s that are rgrp relative */ -extern uint32_t gfs2_blkalloc_internal (struct rgrp_list *rgd,uint32_t goal, +extern uint32_t gfs2_blkalloc_internal (struct rgrp_tree *rgd,uint32_t goal,unsigned char old_state,unsigned char new_state,int do_it);extern int gfs2_check_range (struct gfs2_sbd *sdp,uint64_t blkno);
@@ -332,7 +334,7 @@ extern int gfs2_check_range(struct gfs2_sbd *sdp, uint64_t blkno);/* functions with blk #'s that are file system relative */ extern int valid_block (struct gfs2_sbd *sdp,uint64_t blkno);extern int gfs2_get_bitmap (struct gfs2_sbd *sdp,uint64_t blkno, -struct rgrp_list *rgd); +struct rgrp_tree *rgd);extern int gfs2_set_bitmap (struct gfs2_sbd *sdp,uint64_t blkno,int state);/* fs_geometry.c */
@@ -340,7 +342,8 @@ extern void rgblocks2bitblocks(unsigned int bsize, uint32_t *rgblocks, uint32_t *bitblocks);extern uint64_t how_many_rgrps (struct gfs2_sbd *sdp,struct device *dev,int rgsize_specified); -extern void compute_rgrp_layout (struct gfs2_sbd *sdp,int rgsize_specified); +extern void compute_rgrp_layout (struct gfs2_sbd *sdp,struct osi_root *rgtree, +int rgsize_specified);extern void build_rgrps (struct gfs2_sbd *sdp,int write);/* fs_ops.c */
@@ -698,12 +701,13 @@ extern int gfs2_find_jhead(struct gfs2_inode *ip, struct gfs2_log_header *head);extern int clean_journal (struct gfs2_inode *ip,struct gfs2_log_header *head);/* rgrp.c */ -extern int gfs2_compute_bitstructs (struct gfs2_sbd *sdp,struct rgrp_list *rgd); -extern struct rgrp_list *gfs2_blk2rgrpd (struct gfs2_sbd *sdp,uint64_t blk); -extern uint64_t __gfs2_rgrp_read (struct gfs2_sbd *sdp,struct rgrp_list *rgd); -extern uint64_t gfs2_rgrp_read (struct gfs2_sbd *sdp,struct rgrp_list *rgd); -extern void gfs2_rgrp_relse (struct rgrp_list *rgd); -extern void gfs2_rgrp_free (osi_list_t *rglist); +extern int gfs2_compute_bitstructs (struct gfs2_sbd *sdp,struct rgrp_tree *rgd); +extern struct rgrp_tree *gfs2_blk2rgrpd (struct gfs2_sbd *sdp,uint64_t blk); +extern uint64_t gfs2_rgrp_read (struct gfs2_sbd *sdp,struct rgrp_tree *rgd); +extern void gfs2_rgrp_relse (struct rgrp_tree *rgd); +extern struct rgrp_tree *rgrp_insert (struct osi_root *rgtree, +uint64_t rgblock); +extern void gfs2_rgrp_free (struct osi_root *rgrp_tree);/* structures.c */ extern int build_master (struct gfs2_sbd *sdp);
@@ -720,11 +724,11 @@ extern int build_root(struct gfs2_sbd *sdp);extern int do_init_inum (struct gfs2_sbd *sdp);extern int do_init_statfs (struct gfs2_sbd *sdp);extern int gfs2_check_meta (struct gfs2_buffer_head *bh,int type); -extern int gfs2_next_rg_meta (struct rgrp_list *rgd,uint64_t *block, +extern int gfs2_next_rg_meta (struct rgrp_tree *rgd,uint64_t *block,int first); -extern int gfs2_next_rg_metatype (struct gfs2_sbd *sdp,struct rgrp_list *rgd, +extern int gfs2_next_rg_metatype (struct gfs2_sbd *sdp,struct rgrp_tree *rgd,uint64_t *block,uint32_t type,int first); -extern int gfs2_next_rg_freemeta (struct rgrp_list *rgd,uint64_t *block, +extern int gfs2_next_rg_freemeta (struct rgrp_tree *rgd,uint64_t *block,int first);/* super.c */
gfs2/libgfs2/rgrp.c +50 -48
135 lines not on this page · raw message
gfs2/libgfs2/structures.c +13 -13
@@ -344,8 +344,8 @@ int build_statfs(struct gfs2_sbd *sdp)int build_rindex (struct gfs2_sbd *sdp) {struct gfs2_inode *ip; -osi_list_t *tmp, *head; -struct rgrp_list *rl; +struct osi_node *n, *next =NULL ; +struct rgrp_tree *rl;char buf[sizeof (struct gfs2_rindex )];int count;
@@ -357,9 +357,9 @@ int build_rindex(struct gfs2_sbd *sdp) ip->i_di.di_payload_format =GFS2_FORMAT_RI ;bmodified (ip->i_bh); -for (head = &sdp->rglist, tmp = head->next; tmp != head; - tmp = tmp->next) { - rl = osi_list_entry(tmp, struct rgrp_list, list); +for (n =osi_first (&sdp->rgtree); n; n = next) { + next =osi_next (n); + rl = (struct rgrp_tree *)n;gfs2_rindex_out (&rl->ri, buf);
@@ -502,7 +502,7 @@ int gfs2_check_meta(struct gfs2_buffer_head *bh, int type)* * Returns: 0 on success, -1 when finished */ -static int __gfs2_next_rg_meta (struct rgrp_list *rgd,uint64_t *block, +static int __gfs2_next_rg_meta (struct rgrp_tree *rgd,uint64_t *block,int first,unsigned char state) {struct gfs2_bitmap *bits =NULL ;
@@ -510,17 +510,17 @@ static int __gfs2_next_rg_meta(struct rgrp_list *rgd, uint64_t *block,uint32_t blk = (first)?0 : (uint32_t )((*block +1 ) - rgd->ri.ri_data0);int i; -if (!first && (*block < rgd->ri.ri_data0)) { +if (!first && (*block < rgd->ri.ri_data0)) {log_err ("next_rg_meta: Start block is outside rgrp bounds.\n" );exit (1 ); } -for (i =0 ; i < length; i++){ +for (i =0 ; i < length; i++){ bits = &rgd->bits[i];if (blk < bits->bi_len *GFS2_NBBY )break ; blk -= bits->bi_len *GFS2_NBBY ; } -for (; i < length; i++){ +for (; i < length; i++){ bits = &rgd->bits[i]; blk =gfs2_bitfit ((unsigned char *)rgd->bh[i]->b_data + bits->bi_offset, bits->bi_len, blk, state);
@@ -531,17 +531,17 @@ static int __gfs2_next_rg_meta(struct rgrp_list *rgd, uint64_t *block, } blk =0 ; } -if (i == length) +if (i == length)return -1 ;return 0 ; } -int gfs2_next_rg_meta (struct rgrp_list *rgd,uint64_t *block,int first) +int gfs2_next_rg_meta (struct rgrp_tree *rgd,uint64_t *block,int first) {return __gfs2_next_rg_meta (rgd, block, first,GFS2_BLKST_DINODE ); } -int gfs2_next_rg_freemeta (struct rgrp_list *rgd,uint64_t *block,int first) +int gfs2_next_rg_freemeta (struct rgrp_tree *rgd,uint64_t *block,int first) {return __gfs2_next_rg_meta (rgd, block, first,GFS2_BLKST_UNLINKED ); }
@@ -555,7 +555,7 @@ int gfs2_next_rg_freemeta(struct rgrp_list *rgd, uint64_t *block, int first)* * Returns: 0 on success, -1 on error or finished */ -int gfs2_next_rg_metatype (struct gfs2_sbd *sdp,struct rgrp_list *rgd, +int gfs2_next_rg_metatype (struct gfs2_sbd *sdp,struct rgrp_tree *rgd,uint64_t *block,uint32_t type,int first) {struct gfs2_buffer_head *bh =NULL ;
gfs2/libgfs2/super.c +11 -16
@@ -149,12 +149,12 @@ int rindex_read(struct gfs2_sbd *sdp, int fd, int *count1, int *sane)struct gfs_rindex bufgfs1;struct gfs2_rindex bufgfs2; } buf; -struct rgrp_list *rgd, *prev_rgd; +struct gfs2_rindex ri; +struct rgrp_tree *rgd =NULL , *prev_rgd =NULL ;uint64_t prev_length =0 ; *sane =1 ; *count1 =0 ; - prev_rgd =NULL ;if (!fd && sdp->md.riinode->i_di.di_size %sizeof (struct gfs2_rindex )) *sane =0 ;/* rindex file size must be a multiple of 96 */ for (rg =0 ; ; rg++) {
@@ -170,15 +170,9 @@ int rindex_read(struct gfs2_sbd *sdp, int fd, int *count1, int *sane)if (error !=sizeof (struct gfs2_rindex ))return -1 ; - rgd = (struct rgrp_list *)malloc (sizeof (struct rgrp_list )); -if (!rgd) { -log_crit ("Cannot allocate memory for rindex.\n" ); -exit (-1 ); - } -memset (rgd,0 ,sizeof (struct rgrp_list )); -osi_list_add_prev (&rgd->list, &sdp->rglist); - -gfs2_rindex_in (&rgd->ri, (char *)&buf.bufgfs2); +gfs2_rindex_in (&ri, (char *)&buf.bufgfs2); + rgd =rgrp_insert (&sdp->rgtree, ri.ri_addr); +memcpy (&rgd->ri, &ri,sizeof (struct gfs2_rindex )); rgd->start = rgd->ri.ri_addr;if (prev_rgd) {
@@ -228,17 +222,18 @@ int rindex_read(struct gfs2_sbd *sdp, int fd, int *count1, int *sane)static int __ri_update (struct gfs2_sbd *sdp,int fd,int *rgcount,int *sane,int quiet) { -struct rgrp_list *rgd; +struct rgrp_tree *rgd;struct gfs2_rindex *ri; -osi_list_t *tmp;int count1 =0 , count2 =0 ;uint64_t errblock =0 ;uint64_t rmax =0 ; +struct osi_node *n, *next =NULL ;if (rindex_read (sdp, fd, &count1, sane)) goto fail; -for (tmp = sdp->rglist.next; tmp != &sdp->rglist; tmp = tmp->next) { - rgd = osi_list_entry(tmp, struct rgrp_list, list); +for (n =osi_first (&sdp->rgtree); n; n = next) { + next =osi_next (n); + rgd = (struct rgrp_tree *)n; errblock =gfs2_rgrp_read (sdp, rgd);if (errblock)return errblock;
@@ -260,7 +255,7 @@ static int __ri_update(struct gfs2_sbd *sdp, int fd, int *rgcount, int *sane,return 0 ; fail: -gfs2_rgrp_free (&sdp->rglist); +gfs2_rgrp_free (&sdp->rgtree);return -1 ; }
gfs2/mkfs/main_grow.c +33 -29
138 lines not on this page · raw message
gfs2/mkfs/main_mkfs.c +3 -3
@@ -540,7 +540,7 @@ void main_mkfs(int argc, char *argv[]) sdp->qcsize =GFS2_DEFAULT_QCSIZE ;strcpy (sdp->lockproto,GFS2_DEFAULT_LOCKPROTO ); sdp->time =time (NULL ); -osi_list_init (&sdp->rglist); + sdp->rgtree.osi_node =NULL ;decode_arguments (argc, argv, sdp);if (sdp->rgsize ==-1 )/* if rg size not specified */
@@ -626,7 +626,7 @@ void main_mkfs(int argc, char *argv[])/* Compute the resource group layouts */ -compute_rgrp_layout (sdp, rgsize_specified); +compute_rgrp_layout (sdp, &sdp->rgtree, rgsize_specified);/* Generate a random uuid */ get_random_bytes (uuid,sizeof (uuid));
@@ -680,7 +680,7 @@ void main_mkfs(int argc, char *argv[])inode_put (&sdp->md.inum);inode_put (&sdp->md.statfs); -gfs2_rgrp_free (&sdp->rglist); +gfs2_rgrp_free (&sdp->rgtree); error =fsync (sdp->device_fd);if (error) die( _("can't fsync device (%d): %s\n"),
Signature · 1 line
1.7.4.4
PATCH 56/56 libgfs2: Make in-core rgrps use rbtree
----- Original Message -----
| From 7a26516c6e3ed7e8fc87d48112171630f6db7677 Mon Sep 17 00:00:00 2001 | From: Bob Peterson <[email protected]> | Date: Thu, 25 Aug 2011 11:09:25 -0500 | Subject: [PATCH 56/56] libgfs2: Make in-core rgrps use rbtree | | This patch changes the in-core structure used for resource groups | from a linked list to an rbtree. | | rhbz#675723
Hi,
Please disregard this patch: I've caught some serious bugs in it and will be posting a replacement in the near future.
Regards,
Bob Peterson
Red Hat File Systems