Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OS-4718 ZFS actively hostile to 512e drive replacements #219

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions usr/src/uts/common/fs/zfs/spa.c
Original file line number Diff line number Diff line change
Expand Up @@ -5733,11 +5733,15 @@ spa_vdev_attach(spa_t *spa, uint64_t guid, nvlist_t *nvroot, int replacing)
return (spa_vdev_exit(spa, newrootvd, txg, EOVERFLOW));

/*
* The new device cannot have a higher alignment requirement
* than the top-level vdev.
* The new device cannot have a higher alignment requirement than the
* top-level vdev. If this is an Advanced Format (e.g. 512e) disk, we
* also need to check the fallback logical ashift value.
*/
if (newvd->vdev_ashift > oldvd->vdev_top->vdev_ashift)
if (newvd->vdev_ashift > oldvd->vdev_top->vdev_ashift &&
(newvd->vdev_ashift_af == 0 ||
newvd->vdev_ashift_af > oldvd->vdev_top->vdev_ashift)) {
return (spa_vdev_exit(spa, newrootvd, txg, EDOM));
}

/*
* If this is an in-place replacement, update oldvd's path and devid
Expand Down
1 change: 1 addition & 0 deletions usr/src/uts/common/fs/zfs/sys/vdev_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ struct vdev {
uint64_t vdev_min_asize; /* min acceptable asize */
uint64_t vdev_max_asize; /* max acceptable asize */
uint64_t vdev_ashift; /* block alignment shift */
uint64_t vdev_ashift_af; /* adv. format fallback shift */
uint64_t vdev_state; /* see VDEV_STATE_* #defines */
uint64_t vdev_prevstate; /* used when reopening a vdev */
vdev_ops_t *vdev_ops; /* vdev operations */
Expand Down
22 changes: 21 additions & 1 deletion usr/src/uts/common/fs/zfs/vdev_disk.c
Original file line number Diff line number Diff line change
Expand Up @@ -530,11 +530,31 @@ vdev_disk_open(vdev_t *vd, uint64_t *psize, uint64_t *max_psize,
VDEV_DEBUG("vdev_disk_open(\"%s\"): "
"both DKIOCGMEDIAINFO{,EXT} calls failed, %d\n",
vd->vdev_path, error);
pbsize = DEV_BSIZE;
blksz = pbsize = DEV_BSIZE;
}

*ashift = highbit64(MAX(pbsize, SPA_MINBLOCKSIZE)) - 1;

/*
* Advanced Format (512e) disks have a 4KB physical sector size, but
* also report a 512 byte logical sector size (through emulation in the
* firmware) to better support legacy operating systems. While we
* generally wish to create new pools with a 4KB block size, we also
* need to allow people to use AF disks in their existing 512 byte
* pools, even if not completely optimal.
*/
if (blksz != 0 && blksz < pbsize) {
/*
* The logical block size is smaller than the reported physical
* block size. Record the logical ashift so that
* spa_vdev_attach() can use it as a fallback.
*/
vd->vdev_ashift_af = highbit64(MAX(blksz,
SPA_MINBLOCKSIZE)) - 1;
} else {
vd->vdev_ashift_af = 0;
}

if (vd->vdev_wholedisk == 1) {
int wce = 1;

Expand Down