Skip to content

Commit be665a4

Browse files
Christoph Hellwigcmaiolino
authored andcommitted
xfs: don't use xlog_in_core_2_t in struct xlog_in_core
Most accessed to the on-disk log record header are for the original xlog_rec_header. Make that the main structure, and case for the single remaining place using other union legs. This prepares for removing xlog_in_core_2_t entirely. Signed-off-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Darrick J. Wong <djwong@kernel.org> Reviewed-by: Carlos Maiolino <cmaiolino@redhat.com> Signed-off-by: Carlos Maiolino <cem@kernel.org>
1 parent 899b7ee commit be665a4

4 files changed

Lines changed: 44 additions & 47 deletions

File tree

fs/xfs/xfs_log.c

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -534,8 +534,8 @@ xlog_state_release_iclog(
534534
*/
535535
if ((iclog->ic_state == XLOG_STATE_WANT_SYNC ||
536536
(iclog->ic_flags & XLOG_ICL_NEED_FUA)) &&
537-
!iclog->ic_header.h_tail_lsn) {
538-
iclog->ic_header.h_tail_lsn =
537+
!iclog->ic_header->h_tail_lsn) {
538+
iclog->ic_header->h_tail_lsn =
539539
cpu_to_be64(atomic64_read(&log->l_tail_lsn));
540540
}
541541

@@ -1457,11 +1457,11 @@ xlog_alloc_log(
14571457
iclog->ic_prev = prev_iclog;
14581458
prev_iclog = iclog;
14591459

1460-
iclog->ic_data = kvzalloc(log->l_iclog_size,
1460+
iclog->ic_header = kvzalloc(log->l_iclog_size,
14611461
GFP_KERNEL | __GFP_RETRY_MAYFAIL);
1462-
if (!iclog->ic_data)
1462+
if (!iclog->ic_header)
14631463
goto out_free_iclog;
1464-
head = &iclog->ic_header;
1464+
head = iclog->ic_header;
14651465
memset(head, 0, sizeof(xlog_rec_header_t));
14661466
head->h_magicno = cpu_to_be32(XLOG_HEADER_MAGIC_NUM);
14671467
head->h_version = cpu_to_be32(
@@ -1476,7 +1476,7 @@ xlog_alloc_log(
14761476
iclog->ic_log = log;
14771477
atomic_set(&iclog->ic_refcnt, 0);
14781478
INIT_LIST_HEAD(&iclog->ic_callbacks);
1479-
iclog->ic_datap = (void *)iclog->ic_data + log->l_iclog_hsize;
1479+
iclog->ic_datap = (void *)iclog->ic_header + log->l_iclog_hsize;
14801480

14811481
init_waitqueue_head(&iclog->ic_force_wait);
14821482
init_waitqueue_head(&iclog->ic_write_wait);
@@ -1504,7 +1504,7 @@ xlog_alloc_log(
15041504
out_free_iclog:
15051505
for (iclog = log->l_iclog; iclog; iclog = prev_iclog) {
15061506
prev_iclog = iclog->ic_next;
1507-
kvfree(iclog->ic_data);
1507+
kvfree(iclog->ic_header);
15081508
kfree(iclog);
15091509
if (prev_iclog == log->l_iclog)
15101510
break;
@@ -1524,7 +1524,7 @@ xlog_pack_data(
15241524
struct xlog_in_core *iclog,
15251525
int roundoff)
15261526
{
1527-
struct xlog_rec_header *rhead = &iclog->ic_header;
1527+
struct xlog_rec_header *rhead = iclog->ic_header;
15281528
__be32 cycle_lsn = CYCLE_LSN_DISK(rhead->h_lsn);
15291529
char *dp = iclog->ic_datap;
15301530
int i;
@@ -1536,7 +1536,7 @@ xlog_pack_data(
15361536
}
15371537

15381538
if (xfs_has_logv2(log->l_mp)) {
1539-
xlog_in_core_2_t *xhdr = iclog->ic_data;
1539+
xlog_in_core_2_t *xhdr = (xlog_in_core_2_t *)iclog->ic_header;
15401540

15411541
for (i = 1; i < log->l_iclog_heads; i++)
15421542
xhdr[i].hic_xheader.xh_cycle = cycle_lsn;
@@ -1658,11 +1658,11 @@ xlog_write_iclog(
16581658

16591659
iclog->ic_flags &= ~(XLOG_ICL_NEED_FLUSH | XLOG_ICL_NEED_FUA);
16601660

1661-
if (is_vmalloc_addr(iclog->ic_data)) {
1662-
if (!bio_add_vmalloc(&iclog->ic_bio, iclog->ic_data, count))
1661+
if (is_vmalloc_addr(iclog->ic_header)) {
1662+
if (!bio_add_vmalloc(&iclog->ic_bio, iclog->ic_header, count))
16631663
goto shutdown;
16641664
} else {
1665-
bio_add_virt_nofail(&iclog->ic_bio, iclog->ic_data, count);
1665+
bio_add_virt_nofail(&iclog->ic_bio, iclog->ic_header, count);
16661666
}
16671667

16681668
/*
@@ -1791,19 +1791,19 @@ xlog_sync(
17911791
size = iclog->ic_offset;
17921792
if (xfs_has_logv2(log->l_mp))
17931793
size += roundoff;
1794-
iclog->ic_header.h_len = cpu_to_be32(size);
1794+
iclog->ic_header->h_len = cpu_to_be32(size);
17951795

17961796
XFS_STATS_INC(log->l_mp, xs_log_writes);
17971797
XFS_STATS_ADD(log->l_mp, xs_log_blocks, BTOBB(count));
17981798

1799-
bno = BLOCK_LSN(be64_to_cpu(iclog->ic_header.h_lsn));
1799+
bno = BLOCK_LSN(be64_to_cpu(iclog->ic_header->h_lsn));
18001800

18011801
/* Do we need to split this write into 2 parts? */
18021802
if (bno + BTOBB(count) > log->l_logBBsize)
1803-
xlog_split_iclog(log, &iclog->ic_header, bno, count);
1803+
xlog_split_iclog(log, iclog->ic_header, bno, count);
18041804

18051805
/* calculcate the checksum */
1806-
iclog->ic_header.h_crc = xlog_cksum(log, &iclog->ic_header,
1806+
iclog->ic_header->h_crc = xlog_cksum(log, iclog->ic_header,
18071807
iclog->ic_datap, XLOG_REC_SIZE, size);
18081808
/*
18091809
* Intentionally corrupt the log record CRC based on the error injection
@@ -1814,11 +1814,11 @@ xlog_sync(
18141814
*/
18151815
#ifdef DEBUG
18161816
if (XFS_TEST_ERROR(log->l_mp, XFS_ERRTAG_LOG_BAD_CRC)) {
1817-
iclog->ic_header.h_crc &= cpu_to_le32(0xAAAAAAAA);
1817+
iclog->ic_header->h_crc &= cpu_to_le32(0xAAAAAAAA);
18181818
iclog->ic_fail_crc = true;
18191819
xfs_warn(log->l_mp,
18201820
"Intentionally corrupted log record at LSN 0x%llx. Shutdown imminent.",
1821-
be64_to_cpu(iclog->ic_header.h_lsn));
1821+
be64_to_cpu(iclog->ic_header->h_lsn));
18221822
}
18231823
#endif
18241824
xlog_verify_iclog(log, iclog, count);
@@ -1845,7 +1845,7 @@ xlog_dealloc_log(
18451845
iclog = log->l_iclog;
18461846
for (i = 0; i < log->l_iclog_bufs; i++) {
18471847
next_iclog = iclog->ic_next;
1848-
kvfree(iclog->ic_data);
1848+
kvfree(iclog->ic_header);
18491849
kfree(iclog);
18501850
iclog = next_iclog;
18511851
}
@@ -1867,7 +1867,7 @@ xlog_state_finish_copy(
18671867
{
18681868
lockdep_assert_held(&log->l_icloglock);
18691869

1870-
be32_add_cpu(&iclog->ic_header.h_num_logops, record_cnt);
1870+
be32_add_cpu(&iclog->ic_header->h_num_logops, record_cnt);
18711871
iclog->ic_offset += copy_bytes;
18721872
}
18731873

@@ -2290,7 +2290,7 @@ xlog_state_activate_iclog(
22902290
* We don't need to cover the dummy.
22912291
*/
22922292
if (*iclogs_changed == 0 &&
2293-
iclog->ic_header.h_num_logops == cpu_to_be32(XLOG_COVER_OPS)) {
2293+
iclog->ic_header->h_num_logops == cpu_to_be32(XLOG_COVER_OPS)) {
22942294
*iclogs_changed = 1;
22952295
} else {
22962296
/*
@@ -2302,11 +2302,11 @@ xlog_state_activate_iclog(
23022302

23032303
iclog->ic_state = XLOG_STATE_ACTIVE;
23042304
iclog->ic_offset = 0;
2305-
iclog->ic_header.h_num_logops = 0;
2306-
memset(iclog->ic_header.h_cycle_data, 0,
2307-
sizeof(iclog->ic_header.h_cycle_data));
2308-
iclog->ic_header.h_lsn = 0;
2309-
iclog->ic_header.h_tail_lsn = 0;
2305+
iclog->ic_header->h_num_logops = 0;
2306+
memset(iclog->ic_header->h_cycle_data, 0,
2307+
sizeof(iclog->ic_header->h_cycle_data));
2308+
iclog->ic_header->h_lsn = 0;
2309+
iclog->ic_header->h_tail_lsn = 0;
23102310
}
23112311

23122312
/*
@@ -2398,7 +2398,7 @@ xlog_get_lowest_lsn(
23982398
iclog->ic_state == XLOG_STATE_DIRTY)
23992399
continue;
24002400

2401-
lsn = be64_to_cpu(iclog->ic_header.h_lsn);
2401+
lsn = be64_to_cpu(iclog->ic_header->h_lsn);
24022402
if ((lsn && !lowest_lsn) || XFS_LSN_CMP(lsn, lowest_lsn) < 0)
24032403
lowest_lsn = lsn;
24042404
} while ((iclog = iclog->ic_next) != log->l_iclog);
@@ -2433,7 +2433,7 @@ xlog_state_iodone_process_iclog(
24332433
* If this is not the lowest lsn iclog, then we will leave it
24342434
* for another completion to process.
24352435
*/
2436-
header_lsn = be64_to_cpu(iclog->ic_header.h_lsn);
2436+
header_lsn = be64_to_cpu(iclog->ic_header->h_lsn);
24372437
lowest_lsn = xlog_get_lowest_lsn(log);
24382438
if (lowest_lsn && XFS_LSN_CMP(lowest_lsn, header_lsn) < 0)
24392439
return false;
@@ -2616,7 +2616,7 @@ xlog_state_get_iclog_space(
26162616
goto restart;
26172617
}
26182618

2619-
head = &iclog->ic_header;
2619+
head = iclog->ic_header;
26202620

26212621
atomic_inc(&iclog->ic_refcnt); /* prevents sync */
26222622
log_offset = iclog->ic_offset;
@@ -2781,7 +2781,7 @@ xlog_state_switch_iclogs(
27812781
if (!eventual_size)
27822782
eventual_size = iclog->ic_offset;
27832783
iclog->ic_state = XLOG_STATE_WANT_SYNC;
2784-
iclog->ic_header.h_prev_block = cpu_to_be32(log->l_prev_block);
2784+
iclog->ic_header->h_prev_block = cpu_to_be32(log->l_prev_block);
27852785
log->l_prev_block = log->l_curr_block;
27862786
log->l_prev_cycle = log->l_curr_cycle;
27872787

@@ -2825,7 +2825,7 @@ xlog_force_and_check_iclog(
28252825
struct xlog_in_core *iclog,
28262826
bool *completed)
28272827
{
2828-
xfs_lsn_t lsn = be64_to_cpu(iclog->ic_header.h_lsn);
2828+
xfs_lsn_t lsn = be64_to_cpu(iclog->ic_header->h_lsn);
28292829
int error;
28302830

28312831
*completed = false;
@@ -2837,7 +2837,7 @@ xlog_force_and_check_iclog(
28372837
* If the iclog has already been completed and reused the header LSN
28382838
* will have been rewritten by completion
28392839
*/
2840-
if (be64_to_cpu(iclog->ic_header.h_lsn) != lsn)
2840+
if (be64_to_cpu(iclog->ic_header->h_lsn) != lsn)
28412841
*completed = true;
28422842
return 0;
28432843
}
@@ -2970,7 +2970,7 @@ xlog_force_lsn(
29702970
goto out_error;
29712971

29722972
iclog = log->l_iclog;
2973-
while (be64_to_cpu(iclog->ic_header.h_lsn) != lsn) {
2973+
while (be64_to_cpu(iclog->ic_header->h_lsn) != lsn) {
29742974
trace_xlog_iclog_force_lsn(iclog, _RET_IP_);
29752975
iclog = iclog->ic_next;
29762976
if (iclog == log->l_iclog)
@@ -3236,7 +3236,7 @@ xlog_verify_dump_tail(
32363236
{
32373237
xfs_alert(log->l_mp,
32383238
"ran out of log space tail 0x%llx/0x%llx, head lsn 0x%llx, head 0x%x/0x%x, prev head 0x%x/0x%x",
3239-
iclog ? be64_to_cpu(iclog->ic_header.h_tail_lsn) : -1,
3239+
iclog ? be64_to_cpu(iclog->ic_header->h_tail_lsn) : -1,
32403240
atomic64_read(&log->l_tail_lsn),
32413241
log->l_ailp->ail_head_lsn,
32423242
log->l_curr_cycle, log->l_curr_block,
@@ -3255,7 +3255,7 @@ xlog_verify_tail_lsn(
32553255
struct xlog *log,
32563256
struct xlog_in_core *iclog)
32573257
{
3258-
xfs_lsn_t tail_lsn = be64_to_cpu(iclog->ic_header.h_tail_lsn);
3258+
xfs_lsn_t tail_lsn = be64_to_cpu(iclog->ic_header->h_tail_lsn);
32593259
int blocks;
32603260

32613261
if (CYCLE_LSN(tail_lsn) == log->l_prev_cycle) {
@@ -3309,7 +3309,7 @@ xlog_verify_iclog(
33093309
struct xlog_in_core *iclog,
33103310
int count)
33113311
{
3312-
struct xlog_rec_header *rhead = &iclog->ic_header;
3312+
struct xlog_rec_header *rhead = iclog->ic_header;
33133313
xlog_in_core_t *icptr;
33143314
void *base_ptr, *ptr;
33153315
ptrdiff_t field_offset;
@@ -3507,7 +3507,7 @@ xlog_iclogs_empty(
35073507
/* endianness does not matter here, zero is zero in
35083508
* any language.
35093509
*/
3510-
if (iclog->ic_header.h_num_logops)
3510+
if (iclog->ic_header->h_num_logops)
35113511
return 0;
35123512
iclog = iclog->ic_next;
35133513
} while (iclog != log->l_iclog);

fs/xfs/xfs_log_cil.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -940,7 +940,7 @@ xlog_cil_set_ctx_write_state(
940940
struct xlog_in_core *iclog)
941941
{
942942
struct xfs_cil *cil = ctx->cil;
943-
xfs_lsn_t lsn = be64_to_cpu(iclog->ic_header.h_lsn);
943+
xfs_lsn_t lsn = be64_to_cpu(iclog->ic_header->h_lsn);
944944

945945
ASSERT(!ctx->commit_lsn);
946946
if (!ctx->start_lsn) {
@@ -1458,9 +1458,9 @@ xlog_cil_push_work(
14581458
*/
14591459
spin_lock(&log->l_icloglock);
14601460
if (ctx->start_lsn != ctx->commit_lsn) {
1461-
xfs_lsn_t plsn;
1461+
xfs_lsn_t plsn = be64_to_cpu(
1462+
ctx->commit_iclog->ic_prev->ic_header->h_lsn);
14621463

1463-
plsn = be64_to_cpu(ctx->commit_iclog->ic_prev->ic_header.h_lsn);
14641464
if (plsn && XFS_LSN_CMP(plsn, ctx->commit_lsn) < 0) {
14651465
/*
14661466
* Waiting on ic_force_wait orders the completion of

fs/xfs/xfs_log_priv.h

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -158,10 +158,8 @@ struct xlog_ticket {
158158
};
159159

160160
/*
161-
* - A log record header is 512 bytes. There is plenty of room to grow the
162-
* xlog_rec_header_t into the reserved space.
163-
* - ic_data follows, so a write to disk can start at the beginning of
164-
* the iclog.
161+
* In-core log structure.
162+
*
165163
* - ic_forcewait is used to implement synchronous forcing of the iclog to disk.
166164
* - ic_next is the pointer to the next iclog in the ring.
167165
* - ic_log is a pointer back to the global log structure.
@@ -198,8 +196,7 @@ typedef struct xlog_in_core {
198196

199197
/* reference counts need their own cacheline */
200198
atomic_t ic_refcnt ____cacheline_aligned_in_smp;
201-
xlog_in_core_2_t *ic_data;
202-
#define ic_header ic_data->hic_header
199+
struct xlog_rec_header *ic_header;
203200
#ifdef DEBUG
204201
bool ic_fail_crc : 1;
205202
#endif

fs/xfs/xfs_trace.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4932,7 +4932,7 @@ DECLARE_EVENT_CLASS(xlog_iclog_class,
49324932
__entry->refcount = atomic_read(&iclog->ic_refcnt);
49334933
__entry->offset = iclog->ic_offset;
49344934
__entry->flags = iclog->ic_flags;
4935-
__entry->lsn = be64_to_cpu(iclog->ic_header.h_lsn);
4935+
__entry->lsn = be64_to_cpu(iclog->ic_header->h_lsn);
49364936
__entry->caller_ip = caller_ip;
49374937
),
49384938
TP_printk("dev %d:%d state %s refcnt %d offset %u lsn 0x%llx flags %s caller %pS",

0 commit comments

Comments
 (0)