diff options
author | Brian Behlendorf <behlendorf1@llnl.gov> | 2019-03-29 16:13:20 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-03-29 16:13:20 +0000 |
commit | 1b939560be5c51deecf875af9dada9d094633bf7 (patch) | |
tree | 2a780b838134636ddbc65f89d227e37c74abe17b /module/zfs/vdev_disk.c | |
parent | f94b3cbf43d62f4962e71cfe7ba8c6f0602e2a45 (diff) | |
download | src-1b939560be5c51deecf875af9dada9d094633bf7.tar.gz src-1b939560be5c51deecf875af9dada9d094633bf7.zip |
Diffstat (limited to 'module/zfs/vdev_disk.c')
-rw-r--r-- | module/zfs/vdev_disk.c | 29 |
1 files changed, 26 insertions, 3 deletions
diff --git a/module/zfs/vdev_disk.c b/module/zfs/vdev_disk.c index 4ac08c86148e..c2312e6fa3bf 100644 --- a/module/zfs/vdev_disk.c +++ b/module/zfs/vdev_disk.c @@ -30,6 +30,7 @@ #include <sys/spa_impl.h> #include <sys/vdev_disk.h> #include <sys/vdev_impl.h> +#include <sys/vdev_trim.h> #include <sys/abd.h> #include <sys/fs/zfs.h> #include <sys/zio.h> @@ -223,7 +224,7 @@ vdev_elevator_switch(vdev_t *v, char *elevator) strfree(argv[2]); #endif /* HAVE_ELEVATOR_CHANGE */ if (error) { - zfs_dbgmsg("Unable to set \"%s\" scheduler for %s (%s): %d\n", + zfs_dbgmsg("Unable to set \"%s\" scheduler for %s (%s): %d", elevator, v->vdev_path, device, error); } } @@ -322,7 +323,7 @@ vdev_disk_open(vdev_t *v, uint64_t *psize, uint64_t *max_psize, if (IS_ERR(bdev)) { int error = -PTR_ERR(bdev); - vdev_dbgmsg(v, "open error=%d count=%d\n", error, count); + vdev_dbgmsg(v, "open error=%d count=%d", error, count); vd->vd_bdev = NULL; v->vdev_tsd = vd; rw_exit(&vd->vd_lock); @@ -333,14 +334,22 @@ vdev_disk_open(vdev_t *v, uint64_t *psize, uint64_t *max_psize, rw_exit(&vd->vd_lock); } + struct request_queue *q = bdev_get_queue(vd->vd_bdev); + /* Determine the physical block size */ block_size = vdev_bdev_block_size(vd->vd_bdev); /* Clear the nowritecache bit, causes vdev_reopen() to try again. */ v->vdev_nowritecache = B_FALSE; + /* Set when device reports it supports TRIM. */ + v->vdev_has_trim = !!blk_queue_discard(q); + + /* Set when device reports it supports secure TRIM. */ + v->vdev_has_securetrim = !!blk_queue_discard_secure(q); + /* Inform the ZIO pipeline that we are non-rotational */ - v->vdev_nonrot = blk_queue_nonrot(bdev_get_queue(vd->vd_bdev)); + v->vdev_nonrot = blk_queue_nonrot(q); /* Physical volume size in bytes for the partition */ *psize = bdev_capacity(vd->vd_bdev); @@ -728,6 +737,7 @@ vdev_disk_io_start(zio_t *zio) { vdev_t *v = zio->io_vd; vdev_disk_t *vd = v->vdev_tsd; + unsigned long trim_flags = 0; int rw, flags, error; /* @@ -813,6 +823,19 @@ vdev_disk_io_start(zio_t *zio) #endif break; + case ZIO_TYPE_TRIM: +#if defined(BLKDEV_DISCARD_SECURE) + if (zio->io_trim_flags & ZIO_TRIM_SECURE) + trim_flags |= BLKDEV_DISCARD_SECURE; +#endif + zio->io_error = -blkdev_issue_discard(vd->vd_bdev, + zio->io_offset >> 9, zio->io_size >> 9, GFP_NOFS, + trim_flags); + + rw_exit(&vd->vd_lock); + zio_interrupt(zio); + return; + default: rw_exit(&vd->vd_lock); zio->io_error = SET_ERROR(ENOTSUP); |