Skip to content

Commit

Permalink
Volume resize cmd for uzfs. (openzfs#51)
Browse files Browse the repository at this point in the history
Signed-off-by: satbir <satbir.chhikara@gmail.com>
  • Loading branch information
satbirchhikara authored and Jan Kryl committed Jun 26, 2018
1 parent f4a98dc commit 5e199b9
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 13 deletions.
6 changes: 4 additions & 2 deletions include/sys/zvol.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion module/zfs/zfs_ioctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
33 changes: 23 additions & 10 deletions module/zfs/zvol.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@
#include <libuzfs.h>
#include <uzfs_mgmt.h>
#include <sys/uzfs_zvol.h>
#include <zrepl_mgmt.h>
#endif

unsigned int zvol_inhibit_dev = 0;
Expand Down Expand Up @@ -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));
Expand All @@ -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.
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 5e199b9

Please sign in to comment.