Skip to content

Commit fe985b9

Browse files
Christoph Hellwigcmaiolino
authored andcommitted
xfs: remove xlog_in_core_2_t
xlog_in_core_2_t is a really odd type, not only is it grossly misnamed because it actually is an on-disk structure, but it also reprents the actual on-disk structure in a rather odd way. A v1 or small v2 log header look like: +-----------------------+ | xlog_record | +-----------------------+ while larger v2 log headers look like: +-----------------------+ | xlog_record | +-----------------------+ | xlog_rec_ext_header | +-------------------+---+ | ..... | +-----------------------+ | xlog_rec_ext_header | +-----------------------+ I.e., the ext headers are a variable sized array at the end of the header. So instead of declaring a union of xlog_rec_header, xlog_rec_ext_header and padding to BBSIZE, add the proper padding to struct struct xlog_rec_header and struct xlog_rec_ext_header, and add a variable sized array of the latter to the former. This also exposes the somewhat unusual scope of the log checksums, which is made explicitly now by adding proper padding and macro designating the actual payload length. 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 9ed9df9 commit fe985b9

4 files changed

Lines changed: 26 additions & 35 deletions

File tree

fs/xfs/libxfs/xfs_log_format.h

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,16 @@ struct xlog_op_header {
126126
#define XLOG_FMT XLOG_FMT_LINUX_LE
127127
#endif
128128

129+
struct xlog_rec_ext_header {
130+
__be32 xh_cycle; /* write cycle of log */
131+
__be32 xh_cycle_data[XLOG_CYCLE_DATA_SIZE];
132+
__u8 xh_reserved[252];
133+
};
134+
135+
/* actual ext header payload size for checksumming */
136+
#define XLOG_REC_EXT_SIZE \
137+
offsetofend(struct xlog_rec_ext_header, xh_cycle_data)
138+
129139
typedef struct xlog_rec_header {
130140
__be32 h_magicno; /* log record (LR) identifier : 4 */
131141
__be32 h_cycle; /* write cycle of log : 4 */
@@ -161,30 +171,19 @@ typedef struct xlog_rec_header {
161171
* (little-endian) architectures.
162172
*/
163173
__u32 h_pad0;
174+
175+
__u8 h_reserved[184];
176+
struct xlog_rec_ext_header h_ext[];
164177
} xlog_rec_header_t;
165178

166179
#ifdef __i386__
167180
#define XLOG_REC_SIZE offsetofend(struct xlog_rec_header, h_size)
168-
#define XLOG_REC_SIZE_OTHER sizeof(struct xlog_rec_header)
181+
#define XLOG_REC_SIZE_OTHER offsetofend(struct xlog_rec_header, h_pad0)
169182
#else
170-
#define XLOG_REC_SIZE sizeof(struct xlog_rec_header)
183+
#define XLOG_REC_SIZE offsetofend(struct xlog_rec_header, h_pad0)
171184
#define XLOG_REC_SIZE_OTHER offsetofend(struct xlog_rec_header, h_size)
172185
#endif /* __i386__ */
173186

174-
typedef struct xlog_rec_ext_header {
175-
__be32 xh_cycle; /* write cycle of log : 4 */
176-
__be32 xh_cycle_data[XLOG_CYCLE_DATA_SIZE]; /* : 256 */
177-
} xlog_rec_ext_header_t;
178-
179-
/*
180-
* Quite misnamed, because this union lays out the actual on-disk log buffer.
181-
*/
182-
typedef union xlog_in_core2 {
183-
xlog_rec_header_t hic_header;
184-
xlog_rec_ext_header_t hic_xheader;
185-
char hic_sector[XLOG_HEADER_SIZE];
186-
} xlog_in_core_2_t;
187-
188187
/* not an on-disk structure, but needed by log recovery in userspace */
189188
struct xfs_log_iovec {
190189
void *i_addr; /* beginning address of region */

fs/xfs/libxfs/xfs_ondisk.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,9 +174,11 @@ xfs_check_ondisk_structs(void)
174174
XFS_CHECK_STRUCT_SIZE(struct xfs_rud_log_format, 16);
175175
XFS_CHECK_STRUCT_SIZE(struct xfs_map_extent, 32);
176176
XFS_CHECK_STRUCT_SIZE(struct xfs_phys_extent, 16);
177-
XFS_CHECK_STRUCT_SIZE(struct xlog_rec_header, 328);
178-
XFS_CHECK_STRUCT_SIZE(struct xlog_rec_ext_header, 260);
177+
XFS_CHECK_STRUCT_SIZE(struct xlog_rec_header, 512);
178+
XFS_CHECK_STRUCT_SIZE(struct xlog_rec_ext_header, 512);
179179

180+
XFS_CHECK_OFFSET(struct xlog_rec_header, h_reserved, 328);
181+
XFS_CHECK_OFFSET(struct xlog_rec_ext_header, xh_reserved, 260);
180182
XFS_CHECK_OFFSET(struct xfs_bui_log_format, bui_extents, 16);
181183
XFS_CHECK_OFFSET(struct xfs_cui_log_format, cui_extents, 16);
182184
XFS_CHECK_OFFSET(struct xfs_rui_log_format, rui_extents, 16);

fs/xfs/xfs_log.c

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1526,12 +1526,8 @@ xlog_pack_data(
15261526
dp += BBSIZE;
15271527
}
15281528

1529-
if (xfs_has_logv2(log->l_mp)) {
1530-
xlog_in_core_2_t *xhdr = (xlog_in_core_2_t *)iclog->ic_header;
1531-
1532-
for (i = 1; i < log->l_iclog_heads; i++)
1533-
xhdr[i].hic_xheader.xh_cycle = cycle_lsn;
1534-
}
1529+
for (i = 0; i < log->l_iclog_heads - 1; i++)
1530+
rhead->h_ext[i].xh_cycle = cycle_lsn;
15351531
}
15361532

15371533
/*
@@ -1556,16 +1552,11 @@ xlog_cksum(
15561552

15571553
/* ... then for additional cycle data for v2 logs ... */
15581554
if (xfs_has_logv2(log->l_mp)) {
1559-
union xlog_in_core2 *xhdr = (union xlog_in_core2 *)rhead;
1560-
int i;
1561-
int xheads;
1555+
int xheads, i;
15621556

1563-
xheads = DIV_ROUND_UP(size, XLOG_HEADER_CYCLE_SIZE);
1564-
1565-
for (i = 1; i < xheads; i++) {
1566-
crc = crc32c(crc, &xhdr[i].hic_xheader,
1567-
sizeof(struct xlog_rec_ext_header));
1568-
}
1557+
xheads = DIV_ROUND_UP(size, XLOG_HEADER_CYCLE_SIZE) - 1;
1558+
for (i = 0; i < xheads; i++)
1559+
crc = crc32c(crc, &rhead->h_ext[i], XLOG_REC_EXT_SIZE);
15691560
}
15701561

15711562
/* ... and finally for the payload */

fs/xfs/xfs_log_priv.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -716,11 +716,10 @@ xlog_item_space(
716716
static inline __be32 *xlog_cycle_data(struct xlog_rec_header *rhead, unsigned i)
717717
{
718718
if (i >= XLOG_CYCLE_DATA_SIZE) {
719-
xlog_in_core_2_t *xhdr = (xlog_in_core_2_t *)rhead;
720719
unsigned j = i / XLOG_CYCLE_DATA_SIZE;
721720
unsigned k = i % XLOG_CYCLE_DATA_SIZE;
722721

723-
return &xhdr[j].hic_xheader.xh_cycle_data[k];
722+
return &rhead->h_ext[j - 1].xh_cycle_data[k];
724723
}
725724

726725
return &rhead->h_cycle_data[i];

0 commit comments

Comments
 (0)