Disable TRIM on file backed ZFS vdevs and fix TRIM on init

After r265152 TRIM requests are ZIO_TYPE_FREE instead of ZIO_TYPE_IOCTL
this meant file backed vdevs to attempted to process the ZIO as a write
causing a panic.

We now disable TRIM on file backed vdevs and ASSERT the ZIO types supported
by each vdev type to ensure we explicity support the ZIO type being
processed.

Also ensure that TRIM on init is not procesed for devices which declare they
didn't support TRIM via vdev_notrim.

PR:		195061, 194976, 191573
Sponsored by:	Multiplay
This commit is contained in:
Steven Hartland 2014-11-17 11:32:10 +00:00
parent 4cef7be5c3
commit a559adfbce
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=274619
6 changed files with 18 additions and 9 deletions

View File

@ -146,10 +146,8 @@ trim_map_create(vdev_t *vd)
{
trim_map_t *tm;
ASSERT(vd->vdev_ops->vdev_op_leaf);
if (!zfs_trim_enabled)
return;
ASSERT(zfs_trim_enabled && !vd->vdev_notrim &&
vd->vdev_ops->vdev_op_leaf);
tm = kmem_zalloc(sizeof (*tm), KM_SLEEP);
mutex_init(&tm->tm_lock, NULL, MUTEX_DEFAULT, NULL);

View File

@ -1223,6 +1223,7 @@ vdev_open(vdev_t *vd)
vd->vdev_stat.vs_aux = VDEV_AUX_NONE;
vd->vdev_cant_read = B_FALSE;
vd->vdev_cant_write = B_FALSE;
vd->vdev_notrim = B_FALSE;
vd->vdev_min_asize = vdev_get_min_asize(vd);
/*
@ -1292,10 +1293,8 @@ vdev_open(vdev_t *vd)
if (vd->vdev_ishole || vd->vdev_ops == &vdev_missing_ops)
return (0);
if (vd->vdev_ops->vdev_op_leaf) {
vd->vdev_notrim = B_FALSE;
if (zfs_trim_enabled && !vd->vdev_notrim && vd->vdev_ops->vdev_op_leaf)
trim_map_create(vd);
}
for (int c = 0; c < vd->vdev_children; c++) {
if (vd->vdev_child[c]->vdev_state != VDEV_STATE_HEALTHY) {

View File

@ -796,6 +796,8 @@ vdev_disk_io_start(zio_t *zio)
return;
}
ASSERT(zio->io_type == ZIO_TYPE_READ || zio->io_type == ZIO_TYPE_WRITE);
vb = kmem_alloc(sizeof (vdev_buf_t), KM_SLEEP);
vb->vb_io = zio;

View File

@ -129,6 +129,8 @@ vdev_file_open(vdev_t *vd, uint64_t *psize, uint64_t *max_psize,
return (error);
}
vd->vdev_notrim = B_TRUE;
*max_psize = *psize = vattr.va_size;
*logical_ashift = SPA_MINBLOCKSHIFT;
*physical_ashift = SPA_MINBLOCKSHIFT;
@ -185,6 +187,8 @@ vdev_file_io_start(zio_t *zio)
return;
}
ASSERT(zio->io_type == ZIO_TYPE_READ || zio->io_type == ZIO_TYPE_WRITE);
zio->io_error = vn_rdwr(zio->io_type == ZIO_TYPE_READ ?
UIO_READ : UIO_WRITE, vp, zio->io_data, zio->io_size,
zio->io_offset, UIO_SYSSPACE, 0, RLIM64_INFINITY, kcred, &resid);

View File

@ -832,6 +832,11 @@ vdev_geom_io_start(zio_t *zio)
return;
}
sendreq:
ASSERT(zio->io_type == ZIO_TYPE_READ ||
zio->io_type == ZIO_TYPE_WRITE ||
zio->io_type == ZIO_TYPE_FREE ||
zio->io_type == ZIO_TYPE_IOCTL);
cp = vd->vdev_tsd;
if (cp == NULL) {
zio->io_error = SET_ERROR(ENXIO);

View File

@ -713,8 +713,9 @@ vdev_label_init(vdev_t *vd, uint64_t crtxg, vdev_labeltype_t reason)
* Don't TRIM if removing so that we don't interfere with zpool
* disaster recovery.
*/
if (zfs_trim_enabled && vdev_trim_on_init && (reason == VDEV_LABEL_CREATE ||
reason == VDEV_LABEL_SPARE || reason == VDEV_LABEL_L2CACHE))
if (zfs_trim_enabled && vdev_trim_on_init && !vd->vdev_notrim &&
(reason == VDEV_LABEL_CREATE || reason == VDEV_LABEL_SPARE ||
reason == VDEV_LABEL_L2CACHE))
zio_wait(zio_trim(NULL, spa, vd, 0, vd->vdev_psize));
/*