Skip to content

Commit dba19ca

Browse files
author
Paul Dagnelie
committed
improve byteswap logic
Signed-off-by: Paul Dagnelie <paul.dagnelie@klarasystems.com>
1 parent b5ebe7d commit dba19ca

File tree

2 files changed

+39
-3
lines changed

2 files changed

+39
-3
lines changed

include/sys/vdev_anyraid.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,30 @@ typedef struct anyraid_map_entry {
216216
} ame_u;
217217
} anyraid_map_entry_t;
218218

219+
static inline void
220+
ame_byteswap(anyraid_map_entry_t *ame)
221+
{
222+
uint8_t type = ame->ame_u.ame_amle.amle_type;
223+
switch (type) {
224+
case AMET_SKIP: {
225+
anyraid_map_skip_entry_t *amse =
226+
&ame->ame_u.ame_amse;
227+
amse->amse_u.amse_skip_count =
228+
BSWAP_32(amse_get_skip_count(amse)) >> NBBY;
229+
amse->amse_u.amse_type = AMET_SKIP;
230+
break;
231+
}
232+
case AMET_LOC: {
233+
anyraid_map_loc_entry_t *amle =
234+
&ame->ame_u.ame_amle;
235+
amle->amle_offset = BSWAP_16(amle->amle_offset);
236+
break;
237+
}
238+
default:
239+
PANIC("Invalid entry type %d", type);
240+
}
241+
}
242+
219243
#define VDEV_ANYRAID_MAX_DISKS (1 << 8)
220244
#define VDEV_ANYRAID_MAX_TPD (1 << 16)
221245
#define VDEV_ANYRAID_MAX_TILES (VDEV_ANYRAID_MAX_DISKS * VDEV_ANYRAID_MAX_TPD)

module/zfs/vdev_anyraid.c

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,16 @@ vdev_anyraid_pick_best_mapping(vdev_t *cvd, uint64_t *out_txg,
459459
return (error);
460460
}
461461

462+
#ifdef _ZFS_BIG_ENDIAN
463+
static void
464+
byteswap_map_buf(void *buf, uint32_t length)
465+
{
466+
for (size_t i = 0; i < length; i += sizeof (anyraid_map_entry_t)) {
467+
ame_byteswap((anyraid_map_entry_t *)((char *)buf + i));
468+
}
469+
}
470+
#endif
471+
462472
static int
463473
anyraid_open_existing(vdev_t *vd, uint64_t child, uint16_t **child_capacities)
464474
{
@@ -596,8 +606,8 @@ anyraid_open_existing(vdev_t *vd, uint64_t child, uint16_t **child_capacities)
596606
#ifdef _ZFS_BIG_ENDIAN
597607
uint32_t length = map_length -
598608
next_map * SPA_MAXBLOCKSIZE;
599-
byteswap_uint32_array(map_buf, length <
600-
SPA_MAXBLOCKSIZE ? length : SPA_MAXBLOCKSIZE);
609+
byteswap_map_buf(map_buf, (uint32_t)(length <
610+
SPA_MAXBLOCKSIZE ? length : SPA_MAXBLOCKSIZE));
601611
#endif
602612
}
603613
anyraid_map_entry_t *entry =
@@ -1256,7 +1266,9 @@ map_write_issue(zio_t *zio, vdev_t *vd, uint64_t base_offset,
12561266
int flags)
12571267
{
12581268
#ifdef _ZFS_BIG_ENDIAN
1259-
byteswap_uint32_array(abd, length);
1269+
void *buf = abd_borrow_buf(abd, SPA_MAXBLOCKSIZE);
1270+
byteswap_map_buf(buf, length);
1271+
abd_return_buf(abd, buf, SPA_MAXBLOCKSIZE);
12601272
#else
12611273
(void) length;
12621274
#endif

0 commit comments

Comments
 (0)