Commit cd00158c authored by Darrick J. Wong's avatar Darrick J. Wong Committed by Dave Chinner

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: default avatarDarrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: default avatarDave Chinner <dchinner@redhat.com>
Signed-off-by: default avatarDave Chinner <david@fromorbit.com>
parent ea78d808
...@@ -647,9 +647,17 @@ struct xfs_rui_log_format { ...@@ -647,9 +647,17 @@ struct xfs_rui_log_format {
__uint16_t rui_size; /* size of this item */ __uint16_t rui_size; /* size of this item */
__uint32_t rui_nextents; /* # extents to free */ __uint32_t rui_nextents; /* # extents to free */
__uint64_t rui_id; /* rui identifier */ __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 * 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 * log. The rud_extents array is a variable size array whose
......
...@@ -51,28 +51,16 @@ xfs_rui_item_free( ...@@ -51,28 +51,16 @@ xfs_rui_item_free(
kmem_zone_free(xfs_rui_zone, ruip); 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 STATIC void
xfs_rui_item_size( xfs_rui_item_size(
struct xfs_log_item *lip, struct xfs_log_item *lip,
int *nvecs, int *nvecs,
int *nbytes) int *nbytes)
{ {
struct xfs_rui_log_item *ruip = RUI_ITEM(lip);
*nvecs += 1; *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( ...@@ -97,7 +85,7 @@ xfs_rui_item_format(
ruip->rui_format.rui_size = 1; ruip->rui_format.rui_size = 1;
xlog_copy_iovec(lv, &vecp, XLOG_REG_TYPE_RUI_FORMAT, &ruip->rui_format, 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( ...@@ -205,16 +193,12 @@ xfs_rui_init(
{ {
struct xfs_rui_log_item *ruip; struct xfs_rui_log_item *ruip;
uint size;
ASSERT(nextents > 0); ASSERT(nextents > 0);
if (nextents > XFS_RUI_MAX_FAST_EXTENTS) { if (nextents > XFS_RUI_MAX_FAST_EXTENTS)
size = (uint)(sizeof(struct xfs_rui_log_item) + ruip = kmem_zalloc(xfs_rui_log_item_sizeof(nextents), KM_SLEEP);
((nextents - 1) * sizeof(struct xfs_map_extent))); else
ruip = kmem_zalloc(size, KM_SLEEP);
} else {
ruip = kmem_zone_zalloc(xfs_rui_zone, KM_SLEEP); ruip = kmem_zone_zalloc(xfs_rui_zone, KM_SLEEP);
}
xfs_log_item_init(mp, &ruip->rui_item, XFS_LI_RUI, &xfs_rui_item_ops); xfs_log_item_init(mp, &ruip->rui_item, XFS_LI_RUI, &xfs_rui_item_ops);
ruip->rui_format.rui_nextents = nextents; ruip->rui_format.rui_nextents = nextents;
...@@ -239,14 +223,12 @@ xfs_rui_copy_format( ...@@ -239,14 +223,12 @@ xfs_rui_copy_format(
uint len; uint len;
src_rui_fmt = buf->i_addr; src_rui_fmt = buf->i_addr;
len = sizeof(struct xfs_rui_log_format) + len = xfs_rui_log_format_sizeof(src_rui_fmt->rui_nextents);
(src_rui_fmt->rui_nextents - 1) *
sizeof(struct xfs_map_extent);
if (buf->i_len != len) if (buf->i_len != len)
return -EFSCORRUPTED; return -EFSCORRUPTED;
memcpy((char *)dst_rui_fmt, (char *)src_rui_fmt, len); memcpy(dst_rui_fmt, src_rui_fmt, len);
return 0; return 0;
} }
......
...@@ -70,6 +70,14 @@ struct xfs_rui_log_item { ...@@ -70,6 +70,14 @@ struct xfs_rui_log_item {
struct xfs_rui_log_format rui_format; 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 * 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. * some rmapbt updates mentioned in an earlier rui item have been performed.
......
...@@ -1782,9 +1782,8 @@ xfs_init_zones(void) ...@@ -1782,9 +1782,8 @@ xfs_init_zones(void)
if (!xfs_rud_zone) if (!xfs_rud_zone)
goto out_destroy_icreate_zone; goto out_destroy_icreate_zone;
xfs_rui_zone = kmem_zone_init((sizeof(struct xfs_rui_log_item) + xfs_rui_zone = kmem_zone_init(
((XFS_RUI_MAX_FAST_EXTENTS - 1) * xfs_rui_log_item_sizeof(XFS_RUI_MAX_FAST_EXTENTS),
sizeof(struct xfs_map_extent))),
"xfs_rui_item"); "xfs_rui_item");
if (!xfs_rui_zone) if (!xfs_rui_zone)
goto out_destroy_rud_zone; goto out_destroy_rud_zone;
......
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