aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDarrick J. Wong <darrick.wong@oracle.com>2016-09-18 20:24:27 -0400
committerDave Chinner <david@fromorbit.com>2016-09-18 20:24:27 -0400
commitcd00158ce34d6e2c42d8892e8499779b8ac1d2bf (patch)
treed35fb35e93820365979f4c8f8f293ab5d354b439
parentea78d80866ce375defb2fdd1c8a3aafec95e0f85 (diff)
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>
-rw-r--r--fs/xfs/libxfs/xfs_log_format.h10
-rw-r--r--fs/xfs/xfs_rmap_item.c36
-rw-r--r--fs/xfs/xfs_rmap_item.h8
-rw-r--r--fs/xfs/xfs_super.c5
4 files changed, 28 insertions, 31 deletions
diff --git a/fs/xfs/libxfs/xfs_log_format.h b/fs/xfs/libxfs/xfs_log_format.h
index a6eed43fa7cd..fc5eef85d61e 100644
--- a/fs/xfs/libxfs/xfs_log_format.h
+++ b/fs/xfs/libxfs/xfs_log_format.h
@@ -647,9 +647,17 @@ struct xfs_rui_log_format {
647 __uint16_t rui_size; /* size of this item */ 647 __uint16_t rui_size; /* size of this item */
648 __uint32_t rui_nextents; /* # extents to free */ 648 __uint32_t rui_nextents; /* # extents to free */
649 __uint64_t rui_id; /* rui identifier */ 649 __uint64_t rui_id; /* rui identifier */
650 struct xfs_map_extent rui_extents[1]; /* array of extents to rmap */ 650 struct xfs_map_extent rui_extents[]; /* array of extents to rmap */
651}; 651};
652 652
653static inline size_t
654xfs_rui_log_format_sizeof(
655 unsigned int nr)
656{
657 return sizeof(struct xfs_rui_log_format) +
658 nr * sizeof(struct xfs_map_extent);
659}
660
653/* 661/*
654 * This is the structure used to lay out an rud log item in the 662 * This is the structure used to lay out an rud log item in the
655 * log. The rud_extents array is a variable size array whose 663 * log. The rud_extents array is a variable size array whose
diff --git a/fs/xfs/xfs_rmap_item.c b/fs/xfs/xfs_rmap_item.c
index 2500f28689d5..0432a459871c 100644
--- a/fs/xfs/xfs_rmap_item.c
+++ b/fs/xfs/xfs_rmap_item.c
@@ -51,28 +51,16 @@ xfs_rui_item_free(
51 kmem_zone_free(xfs_rui_zone, ruip); 51 kmem_zone_free(xfs_rui_zone, ruip);
52} 52}
53 53
54/*
55 * This returns the number of iovecs needed to log the given rui item.
56 * We only need 1 iovec for an rui item. It just logs the rui_log_format
57 * structure.
58 */
59static inline int
60xfs_rui_item_sizeof(
61 struct xfs_rui_log_item *ruip)
62{
63 return sizeof(struct xfs_rui_log_format) +
64 (ruip->rui_format.rui_nextents - 1) *
65 sizeof(struct xfs_map_extent);
66}
67
68STATIC void 54STATIC void
69xfs_rui_item_size( 55xfs_rui_item_size(
70 struct xfs_log_item *lip, 56 struct xfs_log_item *lip,
71 int *nvecs, 57 int *nvecs,
72 int *nbytes) 58 int *nbytes)
73{ 59{
60 struct xfs_rui_log_item *ruip = RUI_ITEM(lip);
61
74 *nvecs += 1; 62 *nvecs += 1;
75 *nbytes += xfs_rui_item_sizeof(RUI_ITEM(lip)); 63 *nbytes += xfs_rui_log_format_sizeof(ruip->rui_format.rui_nextents);
76} 64}
77 65
78/* 66/*
@@ -97,7 +85,7 @@ xfs_rui_item_format(
97 ruip->rui_format.rui_size = 1; 85 ruip->rui_format.rui_size = 1;
98 86
99 xlog_copy_iovec(lv, &vecp, XLOG_REG_TYPE_RUI_FORMAT, &ruip->rui_format, 87 xlog_copy_iovec(lv, &vecp, XLOG_REG_TYPE_RUI_FORMAT, &ruip->rui_format,
100 xfs_rui_item_sizeof(ruip)); 88 xfs_rui_log_format_sizeof(ruip->rui_format.rui_nextents));
101} 89}
102 90
103/* 91/*
@@ -205,16 +193,12 @@ xfs_rui_init(
205 193
206{ 194{
207 struct xfs_rui_log_item *ruip; 195 struct xfs_rui_log_item *ruip;
208 uint size;
209 196
210 ASSERT(nextents > 0); 197 ASSERT(nextents > 0);
211 if (nextents > XFS_RUI_MAX_FAST_EXTENTS) { 198 if (nextents > XFS_RUI_MAX_FAST_EXTENTS)
212 size = (uint)(sizeof(struct xfs_rui_log_item) + 199 ruip = kmem_zalloc(xfs_rui_log_item_sizeof(nextents), KM_SLEEP);
213 ((nextents - 1) * sizeof(struct xfs_map_extent))); 200 else
214 ruip = kmem_zalloc(size, KM_SLEEP);
215 } else {
216 ruip = kmem_zone_zalloc(xfs_rui_zone, KM_SLEEP); 201 ruip = kmem_zone_zalloc(xfs_rui_zone, KM_SLEEP);
217 }
218 202
219 xfs_log_item_init(mp, &ruip->rui_item, XFS_LI_RUI, &xfs_rui_item_ops); 203 xfs_log_item_init(mp, &ruip->rui_item, XFS_LI_RUI, &xfs_rui_item_ops);
220 ruip->rui_format.rui_nextents = nextents; 204 ruip->rui_format.rui_nextents = nextents;
@@ -239,14 +223,12 @@ xfs_rui_copy_format(
239 uint len; 223 uint len;
240 224
241 src_rui_fmt = buf->i_addr; 225 src_rui_fmt = buf->i_addr;
242 len = sizeof(struct xfs_rui_log_format) + 226 len = xfs_rui_log_format_sizeof(src_rui_fmt->rui_nextents);
243 (src_rui_fmt->rui_nextents - 1) *
244 sizeof(struct xfs_map_extent);
245 227
246 if (buf->i_len != len) 228 if (buf->i_len != len)
247 return -EFSCORRUPTED; 229 return -EFSCORRUPTED;
248 230
249 memcpy((char *)dst_rui_fmt, (char *)src_rui_fmt, len); 231 memcpy(dst_rui_fmt, src_rui_fmt, len);
250 return 0; 232 return 0;
251} 233}
252 234
diff --git a/fs/xfs/xfs_rmap_item.h b/fs/xfs/xfs_rmap_item.h
index aefcc3a318a5..340c968e1f9c 100644
--- a/fs/xfs/xfs_rmap_item.h
+++ b/fs/xfs/xfs_rmap_item.h
@@ -70,6 +70,14 @@ struct xfs_rui_log_item {
70 struct xfs_rui_log_format rui_format; 70 struct xfs_rui_log_format rui_format;
71}; 71};
72 72
73static inline size_t
74xfs_rui_log_item_sizeof(
75 unsigned int nr)
76{
77 return offsetof(struct xfs_rui_log_item, rui_format) +
78 xfs_rui_log_format_sizeof(nr);
79}
80
73/* 81/*
74 * This is the "rmap update done" log item. It is used to log the fact that 82 * This is the "rmap update done" log item. It is used to log the fact that
75 * some rmapbt updates mentioned in an earlier rui item have been performed. 83 * some rmapbt updates mentioned in an earlier rui item have been performed.
diff --git a/fs/xfs/xfs_super.c b/fs/xfs/xfs_super.c
index fd6be45b3a1e..340975392e91 100644
--- a/fs/xfs/xfs_super.c
+++ b/fs/xfs/xfs_super.c
@@ -1782,9 +1782,8 @@ xfs_init_zones(void)
1782 if (!xfs_rud_zone) 1782 if (!xfs_rud_zone)
1783 goto out_destroy_icreate_zone; 1783 goto out_destroy_icreate_zone;
1784 1784
1785 xfs_rui_zone = kmem_zone_init((sizeof(struct xfs_rui_log_item) + 1785 xfs_rui_zone = kmem_zone_init(
1786 ((XFS_RUI_MAX_FAST_EXTENTS - 1) * 1786 xfs_rui_log_item_sizeof(XFS_RUI_MAX_FAST_EXTENTS),
1787 sizeof(struct xfs_map_extent))),
1788 "xfs_rui_item"); 1787 "xfs_rui_item");
1789 if (!xfs_rui_zone) 1788 if (!xfs_rui_zone)
1790 goto out_destroy_rud_zone; 1789 goto out_destroy_rud_zone;