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

API to get condensed tree of modified blocks between two txg #6

Merged
merged 6 commits into from
Mar 7, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
5 changes: 3 additions & 2 deletions cmd/uzfs_test/uzfs_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@ uzfs_test_info_t uzfs_tests[] = {
{ uzfs_zvol_zap_operation, "uzfs zap operation test" },
{ replay_fn, "zvol replay test" },
{ unit_test_fn, "zvol read/write verification test"},
{ uzfs_zvol_txg_diff_blk_test, "uzfs modified blocks between two txg" },
{ uzfs_zvol_txg_mtree_test, "uzfs offset:len base tree test" },
{ uzfs_txg_diff_verifcation_test,
"test to verify modified blocks between two txg for zvol" },
{ uzfs_txg_diff_tree_test, "txg_diff_tree functionality test" },
};

uint64_t metaverify = 0;
Expand Down
77 changes: 60 additions & 17 deletions cmd/uzfs_test/uzfs_txg_diff.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ extern void populate_data(char *buf, uint64_t offset, int idx,
uint64_t block_size);
extern uint64_t block_size;

static int del_from_mblktree(avl_tree_t *tree, uint64_t b_offset,
static int del_from_txg_diff_tree(avl_tree_t *tree, uint64_t b_offset,
uint64_t b_len);
static int uzfs_search_mblktree(avl_tree_t *tree, uint64_t offset,
static int uzfs_search_txg_diff_tree(avl_tree_t *tree, uint64_t offset,
uint64_t *len);

typedef struct wblkinfo {
Expand All @@ -44,8 +44,13 @@ typedef struct wblkinfo {
list_node_t link;
} wblkinfo_t;

/*
* Delete entry (offset, len) from tree.
* Note : As of now, this API is used in testing code only. To use it in
* library, move this API to library code.
*/
int
del_from_mblktree(avl_tree_t *tree, uint64_t offset, uint64_t len)
del_from_txg_diff_tree(avl_tree_t *tree, uint64_t offset, uint64_t len)
{
uint64_t new_offset, new_len, b_end, b_offset, b_len;
uint64_t entry_len, entry_offset;
Expand All @@ -61,12 +66,20 @@ del_from_mblktree(avl_tree_t *tree, uint64_t offset, uint64_t len)
f_entry.len = new_len;
entry = avl_find(tree, &f_entry, &where);

// found entry whose offset matches with f_entry's offset
if (entry != NULL) {
// entry's len doesn't match with f_entry's len
if (entry->len < new_len) {
err = -1;
goto done;
}

/*
* entry's length is not lesser than f_entry.
* If entry's len is greater than f_entry, then
* update entry's offset to (f_entry's end) and len to
* entry's len - f_entry's len.
*/
entry_offset = entry->offset;
entry_len = entry->len;
avl_remove(tree, entry);
Expand All @@ -82,9 +95,15 @@ del_from_mblktree(avl_tree_t *tree, uint64_t offset, uint64_t len)
goto done;
}

/*
* Search for nearest entry whose offset is lesser than
* f_entry's offset
*/
b_entry = avl_nearest(tree, where, AVL_BEFORE);
if (b_entry) {
b_end = (b_entry->offset + b_entry->len);

// b_entry ends before f_entry ends
if (b_end < (new_offset + new_len)) {
err = -1;
goto done;
Expand Down Expand Up @@ -120,7 +139,7 @@ del_from_mblktree(avl_tree_t *tree, uint64_t offset, uint64_t len)
}

int
uzfs_search_mblktree(avl_tree_t *tree, uint64_t offset, uint64_t *len)
uzfs_search_txg_diff_tree(avl_tree_t *tree, uint64_t offset, uint64_t *len)
{
uzfs_zvol_blk_phy_t tofind;
avl_index_t where;
Expand All @@ -138,7 +157,7 @@ uzfs_search_mblktree(avl_tree_t *tree, uint64_t offset, uint64_t *len)
}

void
uzfs_zvol_txg_diff_blk_test(void *arg)
uzfs_txg_diff_verifcation_test(void *arg)
{
uzfs_test_info_t *test_info = (uzfs_test_info_t *)arg;
avl_tree_t *tree;
Expand All @@ -148,9 +167,10 @@ uzfs_zvol_txg_diff_blk_test(void *arg)
uint64_t blksz = io_block_size, io_num = 0;
void *spa, *zvol;
char *buf;
int diff_txg = 5, count, i = 0;
int max_io, count, i = 0;
list_t wlist;
wblkinfo_t *blk;
wblkinfo_t *blk, *temp_blk;
boolean_t offset_matched;

setup_unit_test();
unit_test_create_pool_ds();
Expand All @@ -166,16 +186,37 @@ uzfs_zvol_txg_diff_blk_test(void *arg)

while (i++ < test_iterations) {
count = 0;
max_io = MAX(uzfs_random(100), 5);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make it as 10K..


txg_wait_synced(spa_get_dsl(spa), 0);
first_txg = spa_last_synced_txg(spa);

while (count++ < diff_txg) {
while (count++ < max_io) {
io_num++;
blk_offset = uzfs_random(vol_blocks - 16);
/*
* make sure offset is aligned to block size
*/
offset = ((blk_offset * blksz + block_size) /

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

offset can be just blk_offset * block_size

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also, have a test case with less active size (probably for 30K or 50K blocks), so that, collisions/merges of tree can be verified

block_size) * block_size;

offset_matched = B_FALSE;
temp_blk = list_head(&wlist);
while (temp_blk) {
if (temp_blk->offset == offset) {
offset_matched = B_TRUE;
break;
}
if (temp_blk->offset + temp_blk->len ==

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this condition is not required at all

offset) {
offset_matched = B_TRUE;
break;
}
temp_blk = list_next(&wlist, temp_blk);
}
if (offset_matched)
continue;

populate_data(buf, offset, 0, block_size);

if (uzfs_write_data(zvol, buf, offset, block_size,
Expand All @@ -193,15 +234,17 @@ uzfs_zvol_txg_diff_blk_test(void *arg)
txg_wait_synced(spa_get_dsl(spa), 0);
last_txg = spa_last_synced_txg(spa);

uzfs_txg_block_diff(zvol, first_txg, last_txg, (void **)&tree);
uzfs_get_txg_diff_tree(zvol, first_txg, last_txg,
(void **)&tree);

while ((blk = list_remove_head(&wlist))) {
VERIFY0(del_from_mblktree(tree, blk->offset, blk->len));
VERIFY0(del_from_txg_diff_tree(tree, blk->offset,
blk->len));
umem_free(blk, sizeof (*blk));
blk = NULL;
}
VERIFY0(avl_numnodes(tree));
printf("%s pass:%d\n", test_info->name, i);
printf("%s : pass:%d\n", test_info->name, i);
umem_free(tree, sizeof (*tree));
tree = NULL;
}
Expand All @@ -219,7 +262,7 @@ check_tree(avl_tree_t *tree, uint64_t offset, uint64_t len, uint64_t exp_off,
int ret;
uint64_t len1 = 0;

ret = uzfs_search_mblktree(tree, exp_off, &len1);
ret = uzfs_search_txg_diff_tree(tree, exp_off, &len1);

VERIFY(ret == exp_ret);

Expand All @@ -231,26 +274,26 @@ static void
add_and_check_tree(avl_tree_t *tree, uint64_t offset, uint64_t len,
uint64_t exp_off, uint64_t exp_len, int exp_ret)
{
add_to_mblktree(tree, offset, len);
add_to_txg_diff_tree(tree, offset, len);
check_tree(tree, offset, len, exp_off, exp_len, exp_ret);
}

static void
delete_and_check_tree(avl_tree_t *tree, uint64_t offset, uint64_t len,
uint64_t exp_off, uint64_t exp_len, int exp_ret)
{
del_from_mblktree(tree, offset, len);
del_from_txg_diff_tree(tree, offset, len);
check_tree(tree, offset, len, exp_off, exp_len, exp_ret);
}

void
uzfs_zvol_txg_mtree_test(void *arg)
uzfs_txg_diff_tree_test(void *arg)
{
uzfs_test_info_t *test_info = (uzfs_test_info_t *)arg;
avl_tree_t *tree;
uint64_t blksz = io_block_size;

uzfs_create_mblktree((void **)&tree);
uzfs_create_txg_diff_tree((void **)&tree);

add_and_check_tree(tree, 100, 50, 100, 50, 1);
add_and_check_tree(tree, 150, 50, 100, 100, 1);
Expand Down Expand Up @@ -315,6 +358,6 @@ uzfs_zvol_txg_mtree_test(void *arg)
add_and_check_tree(tree, 130, 140, 130, 140, 0);
add_and_check_tree(tree, 130, 140, 120, 150, 0);

uzfs_destroy_mblktree((void *)tree);
uzfs_destroy_txg_diff_tree((void *)tree);
printf("%s pass\n", test_info->name);
}
20 changes: 15 additions & 5 deletions cmd/uzfs_test/uzfs_zvol_zap.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ verify_zap_entries(void *zvol, uzfs_zap_kv_t **key_array, uint64_t count)
uzfs_zap_kv_t *kv;
uint64_t value;
int i = 0, err;
uzfs_zap_kv_t dummy_key;
uzfs_zap_kv_t *dummy_key;

for (i = 0; i < count; i++) {
kv = key_array[i];
Expand All @@ -87,15 +87,25 @@ verify_zap_entries(void *zvol, uzfs_zap_kv_t **key_array, uint64_t count)
VERIFY(kv->value == value);
}

dummy_key.key = umem_alloc(20, UMEM_NOFAIL);
dummy_key.size = sizeof (dummy_key.value);
dummy_key = umem_alloc(sizeof (*dummy_key), UMEM_NOFAIL);
dummy_key->size = sizeof (dummy_key->value);

dummy_key.key = "DUMMY";
err = uzfs_read_zap_entry(zvol, &dummy_key);
dummy_key->key = "DUMMY";
err = uzfs_read_zap_entry(zvol, dummy_key);
if (err == 0) {
printf("read zap should fail..\n");
exit(1);
}

dummy_key->size = 16;
err = uzfs_update_zap_entries(zvol,
(const uzfs_zap_kv_t **) &dummy_key, 1);
if (err != EINVAL) {
printf("error in zap update\n");
exit(1);
}

umem_free(dummy_key, sizeof (*dummy_key));
}

void
Expand Down
10 changes: 5 additions & 5 deletions include/uzfs_mtree.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@
#ifndef _UZFS_MTREE_H
#define _UZFS_MTREE_H

extern int uzfs_txg_block_diff(void *zv, uint64_t start_txg,
extern int uzfs_get_txg_diff_tree(void *zv, uint64_t start_txg,
uint64_t end_txg, void **tree);
extern void dump_mblktree(void *tree);
extern void uzfs_create_mblktree(void **tree);
extern void uzfs_destroy_mblktree(void *tree);
extern int add_to_mblktree(void *tree, uint64_t offset, uint64_t size);
extern void dump_txg_diff_tree(void *tree);
extern void uzfs_create_txg_diff_tree(void **tree);
extern void uzfs_destroy_txg_diff_tree(void *tree);
extern int add_to_txg_diff_tree(void *tree, uint64_t offset, uint64_t size);
#endif
4 changes: 2 additions & 2 deletions include/uzfs_test.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,6 @@ typedef struct uzfs_test_info {

void uzfs_zvol_zap_operation(void *arg);
void unit_test_fn(void *arg);
void uzfs_zvol_txg_diff_blk_test(void *arg);
void uzfs_zvol_txg_mtree_test(void *arg);
void uzfs_txg_diff_tree_test(void *arg);
void uzfs_txg_diff_verifcation_test(void *arg);
#endif
Loading