Skip to content

Commit b19be06

Browse files
author
Paul Dagnelie
committed
Rob's feedback
Signed-off-by: Paul Dagnelie <[email protected]>
1 parent 85b0e62 commit b19be06

File tree

16 files changed

+111
-112
lines changed

16 files changed

+111
-112
lines changed

cmd/zdb/zdb.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4970,7 +4970,7 @@ dump_l2arc_header(int fd)
49704970
int error = B_FALSE;
49714971

49724972
if (pread64(fd, &l2dhdr, sizeof (l2dhdr),
4973-
VDEV_LABEL_START_SIZE(B_FALSE)) != sizeof (l2dhdr)) {
4973+
VDEV_OLD_LABEL_START_SIZE) != sizeof (l2dhdr)) {
49744974
error = B_TRUE;
49754975
} else {
49764976
if (l2dhdr.dh_magic == BSWAP_64(L2ARC_DEV_HDR_MAGIC))
@@ -5565,7 +5565,7 @@ dump_label(const char *dev)
55655565
if (large_label) {
55665566
char toc_buf[VDEV_TOC_SIZE];
55675567
if (pread64(fd, toc_buf, VDEV_TOC_SIZE,
5568-
label->label_offset + VDEV_NEW_PAD_SIZE) !=
5568+
label->label_offset + VDEV_LARGE_PAD_SIZE) !=
55695569
VDEV_TOC_SIZE) {
55705570
if (!dump_opt['q'])
55715571
(void) printf("failed to read label "
@@ -5577,7 +5577,7 @@ dump_label(const char *dev)
55775577

55785578
label->cksum_valid =
55795579
phys_cksum_valid(toc_buf,
5580-
label->label_offset + VDEV_NEW_PAD_SIZE,
5580+
label->label_offset + VDEV_LARGE_PAD_SIZE,
55815581
VDEV_TOC_SIZE);
55825582

55835583
label->read_failed = B_FALSE;
@@ -5623,7 +5623,7 @@ dump_label(const char *dev)
56235623
buf = alloca(conf_size);
56245624
buflen = conf_size;
56255625
uint64_t phys_off = label->label_offset +
5626-
VDEV_NEW_PAD_SIZE + toc_size + bootenv_size;
5626+
VDEV_LARGE_PAD_SIZE + toc_size + bootenv_size;
56275627
if (pread64(fd, buf, conf_size, phys_off) !=
56285628
conf_size) {
56295629
if (!dump_opt['q'])

cmd/ztest.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6666,8 +6666,7 @@ ztest_fault_inject(ztest_ds_t *zd, uint64_t id)
66666666
* odd label, so that we can handle crashes in the
66676667
* middle of vdev_config_sync().
66686668
*/
6669-
boolean_t new = vdrand->vdev_large_label;
6670-
if ((leaf & 1) == 0 && offset < VDEV_LABEL_START_SIZE(new))
6669+
if ((leaf & 1) == 0 && offset < VDEV_LABEL_START_SIZE(vdrand))
66716670
continue;
66726671

66736672
/*
@@ -6676,10 +6675,10 @@ ztest_fault_inject(ztest_ds_t *zd, uint64_t id)
66766675
* sizeof (vdev_label_t).
66776676
*/
66786677
uint64_t psize = P2ALIGN_TYPED(fsize,
6679-
new ? VDEV_LARGE_LABEL_ALIGN : sizeof (vdev_label_t),
6680-
uint64_t);
6678+
vdrand->vdev_large_label ? VDEV_LARGE_LABEL_ALIGN :
6679+
sizeof (vdev_label_t), uint64_t);
66816680
if ((leaf & 1) == 1 && offset + sizeof (bad) >
6682-
psize - VDEV_LABEL_END_SIZE(new))
6681+
psize - VDEV_LABEL_END_SIZE(vdrand))
66836682
continue;
66846683

66856684
if (mirror_save != zs->zs_mirrors) {

include/sys/vdev_impl.h

Lines changed: 38 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,13 @@ struct vdev {
438438
int64_t vdev_outlier_count; /* read outlier amongst peers */
439439
hrtime_t vdev_read_sit_out_expire; /* end of sit out period */
440440
list_node_t vdev_leaf_node; /* leaf vdev list */
441+
/*
442+
* vdev_large_label has different meanings for leaf and non-leaf vdevs.
443+
* For leaf vdevs, it is true if that specific vdev is using the large
444+
* label format. For non-leaf vdevs, it is true if any of its children
445+
* is using the new format, so that we know if we need to invoke the
446+
* large label sync logic.
447+
*/
441448
boolean_t vdev_large_label;
442449

443450
kmutex_t vdev_be_lock;
@@ -554,11 +561,13 @@ typedef struct vdev_label {
554561
} vdev_label_t; /* 256K total */
555562

556563
/*
557-
* The new label format is intended to help future-proof ZFS as sector sizes
558-
* grow. The number of uberblocks that can be safely written is limited by the
559-
* size of the ring divided by the sector size, which is already getting
560-
* uncomfortably small. The new label is only used on top-level vdevs and their
561-
* children; l2arc and spare devices are excluded. The new label layout:
564+
* The large label format was introduced to help future-proof ZFS as sector
565+
* sizes grow. The number of uberblocks that can be safely written is limited
566+
* by the size of the ring divided by the sector size, which in the original
567+
* format was already getting uncomfortably small. The new label is only used
568+
* on top-level vdevs and their children; l2arc and spare devices are excluded.
569+
*
570+
* Layout of the large label format:
562571
*
563572
* 16 MiB 112 MiB 128 MiB
564573
* +---------+--------------------------------+-------------------------------+
@@ -576,9 +585,9 @@ typedef struct vdev_label {
576585
* sub-section is larger than 16MiB, it will be split in 16MiB - sizeof
577586
* (zio_eck_t) chunks, which will each have their own checksum.
578587
*/
579-
#define VDEV_NEW_PAD_SIZE (1 << 24) // 16MiB
580-
#define VDEV_NEW_DATA_SIZE ((1 << 27) - VDEV_NEW_PAD_SIZE)
581-
#define VDEV_LARGE_LABEL_SIZE (VDEV_NEW_PAD_SIZE + VDEV_NEW_DATA_SIZE + \
588+
#define VDEV_LARGE_PAD_SIZE (1 << 24) // 16MiB
589+
#define VDEV_LARGE_DATA_SIZE ((1 << 27) - VDEV_LARGE_PAD_SIZE)
590+
#define VDEV_LARGE_LABEL_SIZE (VDEV_LARGE_PAD_SIZE + VDEV_LARGE_DATA_SIZE + \
582591
VDEV_LARGE_UBERBLOCK_RING) // 256MiB per label
583592
#define VDEV_LARGE_LABEL_ALIGN (1 << 24) // 16MiB
584593

@@ -593,9 +602,13 @@ typedef struct vdev_label {
593602
* when we need to read this info.
594603
*/
595604
#define VDEV_TOC_TOC_SIZE "toc_size"
605+
/* The size of the section that stores the boot region */
596606
#define VDEV_TOC_BOOT_REGION "boot_region"
607+
/* The size of the section that stores the vdev config */
597608
#define VDEV_TOC_VDEV_CONFIG "vdev_config"
609+
/* The size of the section that stores the pool config */
598610
#define VDEV_TOC_POOL_CONFIG "pool_config"
611+
/* The size of the section that stores auxilliary uberblocks */
599612
#define VDEV_TOC_AUX_UBERBLOCK "aux_uberblock"
600613

601614
/*
@@ -609,24 +622,31 @@ typedef struct vdev_label {
609622
/*
610623
* Size of embedded boot loader region on each label.
611624
* The total size of the first two labels plus the boot area is 4MB.
612-
* On RAIDZ, this space is overwritten during RAIDZ expansion.
625+
* On RAIDZ, this space is overwritten durinvg RAIDZ expansion.
613626
*/
614627
#define VDEV_BOOT_SIZE (7ULL << 19) /* 3.5M */
615628

616629
/*
617630
* Size of label regions at the start and end of each leaf device.
618631
*/
619-
#define VDEV_LABEL_START_SIZE(new) (new ? \
620-
VDEV_RESERVE_OFFSET + VDEV_RESERVE_SIZE : \
621-
2 * sizeof (vdev_label_t) + VDEV_BOOT_SIZE)
622-
#define VDEV_LABEL_END_SIZE(new) (new ? \
623-
2 * VDEV_LARGE_LABEL_SIZE : 2 * sizeof (vdev_label_t))
632+
#define VDEV_OLD_LABEL_START_SIZE (2 * sizeof (vdev_label_t) + \
633+
VDEV_BOOT_SIZE)
634+
#define VDEV_OLD_LABEL_END_SIZE (2 * sizeof (vdev_label_t))
635+
636+
#define VDEV_LARGE_LABEL_START_SIZE (VDEV_RESERVE_OFFSET + \
637+
VDEV_RESERVE_SIZE)
638+
#define VDEV_LARGE_LABEL_END_SIZE (2 * VDEV_LARGE_LABEL_SIZE)
639+
640+
#define VDEV_LABEL_START_SIZE(vd) ((vd)->vdev_large_label ? \
641+
VDEV_LARGE_LABEL_START_SIZE : VDEV_OLD_LABEL_START_SIZE)
642+
#define VDEV_LABEL_END_SIZE(vd) ((vd)->vdev_large_label ? \
643+
VDEV_LARGE_LABEL_END_SIZE : VDEV_OLD_LABEL_END_SIZE)
644+
624645
#define VDEV_LABELS 4
625646
#define VDEV_BEST_LABEL VDEV_LABELS
626-
#define VDEV_OFFSET_IS_LABEL(vd, off) \
627-
(((off) < VDEV_LABEL_START_SIZE(vd->vdev_large_label)) || \
628-
((off) >= ((vd)->vdev_psize - \
629-
VDEV_LABEL_END_SIZE(vd->vdev_large_label))))
647+
#define VDEV_OFFSET_IS_LABEL(vd, off) \
648+
(((off) < VDEV_LABEL_START_SIZE(vd)) || \
649+
((off) >= ((vd)->vdev_psize - VDEV_LABEL_END_SIZE(vd))))
630650

631651
#define VDEV_ALLOC_LOAD 0
632652
#define VDEV_ALLOC_ADD 1

lib/libzfs/libzfs_import.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,8 +208,7 @@ zpool_clear_label(int fd)
208208
"label < l2arc_dev_hdr_phys_t");
209209
memset(label, 0, sizeof (l2arc_dev_hdr_phys_t));
210210
if (pwrite64(fd, label, sizeof (l2arc_dev_hdr_phys_t),
211-
VDEV_LABEL_START_SIZE(B_FALSE)) ==
212-
sizeof (l2arc_dev_hdr_phys_t))
211+
VDEV_OLD_LABEL_START_SIZE) == sizeof (l2arc_dev_hdr_phys_t))
213212
header_cleared = B_TRUE;
214213
}
215214

module/os/freebsd/zfs/vdev_label_os.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ vdev_check_boot_reserve(spa_t *spa, vdev_t *childvd)
107107
* offset lets us access the boot area.
108108
*/
109109
zio_nowait(zio_vdev_child_io(pio, NULL, childvd,
110-
VDEV_BOOT_OFFSET - VDEV_LABEL_START_SIZE(childvd->vdev_large_label),
110+
VDEV_BOOT_OFFSET - VDEV_LABEL_START_SIZE(childvd),
111111
abd, size, ZIO_TYPE_READ, ZIO_PRIORITY_ASYNC_READ, 0,
112112
vdev_child_done, pio));
113113
zio_wait(pio);

module/zfs/arc.c

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6332,12 +6332,10 @@ arc_read(zio_t *pio, spa_t *spa, const blkptr_t *bp,
63326332
} else {
63336333
abd = hdr_abd;
63346334
}
6335-
boolean_t large_label = vd->vdev_large_label;
63366335

6337-
ASSERT(addr >=
6338-
VDEV_LABEL_START_SIZE(large_label) &&
6336+
ASSERT(addr >= VDEV_LABEL_START_SIZE(vd) &&
63396337
addr + asize <= vd->vdev_psize -
6340-
VDEV_LABEL_END_SIZE(large_label));
6338+
VDEV_LABEL_END_SIZE(vd));
63416339

63426340
/*
63436341
* l2arc read. The SCL_L2ARC lock will be
@@ -9173,7 +9171,7 @@ l2arc_evict(l2arc_dev_t *dev, uint64_t distance, boolean_t all)
91739171
*/
91749172
spa_config_exit(dev->l2ad_spa, SCL_L2ARC, dev);
91759173
vdev_trim_simple(vd, dev->l2ad_evict -
9176-
VDEV_LABEL_START_SIZE(vd->vdev_large_label),
9174+
VDEV_LABEL_START_SIZE(vd),
91779175
taddr - dev->l2ad_evict);
91789176
spa_config_enter(dev->l2ad_spa, SCL_L2ARC, dev,
91799177
RW_READER);
@@ -9979,10 +9977,8 @@ l2arc_add_vdev(spa_t *spa, vdev_t *vd)
99799977
/* leave extra size for an l2arc device header */
99809978
l2dhdr_asize = adddev->l2ad_dev_hdr_asize =
99819979
MAX(sizeof (*adddev->l2ad_dev_hdr), 1 << vd->vdev_ashift);
9982-
adddev->l2ad_start = VDEV_LABEL_START_SIZE(vd->vdev_large_label) +
9983-
l2dhdr_asize;
9984-
adddev->l2ad_end = VDEV_LABEL_START_SIZE(vd->vdev_large_label) +
9985-
vdev_get_min_asize(vd);
9980+
adddev->l2ad_start = VDEV_LABEL_START_SIZE(vd) + l2dhdr_asize;
9981+
adddev->l2ad_end = VDEV_LABEL_START_SIZE(vd) + vdev_get_min_asize(vd);
99869982
ASSERT3U(adddev->l2ad_start, <, adddev->l2ad_end);
99879983
adddev->l2ad_hand = adddev->l2ad_start;
99889984
adddev->l2ad_evict = adddev->l2ad_start;
@@ -10541,17 +10537,17 @@ l2arc_dev_hdr_read(l2arc_dev_t *dev)
1054110537
const uint64_t l2dhdr_asize = dev->l2ad_dev_hdr_asize;
1054210538
abd_t *abd;
1054310539
vdev_t *vd = dev->l2ad_vdev;
10544-
boolean_t large_label = vd ? vd->vdev_large_label :
10545-
B_FALSE;
10540+
uint64_t offset = vd ? VDEV_LABEL_START_SIZE(vd) :
10541+
VDEV_OLD_LABEL_START_SIZE;
1054610542

1054710543
guid = spa_guid(dev->l2ad_vdev->vdev_spa);
1054810544

1054910545
abd = abd_get_from_buf(l2dhdr, l2dhdr_asize);
1055010546

10551-
err = zio_wait(zio_read_phys(NULL, dev->l2ad_vdev,
10552-
VDEV_LABEL_START_SIZE(large_label), l2dhdr_asize, abd,
10553-
ZIO_CHECKSUM_LABEL, NULL, NULL, ZIO_PRIORITY_SYNC_READ,
10554-
ZIO_FLAG_CANFAIL | ZIO_FLAG_DONT_PROPAGATE | ZIO_FLAG_DONT_RETRY |
10547+
err = zio_wait(zio_read_phys(NULL, dev->l2ad_vdev, offset,
10548+
l2dhdr_asize, abd, ZIO_CHECKSUM_LABEL, NULL, NULL,
10549+
ZIO_PRIORITY_SYNC_READ, ZIO_FLAG_CANFAIL |
10550+
ZIO_FLAG_DONT_PROPAGATE | ZIO_FLAG_DONT_RETRY |
1055510551
ZIO_FLAG_SPECULATIVE, B_FALSE));
1055610552

1055710553
abd_free(abd);
@@ -10905,8 +10901,8 @@ l2arc_dev_hdr_update(l2arc_dev_t *dev)
1090510901
abd_t *abd;
1090610902
int err;
1090710903
vdev_t *vd = dev->l2ad_vdev;
10908-
boolean_t large_label = vd ? vd->vdev_large_label :
10909-
B_FALSE;
10904+
uint64_t offset = vd ? VDEV_LABEL_START_SIZE(vd) :
10905+
VDEV_OLD_LABEL_START_SIZE;
1091010906

1091110907
VERIFY(spa_config_held(dev->l2ad_spa, SCL_STATE_ALL, RW_READER));
1091210908

@@ -10929,9 +10925,8 @@ l2arc_dev_hdr_update(l2arc_dev_t *dev)
1092910925
abd = abd_get_from_buf(l2dhdr, l2dhdr_asize);
1093010926

1093110927
err = zio_wait(zio_write_phys(NULL, dev->l2ad_vdev,
10932-
VDEV_LABEL_START_SIZE(large_label), l2dhdr_asize, abd,
10933-
ZIO_CHECKSUM_LABEL, NULL, NULL, ZIO_PRIORITY_ASYNC_WRITE,
10934-
ZIO_FLAG_CANFAIL, B_FALSE));
10928+
offset, l2dhdr_asize, abd, ZIO_CHECKSUM_LABEL, NULL, NULL,
10929+
ZIO_PRIORITY_ASYNC_WRITE, ZIO_FLAG_CANFAIL, B_FALSE));
1093510930

1093610931
abd_free(abd);
1093710932

module/zfs/vdev.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1940,7 +1940,7 @@ vdev_probe(vdev_t *vd, zio_t *zio)
19401940
offset_t offset;
19411941
if (vd->vdev_large_label) {
19421942
size = P2ROUNDUP(VDEV_TOC_SIZE, 1 << vd->vdev_ashift);
1943-
offset = VDEV_NEW_PAD_SIZE;
1943+
offset = VDEV_LARGE_PAD_SIZE;
19441944
} else {
19451945
size = VDEV_PAD_SIZE;
19461946
offset = offsetof(vdev_label_t, vl_be);
@@ -2279,15 +2279,16 @@ vdev_open(vdev_t *vd)
22792279
VDEV_AUX_TOO_SMALL);
22802280
return (SET_ERROR(EOVERFLOW));
22812281
}
2282+
uint64_t ssize = large_label ? VDEV_LARGE_LABEL_START_SIZE :
2283+
VDEV_OLD_LABEL_START_SIZE;
2284+
uint64_t esize = large_label ? VDEV_LARGE_LABEL_END_SIZE :
2285+
VDEV_OLD_LABEL_END_SIZE;
22822286
psize = osize;
2283-
asize = osize - (VDEV_LABEL_START_SIZE(large_label) +
2284-
VDEV_LABEL_END_SIZE(large_label));
2285-
max_asize = max_osize - (VDEV_LABEL_START_SIZE(large_label) +
2286-
VDEV_LABEL_END_SIZE(large_label));
2287+
asize = osize - (ssize + esize);
2288+
max_asize = max_osize - (ssize + esize);
22872289
} else {
22882290
if (vd->vdev_parent != NULL && osize < SPA_MINDEVSIZE -
2289-
(VDEV_LABEL_START_SIZE(B_FALSE) +
2290-
VDEV_LABEL_END_SIZE(B_FALSE))) {
2291+
(VDEV_OLD_LABEL_START_SIZE + VDEV_OLD_LABEL_END_SIZE)) {
22912292
vdev_set_state(vd, B_TRUE, VDEV_STATE_CANT_OPEN,
22922293
VDEV_AUX_TOO_SMALL);
22932294
return (SET_ERROR(EOVERFLOW));
@@ -4952,9 +4953,8 @@ vdev_get_stats_ex(vdev_t *vd, vdev_stat_t *vs, vdev_stat_ex_t *vsx)
49524953

49534954
if (vd->vdev_ops->vdev_op_leaf) {
49544955
vs->vs_pspace = vd->vdev_psize;
4955-
vs->vs_rsize +=
4956-
VDEV_LABEL_START_SIZE(vd->vdev_large_label) +
4957-
VDEV_LABEL_END_SIZE(vd->vdev_large_label);
4956+
vs->vs_rsize += VDEV_LABEL_START_SIZE(vd) +
4957+
VDEV_LABEL_END_SIZE(vd);
49584958
/*
49594959
* Report initializing progress. Since we don't
49604960
* have the initializing locks held, this is only

module/zfs/vdev_draid.c

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2508,11 +2508,9 @@ vdev_draid_spare_open(vdev_t *vd, uint64_t *psize, uint64_t *max_psize,
25082508
vdev_draid_calculate_asize(tvd, &asize, &max_asize,
25092509
logical_ashift, physical_ashift);
25102510

2511-
*psize = asize + VDEV_LABEL_START_SIZE(vd->vdev_large_label) +
2512-
VDEV_LABEL_END_SIZE(vd->vdev_large_label);
2513-
*max_psize = max_asize +
2514-
VDEV_LABEL_START_SIZE(vd->vdev_large_label) +
2515-
VDEV_LABEL_END_SIZE(vd->vdev_large_label);
2511+
*psize = asize + VDEV_LABEL_START_SIZE(vd) + VDEV_LABEL_END_SIZE(vd);
2512+
*max_psize = max_asize + VDEV_LABEL_START_SIZE(vd) +
2513+
VDEV_LABEL_END_SIZE(vd);
25162514

25172515
vds->vds_draid_vdev = tvd;
25182516
vd->vdev_nonrot = tvd->vdev_nonrot;
@@ -2614,8 +2612,7 @@ vdev_draid_spare_io_start(zio_t *zio)
26142612
{
26152613
vdev_t *cvd = NULL, *vd = zio->io_vd;
26162614
vdev_draid_spare_t *vds = vd->vdev_tsd;
2617-
uint64_t offset = zio->io_offset -
2618-
VDEV_LABEL_START_SIZE(vd->vdev_large_label);
2615+
uint64_t offset = zio->io_offset - VDEV_LABEL_START_SIZE(vd);
26192616

26202617
/*
26212618
* If the vdev is closed, it's likely in the REMOVED or FAULTED state.

module/zfs/vdev_indirect.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -952,8 +952,7 @@ vdev_indirect_open(vdev_t *vd, uint64_t *psize, uint64_t *max_psize,
952952
uint64_t *logical_ashift, uint64_t *physical_ashift)
953953
{
954954
*psize = *max_psize = vd->vdev_asize +
955-
VDEV_LABEL_START_SIZE(vd->vdev_large_label) +
956-
VDEV_LABEL_END_SIZE(vd->vdev_large_label);
955+
VDEV_LABEL_START_SIZE(vd) + VDEV_LABEL_END_SIZE(vd);
957956
*logical_ashift = vd->vdev_ashift;
958957
*physical_ashift = vd->vdev_physical_ashift;
959958
return (0);

module/zfs/vdev_initialize.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ vdev_initialize_ranges(vdev_t *vd, abd_t *data)
348348
int error;
349349

350350
error = vdev_initialize_write(vd,
351-
VDEV_LABEL_START_SIZE(vd->vdev_large_label) +
351+
VDEV_LABEL_START_SIZE(vd) +
352352
zfs_rs_get_start(rs, rt) +
353353
(w * zfs_initialize_chunk_size),
354354
MIN(size - (w * zfs_initialize_chunk_size),

0 commit comments

Comments
 (0)