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

US1534 Clone feature of cStor volumes #65

Merged
merged 1 commit into from
Jun 13, 2018
Merged
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
2 changes: 1 addition & 1 deletion lib/libzfs_core/libzfs_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ lzc_promote(const char *fsname, char *snapnamebuf, int snapnamelen)
VERIFY3S(g_fd, !=, -1);

(void) strlcpy(zc.zc_name, fsname, sizeof (zc.zc_name));
if (ioctl(g_fd, ZFS_IOC_PROMOTE, &zc) != 0) {
if (uzfs_ioctl(g_fd, ZFS_IOC_PROMOTE, &zc) != 0) {
int error = errno;
if (error == EEXIST && snapnamebuf != NULL)
(void) strlcpy(snapnamebuf, zc.zc_string, snapnamelen);
Expand Down
33 changes: 29 additions & 4 deletions module/zfs/zfs_ioctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -3430,7 +3430,6 @@ zfs_ioc_create(const char *fsname, nvlist_t *innvl, nvlist_t *outnvl)
return (error);
}

#if defined(_KERNEL)
/*
* innvl: {
* "origin" -> name of origin snapshot
Expand Down Expand Up @@ -3469,10 +3468,12 @@ zfs_ioc_clone(const char *fsname, nvlist_t *innvl, nvlist_t *outnvl)
nvprops, outnvl);
if (error != 0)
(void) dsl_destroy_head(fsname);
#if !defined(_KERNEL)
(void) uzfs_zvol_create_cb(fsname, nvprops);
#endif
}
return (error);
}
#endif /* _KERNEL */

/*
* innvl: {
Expand Down Expand Up @@ -5255,6 +5256,8 @@ zfs_ioc_pool_reopen(zfs_cmd_t *zc)
spa_close(spa, FTAG);
return (0);
}
#endif /* defined(_KERNEL) */

/*
* inputs:
* zc_name name of filesystem
Expand All @@ -5268,7 +5271,6 @@ zfs_ioc_promote(zfs_cmd_t *zc)
dsl_pool_t *dp;
dsl_dataset_t *ds, *ods;
char origin[ZFS_MAX_DATASET_NAME_LEN];
char *cp;
int error;

error = dsl_pool_hold(zc->zc_name, FTAG, &dp);
Expand Down Expand Up @@ -5300,18 +5302,21 @@ zfs_ioc_promote(zfs_cmd_t *zc)
dsl_dataset_rele(ds, FTAG);
dsl_pool_rele(dp, FTAG);

#if defined(_KERNEL)
/*
* We don't need to unmount *all* the origin fs's snapshots, but
* it's easier.
*/
cp = strchr(origin, '@');
char *cp = strchr(origin, '@');
if (cp)
*cp = '\0';
(void) dmu_objset_find(origin,
zfs_unmount_snap_cb, NULL, DS_FIND_SNAPSHOTS);
#endif
return (dsl_dataset_promote(zc->zc_name, zc->zc_string));
}

#if defined(_KERNEL)
/*
* Retrieve a single {user|group}{used|quota}@... property.
*
Expand Down Expand Up @@ -7285,6 +7290,26 @@ uzfs_handle_ioctl(const char *pool, zfs_cmd_t *zc, uzfs_info_t *ucmd_info)
return (zfs_ioc_vdev_detach(zc));
case ZFS_IOC_VDEV_SET_STATE:
return (zfs_ioc_vdev_set_state(zc));
case ZFS_IOC_PROMOTE:
return (zfs_ioc_promote(zc));
case ZFS_IOC_CLONE: {
nvlist_t *outnvl = fnvlist_alloc();

err = zfs_ioc_clone(zc->zc_name, innvl, outnvl);
if (!nvlist_empty(outnvl) || zc->zc_nvlist_dst_size != 0) {
int smusherror = 0;
if (should_smush_nvlist(uzfs_cmd->ioc_num)) {
smusherror = nvlist_smush(outnvl,
zc->zc_nvlist_dst_size);
}
if (smusherror == 0)
puterror = put_nvlist(zc, outnvl);
}
if (puterror != 0)
err = puterror;
nvlist_free(outnvl);
return (err);
}
}
return (err);
}
Expand Down
45 changes: 45 additions & 0 deletions tests/cbtest/gtest/test_zrepl_prot.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1579,3 +1579,48 @@ TEST(ZvolResizeTest, ResizeZvol) {

graceful_close(control_fd);
}

/*
* Test zvol clone
*
* There is no clone protocol command but we need to test that after
* the clone is created, it connects successfully to iscsi target,
* hence the test is here in zrepl protocol test suite.
*/
TEST(ZvolCloneTest, CloneZvol) {
Zrepl zrepl;
Target target;
int rc, control_fd;
std::string host;
uint16_t port;
zvol_op_resize_data_t resize_data;
TestPool pool("resizepool");
std::string zvolname = pool.getZvolName("vol");
std::string snapname = pool.getZvolName("vol@snap");
std::string clonename = pool.getZvolName("clone");
std::string clonesnapname = pool.getZvolName("clone@snap");

zrepl.start();
pool.create();
pool.createZvol("vol", "-o io.openebs:targetip=127.0.0.1");
execCmd("zfs", std::string("snapshot " + snapname));

// clone the zvol
execCmd("zfs", std::string("clone -o "
"io.openebs:targetip=127.0.0.1:6060 " +
snapname + " " + clonename));

rc = target.listen(6060);
ASSERT_GE(rc, 0);
control_fd = target.accept(-1);
ASSERT_GE(control_fd, 0);
do_handshake(zvolname, host, port, NULL, control_fd,
ZVOL_OP_STATUS_OK);

// promote the clone
execCmd("zfs", std::string("promote " + clonename));
// check that snap name has changed after promote
execCmd("zfs", std::string("list -t snapshot " + clonesnapname));

graceful_close(control_fd);
}