xfs: convert RUI log formats to use variable length arrays

Use variable length array declarations for RUI log items,
and replace the open coded sizeof formulae with a single function.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Signed-off-by: Dave Chinner <david@fromorbit.com>
This commit is contained in:
Darrick J. Wong 2016-09-19 10:24:27 +10:00 committed by Dave Chinner
parent ea78d80866
commit cd00158ce3
4 changed files with 28 additions and 31 deletions

View file

@ -647,9 +647,17 @@ struct xfs_rui_log_format {
__uint16_t rui_size; /* size of this item */
__uint32_t rui_nextents; /* # extents to free */
__uint64_t rui_id; /* rui identifier */
struct xfs_map_extent rui_extents[1]; /* array of extents to rmap */
struct xfs_map_extent rui_extents[]; /* array of extents to rmap */
};
static inline size_t
xfs_rui_log_format_sizeof(
unsigned int nr)
{
return sizeof(struct xfs_rui_log_format) +
nr * sizeof(struct xfs_map_extent);
}
/*
* This is the structure used to lay out an rud log item in the
* log. The rud_extents array is a variable size array whose

View file

@ -51,28 +51,16 @@ xfs_rui_item_free(
kmem_zone_free(xfs_rui_zone, ruip);
}
/*
* This returns the number of iovecs needed to log the given rui item.
* We only need 1 iovec for an rui item. It just logs the rui_log_format
* structure.
*/
static inline int
xfs_rui_item_sizeof(
struct xfs_rui_log_item *ruip)
{
return sizeof(struct xfs_rui_log_format) +
(ruip->rui_format.rui_nextents - 1) *
sizeof(struct xfs_map_extent);
}
STATIC void
xfs_rui_item_size(
struct xfs_log_item *lip,
int *nvecs,
int *nbytes)
{
struct xfs_rui_log_item *ruip = RUI_ITEM(lip);
*nvecs += 1;
*nbytes += xfs_rui_item_sizeof(RUI_ITEM(lip));
*nbytes += xfs_rui_log_format_sizeof(ruip->rui_format.rui_nextents);
}
/*
@ -97,7 +85,7 @@ xfs_rui_item_format(
ruip->rui_format.rui_size = 1;
xlog_copy_iovec(lv, &vecp, XLOG_REG_TYPE_RUI_FORMAT, &ruip->rui_format,
xfs_rui_item_sizeof(ruip));
xfs_rui_log_format_sizeof(ruip->rui_format.rui_nextents));
}
/*
@ -205,16 +193,12 @@ xfs_rui_init(
{
struct xfs_rui_log_item *ruip;
uint size;
ASSERT(nextents > 0);
if (nextents > XFS_RUI_MAX_FAST_EXTENTS) {
size = (uint)(sizeof(struct xfs_rui_log_item) +
((nextents - 1) * sizeof(struct xfs_map_extent)));
ruip = kmem_zalloc(size, KM_SLEEP);
} else {
if (nextents > XFS_RUI_MAX_FAST_EXTENTS)
ruip = kmem_zalloc(xfs_rui_log_item_sizeof(nextents), KM_SLEEP);
else
ruip = kmem_zone_zalloc(xfs_rui_zone, KM_SLEEP);
}
xfs_log_item_init(mp, &ruip->rui_item, XFS_LI_RUI, &xfs_rui_item_ops);
ruip->rui_format.rui_nextents = nextents;
@ -239,14 +223,12 @@ xfs_rui_copy_format(
uint len;
src_rui_fmt = buf->i_addr;
len = sizeof(struct xfs_rui_log_format) +
(src_rui_fmt->rui_nextents - 1) *
sizeof(struct xfs_map_extent);
len = xfs_rui_log_format_sizeof(src_rui_fmt->rui_nextents);
if (buf->i_len != len)
return -EFSCORRUPTED;
memcpy((char *)dst_rui_fmt, (char *)src_rui_fmt, len);
memcpy(dst_rui_fmt, src_rui_fmt, len);
return 0;
}

View file

@ -70,6 +70,14 @@ struct xfs_rui_log_item {
struct xfs_rui_log_format rui_format;
};
static inline size_t
xfs_rui_log_item_sizeof(
unsigned int nr)
{
return offsetof(struct xfs_rui_log_item, rui_format) +
xfs_rui_log_format_sizeof(nr);
}
/*
* This is the "rmap update done" log item. It is used to log the fact that
* some rmapbt updates mentioned in an earlier rui item have been performed.

View file

@ -1782,9 +1782,8 @@ xfs_init_zones(void)
if (!xfs_rud_zone)
goto out_destroy_icreate_zone;
xfs_rui_zone = kmem_zone_init((sizeof(struct xfs_rui_log_item) +
((XFS_RUI_MAX_FAST_EXTENTS - 1) *
sizeof(struct xfs_map_extent))),
xfs_rui_zone = kmem_zone_init(
xfs_rui_log_item_sizeof(XFS_RUI_MAX_FAST_EXTENTS),
"xfs_rui_item");
if (!xfs_rui_zone)
goto out_destroy_rud_zone;