Skip to content

Commit

Permalink
[TA3113] Refactor DW rebuild unit test cases. (openzfs#118)
Browse files Browse the repository at this point in the history
Signed-off-by: satbir <[email protected]>
  • Loading branch information
satbirchhikara authored and vishnuitta committed Sep 21, 2018
1 parent 571f8d7 commit 53c3e02
Show file tree
Hide file tree
Showing 5 changed files with 401 additions and 207 deletions.
3 changes: 2 additions & 1 deletion cmd/uzfs_test/uzfs_test_rebuilding.c
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ fetch_modified_data(void *arg)
int err;
blk_metadata_t md;
off_t offset, end;
zvol_state_t *snap_zv = NULL;
size_t len;
int max_count = 4;

Expand All @@ -251,7 +252,7 @@ fetch_modified_data(void *arg)
if (end > r_data->zvol->zv_volsize)
len = r_data->zvol->zv_volsize - offset;

err = uzfs_get_io_diff(repl_data->zvol, &md,
err = uzfs_get_io_diff(repl_data->zvol, &md, snap_zv,
uzfs_test_meta_diff_traverse_cb, offset, len,
r_data);
if (err)
Expand Down
3 changes: 2 additions & 1 deletion include/uzfs_rebuilding.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ int compare_blk_metadata(blk_metadata_t *first_md, blk_metadata_t *second_md);
* API to access data whose metadata is higer than base_metadata
*/
int uzfs_get_io_diff(zvol_state_t *zv, blk_metadata_t *base_metadata,
uzfs_get_io_diff_cb_t *cb_func, off_t offset, size_t len, void *arg);
zvol_state_t *snap_zv, uzfs_get_io_diff_cb_t *cb_func,
off_t offset, size_t len, void *arg);

/*
* uzfs_get_nonoverlapping_ondisk_blks will check on_disk metadata with
Expand Down
43 changes: 24 additions & 19 deletions lib/libzpool/uzfs_rebuilding.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,15 @@ iszero(blk_metadata_t *md)
} while (0)

int
uzfs_get_io_diff(zvol_state_t *zv, blk_metadata_t *low,
uzfs_get_io_diff(zvol_state_t *zv, blk_metadata_t *low, zvol_state_t *snap,
uzfs_get_io_diff_cb_t *func, off_t lun_offset, size_t lun_len, void *arg)
{
uint64_t blocksize = zv->zv_volmetablocksize;
uint64_t metadata_read_chunk_size = 10 * blocksize;
uint64_t metaobjectsize = (zv->zv_volsize / zv->zv_metavolblocksize) *
zv->zv_volmetadatasize;
uint64_t metadatasize = zv->zv_volmetadatasize;
char *buf, *snap_name;
char *buf, *snap_name = NULL;
uint64_t i, read;
uint64_t offset, len, end;
int ret = 0;
Expand All @@ -98,15 +98,18 @@ uzfs_get_io_diff(zvol_state_t *zv, blk_metadata_t *low,

if (end > metaobjectsize)
end = metaobjectsize;

snap_name = kmem_asprintf("%s%llu", IO_DIFF_SNAPNAME, low->io_num);

ret = get_snapshot_zv(zv, snap_name, &snap_zv);
if (ret != 0) {
LOG_ERR("Failed to get info about %s@%s io_num %lu",
zv->zv_name, snap_name, low->io_num);
strfree(snap_name);
return (ret);
if (snap == NULL) {
snap_name = kmem_asprintf("%s%llu", IO_DIFF_SNAPNAME,
low->io_num);
ret = get_snapshot_zv(zv, snap_name, &snap_zv);
if (ret != 0) {
LOG_ERR("Failed to get info about %s@%s io_num %lu",
zv->zv_name, snap_name, low->io_num);
strfree(snap_name);
return (ret);
}
} else {
snap_zv = snap;
}

metadata_read_chunk_size = (metadata_read_chunk_size / metadatasize) *
Expand Down Expand Up @@ -185,17 +188,19 @@ uzfs_get_io_diff(zvol_state_t *zv, blk_metadata_t *low,
}
}

uzfs_close_dataset(snap_zv);
if (snap == NULL) {
uzfs_close_dataset(snap_zv);

/*
* TODO: if we failed to destroy snapshot here then
* this should be handled separately from application.
*/
if (end == metaobjectsize)
destroy_snapshot_zv(zv, snap_name);
/*
* TODO: if we failed to destroy snapshot here then
* this should be handled separately from application.
*/
if (end == metaobjectsize)
destroy_snapshot_zv(zv, snap_name);

strfree(snap_name);
}
umem_free(buf, metadata_read_chunk_size);
strfree(snap_name);
return (ret);
}

Expand Down
3 changes: 2 additions & 1 deletion lib/libzrepl/data_conn.c
Original file line number Diff line number Diff line change
Expand Up @@ -1122,6 +1122,7 @@ uzfs_zvol_rebuild_scanner(void *arg)
{
int fd = (uintptr_t)arg;
zvol_info_t *zinfo = NULL;
zvol_state_t *snap_zv = NULL;
zvol_io_hdr_t hdr;
int rc = 0;
zvol_rebuild_t warg;
Expand Down Expand Up @@ -1213,7 +1214,7 @@ uzfs_zvol_rebuild_scanner(void *arg)
sleep(5);
#endif
rc = uzfs_get_io_diff(zinfo->main_zv, &metadata,
uzfs_zvol_rebuild_scanner_callback,
snap_zv, uzfs_zvol_rebuild_scanner_callback,
rebuild_req_offset, rebuild_req_len, &warg);
if (rc != 0) {
LOG_ERR("Rebuild scanning failed on zvol %s ",
Expand Down
Loading

0 comments on commit 53c3e02

Please sign in to comment.