Skip to content

Commit 899b7ee

Browse files
Christoph Hellwigcmaiolino
authored andcommitted
xfs: add a on-disk log header cycle array accessor
Accessing the cycle arrays in the original log record header vs the extended header is messy and duplicated in multiple places. Add a xlog_cycle_data helper to abstract it out. 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 74d975e commit 899b7ee

3 files changed

Lines changed: 37 additions & 61 deletions

File tree

fs/xfs/xfs_log.c

Lines changed: 16 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1524,33 +1524,20 @@ xlog_pack_data(
15241524
struct xlog_in_core *iclog,
15251525
int roundoff)
15261526
{
1527-
int i, j, k;
1528-
int size = iclog->ic_offset + roundoff;
1529-
__be32 cycle_lsn;
1530-
char *dp;
1531-
1532-
cycle_lsn = CYCLE_LSN_DISK(iclog->ic_header.h_lsn);
1527+
struct xlog_rec_header *rhead = &iclog->ic_header;
1528+
__be32 cycle_lsn = CYCLE_LSN_DISK(rhead->h_lsn);
1529+
char *dp = iclog->ic_datap;
1530+
int i;
15331531

1534-
dp = iclog->ic_datap;
1535-
for (i = 0; i < BTOBB(size); i++) {
1536-
if (i >= XLOG_CYCLE_DATA_SIZE)
1537-
break;
1538-
iclog->ic_header.h_cycle_data[i] = *(__be32 *)dp;
1532+
for (i = 0; i < BTOBB(iclog->ic_offset + roundoff); i++) {
1533+
*xlog_cycle_data(rhead, i) = *(__be32 *)dp;
15391534
*(__be32 *)dp = cycle_lsn;
15401535
dp += BBSIZE;
15411536
}
15421537

15431538
if (xfs_has_logv2(log->l_mp)) {
15441539
xlog_in_core_2_t *xhdr = iclog->ic_data;
15451540

1546-
for ( ; i < BTOBB(size); i++) {
1547-
j = i / XLOG_CYCLE_DATA_SIZE;
1548-
k = i % XLOG_CYCLE_DATA_SIZE;
1549-
xhdr[j].hic_xheader.xh_cycle_data[k] = *(__be32 *)dp;
1550-
*(__be32 *)dp = cycle_lsn;
1551-
dp += BBSIZE;
1552-
}
1553-
15541541
for (i = 1; i < log->l_iclog_heads; i++)
15551542
xhdr[i].hic_xheader.xh_cycle = cycle_lsn;
15561543
}
@@ -3322,13 +3309,12 @@ xlog_verify_iclog(
33223309
struct xlog_in_core *iclog,
33233310
int count)
33243311
{
3325-
struct xlog_op_header *ophead;
3312+
struct xlog_rec_header *rhead = &iclog->ic_header;
33263313
xlog_in_core_t *icptr;
3327-
xlog_in_core_2_t *xhdr;
3328-
void *base_ptr, *ptr, *p;
3314+
void *base_ptr, *ptr;
33293315
ptrdiff_t field_offset;
33303316
uint8_t clientid;
3331-
int len, i, j, k, op_len;
3317+
int len, i, op_len;
33323318
int idx;
33333319

33343320
/* check validity of iclog pointers */
@@ -3342,41 +3328,30 @@ xlog_verify_iclog(
33423328
spin_unlock(&log->l_icloglock);
33433329

33443330
/* check log magic numbers */
3345-
if (iclog->ic_header.h_magicno != cpu_to_be32(XLOG_HEADER_MAGIC_NUM))
3331+
if (rhead->h_magicno != cpu_to_be32(XLOG_HEADER_MAGIC_NUM))
33463332
xfs_emerg(log->l_mp, "%s: invalid magic num", __func__);
33473333

3348-
base_ptr = ptr = &iclog->ic_header;
3349-
p = &iclog->ic_header;
3334+
base_ptr = ptr = rhead;
33503335
for (ptr += BBSIZE; ptr < base_ptr + count; ptr += BBSIZE) {
33513336
if (*(__be32 *)ptr == cpu_to_be32(XLOG_HEADER_MAGIC_NUM))
33523337
xfs_emerg(log->l_mp, "%s: unexpected magic num",
33533338
__func__);
33543339
}
33553340

33563341
/* check fields */
3357-
len = be32_to_cpu(iclog->ic_header.h_num_logops);
3342+
len = be32_to_cpu(rhead->h_num_logops);
33583343
base_ptr = ptr = iclog->ic_datap;
3359-
ophead = ptr;
3360-
xhdr = iclog->ic_data;
33613344
for (i = 0; i < len; i++) {
3362-
ophead = ptr;
3345+
struct xlog_op_header *ophead = ptr;
3346+
void *p = &ophead->oh_clientid;
33633347

33643348
/* clientid is only 1 byte */
3365-
p = &ophead->oh_clientid;
33663349
field_offset = p - base_ptr;
33673350
if (field_offset & 0x1ff) {
33683351
clientid = ophead->oh_clientid;
33693352
} else {
33703353
idx = BTOBBT((void *)&ophead->oh_clientid - iclog->ic_datap);
3371-
if (idx >= XLOG_CYCLE_DATA_SIZE) {
3372-
j = idx / XLOG_CYCLE_DATA_SIZE;
3373-
k = idx % XLOG_CYCLE_DATA_SIZE;
3374-
clientid = xlog_get_client_id(
3375-
xhdr[j].hic_xheader.xh_cycle_data[k]);
3376-
} else {
3377-
clientid = xlog_get_client_id(
3378-
iclog->ic_header.h_cycle_data[idx]);
3379-
}
3354+
clientid = xlog_get_client_id(*xlog_cycle_data(rhead, idx));
33803355
}
33813356
if (clientid != XFS_TRANSACTION && clientid != XFS_LOG) {
33823357
xfs_warn(log->l_mp,
@@ -3392,13 +3367,7 @@ xlog_verify_iclog(
33923367
op_len = be32_to_cpu(ophead->oh_len);
33933368
} else {
33943369
idx = BTOBBT((void *)&ophead->oh_len - iclog->ic_datap);
3395-
if (idx >= XLOG_CYCLE_DATA_SIZE) {
3396-
j = idx / XLOG_CYCLE_DATA_SIZE;
3397-
k = idx % XLOG_CYCLE_DATA_SIZE;
3398-
op_len = be32_to_cpu(xhdr[j].hic_xheader.xh_cycle_data[k]);
3399-
} else {
3400-
op_len = be32_to_cpu(iclog->ic_header.h_cycle_data[idx]);
3401-
}
3370+
op_len = be32_to_cpu(*xlog_cycle_data(rhead, idx));
34023371
}
34033372
ptr += sizeof(struct xlog_op_header) + op_len;
34043373
}

fs/xfs/xfs_log_priv.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -711,4 +711,22 @@ xlog_item_space(
711711
return round_up(nbytes, sizeof(uint64_t));
712712
}
713713

714+
/*
715+
* Cycles over XLOG_CYCLE_DATA_SIZE overflow into the extended header that was
716+
* added for v2 logs. Addressing for the cycles array there is off by one,
717+
* because the first batch of cycles is in the original header.
718+
*/
719+
static inline __be32 *xlog_cycle_data(struct xlog_rec_header *rhead, unsigned i)
720+
{
721+
if (i >= XLOG_CYCLE_DATA_SIZE) {
722+
xlog_in_core_2_t *xhdr = (xlog_in_core_2_t *)rhead;
723+
unsigned j = i / XLOG_CYCLE_DATA_SIZE;
724+
unsigned k = i % XLOG_CYCLE_DATA_SIZE;
725+
726+
return &xhdr[j].hic_xheader.xh_cycle_data[k];
727+
}
728+
729+
return &rhead->h_cycle_data[i];
730+
}
731+
714732
#endif /* __XFS_LOG_PRIV_H__ */

fs/xfs/xfs_log_recover.c

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2863,23 +2863,12 @@ xlog_unpack_data(
28632863
char *dp,
28642864
struct xlog *log)
28652865
{
2866-
int i, j, k;
2866+
int i;
28672867

2868-
for (i = 0; i < BTOBB(be32_to_cpu(rhead->h_len)) &&
2869-
i < XLOG_CYCLE_DATA_SIZE; i++) {
2870-
*(__be32 *)dp = *(__be32 *)&rhead->h_cycle_data[i];
2868+
for (i = 0; i < BTOBB(be32_to_cpu(rhead->h_len)); i++) {
2869+
*(__be32 *)dp = *xlog_cycle_data(rhead, i);
28712870
dp += BBSIZE;
28722871
}
2873-
2874-
if (xfs_has_logv2(log->l_mp)) {
2875-
xlog_in_core_2_t *xhdr = (xlog_in_core_2_t *)rhead;
2876-
for ( ; i < BTOBB(be32_to_cpu(rhead->h_len)); i++) {
2877-
j = i / XLOG_CYCLE_DATA_SIZE;
2878-
k = i % XLOG_CYCLE_DATA_SIZE;
2879-
*(__be32 *)dp = xhdr[j].hic_xheader.xh_cycle_data[k];
2880-
dp += BBSIZE;
2881-
}
2882-
}
28832872
}
28842873

28852874
/*

0 commit comments

Comments
 (0)