Merge commit 'refs/top-bases/fix-branch' into fix-branch

This commit is contained in:
Brian Behlendorf 2010-06-29 10:21:53 -07:00
commit c3681c9f29
1 changed files with 38 additions and 27 deletions

View File

@ -356,43 +356,54 @@ static int
traverse_impl(spa_t *spa, uint64_t objset, blkptr_t *rootbp, traverse_impl(spa_t *spa, uint64_t objset, blkptr_t *rootbp,
uint64_t txg_start, int flags, blkptr_cb_t func, void *arg) uint64_t txg_start, int flags, blkptr_cb_t func, void *arg)
{ {
struct traverse_data td; struct traverse_data *td;
struct prefetch_data pd = { 0 }; struct prefetch_data *pd;
zbookmark_t czb; zbookmark_t *czb;
int err; int err;
td.td_spa = spa; td = kmem_alloc(sizeof(struct traverse_data), KM_SLEEP);
td.td_objset = objset; pd = kmem_alloc(sizeof(struct prefetch_data), KM_SLEEP);
td.td_rootbp = rootbp; czb = kmem_alloc(sizeof(zbookmark_t), KM_SLEEP);
td.td_min_txg = txg_start;
td.td_func = func;
td.td_arg = arg;
td.td_pfd = &pd;
td.td_flags = flags;
pd.pd_blks_max = 100; td->td_spa = spa;
pd.pd_flags = flags; td->td_objset = objset;
mutex_init(&pd.pd_mtx, NULL, MUTEX_DEFAULT, NULL); td->td_rootbp = rootbp;
cv_init(&pd.pd_cv, NULL, CV_DEFAULT, NULL); td->td_min_txg = txg_start;
td->td_func = func;
td->td_arg = arg;
td->td_pfd = pd;
td->td_flags = flags;
pd->pd_blks_max = 100;
pd->pd_blks_fetched = 0;
pd->pd_flags = flags;
pd->pd_cancel = B_FALSE;
pd->pd_exited = B_FALSE;
mutex_init(&pd->pd_mtx, NULL, MUTEX_DEFAULT, NULL);
cv_init(&pd->pd_cv, NULL, CV_DEFAULT, NULL);
if (!(flags & TRAVERSE_PREFETCH) || if (!(flags & TRAVERSE_PREFETCH) ||
0 == taskq_dispatch(system_taskq, traverse_prefetch_thread, 0 == taskq_dispatch(system_taskq, traverse_prefetch_thread,
&td, TQ_NOQUEUE)) td, TQ_NOQUEUE))
pd.pd_exited = B_TRUE; pd->pd_exited = B_TRUE;
SET_BOOKMARK(&czb, objset, SET_BOOKMARK(czb, objset,
ZB_ROOT_OBJECT, ZB_ROOT_LEVEL, ZB_ROOT_BLKID); ZB_ROOT_OBJECT, ZB_ROOT_LEVEL, ZB_ROOT_BLKID);
err = traverse_visitbp(&td, NULL, NULL, rootbp, &czb); err = traverse_visitbp(td, NULL, NULL, rootbp, czb);
mutex_enter(&pd.pd_mtx); mutex_enter(&pd->pd_mtx);
pd.pd_cancel = B_TRUE; pd->pd_cancel = B_TRUE;
cv_broadcast(&pd.pd_cv); cv_broadcast(&pd->pd_cv);
while (!pd.pd_exited) while (!pd->pd_exited)
cv_wait(&pd.pd_cv, &pd.pd_mtx); cv_wait(&pd->pd_cv, &pd->pd_mtx);
mutex_exit(&pd.pd_mtx); mutex_exit(&pd->pd_mtx);
mutex_destroy(&pd.pd_mtx); mutex_destroy(&pd->pd_mtx);
cv_destroy(&pd.pd_cv); cv_destroy(&pd->pd_cv);
kmem_free(czb, sizeof(zbookmark_t));
kmem_free(pd, sizeof(struct prefetch_data));
kmem_free(td, sizeof(struct traverse_data));
return (err); return (err);
} }