From 5e199b9a485d31884048faed77221593fdab4dad Mon Sep 17 00:00:00 2001 From: Satbir Singh <34478047+satbirchhikara@users.noreply.github.com> Date: Tue, 5 Jun 2018 14:54:06 +0530 Subject: [PATCH] Volume resize cmd for uzfs. (#51) Signed-off-by: satbir --- include/sys/zvol.h | 6 ++++-- module/zfs/zfs_ioctl.c | 2 +- module/zfs/zvol.c | 33 +++++++++++++++++++++++---------- 3 files changed, 28 insertions(+), 13 deletions(-) diff --git a/include/sys/zvol.h b/include/sys/zvol.h index 02a2423a08e8..602f306206c7 100644 --- a/include/sys/zvol.h +++ b/include/sys/zvol.h @@ -45,11 +45,13 @@ extern int zvol_check_volsize(uint64_t volsize, uint64_t blocksize); extern int zvol_check_volblocksize(const char *name, uint64_t volblocksize); extern int zvol_get_stats(objset_t *os, nvlist_t *nv); -#ifdef _KERNEL typedef struct zvol_state zvol_state_t; +extern int zvol_update_volsize(uint64_t volsize, objset_t *os); +extern void zvol_size_changed(zvol_state_t *zv, uint64_t volsize); +extern int zvol_set_volsize(const char *, uint64_t); +#ifdef _KERNEL extern boolean_t zvol_is_zvol(const char *); -extern int zvol_set_volsize(const char *, uint64_t); extern int zvol_set_volblocksize(const char *, uint64_t); extern int zvol_set_snapdev(const char *, zprop_source_t, uint64_t); extern int zvol_set_volmode(const char *, zprop_source_t, uint64_t); diff --git a/module/zfs/zfs_ioctl.c b/module/zfs/zfs_ioctl.c index d4ba4f6b3b8c..6518370ae846 100644 --- a/module/zfs/zfs_ioctl.c +++ b/module/zfs/zfs_ioctl.c @@ -2579,10 +2579,10 @@ zfs_prop_set_special(const char *dsname, zprop_source_t source, case ZFS_PROP_REFRESERVATION: err = dsl_dataset_set_refreservation(dsname, source, intval); break; -#ifdef _KERNEL case ZFS_PROP_VOLSIZE: err = zvol_set_volsize(dsname, intval); break; +#ifdef _KERNEL case ZFS_PROP_SNAPDEV: err = zvol_set_snapdev(dsname, source, intval); break; diff --git a/module/zfs/zvol.c b/module/zfs/zvol.c index 4f0e34f2e5eb..e762c19f2785 100644 --- a/module/zfs/zvol.c +++ b/module/zfs/zvol.c @@ -95,6 +95,7 @@ #include #include #include +#include #endif unsigned int zvol_inhibit_dev = 0; @@ -354,10 +355,10 @@ zvol_get_stats(objset_t *os, nvlist_t *nv) return (SET_ERROR(error)); } -#if defined(_KERNEL) -static void +void zvol_size_changed(zvol_state_t *zv, uint64_t volsize) { +#if defined(_KERNEL) struct block_device *bdev; ASSERT(MUTEX_HELD(&zv->zv_state_lock)); @@ -367,12 +368,12 @@ zvol_size_changed(zvol_state_t *zv, uint64_t volsize) return; set_capacity(zv->zv_disk, volsize >> 9); - zv->zv_volsize = volsize; check_disk_size_change(zv->zv_disk, bdev); bdput(bdev); -} #endif + zv->zv_volsize = volsize; +} /* * Sanity check volume size. @@ -393,11 +394,10 @@ zvol_check_volsize(uint64_t volsize, uint64_t blocksize) return (0); } -#if defined(_KERNEL) /* * Ensure the zap is flushed then inform the VFS of the capacity change. */ -static int +int zvol_update_volsize(uint64_t volsize, objset_t *os) { dmu_tx_t *tx; @@ -461,18 +461,27 @@ zvol_set_volsize(const char *name, uint64_t volsize) if (readonly) return (SET_ERROR(EROFS)); +#if !defined(_KERNEL) + zvol_info_t *zinfo = uzfs_zinfo_lookup(name); + if (zinfo == NULL) + return (SET_ERROR(ENOENT)); + zv = zinfo->zv; +#else zv = zvol_find_by_name(name, RW_READER); - ASSERT(zv == NULL || (MUTEX_HELD(&zv->zv_state_lock) && RW_READ_HELD(&zv->zv_suspend_lock))); - +#endif if (zv == NULL || zv->zv_objset == NULL) { +#if defined(_KERNEL) if (zv != NULL) rw_exit(&zv->zv_suspend_lock); +#endif if ((error = dmu_objset_own(name, DMU_OST_ZVOL, B_FALSE, FTAG, &os)) != 0) { +#if defined(_KERNEL) if (zv != NULL) mutex_exit(&zv->zv_state_lock); +#endif return (SET_ERROR(error)); } owned = B_TRUE; @@ -500,15 +509,19 @@ zvol_set_volsize(const char *name, uint64_t volsize) if (zv != NULL) zv->zv_objset = NULL; } else { +#if defined(_KERNEL) rw_exit(&zv->zv_suspend_lock); +#endif } +#if !defined(_KERNEL) + uzfs_zinfo_drop_refcnt(zinfo, B_FALSE); +#else if (zv != NULL) mutex_exit(&zv->zv_state_lock); - +#endif return (SET_ERROR(error)); } -#endif /* * Sanity check volume block size.