libgfs2: Superblock building and writing improvements
PATCH 1/4 libgfs2: Superblock building and writing improvements
build_sb was creating the sb, setting its fields from an sdp and then writing it, and also zeroing the gap before the sb on the device in a block-by-block way using buffer_heads.
This patch splits the build_sb function into lgfs2_sb_init and lgfs2_sb_write which operate on gfs2_sb structures instead of gfs2_sbds. lgfs2_sb_write now uses pwritev to zero the initial blocks and write the sb to an fd.
get_random_bytes has been moved into structures.c and made static as only lgfs2_sb_init now uses it.
--- gfs2/convert/gfs2_convert.c | 3 +- gfs2/edit/hexedit.c | 3 +- gfs2/fsck/initialize.c | 14 +++--- gfs2/libgfs2/libgfs2.h | 8 +-- gfs2/libgfs2/misc.c | 45 ----------------- gfs2/libgfs2/ondisk.c | 9 ++-- gfs2/libgfs2/structures.c | 120 +++++++++++++++++++++++++++++++++----------- gfs2/libgfs2/super.c | 12 ----- gfs2/mkfs/main_mkfs.c | 32 ++++++++---- 9 files changed, 132 insertions(+), 114 deletions(-)
gfs2/convert/gfs2_convert.c +2 -1
@@ -2323,7 +2323,8 @@ int main(int argc, char **argv) bh =bread (&sb2, sb2.sb_addr); sb2.sd_sb.sb_fs_format =GFS2_FORMAT_FS ; sb2.sd_sb.sb_multihost_format =GFS2_FORMAT_MULTI ; -gfs2_sb_out (&sb2.sd_sb, bh); +gfs2_sb_out (&sb2.sd_sb, bh->b_data); +bmodified (bh);brelse (bh); error =fsync (sb2.device_fd);
gfs2/edit/hexedit.c +2 -1
@@ -2150,7 +2150,8 @@ static void process_field(const char *field, const char *nstr)gfs2_sb_assigns (&lsb, field, nstr); else gfs2_sb_assignval(&lsb, field, newval); -gfs2_sb_out (&lsb, rbh); +gfs2_sb_out (&lsb, rbh->b_data); +bmodified (rbh);if (!termlines)gfs2_sb_printval (&lsb, field); }else {
gfs2/fsck/initialize.c +8 -6
@@ -60,7 +60,7 @@ static int block_mounters(struct gfs2_sbd *sdp, int block_em) } } -if (write_sb (sdp)) { +if (lgfs2_sb_write (&sdp->sd_sb, sdp->device_fd, sdp->bsize)) { stack;return -1 ; }
@@ -1130,7 +1130,6 @@ static int sb_repair(struct gfs2_sbd *sdp) {uint64_t half;uint32_t known_bsize =0 ; -unsigned char uuid[16 ];int error =0 ;memset (&fix_md,0 ,sizeof (fix_md));
@@ -1205,9 +1204,8 @@ static int sb_repair(struct gfs2_sbd *sdp) } }/* Step 3 - Rebuild the lock protocol and file system table name */ -strcpy (sdp->lockproto,GFS2_DEFAULT_LOCKPROTO ); -strcpy (sdp->locktable,"unknown" );if (query (_ ("Okay to fix the GFS2 superblock? (y/n)" ))) { +struct gfs2_sb sb;log_info (_ ("Found system master directory at: 0x%llx\n" ), sdp->sd_sb.sb_master_dir.no_addr); sdp->master_dir = lgfs2_inode_read(sdp,
@@ -1226,8 +1224,12 @@ static int sb_repair(struct gfs2_sbd *sdp)log_crit (_ ("Error reading root inode: %s\n" ),strerror (errno));return -1 ; } -get_random_bytes (uuid,sizeof (uuid)); -build_sb (sdp, uuid); +lgfs2_sb_init (&sb, sdp->bsize); +strcpy (sb.sb_lockproto,GFS2_DEFAULT_LOCKPROTO ); +strcpy (sb.sb_locktable,"unknown" ); + sb.sb_master_dir = sdp->master_dir->i_di.di_num; + sb.sb_root_dir = sdp->md.rooti->i_di.di_num; +lgfs2_sb_write (&sb, sdp->device_fd, sdp->bsize);inode_put (&sdp->md.rooti);inode_put (&sdp->master_dir); sb_fixed =1 ;
gfs2/libgfs2/libgfs2.h +4 -4
@@ -719,7 +719,6 @@ extern int dir_exists(const char *dir);extern int mount_gfs2_meta (struct gfs2_sbd *sdp);extern void cleanup_metafs (struct gfs2_sbd *sdp);extern int is_fsname (char *name); -extern void get_random_bytes (void *buf,int nbytes);/* recovery.c */ extern void gfs2_replay_incr_blk (struct gfs2_inode *ip,unsigned int *blk);
@@ -753,7 +752,8 @@ static inline unsigned int rgrp_size(struct rgrp_tree *rgrp)/* structures.c */ extern int build_master (struct gfs2_sbd *sdp); -extern void build_sb (struct gfs2_sbd *sdp,const unsigned char *uuid); +extern void lgfs2_sb_init (struct gfs2_sb *sb,unsigned bsize); +extern int lgfs2_sb_write (const struct gfs2_sb *sb,int fd,const unsigned bsize);extern int build_journal (struct gfs2_sbd *sdp,int j,struct gfs2_inode *jindex);extern int build_jindex (struct gfs2_sbd *sdp);
@@ -789,14 +789,14 @@ extern void print_it(const char *label, const char *fmt, const char *fmt2, ...)/* Translation functions */ extern void gfs2_inum_in (struct gfs2_inum *no,char *buf); -extern void gfs2_inum_out (struct gfs2_inum *no,char *buf); +extern void gfs2_inum_out (const struct gfs2_inum *no,char *buf);extern void gfs2_meta_header_in (struct gfs2_meta_header *mh,struct gfs2_buffer_head *bh);extern void gfs2_meta_header_out (const struct gfs2_meta_header *mh,char *buf);extern void gfs2_meta_header_out_bh (const struct gfs2_meta_header *mh,struct gfs2_buffer_head *bh);extern void gfs2_sb_in (struct gfs2_sb *sb,struct gfs2_buffer_head *bh); -extern void gfs2_sb_out (struct gfs2_sb *sb,struct gfs2_buffer_head *bh); +extern void gfs2_sb_out (const struct gfs2_sb *sb,char *buf);extern void gfs2_rindex_in (struct gfs2_rindex *ri,char *buf);extern void gfs2_rindex_out (struct gfs2_rindex *ri,char *buf);extern void gfs2_rgrp_in (struct gfs2_rgrp *rg,struct gfs2_buffer_head *bh);
gfs2/libgfs2/misc.c +0 -45
54 lines not on this page · raw message
gfs2/libgfs2/ondisk.c +4 -5
@@ -48,7 +48,7 @@ void gfs2_inum_in(struct gfs2_inum *no, char *buf)CPIN_64 (no, str, no_addr); } -void gfs2_inum_out (struct gfs2_inum *no,char *buf) +void gfs2_inum_out (const struct gfs2_inum *no,char *buf) {struct gfs2_inum *str = (struct gfs2_inum *)buf;
@@ -124,11 +124,11 @@ void gfs2_sb_in(struct gfs2_sb *sb, struct gfs2_buffer_head *bh)#endif } -void gfs2_sb_out (struct gfs2_sb *sb,struct gfs2_buffer_head *bh) +void gfs2_sb_out (const struct gfs2_sb *sb,char *buf) { -struct gfs2_sb *str = (struct gfs2_sb *)bh->b_data; +struct gfs2_sb *str = (struct gfs2_sb *)buf; -gfs2_meta_header_out_bh (&sb->sb_header, bh); +gfs2_meta_header_out (&sb->sb_header, buf);CPOUT_32 (sb, str, sb_fs_format);CPOUT_32 (sb, str, sb_multihost_format);
@@ -144,7 +144,6 @@ void gfs2_sb_out(struct gfs2_sb *sb, struct gfs2_buffer_head *bh)#ifdef GFS2_HAS_UUID memcpy (str->sb_uuid, sb->sb_uuid,16 );#endif -bmodified (bh); }const char *str_uuid (const unsigned char *uuid)
gfs2/libgfs2/structures.c +90 -30
139 lines not on this page · raw message
gfs2/libgfs2/super.c +0 -12
@@ -309,15 +309,3 @@ int gfs1_ri_update(struct gfs2_sbd *sdp, int fd, int *rgcount, int quiet)return __ri_update (sdp, fd, rgcount, &sane, quiet); } - -int write_sb (struct gfs2_sbd *sbp) -{ -struct gfs2_buffer_head *bh; - - bh =bread (sbp,GFS2_SB_ADDR >> sbp->sd_fsb2bb_shift); -gfs2_sb_out (&sbp->sd_sb, bh); -brelse (bh); -fsync (sbp->device_fd);/* make sure the change gets to disk ASAP */ -return 0 ; -} -
gfs2/mkfs/main_mkfs.c +22 -10
@@ -569,8 +569,8 @@ static void print_results(struct gfs2_sbd *sdp, uint64_t real_device_size, (unsigned long long)sdp->fssize, _("blocks"));printf ("%-27s%u\n" ,_ ("Journals:" ), sdp->md.journals);printf ("%-27s%llu\n" ,_ ("Resource groups:" ), (unsigned long long )sdp->rgrps); -printf ("%-27s\"%s\"\n" ,_ ("Locking protocol:" ), sdp->lockproto); -printf ("%-27s\"%s\"\n" ,_ ("Lock table:" ), sdp->locktable); +printf ("%-27s\"%s\"\n" ,_ ("Locking protocol:" ), opts->lockproto); +printf ("%-27s\"%s\"\n" ,_ ("Lock table:" ), opts->locktable);/* Translators: "UUID" = universally unique identifier. */ printf ("%-27s%s\n" ,_ ("UUID:" ),str_uuid (uuid)); }
@@ -701,8 +701,6 @@ static void sbd_init(struct gfs2_sbd *sdp, struct mkfs_opts *opts, struct mkfs_d/* TODO: Check if the fssize is too small, somehow */ sdp->device.length = opts->fssize; } -strcpy (sdp->lockproto, opts->lockproto); -strcpy (sdp->locktable, opts->locktable); }static int probe_contents (struct mkfs_dev *dev)
@@ -791,11 +789,11 @@ static void open_dev(const char *path, struct mkfs_dev *dev)void main_mkfs (int argc,char *argv[]) {struct gfs2_sbd sbd; +struct gfs2_sb sb;struct mkfs_opts opts;struct mkfs_dev dev;lgfs2_rgrps_t rgs;int error; -unsigned char uuid[16 ];unsigned bsize;opts_init (&opts);
@@ -810,15 +808,16 @@ void main_mkfs(int argc, char *argv[]) }sbd_init (&sbd, &opts, &dev, bsize); +lgfs2_sb_init (&sb, bsize);if (opts.debug) {printf (_ ("File system options:\n" ));printf (" bsize = %u\n" , sbd.bsize);printf (" qcsize = %u\n" , sbd.qcsize);printf (" jsize = %u\n" , sbd.jsize);printf (" journals = %u\n" , sbd.md.journals); -printf (" proto = %s\n" , sbd.lockproto); +printf (" proto = %s\n" , opts.lockproto); +printf (" table = %s\n" , opts.locktable);printf (" rgsize = %u\n" , sbd.rgsize); -printf (" table = %s\n" , sbd.locktable);printf (" fssize = %" PRIu64"\n" , opts.fssize);printf (" sunit = %lu\n" , opts.sunit);printf (" swidth = %lu\n" , opts.swidth);
@@ -838,8 +837,13 @@ void main_mkfs(int argc, char *argv[])exit (1 ); } sbd.rgtree.osi_node =lgfs2_rgrps_root (rgs);// Temporary +build_root (&sbd); + sb.sb_root_dir = sbd.md.rooti->i_di.di_num; +build_master (&sbd); + sb.sb_master_dir = sbd.master_dir->i_di.di_num; + error =build_jindex (&sbd);if (error) {fprintf (stderr,_ ("Error building '%s': %s\n" ),"jindex" ,strerror (errno));
@@ -872,8 +876,9 @@ void main_mkfs(int argc, char *argv[])fprintf (stderr,_ ("Error building '%s': %s\n" ),"quota" ,strerror (errno));exit (EXIT_FAILURE ); } -get_random_bytes (uuid,sizeof (uuid)); -build_sb (&sbd, uuid); + +strcpy (sb.sb_lockproto, opts.lockproto); +strcpy (sb.sb_locktable, opts.locktable);do_init_inum (&sbd);do_init_statfs (&sbd);
@@ -884,6 +889,13 @@ void main_mkfs(int argc, char *argv[])inode_put (&sbd.md.statfs);gfs2_rgrp_free (&sbd.rgtree); + + error =lgfs2_sb_write (&sb, dev.fd, sbd.bsize); +if (error) { +perror (_ ("Failed to write superblock\n" )); +exit (EXIT_FAILURE ); + } + error =fsync (dev.fd);if (error){perror (opts.device);
@@ -897,5 +909,5 @@ void main_mkfs(int argc, char *argv[]) }if (!opts.quiet) -print_results (&sbd, dev.size, &opts, uuid); +print_results (&sbd, dev.size, &opts, sb.sb_uuid); }
Signature · 1 line
1.8.5.3
PATCH 2/4 gfs2-utils: Ensure sb_uuid uses are guarded
Guard uses of sb_uuid with #ifdef GFS2_HAS_UUID
Tweak print_results() in mkfs.gfs2 to accept the gfs2_sb which we conditionally print the uuid from, instead of the gfs2_sbd.
--- gfs2/edit/hexedit.c | 5 ++++- gfs2/mkfs/main_mkfs.c | 27 ++++++++++++++------------- gfs2/tune/super.c | 5 +++-- 3 files changed, 21 insertions(+), 16 deletions(-)
gfs2/edit/hexedit.c +4 -1
@@ -104,10 +104,12 @@ static int gfs2_sb_printval(struct gfs2_sb *lsb, const char *strfield)checkprints (strfield, lsb, sb_locktable);checkprint (strfield, lsb, __pad3.no_addr);checkprint (strfield, lsb, __pad4.no_addr); +#ifdef GFS2_HAS_UUID if (strcmp (strfield,"sb_uuid" ) ==0 ) {printf ("%s\n" ,str_uuid (lsb->sb_uuid));return 0 ; } +#endif return -1 ; }
@@ -135,8 +137,9 @@ static int gfs2_sb_assigns(struct gfs2_sb *lsb, const char *strfield, {checkassigns (strfield, lsb, sb_lockproto, val);checkassigns (strfield, lsb, sb_locktable, val); +#ifdef GFS2_HAS_UUID checkassigns (strfield, lsb, sb_uuid, val); - +#endif return -1 ; }
gfs2/mkfs/main_mkfs.c +14 -13
@@ -555,24 +555,25 @@ static void opts_check(struct mkfs_opts *opts) } } -static void print_results (struct gfs2_sbd *sdp,uint64_t real_device_size, -struct mkfs_opts *opts,unsigned char uuid[16 ]) +static void print_results (struct gfs2_sb *sb,struct mkfs_dev *dev,struct mkfs_opts *opts, +uint64_t rgrps,uint64_t fssize) {printf ("%-27s%s\n" ,_ ("Device:" ), opts->device); -printf ("%-27s%u\n" ,_ ("Block size:" ), sdp->bsize); -printf ("%-27s%.2f %s (%llu %s)\n" ,_ ("Device size:" ), +printf ("%-27s%u\n" ,_ ("Block size:" ), sb->sb_bsize); +printf ("%-27s%.2f %s (%" PRIu64" %s)\n" ,_ ("Device size:" ),/* Translators: "GB" here means "gigabytes" */ - real_device_size / ((float )(1 <<30 )),_ ("GB" ), - (unsigned long long )real_device_size / sdp->bsize,_ ("blocks" )); -printf ("%-27s%.2f %s (%llu %s)\n" ,_ ("Filesystem size:" ), - sdp->fssize / ((float )(1 <<30 )) * sdp->bsize,_ ("GB" ), - (unsigned long long )sdp->fssize,_ ("blocks" )); -printf ("%-27s%u\n" ,_ ("Journals:" ), sdp->md.journals); -printf ("%-27s%llu\n" ,_ ("Resource groups:" ), (unsigned long long )sdp->rgrps); + (dev->size / ((float )(1 <<30 ))),_ ("GB" ), + (dev->size / sb->sb_bsize),_ ("blocks" )); +printf ("%-27s%.2f %s (%" PRIu64" %s)\n" ,_ ("Filesystem size:" ), + (fssize / ((float )(1 <<30 )) * sb->sb_bsize),_ ("GB" ), fssize,_ ("blocks" )); +printf ("%-27s%u\n" ,_ ("Journals:" ), opts->journals); +printf ("%-27s%" PRIu64"\n" ,_ ("Resource groups:" ), rgrps);printf ("%-27s\"%s\"\n" ,_ ("Locking protocol:" ), opts->lockproto);printf ("%-27s\"%s\"\n" ,_ ("Lock table:" ), opts->locktable); +#ifdef GFS2_HAS_UUID /* Translators: "UUID" = universally unique identifier. */ -printf ("%-27s%s\n" ,_ ("UUID:" ),str_uuid (uuid)); +printf ("%-27s%s\n" ,_ ("UUID:" ),str_uuid (sb->sb_uuid)); +#endif }static void warn_of_destruction (const char *path)
@@ -909,5 +910,5 @@ void main_mkfs(int argc, char *argv[]) }if (!opts.quiet) -print_results (&sbd, dev.size, &opts, sb.sb_uuid); +print_results (&sb, &dev, &opts, sbd.rgrps, sbd.fssize); }
gfs2/tune/super.c +3 -2
@@ -124,8 +124,9 @@ static int is_gfs2(const struct tunegfs2 *tfs)int print_super (const struct tunegfs2 *tfs) {printf (_ ("File system volume name: %s\n" ), tfs->sb->sb_locktable); -if (is_gfs2 (tfs)) -printf (_ ("File system UUID: %s\n" ),uuid2str (tfs->sb->sb_uuid)); +#ifdef GFS2_HAS_UUID +printf (_ ("File system UUID: %s\n" ),uuid2str (tfs->sb->sb_uuid)); +#endif printf (_ ("File system magic number: 0x%X\n" ),be32_to_cpu (tfs->sb->sb_header.mh_magic));printf (_ ("Block size: %d\n" ),be32_to_cpu (tfs->sb->sb_bsize));printf (_ ("Block shift: %d\n" ),be32_to_cpu (tfs->sb->sb_bsize_shift));
Signature · 1 line
1.8.5.3
PATCH 3/4 libgfs2: Add support for new leaf hint fields
In reply to Andrew PriceKernel commit 01bcb0de introduces new gfs2_leaf fields. This patch adds support for those fields to libgfs2, conditional upon them being discovered in the configure stage. Includes meta.c changes by Steve Whitehouse.
--- configure.ac | 10 ++++------ gfs2/edit/extended.c | 20 ++++++++++++++++---- gfs2/edit/gfs2hex.c | 9 ++------- gfs2/edit/hexedit.c | 14 ++++++++++++++ gfs2/edit/hexedit.h | 5 +---- gfs2/fsck/metawalk.c | 2 +- gfs2/libgfs2/fs_ops.c | 11 +++++++++-- gfs2/libgfs2/meta.c | 8 ++++++++ gfs2/libgfs2/ondisk.c | 26 +++++++++++++++++++++++--- 9 files changed, 78 insertions(+), 27 deletions(-)
configure.ac +4 -6
@@ -116,12 +116,10 @@ AC_CHECK_HEADERS([arpa/inet.h fcntl.h inttypes.h libintl.h limits.h locale.h mnt AC_CHECK_HEADERS([linux/dlmconstants.h linux/limits.h linux/types.h linux/netlink.h linux/fs.h],, [AC_MSG_ERROR([Unable to find all required kernel headers.])]) -AC_CHECK_HEADERS([linux/gfs2_ondisk.h], - [AC_CHECK_MEMBERS([struct gfs2_sb.sb_uuid],, - [AC_MSG_ERROR([Unable to find gfs2 uuid support in your headers. -Please update your kernel headers to a more recent version])], - [#include <linux/gfs2_ondisk.h>])], - [AC_MSG_ERROR([Unable to find required kernel headers.])]) +AC_CHECK_HEADER([linux/gfs2_ondisk.h], [], [AC_MSG_ERROR([Unable to find linux/gfs2_ondisk.h])]) +AC_CHECK_MEMBER([struct gfs2_sb.sb_uuid], [], [], [[#include <linux/gfs2_ondisk.h>]]) +AC_CHECK_MEMBER([struct gfs2_leaf.lf_inode],[AC_DEFINE([GFS2_HAS_LEAF_HINTS],[],[Leaf block hints])], + [], [[#include <linux/gfs2_ondisk.h>]]) # Checks for typedefs, structures, and compiler characteristics. AC_C_INLINE
gfs2/edit/extended.c +16 -4
@@ -296,8 +296,18 @@ static void print_inode_type(__be16 de_type) } } +#ifdef GFS2_HAS_LEAF_HINTS +#define LEAF_HINT_FMTS "lf_inode: 0x%"PRIx64", lf_dist: %"PRIu32", " \ + "lf_nsec: %"PRIu32", lf_sec: %"PRIu64", " +#define LEAF_HINT_FIELDS (lp) lp->lf_inode, lp->lf_dist, lp->lf_nsec, lp->lf_sec, +#else +#define LEAF_HINT_FMTS +#define LEAF_HINT_FIELDS (lp) +#endif +static int display_leaf (struct iinfo *ind) { +struct gfs2_leaf *leaf = &ind->ii[0 ].lf;int start_line, total_dirents = start_row[dmode];int d;
@@ -305,11 +315,13 @@ static int display_leaf(struct iinfo *ind)if (gfs2_struct_type ==GFS2_METATYPE_SB )print_gfs2 ("The superblock has 2 directories" );else -print_gfs2 ("Directory block: lf_depth:%d, lf_entries:%d," +print_gfs2 ("Directory block: lf_depth:%d, lf_entries:%d, " +LEAF_HINT_FMTS "fmt:%d next=0x%llx (%d dirents)." , - ind->ii[0 ].lf_depth, ind->ii[0 ].lf_entries, - ind->ii[0 ].lf_dirent_format, - ind->ii[0 ].lf_next, + leaf->lf_depth, leaf->lf_entries, +LEAF_HINT_FIELDS (leaf) + leaf->lf_dirent_format, + leaf->lf_next, ind->ii[0 ].dirents); start_line = line;
gfs2/edit/gfs2hex.c +2 -7
@@ -322,17 +322,12 @@ uint64_t do_leaf_extended(char *dlebuf, struct iinfo *indir) {int x, i;struct gfs2_dirent de; -struct gfs2_leaf leaf;struct gfs2_buffer_head tbh;/* kludge */ x =0 ;memset (indir,0 ,sizeof (*indir)); tbh.b_data = dlebuf; -gfs2_leaf_in (&leaf, &tbh); - indir->ii[0 ].lf_depth = leaf.lf_depth; - indir->ii[0 ].lf_entries = leaf.lf_entries; - indir->ii[0 ].lf_dirent_format = leaf.lf_dirent_format; - indir->ii[0 ].lf_next = leaf.lf_next; +gfs2_leaf_in (&indir->ii[0 ].lf, &tbh);/* Directory Entries: */ for (i =sizeof (struct gfs2_leaf ); i < sbd.bsize; i += de.de_rec_len) {
@@ -353,7 +348,7 @@ uint64_t do_leaf_extended(char *dlebuf, struct iinfo *indir)if (de.de_rec_len <=sizeof (struct gfs2_dirent ))break ; } -return leaf.lf_next; +return indir->ii[0 ].lf.lf_next; }static void do_eattr_extended (struct gfs2_buffer_head *ebh)
gfs2/edit/hexedit.c +14 -0
@@ -219,7 +219,15 @@ static int gfs2_leaf_printval(struct gfs2_leaf *lf, const char *strfield)checkprint (strfield, lf, lf_entries);checkprint (strfield, lf, lf_dirent_format);checkprint (strfield, lf, lf_next); +#ifdef GFS2_HAS_LEAF_HINTS +checkprint (strfield, lf, lf_inode); +checkprint (strfield, lf, lf_dist); +checkprint (strfield, lf, lf_nsec); +checkprint (strfield, lf, lf_sec); +checkprints (strfield, lf, lf_reserved2); +#else checkprints (strfield, lf, lf_reserved); +#endif return -1 ; }
@@ -231,6 +239,12 @@ static int gfs2_leaf_assignval(struct gfs2_leaf *lf, const char *strfield,checkassign (strfield, lf, lf_entries, value);checkassign (strfield, lf, lf_dirent_format, value);checkassign (strfield, lf, lf_next, value); +#ifdef GFS2_HAS_LEAF_HINTS +checkassign (strfield, lf, lf_inode, value); +checkassign (strfield, lf, lf_dist, value); +checkassign (strfield, lf, lf_nsec, value); +checkassign (strfield, lf, lf_sec, value); +#endif return -1 ; }
gfs2/edit/hexedit.h +1 -4
@@ -79,10 +79,7 @@ struct indirect_info {int height;uint64_t block;uint32_t dirents; -uint16_t lf_depth; -uint16_t lf_entries; -uint32_t lf_dirent_format; -uint64_t lf_next; +struct gfs2_leaf lf;struct metapath mp;struct gfs2_dirents dirent[64 ]; };
gfs2/fsck/metawalk.c +1 -1
@@ -657,7 +657,6 @@ static void dir_leaf_reada(struct gfs2_inode *ip, uint64_t *tbl, unsigned hsize)static int check_leaf_blks (struct gfs2_inode *ip,struct metawalk_fxns *pass) {int error =0 ; -struct gfs2_leaf leaf;unsigned hsize = (1 << ip->i_di.di_depth);uint64_t leaf_no, leaf_next;uint64_t first_ok_leaf, orig_di_blocks;
@@ -767,6 +766,7 @@ static int check_leaf_blks(struct gfs2_inode *ip, struct metawalk_fxns *pass) chained_leaf =0 ; do { + struct gfs2_leaf leaf; if (fsck_abort) { free(tbl); posix_fadvise(sdp->device_fd, 0, 0, POSIX_FADV_NORMAL);
gfs2/libgfs2/fs_ops.c +9 -2
@@ -941,6 +941,9 @@ void dir_split_leaf(struct gfs2_inode *dip, uint32_t start, uint64_t leaf_no, oleaf->lf_depth =cpu_to_be16 (oleaf->lf_depth); nleaf->lf_depth = oleaf->lf_depth; +#ifdef GFS2_HAS_LEAF_HINTS + nleaf->lf_inode =cpu_to_be64 (dip->i_di.di_num.no_addr); +#endif dip->i_di.di_blocks++;bmodified (dip->i_bh);
@@ -1124,7 +1127,9 @@ restart: nleaf = (struct gfs2_leaf *)nbh->b_data; nleaf->lf_depth = leaf->lf_depth; nleaf->lf_dirent_format =cpu_to_be32 (GFS2_FORMAT_DE ); - +#ifdef GFS2_HAS_LEAF_HINTS + nleaf->lf_inode =cpu_to_be64 (dip->i_di.di_num.no_addr); +#endif err =dirent_alloc (dip, nbh, len, &dent);if (err)return err;
@@ -1175,7 +1180,9 @@ static void dir_make_exhash(struct gfs2_inode *dip) leaf = (struct gfs2_leaf *)bh->b_data; leaf->lf_dirent_format =cpu_to_be32 (GFS2_FORMAT_DE ); leaf->lf_entries =cpu_to_be16 (dip->i_di.di_entries); - +#ifdef GFS2_HAS_LEAF_HINTS + leaf->lf_inode =cpu_to_be64 (dip->i_di.di_num.no_addr); +#endif buffer_copy_tail (sdp, bh,sizeof (struct gfs2_leaf ), dip->i_bh,sizeof (struct gfs2_dinode ));
gfs2/libgfs2/meta.c +8 -0
@@ -317,7 +317,15 @@ F(lf_depth) F(lf_entries) F(lf_dirent_format) F(lf_next) +#ifdef GFS2_HAS_LEAF_HINTS +FP(lf_inode, .points_to = (1 << LGFS2_MT_GFS2_DINODE)) +F(lf_dist) +F(lf_nsec, .flags = LGFS2_MFF_NSECS) +F(lf_sec, .flags = LGFS2_MFF_SECS) +RF(lf_reserved2) +#else RF(lf_reserved) +#endif };#undef STRUCT
gfs2/libgfs2/ondisk.c +23 -3
@@ -433,8 +433,15 @@ void gfs2_leaf_in(struct gfs2_leaf *lf, struct gfs2_buffer_head *bh)CPIN_16 (lf, str, lf_entries);CPIN_32 (lf, str, lf_dirent_format);CPIN_64 (lf, str, lf_next); - +#ifdef GFS2_HAS_LEAF_HINTS +CPIN_64 (lf, str, lf_inode); +CPIN_32 (lf, str, lf_dist); +CPIN_32 (lf, str, lf_nsec); +CPIN_64 (lf, str, lf_sec); +CPIN_08 (lf, str, lf_reserved2,40 ); +#else CPIN_08 (lf, str, lf_reserved,32 ); +#endif }void gfs2_leaf_out (struct gfs2_leaf *lf,struct gfs2_buffer_head *bh)
@@ -446,8 +453,15 @@ void gfs2_leaf_out(struct gfs2_leaf *lf, struct gfs2_buffer_head *bh)CPOUT_16 (lf, str, lf_entries);CPOUT_32 (lf, str, lf_dirent_format);CPOUT_64 (lf, str, lf_next); - -CPOUT_08 (lf, str, lf_reserved,32 ); +#ifdef GFS2_HAS_LEAF_HINTS +CPOUT_64 (lf, str, lf_inode); +CPOUT_32 (lf, str, lf_dist); +CPOUT_32 (lf, str, lf_nsec); +CPOUT_64 (lf, str, lf_sec); +CPOUT_08 (lf, str, lf_reserved2,40 ); +#else +CPOUT_08 (lf, str, lf_reserved,64 ); +#endif bmodified (bh); }
@@ -458,6 +472,12 @@ void gfs2_leaf_print(struct gfs2_leaf *lf)pv (lf, lf_entries,"%u" ,"0x%x" );pv (lf, lf_dirent_format,"%u" ,"0x%x" );pv (lf, lf_next,"%llu" ,"0x%llx" ); +#ifdef GFS2_HAS_LEAF_HINTS +pv (lf, lf_inode,"%llu" ,"0x%llx" ); +pv (lf, lf_dist,"%u" ,"0x%x" ); +pv (lf, lf_nsec,"%u" ,"0x%x" ); +pv (lf, lf_sec,"%llu" ,"0x%llx" ); +#endif }void gfs2_ea_header_in (struct gfs2_ea_header *ea,char *buf)
Signature · 1 line
1.8.5.3
PATCH 3/4 libgfs2: Add support for new leaf hint fields
Hi,
Quoted 68 lines · Andrew Price
Kernel commit
01bcb0deintroduces newgfs2_leaffields. This patch adds support for those fields to libgfs2, conditional upon them being discovered in the configure stage. Includesmeta.cchanges by Steve Whitehouse.Signed-off-by Andrew Price <[email protected]>--- configure.ac | 10 ++++------ gfs2/edit/extended.c | 20 ++++++++++++++++---- gfs2/edit/gfs2hex.c | 9 ++------- gfs2/edit/hexedit.c | 14 ++++++++++++++ gfs2/edit/hexedit.h | 5 +---- gfs2/fsck/metawalk.c | 2 +- gfs2/libgfs2/fs_ops.c | 11 +++++++++-- gfs2/libgfs2/meta.c | 8 ++++++++ gfs2/libgfs2/ondisk.c | 26 +++++++++++++++++++++++--- 9 files changed, 78 insertions(+), 27 deletions(-)configure.ac +4
-6@@ -116,12 +116,10 @@ AC_CHECK_HEADERS([arpa/inet.h fcntl.h inttypes.h libintl.h limits.h locale.h mnt AC_CHECK_HEADERS([linux/dlmconstants.h linux/limits.h linux/types.h linux/netlink.h linux/fs.h],, [AC_MSG_ERROR([Unable to find all required kernel headers.])]) -AC_CHECK_HEADERS([linux/gfs2_ondisk.h], - [AC_CHECK_MEMBERS([struct gfs2_sb.sb_uuid],, - [AC_MSG_ERROR([Unable to find gfs2 uuid support in your headers. -Please update your kernel headers to a more recent version])], - [#include <linux/gfs2_ondisk.h>])], - [AC_MSG_ERROR([Unable to find required kernel headers.])]) +AC_CHECK_HEADER([linux/gfs2_ondisk.h], [], [AC_MSG_ERROR([Unable to find linux/gfs2_ondisk.h])]) +AC_CHECK_MEMBER([struct gfs2_sb.sb_uuid], [], [], [[#include <linux/gfs2_ondisk.h>]]) +AC_CHECK_MEMBER([struct gfs2_leaf.lf_inode],[AC_DEFINE([GFS2_HAS_LEAF_HINTS],[],[Leaf block hints])], + [], [[#include <linux/gfs2_ondisk.h>]]) # Checks for typedefs, structures, and compiler characteristics. AC_C_INLINEgfs2/edit/extended.c +11
-1@@ -296,8 +296,18 @@ static void print_inode_type(__be16 de_type) } } +#ifdef GFS2_HAS_LEAF_HINTS +#define LEAF_HINT_FMTS "lf_inode: 0x%"PRIx64", lf_dist: %"PRIu32", " \ + "lf_nsec: %"PRIu32", lf_sec: %"PRIu64", " +#define LEAF_HINT_FIELDS (lp) lp->lf_inode, lp->lf_dist, lp->lf_nsec, lp->lf_sec, +#else +#define LEAF_HINT_FMTS +#define LEAF_HINT_FIELDS (lp) +#endif +static int display_leaf (struct iinfo *ind) { +struct gfs2_leaf *leaf = &ind->ii[0 ].lf;int start_line, total_dirents = start_row[dmode];int d;@@ -305,11 +315,13 @@ static int display_leaf(struct iinfo *ind)if (gfs2_struct_type ==GFS2_METATYPE_SB )print_gfs2 ("The superblock has 2 directories" );else - print_gfs2("Directory block: lf_depth:%d, lf_entries:%d," + print_gfs2("Directory block: lf_depth:%d, lf_entries:%d, "
gfs2/edit/extended.c static int display_leaf(struct iinfo *ind) · line 325
Quoted 10 lines
gfs2/edit/extended.c +5
-3+LEAF_HINT_FMTS "fmt:%d next=0x%llx (%d dirents)." , - ind->ii[0 ].lf_depth, ind->ii[0 ].lf_entries, - ind->ii[0 ].lf_dirent_format, - ind->ii[0 ].lf_next, + leaf->lf_depth, leaf->lf_entries, +LEAF_HINT_FIELDS (leaf) + leaf->lf_dirent_format, + leaf->lf_next, ind->ii[0].dirents);
Hmm. It should be possible to use the metadata description to print out any arbitrary data structure without needing to reference the fields in the structure directly, so that this kind of thing shouldn't be required.
Quoted 41 lines
gfs2/edit/extended.c +0
-0start_line = line;gfs2/edit/gfs2hex.c +2
-7@@ -322,17 +322,12 @@ uint64_t do_leaf_extended(char *dlebuf, struct iinfo *indir) {int x, i;struct gfs2_dirent de; -struct gfs2_leaf leaf;struct gfs2_buffer_head tbh;/* kludge */ x =0 ;memset (indir,0 ,sizeof (*indir)); tbh.b_data = dlebuf; -gfs2_leaf_in (&leaf, &tbh); - indir->ii[0 ].lf_depth = leaf.lf_depth; - indir->ii[0 ].lf_entries = leaf.lf_entries; - indir->ii[0 ].lf_dirent_format = leaf.lf_dirent_format; - indir->ii[0 ].lf_next = leaf.lf_next; +gfs2_leaf_in (&indir->ii[0 ].lf, &tbh);/* Directory Entries: */ for (i =sizeof (struct gfs2_leaf ); i < sbd.bsize; i += de.de_rec_len) {@@ -353,7 +348,7 @@ uint64_t do_leaf_extended(char *dlebuf, struct iinfo *indir)if (de.de_rec_len <=sizeof (struct gfs2_dirent ))break ; } -return leaf.lf_next; +return indir->ii[0 ].lf.lf_next; }static void do_eattr_extended (struct gfs2_buffer_head *ebh)gfs2/edit/hexedit.c +0
-0@@ -219,7 +219,15 @@ static int gfs2_leaf_printval(struct gfs2_leaf *lf, const char *strfield)checkprint (strfield, lf, lf_entries);checkprint (strfield, lf, lf_dirent_format);
gfs2/edit/hexedit.c static int gfs2_leaf_printval(struct gfs2_leaf *lf, const char *strfield) · line 230
Quoted 10 lines
gfs2/edit/hexedit.c +8
-0checkprint (strfield, lf, lf_next); +#ifdef GFS2_HAS_LEAF_HINTS +checkprint (strfield, lf, lf_inode); +checkprint (strfield, lf, lf_dist); +checkprint (strfield, lf, lf_nsec); +checkprint (strfield, lf, lf_sec); +checkprints (strfield, lf, lf_reserved2); +#else checkprints (strfield, lf, lf_reserved); +#endif
Likewise here as well,
Steve.
PATCH 3/4 libgfs2: Add support for new leaf hint fields
Quoted 77 lines · Steven Whitehouse
Hi,
Quoted 74 lines · Andrew Price
Kernel commit
01bcb0deintroduces newgfs2_leaffields. This patch adds support for those fields to libgfs2, conditional upon them being discovered in the configure stage. Includesmeta.cchanges by Steve Whitehouse.Signed-off-by Andrew Price <[email protected]>--- configure.ac | 10 ++++------ gfs2/edit/extended.c | 20 ++++++++++++++++---- gfs2/edit/gfs2hex.c | 9 ++------- gfs2/edit/hexedit.c | 14 ++++++++++++++ gfs2/edit/hexedit.h | 5 +---- gfs2/fsck/metawalk.c | 2 +- gfs2/libgfs2/fs_ops.c | 11 +++++++++-- gfs2/libgfs2/meta.c | 8 ++++++++ gfs2/libgfs2/ondisk.c | 26 +++++++++++++++++++++++--- 9 files changed, 78 insertions(+), 27 deletions(-)configure.ac +4
-6@@ -116,12 +116,10 @@ AC_CHECK_HEADERS([arpa/inet.h fcntl.h inttypes.h libintl.h limits.h locale.h mnt AC_CHECK_HEADERS([linux/dlmconstants.h linux/limits.h linux/types.h linux/netlink.h linux/fs.h],, [AC_MSG_ERROR([Unable to find all required kernel headers.])]) -AC_CHECK_HEADERS([linux/gfs2_ondisk.h], - [AC_CHECK_MEMBERS([struct gfs2_sb.sb_uuid],, - [AC_MSG_ERROR([Unable to find gfs2 uuid support in your headers. -Please update your kernel headers to a more recent version])], - [#include <linux/gfs2_ondisk.h>])], - [AC_MSG_ERROR([Unable to find required kernel headers.])]) +AC_CHECK_HEADER([linux/gfs2_ondisk.h], [], [AC_MSG_ERROR([Unable to find linux/gfs2_ondisk.h])]) +AC_CHECK_MEMBER([struct gfs2_sb.sb_uuid], [], [], [[#include <linux/gfs2_ondisk.h>]]) +AC_CHECK_MEMBER([struct gfs2_leaf.lf_inode],[AC_DEFINE([GFS2_HAS_LEAF_HINTS],[],[Leaf block hints])], + [], [[#include <linux/gfs2_ondisk.h>]]) # Checks for typedefs, structures, and compiler characteristics. AC_C_INLINEgfs2/edit/extended.c +13
-4@@ -296,8 +296,18 @@ static void print_inode_type(__be16 de_type) } } +#ifdef GFS2_HAS_LEAF_HINTS +#define LEAF_HINT_FMTS "lf_inode: 0x%"PRIx64", lf_dist: %"PRIu32", " \ + "lf_nsec: %"PRIu32", lf_sec: %"PRIu64", " +#define LEAF_HINT_FIELDS (lp) lp->lf_inode, lp->lf_dist, lp->lf_nsec, lp->lf_sec, +#else +#define LEAF_HINT_FMTS +#define LEAF_HINT_FIELDS (lp) +#endif +static int display_leaf (struct iinfo *ind) { +struct gfs2_leaf *leaf = &ind->ii[0 ].lf;int start_line, total_dirents = start_row[dmode];int d;@@ -305,11 +315,13 @@ static int display_leaf(struct iinfo *ind)if (gfs2_struct_type ==GFS2_METATYPE_SB )print_gfs2 ("The superblock has 2 directories" );else - print_gfs2("Directory block: lf_depth:%d, lf_entries:%d," + print_gfs2("Directory block: lf_depth:%d, lf_entries:%d, " + LEAF_HINT_FMTS "fmt:%d next=0x%llx (%d dirents).", - ind->ii[0].lf_depth, ind->ii[0].lf_entries, - ind->ii[0].lf_dirent_format, - ind->ii[0].lf_next, + leaf->lf_depth, leaf->lf_entries,
Quoted 8 lines
gfs2/edit/extended.c static int display_leaf(struct iinfo *ind) · line 325
Quoted 4 lines
gfs2/edit/extended.c +3
-0+LEAF_HINT_FIELDS (leaf) + leaf->lf_dirent_format, + leaf->lf_next, ind->ii[0].dirents);Hmm. It should be possible to use the metadata description to print out any arbitrary data structure without needing to reference the fields in the structure directly, so that this kind of thing shouldn't be required.
Yes, that's true of a lot of parts of the code and I've been planning to take care of it all at once by adding generic printing or 'tostring' functions to libgfs2. What I haven't decided yet is whether we need to store format strings ("%s" etc.) for each field in the metadata description or whether we can just use something like the field_print function in libgfs2/lang.c, which is slightly hacky:
static int field_print(const struct gfs2_buffer_head *bh, const struct lgfs2_metadata *mtype,
const struct lgfs2_metafield *field)
{
const char *fieldp = (char *)bh->iov.iov_base + field->offset;
printf("%s\t%"PRIu64"\t%u\t%u\t%s\t", mtype->name,
bh->b_blocknr, field->offset, field->length, field->name);
if (field->flags & LGFS2_MFF_UUID) {
printf("'%s'\n", str_uuid((const unsigned char *)fieldp));
} else if (field->flags & LGFS2_MFF_STRING) {
printf("'%s'\n", fieldp);
} else {
switch(field->length) {
case 1:
printf("%"PRIu8"\n", *(uint8_t *)fieldp);
break;
case 2:
printf("%"PRIu16"\n", be16_to_cpu(*(uint16_t
*)fieldp));
break;
case 4:
printf("%"PRIu32"\n", be32_to_cpu(*(uint32_t
*)fieldp));
break;
case 8:
printf("%"PRIu64"\n", be64_to_cpu(*(uint64_t
*)fieldp));
break;
default:
// "Reserved" field so just print 0
printf("0\n");
return 1;
}
}
return 0;
}Andy
Quoted 57 lines
Quoted 42 lines
gfs2/edit/extended.c +0
-0start_line = line;gfs2/edit/gfs2hex.c +2
-7@@ -322,17 +322,12 @@ uint64_t do_leaf_extended(char *dlebuf, struct iinfo *indir) {int x, i;struct gfs2_dirent de; -struct gfs2_leaf leaf;struct gfs2_buffer_head tbh;/* kludge */ x =0 ;memset (indir,0 ,sizeof (*indir)); tbh.b_data = dlebuf; -gfs2_leaf_in (&leaf, &tbh); - indir->ii[0 ].lf_depth = leaf.lf_depth; - indir->ii[0 ].lf_entries = leaf.lf_entries; - indir->ii[0 ].lf_dirent_format = leaf.lf_dirent_format; - indir->ii[0 ].lf_next = leaf.lf_next; +gfs2_leaf_in (&indir->ii[0 ].lf, &tbh);/* Directory Entries: */ for (i =sizeof (struct gfs2_leaf ); i < sbd.bsize; i += de.de_rec_len) {@@ -353,7 +348,7 @@ uint64_t do_leaf_extended(char *dlebuf, struct iinfo *indir)if (de.de_rec_len <=sizeof (struct gfs2_dirent ))break ; } -return leaf.lf_next; +return indir->ii[0 ].lf.lf_next; }static void do_eattr_extended (struct gfs2_buffer_head *ebh)gfs2/edit/hexedit.c +0
-0@@ -219,7 +219,15 @@ static int gfs2_leaf_printval(struct gfs2_leaf *lf, const char *strfield)checkprint (strfield, lf, lf_entries);checkprint (strfield, lf, lf_dirent_format);gfs2/edit/hexedit.c static int gfs2_leaf_printval(struct gfs2_leaf *lf, const char *strfield) · line 230
Quoted 10 lines
gfs2/edit/hexedit.c +8
-0checkprint (strfield, lf, lf_next); +#ifdef GFS2_HAS_LEAF_HINTS +checkprint (strfield, lf, lf_inode); +checkprint (strfield, lf, lf_dist); +checkprint (strfield, lf, lf_nsec); +checkprint (strfield, lf, lf_sec); +checkprints (strfield, lf, lf_reserved2); +#else checkprints (strfield, lf, lf_reserved); +#endif Likewise here as well,
Steve.
PATCH 4/4 mkfs.gfs2: Remove a dead structure
In reply to Andrew Pricestruct mkfs_rgs has not been used since the new rgrp functions were added to libgfs2. Remove it.
--- gfs2/mkfs/main_mkfs.c | 19 ------------------- 1 file changed, 19 deletions(-)
gfs2/mkfs/main_mkfs.c +0 -19
@@ -151,25 +151,6 @@ struct mkfs_dev { unsigned int got_topol:1; }; -/** -* A representation of the state of resource group calculation. Allows mkfs to create -* resource groups at any point instead of creating them all in one batch. -*/ -struct mkfs_rgs { -struct osi_root *root; -uint64_t nextaddr; -unsigned bsize; -unsigned long align; -unsigned long align_off; -unsigned long curr_offset; -uint64_t maxrgsz; -uint64_t minrgsz; -uint64_t devlen; -uint64_t rgsize; -uint64_t count; -uint64_t blks_total; -}; -static void opts_init (struct mkfs_opts *opts) {memset (opts,0 ,sizeof (*opts));
Signature · 1 line
1.8.5.3
PATCH 1/4 libgfs2: Superblock building and writing improvements
In reply to Andrew Price----- Original Message -----
| build_sb was creating the sb, setting its fields from an sdp and then | writing it, and also zeroing the gap before the sb on the device in a | block-by-block way using buffer_heads. | | This patch splits the build_sb function into lgfs2_sb_init and | lgfs2_sb_write which operate on gfs2_sb structures instead of gfs2_sbds. | lgfs2_sb_write now uses pwritev to zero the initial blocks and write the | sb to an fd. | | get_random_bytes has been moved into structures.c and made static as | only lgfs2_sb_init now uses it. | | Signed-off-by: Andrew Price <[email protected]> | ---
Hi,
All four patches look good to me. ACK.
Bob Peterson
Red Hat File Systems
PATCH 1/1 fsck.gfs2: special handling for gfs1 sb update
In reply to Andrew PriceSince the gfs2_sb structure doesn't contain all the gfs1 fields, updating using lgfs2_sb_write overwrites some gfs1 fields with zeros and breaks the filesystem.
We need to update only the gfs2_sb fields and leave the rest as-is.
gfs2/fsck/initialize.c +3 -0
@@ -60,6 +60,9 @@ static int block_mounters(struct gfs2_sbd *sdp, int block_em) } } +if (sdp->gfs1) +return lgfs2_sb_update (sdp); +if (lgfs2_sb_write (&sdp->sd_sb, sdp->device_fd, sdp->bsize)) { stack;return -1 ;
gfs2/libgfs2/libgfs2.h +1 -0
@@ -754,6 +754,7 @@ static inline unsigned int rgrp_size(struct rgrp_tree *rgrp)extern int build_master (struct gfs2_sbd *sdp);extern void lgfs2_sb_init (struct gfs2_sb *sb,unsigned bsize);extern int lgfs2_sb_write (const struct gfs2_sb *sb,int fd,const unsigned bsize); +extern int lgfs2_sb_update (struct gfs2_sbd *sbp);extern int build_journal (struct gfs2_sbd *sdp,int j,struct gfs2_inode *jindex);extern int build_jindex (struct gfs2_sbd *sdp);
gfs2/libgfs2/structures.c +11 -0
@@ -105,6 +105,17 @@ void lgfs2_sb_init(struct gfs2_sb *sb, unsigned bsize)#endif } +int lgfs2_sb_update (struct gfs2_sbd *sbp) +{ +struct gfs2_buffer_head *bh; + + bh =bread (sbp,GFS2_SB_ADDR >> sbp->sd_fsb2bb_shift); +gfs2_sb_out (&sbp->sd_sb, bh->b_data); +brelse (bh); +fsync (sbp->device_fd);/* make sure the change gets to disk ASAP */ +return 0 ; +} +int lgfs2_sb_write (const struct gfs2_sb *sb,int fd,const unsigned bsize) {int i, err =-1 ;
PATCH 1/1 fsck.gfs2: special handling for gfs1 sb update
Hi Abhi,
Quoted 39 lines · Abhijith Das
Since the
gfs2_sbstructure doesn't contain all the gfs1 fields, updating usinglgfs2_sb_writeoverwrites some gfs1 fields with zeros and breaks the filesystem.We need to update only the
gfs2_sbfields and leave the rest as-is.Signed-off-by Abhi Das <[email protected]>gfs2/fsck/initialize.c +3
-0@@ -60,6 +60,9 @@ static int block_mounters(struct gfs2_sbd *sdp, int block_em) } } +if (sdp->gfs1) +return lgfs2_sb_update (sdp); +if (lgfs2_sb_write (&sdp->sd_sb, sdp->device_fd, sdp->bsize)) { stack;return -1 ;gfs2/libgfs2/libgfs2.h +1
-0@@ -754,6 +754,7 @@ static inline unsigned int rgrp_size(struct rgrp_tree *rgrp)extern int build_master (struct gfs2_sbd *sdp);extern void lgfs2_sb_init (struct gfs2_sb *sb,unsigned bsize);extern int lgfs2_sb_write (const struct gfs2_sb *sb,int fd,const unsigned bsize); +extern int lgfs2_sb_update (struct gfs2_sbd *sbp);extern int build_journal (struct gfs2_sbd *sdp,int j,struct gfs2_inode *jindex);extern int build_jindex (struct gfs2_sbd *sdp);gfs2/libgfs2/structures.c +0
-0
gfs2/libgfs2/structures.c void lgfs2_sb_init(struct gfs2_sb *sb, unsigned bsize) · line 112
Quoted 8 lines
gfs2/libgfs2/structures.c +5
-0@@ -105,6 +105,17 @@ void lgfs2_sb_init(struct gfs2_sb *sb, unsigned bsize)#endif } +int lgfs2_sb_update (struct gfs2_sbd *sbp) +{ +struct gfs2_buffer_head *bh; + + bh =bread (sbp,GFS2_SB_ADDR >> sbp->sd_fsb2bb_shift);
Perhaps it should return non-zero if bh == NULL. bread() is one of those cases where libgfs2 still calls exit() in an error path but that's going to change at some point (I promise!).
gfs2/libgfs2/structures.c void lgfs2_sb_init(struct gfs2_sb *sb, unsigned bsize) · line 113
Quoted 1 line
gfs2/libgfs2/structures.c +1
-0+gfs2_sb_out (&sbp->sd_sb, bh->b_data);
I think a bmodified(bh); might be needed here too. I've been slowing pushing the gfs2_buffer_head usage out of ondisk.c and the long term plan is to replace them entirely but until then we'll need to set them modified explicitly in some cases.
Cheers,
Andy
Quoted 9 lines
gfs2/libgfs2/structures.c +5
-0+brelse (bh); +fsync (sbp->device_fd);/* make sure the change gets to disk ASAP */ +return 0 ; +} +int lgfs2_sb_write (const struct gfs2_sb *sb,int fd,const unsigned bsize) {int i, err =-1 ;