Skip to content

Commit 47c91c2

Browse files
author
Paul Dagnelie
committed
Final byteswap handling
Signed-off-by: Paul Dagnelie <[email protected]>
1 parent 1f9da24 commit 47c91c2

File tree

3 files changed

+57
-60
lines changed

3 files changed

+57
-60
lines changed

cmd/zdb/zdb.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9590,7 +9590,7 @@ print_anyraid_mapping(vdev_t *vd, int child, int mapping,
95909590
uint32_t mo = off % SPA_MAXBLOCKSIZE;
95919591
anyraid_map_entry_t *entry =
95929592
(anyraid_map_entry_t *)(map_buf + mo);
9593-
uint8_t type = entry->ame_u.ame_amle.amle_type;
9593+
uint8_t type = ame_get_type(entry);
95949594
uint8_t *buf;
95959595
boolean_t allocated = B_FALSE;
95969596
if (size > SPA_MAXBLOCKSIZE - mo) {
@@ -9628,8 +9628,8 @@ print_anyraid_mapping(vdev_t *vd, int child, int mapping,
96289628
(void) printf("loc %u:", cur_tile);
96299629
cur_tile++;
96309630
}
9631-
(void) printf("\td%u o%u,", amle->amle_disk,
9632-
amle->amle_offset);
9631+
(void) printf("\td%u o%u,", amle_get_disk(amle),
9632+
amle_get_offset(amle));
96339633
par_cnt = (par_cnt + 1) % (var->vd_nparity + 1);
96349634
if (par_cnt == 0)
96359635
(void) printf("\n");

include/sys/vdev_anyraid.h

Lines changed: 45 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -157,51 +157,76 @@ typedef enum anyraid_map_entry_type {
157157
AMET_TYPES
158158
} anyraid_map_entry_type_t;
159159

160+
#define AME_TYPE_BITS 8
161+
160162
/*
161163
* ==========================================================================
162164
* Skip entry definitions and functions
163165
* ==========================================================================
164166
*/
165-
typedef struct anyraid_map_skip_entry {
166-
union {
167-
uint8_t amse_type;
168-
uint32_t amse_skip_count; // tile count to skip ahead
169-
} amse_u;
170-
} anyraid_map_skip_entry_t;
167+
typedef uint32_t anyraid_map_skip_entry_t;
171168

172169
#define AMSE_TILE_BITS 24
173170

174171
static inline void
175172
amse_set_type(anyraid_map_skip_entry_t *amse)
176173
{
177-
amse->amse_u.amse_type = AMET_SKIP;
178-
ASSERT3U(amse->amse_u.amse_type, ==,
179-
BF32_GET(amse->amse_u.amse_type, 0, 8));
174+
BF32_SET(*amse, 0, AME_TYPE_BITS, AMET_SKIP);
180175
}
181176

182177
static inline void
183178
amse_set_skip_count(anyraid_map_skip_entry_t *amse, uint32_t skip_count)
184179
{
185-
BF32_SET(amse->amse_u.amse_skip_count, 8, AMSE_TILE_BITS, skip_count);
180+
BF32_SET(*amse, AME_TYPE_BITS, AMSE_TILE_BITS, skip_count);
186181
}
187182

188183
static inline uint32_t
189184
amse_get_skip_count(anyraid_map_skip_entry_t *amse)
190185
{
191-
return (BF32_GET(amse->amse_u.amse_skip_count, 8, AMSE_TILE_BITS));
186+
return (BF32_GET(*amse, AME_TYPE_BITS, AMSE_TILE_BITS));
192187
}
193188

194189
/*
195190
* ==========================================================================
196191
* Location entry definitions and functions
197192
* ==========================================================================
198193
*/
199-
typedef struct anyraid_map_loc_entry {
200-
uint8_t amle_type;
201-
uint8_t amle_disk;
202-
uint16_t amle_offset;
203-
} anyraid_map_loc_entry_t;
204-
_Static_assert(sizeof (anyraid_map_loc_entry_t) == sizeof (uint32_t), "");
194+
typedef uint32_t anyraid_map_loc_entry_t;
195+
196+
#define AMLE_DISK_BITS 8
197+
#define AMLE_OFFSET_BITS 16
198+
199+
static inline void
200+
amle_set_type(anyraid_map_loc_entry_t *amle)
201+
{
202+
BF32_SET(*amle, 0, AME_TYPE_BITS, AMET_LOC);
203+
}
204+
205+
static inline void
206+
amle_set_disk(anyraid_map_loc_entry_t *amle, uint8_t disk)
207+
{
208+
BF32_SET(*amle, AME_TYPE_BITS, AMLE_DISK_BITS, disk);
209+
}
210+
211+
static inline uint32_t
212+
amle_get_disk(anyraid_map_loc_entry_t *amle)
213+
{
214+
return (BF32_GET(*amle, AME_TYPE_BITS, AMLE_DISK_BITS));
215+
}
216+
217+
static inline void
218+
amle_set_offset(anyraid_map_loc_entry_t *amle, uint8_t offset)
219+
{
220+
BF32_SET(*amle, (AME_TYPE_BITS + AMLE_DISK_BITS), AMLE_OFFSET_BITS,
221+
offset);
222+
}
223+
224+
static inline uint32_t
225+
amle_get_offset(anyraid_map_loc_entry_t *amle)
226+
{
227+
return (BF32_GET(*amle, (AME_TYPE_BITS + AMLE_DISK_BITS),
228+
AMLE_OFFSET_BITS));
229+
}
205230

206231
/*
207232
* ==========================================================================
@@ -216,28 +241,10 @@ typedef struct anyraid_map_entry {
216241
} ame_u;
217242
} anyraid_map_entry_t;
218243

219-
static inline void
220-
ame_byteswap(anyraid_map_entry_t *ame)
244+
static inline anyraid_map_entry_type_t
245+
ame_get_type(anyraid_map_entry_t *ame)
221246
{
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-
}
247+
return (BF32_GET(ame->ame_u.ame_amle, 0, AME_TYPE_BITS));
241248
}
242249

243250
#define VDEV_ANYRAID_MAX_DISKS (1 << 8)

module/zfs/vdev_anyraid.c

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -238,8 +238,8 @@ static void
238238
create_tile_entry(vdev_anyraid_t *var, anyraid_map_loc_entry_t *amle,
239239
uint8_t *pat_cnt, anyraid_tile_t **out_ar, uint32_t *cur_tile)
240240
{
241-
uint8_t disk = amle->amle_disk;
242-
uint16_t offset = amle->amle_offset;
241+
uint8_t disk = amle_get_disk(amle);
242+
uint16_t offset = amle_get_offset(amle);
243243
anyraid_tile_t *ar = *out_ar;
244244

245245
if (*pat_cnt == 0) {
@@ -459,16 +459,6 @@ 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-
472462
static int
473463
anyraid_open_existing(vdev_t *vd, uint64_t child, uint16_t **child_capacities)
474464
{
@@ -606,13 +596,13 @@ anyraid_open_existing(vdev_t *vd, uint64_t child, uint16_t **child_capacities)
606596
#ifdef _ZFS_BIG_ENDIAN
607597
uint32_t length = map_length -
608598
next_map * SPA_MAXBLOCKSIZE;
609-
byteswap_map_buf(map_buf, (uint32_t)(length <
610-
SPA_MAXBLOCKSIZE ? length : SPA_MAXBLOCKSIZE));
599+
byteswap_uint32_array(map_buf, MIN(length,
600+
SPA_MAXBLOCKSIZE));
611601
#endif
612602
}
613603
anyraid_map_entry_t *entry =
614604
(anyraid_map_entry_t *)(map_buf + (off % SPA_MAXBLOCKSIZE));
615-
uint8_t type = entry->ame_u.ame_amle.amle_type;
605+
uint8_t type = ame_get_type(entry);
616606
switch (type) {
617607
case AMET_SKIP: {
618608
anyraid_map_skip_entry_t *amse =
@@ -1236,9 +1226,9 @@ static boolean_t
12361226
map_write_loc_entry(anyraid_tile_node_t *arn, void *buf, uint32_t *offset)
12371227
{
12381228
anyraid_map_loc_entry_t *entry = (void *)((char *)buf + *offset);
1239-
entry->amle_type = AMET_LOC;
1240-
entry->amle_disk = arn->atn_disk;
1241-
entry->amle_offset = arn->atn_offset;
1229+
amle_set_type(entry);
1230+
amle_set_disk(entry, arn->atn_disk);
1231+
amle_set_offset(entry, arn->atn_offset);
12421232
*offset += sizeof (*entry);
12431233
return (*offset == SPA_MAXBLOCKSIZE);
12441234
}
@@ -1267,7 +1257,7 @@ map_write_issue(zio_t *zio, vdev_t *vd, uint64_t base_offset,
12671257
{
12681258
#ifdef _ZFS_BIG_ENDIAN
12691259
void *buf = abd_borrow_buf(abd, SPA_MAXBLOCKSIZE);
1270-
byteswap_map_buf(buf, length);
1260+
byteswap_uint32_array(buf, length);
12711261
abd_return_buf(abd, buf, SPA_MAXBLOCKSIZE);
12721262
#else
12731263
(void) length;

0 commit comments

Comments
 (0)