Skip to content

Commit

Permalink
[GFS] Fix bug in endian conversion for metadata header
Browse files Browse the repository at this point in the history
In some cases 16 bit functions were being used rather than 32 bit
functions.

Signed-off-by: Steven Whitehouse <swhiteho@redhat.com>
  • Loading branch information
Steven Whitehouse committed Mar 30, 2006
1 parent cd45697 commit e3167de
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 23 deletions.
6 changes: 3 additions & 3 deletions fs/gfs2/dir.c
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ static int gfs2_dirent_offset(const void *buf)

BUG_ON(buf == NULL);

switch(be16_to_cpu(h->mh_type)) {
switch(be32_to_cpu(h->mh_type)) {
case GFS2_METATYPE_LF:
offset = sizeof(struct gfs2_leaf);
break;
Expand All @@ -475,7 +475,7 @@ static int gfs2_dirent_offset(const void *buf)
return offset;
wrong_type:
printk(KERN_WARNING "gfs2_scan_dirent: wrong block type %u\n",
be16_to_cpu(h->mh_type));
be32_to_cpu(h->mh_type));
return -1;
}

Expand Down Expand Up @@ -548,7 +548,7 @@ static int dirent_first(struct gfs2_inode *dip, struct buffer_head *bh,
{
struct gfs2_meta_header *h = (struct gfs2_meta_header *)bh->b_data;

if (be16_to_cpu(h->mh_type) == GFS2_METATYPE_LF) {
if (be32_to_cpu(h->mh_type) == GFS2_METATYPE_LF) {
if (gfs2_meta_check(dip->i_sbd, bh))
return -EIO;
*dent = (struct gfs2_dirent *)(bh->b_data +
Expand Down
4 changes: 2 additions & 2 deletions fs/gfs2/log.c
Original file line number Diff line number Diff line change
Expand Up @@ -377,8 +377,8 @@ static void log_write_header(struct gfs2_sbd *sdp, uint32_t flags, int pull)
lh = (struct gfs2_log_header *)bh->b_data;
memset(lh, 0, sizeof(struct gfs2_log_header));
lh->lh_header.mh_magic = cpu_to_be32(GFS2_MAGIC);
lh->lh_header.mh_type = cpu_to_be16(GFS2_METATYPE_LH);
lh->lh_header.mh_format = cpu_to_be16(GFS2_FORMAT_LH);
lh->lh_header.mh_type = cpu_to_be32(GFS2_METATYPE_LH);
lh->lh_header.mh_format = cpu_to_be32(GFS2_FORMAT_LH);
lh->lh_sequence = be64_to_cpu(sdp->sd_log_sequence++);
lh->lh_flags = be32_to_cpu(flags);
lh->lh_tail = be32_to_cpu(tail);
Expand Down
16 changes: 8 additions & 8 deletions fs/gfs2/lops.c
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,8 @@ static void buf_lo_before_commit(struct gfs2_sbd *sdp)
ld = (struct gfs2_log_descriptor *)bh->b_data;
ptr = (__be64 *)(bh->b_data + offset);
ld->ld_header.mh_magic = cpu_to_be32(GFS2_MAGIC);
ld->ld_header.mh_type = cpu_to_be16(GFS2_METATYPE_LD);
ld->ld_header.mh_format = cpu_to_be16(GFS2_FORMAT_LD);
ld->ld_header.mh_type = cpu_to_be32(GFS2_METATYPE_LD);
ld->ld_header.mh_format = cpu_to_be32(GFS2_FORMAT_LD);
ld->ld_type = cpu_to_be32(GFS2_LOG_DESC_METADATA);
ld->ld_length = cpu_to_be32(num + 1);
ld->ld_data1 = cpu_to_be32(num);
Expand Down Expand Up @@ -291,8 +291,8 @@ static void revoke_lo_before_commit(struct gfs2_sbd *sdp)
bh = gfs2_log_get_buf(sdp);
ld = (struct gfs2_log_descriptor *)bh->b_data;
ld->ld_header.mh_magic = cpu_to_be32(GFS2_MAGIC);
ld->ld_header.mh_type = cpu_to_be16(GFS2_METATYPE_LD);
ld->ld_header.mh_format = cpu_to_be16(GFS2_FORMAT_LD);
ld->ld_header.mh_type = cpu_to_be32(GFS2_METATYPE_LD);
ld->ld_header.mh_format = cpu_to_be32(GFS2_FORMAT_LD);
ld->ld_type = cpu_to_be32(GFS2_LOG_DESC_REVOKE);
ld->ld_length = cpu_to_be32(gfs2_struct2blk(sdp, sdp->sd_log_num_revoke,
sizeof(uint64_t)));
Expand All @@ -313,8 +313,8 @@ static void revoke_lo_before_commit(struct gfs2_sbd *sdp)
bh = gfs2_log_get_buf(sdp);
mh = (struct gfs2_meta_header *)bh->b_data;
mh->mh_magic = cpu_to_be32(GFS2_MAGIC);
mh->mh_type = cpu_to_be16(GFS2_METATYPE_LB);
mh->mh_format = cpu_to_be16(GFS2_FORMAT_LB);
mh->mh_type = cpu_to_be32(GFS2_METATYPE_LB);
mh->mh_format = cpu_to_be32(GFS2_FORMAT_LB);
offset = sizeof(struct gfs2_meta_header);
}

Expand Down Expand Up @@ -576,9 +576,9 @@ static void databuf_lo_before_commit(struct gfs2_sbd *sdp)
ld->ld_header.mh_magic =
cpu_to_be32(GFS2_MAGIC);
ld->ld_header.mh_type =
cpu_to_be16(GFS2_METATYPE_LD);
cpu_to_be32(GFS2_METATYPE_LD);
ld->ld_header.mh_format =
cpu_to_be16(GFS2_FORMAT_LD);
cpu_to_be32(GFS2_FORMAT_LD);
ld->ld_type =
cpu_to_be32(GFS2_LOG_DESC_JDATA);
ld->ld_length = cpu_to_be32(num + 1);
Expand Down
8 changes: 4 additions & 4 deletions fs/gfs2/ondisk.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,17 +83,17 @@ static void gfs2_meta_header_in(struct gfs2_meta_header *mh, char *buf)
struct gfs2_meta_header *str = (struct gfs2_meta_header *)buf;

mh->mh_magic = be32_to_cpu(str->mh_magic);
mh->mh_type = be16_to_cpu(str->mh_type);
mh->mh_format = be16_to_cpu(str->mh_format);
mh->mh_type = be32_to_cpu(str->mh_type);
mh->mh_format = be32_to_cpu(str->mh_format);
}

static void gfs2_meta_header_out(struct gfs2_meta_header *mh, char *buf)
{
struct gfs2_meta_header *str = (struct gfs2_meta_header *)buf;

str->mh_magic = cpu_to_be32(mh->mh_magic);
str->mh_type = cpu_to_be16(mh->mh_type);
str->mh_format = cpu_to_be16(mh->mh_format);
str->mh_type = cpu_to_be32(mh->mh_type);
str->mh_format = cpu_to_be32(mh->mh_format);
}

void gfs2_meta_header_print(struct gfs2_meta_header *mh)
Expand Down
4 changes: 2 additions & 2 deletions fs/gfs2/recovery.c
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ static int foreach_descriptor(struct gfs2_jdesc *jd, unsigned int start,
ld = (struct gfs2_log_descriptor *)bh->b_data;
length = be32_to_cpu(ld->ld_length);

if (be16_to_cpu(ld->ld_header.mh_type) == GFS2_METATYPE_LH) {
if (be32_to_cpu(ld->ld_header.mh_type) == GFS2_METATYPE_LH) {
struct gfs2_log_header lh;
error = get_log_header(jd, start, &lh);
if (!error) {
Expand Down Expand Up @@ -400,7 +400,7 @@ static int clean_journal(struct gfs2_jdesc *jd, struct gfs2_log_header *head)
memset(lh, 0, sizeof(struct gfs2_log_header));
lh->lh_header.mh_magic = cpu_to_be32(GFS2_MAGIC);
lh->lh_header.mh_type = cpu_to_be16(GFS2_METATYPE_LH);
lh->lh_header.mh_format = cpu_to_be16(GFS2_FORMAT_LH);
lh->lh_header.mh_format = cpu_to_be32(GFS2_FORMAT_LH);
lh->lh_sequence = cpu_to_be64(head->lh_sequence + 1);
lh->lh_flags = cpu_to_be32(GFS2_LOG_HEAD_UNMOUNT);
lh->lh_blkno = cpu_to_be32(lblock);
Expand Down
7 changes: 3 additions & 4 deletions fs/gfs2/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,11 @@ static inline int gfs2_metatype_check_i(struct gfs2_sbd *sdp,
{
struct gfs2_meta_header *mh = (struct gfs2_meta_header *)bh->b_data;
uint32_t magic = mh->mh_magic;
uint16_t t = mh->mh_type;
uint16_t t = be32_to_cpu(mh->mh_type);
magic = be32_to_cpu(magic);
if (unlikely(magic != GFS2_MAGIC))
return gfs2_meta_check_ii(sdp, bh, "magic number", function,
file, line);
t = be16_to_cpu(t);
if (unlikely(t != type))
return gfs2_metatype_check_ii(sdp, bh, type, t, function,
file, line);
Expand All @@ -127,8 +126,8 @@ static inline void gfs2_metatype_set(struct buffer_head *bh, uint16_t type,
{
struct gfs2_meta_header *mh;
mh = (struct gfs2_meta_header *)bh->b_data;
mh->mh_type = cpu_to_be16(type);
mh->mh_format = cpu_to_be16(format);
mh->mh_type = cpu_to_be32(type);
mh->mh_format = cpu_to_be32(format);
}


Expand Down

0 comments on commit e3167de

Please sign in to comment.