This is an automated email from the git hooks/post-receive script.
andyp pushed a commit to branch master in repository gfs2-utils.
commit 56d329d5b95070bfc07d3fad7a3b3367518f46fc Author: Andrew Price anprice@redhat.com AuthorDate: Wed Jun 9 16:17:51 2021 +0100
libgfs2: Endianness improvements for gfs2_leaf
Introduce a lgfs2_leaf native-endian struct and convert the gfs2_leaf_{in,out} functions to work with it.
Signed-off-by: Andrew Price anprice@redhat.com --- gfs2/fsck/metawalk.c | 16 +++++++++------- gfs2/fsck/metawalk.h | 2 +- gfs2/fsck/pass2.c | 10 +++++----- gfs2/libgfs2/libgfs2.h | 15 +++++++++++++-- gfs2/libgfs2/ondisk.c | 48 ++++++++++++++++++++++-------------------------- 5 files changed, 50 insertions(+), 41 deletions(-)
diff --git a/gfs2/fsck/metawalk.c b/gfs2/fsck/metawalk.c index d915b085..7b5bd873 100644 --- a/gfs2/fsck/metawalk.c +++ b/gfs2/fsck/metawalk.c @@ -515,10 +515,11 @@ static int check_entries(struct gfs2_inode *ip, struct gfs2_buffer_head *bh, * Leaves the buffer around for further analysis (caller must brelse) */ int check_leaf(struct gfs2_inode *ip, int lindex, struct metawalk_fxns *pass, - uint64_t *leaf_no, struct gfs2_leaf *leaf, int *ref_count) + uint64_t *leaf_no, struct lgfs2_leaf *leaf, int *ref_count) { int error = 0, fix; struct gfs2_buffer_head *lbh = NULL; + struct gfs2_leaf *lfp; uint32_t count = 0; struct gfs2_sbd *sdp = ip->i_sbd; const char *msg; @@ -560,18 +561,19 @@ int check_leaf(struct gfs2_inode *ip, int lindex, struct metawalk_fxns *pass, to use cpu_to_be32(), but we should check for incorrect values and replace them with the correct value. */
- gfs2_leaf_in(leaf, lbh->b_data); + lgfs2_leaf_in(leaf, lbh->b_data); if (leaf->lf_dirent_format == (GFS2_FORMAT_DE << 16)) { log_debug( _("incorrect lf_dirent_format at leaf #%" PRIu64 "\n"), *leaf_no); leaf->lf_dirent_format = GFS2_FORMAT_DE; - gfs2_leaf_out(leaf, lbh->b_data); + lgfs2_leaf_out(leaf, lbh->b_data); bmodified(lbh); log_debug( _("Fixing lf_dirent_format.\n")); }
+ lfp = (struct gfs2_leaf *)lbh->b_data; /* Make sure it's really a leaf. */ - if (leaf->lf_header.mh_type != GFS2_METATYPE_LF) { + if (be32_to_cpu(lfp->lf_header.mh_type) != GFS2_METATYPE_LF) { log_err(_("Inode %"PRIu64" (0x%"PRIx64") points to bad leaf %"PRIu64 " (0x%"PRIx64").\n"), ip->i_addr, ip->i_addr, *leaf_no, *leaf_no); @@ -598,7 +600,7 @@ int check_leaf(struct gfs2_inode *ip, int lindex, struct metawalk_fxns *pass, changed it. */ brelse(lbh); lbh = bread(sdp, *leaf_no); - gfs2_leaf_in(leaf, lbh->b_data); + lgfs2_leaf_in(leaf, lbh->b_data); if (count != leaf->lf_entries) { log_err(_("Leaf %"PRIu64" (0x%"PRIx64") entry count in " "directory %"PRIu64" (0x%"PRIx64") does not match " @@ -607,7 +609,7 @@ int check_leaf(struct gfs2_inode *ip, int lindex, struct metawalk_fxns *pass, leaf->lf_entries, count); if (query( _("Update leaf entry count? (y/n) "))) { leaf->lf_entries = count; - gfs2_leaf_out(leaf, lbh->b_data); + lgfs2_leaf_out(leaf, lbh->b_data); bmodified(lbh); log_warn( _("Leaf entry count updated\n")); } else @@ -789,7 +791,7 @@ int check_leaf_blks(struct gfs2_inode *ip, struct metawalk_fxns *pass)
chained_leaf = 0; do { - struct gfs2_leaf leaf; + struct lgfs2_leaf leaf; if (fsck_abort) { free(tbl); posix_fadvise(sdp->device_fd, 0, 0, POSIX_FADV_NORMAL); diff --git a/gfs2/fsck/metawalk.h b/gfs2/fsck/metawalk.h index f6c6bc31..a1038854 100644 --- a/gfs2/fsck/metawalk.h +++ b/gfs2/fsck/metawalk.h @@ -18,7 +18,7 @@ extern int check_linear_dir(struct gfs2_inode *ip, struct gfs2_buffer_head *bh, struct metawalk_fxns *pass); extern int check_leaf(struct gfs2_inode *ip, int lindex, struct metawalk_fxns *pass, uint64_t *leaf_no, - struct gfs2_leaf *leaf, int *ref_count); + struct lgfs2_leaf *leaf, int *ref_count); extern int _fsck_bitmap_set(struct gfs2_inode *ip, uint64_t bblock, const char *btype, int mark, int error_on_dinode, const char *caller, int line); diff --git a/gfs2/fsck/pass2.c b/gfs2/fsck/pass2.c index 137bf042..e06b45a3 100644 --- a/gfs2/fsck/pass2.c +++ b/gfs2/fsck/pass2.c @@ -1310,7 +1310,7 @@ static int fix_hashtable(struct gfs2_inode *ip, uint64_t *tbl, unsigned hsize, { struct gfs2_buffer_head *lbh; struct lgfs2_dirent dentry; - struct gfs2_leaf leaf; + struct lgfs2_leaf leaf; struct gfs2_dirent *de; int changes = 0, error, i, extras, hash_index; uint64_t new_leaf_blk; @@ -1421,7 +1421,7 @@ static int fix_hashtable(struct gfs2_inode *ip, uint64_t *tbl, unsigned hsize, new_leaf_blk = find_free_blk(ip->i_sbd); dir_split_leaf(ip, lindex, leafblk, lbh); /* re-read the leaf to pick up dir_split_leaf's changes */ - gfs2_leaf_in(&leaf, lbh->b_data); + lgfs2_leaf_in(&leaf, lbh->b_data); *proper_len = 1 << (ip->i_depth - leaf.lf_depth); log_err(_("Leaf block %llu (0x%llx) was split from length " "%d to %d\n"), (unsigned long long)leafblk, @@ -1608,7 +1608,7 @@ static int check_hash_tbl(struct gfs2_inode *ip, uint64_t *tbl, int error = 0; int lindex, len, proper_len, i, changes = 0; uint64_t leafblk; - struct gfs2_leaf leaf; + struct lgfs2_leaf leaf; struct gfs2_buffer_head *lbh; int factor; uint32_t proper_start; @@ -1713,7 +1713,7 @@ static int check_hash_tbl(struct gfs2_inode *ip, uint64_t *tbl, (unsigned long long)leafblk, proper_len, proper_len); lbh = bread(ip->i_sbd, leafblk); - gfs2_leaf_in(&leaf, lbh->b_data); + lgfs2_leaf_in(&leaf, lbh->b_data); if (gfs2_check_meta(lbh->b_data, GFS2_METATYPE_LF) || leaf.lf_depth > ip->i_depth) leaf.lf_depth = factor; @@ -1752,7 +1752,7 @@ static int check_hash_tbl(struct gfs2_inode *ip, uint64_t *tbl, /* Now we have to determine if the hash table is corrupt, or if the leaf has the wrong depth. */ lbh = bread(ip->i_sbd, leafblk); - gfs2_leaf_in(&leaf, lbh->b_data); + lgfs2_leaf_in(&leaf, lbh->b_data); brelse(lbh); /* Calculate the expected pointer count based on the leaf depth. */ diff --git a/gfs2/libgfs2/libgfs2.h b/gfs2/libgfs2/libgfs2.h index 6a7b3097..ba22f3bb 100644 --- a/gfs2/libgfs2/libgfs2.h +++ b/gfs2/libgfs2/libgfs2.h @@ -402,6 +402,17 @@ struct lgfs2_dirent { uint32_t dr_cookie; };
+struct lgfs2_leaf { + uint16_t lf_depth; + uint16_t lf_entries; + uint32_t lf_dirent_format; + uint64_t lf_next; + uint64_t lf_inode; + uint32_t lf_dist; + uint32_t lf_nsec; + uint64_t lf_sec; +}; + struct metapath { unsigned int mp_list[GFS2_MAX_META_HEIGHT]; }; @@ -811,8 +822,8 @@ extern void lgfs2_dinode_in(struct gfs2_inode *ip, char *buf); extern void lgfs2_dinode_out(struct gfs2_inode *ip, char *buf); extern void lgfs2_dirent_in(struct lgfs2_dirent *d, void *dep); extern void lgfs2_dirent_out(struct lgfs2_dirent *d, void *dep); -extern void gfs2_leaf_in(struct gfs2_leaf *lf, char *buf); -extern void gfs2_leaf_out(struct gfs2_leaf *lf, char *buf); +extern void lgfs2_leaf_in(struct lgfs2_leaf *lf, void *lfp); +extern void lgfs2_leaf_out(struct lgfs2_leaf *lf, void *lfp);
/* Printing functions. These expect on-disk data */ extern void lgfs2_inum_print(void *nop); diff --git a/gfs2/libgfs2/ondisk.c b/gfs2/libgfs2/ondisk.c index 1e7adbeb..c6d396f5 100644 --- a/gfs2/libgfs2/ondisk.c +++ b/gfs2/libgfs2/ondisk.c @@ -388,36 +388,32 @@ void lgfs2_dirent_out(struct lgfs2_dirent *d, void *dep) de->de_cookie = cpu_to_be32(d->dr_cookie); }
-void gfs2_leaf_in(struct gfs2_leaf *lf, char *buf) +void lgfs2_leaf_in(struct lgfs2_leaf *lf, void *lfp) { - struct gfs2_leaf *str = (struct gfs2_leaf *)buf; - - gfs2_meta_header_in(&lf->lf_header, buf); - CPIN_16(lf, str, lf_depth); - CPIN_16(lf, str, lf_entries); - CPIN_32(lf, str, lf_dirent_format); - CPIN_64(lf, str, lf_next); - 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); + struct gfs2_leaf *l = lfp; + + lf->lf_depth = be16_to_cpu(l->lf_depth); + lf->lf_entries = be16_to_cpu(l->lf_entries); + lf->lf_dirent_format = be32_to_cpu(l->lf_dirent_format); + lf->lf_next = be64_to_cpu(l->lf_next); + lf->lf_inode = be64_to_cpu(l->lf_inode); + lf->lf_dist = be32_to_cpu(l->lf_dist); + lf->lf_nsec = be32_to_cpu(l->lf_nsec); + lf->lf_sec = be64_to_cpu(l->lf_sec); }
-void gfs2_leaf_out(struct gfs2_leaf *lf, char *buf) +void lgfs2_leaf_out(struct lgfs2_leaf *lf, void *lfp) { - struct gfs2_leaf *str = (struct gfs2_leaf *)buf; - - gfs2_meta_header_out(&lf->lf_header, buf); - CPOUT_16(lf, str, lf_depth); - CPOUT_16(lf, str, lf_entries); - CPOUT_32(lf, str, lf_dirent_format); - CPOUT_64(lf, str, lf_next); - 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); + struct gfs2_leaf *l = lfp; + + l->lf_depth = cpu_to_be16(lf->lf_depth); + l->lf_entries = cpu_to_be16(lf->lf_entries); + l->lf_dirent_format = cpu_to_be32(lf->lf_dirent_format); + l->lf_next = cpu_to_be64(lf->lf_next); + l->lf_inode = cpu_to_be64(lf->lf_inode); + l->lf_dist = cpu_to_be32(lf->lf_dist); + l->lf_nsec = cpu_to_be32(lf->lf_nsec); + l->lf_sec = cpu_to_be64(lf->lf_sec); }
void lgfs2_leaf_print(void *lfp)
cluster-commits@lists.fedorahosted.org