mkfs.gfs2 improvements (groundwork)
cover mkfs.gfs2 improvements (groundwork)
This patchset lays the groundwork for the RAID stripe alignment (etc.) enhancements I'm working on. Notably it reduces the peak heap usage (from >3GB to ~25MB for a 50TB fs with default options) and also improves performance slightly. It also adds more tests to the test suite (run 'make check').
Andrew Price (5):
libgfs2: Rework blk_alloc_i
libgfs2: Make gfs2_rgrp_out accept char buffers mkfs.gfs2: Reduce memory usage
gfs2-utils: Make the tool tests script more useful mkfs.gfs2: Separate user options from file system params
.gitignore | 2 + gfs2/convert/gfs2_convert.c | 10 +- gfs2/edit/hexedit.c | 4 +- gfs2/fsck/initialize.c | 4 +- gfs2/fsck/metawalk.c | 4 +- gfs2/fsck/pass5.c | 2 +- gfs2/fsck/rgrepair.c | 4 +- gfs2/libgfs2/fs_geometry.c | 4 +- gfs2/libgfs2/fs_ops.c | 99 +++++--- gfs2/libgfs2/gfs1.c | 6 +- gfs2/libgfs2/libgfs2.h | 10 +- gfs2/libgfs2/ondisk.c | 32 ++- gfs2/libgfs2/structures.c | 2 +- gfs2/mkfs/main_jadd.c | 2 +- gfs2/mkfs/main_mkfs.c | 593 +++++++++++++++++++++++--------------------- tests/tool_tests.sh | 56 ++++- 16 files changed, 476 insertions(+), 358 deletions(-)
Signature · 1 line
1.8.1.2
PATCH 1/5 libgfs2: Rework blk_alloc_i
blk_alloc_i previously chose any resource group with a free block and assumed that the bitmaps were already available in the rgrp_tree. This patch allows us to allocate blocks in a resource group with a given number of free blocks in order to plan ahead and reads in the bitmap data on demand. It also removes some exit()s from blk_alloc_i.
--- gfs2/libgfs2/fs_ops.c | 79 ++++++++++++++++++++++++++++++++++++++------------ gfs2/libgfs2/libgfs2.h | 1 + 2 files changed, 61 insertions(+), 19 deletions(-)
gfs2/libgfs2/fs_ops.c +60 -19
@@ -116,32 +116,24 @@ void inode_put(struct gfs2_inode **ip_in) *ip_in =NULL ;/* make sure the memory isn't accessed again */ } -static uint64_t blk_alloc_i (struct gfs2_sbd *sdp,unsigned int type) +static int blk_alloc_in_rg (struct gfs2_sbd *sdp,unsigned int type,struct rgrp_tree *rl,uint64_t *blkno) { -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 ;unsigned int state;struct gfs2_buffer_head *bh; -memset (&rg,0 ,sizeof (rg)); -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 (rl ==NULL || rl->rg.rg_free ==0 ) { + errno =ENOSPC ; +return -1 ; } -if (n ==NULL ) { -fprintf (stderr,"Not enough space available on device\n" ); -exit (1 ); - } +if (rl->bh[0 ] ==NULL &&gfs2_rgrp_read (sdp, rl) !=0 ) +return -1 ; ri = &rl->ri; rg = &rl->rg; -for (block =0 ; block < ri->ri_length; block++) { bh = rl->bh[block]; x = (block) ?sizeof (struct gfs2_meta_header ) :sizeof (struct gfs2_rgrp );
@@ -157,7 +149,7 @@ static uint64_t blk_alloc_i(struct gfs2_sbd *sdp, unsigned int type)fprintf (stderr,"allocation is broken (1): %" PRIu64" %u\n" , (uint64_t )rl->ri.ri_addr, rl->rg.rg_free); -exit (1 ); +return -1 ; found:if (bn >= ri->ri_bitbytes *GFS2_NBBY ) {
@@ -165,7 +157,7 @@ found:" (0x%" PRIx64") Free:%u\n" , bn, ri->ri_bitbytes *GFS2_NBBY , (uint64_t )rl->ri.ri_addr, (uint64_t)rl->ri.ri_addr, rl->rg.rg_free); -exit (1 ); +return -1 ; }switch (type) {
@@ -179,7 +171,7 @@ found:break ;default :fprintf (stderr,"bad state\n" ); -exit (1 ); +return -1 ; } bh->b_data[x] &= ~(0x03 << (GFS2_BIT_SIZE * y));
@@ -193,7 +185,27 @@ found:gfs2_rgrp_out (rg, rl->bh[0 ]); sdp->blks_alloced++; -return ri->ri_data0 + bn; + *blkno = ri->ri_data0 + bn; +return 0 ; +} + +/** +* Do not use this function, it's only here until we can kill it. +* Use blk_alloc_in_rg directly instead. +*/ +static uint64_t blk_alloc_i (struct gfs2_sbd *sdp,unsigned int type) +{ +int ret; +uint64_t blkno =0 ; +struct osi_node *n =NULL ; +for (n =osi_first (&sdp->rgtree); n; n =osi_next (n)) { +if (((struct rgrp_tree *)n)->rg.rg_free) +break ; + } + ret =blk_alloc_in_rg (sdp, type, (struct rgrp_tree *)n, &blkno); +if (ret !=0 )/* Do what the old blk_alloc_i did */ +exit (1 ); +return blkno; }uint64_t data_alloc (struct gfs2_inode *ip)
@@ -220,6 +232,33 @@ uint64_t dinode_alloc(struct gfs2_sbd *sdp)return blk_alloc_i (sdp,DINODE ); } +/** +* Allocate a dinode block in a bitmap. In order to plan ahead we look for a +* resource group with blksreq free blocks but only allocate the one dinode block. +* Returns 0 on success with the allocated block number in *blkno or non-zero otherwise. +*/ +int lgfs2_dinode_alloc (struct gfs2_sbd *sdp,const uint64_t blksreq,uint64_t *blkno) +{ +int ret; +struct rgrp_tree *rgt; +struct osi_node *n =NULL ; +for (n =osi_first (&sdp->rgtree); n; n =osi_next (n)) { + rgt = (struct rgrp_tree *)n; +if (rgt->rg.rg_free >= blksreq) +break ; + } +if (rgt ==NULL ) +return -1 ; + + ret =blk_alloc_in_rg (sdp,DINODE , rgt, blkno); +gfs2_rgrp_relse (rgt); + +if (ret ==0 ) + sdp->dinodes_alloced++; + +return ret; +} +static __inline__void buffer_clear_tail (struct gfs2_sbd *sdp,struct gfs2_buffer_head *bh,int head) {
@@ -1380,7 +1419,9 @@ static struct gfs2_inode *__createi(struct gfs2_inode *dip,gfs2_lookupi (dip, filename,strlen (filename), &ip);if (!ip) { - bn =dinode_alloc (sdp); + err =lgfs2_dinode_alloc (sdp,1 , &bn); +if (err !=0 ) +return NULL ;if (if_gfs1) inum.no_formal_ino = bn;
gfs2/libgfs2/libgfs2.h +1 -0
@@ -440,6 +440,7 @@ extern void inode_put(struct gfs2_inode **ip);extern uint64_t data_alloc (struct gfs2_inode *ip);extern uint64_t meta_alloc (struct gfs2_inode *ip);extern uint64_t dinode_alloc (struct gfs2_sbd *sdp); +extern int lgfs2_dinode_alloc (struct gfs2_sbd *sdp,const uint64_t blksreq,uint64_t *blkno);extern int gfs2_readi (struct gfs2_inode *ip,void *buf,uint64_t offset,unsigned int size);#define gfs2_writei (ip, buf, offset, size) \
Signature · 1 line
1.8.1.2
PATCH 2/5 libgfs2: Make gfs2_rgrp_out accept char buffers
In reply to Andrew PriceIn order to prepare for handling resource groups separately from buffer heads in mkfs.gfs2, change gfs2_rgrp_out to copy rgrps to char buffers instead of buffer heads. Copying to bh's is now done in gfs2_rgrp_out_bh.
--- gfs2/convert/gfs2_convert.c | 10 +++++----- gfs2/edit/hexedit.c | 4 ++-- gfs2/fsck/initialize.c | 4 ++-- gfs2/fsck/metawalk.c | 4 ++-- gfs2/fsck/pass5.c | 2 +- gfs2/fsck/rgrepair.c | 4 ++-- gfs2/libgfs2/fs_geometry.c | 4 ++-- gfs2/libgfs2/fs_ops.c | 20 ++++++++++---------- gfs2/libgfs2/gfs1.c | 6 +++--- gfs2/libgfs2/libgfs2.h | 8 +++++--- gfs2/libgfs2/ondisk.c | 32 +++++++++++++++++++++----------- gfs2/libgfs2/structures.c | 2 +- gfs2/mkfs/main_jadd.c | 2 +- 13 files changed, 57 insertions(+), 45 deletions(-)
gfs2/convert/gfs2_convert.c +5 -5
@@ -237,7 +237,7 @@ static int convert_rgs(struct gfs2_sbd *sbp) sbp->dinodes_alloced += rgd1->rg_useddi;convert_bitmaps (sbp, rgd);/* Write the updated rgrp to the gfs2 buffer */ -gfs2_rgrp_out (&rgd->rg, rgd->bh[0 ]); +gfs2_rgrp_out_bh (&rgd->rg, rgd->bh[0 ]); rgs++;if (rgs %100 ==0 ) {printf ("." );
@@ -359,7 +359,7 @@ static void fix_metatree(struct gfs2_sbd *sbp, struct gfs2_inode *ip, bh =bread (sbp, block);if (new)memset (bh->b_data,0 , sbp->bsize); -gfs2_meta_header_out (&mh, bh); +gfs2_meta_header_out_bh (&mh, bh); } hdrsize = blk->height ? sizeof(struct gfs2_meta_header) :
@@ -517,7 +517,7 @@ static void fix_jdatatree(struct gfs2_sbd *sbp, struct gfs2_inode *ip,if (new)memset (bh->b_data,0 , sbp->bsize);if (h < (blk->height -1 )) -gfs2_meta_header_out (&mh, bh); +gfs2_meta_header_out_bh (&mh, bh); }if (amount > sbp->bsize - ptramt)
@@ -1855,9 +1855,9 @@ static int journ_space_to_rg(struct gfs2_sbd *sdp)convert_bitmaps (sdp, rgd);for (x =0 ; x < rgd->ri.ri_length; x++) {if (x) -gfs2_meta_header_out (&mh, rgd->bh[x]); +gfs2_meta_header_out_bh (&mh, rgd->bh[x]);else -gfs2_rgrp_out (&rgd->rg, rgd->bh[x]); +gfs2_rgrp_out_bh (&rgd->rg, rgd->bh[x]); } }/* for each journal */ return error;
gfs2/edit/hexedit.c +2 -2
@@ -1106,7 +1106,7 @@ static void set_rgrp_flags(int rgnum, uint32_t new_flags, int modify, int full)if (sbd.gfs1)gfs_rgrp_out (&rg.rg1, rbh);else -gfs2_rgrp_out (&rg.rg2, rbh); +gfs2_rgrp_out_bh (&rg.rg2, rbh);brelse (rbh); }else {if (full) {
@@ -2125,7 +2125,7 @@ static void process_field(const char *field, const char *nstr)gfs2_rgrp_in (&rg, rbh);if (setval) {gfs2_rgrp_assignval (&rg, field, newval); -gfs2_rgrp_out (&rg, rbh); +gfs2_rgrp_out_bh (&rg, rbh);if (!termlines)gfs2_rgrp_printval (&rg, field); }else {
gfs2/fsck/initialize.c +2 -2
@@ -314,7 +314,7 @@ static void check_rgrp_integrity(struct gfs2_sbd *sdp, struct rgrp_tree *rgd,if (sdp->gfs1)gfs_rgrp_out ((struct gfs_rgrp *)&rgd->rg, rgd->bh[0 ]);else -gfs2_rgrp_out (&rgd->rg, rgd->bh[0 ]); +gfs2_rgrp_out_bh (&rgd->rg, rgd->bh[0 ]); *this_rg_cleaned =1 ; log_info( _("The rgrp at %lld (0x%llx) was cleaned of %d " "free metadata blocks.\n"),
@@ -336,7 +336,7 @@ static void check_rgrp_integrity(struct gfs2_sbd *sdp, struct rgrp_tree *rgd,gfs_rgrp_out ((struct gfs_rgrp *)&rgd->rg, rgd->bh[0 ]); else - gfs2_rgrp_out(&rgd->rg, rgd->bh[0]); + gfs2_rgrp_out_bh(&rgd->rg, rgd->bh[0]); *this_rg_fixed =1 ;log_err (_ ("The rgrp was fixed.\n" )); }else
gfs2/fsck/metawalk.c +2 -2
@@ -83,14 +83,14 @@ int check_n_fix_bitmap(struct gfs2_sbd *sdp, uint64_t blk,gfs_rgrp_out ((struct gfs_rgrp *) &rgd->rg, rgd->bh[0 ]); else - gfs2_rgrp_out(&rgd->rg, rgd->bh[0]); + gfs2_rgrp_out_bh(&rgd->rg, rgd->bh[0]); }else if (old_bitmap_state ==GFS2_BLKST_FREE ) { rgd->rg.rg_free--;if (sdp->gfs1)gfs_rgrp_out ((struct gfs_rgrp *) &rgd->rg, rgd->bh[0 ]);else -gfs2_rgrp_out (&rgd->rg, rgd->bh[0 ]); +gfs2_rgrp_out_bh (&rgd->rg, rgd->bh[0 ]); }log_err (_ ("The bitmap was fixed.\n" )); }else {
gfs2/fsck/pass5.c +1 -1
@@ -274,7 +274,7 @@ static void update_rgrp(struct gfs2_sbd *sdp, struct rgrp_tree *rgp,if (sdp->gfs1)gfs_rgrp_out (gfs1rg, rgp->bh[0 ]);else -gfs2_rgrp_out (&rgp->rg, rgp->bh[0 ]); +gfs2_rgrp_out_bh (&rgp->rg, rgp->bh[0 ]); }else log_err (_ ("Resource group counts left inconsistent\n" )); }
gfs2/fsck/rgrepair.c +2 -2
@@ -684,7 +684,7 @@ static int rewrite_rg_block(struct gfs2_sbd *sdp, struct rgrp_tree *rg, mh.mh_magic =GFS2_MAGIC ; mh.mh_type =GFS2_METATYPE_RB ; mh.mh_format =GFS2_FORMAT_RB ; -gfs2_meta_header_out (&mh, rg->bh[x]); +gfs2_meta_header_out_bh (&mh, rg->bh[x]); }else {if (sdp->gfs1)memset (&rg->rg,0 ,sizeof (struct gfs_rgrp ));
@@ -698,7 +698,7 @@ static int rewrite_rg_block(struct gfs2_sbd *sdp, struct rgrp_tree *rg,gfs_rgrp_out ((struct gfs_rgrp *)&rg->rg, rg->bh[x]); else - gfs2_rgrp_out(&rg->rg, rg->bh[x]); + gfs2_rgrp_out_bh(&rg->rg, rg->bh[x]); }brelse (rg->bh[x]); rg->bh[x] =NULL ;
gfs2/libgfs2/fs_geometry.c +2 -2
@@ -217,9 +217,9 @@ void build_rgrps(struct gfs2_sbd *sdp, int do_write)for (x =0 ; x < bitblocks; x++) { rl->bh[x] =bget (sdp, rl->start + x);if (x) -gfs2_meta_header_out (&mh, rl->bh[x]); +gfs2_meta_header_out_bh (&mh, rl->bh[x]);else -gfs2_rgrp_out (&rl->rg, rl->bh[x]); +gfs2_rgrp_out_bh (&rl->rg, rl->bh[x]); } }
gfs2/libgfs2/fs_ops.c +10 -10
@@ -182,7 +182,7 @@ found:if (sdp->gfs1)gfs_rgrp_out ((struct gfs_rgrp *)rg, rl->bh[0 ]);else -gfs2_rgrp_out (rg, rl->bh[0 ]); +gfs2_rgrp_out_bh (rg, rl->bh[0 ]); sdp->blks_alloced++; *blkno = ri->ri_data0 + bn;
@@ -294,7 +294,7 @@ void unstuff_dinode(struct gfs2_inode *ip) mh.mh_magic =GFS2_MAGIC ; mh.mh_type =GFS2_METATYPE_JD ; mh.mh_format =GFS2_FORMAT_JD ; -gfs2_meta_header_out (&mh, bh); +gfs2_meta_header_out_bh (&mh, bh); buffer_copy_tail(sdp, bh, sizeof(struct gfs2_meta_header),
@@ -371,7 +371,7 @@ void build_height(struct gfs2_inode *ip, int height) mh.mh_magic =GFS2_MAGIC ; mh.mh_type =GFS2_METATYPE_IN ; mh.mh_format =GFS2_FORMAT_IN ; -gfs2_meta_header_out (&mh, bh); +gfs2_meta_header_out_bh (&mh, bh);buffer_copy_tail (sdp, bh,sizeof (struct gfs2_meta_header ), ip->i_bh,sizeof (struct gfs2_dinode ));
@@ -494,7 +494,7 @@ void block_map(struct gfs2_inode *ip, uint64_t lblock, int *new, mh.mh_magic =GFS2_MAGIC ; mh.mh_type =GFS2_METATYPE_IN ; mh.mh_format =GFS2_FORMAT_IN ; -gfs2_meta_header_out (&mh, bh); +gfs2_meta_header_out_bh (&mh, bh); }else {if (*dblock == ip->i_di.di_num.no_addr) bh = ip->i_bh;
@@ -688,7 +688,7 @@ int __gfs2_writei(struct gfs2_inode *ip, void *buf, mh.mh_magic =GFS2_MAGIC ; mh.mh_type =GFS2_METATYPE_JD ; mh.mh_format =GFS2_FORMAT_JD ; -gfs2_meta_header_out (&mh, bh); +gfs2_meta_header_out_bh (&mh, bh); } }else {if (dblock == ip->i_di.di_num.no_addr)
@@ -935,7 +935,7 @@ static void dir_split_leaf(struct gfs2_inode *dip, uint32_t lindex, mh.mh_magic =GFS2_MAGIC ; mh.mh_type =GFS2_METATYPE_LF ; mh.mh_format =GFS2_FORMAT_LF ; -gfs2_meta_header_out (&mh, nbh); +gfs2_meta_header_out_bh (&mh, nbh);buffer_clear_tail (dip->i_sbd, nbh,sizeof (struct gfs2_meta_header )); }
@@ -1197,7 +1197,7 @@ restart: mh.mh_magic =GFS2_MAGIC ; mh.mh_type =GFS2_METATYPE_LF ; mh.mh_format =GFS2_FORMAT_LF ; -gfs2_meta_header_out (&mh, nbh); +gfs2_meta_header_out_bh (&mh, nbh); leaf->lf_next =cpu_to_be64 (bn);
@@ -1248,7 +1248,7 @@ static void dir_make_exhash(struct gfs2_inode *dip) mh.mh_magic =GFS2_MAGIC ; mh.mh_type =GFS2_METATYPE_LF ; mh.mh_format =GFS2_FORMAT_LF ; -gfs2_meta_header_out (&mh, bh); +gfs2_meta_header_out_bh (&mh, bh); } leaf = (struct gfs2_leaf *)bh->b_data;
@@ -1821,7 +1821,7 @@ void gfs2_free_block(struct gfs2_sbd *sdp, uint64_t block)if (sdp->gfs1)gfs_rgrp_out ((struct gfs_rgrp *)&rgd->rg, rgd->bh[0 ]);else -gfs2_rgrp_out (&rgd->rg, rgd->bh[0 ]); +gfs2_rgrp_out_bh (&rgd->rg, rgd->bh[0 ]); sdp->blks_alloced--; } }
@@ -1892,7 +1892,7 @@ int gfs2_freedi(struct gfs2_sbd *sdp, uint64_t diblock)if (sdp->gfs1)gfs_rgrp_out ((struct gfs_rgrp *)&rgd->rg, rgd->bh[0 ]);else -gfs2_rgrp_out (&rgd->rg, rgd->bh[0 ]); +gfs2_rgrp_out_bh (&rgd->rg, rgd->bh[0 ]); sdp->dinodes_alloced--;return 0 ; }
gfs2/libgfs2/gfs1.c +3 -3
@@ -126,7 +126,7 @@ void gfs1_block_map(struct gfs2_inode *ip, uint64_t lblock, int *new, mh.mh_magic =GFS2_MAGIC ; mh.mh_type =GFS2_METATYPE_IN ; mh.mh_format =GFS2_FORMAT_IN ; -gfs2_meta_header_out (&mh, bh); +gfs2_meta_header_out_bh (&mh, bh); }else {if (*dblock == ip->i_di.di_num.no_addr) bh = ip->i_bh;
@@ -225,7 +225,7 @@ int gfs1_writei(struct gfs2_inode *ip, char *buf, uint64_t offset, mh.mh_magic =GFS2_MAGIC ; mh.mh_type =GFS2_METATYPE_JD ; mh.mh_format =GFS2_FORMAT_JD ; -gfs2_meta_header_out (&mh, bh); +gfs2_meta_header_out_bh (&mh, bh); }memcpy (bh->b_data + offset, buf + copied, amount);
@@ -381,7 +381,7 @@ void gfs_rgrp_out(struct gfs_rgrp *rgrp, struct gfs2_buffer_head *rbh) {struct gfs_rgrp *str = (struct gfs_rgrp *)rbh->b_data; -gfs2_meta_header_out (&rgrp->rg_header, rbh); +gfs2_meta_header_out_bh (&rgrp->rg_header, rbh); str->rg_flags =cpu_to_be32 (rgrp->rg_flags); str->rg_free =cpu_to_be32 (rgrp->rg_free); str->rg_useddi =cpu_to_be32 (rgrp->rg_useddi);
gfs2/libgfs2/libgfs2.h +5 -3
@@ -785,14 +785,16 @@ 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_meta_header_in (struct gfs2_meta_header *mh,struct gfs2_buffer_head *bh); -extern void gfs2_meta_header_out (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_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); -extern void gfs2_rgrp_out (struct gfs2_rgrp *rg,struct gfs2_buffer_head *bh); +extern void gfs2_rgrp_out (const struct gfs2_rgrp *rg,char *buf); +extern void gfs2_rgrp_out_bh (const struct gfs2_rgrp *rg,struct gfs2_buffer_head *bh);extern void gfs2_quota_in (struct gfs2_quota *qu,char *buf);extern void gfs2_quota_out (struct gfs2_quota *qu,char *buf); extern void gfs2_dinode_in(struct gfs2_dinode *di,
gfs2/libgfs2/ondisk.c +21 -11
@@ -72,16 +72,21 @@ void gfs2_meta_header_in(struct gfs2_meta_header *mh,CPIN_32 (mh, str, mh_format); } -void gfs2_meta_header_out (struct gfs2_meta_header *mh, -struct gfs2_buffer_head *bh) +void gfs2_meta_header_out (const struct gfs2_meta_header *mh,char *buf) { -struct gfs2_meta_header *str = (struct gfs2_meta_header *)bh->b_data; +struct gfs2_meta_header *str = (struct gfs2_meta_header *)buf;CPOUT_32 (mh, str, mh_magic);CPOUT_32 (mh, str, mh_type);CPOUT_32 (mh, str, mh_format); str->__pad0 =0 ; str->__pad1 =0 ; +} + +void gfs2_meta_header_out_bh (const struct gfs2_meta_header *mh, +struct gfs2_buffer_head *bh) +{ +gfs2_meta_header_out (mh, bh->iov.iov_base);bmodified (bh); }
@@ -123,7 +128,7 @@ void gfs2_sb_out(struct gfs2_sb *sb, struct gfs2_buffer_head *bh) {struct gfs2_sb *str = (struct gfs2_sb *)bh->b_data; -gfs2_meta_header_out (&sb->sb_header, bh); +gfs2_meta_header_out_bh (&sb->sb_header, bh);CPOUT_32 (sb, str, sb_fs_format);CPOUT_32 (sb, str, sb_multihost_format);
@@ -243,16 +248,21 @@ void gfs2_rgrp_in(struct gfs2_rgrp *rg, struct gfs2_buffer_head *bh)CPIN_08 (rg, str, rg_reserved,80 ); } -void gfs2_rgrp_out (struct gfs2_rgrp *rg,struct gfs2_buffer_head *bh) +void gfs2_rgrp_out (const struct gfs2_rgrp *rg,char *buf) { -struct gfs2_rgrp *str = (struct gfs2_rgrp *)bh->b_data; +struct gfs2_rgrp *str = (struct gfs2_rgrp *)buf; -gfs2_meta_header_out (&rg->rg_header, bh); +gfs2_meta_header_out (&rg->rg_header, buf);CPOUT_32 (rg, str, rg_flags);CPOUT_32 (rg, str, rg_free);CPOUT_32 (rg, str, rg_dinodes);CPOUT_08 (rg, str, rg_reserved,80 ); +} + +void gfs2_rgrp_out_bh (const struct gfs2_rgrp *rg,struct gfs2_buffer_head *bh) +{ +gfs2_rgrp_out (rg, bh->iov.iov_base);bmodified (bh); }
@@ -330,7 +340,7 @@ void gfs2_dinode_out(struct gfs2_dinode *di, struct gfs2_buffer_head *bh) {struct gfs2_dinode *str = (struct gfs2_dinode *)bh->b_data; -gfs2_meta_header_out (&di->di_header, bh); +gfs2_meta_header_out_bh (&di->di_header, bh);gfs2_inum_out (&di->di_num, (char *)&str->di_num);CPOUT_32 (di, str, di_mode);
@@ -432,7 +442,7 @@ void gfs2_leaf_out(struct gfs2_leaf *lf, struct gfs2_buffer_head *bh) {struct gfs2_leaf *str = (struct gfs2_leaf *)bh->b_data; -gfs2_meta_header_out (&lf->lf_header, bh); +gfs2_meta_header_out_bh (&lf->lf_header, bh);CPOUT_16 (lf, str, lf_depth);CPOUT_16 (lf, str, lf_entries);CPOUT_32 (lf, str, lf_dirent_format);
@@ -497,7 +507,7 @@ void gfs2_log_header_out(struct gfs2_log_header *lh, {struct gfs2_log_header *str = (struct gfs2_log_header *)bh->b_data; -gfs2_meta_header_out (&lh->lh_header, bh); +gfs2_meta_header_out_bh (&lh->lh_header, bh);CPOUT_64 (lh, str, lh_sequence);CPOUT_32 (lh, str, lh_flags);CPOUT_32 (lh, str, lh_tail);
@@ -535,7 +545,7 @@ void gfs2_log_descriptor_out(struct gfs2_log_descriptor *ld, {struct gfs2_log_descriptor *str = (struct gfs2_log_descriptor *)bh->b_data; -gfs2_meta_header_out (&ld->ld_header, bh); +gfs2_meta_header_out_bh (&ld->ld_header, bh);CPOUT_32 (ld, str, ld_type);CPOUT_32 (ld, str, ld_length);CPOUT_32 (ld, str, ld_data1);
gfs2/libgfs2/structures.c +1 -1
@@ -256,7 +256,7 @@ static int build_quota_change(struct gfs2_inode *per_node, unsigned int j)return -1 ;memset (bh->b_data,0 , sdp->bsize); -gfs2_meta_header_out (&mh, bh); +gfs2_meta_header_out_bh (&mh, bh);brelse (bh); }
gfs2/mkfs/main_jadd.c +1 -1
@@ -342,7 +342,7 @@ add_qc(struct gfs2_sbd *sdp) mh.mh_magic =GFS2_MAGIC ; mh.mh_type =GFS2_METATYPE_QC ; mh.mh_format =GFS2_FORMAT_QC ; -gfs2_meta_header_out (&mh, &dummy_bh); +gfs2_meta_header_out_bh (&mh, &dummy_bh);for (x=0 ; x<blocks; x++) {if (write (fd, buf, sdp->bsize) != sdp->bsize) {
Signature · 1 line
1.8.1.2
PATCH 3/5 mkfs.gfs2: Reduce memory usage
In reply to Andrew PriceThis folds much of the resource group allocation and writing into two new functions so that we allocate memory for each entire header at once and free it once we're done with it.
Testing on a 50TB volume with default options, this brings the peak heap usage down from 3.03GB to 24MB while also reducing the run time slightly due to fewer writes and allocations.
There are still memory efficiency gains to be made here, notably we still use gfs2_compute_bitstructs which allocates bitmap buffers and an array of bh pointers for each rgrp.
--- gfs2/mkfs/main_mkfs.c | 110 ++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 94 insertions(+), 16 deletions(-)
gfs2/mkfs/main_mkfs.c +94 -16
@@ -567,6 +567,93 @@ static int is_symlink(char *path, char **abspath)return 1 ; } +static int writerg (int fd,const struct rgrp_tree *rgt,const unsigned bsize) +{ +ssize_t ret =0 ; +unsigned int i; +const struct gfs2_meta_header bmh = { + .mh_magic =GFS2_MAGIC , + .mh_type =GFS2_METATYPE_RB , + .mh_format =GFS2_FORMAT_RB , + }; +struct iovec iov = { + .iov_len = rgt->ri.ri_length * bsize, + .iov_base =calloc (rgt->ri.ri_length, bsize), + }; +if (iov.iov_base ==NULL ) +return -1 ; + +gfs2_rgrp_out (&rgt->rg, iov.iov_base); +for (i =1 ; i < rgt->ri.ri_length; i++) +gfs2_meta_header_out (&bmh, (char *)iov.iov_base + (i * bsize)); + + ret =pwritev (fd, &iov,1 , rgt->ri.ri_addr * bsize); +if (ret != iov.iov_len) { +free (iov.iov_base); +return -1 ; + } + +free (iov.iov_base); +return 0 ; +} + +static int place_rgrps (struct gfs2_sbd *sdp,int rgsize_specified) +{ +struct rgrp_tree *rgt =NULL ; +uint64_t rgaddr =0 ; +unsigned int i =0 ; +int err =0 ; + + sdp->device.length -= sdp->sb_addr +1 ; + sdp->new_rgrps =how_many_rgrps (sdp, &sdp->device, rgsize_specified); + rgaddr = sdp->sb_addr +1 ; + +for (i =0 ; i < sdp->new_rgrps; i++) { +/* TODO: align to RAID stripes, etc. */ + rgt =rgrp_insert (&sdp->rgtree, rgaddr); +if (rgt ==NULL ) +return -1 ; +if (i ==0 ) + rgt->length = sdp->device.length - ((sdp->new_rgrps -1 ) * (sdp->device.length / sdp->new_rgrps)); +else + rgt->length = sdp->device.length / sdp->new_rgrps; + +/* Build the rindex entry */ + rgt->ri.ri_length =rgblocks2bitblocks (sdp->bsize, rgt->length, &rgt->ri.ri_data); + rgt->ri.ri_addr = rgaddr; + rgt->ri.ri_data0 = rgaddr + rgt->ri.ri_length; + rgt->ri.ri_bitbytes = rgt->ri.ri_data /GFS2_NBBY ; + +/* Build the rgrp header */ +memset (&rgt->rg,0 ,sizeof (rgt->rg)); + rgt->rg.rg_header.mh_magic =GFS2_MAGIC ; + rgt->rg.rg_header.mh_type =GFS2_METATYPE_RG ; + rgt->rg.rg_header.mh_format =GFS2_FORMAT_RG ; + rgt->rg.rg_free = rgt->ri.ri_data; + +/* TODO: This call allocates buffer heads and bitmap pointers +* in rgt. We really shouldn't need to do that. */ + err =gfs2_compute_bitstructs (sdp, rgt); +if (err !=0 ) { +fprintf (stderr,_ ("Could not compute bitmaps. " +"Check resource group and block size options.\n" )); +return -1 ; + } + + err =writerg (sdp->device_fd, rgt, sdp->bsize); +if (err !=0 ) { +perror (_ ("Failed to write resource group" )); +return -1 ; + } + sdp->blks_total += rgt->ri.ri_data; + rgaddr += rgt->length; + } + + sdp->rgrps = sdp->new_rgrps; + sdp->fssize = rgt->ri.ri_data0 + rgt->ri.ri_data; +return 0 ; +} +/** * main_mkfs - do everything * @argc:
@@ -668,20 +755,13 @@ void main_mkfs(int argc, char *argv[])if (!S_ISREG (sdp->dinfo.stat.st_mode) && discard)discard_blocks (sdp); -/* Compute the resource group layouts */ - -compute_rgrp_layout (sdp, &sdp->rgtree, rgsize_specified); -debug_print_rgrps (sdp, &sdp->rgtree); - -/* Generate a random uuid */ -get_random_bytes (uuid,sizeof (uuid)); - -/* Build ondisk structures */ - -build_rgrps (sdp, TRUE); + error =place_rgrps (sdp, rgsize_specified); +if (error) { +fprintf (stderr,_ ("Failed to build resource groups\n" )); +exit (1 ); + }build_root (sdp);build_master (sdp); -build_sb (sdp, uuid); error =build_jindex (sdp);if (error) {fprintf (stderr,_ ("Error building '%s': %s\n" ),"jindex" ,strerror (errno));
@@ -714,12 +794,12 @@ 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 (sdp, uuid);do_init_inum (sdp);do_init_statfs (sdp); -/* Cleanup */ -inode_put (&sdp->md.rooti);inode_put (&sdp->master_dir);inode_put (&sdp->md.inum);
@@ -727,14 +807,12 @@ void main_mkfs(int argc, char *argv[])gfs2_rgrp_free (&sdp->rgtree); error =fsync (sdp->device_fd); -if (error){perror (sdp->device_name);exit (EXIT_FAILURE ); } error =close (sdp->device_fd); -if (error){perror (sdp->device_name);exit (EXIT_FAILURE );
Signature · 1 line
1.8.1.2
PATCH 4/5 gfs2-utils: Make the tool tests script more useful
In reply to Andrew PriceThis makes the tool test script log command output to a file and only remove the test file (now named testvol by default) on success so that we can analyze it on failure.
Also adds some tests to create and check file systems with various resource group sizes.
--- .gitignore | 2 ++ tests/tool_tests.sh | 28 +++++++++++++++++++--------- 2 files changed, 21 insertions(+), 9 deletions(-)
.gitignore +2 -0
@@ -41,6 +41,8 @@ gfs2/fsck/fsck.gfs2 gfs2/mkfs/mkfs.gfs2 gfs2/tune/tunegfs2 tests/check_libgfs2 +tests/testvol +tests/tests.log group/gfs_control/gfs_control group/gfs_controld/gfs_controld ABOUT-NLS
tests/tool_tests.sh +19 -9
@@ -11,7 +11,10 @@ MKFS="${TOPBUILDDIR}/gfs2/mkfs/mkfs.gfs2 -qO" FSCK="${TOPBUILDDIR}/gfs2/fsck/fsck.gfs2 -qn" # Name of the sparse file we'll use for testing -TEST_TARGET=${TEST_TARGET:-test_sparse} +TEST_TARGET=${TEST_TARGET:-testvol} +# Log of test output +TEST_LOG=${TEST_LOG:-tests.log} +truncate -cs0 "${TEST_LOG}" # Size, in GB, of the sparse file we'll create to run the tests TEST_TARGET_SZ=${TEST_TARGET_SZ:-10} [ $TEST_TARGET_SZ -gt 0 ] || { echo "Target size (in GB) must be greater than 0" >&2; exit 1; }
@@ -22,17 +25,17 @@ fn_test() { local expected="$1" local cmd="$2" - echo -n "Running '$cmd' - (Exp: $expected Got: " - $cmd &> /dev/null; + echo -n "** Test '$cmd'" | tee -a "${TEST_LOG}" + $cmd &>> "${TEST_LOG}"; local ret=$? - echo -n "$ret) " + echo -n " (exp: $expected got: $ret) " | tee -a "${TEST_LOG}" if [ "$ret" != "$expected" ]; then - echo "FAIL" + echo "FAIL" | tee -a "${TEST_LOG}" TEST_RET=1 TEST_GRP_RET=1 else - echo "PASS" + echo "PASS" | tee -a "${TEST_LOG}" fi }
@@ -44,7 +47,7 @@ fn_rm_target() fn_recreate_target() { fn_rm_target - fn_test 0 "dd if=/dev/null of=$TEST_TARGET bs=1 count=0 seek=${TEST_TARGET_SZ}G" + fn_test 0 "truncate -s ${TEST_TARGET_SZ}G ${TEST_TARGET}" }
@@ -54,9 +57,16 @@ fn_test 0 "$MKFS -p lock_nolock $TEST_TARGET" fn_test 0 "$MKFS -p lock_dlm -t foo:bar $TEST_TARGET" fn_test 255 "$MKFS -p badprotocol $TEST_TARGET" fn_test 0 "$FSCK $TEST_TARGET" +fn_test 255 "$MKFS -p lock_nolock -r 31 $TEST_TARGET" +fn_test 255 "$MKFS -p lock_nolock -r 2049 $TEST_TARGET" +fn_test 0 "$MKFS -p lock_nolock -r 32 $TEST_TARGET" +fn_test 0 "$FSCK $TEST_TARGET" +fn_test 0 "$MKFS -p lock_nolock -r 2048 $TEST_TARGET" +fn_test 0 "$FSCK $TEST_TARGET" # Tests end here -# Clean up -fn_test 0 "rm -f $TEST_TARGET" +# Only remove the test file on success +[ "$TEST_RET" = "0" ] && fn_test 0 "rm -f $TEST_TARGET" +echo "Tool test output written to ${TEST_LOG}" exit $TEST_RET
Signature · 1 line
1.8.1.2
PATCH 5/5 mkfs.gfs2: Separate user options from file system params
In reply to Andrew PricePreviously the user-supplied options were tangled up with the calculated file system parameters in the gfs2_sbd. This patch adds a mkfs_opts structure to create a separation between the two and rearranges the code to make that separation more apparent. It also adds some more tool tests to be run with 'make check' and removes the now-unneeded orig_fssize field from the gfs2_sbd definition.
--- gfs2/libgfs2/libgfs2.h | 1 - gfs2/mkfs/main_mkfs.c | 493 ++++++++++++++++++++++--------------------------- tests/tool_tests.sh | 30 ++- 3 files changed, 249 insertions(+), 275 deletions(-)
gfs2/libgfs2/libgfs2.h +0 -1
@@ -295,7 +295,6 @@ struct gfs2_sbd {uint64_t sb_addr; -uint64_t orig_fssize;uint64_t fssize;uint64_t blks_total;uint64_t blks_alloced;
gfs2/mkfs/main_mkfs.c +223 -270
730 lines not on this page · raw message
tests/tool_tests.sh +26 -4
@@ -5,10 +5,10 @@ # of the whole script will be non-zero but the tests will continue to be run. The # sparse file which is used as the target of the tests can be configured by # setting the environment variables TEST_TARGET (the filename) and TEST_TARGET_SZ -# (its apparent size in gigabytes). Defaults to "test_sparse" and 10GB. +# (its apparent size in gigabytes). Defaults to "testvol" and 10GB. -MKFS="${TOPBUILDDIR}/gfs2/mkfs/mkfs.gfs2 -qO" -FSCK="${TOPBUILDDIR}/gfs2/fsck/fsck.gfs2 -qn" +MKFS="${TOPBUILDDIR}/gfs2/mkfs/mkfs.gfs2 -O" +FSCK="${TOPBUILDDIR}/gfs2/fsck/fsck.gfs2 -n" # Name of the sparse file we'll use for testing TEST_TARGET=${TEST_TARGET:-testvol}
@@ -50,19 +50,41 @@ fn_recreate_target() fn_test 0 "truncate -s ${TEST_TARGET_SZ}G ${TEST_TARGET}" } +util_max_blocks() +{ + printf $((TEST_TARGET_SZ*1073741824/$1)) +} # Tests start here fn_recreate_target fn_test 0 "$MKFS -p lock_nolock $TEST_TARGET" fn_test 0 "$MKFS -p lock_dlm -t foo:bar $TEST_TARGET" -fn_test 255 "$MKFS -p badprotocol $TEST_TARGET" fn_test 0 "$FSCK $TEST_TARGET" +fn_test 255 "$MKFS -p badprotocol $TEST_TARGET" fn_test 255 "$MKFS -p lock_nolock -r 31 $TEST_TARGET" fn_test 255 "$MKFS -p lock_nolock -r 2049 $TEST_TARGET" fn_test 0 "$MKFS -p lock_nolock -r 32 $TEST_TARGET" fn_test 0 "$FSCK $TEST_TARGET" fn_test 0 "$MKFS -p lock_nolock -r 2048 $TEST_TARGET" fn_test 0 "$FSCK $TEST_TARGET" +fn_test 255 "$MKFS -p lock_nolock -b 512 $TEST_TARGET $(($(util_max_blocks 512)+1))" +fn_test 255 "$MKFS -p lock_nolock -b 4096 $TEST_TARGET $(($(util_max_blocks 4096)+1))" +fn_test 0 "$MKFS -p lock_nolock -b 512 $TEST_TARGET $(util_max_blocks 512)" +fn_test 0 "$FSCK $TEST_TARGET" +fn_test 0 "$MKFS -p lock_nolock -b 4096 $TEST_TARGET $(util_max_blocks 4096)" +fn_test 0 "$FSCK $TEST_TARGET" +fn_test 255 "$MKFS -p lock_nolock -J 7 $TEST_TARGET" +fn_test 255 "$MKFS -p lock_nolock -J 1025 $TEST_TARGET" +fn_test 0 "$MKFS -p lock_nolock -J 1024 $TEST_TARGET" +fn_test 0 "$FSCK $TEST_TARGET" +fn_test 0 "$MKFS -p lock_nolock -J 8 $TEST_TARGET" +fn_test 0 "$FSCK $TEST_TARGET" +fn_test 255 "$MKFS -p lock_nolock -c 0 $TEST_TARGET" +fn_test 255 "$MKFS -p lock_nolock -c 65 $TEST_TARGET" +fn_test 0 "$MKFS -p lock_nolock -c 1 $TEST_TARGET" +fn_test 0 "$FSCK $TEST_TARGET" +fn_test 0 "$MKFS -p lock_nolock -c 64 $TEST_TARGET" +fn_test 0 "$FSCK $TEST_TARGET" # Tests end here
Signature · 1 line
1.8.1.2