libgfs2: Make check_sb and read_sb operate on gfs1
PATCH 4/56 libgfs2: Make check_sb and read_sb operate on gfs1
From eb78d8bc0c745495cfbf48eacbdd2bc8c40687b4 Mon Sep 17 00:00:00 2001
From: Bob Peterson <[email protected]>
Date: Fri, 12 Aug 2011 14:46:22 -0500
Subject: [PATCH 04/56] libgfs2: Make check_sb and read_sb operate on gfs1
This patch adds "allow_gfs1" parameters to the read_sb and check_sb functions. This will allow gfs2-utils to read and operate on gfs1 file systems in follow-up patches.
rhbz#675723
--- gfs2/edit/savemeta.c | 38 +++++++++------------------- gfs2/fsck/initialize.c | 4 +- gfs2/fsck/util.c | 5 ++- gfs2/libgfs2/libgfs2.h | 28 +++++++++++++++++++-- gfs2/libgfs2/super.c | 63 +++++++++++++++++++++++++++++------------------- gfs2/mkfs/main_grow.c | 2 +- 6 files changed, 81 insertions(+), 59 deletions(-)
gfs2/edit/savemeta.c +12 -26
@@ -630,7 +630,7 @@ static int next_rg_freemeta(struct gfs2_sbd *sdp, struct rgrp_list *rgd,void savemeta (char *out_fn,int saveoption,int gziplevel) { -int slow; +int slow, ret;osi_list_t *tmp;int rgcount;uint64_t jindex_block;
@@ -668,26 +668,13 @@ void savemeta(char *out_fn, int saveoption, int gziplevel)fprintf (stderr,"Bad constants (1)\n" );exit (-1 ); } -if (sbd.gfs1) { - sbd.bsize = sbd.sd_sb.sb_bsize; - sbd.sd_inptrs = (sbd.bsize - -sizeof (struct gfs_indirect )) / -sizeof (uint64_t ); - sbd.sd_diptrs = (sbd.bsize - -sizeof (struct gfs_dinode )) / -sizeof (uint64_t ); - }else { -if (read_sb (&sbd) <0 ) - slow = TRUE; -else { - sbd.sd_inptrs = (sbd.bsize - -sizeof (struct gfs2_meta_header )) / -sizeof (uint64_t ); - sbd.sd_diptrs = (sbd.bsize - -sizeof (struct gfs2_dinode )) / -sizeof (uint64_t ); - } + ret =read_sb (&sbd,1 ); +if (ret <0 ) { + slow = TRUE; + sbd.gfs1 =0 ; } +if (sbd.gfs1) + sbd.bsize = sbd.sd_sb.sb_bsize; } last_fs_block =lseek (sbd.device_fd,0 ,SEEK_END ) / sbd.bsize; printf("There are %llu blocks of %u bytes in the destination "
@@ -913,20 +900,19 @@ static int restore_data(int fd, gzFile *gzin_fd, int printblocksonly, }if (first) {struct gfs2_sb bufsb; +int ret; dummy_bh.b_data = (char *)&bufsb;memcpy (&bufsb, savedata->buf,sizeof (bufsb));gfs2_sb_in (&sbd.sd_sb, &dummy_bh); sbd1 = (struct gfs_sb *)&sbd.sd_sb; -if (sbd1->sb_fs_format ==GFS_FORMAT_FS && - sbd1->sb_header.mh_type ==GFS_METATYPE_SB && - sbd1->sb_header.mh_format ==GFS_FORMAT_SB && - sbd1->sb_multihost_format ==GFS_FORMAT_MULTI ) { - sbd.gfs1 = TRUE; - }else if (check_sb (&sbd.sd_sb)) { + ret =check_sb (&sbd.sd_sb,0 ); +if (ret <0 ) {fprintf (stderr,"Error: Invalid superblock data.\n" );return -1 ; } +if (ret ==1 ) + sbd.gfs1 = TRUE; sbd.bsize = sbd.sd_sb.sb_bsize;if (find_highblk) ;
gfs2/fsck/initialize.c +2 -2
@@ -1160,7 +1160,7 @@ static int fill_super_block(struct gfs2_sbd *sdp)log_crit (_ ("Bad constants (1)\n" ));exit (-1 ); } -if (read_sb (sdp) <0 ) { +if (read_sb (sdp,0 ) <0 ) {/* First, check for a gfs1 (not gfs2) file system */ if (sdp->sd_sb.sb_header.mh_magic ==GFS2_MAGIC && sdp->sd_sb.sb_header.mh_type ==GFS2_METATYPE_SB )
@@ -1169,7 +1169,7 @@ static int fill_super_block(struct gfs2_sbd *sdp)if (sb_repair (sdp) !=0 )return -1 ;/* unrepairable, so exit */ /* Now that we've tried to repair it, re-read it. */ -if (read_sb (sdp) <0 ) +if (read_sb (sdp,0 ) <0 )return -1 ; }
gfs2/fsck/util.c +3 -2
@@ -29,7 +29,7 @@ void big_file_comfort(struct gfs2_inode *ip, uint64_t blks_checked)if (blks_checked - last_reported_fblock < one_percent)return ; - last_reported_block = blks_checked; + last_reported_fblock = blks_checked;gettimeofday (&tv,NULL );if (!seconds) seconds = tv.tv_sec;
@@ -64,7 +64,8 @@ void warm_fuzzy_stuff(uint64_t block)if (!one_percent) one_percent = last_fs_block /100 ; -if (block - last_reported_block >= one_percent) { +if (!last_reported_block || + block - last_reported_block >= one_percent) { last_reported_block = block;gettimeofday (&tv,NULL );if (!seconds)
gfs2/libgfs2/libgfs2.h +25 -3
@@ -493,7 +493,29 @@ extern int write_journal(struct gfs2_sbd *sdp, unsigned int j,extern int device_size (int fd,uint64_t *bytes); -/* gfs1.c - GFS1 backward compatibility functions */ +/* gfs1.c - GFS1 backward compatibility structures and functions */ + +#define GFS_FORMAT_SB (100)/* Super-Block */ +#define GFS_METATYPE_SB (1)/* Super-Block */ +#define GFS_FORMAT_FS (1309)/* Filesystem (all-encompassing) */ +#define GFS_FORMAT_MULTI (1401)/* Multi-Host */ +/* GFS1 Dinode types */ +#define GFS_FILE_NON (0) +#define GFS_FILE_REG (1)/* regular file */ +#define GFS_FILE_DIR (2)/* directory */ +#define GFS_FILE_LNK (5)/* link */ +#define GFS_FILE_BLK (7)/* block device node */ +#define GFS_FILE_CHR (8)/* character device node */ +#define GFS_FILE_FIFO (101)/* fifo/pipe */ +#define GFS_FILE_SOCK (102)/* socket */ + +/* GFS 1 journal block types: */ +#define GFS_LOG_DESC_METADATA (300)/* metadata */ +#define GFS_LOG_DESC_IUL (400)/* unlinked inode */ +#define GFS_LOG_DESC_IDA (401)/* de-allocated inode */ +#define GFS_LOG_DESC_Q (402)/* quota */ +#define GFS_LOG_DESC_LAST (500)/* final in a logged transaction */ +struct gfs_indirect {struct gfs2_meta_header in_header;
@@ -672,8 +694,8 @@ extern int gfs2_next_rg_meta(struct rgrp_list *rgd, uint64_t *block,extern int gfs2_next_rg_metatype (struct gfs2_sbd *sdp,struct rgrp_list *rgd,uint64_t *block,uint32_t type,int first);/* super.c */ -extern int check_sb (struct gfs2_sb *sb); -extern int read_sb (struct gfs2_sbd *sdp); +extern int check_sb (struct gfs2_sb *sb,int allow_gfs); +extern int read_sb (struct gfs2_sbd *sdp,int allow_gfs);extern int rindex_read (struct gfs2_sbd *sdp,int fd,int *count1,int *sane);extern int ri_update (struct gfs2_sbd *sdp,int fd,int *rgcount,int *sane);extern int write_sb (struct gfs2_sbd *sdp);
gfs2/libgfs2/super.c +38 -25
113 lines not on this page · raw message
gfs2/mkfs/main_grow.c +1 -1
@@ -354,7 +354,7 @@ main_grow(int argc, char *argv[])log_crit (_ ("Bad constants (1)\n" ));exit (-1 ); } -if (read_sb (sdp) <0 ) +if (read_sb (sdp,0 ) <0 )die (_ ("gfs: Error reading superblock.\n" ));if (fix_device_geometry (sdp)) {
Signature · 1 line
1.7.4.4