This is an automated email from the git hooks/post-receive script.
andyp pushed a commit to branch andyp-sparse
in repository gfs2-utils.
commit afa1d8dfbc1e856ebcb9368009681ca18ed8a1ed
Author: Andrew Price <anprice(a)redhat.com>
AuthorDate: Mon May 10 08:41:13 2021 +0100
libgfs2: Fix endianness mismatches for struct gfs2_log_header
Convert gfs2_log_header_print to accept big-endian data and remove a
bunch of uses of gfs2_log_header_{in,out}. Not all of them can be
removed as some the journal recovery deeply depends on it so that will
require a different approach.
Signed-off-by: Andrew Price <anprice(a)redhat.com>
---
gfs2/edit/gfs2hex.c | 13 +++-----
gfs2/edit/hexedit.c | 40 ++++++------------------
gfs2/edit/hexedit.h | 3 +-
gfs2/edit/journal.c | 77 +++++++++++++++++++++++------------------------
gfs2/edit/savemeta.c | 31 ++++++++++---------
gfs2/libgfs2/libgfs2.h | 2 +-
gfs2/libgfs2/ondisk.c | 38 ++++++++++++-----------
gfs2/libgfs2/structures.c | 76 +++++++++++++++++++++-------------------------
gfs2/mkfs/main_jadd.c | 43 ++++++++++++++------------
9 files changed, 149 insertions(+), 174 deletions(-)
diff --git a/gfs2/edit/gfs2hex.c b/gfs2/edit/gfs2hex.c
index 9d5eff71..4c3426db 100644
--- a/gfs2/edit/gfs2hex.c
+++ b/gfs2/edit/gfs2hex.c
@@ -396,8 +396,6 @@ static void gfs_sb_print(void *sbp)
int display_gfs2(char *buf)
{
struct gfs2_meta_header mh;
- struct gfs_log_header lh1;
- struct gfs2_log_header lh;
uint32_t magic;
@@ -448,13 +446,10 @@ int display_gfs2(char *buf)
break;
case GFS2_METATYPE_LH:
- if (sbd.gfs1) {
- gfs_log_header_in(&lh1, buf);
- gfs_log_header_print(&lh1);
- } else {
- gfs2_log_header_in(&lh, buf);
- gfs2_log_header_print(&lh);
- }
+ if (sbd.gfs1)
+ gfs_log_header_print(buf);
+ else
+ lgfs2_log_header_print(buf);
break;
case GFS2_METATYPE_LD:
diff --git a/gfs2/edit/hexedit.c b/gfs2/edit/hexedit.c
index f63dc3ec..2e647211 100644
--- a/gfs2/edit/hexedit.c
+++ b/gfs2/edit/hexedit.c
@@ -2043,40 +2043,20 @@ static void interactive_mode(void)
endwin();
}/* interactive_mode */
-/* ------------------------------------------------------------------------ */
-/* gfs_log_header_in - read in a gfs1-style log header */
-/* ------------------------------------------------------------------------ */
-void gfs_log_header_in(struct gfs_log_header *head, const char *buf)
-{
- const struct gfs_log_header *str = (void *)buf;
-
- gfs2_meta_header_in(&head->lh_header, buf);
-
- head->lh_flags = be32_to_cpu(str->lh_flags);
- head->lh_pad = be32_to_cpu(str->lh_pad);
-
- head->lh_first = be64_to_cpu(str->lh_first);
- head->lh_sequence = be64_to_cpu(str->lh_sequence);
-
- head->lh_tail = be64_to_cpu(str->lh_tail);
- head->lh_last_dump = be64_to_cpu(str->lh_last_dump);
-
- memcpy(head->lh_reserved, str->lh_reserved, 64);
-}
-
-
/* ------------------------------------------------------------------------ */
/* gfs_log_header_print - print a gfs1-style log header */
/* ------------------------------------------------------------------------ */
-void gfs_log_header_print(struct gfs_log_header *lh)
+void gfs_log_header_print(void *lhp)
{
- gfs2_meta_header_print(&lh->lh_header);
- pv(lh, lh_flags, "%u", "0x%.8x");
- pv(lh, lh_pad, "%u", "%x");
- pv((unsigned long long)lh, lh_first, "%llu", "%llx");
- pv((unsigned long long)lh, lh_sequence, "%llu", "%llx");
- pv((unsigned long long)lh, lh_tail, "%llu", "%llx");
- pv((unsigned long long)lh, lh_last_dump, "%llu", "%llx");
+ struct gfs_log_header *lh = lhp;
+
+ lgfs2_meta_header_print(&lh->lh_header);
+ print_it(" lh_flags", "%"PRIu32, "0x%.8"PRIx32,
be32_to_cpu(lh->lh_flags));
+ print_it(" lh_pad", "%"PRIu32, "0x%"PRIx32,
be32_to_cpu(lh->lh_pad));
+ print_it(" lh_first", "%"PRIu64, "0x%"PRIx64,
be64_to_cpu(lh->lh_first));
+ print_it(" lh_sequence", "%"PRIu64, "0x%"PRIx64,
be64_to_cpu(lh->lh_sequence));
+ print_it(" lh_tail", "%"PRIu64, "0x%"PRIx64,
be64_to_cpu(lh->lh_tail));
+ print_it(" lh_last_dump", "%"PRIu64, "0x%"PRIx64,
be64_to_cpu(lh->lh_last_dump));
}
/* ------------------------------------------------------------------------ */
diff --git a/gfs2/edit/hexedit.h b/gfs2/edit/hexedit.h
index 11e6f105..cb3343d0 100644
--- a/gfs2/edit/hexedit.h
+++ b/gfs2/edit/hexedit.h
@@ -222,8 +222,7 @@ extern int block_is_quota_file(uint64_t blk);
extern int block_is_per_node(uint64_t blk);
extern int display_block_type(char *buf, uint64_t addr, int from_restore);
extern void gfs_jindex_in(struct gfs_jindex *jindex, char *buf);
-extern void gfs_log_header_in(struct gfs_log_header *head, const char *buf);
-extern void gfs_log_header_print(struct gfs_log_header *lh);
+extern void gfs_log_header_print(void *lhp);
extern void savemeta(char *out_fn, int saveoption, int gziplevel);
extern void restoremeta(const char *in_fn, const char *out_device,
uint64_t printblocksonly);
diff --git a/gfs2/edit/journal.c b/gfs2/edit/journal.c
index 7f27109a..607f65e5 100644
--- a/gfs2/edit/journal.c
+++ b/gfs2/edit/journal.c
@@ -301,7 +301,7 @@ static int print_ld_blks(const uint64_t *b, const char *end, int
start_line,
return bcount;
}
-static int is_wrap_pt(char *buf, uint64_t *highest_seq)
+static int is_wrap_pt(void *buf, uint64_t *highest_seq)
{
const struct lgfs2_metadata *mtype = get_block_type(buf);
@@ -309,13 +309,11 @@ static int is_wrap_pt(char *buf, uint64_t *highest_seq)
uint64_t seq;
if (sbd.gfs1) {
- struct gfs_log_header lh;
- gfs_log_header_in(&lh, buf);
- seq = lh.lh_sequence;
+ struct gfs_log_header *lh = buf;
+ seq = be64_to_cpu(lh->lh_sequence);
} else {
- struct gfs2_log_header lh;
- gfs2_log_header_in(&lh, buf);
- seq = lh.lh_sequence;
+ struct gfs2_log_header *lh = buf;
+ seq = be64_to_cpu(lh->lh_sequence);
}
if (seq < *highest_seq)
return 1;
@@ -467,6 +465,38 @@ static uint64_t get_ldref(uint64_t abs_ld, int offset_from_ld)
return refblk;
}
+static void display_log_header(void *buf, uint64_t *highest_seq, uint64_t abs_block,
uint64_t jb, uint64_t j_size)
+{
+ const struct lgfs2_metafield *lh_flags_field;
+ const struct lgfs2_metadata *mtype;
+ struct gfs2_log_header *lh = buf;
+ struct gfs_log_header *lh1 = buf;
+ char flags_str[256];
+
+ if (sbd.gfs1) {
+ mtype = &lgfs2_metadata[LGFS2_MT_GFS_LOG_HEADER];
+ lh_flags_field = &mtype->fields[7]; /* lh_flags is the 8th field in the struct
*/
+ check_journal_wrap(be64_to_cpu(lh1->lh_sequence), highest_seq);
+ } else {
+ mtype = &lgfs2_metadata[LGFS2_MT_GFS2_LOG_HEADER];
+ lh_flags_field = &mtype->fields[6]; /* lh_flags is the 7th field in the struct
*/
+ check_journal_wrap(be64_to_cpu(lh->lh_sequence), highest_seq);
+ }
+ lgfs2_field_str(flags_str, sizeof(flags_str), buf, lh_flags_field, (dmode ==
HEX_MODE));
+ if (sbd.gfs1) {
+ print_gfs2("0x%"PRIx64" (j+%4"PRIx64"): Log header: Seq:
0x%"PRIx64", "
+ "1st: 0x%"PRIx64", tail: 0x%"PRIx64", last:
0x%"PRIx64" [%s]",
+ abs_block, jb, be64_to_cpu(lh1->lh_sequence),
+ be64_to_cpu(lh1->lh_first), be64_to_cpu(lh1->lh_tail),
+ be64_to_cpu(lh1->lh_last_dump), flags_str);
+ } else {
+ print_gfs2("0x%"PRIx64" (j+%4"PRIx64"): Log header: Seq:
0x%"PRIx64", "
+ "tail: 0x%"PRIx32", blk: 0x%"PRIx32" [%s]",
+ abs_block, (jb % j_size) / sbd.bsize, be64_to_cpu(lh->lh_sequence),
+ be32_to_cpu(lh->lh_tail), be32_to_cpu(lh->lh_blkno), flags_str);
+ }
+}
+
/**
* dump_journal - dump a journal file's contents.
* @journal: name of the journal to dump
@@ -480,7 +510,6 @@ static uint64_t get_ldref(uint64_t abs_ld, int offset_from_ld)
void dump_journal(const char *journal, int tblk)
{
const struct lgfs2_metadata *mtype;
- const struct lgfs2_metafield *lh_flags_field;
struct gfs2_buffer_head *j_bh = NULL;
uint64_t jblock, j_size, jb, abs_block, saveblk, wrappt = 0;
int start_line, journal_num;
@@ -494,7 +523,6 @@ void dump_journal(const char *journal, int tblk)
uint64_t abs_ld = 0;
mtype = lgfs2_find_mtype(GFS2_METATYPE_LH, sbd.gfs1 ? LGFS2_MD_GFS1 : LGFS2_MD_GFS2);
- lh_flags_field = lgfs2_find_mfield_name("lh_flags", mtype);
start_line = line;
lines_per_row[dmode] = 1;
@@ -589,36 +617,7 @@ void dump_journal(const char *journal, int tblk)
offset_from_ld = 0;
abs_ld = abs_block;
} else if (!tblk && block_type == GFS2_METATYPE_LH) {
- struct gfs2_log_header lh;
- struct gfs_log_header lh1;
-
- if (sbd.gfs1) {
- gfs_log_header_in(&lh1, buf);
- check_journal_wrap(lh1.lh_sequence,
- &highest_seq);
- print_gfs2("0x%"PRIx64" (j+%4"PRIx64"): Log header: "
- "Flags:%"PRIx32", Seq: 0x%"PRIx64", 1st:
0x%"PRIx64", "
- "tail: 0x%"PRIx64", last: 0x%"PRIx64,
- abs_block, jb + wrappt,
- lh1.lh_flags, lh1.lh_sequence,
- lh1.lh_first, lh1.lh_tail,
- lh1.lh_last_dump);
- } else {
- char flags_str[256];
-
- gfs2_log_header_in(&lh, buf);
- check_journal_wrap(lh.lh_sequence,
- &highest_seq);
- lgfs2_field_str(flags_str, sizeof(flags_str),
- buf, lh_flags_field,
- (dmode == HEX_MODE));
- print_gfs2("0x%"PRIx64" (j+%4"PRIx64"): Log header: Seq:
"
- "0x%"PRIx64", tail: 0x%"PRIx32", blk:
0x%"PRIx32" [%s]",
- abs_block, ((jb + wrappt) % j_size)
- / sbd.bsize, lh.lh_sequence,
- lh.lh_tail, lh.lh_blkno,
- flags_str);
- }
+ display_log_header(buf, &highest_seq, abs_block, jb + wrappt, j_size);
eol(0);
} else if ((ld_blocks > 0) &&
(sbd.gfs1 || block_type == GFS2_METATYPE_LB)) {
diff --git a/gfs2/edit/savemeta.c b/gfs2/edit/savemeta.c
index 664c92d6..9c003e68 100644
--- a/gfs2/edit/savemeta.c
+++ b/gfs2/edit/savemeta.c
@@ -857,15 +857,14 @@ static void save_leaf_blocks(struct metafd *mfd, struct
block_range_queue *q)
static void save_inode_data(struct metafd *mfd, char *ibuf, uint64_t iblk)
{
struct block_range_queue indq[GFS2_MAX_META_HEIGHT] = {{NULL}};
- uint32_t height;
- struct gfs2_dinode _di = {0};
+ struct gfs2_dinode *dip = (struct gfs2_dinode *)ibuf;
+ uint16_t height;
int is_exhash;
for (unsigned i = 0; i < GFS2_MAX_META_HEIGHT; i++)
block_range_queue_init(&indq[i]);
- gfs2_dinode_in(&_di, ibuf);
- height = _di.di_height;
+ height = be16_to_cpu(dip->di_height);
/* If this is a user inode, we don't follow to the file height.
We stop one level less. That way we save off the indirect
@@ -873,16 +872,20 @@ static void save_inode_data(struct metafd *mfd, char *ibuf, uint64_t
iblk)
is directories, where the height represents the level at which
the hash table exists, and we have to save the directory data. */
- is_exhash = (S_ISDIR(_di.di_mode) || (sbd.gfs1 && _di.__pad1 == GFS_FILE_DIR))
&&
- _di.di_flags & GFS2_DIF_EXHASH;
+ is_exhash = (S_ISDIR(be32_to_cpu(dip->di_mode)) ||
+ (sbd.gfs1 && be16_to_cpu(dip->__pad1) == GFS_FILE_DIR))
&&
+ be32_to_cpu(dip->di_flags) & GFS2_DIF_EXHASH;
if (is_exhash)
height++;
- else if (height > 0 && !(_di.di_flags & GFS2_DIF_SYSTEM) &&
- !block_is_systemfile(iblk) && !S_ISDIR(_di.di_mode))
+ else if (height > 0 && !(be32_to_cpu(dip->di_flags) & GFS2_DIF_SYSTEM)
&&
+ !block_is_systemfile(iblk) && !S_ISDIR(be32_to_cpu(dip->di_mode)))
height--;
- if (height > 0)
- save_indirect_blocks(mfd, ibuf, iblk, height == 1 ? NULL : &indq[0], sizeof(_di));
+ if (height == 1)
+ save_indirect_blocks(mfd, ibuf, iblk, NULL, sizeof(*dip));
+ else if (height > 1)
+ save_indirect_blocks(mfd, ibuf, iblk, &indq[0], sizeof(*dip));
+
for (unsigned i = 1; i < height; i++) {
struct block_range_queue *nextq = &indq[i];
@@ -895,7 +898,7 @@ static void save_inode_data(struct metafd *mfd, char *ibuf, uint64_t
iblk)
for (unsigned j = 0; j < q->len; j++) {
char *_buf = q->buf + (j * sbd.bsize);
- save_indirect_blocks(mfd, _buf, iblk, nextq, sizeof(_di.di_header));
+ save_indirect_blocks(mfd, _buf, iblk, nextq, sizeof(dip->di_header));
}
report_progress(q->start + q->len, 0);
block_range_free(&q);
@@ -903,20 +906,20 @@ static void save_inode_data(struct metafd *mfd, char *ibuf, uint64_t
iblk)
}
if (is_exhash)
save_leaf_blocks(mfd, &indq[height - 1]);
- if (_di.di_eattr) { /* if this inode has extended attributes */
+ if (dip->di_eattr) { /* if this inode has extended attributes */
size_t blklen;
uint64_t blk;
int mhtype;
char *buf;
- blk = _di.di_eattr;
+ blk = be64_to_cpu(dip->di_eattr);
buf = check_read_block(sbd.device_fd, blk, iblk, &mhtype, &blklen);
if (buf != NULL) {
save_buf(mfd, buf, blk, blklen);
if (mhtype == GFS2_METATYPE_EA)
save_ea_block(mfd, buf, iblk);
else if (mhtype == GFS2_METATYPE_IN)
- save_indirect_blocks(mfd, buf, iblk, NULL, sizeof(_di.di_header));
+ save_indirect_blocks(mfd, buf, iblk, NULL, sizeof(dip->di_header));
free(buf);
}
}
diff --git a/gfs2/libgfs2/libgfs2.h b/gfs2/libgfs2/libgfs2.h
index 594db181..922d35f8 100644
--- a/gfs2/libgfs2/libgfs2.h
+++ b/gfs2/libgfs2/libgfs2.h
@@ -720,12 +720,12 @@ extern void gfs2_inum_print(const struct gfs2_inum *no);
extern void gfs2_meta_header_print(const struct gfs2_meta_header *mh);
extern void gfs2_rindex_print(const struct gfs2_rindex *ri);
extern void gfs2_dinode_print(const struct gfs2_dinode *di);
-extern void gfs2_log_header_print(const struct gfs2_log_header *lh);
/* These expect on-disk data instead of native-endian structs */
extern void lgfs2_inum_print(void *nop);
extern void lgfs2_meta_header_print(void *mhp);
extern void lgfs2_sb_print(void *sbp);
extern void lgfs2_dinode_print(void *dip);
+extern void lgfs2_log_header_print(void *lhp);
extern void lgfs2_log_descriptor_print(void *ldp);
extern void lgfs2_quota_print(void *qp);
extern void lgfs2_quota_change_print(void *qcp);
diff --git a/gfs2/libgfs2/ondisk.c b/gfs2/libgfs2/ondisk.c
index a7f87d7a..b9b8a67e 100644
--- a/gfs2/libgfs2/ondisk.c
+++ b/gfs2/libgfs2/ondisk.c
@@ -551,24 +551,26 @@ void gfs2_log_header_out(struct gfs2_log_header *lh, char *buf)
CPOUT_64(lh, str, lh_local_dinodes);
}
-void gfs2_log_header_print(const struct gfs2_log_header *lh)
-{
- gfs2_meta_header_print(&lh->lh_header);
- pv(lh, lh_sequence, "%"PRIu64, "0x%"PRIx64);
- pv(lh, lh_flags, "0x%.8"PRIX32, NULL);
- pv(lh, lh_tail, "%"PRIu32, "0x%"PRIx32);
- pv(lh, lh_blkno, "%"PRIu32, "0x%"PRIx32);
- pv(lh, lh_hash, "0x%.8"PRIX32, NULL);
- pv(lh, lh_crc, "0x%.8"PRIX32, NULL);
- pv(lh, lh_nsec, "%"PRIu32, "0x%"PRIx32);
- pv(lh, lh_sec, "%"PRIu64, "0x%"PRIx64);
- pv(lh, lh_addr, "%"PRIu64, "0x%"PRIx64);
- pv(lh, lh_jinode, "%"PRIu64, "0x%"PRIx64);
- pv(lh, lh_statfs_addr, "%"PRIu64, "0x%"PRIx64);
- pv(lh, lh_quota_addr, "%"PRIu64, "0x%"PRIx64);
- pv(lh, lh_local_total, "%"PRId64, "0x%"PRIx64);
- pv(lh, lh_local_free, "%"PRId64, "0x%"PRIx64);
- pv(lh, lh_local_dinodes, "%"PRId64, "0x%"PRIx64);
+void lgfs2_log_header_print(void *lhp)
+{
+ struct gfs2_log_header *lh = lhp;
+
+ lgfs2_meta_header_print(&lh->lh_header);
+ printbe64(lh, lh_sequence);
+ print_it(" lh_flags", "0x%.8"PRIX32, NULL,
be32_to_cpu(lh->lh_flags));
+ printbe32(lh, lh_tail);
+ printbe32(lh, lh_blkno);
+ print_it(" lh_hash", "0x%.8"PRIX32, NULL,
be32_to_cpu(lh->lh_hash));
+ print_it(" lh_crc", "0x%.8"PRIX32, NULL,
be32_to_cpu(lh->lh_crc));
+ printbe32(lh, lh_nsec);
+ printbe64(lh, lh_sec);
+ printbe64(lh, lh_addr);
+ printbe64(lh, lh_jinode);
+ printbe64(lh, lh_statfs_addr);
+ printbe64(lh, lh_quota_addr);
+ print_it(" lh_local_total", "%"PRId64, "0x%"PRIx64,
be64_to_cpu(lh->lh_local_total));
+ print_it(" lh_local_free", "%"PRId64, "0x%"PRIx64,
be64_to_cpu(lh->lh_local_free));
+ print_it(" lh_local_dinodes", "%"PRId64, "0x%"PRIx64,
be64_to_cpu(lh->lh_local_dinodes));
}
void lgfs2_log_descriptor_print(void *ldp)
diff --git a/gfs2/libgfs2/structures.c b/gfs2/libgfs2/structures.c
index 79d99ba1..4ef4e685 100644
--- a/gfs2/libgfs2/structures.c
+++ b/gfs2/libgfs2/structures.c
@@ -124,28 +124,11 @@ uint32_t lgfs2_log_header_crc(char *buf, unsigned bsize)
*/
int lgfs2_write_journal_data(struct gfs2_inode *ip)
{
- struct gfs2_log_header lh = {
- .lh_header.mh_magic = GFS2_MAGIC,
- .lh_header.mh_type = GFS2_METATYPE_LH,
- .lh_header.mh_format = GFS2_FORMAT_LH,
- .lh_tail = 0,
- .lh_blkno = 0,
- .lh_hash = 0,
- .lh_flags = GFS2_LOG_HEAD_UNMOUNT | GFS2_LOG_HEAD_USERSPACE,
- .lh_crc = 0,
- .lh_nsec = 0,
- .lh_sec = 0,
- .lh_jinode = ip->i_di.di_num.no_addr,
- .lh_statfs_addr = 0,
- .lh_quota_addr = 0,
- .lh_local_total = 0,
- .lh_local_free = 0,
- .lh_local_dinodes = 0,
- };
struct gfs2_sbd *sdp = ip->i_sbd;
unsigned blocks = (ip->i_di.di_size + sdp->bsize - 1) / sdp->bsize;
uint64_t jext0 = ip->i_di.di_num.no_addr + ip->i_di.di_blocks - blocks;
uint64_t seq = ((blocks) * (random() / (RAND_MAX + 1.0)));
+ struct gfs2_log_header *lh;
uint64_t jblk = jext0;
char *buf;
@@ -153,23 +136,33 @@ int lgfs2_write_journal_data(struct gfs2_inode *ip)
if (buf == NULL)
return -1;
+ lh = (void *)buf;
+ lh->lh_header.mh_magic = cpu_to_be32(GFS2_MAGIC);
+ lh->lh_header.mh_type = cpu_to_be32(GFS2_METATYPE_LH);
+ lh->lh_header.mh_format = cpu_to_be32(GFS2_FORMAT_LH);
+ lh->lh_flags = cpu_to_be32(GFS2_LOG_HEAD_UNMOUNT | GFS2_LOG_HEAD_USERSPACE);
+ lh->lh_jinode = cpu_to_be64(ip->i_di.di_num.no_addr);
+
crc32c_optimization_init();
do {
- struct gfs2_log_header *buflh = (struct gfs2_log_header *)buf;
-
- lh.lh_sequence = seq;
- lh.lh_blkno = jblk - jext0;
- gfs2_log_header_out(&lh, buf);
+ uint32_t hash;
- buflh->lh_hash = cpu_to_be32(lgfs2_log_header_hash(buf));
- buflh->lh_addr = cpu_to_be64(jblk);
- buflh->lh_crc = cpu_to_be32(lgfs2_log_header_crc(buf, sdp->bsize));
+ lh->lh_sequence = cpu_to_be64(seq);
+ lh->lh_blkno = cpu_to_be32(jblk - jext0);
+ hash = lgfs2_log_header_hash(buf);
+ lh->lh_hash = cpu_to_be32(hash);
+ lh->lh_addr = cpu_to_be64(jblk);
+ hash = lgfs2_log_header_crc(buf, sdp->bsize);
+ lh->lh_crc = cpu_to_be32(hash);
if (pwrite(sdp->device_fd, buf, sdp->bsize, jblk * sdp->bsize) !=
sdp->bsize) {
free(buf);
return -1;
}
+ lh->lh_crc = 0;
+ lh->lh_hash = 0;
+
if (++seq == blocks)
seq = 0;
@@ -205,8 +198,8 @@ static struct gfs2_buffer_head *get_file_buf(struct gfs2_inode *ip,
uint64_t lbn
int write_journal(struct gfs2_inode *jnl, unsigned bsize, unsigned int blocks)
{
- struct gfs2_log_header lh;
- unsigned int x;
+ struct gfs2_log_header *lh;
+ uint32_t x;
uint64_t seq = ((blocks) * (random() / (RAND_MAX + 1.0)));
uint32_t hash;
unsigned int height;
@@ -216,14 +209,6 @@ int write_journal(struct gfs2_inode *jnl, unsigned bsize, unsigned
int blocks)
height = calc_tree_height(jnl, (blocks + 1) * bsize);
build_height(jnl, height);
- memset(&lh, 0, sizeof(struct gfs2_log_header));
- lh.lh_header.mh_magic = GFS2_MAGIC;
- lh.lh_header.mh_type = GFS2_METATYPE_LH;
- lh.lh_header.mh_format = GFS2_FORMAT_LH;
- lh.lh_flags = GFS2_LOG_HEAD_UNMOUNT;
- lh.lh_flags |= GFS2_LOG_HEAD_USERSPACE;
- lh.lh_jinode = jnl->i_di.di_num.no_addr;
-
for (x = 0; x < blocks; x++) {
struct gfs2_buffer_head *bh = get_file_buf(jnl, x, 1);
if (!bh)
@@ -238,14 +223,21 @@ int write_journal(struct gfs2_inode *jnl, unsigned bsize, unsigned
int blocks)
return -1;
memset(bh->b_data, 0, bsize);
- lh.lh_sequence = seq;
- lh.lh_blkno = x;
- gfs2_log_header_out(&lh, bh->b_data);
+ lh = (void *)bh->b_data;
+ lh->lh_header.mh_magic = cpu_to_be32(GFS2_MAGIC);
+ lh->lh_header.mh_type = cpu_to_be32(GFS2_METATYPE_LH);
+ lh->lh_header.mh_format = cpu_to_be32(GFS2_FORMAT_LH);
+ lh->lh_flags = cpu_to_be32(GFS2_LOG_HEAD_UNMOUNT | GFS2_LOG_HEAD_USERSPACE);
+ lh->lh_jinode = cpu_to_be64(jnl->i_di.di_num.no_addr);
+ lh->lh_sequence = cpu_to_be64(seq);
+ lh->lh_blkno = cpu_to_be32(x);
+
hash = lgfs2_log_header_hash(bh->b_data);
- ((struct gfs2_log_header *)bh->b_data)->lh_hash = cpu_to_be32(hash);
- ((struct gfs2_log_header *)bh->b_data)->lh_addr = cpu_to_be64(bh->b_blocknr);
+ lh->lh_hash = cpu_to_be32(hash);
+ lh->lh_addr = cpu_to_be64(bh->b_blocknr);
+
hash = lgfs2_log_header_crc(bh->b_data, bsize);
- ((struct gfs2_log_header *)bh->b_data)->lh_crc = cpu_to_be32(hash);
+ lh->lh_crc = cpu_to_be32(hash);
bmodified(bh);
brelse(bh);
diff --git a/gfs2/mkfs/main_jadd.c b/gfs2/mkfs/main_jadd.c
index bad7db25..8e349c9c 100644
--- a/gfs2/mkfs/main_jadd.c
+++ b/gfs2/mkfs/main_jadd.c
@@ -517,16 +517,20 @@ out_errno:
static int add_j(struct gfs2_sbd *sdp, struct jadd_opts *opts)
{
int fd, error = 0;
- char new_name[256], buf[sdp->bsize];
- unsigned int x, blocks =
- sdp->jsize << (20 - sdp->sd_sb.sb_bsize_shift);
- struct gfs2_log_header lh;
+ char new_name[256], *buf;
+ uint32_t x, blocks = sdp->jsize << (20 - sdp->sd_sb.sb_bsize_shift);
+ struct gfs2_log_header *lh;
uint64_t seq = RANDOM(blocks), addr = 0;
off_t off = 0;
- if ((fd = create_new_inode(opts, &addr)) < 0)
- return fd;
+ buf = calloc(1, sdp->bsize);
+ if (buf == NULL)
+ return -1;
+ if ((fd = create_new_inode(opts, &addr)) < 0) {
+ free(buf);
+ return fd;
+ }
if ((error = set_flags(fd, JA_FL_CLEAR, FS_JOURNAL_DATA_FL)))
goto close_fd;
@@ -544,34 +548,34 @@ static int add_j(struct gfs2_sbd *sdp, struct jadd_opts *opts)
goto close_fd;
}
- memset(&lh, 0, sizeof(struct gfs2_log_header));
- lh.lh_header.mh_magic = GFS2_MAGIC;
- lh.lh_header.mh_type = GFS2_METATYPE_LH;
- lh.lh_header.mh_format = GFS2_FORMAT_LH;
- lh.lh_flags = GFS2_LOG_HEAD_UNMOUNT;
- lh.lh_flags |= GFS2_LOG_HEAD_USERSPACE;
- lh.lh_jinode = addr;
+ lh = (void *)buf;
+ lh->lh_header.mh_magic = cpu_to_be32(GFS2_MAGIC);
+ lh->lh_header.mh_type = cpu_to_be32(GFS2_METATYPE_LH);
+ lh->lh_header.mh_format = cpu_to_be32(GFS2_FORMAT_LH);
+ lh->lh_flags = cpu_to_be32(GFS2_LOG_HEAD_UNMOUNT | GFS2_LOG_HEAD_USERSPACE);
+ lh->lh_jinode = cpu_to_be64(addr);
for (x=0; x<blocks; x++) {
uint32_t hash;
uint64_t blk_addr = 0;
- lh.lh_sequence = seq;
- lh.lh_blkno = x;
- gfs2_log_header_out(&lh, buf);
+ lh->lh_sequence = cpu_to_be64(seq);
+ lh->lh_blkno = cpu_to_be32(x);
hash = lgfs2_log_header_hash(buf);
- ((struct gfs2_log_header *)buf)->lh_hash = cpu_to_be32(hash);
+ lh->lh_hash = cpu_to_be32(hash);
if (!(blk_addr = find_block_address(fd, off, sdp->bsize))) {
error = -1;
goto close_fd;
}
- ((struct gfs2_log_header *)buf)->lh_addr = cpu_to_be64(blk_addr);
+ lh->lh_addr = cpu_to_be64(blk_addr);
hash = lgfs2_log_header_crc(buf, sdp->bsize);
- ((struct gfs2_log_header *)buf)->lh_crc = cpu_to_be32(hash);
+ lh->lh_crc = cpu_to_be32(hash);
if (write(fd, buf, sdp->bsize) != sdp->bsize) {
perror("add_j write");
error = -1;
goto close_fd;
}
+ lh->lh_crc = 0;
+ lh->lh_hash = 0;
if (++seq == blocks)
seq = 0;
@@ -590,6 +594,7 @@ static int add_j(struct gfs2_sbd *sdp, struct jadd_opts *opts)
goto close_fd;
}
close_fd:
+ free(buf);
return close(fd) || error;
}
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.