Skip to content

Commit

Permalink
[cstor#21] thread to update txg every 10 mins (#65)
Browse files Browse the repository at this point in the history
[cstor#21] thread to update txg every 10 mins
  • Loading branch information
vishnuitta authored and Jan Kryl committed Jun 26, 2018
1 parent 6ea0578 commit 3fef28e
Show file tree
Hide file tree
Showing 12 changed files with 360 additions and 27 deletions.
10 changes: 2 additions & 8 deletions cmd/uzfs_test/uzfs_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -274,18 +274,12 @@ unit_test_create_pool_ds(void)
err2 = uzfs_create_pool("testp1", "/tmp/uztest.xyz", &spa2);
err3 = uzfs_open_pool("testp", &spa3);
err4 = uzfs_open_pool("testp1", &spa4);
if (spa1 != NULL || spa2 != NULL || spa4 != NULL ||
err1 == 0 || err2 == 0 || err4 == 0) {
if (spa1 != NULL || spa2 != NULL || spa3 != NULL || spa4 != NULL ||
err1 == 0 || err2 == 0 || err3 == 0 || err4 == 0) {
printf("shouldn't create/open, but succeeded..\n");
exit(1);
}

if (err3 != 0 || spa3 == NULL) {
printf("opening pool errored %d..\n", err3);
exit(1);
}
uzfs_close_pool(spa3);

err = uzfs_create_dataset(spa, "ds0", vol_size, block_size, 0, &zv);
if (zv == NULL || err != 0) {
printf("creating ds errored %d..\n", err);
Expand Down
58 changes: 52 additions & 6 deletions cmd/uzfs_test/uzfs_zvol_zap.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ verify_zap_entries(void *zvol, uzfs_zap_kv_t **key_array, uint64_t count)
{
uzfs_zap_kv_t *kv;
char *value, *temp_value;
int i = 0;
int i = 0, err;
uzfs_zap_kv_t dummy_key;

for (i = 0; i < count; i++) {
kv = key_array[i];
Expand All @@ -90,6 +91,17 @@ verify_zap_entries(void *zvol, uzfs_zap_kv_t **key_array, uint64_t count)
free(temp_value);
value = NULL;
}

dummy_key.key = malloc(20);
dummy_key.value = malloc(20);
dummy_key.size = 20;

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

void
Expand All @@ -101,30 +113,31 @@ uzfs_zvol_zap_operation(void *arg)
void *spa, *zvol;
uzfs_zap_kv_t **kv_array;
int zap_count;
uint64_t txg1, txg2, txg3, txg4;
struct timespec ts;
int err1, err2;
txg_update_interval_time = hz;

setup_unit_test();
unit_test_create_pool_ds();
open_pool_ds(&spa, &zvol);

now = gethrtime();
end = now + (hrtime_t)(total_time_in_sec * (hrtime_t)(NANOSEC));

while (i++ < test_iterations) {
zap_count = uzfs_random(16) + 1;

kv_array = malloc(zap_count * sizeof (*kv_array));
fill_up_zap_entries(kv_array, zap_count);

/* update key/value pair in ZAP entries */
VERIFY0(uzfs_update_zap_entry(zvol,
VERIFY0(uzfs_update_zap_entries(zvol,
(const uzfs_zap_kv_t **) kv_array, zap_count));

verify_zap_entries(zvol, kv_array, zap_count);

/* update value against existing ZAP key entries */
update_zap_entries(kv_array, zap_count);

VERIFY0(uzfs_update_zap_entry(zvol,
VERIFY0(uzfs_update_zap_entries(zvol,
(const uzfs_zap_kv_t **) kv_array, zap_count));

verify_zap_entries(zvol, kv_array, zap_count);
Expand All @@ -134,6 +147,39 @@ uzfs_zvol_zap_operation(void *arg)
kv_array = NULL;

printf("%s pass:%d\n", test_info->name, i);
}

now = gethrtime();
end = now + (hrtime_t)(total_time_in_sec * (hrtime_t)(NANOSEC));

zfs_txg_timeout = 1;
ts.tv_sec = 3;
ts.tv_nsec = 0;

while (1) {
err1 = uzfs_read_last_iter_txg(spa, &txg1);
if ((err1 != 0) && (err1 != 2)) {
printf("error in reading last iter txg..\n");
exit(1);
}

txg2 = spa_last_synced_txg(spa);

nanosleep(&ts, NULL);

err2 = uzfs_read_last_iter_txg(spa, &txg3);
if ((err2 != 0) && (err2 != 2)) {
printf("error in reading last iter txg..\n");
exit(1);
}

txg4 = spa_last_synced_txg(spa);

if (txg2 != txg4)
if ((txg1 == txg3) && ((err1 == 0) || (err2 == 0))) {
printf("doesn't seem to be updating txg..\n");
exit(1);
}

now = gethrtime();
if (now > end)
Expand Down
4 changes: 3 additions & 1 deletion include/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ USER_H = \
$(top_srcdir)/include/rte_common.h \
$(top_srcdir)/include/rte_memory.h \
$(top_srcdir)/include/rte_pause.h \
$(top_srcdir)/include/uzfs_zap.h
$(top_srcdir)/include/uzfs_zap.h \
$(top_srcdir)/include/uzfs.h \
$(top_srcdir)/include/uzfs_task.h

EXTRA_DIST = $(COMMON_H) $(KERNEL_H) $(USER_H)

Expand Down
4 changes: 4 additions & 0 deletions include/sys/spa_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,10 @@ struct spa {
refcount_t spa_refcount; /* number of opens */

taskq_t *spa_upgrade_taskq; /* taskq for upgrade jobs */

#if !defined(_KERNEL)
void *spa_us; /* uzfs_pool structure */
#endif
};

extern char *spa_config_path;
Expand Down
50 changes: 50 additions & 0 deletions include/uzfs.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/

#include <uzfs_task.h>
#include <sys/spa_impl.h>

#ifndef _UZFS_H

#define _UZFS_H

typedef int (*const uzfs_pool_task_func_t)(void *spa);

typedef struct uzfs_pool_task_funcs {
uzfs_pool_task_func_t open_func;
uzfs_pool_task_func_t close_func;
} uzfs_pool_task_funcs_t;

#define UZFS_POOL_MAX_TASKS 3

typedef struct uzfs_spa {
boolean_t tasks_initialized[UZFS_POOL_MAX_TASKS];
boolean_t close_pool;
kmutex_t mtx;
kcondvar_t cv;
kthread_t *update_txg_tid;
} uzfs_spa_t;

extern uzfs_pool_task_funcs_t uzfs_pool_tasks[UZFS_POOL_MAX_TASKS];

#define uzfs_spa(s) ((uzfs_spa_t *)(s->spa_us))

#endif
4 changes: 3 additions & 1 deletion include/uzfs_mgmt.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
*/

#ifndef _UZFS_MGMT_H

#define _UZFS_MGMT_H

extern int uzfs_init(void);
Expand All @@ -29,9 +30,10 @@ extern int uzfs_vdev_add(void *spa, char *path, int ashift, int log);
extern int uzfs_create_dataset(void *spa, char *ds, uint64_t vol_size,
uint64_t block_size, int sync, void **zv);
extern int uzfs_open_dataset(void *spa, char *ds, int sync, void **zv);
extern uint64_t uzfs_synced_txg(void *spa);
extern uint64_t uzfs_synced_txg(void *zv);
extern void uzfs_close_dataset(void *zv);
extern void uzfs_close_pool(void *spa);
extern void uzfs_fini(void);
extern uint64_t uzfs_random(uint64_t);

#endif
33 changes: 33 additions & 0 deletions include/uzfs_task.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/

#ifndef _UZFS_TASK_H

#define _UZFS_TASK_H

int dummy_pool_task(void *s);
int post_open_pool(void *s);
int pre_close_pool(void *s);
int post_close_pool(void *s);
int create_txg_update_thread(void *s);
int close_txg_update_thread(void *s);

#endif
9 changes: 8 additions & 1 deletion include/uzfs_zap.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,17 @@ typedef struct {
size_t size; /* size of value */
} uzfs_zap_kv_t;

#define LAST_ITER_TXG "last_iter_txg"

extern long long txg_update_interval_time;

/*
* Here, allocation/freeing of kv_array needs to be handled by caller function.
*/
int uzfs_update_zap_entry(void *zv, const uzfs_zap_kv_t **kv_array, uint64_t n);
int uzfs_update_zap_entries(void *zv, const uzfs_zap_kv_t **kv_array,
uint64_t n);
int uzfs_read_zap_entry(void *zv, uzfs_zap_kv_t *entry);
int uzfs_read_last_iter_txg(void *spa, uint64_t *val);
void uzfs_update_txg_zap_thread(void *s);

#endif
1 change: 1 addition & 0 deletions lib/libzpool/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ USER_C = \
taskq.c \
util.c \
uzfs_io.c \
uzfs_task.c \
uzfs_mgmt.c \
uzfs_zap.c \
vdev_disk_aio.c
Expand Down
57 changes: 48 additions & 9 deletions lib/libzpool/uzfs_mgmt.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,19 @@
#include <sys/zap.h>
#include <sys/uzfs_zvol.h>
#include <sys/stat.h>
#include <uzfs.h>

static int uzfs_fd_rand = -1;

/*
* Pool tasks that need to be done during pool open and close
*/
uzfs_pool_task_funcs_t uzfs_pool_tasks[UZFS_POOL_MAX_TASKS] = {
{ post_open_pool, post_close_pool },
{ create_txg_update_thread, close_txg_update_thread },
{ dummy_pool_task, pre_close_pool }
};

static nvlist_t *
make_root(char *path, int ashift, int log)
{
Expand Down Expand Up @@ -102,16 +112,51 @@ uzfs_init(void)
return (err);
}

/* Opens the pool if any with 'name' */
/*
* closes uzfs pool
*/
void
uzfs_close_pool(spa_t *spa)
{
int i;
for (i = (UZFS_POOL_MAX_TASKS - 1); i >= 0; i--) {
if (uzfs_spa(spa)->tasks_initialized[i] == B_TRUE) {
uzfs_spa(spa)->tasks_initialized[i] = B_FALSE;
uzfs_pool_tasks[i].close_func(spa);
}
}
spa_close(spa, "UZFS_SPA_TAG");
}

/*
* Opens the pool if any with 'name'
*/
int
uzfs_open_pool(char *name, spa_t **s)
{
spa_t *spa = NULL;
int err = spa_open(name, &spa, "SPA");
int i;
int err = spa_open(name, &spa, "UZFS_SPA_TAG");
if (err != 0) {
spa = NULL;
goto ret;
}

if (spa->spa_us != NULL) {
spa_close(spa, "UZFS_SPA_TAG");
spa = NULL;
err = EEXIST;
goto ret;
}
for (i = 0; i < UZFS_POOL_MAX_TASKS; i++) {
err = uzfs_pool_tasks[i].open_func(spa);
if (err != 0) {
uzfs_close_pool(spa);
spa = NULL;
goto ret;
}
uzfs_spa(spa)->tasks_initialized[i] = B_TRUE;
}
ret:
*s = spa;
return (err);
Expand Down Expand Up @@ -346,7 +391,7 @@ uzfs_synced_txg(zvol_state_t *zv)
return (spa_last_synced_txg(zv->zv_spa));
}

/* disowns, closes dataset and pool */
/* disowns, closes dataset */
void
uzfs_close_dataset(zvol_state_t *zv)
{
Expand All @@ -358,12 +403,6 @@ uzfs_close_dataset(zvol_state_t *zv)
kmem_free(zv, sizeof (zvol_state_t));
}

void
uzfs_close_pool(spa_t *spa)
{
spa_close(spa, "SPA");
}

void
uzfs_fini(void)
{
Expand Down
Loading

0 comments on commit 3fef28e

Please sign in to comment.