This is an automated email from the git hooks/post-receive script.
andyp pushed a commit to branch andyp-fsck_cx in repository gfs2-utils.
commit fedc173c33315aefa1a04c8f246af9231c1d6992 Author: Andrew Price anprice@redhat.com AuthorDate: Fri Jul 29 12:28:14 2022 +0100
fsck.gfs2: Introduce struct fsck_cx
Add a fsck-specific context structure so that we can pass around more context than the general lgfs2_sbd structure, without overloading the libgfs2 structure with fsck-specific fields. Use it in the pass functions to begin with.
Signed-off-by: Andrew Price anprice@redhat.com --- gfs2/fsck/fsck.h | 18 +++++++++++------- gfs2/fsck/main.c | 53 ++++++++++++++++++++++++++++------------------------- gfs2/fsck/pass1.c | 5 +++-- gfs2/fsck/pass1b.c | 3 ++- gfs2/fsck/pass2.c | 3 ++- gfs2/fsck/pass3.c | 3 ++- gfs2/fsck/pass4.c | 4 +++- gfs2/fsck/pass5.c | 3 ++- gfs2/fsck/util.h | 2 +- 9 files changed, 54 insertions(+), 40 deletions(-)
diff --git a/gfs2/fsck/fsck.h b/gfs2/fsck/fsck.h index 94b8620c..d4be11e4 100644 --- a/gfs2/fsck/fsck.h +++ b/gfs2/fsck/fsck.h @@ -108,6 +108,10 @@ enum rgindex_trust_level { /* how far can we trust our RG index? */ must have been converted from gfs2_convert. */ };
+struct fsck_cx { + struct lgfs2_sbd *sdp; +}; + extern struct lgfs2_inode *fsck_load_inode(struct lgfs2_sbd *sdp, uint64_t block); extern struct lgfs2_inode *fsck_inode_get(struct lgfs2_sbd *sdp, struct lgfs2_rgrp_tree *rgd, @@ -117,13 +121,13 @@ extern void fsck_inode_put(struct lgfs2_inode **ip); extern int initialize(struct lgfs2_sbd *sdp, int force_check, int preen, int *all_clean); extern void destroy(struct lgfs2_sbd *sdp); -extern int pass1(struct lgfs2_sbd *sdp); -extern int pass1b(struct lgfs2_sbd *sdp); -extern int pass1c(struct lgfs2_sbd *sdp); -extern int pass2(struct lgfs2_sbd *sdp); -extern int pass3(struct lgfs2_sbd *sdp); -extern int pass4(struct lgfs2_sbd *sdp); -extern int pass5(struct lgfs2_sbd *sdp, struct gfs2_bmap *bl); +extern int pass1(struct fsck_cx *cx); +extern int pass1b(struct fsck_cx *cx); +extern int pass1c(struct fsck_cx *cx); +extern int pass2(struct fsck_cx *cx); +extern int pass3(struct fsck_cx *cx); +extern int pass4(struct fsck_cx *cx); +extern int pass5(struct fsck_cx *cx, struct gfs2_bmap *bl); extern int rindex_repair(struct lgfs2_sbd *sdp, int trust_lvl, int *ok); extern int fsck_query(const char *format, ...) __attribute__((format(printf,1,2))); diff --git a/gfs2/fsck/main.c b/gfs2/fsck/main.c index ed6b068f..7eb45c63 100644 --- a/gfs2/fsck/main.c +++ b/gfs2/fsck/main.c @@ -152,11 +152,12 @@ static void interrupt(int sig) } }
-static int check_statfs(struct lgfs2_sbd *sdp) +static int check_statfs(struct fsck_cx *cx) { struct osi_node *n, *next = NULL; struct lgfs2_rgrp_tree *rgd; struct gfs2_statfs_change sc; + struct lgfs2_sbd *sdp = cx->sdp; uint64_t sc_total; uint64_t sc_free; uint64_t sc_dinodes; @@ -233,7 +234,7 @@ static const struct fsck_pass passes[] = { { .name = NULL, } };
-static int fsck_pass(const struct fsck_pass *p, struct lgfs2_sbd *sdp) +static int fsck_pass(const struct fsck_pass *p, struct fsck_cx *cx) { int ret; struct timeval timer; @@ -245,7 +246,7 @@ static int fsck_pass(const struct fsck_pass *p, struct lgfs2_sbd *sdp) log_notice( _("Starting %s\n"), p->name); gettimeofday(&timer, NULL);
- ret = p->f(sdp); + ret = p->f(cx); if (ret) exit(ret); if (skip_this_pass || fsck_abort) { @@ -303,7 +304,9 @@ static void startlog(int argc, char **argv) int main(int argc, char **argv) { struct lgfs2_sbd sb; - struct lgfs2_sbd *sdp = &sb; + struct fsck_cx cx = { + .sdp = &sb + }; int j; int i; int error = 0; @@ -321,51 +324,51 @@ int main(int argc, char **argv) atexit(exitlog); #endif
- memset(sdp, 0, sizeof(*sdp)); + memset(&sb, 0, sizeof(sb));
if ((error = read_cmdline(argc, argv, &opts))) exit(error); setbuf(stdout, NULL); log_notice( _("Initializing fsck\n")); - if ((error = initialize(sdp, force_check, preen, &all_clean))) + if ((error = initialize(&sb, force_check, preen, &all_clean))) exit(error);
if (!force_check && all_clean && preen) { log_err( _("%s: clean.\n"), opts.device); - destroy(sdp); + destroy(&sb); exit(FSCK_OK); }
sigaction(SIGINT, &act, NULL);
for (i = 0; passes[i].name; i++) - error = fsck_pass(passes + i, sdp); + error = fsck_pass(passes + i, &cx);
/* Free up our system inodes */ - if (!sdp->gfs1) - lgfs2_inode_put(&sdp->md.inum); - lgfs2_inode_put(&sdp->md.statfs); - for (j = 0; j < sdp->md.journals; j++) - lgfs2_inode_put(&sdp->md.journal[j]); - free(sdp->md.journal); - sdp->md.journal = NULL; - lgfs2_inode_put(&sdp->md.jiinode); - lgfs2_inode_put(&sdp->md.riinode); - lgfs2_inode_put(&sdp->md.qinode); - if (!sdp->gfs1) - lgfs2_inode_put(&sdp->md.pinode); - lgfs2_inode_put(&sdp->md.rooti); - if (!sdp->gfs1) - lgfs2_inode_put(&sdp->master_dir); + if (!sb.gfs1) + lgfs2_inode_put(&sb.md.inum); + lgfs2_inode_put(&sb.md.statfs); + for (j = 0; j < sb.md.journals; j++) + lgfs2_inode_put(&sb.md.journal[j]); + free(sb.md.journal); + sb.md.journal = NULL; + lgfs2_inode_put(&sb.md.jiinode); + lgfs2_inode_put(&sb.md.riinode); + lgfs2_inode_put(&sb.md.qinode); + if (!sb.gfs1) + lgfs2_inode_put(&sb.md.pinode); + lgfs2_inode_put(&sb.md.rooti); + if (!sb.gfs1) + lgfs2_inode_put(&sb.master_dir); if (lf_dip) lgfs2_inode_put(&lf_dip);
if (!opts.no && errors_corrected) log_notice( _("Writing changes to disk\n")); - fsync(sdp->device_fd); + fsync(sb.device_fd); link1_destroy(&nlink1map); link1_destroy(&clink1map); - destroy(sdp); + destroy(&sb); if (sb_fixed) log_warn(_("Superblock was reset. Use tunegfs2 to manually " "set lock table before mounting.\n")); diff --git a/gfs2/fsck/pass1.c b/gfs2/fsck/pass1.c index 1ee10795..a7dc442e 100644 --- a/gfs2/fsck/pass1.c +++ b/gfs2/fsck/pass1.c @@ -1948,8 +1948,9 @@ static void enomem(uint64_t addl_mem_needed) * inodes size * dir info */ -int pass1(struct lgfs2_sbd *sdp) +int pass1(struct fsck_cx *cx) { + struct lgfs2_sbd *sdp = cx->sdp; struct osi_node *n, *next = NULL; struct lgfs2_rgrp_tree *rgd; uint64_t i; @@ -2025,7 +2026,7 @@ int pass1(struct lgfs2_sbd *sdp) } log_notice(_("Reconciling bitmaps.\n")); gettimeofday(&timer, NULL); - pass5(sdp, bl); + pass5(cx, bl); print_pass_duration("reconcile_bitmaps", &timer); out: gfs2_special_free(&gfs1_rindex_blks); diff --git a/gfs2/fsck/pass1b.c b/gfs2/fsck/pass1b.c index d1e1050a..76c01fb3 100644 --- a/gfs2/fsck/pass1b.c +++ b/gfs2/fsck/pass1b.c @@ -857,8 +857,9 @@ out: /* Pass 1b handles finding the previous inode for a duplicate block * When found, store the inodes pointing to the duplicate block for * use in pass2 */ -int pass1b(struct lgfs2_sbd *sdp) +int pass1b(struct fsck_cx *cx) { + struct lgfs2_sbd *sdp = cx->sdp; struct duptree *dt; uint64_t i; int q; diff --git a/gfs2/fsck/pass2.c b/gfs2/fsck/pass2.c index 25da1091..62f84516 100644 --- a/gfs2/fsck/pass2.c +++ b/gfs2/fsck/pass2.c @@ -2106,8 +2106,9 @@ static int pass2_check_dir(struct lgfs2_sbd *sdp, struct lgfs2_inode *ip) * directory name length * entries in range */ -int pass2(struct lgfs2_sbd *sdp) +int pass2(struct fsck_cx *cx) { + struct lgfs2_sbd *sdp = cx->sdp; struct osi_node *tmp, *next = NULL; struct lgfs2_inode *ip; struct dir_info *dt; diff --git a/gfs2/fsck/pass3.c b/gfs2/fsck/pass3.c index 4fa826e7..94d91d19 100644 --- a/gfs2/fsck/pass3.c +++ b/gfs2/fsck/pass3.c @@ -156,8 +156,9 @@ out: * handle disconnected directories * handle lost+found directory errors (missing, not a directory, no space) */ -int pass3(struct lgfs2_sbd *sdp) +int pass3(struct fsck_cx *cx) { + struct lgfs2_sbd *sdp = cx->sdp; struct osi_node *tmp, *next = NULL; struct dir_info *di, *tdi; struct lgfs2_inode *ip; diff --git a/gfs2/fsck/pass4.c b/gfs2/fsck/pass4.c index 651c7752..5862ca0f 100644 --- a/gfs2/fsck/pass4.c +++ b/gfs2/fsck/pass4.c @@ -262,8 +262,10 @@ static int scan_nlink1_list(struct lgfs2_sbd *sdp) * handle unreferenced inodes of other types * handle bad blocks */ -int pass4(struct lgfs2_sbd *sdp) +int pass4(struct fsck_cx *cx) { + struct lgfs2_sbd *sdp = cx->sdp; + if (lf_dip) log_debug( _("At beginning of pass4, lost+found entries is %u\n"), lf_dip->i_entries); diff --git a/gfs2/fsck/pass5.c b/gfs2/fsck/pass5.c index e412a4d0..e464fdff 100644 --- a/gfs2/fsck/pass5.c +++ b/gfs2/fsck/pass5.c @@ -194,8 +194,9 @@ static void update_rgrp(struct lgfs2_sbd *sdp, struct lgfs2_rgrp_tree *rgp, * fix free block maps * fix used inode maps */ -int pass5(struct lgfs2_sbd *sdp, struct gfs2_bmap *bl) +int pass5(struct fsck_cx *cx, struct gfs2_bmap *bl) { + struct lgfs2_sbd *sdp = cx->sdp; struct osi_node *n, *next = NULL; struct lgfs2_rgrp_tree *rgp = NULL; uint32_t count[5]; /* we need 5 because of GFS1 usedmeta */ diff --git a/gfs2/fsck/util.h b/gfs2/fsck/util.h index daef0b86..f63a8af1 100644 --- a/gfs2/fsck/util.h +++ b/gfs2/fsck/util.h @@ -29,7 +29,7 @@ extern const char *reftypes[REF_TYPES + 1];
struct fsck_pass { const char *name; - int (*f)(struct lgfs2_sbd *sdp); + int (*f)(struct fsck_cx *cx); };
static inline int block_type(struct gfs2_bmap *bl, uint64_t bblock)