Skip to content

Commit

Permalink
[TA2330] API to store snapshot IO num when taking snapshot, to retrie…
Browse files Browse the repository at this point in the history
…ve snapshot dataset and IO number from given snapname (#98)

Signed-off-by: satbir <[email protected]>
  • Loading branch information
satbirchhikara authored and vishnuitta committed Aug 16, 2018
1 parent 81aa89e commit 33218f9
Show file tree
Hide file tree
Showing 4 changed files with 131 additions and 1 deletion.
6 changes: 6 additions & 0 deletions include/mgmt_conn.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,12 @@ void zinfo_destroy_cb(zvol_info_t *zinfo);
void uzfs_zvol_mgmt_thread(void *arg);
int finish_async_tasks(void);

int uzfs_zvol_create_snapshot_update_zap(zvol_info_t *zinfo,
char *snapname, uint64_t snapshot_io_num);

int uzfs_zvol_get_snap_dataset_with_io(zvol_info_t *zinfo,
char *snapname, uint64_t *snapshot_io_num, zvol_state_t **snap_zv);

#ifdef __cplusplus
}
#endif
Expand Down
1 change: 0 additions & 1 deletion lib/libzpool/uzfs_rebuilding.c
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,6 @@ uzfs_zvol_create_snaprebuild_clone(zvol_state_t *zv,
if (ret != 0) {
LOG_ERR("Failed to get info about %s@%s",
zv->zv_name, REBUILD_SNAPSHOT_SNAPNAME);
strfree(snapname);
return (ret);
}

Expand Down
61 changes: 61 additions & 0 deletions lib/libzrepl/mgmt_conn.c
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,67 @@ finish_async_tasks(void)
return (rc);
}

/*
* Take a snapshot and update snapshot IO to ZAP.
*/
int
uzfs_zvol_create_snapshot_update_zap(zvol_info_t *zinfo,
char *snapname, uint64_t snapshot_io_num)
{
int ret = 0;

if (uzfs_zvol_get_status(zinfo->zv) != ZVOL_STATUS_HEALTHY) {
return (ret = -1);
}

if (zinfo->running_ionum > snapshot_io_num -1)
return (ret = -1);

mutex_enter(&zvol_list_mutex);

uzfs_zvol_store_last_committed_io_no(zinfo->zv,
snapshot_io_num -1);
zinfo->checkpointed_ionum = snapshot_io_num -1;
zinfo->checkpointed_time = time(NULL);

mutex_exit(&zvol_list_mutex);
ret = dmu_objset_snapshot_one(zinfo->name, snapname);
return (ret);
}

/*
* For a given snap name, get snap dataset and IO number stored in ZAP
* Input: zinfo, snap
* Output: snapshot_io_num, snap_zv
*/
int
uzfs_zvol_get_snap_dataset_with_io(zvol_info_t *zinfo,
char *snapname, uint64_t *snapshot_io_num, zvol_state_t **snap_zv)
{
int ret = 0;

char *longsnap = kmem_asprintf("%s@%s",
strchr(zinfo->name, '/') + 1, snapname);
ret = uzfs_open_dataset(zinfo->zv->zv_spa, longsnap, snap_zv);
if (ret != 0) {
LOG_ERR("Failed to get info about %s", longsnap);
strfree(longsnap);
return (ret);
}

strfree(longsnap);
ret = uzfs_hold_dataset(*snap_zv);
if (ret != 0) {
LOG_ERR("Failed to hold snapshot: %d", ret);
uzfs_close_dataset(*snap_zv);
*snap_zv = NULL;
return (ret);
}

(*snapshot_io_num) = uzfs_zvol_get_last_committed_io_no(*snap_zv);
return (ret);
}

/*
* Perform the command (in async context).
*
Expand Down
64 changes: 64 additions & 0 deletions tests/cbtest/gtest/test_uzfs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1317,3 +1317,67 @@ TEST(SnapRebuild, CloneReCreateFailure) {
EXPECT_EQ(0, uzfs_zvol_destroy_snaprebuild_clone(zinfo->zv,
snap_zv));
}

uint64_t snapshot_io_num = 1000;
char *snapname = (char *)"hello_snap";

/* Snap create failure */
TEST(SnapCreate, SnapCreateFailureHigherIO) {

/*
* By default volume state is marked downgraded
* so updation of ZAP attribute would fail
*/
uzfs_zvol_set_rebuild_status(zinfo->zv, ZVOL_REBUILDING_INIT);
uzfs_zvol_set_status(zinfo->zv, ZVOL_STATUS_DEGRADED);

zinfo->running_ionum = snapshot_io_num + 1;
/* Create snapshot */
EXPECT_EQ(-1, uzfs_zvol_create_snapshot_update_zap(zinfo,
snapname, snapshot_io_num));
}

/* Snap create failure */
TEST(SnapCreate, SnapCreateFailure) {

/*
* By default volume state is marked downgraded
* so updation of ZAP attribute would fail
*/
uzfs_zvol_set_rebuild_status(zinfo->zv, ZVOL_REBUILDING_INIT);
uzfs_zvol_set_status(zinfo->zv, ZVOL_STATUS_DEGRADED);

zinfo->running_ionum = snapshot_io_num -1;
/* Create snapshot */
EXPECT_EQ(-1, uzfs_zvol_create_snapshot_update_zap(zinfo,
snapname, snapshot_io_num));
}

/* Snap create success */
TEST(SnapCreate, SnapCreateSuccess) {

/*
* Set volume state to healthy so that we can
* upsate ZAP attribute and take snapshot
*/
uzfs_zvol_set_rebuild_status(zinfo->zv, ZVOL_REBUILDING_DONE);
uzfs_zvol_set_status(zinfo->zv, ZVOL_STATUS_HEALTHY);

zinfo->running_ionum = snapshot_io_num -1;
/* Create snapshot */
EXPECT_EQ(0, uzfs_zvol_create_snapshot_update_zap(zinfo,
snapname, snapshot_io_num));
}

/* Retrieve Snap dataset and IO number */
TEST(SnapCreate, SnapRetrieve) {

uint64_t io = 0;
zvol_state_t *snap_zv = NULL;

/* Create snapshot */
EXPECT_EQ(0, uzfs_zvol_get_snap_dataset_with_io(zinfo,
snapname, &io, &snap_zv));

EXPECT_EQ(snapshot_io_num -1, io);
}

0 comments on commit 33218f9

Please sign in to comment.