]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
xfs: refactor all the EFI/EFD log item sizeof logic
authorDarrick J. Wong <djwong@kernel.org>
Fri, 18 Nov 2022 09:59:45 +0000 (10:59 +0100)
committerCarlos Maiolino <cem@kernel.org>
Mon, 21 Nov 2022 14:26:48 +0000 (15:26 +0100)
Source kernel commit: 3c5aaaced99912c9fb3352fc5af5b104df67d4aa

Refactor all the open-coded sizeof logic for EFI/EFD log item and log
format structures into common helper functions whose names reflect the
struct names.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Allison Henderson <allison.henderson@oracle.com>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Signed-off-by: Carlos Maiolino <cem@kernel.org>
libxfs/xfs_log_format.h
logprint/log_redo.c

index 2f41fa8477c9d617117388dfd62117b9ae1d08db..f13e0809dc63f2a2890c570dade05894224cbbec 100644 (file)
@@ -616,6 +616,14 @@ typedef struct xfs_efi_log_format {
        xfs_extent_t            efi_extents[];  /* array of extents to free */
 } xfs_efi_log_format_t;
 
+static inline size_t
+xfs_efi_log_format_sizeof(
+       unsigned int            nr)
+{
+       return sizeof(struct xfs_efi_log_format) +
+                       nr * sizeof(struct xfs_extent);
+}
+
 typedef struct xfs_efi_log_format_32 {
        uint16_t                efi_type;       /* efi log item type */
        uint16_t                efi_size;       /* size of this item */
@@ -624,6 +632,14 @@ typedef struct xfs_efi_log_format_32 {
        xfs_extent_32_t         efi_extents[];  /* array of extents to free */
 } __attribute__((packed)) xfs_efi_log_format_32_t;
 
+static inline size_t
+xfs_efi_log_format32_sizeof(
+       unsigned int            nr)
+{
+       return sizeof(struct xfs_efi_log_format_32) +
+                       nr * sizeof(struct xfs_extent_32);
+}
+
 typedef struct xfs_efi_log_format_64 {
        uint16_t                efi_type;       /* efi log item type */
        uint16_t                efi_size;       /* size of this item */
@@ -632,6 +648,14 @@ typedef struct xfs_efi_log_format_64 {
        xfs_extent_64_t         efi_extents[];  /* array of extents to free */
 } xfs_efi_log_format_64_t;
 
+static inline size_t
+xfs_efi_log_format64_sizeof(
+       unsigned int            nr)
+{
+       return sizeof(struct xfs_efi_log_format_64) +
+                       nr * sizeof(struct xfs_extent_64);
+}
+
 /*
  * This is the structure used to lay out an efd log item in the
  * log.  The efd_extents array is a variable size array whose
@@ -645,6 +669,14 @@ typedef struct xfs_efd_log_format {
        xfs_extent_t            efd_extents[];  /* array of extents freed */
 } xfs_efd_log_format_t;
 
+static inline size_t
+xfs_efd_log_format_sizeof(
+       unsigned int            nr)
+{
+       return sizeof(struct xfs_efd_log_format) +
+                       nr * sizeof(struct xfs_extent);
+}
+
 typedef struct xfs_efd_log_format_32 {
        uint16_t                efd_type;       /* efd log item type */
        uint16_t                efd_size;       /* size of this item */
@@ -653,6 +685,14 @@ typedef struct xfs_efd_log_format_32 {
        xfs_extent_32_t         efd_extents[];  /* array of extents freed */
 } __attribute__((packed)) xfs_efd_log_format_32_t;
 
+static inline size_t
+xfs_efd_log_format32_sizeof(
+       unsigned int            nr)
+{
+       return sizeof(struct xfs_efd_log_format_32) +
+                       nr * sizeof(struct xfs_extent_32);
+}
+
 typedef struct xfs_efd_log_format_64 {
        uint16_t                efd_type;       /* efd log item type */
        uint16_t                efd_size;       /* size of this item */
@@ -661,6 +701,14 @@ typedef struct xfs_efd_log_format_64 {
        xfs_extent_64_t         efd_extents[];  /* array of extents freed */
 } xfs_efd_log_format_64_t;
 
+static inline size_t
+xfs_efd_log_format64_sizeof(
+       unsigned int            nr)
+{
+       return sizeof(struct xfs_efd_log_format_64) +
+                       nr * sizeof(struct xfs_extent_64);
+}
+
 /*
  * RUI/RUD (reverse mapping) log format definitions
  */
index 226bc30aa4fda8a63067b26baf04b43e01e1bf8e..edf7e0fbfa90a50fd43a1a968a4c9b4716a7b4a7 100644 (file)
@@ -20,9 +20,9 @@ xfs_efi_copy_format(
 {
        uint i;
        uint nextents = ((xfs_efi_log_format_t *)buf)->efi_nextents;
-       uint dst_len = sizeof(xfs_efi_log_format_t) + (nextents) * sizeof(xfs_extent_t);
-       uint len32 = sizeof(xfs_efi_log_format_32_t) + (nextents) * sizeof(xfs_extent_32_t);
-       uint len64 = sizeof(xfs_efi_log_format_64_t) + (nextents) * sizeof(xfs_extent_64_t);
+       uint dst_len = xfs_efi_log_format_sizeof(nextents);
+       uint len32 = xfs_efi_log_format32_sizeof(nextents);
+       uint len64 = xfs_efi_log_format64_sizeof(nextents);
 
        if (len == dst_len || continued) {
                memcpy((char *)dst_efi_fmt, buf, len);
@@ -86,7 +86,7 @@ xlog_print_trans_efi(
        *ptr += src_len;
 
        /* convert to native format */
-       dst_len = sizeof(xfs_efi_log_format_t) + (src_f->efi_nextents) * sizeof(xfs_extent_t);
+       dst_len = xfs_efi_log_format_sizeof(src_f->efi_nextents);
 
        if (continued && src_len < core_size) {
                printf(_("EFI: Not enough data to decode further\n"));