fsck.gfs2: Add ability to check gfs1 file systems
PATCH 44/56 fsck.gfs2: Add ability to check gfs1 file systems
From 4b12052b4d8d15d6ff854d94c23a7086f9123be3 Mon Sep 17 00:00:00 2001
From: Bob Peterson <[email protected]>
Date: Thu, 11 Aug 2011 14:51:08 -0500
Subject: [PATCH 44/56] fsck.gfs2: Add ability to check gfs1 file systems
This patch gives fsck.gfs2 the ability to check GFS1 file systems.
rhbz#675723
--- gfs2/fsck/fs_recovery.c | 37 ++++-- gfs2/fsck/fsck.h | 3 + gfs2/fsck/initialize.c | 303 ++++++++++++++++++++++++++++++++++----------- gfs2/fsck/lost_n_found.c | 96 ++++++++++++--- gfs2/fsck/main.c | 14 ++- gfs2/fsck/metawalk.c | 90 ++++++++++---- gfs2/fsck/pass1.c | 167 ++++++++++++++++++++----- gfs2/fsck/pass1b.c | 5 +- gfs2/fsck/pass2.c | 41 ++++--- gfs2/fsck/pass3.c | 41 +++++- gfs2/fsck/pass4.c | 7 + gfs2/fsck/pass5.c | 87 ++++++++++++- gfs2/fsck/rgrepair.c | 20 +++- gfs2/fsck/util.h | 111 ++++++++++++----- gfs2/libgfs2/libgfs2.h | 3 + gfs2/libgfs2/structures.c | 29 +++-- 16 files changed, 825 insertions(+), 229 deletions(-)
gfs2/fsck/fs_recovery.c +28 -9
@@ -631,7 +631,9 @@ int ji_update(struct gfs2_sbd *sdp) {struct gfs2_inode *jip, *ip = sdp->md.jiinode;char journal_name[JOURNAL_NAME_SIZE ]; -int i; +int i, error; +char buf[sizeof (struct gfs_jindex )]; +struct gfs_jindex ji;if (!ip) {log_crit ("Journal index inode not found.\n" );
@@ -642,24 +644,41 @@ int ji_update(struct gfs2_sbd *sdp)plus two for "." and "..". So we subtract the 2 and divide by 3. If per_node is missing or damaged, we have to trust jindex has the correct number of entries. */ -if (sdp->md.pinode)/* if per_node was read in properly */ +if (sdp->gfs1) + sdp->md.journals = ip->i_di.di_size /sizeof (struct gfs_jindex ); +else if (sdp->md.pinode)/* if per_node was read in properly */ sdp->md.journals = (sdp->md.pinode->i_di.di_entries -2 ) /3 ;else sdp->md.journals = ip->i_di.di_entries -2 ;if (!(sdp->md.journal =calloc (sdp->md.journals, -sizeof (struct gfs2_inode *)))) { +sizeof (struct gfs2_inode *)))) {log_err ("Unable to allocate journal index\n" );return -1 ; }memset (journal_name,0 ,sizeof (*journal_name));for (i =0 ; i < sdp->md.journals; i++) { -/* FIXME check snprintf return code */ -snprintf (journal_name,JOURNAL_NAME_SIZE ,"journal%u" , i); -gfs2_lookupi (sdp->md.jiinode, journal_name,strlen (journal_name), - &jip); - sdp->md.journal[i] = jip; +if (sdp->gfs1) { + error =gfs2_readi (ip, + buf, i *sizeof (struct gfs_jindex ), +sizeof (struct gfs_jindex )); +if (!error) +break ; +if (error !=sizeof (struct gfs_jindex )){ +log_err ("An error occurred while reading the" +" journal index file.\n" ); +return -1 ; + } +gfs_jindex_in (&ji, buf); + sdp->md.journal[i] =inode_read (sdp, ji.ji_addr); + }else { +/* FIXME check snprintf return code */ +snprintf (journal_name,JOURNAL_NAME_SIZE , +"journal%u" , i); +gfs2_lookupi (sdp->md.jiinode, journal_name, +strlen (journal_name), &jip); + sdp->md.journal[i] = jip; + } }return 0 ; - }
gfs2/fsck/fsck.h +3 -0
@@ -113,6 +113,7 @@ extern void gfs2_dup_free(void);extern int fsck_query (const char *format, ...) __attribute__((format (printf,1 ,2 )));extern struct dir_info *dirtree_find (uint64_t block); +extern void dup_listent_delete (struct inode_with_dups *id);extern void dup_delete (struct duptree *b);extern void dirtree_delete (struct dir_info *b);
@@ -135,4 +136,6 @@ extern struct osi_root inodetree;extern int dups_found;/* How many duplicate references have we found? */ extern int dups_found_first;/* How many duplicates have we found the original reference for? */ +extern struct gfs_sb *sbd1; +#endif /* _FSCK_H */
gfs2/fsck/initialize.c +231 -72
443 lines not on this page · raw message
gfs2/fsck/lost_n_found.c +77 -19
188 lines not on this page · raw message
gfs2/fsck/main.c +11 -3
@@ -35,6 +35,7 @@ struct osi_root dup_blocks = (struct osi_root) { NULL, };struct osi_root dirtree = (struct osi_root ) {NULL , };struct osi_root inodetree = (struct osi_root ) {NULL , };int dups_found =0 , dups_found_first =0 ; +struct gfs_sb *sbd1 =NULL ;/* This function is for libgfs2's sake. */ void print_it (const char *label,const char *fmt,const char *fmt2, ...)
@@ -155,6 +156,10 @@ static void check_statfs(struct gfs2_sbd *sdp)char buf[sizeof (struct gfs2_statfs_change )];int count; +if (sdp->gfs1 && !sdp->md.statfs->i_di.di_size) { +log_info ("This GFS1 file system is not using fast_statfs.\n" ); +return ; + }/* Read the current statfs values */ count =gfs2_readi (sdp->md.statfs, buf,0 , sdp->md.statfs->i_di.di_size);
@@ -340,16 +345,19 @@ int main(int argc, char **argv)check_statfs (sdp);/* Free up our system inodes */ -inode_put (&sdp->md.inum); +if (!sdp->gfs1) +inode_put (&sdp->md.inum);inode_put (&sdp->md.statfs);for (j =0 ; j < sdp->md.journals; j++)inode_put (&sdp->md.journal[j]);inode_put (&sdp->md.jiinode);inode_put (&sdp->md.riinode);inode_put (&sdp->md.qinode); -inode_put (&sdp->md.pinode); +if (!sdp->gfs1) +inode_put (&sdp->md.pinode);inode_put (&sdp->md.rooti); -inode_put (&sdp->master_dir); +if (!sdp->gfs1) +inode_put (&sdp->master_dir);if (lf_dip)inode_put (&lf_dip);
gfs2/fsck/metawalk.c +65 -25
200 lines not on this page · raw message
gfs2/fsck/pass1.c +136 -31
333 lines not on this page · raw message
gfs2/fsck/pass1b.c +3 -2
@@ -360,7 +360,8 @@ static int find_block_ref(struct gfs2_sbd *sdp, uint64_t inode)/* Exhash dir leafs will be checked by check_metatree (right after the "end:" label.) But if this is a linear directory we need to check the dir with check_linear_dir. */ -if (S_ISDIR (ip->i_di.di_mode) && !(ip->i_di.di_flags &GFS2_DIF_EXHASH )) +if (is_dir (&ip->i_di, sdp->gfs1) && + !(ip->i_di.di_flags &GFS2_DIF_EXHASH )) error =check_linear_dir (ip, ip->i_bh, &find_dirents);/* Check for ea references in the inode */
@@ -696,7 +697,7 @@ static int handle_dup_blk(struct gfs2_sbd *sdp, struct duptree *b)_ ("reference-repaired data" ), gfs2_block_used); }else if (id->reftypecount[ref_as_meta]) { -if (S_ISDIR (ip->i_di.di_mode)) +if (is_dir (&ip->i_di, sdp->gfs1))fsck_blockmap_set (ip, b->block,_ ("reference-repaired leaf" ), gfs2_leaf_blk);
gfs2/fsck/pass2.c +26 -15
105 lines not on this page · raw message
gfs2/fsck/pass3.c +35 -6
56 lines not on this page · raw message
gfs2/fsck/pass4.c +7 -0
@@ -58,6 +58,13 @@ static int scan_inode_list(struct gfs2_sbd *sdp) {log_crit (_ ("osi_tree broken in scan_info_list!!\n" ));exit (FSCK_ERROR ); } +/* Don't check reference counts on the special gfs files */ +if (sdp->gfs1 && + ((ii->inode == sdp->md.riinode->i_di.di_num.no_addr) || + (ii->inode == sdp->md.jiinode->i_di.di_num.no_addr) || + (ii->inode == sdp->md.qinode->i_di.di_num.no_addr) || + (ii->inode == sdp->md.statfs->i_di.di_num.no_addr))) +continue ;if (ii->counted_links ==0 ) { log_err( _("Found unlinked inode at %llu (0x%llx)\n"), (unsigned long long)ii->inode,
gfs2/fsck/pass5.c +82 -5
133 lines not on this page · raw message
gfs2/fsck/rgrepair.c +16 -4
@@ -187,8 +187,13 @@ static uint64_t count_usedspace(struct gfs2_sbd *sdp, int first,unsigned int state;/* Count up the free blocks in the bitmap */ - off = (first) ?sizeof (struct gfs2_rgrp ) : -sizeof (struct gfs2_meta_header ); +if (first) { +if (sdp->gfs1) + off =sizeof (struct gfs_rgrp ); +else + off =sizeof (struct gfs2_rgrp ); + }else + off =sizeof (struct gfs2_meta_header ); bytes_to_check = sdp->bsize - off;for (x =0 ; x < bytes_to_check; x++) {unsigned char *byte;
@@ -685,12 +690,19 @@ static int rewrite_rg_block(struct gfs2_sbd *sdp, struct rgrp_list *rg, mh.mh_format =GFS2_FORMAT_RB ;gfs2_meta_header_out (&mh, rg->bh[x]); }else { -memset (&rg->rg,0 ,sizeof (struct gfs2_rgrp )); +if (sdp->gfs1) +memset (&rg->rg,0 ,sizeof (struct gfs_rgrp )); +else +memset (&rg->rg,0 ,sizeof (struct gfs2_rgrp )); rg->rg.rg_header.mh_magic =GFS2_MAGIC ; rg->rg.rg_header.mh_type =GFS2_METATYPE_RG ; rg->rg.rg_header.mh_format =GFS2_FORMAT_RG ; rg->rg.rg_free = rg->ri.ri_data; -gfs2_rgrp_out (&rg->rg, rg->bh[x]); +if (sdp->gfs1) +gfs_rgrp_out ((struct gfs_rgrp *)&rg->rg, + rg->bh[x]); +else +gfs2_rgrp_out (&rg->rg, rg->bh[x]); }brelse (rg->bh[x]); rg->bh[x] =NULL ;
gfs2/fsck/util.h +82 -29
152 lines not on this page · raw message
gfs2/libgfs2/libgfs2.h +3 -0
@@ -724,6 +724,9 @@ extern int gfs2_next_rg_meta(struct rgrp_list *rgd, uint64_t *block, int first);extern int gfs2_next_rg_metatype (struct gfs2_sbd *sdp,struct rgrp_list *rgd,uint64_t *block,uint32_t type,int first); +extern int gfs2_next_rg_freemeta (struct rgrp_list *rgd,uint64_t *block, +int first); +/* super.c */ extern int check_sb (struct gfs2_sb *sb,int allow_gfs);extern int read_sb (struct gfs2_sbd *sdp,int allow_gfs);
gfs2/libgfs2/structures.c +20 -9
@@ -502,39 +502,50 @@ int gfs2_check_meta(struct gfs2_buffer_head *bh, int type)* * Returns: 0 on success, -1 when finished */ -int gfs2_next_rg_meta (struct rgrp_list *rgd,uint64_t *block,int first) +static int __gfs2_next_rg_meta (struct rgrp_list *rgd,uint64_t *block, +int first,unsigned char state) {struct gfs2_bitmap *bits =NULL ;uint32_t length = rgd->ri.ri_length; -uint32_t blk = (first)?0 : (uint32_t )((*block+1 )-rgd->ri.ri_data0); +uint32_t blk = (first)?0 : (uint32_t )((*block +1 ) - rgd->ri.ri_data0);int i;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 ) +if (blk < bits->bi_len *GFS2_NBBY )break ; - blk -= bits->bi_len*GFS2_NBBY ; + blk -= bits->bi_len *GFS2_NBBY ; }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, -GFS2_BLKST_DINODE ); + bits->bi_offset, bits->bi_len, blk, state);if (blk !=BFITNOENT ){ - *block = blk + (bits->bi_start *GFS2_NBBY ) + rgd->ri.ri_data0; + *block = blk + (bits->bi_start *GFS2_NBBY ) + + rgd->ri.ri_data0;break ; } - blk=0 ; + blk =0 ; }if (i == length)return -1 ;return 0 ; } +int gfs2_next_rg_meta (struct rgrp_list *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) +{ +return __gfs2_next_rg_meta (rgd, block, first,GFS2_BLKST_UNLINKED ); +} +/** * next_rg_metatype * @rgd:
Signature · 1 line
1.7.4.4