mirror of
https://github.com/torvalds/linux.git
synced 2025-01-01 15:51:46 +00:00
ext4: introduce EXT4_FC_TAG_BASE_LEN helper
Introduce EXT4_FC_TAG_BASE_LEN helper for calculate length of struct ext4_fc_tl. Signed-off-by: Ye Bin <yebin10@huawei.com> Link: https://lore.kernel.org/r/20220924075233.2315259-2-yebin10@huawei.com Signed-off-by: Theodore Ts'o <tytso@mit.edu>
This commit is contained in:
parent
7ff5fddadd
commit
fdc2a3c75d
@ -702,10 +702,10 @@ static u8 *ext4_fc_reserve_space(struct super_block *sb, int len, u32 *crc)
|
|||||||
* After allocating len, we should have space at least for a 0 byte
|
* After allocating len, we should have space at least for a 0 byte
|
||||||
* padding.
|
* padding.
|
||||||
*/
|
*/
|
||||||
if (len + sizeof(struct ext4_fc_tl) > bsize)
|
if (len + EXT4_FC_TAG_BASE_LEN > bsize)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if (bsize - off - 1 > len + sizeof(struct ext4_fc_tl)) {
|
if (bsize - off - 1 > len + EXT4_FC_TAG_BASE_LEN) {
|
||||||
/*
|
/*
|
||||||
* Only allocate from current buffer if we have enough space for
|
* Only allocate from current buffer if we have enough space for
|
||||||
* this request AND we have space to add a zero byte padding.
|
* this request AND we have space to add a zero byte padding.
|
||||||
@ -722,10 +722,10 @@ static u8 *ext4_fc_reserve_space(struct super_block *sb, int len, u32 *crc)
|
|||||||
/* Need to add PAD tag */
|
/* Need to add PAD tag */
|
||||||
tl = (struct ext4_fc_tl *)(sbi->s_fc_bh->b_data + off);
|
tl = (struct ext4_fc_tl *)(sbi->s_fc_bh->b_data + off);
|
||||||
tl->fc_tag = cpu_to_le16(EXT4_FC_TAG_PAD);
|
tl->fc_tag = cpu_to_le16(EXT4_FC_TAG_PAD);
|
||||||
pad_len = bsize - off - 1 - sizeof(struct ext4_fc_tl);
|
pad_len = bsize - off - 1 - EXT4_FC_TAG_BASE_LEN;
|
||||||
tl->fc_len = cpu_to_le16(pad_len);
|
tl->fc_len = cpu_to_le16(pad_len);
|
||||||
if (crc)
|
if (crc)
|
||||||
*crc = ext4_chksum(sbi, *crc, tl, sizeof(*tl));
|
*crc = ext4_chksum(sbi, *crc, tl, EXT4_FC_TAG_BASE_LEN);
|
||||||
if (pad_len > 0)
|
if (pad_len > 0)
|
||||||
ext4_fc_memzero(sb, tl + 1, pad_len, crc);
|
ext4_fc_memzero(sb, tl + 1, pad_len, crc);
|
||||||
ext4_fc_submit_bh(sb, false);
|
ext4_fc_submit_bh(sb, false);
|
||||||
@ -767,7 +767,7 @@ static int ext4_fc_write_tail(struct super_block *sb, u32 crc)
|
|||||||
* ext4_fc_reserve_space takes care of allocating an extra block if
|
* ext4_fc_reserve_space takes care of allocating an extra block if
|
||||||
* there's no enough space on this block for accommodating this tail.
|
* there's no enough space on this block for accommodating this tail.
|
||||||
*/
|
*/
|
||||||
dst = ext4_fc_reserve_space(sb, sizeof(tl) + sizeof(tail), &crc);
|
dst = ext4_fc_reserve_space(sb, EXT4_FC_TAG_BASE_LEN + sizeof(tail), &crc);
|
||||||
if (!dst)
|
if (!dst)
|
||||||
return -ENOSPC;
|
return -ENOSPC;
|
||||||
|
|
||||||
@ -777,8 +777,8 @@ static int ext4_fc_write_tail(struct super_block *sb, u32 crc)
|
|||||||
tl.fc_len = cpu_to_le16(bsize - off - 1 + sizeof(struct ext4_fc_tail));
|
tl.fc_len = cpu_to_le16(bsize - off - 1 + sizeof(struct ext4_fc_tail));
|
||||||
sbi->s_fc_bytes = round_up(sbi->s_fc_bytes, bsize);
|
sbi->s_fc_bytes = round_up(sbi->s_fc_bytes, bsize);
|
||||||
|
|
||||||
ext4_fc_memcpy(sb, dst, &tl, sizeof(tl), &crc);
|
ext4_fc_memcpy(sb, dst, &tl, EXT4_FC_TAG_BASE_LEN, &crc);
|
||||||
dst += sizeof(tl);
|
dst += EXT4_FC_TAG_BASE_LEN;
|
||||||
tail.fc_tid = cpu_to_le32(sbi->s_journal->j_running_transaction->t_tid);
|
tail.fc_tid = cpu_to_le32(sbi->s_journal->j_running_transaction->t_tid);
|
||||||
ext4_fc_memcpy(sb, dst, &tail.fc_tid, sizeof(tail.fc_tid), &crc);
|
ext4_fc_memcpy(sb, dst, &tail.fc_tid, sizeof(tail.fc_tid), &crc);
|
||||||
dst += sizeof(tail.fc_tid);
|
dst += sizeof(tail.fc_tid);
|
||||||
@ -800,15 +800,15 @@ static bool ext4_fc_add_tlv(struct super_block *sb, u16 tag, u16 len, u8 *val,
|
|||||||
struct ext4_fc_tl tl;
|
struct ext4_fc_tl tl;
|
||||||
u8 *dst;
|
u8 *dst;
|
||||||
|
|
||||||
dst = ext4_fc_reserve_space(sb, sizeof(tl) + len, crc);
|
dst = ext4_fc_reserve_space(sb, EXT4_FC_TAG_BASE_LEN + len, crc);
|
||||||
if (!dst)
|
if (!dst)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
tl.fc_tag = cpu_to_le16(tag);
|
tl.fc_tag = cpu_to_le16(tag);
|
||||||
tl.fc_len = cpu_to_le16(len);
|
tl.fc_len = cpu_to_le16(len);
|
||||||
|
|
||||||
ext4_fc_memcpy(sb, dst, &tl, sizeof(tl), crc);
|
ext4_fc_memcpy(sb, dst, &tl, EXT4_FC_TAG_BASE_LEN, crc);
|
||||||
ext4_fc_memcpy(sb, dst + sizeof(tl), val, len, crc);
|
ext4_fc_memcpy(sb, dst + EXT4_FC_TAG_BASE_LEN, val, len, crc);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -820,8 +820,8 @@ static bool ext4_fc_add_dentry_tlv(struct super_block *sb, u32 *crc,
|
|||||||
struct ext4_fc_dentry_info fcd;
|
struct ext4_fc_dentry_info fcd;
|
||||||
struct ext4_fc_tl tl;
|
struct ext4_fc_tl tl;
|
||||||
int dlen = fc_dentry->fcd_name.len;
|
int dlen = fc_dentry->fcd_name.len;
|
||||||
u8 *dst = ext4_fc_reserve_space(sb, sizeof(tl) + sizeof(fcd) + dlen,
|
u8 *dst = ext4_fc_reserve_space(sb,
|
||||||
crc);
|
EXT4_FC_TAG_BASE_LEN + sizeof(fcd) + dlen, crc);
|
||||||
|
|
||||||
if (!dst)
|
if (!dst)
|
||||||
return false;
|
return false;
|
||||||
@ -830,8 +830,8 @@ static bool ext4_fc_add_dentry_tlv(struct super_block *sb, u32 *crc,
|
|||||||
fcd.fc_ino = cpu_to_le32(fc_dentry->fcd_ino);
|
fcd.fc_ino = cpu_to_le32(fc_dentry->fcd_ino);
|
||||||
tl.fc_tag = cpu_to_le16(fc_dentry->fcd_op);
|
tl.fc_tag = cpu_to_le16(fc_dentry->fcd_op);
|
||||||
tl.fc_len = cpu_to_le16(sizeof(fcd) + dlen);
|
tl.fc_len = cpu_to_le16(sizeof(fcd) + dlen);
|
||||||
ext4_fc_memcpy(sb, dst, &tl, sizeof(tl), crc);
|
ext4_fc_memcpy(sb, dst, &tl, EXT4_FC_TAG_BASE_LEN, crc);
|
||||||
dst += sizeof(tl);
|
dst += EXT4_FC_TAG_BASE_LEN;
|
||||||
ext4_fc_memcpy(sb, dst, &fcd, sizeof(fcd), crc);
|
ext4_fc_memcpy(sb, dst, &fcd, sizeof(fcd), crc);
|
||||||
dst += sizeof(fcd);
|
dst += sizeof(fcd);
|
||||||
ext4_fc_memcpy(sb, dst, fc_dentry->fcd_name.name, dlen, crc);
|
ext4_fc_memcpy(sb, dst, fc_dentry->fcd_name.name, dlen, crc);
|
||||||
@ -868,13 +868,13 @@ static int ext4_fc_write_inode(struct inode *inode, u32 *crc)
|
|||||||
|
|
||||||
ret = -ECANCELED;
|
ret = -ECANCELED;
|
||||||
dst = ext4_fc_reserve_space(inode->i_sb,
|
dst = ext4_fc_reserve_space(inode->i_sb,
|
||||||
sizeof(tl) + inode_len + sizeof(fc_inode.fc_ino), crc);
|
EXT4_FC_TAG_BASE_LEN + inode_len + sizeof(fc_inode.fc_ino), crc);
|
||||||
if (!dst)
|
if (!dst)
|
||||||
goto err;
|
goto err;
|
||||||
|
|
||||||
if (!ext4_fc_memcpy(inode->i_sb, dst, &tl, sizeof(tl), crc))
|
if (!ext4_fc_memcpy(inode->i_sb, dst, &tl, EXT4_FC_TAG_BASE_LEN, crc))
|
||||||
goto err;
|
goto err;
|
||||||
dst += sizeof(tl);
|
dst += EXT4_FC_TAG_BASE_LEN;
|
||||||
if (!ext4_fc_memcpy(inode->i_sb, dst, &fc_inode, sizeof(fc_inode), crc))
|
if (!ext4_fc_memcpy(inode->i_sb, dst, &fc_inode, sizeof(fc_inode), crc))
|
||||||
goto err;
|
goto err;
|
||||||
dst += sizeof(fc_inode);
|
dst += sizeof(fc_inode);
|
||||||
@ -2026,9 +2026,10 @@ static int ext4_fc_replay_scan(journal_t *journal,
|
|||||||
}
|
}
|
||||||
|
|
||||||
state->fc_replay_expected_off++;
|
state->fc_replay_expected_off++;
|
||||||
for (cur = start; cur < end; cur = cur + sizeof(tl) + le16_to_cpu(tl.fc_len)) {
|
for (cur = start; cur < end;
|
||||||
memcpy(&tl, cur, sizeof(tl));
|
cur = cur + EXT4_FC_TAG_BASE_LEN + le16_to_cpu(tl.fc_len)) {
|
||||||
val = cur + sizeof(tl);
|
memcpy(&tl, cur, EXT4_FC_TAG_BASE_LEN);
|
||||||
|
val = cur + EXT4_FC_TAG_BASE_LEN;
|
||||||
ext4_debug("Scan phase, tag:%s, blk %lld\n",
|
ext4_debug("Scan phase, tag:%s, blk %lld\n",
|
||||||
tag2str(le16_to_cpu(tl.fc_tag)), bh->b_blocknr);
|
tag2str(le16_to_cpu(tl.fc_tag)), bh->b_blocknr);
|
||||||
switch (le16_to_cpu(tl.fc_tag)) {
|
switch (le16_to_cpu(tl.fc_tag)) {
|
||||||
@ -2051,13 +2052,13 @@ static int ext4_fc_replay_scan(journal_t *journal,
|
|||||||
case EXT4_FC_TAG_PAD:
|
case EXT4_FC_TAG_PAD:
|
||||||
state->fc_cur_tag++;
|
state->fc_cur_tag++;
|
||||||
state->fc_crc = ext4_chksum(sbi, state->fc_crc, cur,
|
state->fc_crc = ext4_chksum(sbi, state->fc_crc, cur,
|
||||||
sizeof(tl) + le16_to_cpu(tl.fc_len));
|
EXT4_FC_TAG_BASE_LEN + le16_to_cpu(tl.fc_len));
|
||||||
break;
|
break;
|
||||||
case EXT4_FC_TAG_TAIL:
|
case EXT4_FC_TAG_TAIL:
|
||||||
state->fc_cur_tag++;
|
state->fc_cur_tag++;
|
||||||
memcpy(&tail, val, sizeof(tail));
|
memcpy(&tail, val, sizeof(tail));
|
||||||
state->fc_crc = ext4_chksum(sbi, state->fc_crc, cur,
|
state->fc_crc = ext4_chksum(sbi, state->fc_crc, cur,
|
||||||
sizeof(tl) +
|
EXT4_FC_TAG_BASE_LEN +
|
||||||
offsetof(struct ext4_fc_tail,
|
offsetof(struct ext4_fc_tail,
|
||||||
fc_crc));
|
fc_crc));
|
||||||
if (le32_to_cpu(tail.fc_tid) == expected_tid &&
|
if (le32_to_cpu(tail.fc_tid) == expected_tid &&
|
||||||
@ -2084,7 +2085,7 @@ static int ext4_fc_replay_scan(journal_t *journal,
|
|||||||
}
|
}
|
||||||
state->fc_cur_tag++;
|
state->fc_cur_tag++;
|
||||||
state->fc_crc = ext4_chksum(sbi, state->fc_crc, cur,
|
state->fc_crc = ext4_chksum(sbi, state->fc_crc, cur,
|
||||||
sizeof(tl) + le16_to_cpu(tl.fc_len));
|
EXT4_FC_TAG_BASE_LEN + le16_to_cpu(tl.fc_len));
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
ret = state->fc_replay_num_tags ?
|
ret = state->fc_replay_num_tags ?
|
||||||
@ -2139,9 +2140,10 @@ static int ext4_fc_replay(journal_t *journal, struct buffer_head *bh,
|
|||||||
start = (u8 *)bh->b_data;
|
start = (u8 *)bh->b_data;
|
||||||
end = (__u8 *)bh->b_data + journal->j_blocksize - 1;
|
end = (__u8 *)bh->b_data + journal->j_blocksize - 1;
|
||||||
|
|
||||||
for (cur = start; cur < end; cur = cur + sizeof(tl) + le16_to_cpu(tl.fc_len)) {
|
for (cur = start; cur < end;
|
||||||
memcpy(&tl, cur, sizeof(tl));
|
cur = cur + EXT4_FC_TAG_BASE_LEN + le16_to_cpu(tl.fc_len)) {
|
||||||
val = cur + sizeof(tl);
|
memcpy(&tl, cur, EXT4_FC_TAG_BASE_LEN);
|
||||||
|
val = cur + EXT4_FC_TAG_BASE_LEN;
|
||||||
|
|
||||||
if (state->fc_replay_num_tags == 0) {
|
if (state->fc_replay_num_tags == 0) {
|
||||||
ret = JBD2_FC_REPLAY_STOP;
|
ret = JBD2_FC_REPLAY_STOP;
|
||||||
|
@ -70,6 +70,9 @@ struct ext4_fc_tail {
|
|||||||
__le32 fc_crc;
|
__le32 fc_crc;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/* Tag base length */
|
||||||
|
#define EXT4_FC_TAG_BASE_LEN (sizeof(struct ext4_fc_tl))
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Fast commit status codes
|
* Fast commit status codes
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user