Commit 56316a0d authored by Darrick J. Wong's avatar Darrick J. Wong Committed by Theodore Ts'o

jbd2: clean up feature test macros with predicate functions

Create separate predicate functions to test/set/clear feature flags,
thereby replacing the wordy old macros.  Furthermore, clean out the
places where we open-coded feature tests.
Signed-off-by: default avatarDarrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: default avatarTheodore Ts'o <tytso@mit.edu>
parent e2b911c5
...@@ -142,8 +142,7 @@ static int journal_submit_commit_record(journal_t *journal, ...@@ -142,8 +142,7 @@ static int journal_submit_commit_record(journal_t *journal,
tmp->h_commit_sec = cpu_to_be64(now.tv_sec); tmp->h_commit_sec = cpu_to_be64(now.tv_sec);
tmp->h_commit_nsec = cpu_to_be32(now.tv_nsec); tmp->h_commit_nsec = cpu_to_be32(now.tv_nsec);
if (JBD2_HAS_COMPAT_FEATURE(journal, if (jbd2_has_feature_checksum(journal)) {
JBD2_FEATURE_COMPAT_CHECKSUM)) {
tmp->h_chksum_type = JBD2_CRC32_CHKSUM; tmp->h_chksum_type = JBD2_CRC32_CHKSUM;
tmp->h_chksum_size = JBD2_CRC32_CHKSUM_SIZE; tmp->h_chksum_size = JBD2_CRC32_CHKSUM_SIZE;
tmp->h_chksum[0] = cpu_to_be32(crc32_sum); tmp->h_chksum[0] = cpu_to_be32(crc32_sum);
...@@ -157,8 +156,7 @@ static int journal_submit_commit_record(journal_t *journal, ...@@ -157,8 +156,7 @@ static int journal_submit_commit_record(journal_t *journal,
bh->b_end_io = journal_end_buffer_io_sync; bh->b_end_io = journal_end_buffer_io_sync;
if (journal->j_flags & JBD2_BARRIER && if (journal->j_flags & JBD2_BARRIER &&
!JBD2_HAS_INCOMPAT_FEATURE(journal, !jbd2_has_feature_async_commit(journal))
JBD2_FEATURE_INCOMPAT_ASYNC_COMMIT))
ret = submit_bh(WRITE_SYNC | WRITE_FLUSH_FUA, bh); ret = submit_bh(WRITE_SYNC | WRITE_FLUSH_FUA, bh);
else else
ret = submit_bh(WRITE_SYNC, bh); ret = submit_bh(WRITE_SYNC, bh);
...@@ -317,7 +315,7 @@ static void write_tag_block(journal_t *j, journal_block_tag_t *tag, ...@@ -317,7 +315,7 @@ static void write_tag_block(journal_t *j, journal_block_tag_t *tag,
unsigned long long block) unsigned long long block)
{ {
tag->t_blocknr = cpu_to_be32(block & (u32)~0); tag->t_blocknr = cpu_to_be32(block & (u32)~0);
if (JBD2_HAS_INCOMPAT_FEATURE(j, JBD2_FEATURE_INCOMPAT_64BIT)) if (jbd2_has_feature_64bit(j))
tag->t_blocknr_high = cpu_to_be32((block >> 31) >> 1); tag->t_blocknr_high = cpu_to_be32((block >> 31) >> 1);
} }
...@@ -356,7 +354,7 @@ static void jbd2_block_tag_csum_set(journal_t *j, journal_block_tag_t *tag, ...@@ -356,7 +354,7 @@ static void jbd2_block_tag_csum_set(journal_t *j, journal_block_tag_t *tag,
bh->b_size); bh->b_size);
kunmap_atomic(addr); kunmap_atomic(addr);
if (JBD2_HAS_INCOMPAT_FEATURE(j, JBD2_FEATURE_INCOMPAT_CSUM_V3)) if (jbd2_has_feature_csum3(j))
tag3->t_checksum = cpu_to_be32(csum32); tag3->t_checksum = cpu_to_be32(csum32);
else else
tag->t_checksum = cpu_to_be16(csum32); tag->t_checksum = cpu_to_be16(csum32);
...@@ -730,8 +728,7 @@ void jbd2_journal_commit_transaction(journal_t *journal) ...@@ -730,8 +728,7 @@ void jbd2_journal_commit_transaction(journal_t *journal)
/* /*
* Compute checksum. * Compute checksum.
*/ */
if (JBD2_HAS_COMPAT_FEATURE(journal, if (jbd2_has_feature_checksum(journal)) {
JBD2_FEATURE_COMPAT_CHECKSUM)) {
crc32_sum = crc32_sum =
jbd2_checksum_data(crc32_sum, bh); jbd2_checksum_data(crc32_sum, bh);
} }
...@@ -797,8 +794,7 @@ void jbd2_journal_commit_transaction(journal_t *journal) ...@@ -797,8 +794,7 @@ void jbd2_journal_commit_transaction(journal_t *journal)
blkdev_issue_flush(journal->j_fs_dev, GFP_NOFS, NULL); blkdev_issue_flush(journal->j_fs_dev, GFP_NOFS, NULL);
/* Done it all: now write the commit record asynchronously. */ /* Done it all: now write the commit record asynchronously. */
if (JBD2_HAS_INCOMPAT_FEATURE(journal, if (jbd2_has_feature_async_commit(journal)) {
JBD2_FEATURE_INCOMPAT_ASYNC_COMMIT)) {
err = journal_submit_commit_record(journal, commit_transaction, err = journal_submit_commit_record(journal, commit_transaction,
&cbh, crc32_sum); &cbh, crc32_sum);
if (err) if (err)
...@@ -889,8 +885,7 @@ void jbd2_journal_commit_transaction(journal_t *journal) ...@@ -889,8 +885,7 @@ void jbd2_journal_commit_transaction(journal_t *journal)
commit_transaction->t_state = T_COMMIT_JFLUSH; commit_transaction->t_state = T_COMMIT_JFLUSH;
write_unlock(&journal->j_state_lock); write_unlock(&journal->j_state_lock);
if (!JBD2_HAS_INCOMPAT_FEATURE(journal, if (!jbd2_has_feature_async_commit(journal)) {
JBD2_FEATURE_INCOMPAT_ASYNC_COMMIT)) {
err = journal_submit_commit_record(journal, commit_transaction, err = journal_submit_commit_record(journal, commit_transaction,
&cbh, crc32_sum); &cbh, crc32_sum);
if (err) if (err)
...@@ -898,8 +893,7 @@ void jbd2_journal_commit_transaction(journal_t *journal) ...@@ -898,8 +893,7 @@ void jbd2_journal_commit_transaction(journal_t *journal)
} }
if (cbh) if (cbh)
err = journal_wait_on_commit_record(journal, cbh); err = journal_wait_on_commit_record(journal, cbh);
if (JBD2_HAS_INCOMPAT_FEATURE(journal, if (jbd2_has_feature_async_commit(journal) &&
JBD2_FEATURE_INCOMPAT_ASYNC_COMMIT) &&
journal->j_flags & JBD2_BARRIER) { journal->j_flags & JBD2_BARRIER) {
blkdev_issue_flush(journal->j_dev, GFP_NOFS, NULL); blkdev_issue_flush(journal->j_dev, GFP_NOFS, NULL);
} }
......
...@@ -1523,8 +1523,8 @@ static int journal_get_superblock(journal_t *journal) ...@@ -1523,8 +1523,8 @@ static int journal_get_superblock(journal_t *journal)
goto out; goto out;
} }
if (JBD2_HAS_INCOMPAT_FEATURE(journal, JBD2_FEATURE_INCOMPAT_CSUM_V2) && if (jbd2_has_feature_csum2(journal) &&
JBD2_HAS_INCOMPAT_FEATURE(journal, JBD2_FEATURE_INCOMPAT_CSUM_V3)) { jbd2_has_feature_csum3(journal)) {
/* Can't have checksum v2 and v3 at the same time! */ /* Can't have checksum v2 and v3 at the same time! */
printk(KERN_ERR "JBD2: Can't enable checksumming v2 and v3 " printk(KERN_ERR "JBD2: Can't enable checksumming v2 and v3 "
"at the same time!\n"); "at the same time!\n");
...@@ -1532,7 +1532,7 @@ static int journal_get_superblock(journal_t *journal) ...@@ -1532,7 +1532,7 @@ static int journal_get_superblock(journal_t *journal)
} }
if (jbd2_journal_has_csum_v2or3_feature(journal) && if (jbd2_journal_has_csum_v2or3_feature(journal) &&
JBD2_HAS_COMPAT_FEATURE(journal, JBD2_FEATURE_COMPAT_CHECKSUM)) { jbd2_has_feature_checksum(journal)) {
/* Can't have checksum v1 and v2 on at the same time! */ /* Can't have checksum v1 and v2 on at the same time! */
printk(KERN_ERR "JBD2: Can't enable checksumming v1 and v2/3 " printk(KERN_ERR "JBD2: Can't enable checksumming v1 and v2/3 "
"at the same time!\n"); "at the same time!\n");
...@@ -2198,15 +2198,15 @@ size_t journal_tag_bytes(journal_t *journal) ...@@ -2198,15 +2198,15 @@ size_t journal_tag_bytes(journal_t *journal)
{ {
size_t sz; size_t sz;
if (JBD2_HAS_INCOMPAT_FEATURE(journal, JBD2_FEATURE_INCOMPAT_CSUM_V3)) if (jbd2_has_feature_csum3(journal))
return sizeof(journal_block_tag3_t); return sizeof(journal_block_tag3_t);
sz = sizeof(journal_block_tag_t); sz = sizeof(journal_block_tag_t);
if (JBD2_HAS_INCOMPAT_FEATURE(journal, JBD2_FEATURE_INCOMPAT_CSUM_V2)) if (jbd2_has_feature_csum2(journal))
sz += sizeof(__u16); sz += sizeof(__u16);
if (JBD2_HAS_INCOMPAT_FEATURE(journal, JBD2_FEATURE_INCOMPAT_64BIT)) if (jbd2_has_feature_64bit(journal))
return sz; return sz;
else else
return sz - sizeof(__u32); return sz - sizeof(__u32);
......
...@@ -342,7 +342,7 @@ static inline unsigned long long read_tag_block(journal_t *journal, ...@@ -342,7 +342,7 @@ static inline unsigned long long read_tag_block(journal_t *journal,
journal_block_tag_t *tag) journal_block_tag_t *tag)
{ {
unsigned long long block = be32_to_cpu(tag->t_blocknr); unsigned long long block = be32_to_cpu(tag->t_blocknr);
if (JBD2_HAS_INCOMPAT_FEATURE(journal, JBD2_FEATURE_INCOMPAT_64BIT)) if (jbd2_has_feature_64bit(journal))
block |= (u64)be32_to_cpu(tag->t_blocknr_high) << 32; block |= (u64)be32_to_cpu(tag->t_blocknr_high) << 32;
return block; return block;
} }
...@@ -411,7 +411,7 @@ static int jbd2_block_tag_csum_verify(journal_t *j, journal_block_tag_t *tag, ...@@ -411,7 +411,7 @@ static int jbd2_block_tag_csum_verify(journal_t *j, journal_block_tag_t *tag,
csum32 = jbd2_chksum(j, j->j_csum_seed, (__u8 *)&seq, sizeof(seq)); csum32 = jbd2_chksum(j, j->j_csum_seed, (__u8 *)&seq, sizeof(seq));
csum32 = jbd2_chksum(j, csum32, buf, j->j_blocksize); csum32 = jbd2_chksum(j, csum32, buf, j->j_blocksize);
if (JBD2_HAS_INCOMPAT_FEATURE(j, JBD2_FEATURE_INCOMPAT_CSUM_V3)) if (jbd2_has_feature_csum3(j))
return tag3->t_checksum == cpu_to_be32(csum32); return tag3->t_checksum == cpu_to_be32(csum32);
else else
return tag->t_checksum == cpu_to_be16(csum32); return tag->t_checksum == cpu_to_be16(csum32);
...@@ -538,8 +538,7 @@ static int do_one_pass(journal_t *journal, ...@@ -538,8 +538,7 @@ static int do_one_pass(journal_t *journal,
* just skip over the blocks it describes. */ * just skip over the blocks it describes. */
if (pass != PASS_REPLAY) { if (pass != PASS_REPLAY) {
if (pass == PASS_SCAN && if (pass == PASS_SCAN &&
JBD2_HAS_COMPAT_FEATURE(journal, jbd2_has_feature_checksum(journal) &&
JBD2_FEATURE_COMPAT_CHECKSUM) &&
!info->end_transaction) { !info->end_transaction) {
if (calc_chksums(journal, bh, if (calc_chksums(journal, bh,
&next_log_block, &next_log_block,
...@@ -694,8 +693,7 @@ static int do_one_pass(journal_t *journal, ...@@ -694,8 +693,7 @@ static int do_one_pass(journal_t *journal,
* much to do other than move on to the next sequence * much to do other than move on to the next sequence
* number. */ * number. */
if (pass == PASS_SCAN && if (pass == PASS_SCAN &&
JBD2_HAS_COMPAT_FEATURE(journal, jbd2_has_feature_checksum(journal)) {
JBD2_FEATURE_COMPAT_CHECKSUM)) {
int chksum_err, chksum_seen; int chksum_err, chksum_seen;
struct commit_header *cbh = struct commit_header *cbh =
(struct commit_header *)bh->b_data; (struct commit_header *)bh->b_data;
...@@ -735,8 +733,7 @@ static int do_one_pass(journal_t *journal, ...@@ -735,8 +733,7 @@ static int do_one_pass(journal_t *journal,
if (chksum_err) { if (chksum_err) {
info->end_transaction = next_commit_ID; info->end_transaction = next_commit_ID;
if (!JBD2_HAS_INCOMPAT_FEATURE(journal, if (!jbd2_has_feature_async_commit(journal)) {
JBD2_FEATURE_INCOMPAT_ASYNC_COMMIT)){
journal->j_failed_commit = journal->j_failed_commit =
next_commit_ID; next_commit_ID;
brelse(bh); brelse(bh);
...@@ -750,8 +747,7 @@ static int do_one_pass(journal_t *journal, ...@@ -750,8 +747,7 @@ static int do_one_pass(journal_t *journal,
bh->b_data)) { bh->b_data)) {
info->end_transaction = next_commit_ID; info->end_transaction = next_commit_ID;
if (!JBD2_HAS_INCOMPAT_FEATURE(journal, if (!jbd2_has_feature_async_commit(journal)) {
JBD2_FEATURE_INCOMPAT_ASYNC_COMMIT)) {
journal->j_failed_commit = journal->j_failed_commit =
next_commit_ID; next_commit_ID;
brelse(bh); brelse(bh);
...@@ -859,7 +855,7 @@ static int scan_revoke_records(journal_t *journal, struct buffer_head *bh, ...@@ -859,7 +855,7 @@ static int scan_revoke_records(journal_t *journal, struct buffer_head *bh,
return -EINVAL; return -EINVAL;
max = rcount; max = rcount;
if (JBD2_HAS_INCOMPAT_FEATURE(journal, JBD2_FEATURE_INCOMPAT_64BIT)) if (jbd2_has_feature_64bit(journal))
record_len = 8; record_len = 8;
while (offset + record_len <= max) { while (offset + record_len <= max) {
......
...@@ -589,7 +589,7 @@ static void write_one_revoke_record(journal_t *journal, ...@@ -589,7 +589,7 @@ static void write_one_revoke_record(journal_t *journal,
if (jbd2_journal_has_csum_v2or3(journal)) if (jbd2_journal_has_csum_v2or3(journal))
csum_size = sizeof(struct jbd2_journal_revoke_tail); csum_size = sizeof(struct jbd2_journal_revoke_tail);
if (JBD2_HAS_INCOMPAT_FEATURE(journal, JBD2_FEATURE_INCOMPAT_64BIT)) if (jbd2_has_feature_64bit(journal))
sz = 8; sz = 8;
else else
sz = 4; sz = 4;
...@@ -619,7 +619,7 @@ static void write_one_revoke_record(journal_t *journal, ...@@ -619,7 +619,7 @@ static void write_one_revoke_record(journal_t *journal,
*descriptorp = descriptor; *descriptorp = descriptor;
} }
if (JBD2_HAS_INCOMPAT_FEATURE(journal, JBD2_FEATURE_INCOMPAT_64BIT)) if (jbd2_has_feature_64bit(journal))
* ((__be64 *)(&descriptor->b_data[offset])) = * ((__be64 *)(&descriptor->b_data[offset])) =
cpu_to_be64(record->blocknr); cpu_to_be64(record->blocknr);
else else
......
...@@ -278,6 +278,7 @@ typedef struct journal_superblock_s ...@@ -278,6 +278,7 @@ typedef struct journal_superblock_s
/* 0x0400 */ /* 0x0400 */
} journal_superblock_t; } journal_superblock_t;
/* Use the jbd2_{has,set,clear}_feature_* helpers; these will be removed */
#define JBD2_HAS_COMPAT_FEATURE(j,mask) \ #define JBD2_HAS_COMPAT_FEATURE(j,mask) \
((j)->j_format_version >= 2 && \ ((j)->j_format_version >= 2 && \
((j)->j_superblock->s_feature_compat & cpu_to_be32((mask)))) ((j)->j_superblock->s_feature_compat & cpu_to_be32((mask))))
...@@ -296,6 +297,8 @@ typedef struct journal_superblock_s ...@@ -296,6 +297,8 @@ typedef struct journal_superblock_s
#define JBD2_FEATURE_INCOMPAT_CSUM_V2 0x00000008 #define JBD2_FEATURE_INCOMPAT_CSUM_V2 0x00000008
#define JBD2_FEATURE_INCOMPAT_CSUM_V3 0x00000010 #define JBD2_FEATURE_INCOMPAT_CSUM_V3 0x00000010
/* See "journal feature predicate functions" below */
/* Features known to this kernel version: */ /* Features known to this kernel version: */
#define JBD2_KNOWN_COMPAT_FEATURES JBD2_FEATURE_COMPAT_CHECKSUM #define JBD2_KNOWN_COMPAT_FEATURES JBD2_FEATURE_COMPAT_CHECKSUM
#define JBD2_KNOWN_ROCOMPAT_FEATURES 0 #define JBD2_KNOWN_ROCOMPAT_FEATURES 0
...@@ -1034,6 +1037,69 @@ struct journal_s ...@@ -1034,6 +1037,69 @@ struct journal_s
__u32 j_csum_seed; __u32 j_csum_seed;
}; };
/* journal feature predicate functions */
#define JBD2_FEATURE_COMPAT_FUNCS(name, flagname) \
static inline bool jbd2_has_feature_##name(journal_t *j) \
{ \
return ((j)->j_format_version >= 2 && \
((j)->j_superblock->s_feature_compat & \
cpu_to_be32(JBD2_FEATURE_COMPAT_##flagname)) != 0); \
} \
static inline void jbd2_set_feature_##name(journal_t *j) \
{ \
(j)->j_superblock->s_feature_compat |= \
cpu_to_be32(JBD2_FEATURE_COMPAT_##flagname); \
} \
static inline void jbd2_clear_feature_##name(journal_t *j) \
{ \
(j)->j_superblock->s_feature_compat &= \
~cpu_to_be32(JBD2_FEATURE_COMPAT_##flagname); \
}
#define JBD2_FEATURE_RO_COMPAT_FUNCS(name, flagname) \
static inline bool jbd2_has_feature_##name(journal_t *j) \
{ \
return ((j)->j_format_version >= 2 && \
((j)->j_superblock->s_feature_ro_compat & \
cpu_to_be32(JBD2_FEATURE_RO_COMPAT_##flagname)) != 0); \
} \
static inline void jbd2_set_feature_##name(journal_t *j) \
{ \
(j)->j_superblock->s_feature_ro_compat |= \
cpu_to_be32(JBD2_FEATURE_RO_COMPAT_##flagname); \
} \
static inline void jbd2_clear_feature_##name(journal_t *j) \
{ \
(j)->j_superblock->s_feature_ro_compat &= \
~cpu_to_be32(JBD2_FEATURE_RO_COMPAT_##flagname); \
}
#define JBD2_FEATURE_INCOMPAT_FUNCS(name, flagname) \
static inline bool jbd2_has_feature_##name(journal_t *j) \
{ \
return ((j)->j_format_version >= 2 && \
((j)->j_superblock->s_feature_incompat & \
cpu_to_be32(JBD2_FEATURE_INCOMPAT_##flagname)) != 0); \
} \
static inline void jbd2_set_feature_##name(journal_t *j) \
{ \
(j)->j_superblock->s_feature_incompat |= \
cpu_to_be32(JBD2_FEATURE_INCOMPAT_##flagname); \
} \
static inline void jbd2_clear_feature_##name(journal_t *j) \
{ \
(j)->j_superblock->s_feature_incompat &= \
~cpu_to_be32(JBD2_FEATURE_INCOMPAT_##flagname); \
}
JBD2_FEATURE_COMPAT_FUNCS(checksum, CHECKSUM)
JBD2_FEATURE_INCOMPAT_FUNCS(revoke, REVOKE)
JBD2_FEATURE_INCOMPAT_FUNCS(64bit, 64BIT)
JBD2_FEATURE_INCOMPAT_FUNCS(async_commit, ASYNC_COMMIT)
JBD2_FEATURE_INCOMPAT_FUNCS(csum2, CSUM_V2)
JBD2_FEATURE_INCOMPAT_FUNCS(csum3, CSUM_V3)
/* /*
* Journal flag definitions * Journal flag definitions
*/ */
...@@ -1340,8 +1406,7 @@ extern size_t journal_tag_bytes(journal_t *journal); ...@@ -1340,8 +1406,7 @@ extern size_t journal_tag_bytes(journal_t *journal);
static inline bool jbd2_journal_has_csum_v2or3_feature(journal_t *j) static inline bool jbd2_journal_has_csum_v2or3_feature(journal_t *j)
{ {
return JBD2_HAS_INCOMPAT_FEATURE(j, JBD2_FEATURE_INCOMPAT_CSUM_V2) || return jbd2_has_feature_csum2(j) || jbd2_has_feature_csum3(j);
JBD2_HAS_INCOMPAT_FEATURE(j, JBD2_FEATURE_INCOMPAT_CSUM_V3);
} }
static inline int jbd2_journal_has_csum_v2or3(journal_t *journal) static inline int jbd2_journal_has_csum_v2or3(journal_t *journal)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment