2008-11-20 20:01:55 +00:00
|
|
|
/*
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
/*
|
2010-05-28 20:45:14 +00:00
|
|
|
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
|
2008-11-20 20:01:55 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/zfs_context.h>
|
|
|
|
#include <sys/dmu_objset.h>
|
|
|
|
#include <sys/dmu_traverse.h>
|
|
|
|
#include <sys/dsl_dataset.h>
|
|
|
|
#include <sys/dsl_dir.h>
|
|
|
|
#include <sys/dsl_pool.h>
|
|
|
|
#include <sys/dnode.h>
|
|
|
|
#include <sys/spa.h>
|
|
|
|
#include <sys/zio.h>
|
|
|
|
#include <sys/dmu_impl.h>
|
2010-05-28 20:45:14 +00:00
|
|
|
#include <sys/sa.h>
|
|
|
|
#include <sys/sa_impl.h>
|
2008-12-03 20:09:06 +00:00
|
|
|
#include <sys/callb.h>
|
|
|
|
|
2010-08-26 21:24:34 +00:00
|
|
|
int zfs_pd_blks_max = 100;
|
|
|
|
|
|
|
|
typedef struct prefetch_data {
|
2008-12-03 20:09:06 +00:00
|
|
|
kmutex_t pd_mtx;
|
|
|
|
kcondvar_t pd_cv;
|
|
|
|
int pd_blks_max;
|
|
|
|
int pd_blks_fetched;
|
|
|
|
int pd_flags;
|
|
|
|
boolean_t pd_cancel;
|
|
|
|
boolean_t pd_exited;
|
2010-08-26 21:24:34 +00:00
|
|
|
} prefetch_data_t;
|
2008-12-03 20:09:06 +00:00
|
|
|
|
2010-08-26 21:24:34 +00:00
|
|
|
typedef struct traverse_data {
|
2008-12-03 20:09:06 +00:00
|
|
|
spa_t *td_spa;
|
|
|
|
uint64_t td_objset;
|
|
|
|
blkptr_t *td_rootbp;
|
|
|
|
uint64_t td_min_txg;
|
|
|
|
int td_flags;
|
2010-08-26 21:24:34 +00:00
|
|
|
prefetch_data_t *td_pfd;
|
2008-12-03 20:09:06 +00:00
|
|
|
blkptr_cb_t *td_func;
|
|
|
|
void *td_arg;
|
2010-08-26 21:24:34 +00:00
|
|
|
} traverse_data_t;
|
2008-11-20 20:01:55 +00:00
|
|
|
|
2010-08-27 23:48:18 +00:00
|
|
|
typedef struct traverse_visitbp_data {
|
|
|
|
/* Function arguments */
|
|
|
|
traverse_data_t *tv_td;
|
|
|
|
const dnode_phys_t *tv_dnp;
|
|
|
|
arc_buf_t *tv_pbuf;
|
|
|
|
blkptr_t *tv_bp;
|
|
|
|
const zbookmark_t *tv_zb;
|
|
|
|
/* Local variables */
|
|
|
|
prefetch_data_t *tv_pd;
|
|
|
|
zbookmark_t tv_czb;
|
|
|
|
arc_buf_t *tv_buf;
|
|
|
|
boolean_t tv_hard;
|
|
|
|
objset_phys_t *tv_osp;
|
|
|
|
dnode_phys_t *tv_ldnp;
|
|
|
|
blkptr_t *tv_cbp;
|
|
|
|
uint32_t tv_flags;
|
|
|
|
int tv_err;
|
|
|
|
int tv_lasterr;
|
|
|
|
int tv_i;
|
|
|
|
int tv_epb;
|
|
|
|
int tv_depth;
|
|
|
|
} traverse_visitbp_data_t;
|
|
|
|
|
|
|
|
static inline int traverse_visitbp(traverse_data_t *td, const
|
|
|
|
dnode_phys_t *dnp, arc_buf_t *pbuf, blkptr_t *bp, const zbookmark_t *zb);
|
2010-08-26 21:24:34 +00:00
|
|
|
static int traverse_dnode(traverse_data_t *td, const dnode_phys_t *dnp,
|
2009-07-02 22:44:48 +00:00
|
|
|
arc_buf_t *buf, uint64_t objset, uint64_t object);
|
|
|
|
|
2010-05-28 20:45:14 +00:00
|
|
|
static int
|
2008-11-20 20:01:55 +00:00
|
|
|
traverse_zil_block(zilog_t *zilog, blkptr_t *bp, void *arg, uint64_t claim_txg)
|
|
|
|
{
|
2010-08-26 21:24:34 +00:00
|
|
|
traverse_data_t *td = arg;
|
2008-12-03 20:09:06 +00:00
|
|
|
zbookmark_t zb;
|
2008-11-20 20:01:55 +00:00
|
|
|
|
2008-12-03 20:09:06 +00:00
|
|
|
if (bp->blk_birth == 0)
|
2010-05-28 20:45:14 +00:00
|
|
|
return (0);
|
2008-11-20 20:01:55 +00:00
|
|
|
|
2008-12-03 20:09:06 +00:00
|
|
|
if (claim_txg == 0 && bp->blk_birth >= spa_first_txg(td->td_spa))
|
2010-05-28 20:45:14 +00:00
|
|
|
return (0);
|
|
|
|
|
|
|
|
SET_BOOKMARK(&zb, td->td_objset, ZB_ZIL_OBJECT, ZB_ZIL_LEVEL,
|
|
|
|
bp->blk_cksum.zc_word[ZIL_ZC_SEQ]);
|
|
|
|
|
|
|
|
(void) td->td_func(td->td_spa, zilog, bp, NULL, &zb, NULL, td->td_arg);
|
2008-12-03 20:09:06 +00:00
|
|
|
|
2010-05-28 20:45:14 +00:00
|
|
|
return (0);
|
2008-11-20 20:01:55 +00:00
|
|
|
}
|
|
|
|
|
2010-05-28 20:45:14 +00:00
|
|
|
static int
|
2008-11-20 20:01:55 +00:00
|
|
|
traverse_zil_record(zilog_t *zilog, lr_t *lrc, void *arg, uint64_t claim_txg)
|
|
|
|
{
|
2010-08-26 21:24:34 +00:00
|
|
|
traverse_data_t *td = arg;
|
2008-11-20 20:01:55 +00:00
|
|
|
|
|
|
|
if (lrc->lrc_txtype == TX_WRITE) {
|
|
|
|
lr_write_t *lr = (lr_write_t *)lrc;
|
|
|
|
blkptr_t *bp = &lr->lr_blkptr;
|
2008-12-03 20:09:06 +00:00
|
|
|
zbookmark_t zb;
|
2008-11-20 20:01:55 +00:00
|
|
|
|
2008-12-03 20:09:06 +00:00
|
|
|
if (bp->blk_birth == 0)
|
2010-05-28 20:45:14 +00:00
|
|
|
return (0);
|
2008-11-20 20:01:55 +00:00
|
|
|
|
2008-12-03 20:09:06 +00:00
|
|
|
if (claim_txg == 0 || bp->blk_birth < claim_txg)
|
2010-05-28 20:45:14 +00:00
|
|
|
return (0);
|
2008-12-03 20:09:06 +00:00
|
|
|
|
2010-08-26 21:24:34 +00:00
|
|
|
SET_BOOKMARK(&zb, td->td_objset, lr->lr_foid,
|
|
|
|
ZB_ZIL_LEVEL, lr->lr_offset / BP_GET_LSIZE(bp));
|
2010-05-28 20:45:14 +00:00
|
|
|
|
|
|
|
(void) td->td_func(td->td_spa, zilog, bp, NULL, &zb, NULL,
|
|
|
|
td->td_arg);
|
2008-11-20 20:01:55 +00:00
|
|
|
}
|
2010-05-28 20:45:14 +00:00
|
|
|
return (0);
|
2008-11-20 20:01:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-08-26 21:24:34 +00:00
|
|
|
traverse_zil(traverse_data_t *td, zil_header_t *zh)
|
2008-11-20 20:01:55 +00:00
|
|
|
{
|
|
|
|
uint64_t claim_txg = zh->zh_claim_txg;
|
|
|
|
zilog_t *zilog;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We only want to visit blocks that have been claimed but not yet
|
2010-05-28 20:45:14 +00:00
|
|
|
* replayed; plus, in read-only mode, blocks that are already stable.
|
2008-11-20 20:01:55 +00:00
|
|
|
*/
|
2009-01-15 21:59:39 +00:00
|
|
|
if (claim_txg == 0 && spa_writeable(td->td_spa))
|
2008-11-20 20:01:55 +00:00
|
|
|
return;
|
|
|
|
|
2008-12-03 20:09:06 +00:00
|
|
|
zilog = zil_alloc(spa_get_dsl(td->td_spa)->dp_meta_objset, zh);
|
2008-11-20 20:01:55 +00:00
|
|
|
|
2008-12-03 20:09:06 +00:00
|
|
|
(void) zil_parse(zilog, traverse_zil_block, traverse_zil_record, td,
|
2008-11-20 20:01:55 +00:00
|
|
|
claim_txg);
|
|
|
|
|
|
|
|
zil_free(zilog);
|
|
|
|
}
|
|
|
|
|
2010-08-27 23:48:18 +00:00
|
|
|
#define TRAVERSE_VISITBP_MAX_DEPTH 20
|
|
|
|
|
|
|
|
static void
|
|
|
|
__traverse_visitbp_init(traverse_visitbp_data_t *tv,
|
|
|
|
traverse_data_t *td, const dnode_phys_t *dnp,
|
|
|
|
arc_buf_t *pbuf, blkptr_t *bp, const zbookmark_t *zb, int depth)
|
2008-11-20 20:01:55 +00:00
|
|
|
{
|
2010-08-27 23:48:18 +00:00
|
|
|
tv->tv_td = td;
|
|
|
|
tv->tv_dnp = dnp;
|
|
|
|
tv->tv_pbuf = pbuf;
|
|
|
|
tv->tv_bp = bp;
|
|
|
|
tv->tv_zb = zb;
|
|
|
|
tv->tv_err = 0;
|
|
|
|
tv->tv_lasterr = 0;
|
|
|
|
tv->tv_buf = NULL;
|
|
|
|
tv->tv_pd = td->td_pfd;
|
|
|
|
tv->tv_hard = td->td_flags & TRAVERSE_HARD;
|
|
|
|
tv->tv_flags = ARC_WAIT;
|
|
|
|
tv->tv_depth = depth;
|
|
|
|
}
|
2008-12-03 20:09:06 +00:00
|
|
|
|
2010-08-27 23:48:18 +00:00
|
|
|
static noinline int
|
|
|
|
__traverse_visitbp(traverse_visitbp_data_t *tv)
|
|
|
|
{
|
|
|
|
ASSERT3S(tv->tv_depth, <, TRAVERSE_VISITBP_MAX_DEPTH);
|
|
|
|
|
|
|
|
if (tv->tv_bp->blk_birth == 0) {
|
|
|
|
tv->tv_err = tv->tv_td->td_func(tv->tv_td->td_spa, NULL, NULL,
|
|
|
|
tv->tv_pbuf, tv->tv_zb, tv->tv_dnp, tv->tv_td->td_arg);
|
|
|
|
return (tv->tv_err);
|
2008-11-20 20:01:55 +00:00
|
|
|
}
|
|
|
|
|
2010-08-27 23:48:18 +00:00
|
|
|
if (tv->tv_bp->blk_birth <= tv->tv_td->td_min_txg)
|
2008-12-03 20:09:06 +00:00
|
|
|
return (0);
|
2008-11-20 20:01:55 +00:00
|
|
|
|
2010-08-27 23:48:18 +00:00
|
|
|
if (tv->tv_pd && !tv->tv_pd->pd_exited &&
|
|
|
|
((tv->tv_pd->pd_flags & TRAVERSE_PREFETCH_DATA) ||
|
|
|
|
BP_GET_TYPE(tv->tv_bp) == DMU_OT_DNODE ||
|
|
|
|
BP_GET_LEVEL(tv->tv_bp) > 0)) {
|
|
|
|
mutex_enter(&tv->tv_pd->pd_mtx);
|
|
|
|
ASSERT(tv->tv_pd->pd_blks_fetched >= 0);
|
|
|
|
while (tv->tv_pd->pd_blks_fetched == 0 && !tv->tv_pd->pd_exited)
|
|
|
|
cv_wait(&tv->tv_pd->pd_cv, &tv->tv_pd->pd_mtx);
|
|
|
|
tv->tv_pd->pd_blks_fetched--;
|
|
|
|
cv_broadcast(&tv->tv_pd->pd_cv);
|
|
|
|
mutex_exit(&tv->tv_pd->pd_mtx);
|
2008-11-20 20:01:55 +00:00
|
|
|
}
|
|
|
|
|
2010-08-27 23:48:18 +00:00
|
|
|
if (tv->tv_td->td_flags & TRAVERSE_PRE) {
|
|
|
|
tv->tv_err = tv->tv_td->td_func(tv->tv_td->td_spa, NULL,
|
|
|
|
tv->tv_bp, tv->tv_pbuf, tv->tv_zb, tv->tv_dnp,
|
|
|
|
tv->tv_td->td_arg);
|
|
|
|
if (tv->tv_err == TRAVERSE_VISIT_NO_CHILDREN)
|
2010-08-26 21:24:34 +00:00
|
|
|
return (0);
|
2010-08-27 23:48:18 +00:00
|
|
|
if (tv->tv_err)
|
|
|
|
return (tv->tv_err);
|
2008-11-20 20:01:55 +00:00
|
|
|
}
|
|
|
|
|
2010-08-27 23:48:18 +00:00
|
|
|
if (BP_GET_LEVEL(tv->tv_bp) > 0) {
|
|
|
|
tv->tv_epb = BP_GET_LSIZE(tv->tv_bp) >> SPA_BLKPTRSHIFT;
|
2008-12-03 20:09:06 +00:00
|
|
|
|
2010-08-27 23:48:18 +00:00
|
|
|
tv->tv_err = dsl_read(NULL, tv->tv_td->td_spa, tv->tv_bp,
|
|
|
|
tv->tv_pbuf, arc_getbuf_func, &tv->tv_buf,
|
|
|
|
ZIO_PRIORITY_ASYNC_READ, ZIO_FLAG_CANFAIL,
|
|
|
|
&tv->tv_flags, tv->tv_zb);
|
|
|
|
if (tv->tv_err)
|
|
|
|
return (tv->tv_err);
|
2008-12-03 20:09:06 +00:00
|
|
|
|
|
|
|
/* recursively visitbp() blocks below this */
|
2010-08-27 23:48:18 +00:00
|
|
|
tv->tv_cbp = tv->tv_buf->b_data;
|
|
|
|
for (tv->tv_i = 0; tv->tv_i < tv->tv_epb;
|
|
|
|
tv->tv_i++, tv->tv_cbp++) {
|
|
|
|
SET_BOOKMARK(&tv->tv_czb, tv->tv_zb->zb_objset,
|
|
|
|
tv->tv_zb->zb_object, tv->tv_zb->zb_level - 1,
|
|
|
|
tv->tv_zb->zb_blkid * tv->tv_epb + tv->tv_i);
|
|
|
|
__traverse_visitbp_init(tv + 1, tv->tv_td,
|
|
|
|
tv->tv_dnp, tv->tv_buf, tv->tv_cbp,
|
|
|
|
&tv->tv_czb, tv->tv_depth + 1);
|
|
|
|
tv->tv_err = __traverse_visitbp(tv + 1);
|
|
|
|
if (tv->tv_err) {
|
|
|
|
if (!tv->tv_hard)
|
2010-05-28 20:45:14 +00:00
|
|
|
break;
|
2010-08-27 23:48:18 +00:00
|
|
|
tv->tv_lasterr = tv->tv_err;
|
2010-05-28 20:45:14 +00:00
|
|
|
}
|
2008-12-03 20:09:06 +00:00
|
|
|
}
|
2010-08-27 23:48:18 +00:00
|
|
|
} else if (BP_GET_TYPE(tv->tv_bp) == DMU_OT_DNODE) {
|
|
|
|
tv->tv_epb = BP_GET_LSIZE(tv->tv_bp) >> DNODE_SHIFT;
|
2008-12-03 20:09:06 +00:00
|
|
|
|
2010-08-27 23:48:18 +00:00
|
|
|
tv->tv_err = dsl_read(NULL, tv->tv_td->td_spa, tv->tv_bp,
|
|
|
|
tv->tv_pbuf, arc_getbuf_func, &tv->tv_buf,
|
|
|
|
ZIO_PRIORITY_ASYNC_READ, ZIO_FLAG_CANFAIL,
|
|
|
|
&tv->tv_flags, tv->tv_zb);
|
|
|
|
if (tv->tv_err)
|
|
|
|
return (tv->tv_err);
|
2008-12-03 20:09:06 +00:00
|
|
|
|
|
|
|
/* recursively visitbp() blocks below this */
|
2010-08-27 23:48:18 +00:00
|
|
|
tv->tv_dnp = tv->tv_buf->b_data;
|
|
|
|
for (tv->tv_i = 0; tv->tv_i < tv->tv_epb;
|
|
|
|
tv->tv_i++, tv->tv_dnp++) {
|
|
|
|
tv->tv_err = traverse_dnode(tv->tv_td, tv->tv_dnp,
|
|
|
|
tv->tv_buf, tv->tv_zb->zb_objset,
|
|
|
|
tv->tv_zb->zb_blkid * tv->tv_epb + tv->tv_i);
|
|
|
|
if (tv->tv_err) {
|
|
|
|
if (!tv->tv_hard)
|
2010-05-28 20:45:14 +00:00
|
|
|
break;
|
2010-08-27 23:48:18 +00:00
|
|
|
tv->tv_lasterr = tv->tv_err;
|
2010-05-28 20:45:14 +00:00
|
|
|
}
|
2008-11-20 20:01:55 +00:00
|
|
|
}
|
2010-08-27 23:48:18 +00:00
|
|
|
} else if (BP_GET_TYPE(tv->tv_bp) == DMU_OT_OBJSET) {
|
|
|
|
|
|
|
|
tv->tv_err = dsl_read_nolock(NULL, tv->tv_td->td_spa,
|
|
|
|
tv->tv_bp, arc_getbuf_func, &tv->tv_buf,
|
|
|
|
ZIO_PRIORITY_ASYNC_READ, ZIO_FLAG_CANFAIL,
|
|
|
|
&tv->tv_flags, tv->tv_zb);
|
|
|
|
if (tv->tv_err)
|
|
|
|
return (tv->tv_err);
|
|
|
|
|
|
|
|
tv->tv_osp = tv->tv_buf->b_data;
|
|
|
|
tv->tv_ldnp = &tv->tv_osp->os_meta_dnode;
|
|
|
|
tv->tv_err = traverse_dnode(tv->tv_td, tv->tv_ldnp, tv->tv_buf,
|
|
|
|
tv->tv_zb->zb_objset, DMU_META_DNODE_OBJECT);
|
|
|
|
if (tv->tv_err && tv->tv_hard) {
|
|
|
|
tv->tv_lasterr = tv->tv_err;
|
|
|
|
tv->tv_err = 0;
|
2010-05-28 20:45:14 +00:00
|
|
|
}
|
2010-08-27 23:48:18 +00:00
|
|
|
if (tv->tv_err == 0 &&
|
|
|
|
arc_buf_size(tv->tv_buf) >= sizeof (objset_phys_t)) {
|
|
|
|
tv->tv_ldnp = &tv->tv_osp->os_userused_dnode;
|
|
|
|
tv->tv_err = traverse_dnode(tv->tv_td, tv->tv_ldnp,
|
|
|
|
tv->tv_buf, tv->tv_zb->zb_objset,
|
2009-07-02 22:44:48 +00:00
|
|
|
DMU_USERUSED_OBJECT);
|
|
|
|
}
|
2010-08-27 23:48:18 +00:00
|
|
|
if (tv->tv_err && tv->tv_hard) {
|
|
|
|
tv->tv_lasterr = tv->tv_err;
|
|
|
|
tv->tv_err = 0;
|
2010-05-28 20:45:14 +00:00
|
|
|
}
|
2010-08-27 23:48:18 +00:00
|
|
|
if (tv->tv_err == 0 &&
|
|
|
|
arc_buf_size(tv->tv_buf) >= sizeof (objset_phys_t)) {
|
|
|
|
tv->tv_ldnp = &tv->tv_osp->os_groupused_dnode;
|
|
|
|
tv->tv_err = traverse_dnode(tv->tv_td, tv->tv_ldnp,
|
|
|
|
tv->tv_buf, tv->tv_zb->zb_objset,
|
2009-07-02 22:44:48 +00:00
|
|
|
DMU_GROUPUSED_OBJECT);
|
2008-11-20 20:01:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-27 23:48:18 +00:00
|
|
|
if (tv->tv_buf)
|
|
|
|
(void) arc_buf_remove_ref(tv->tv_buf, &tv->tv_buf);
|
2008-11-20 20:01:55 +00:00
|
|
|
|
2010-08-27 23:48:18 +00:00
|
|
|
if (tv->tv_err == 0 && tv->tv_lasterr == 0 &&
|
|
|
|
(tv->tv_td->td_flags & TRAVERSE_POST)) {
|
|
|
|
tv->tv_err = tv->tv_td->td_func(tv->tv_td->td_spa, NULL,
|
|
|
|
tv->tv_bp, tv->tv_pbuf, tv->tv_zb, tv->tv_dnp,
|
|
|
|
tv->tv_td->td_arg);
|
2010-05-28 20:45:14 +00:00
|
|
|
}
|
2008-11-20 20:01:55 +00:00
|
|
|
|
2010-08-27 23:48:18 +00:00
|
|
|
return (tv->tv_err != 0 ? tv->tv_err : tv->tv_lasterr);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Due to limited stack space recursive functions are frowned upon in
|
|
|
|
* the Linux kernel. However, they often are the most elegant solution
|
|
|
|
* to a problem. The following code preserves the recursive function
|
|
|
|
* traverse_visitbp() but moves the local variables AND function
|
|
|
|
* arguments to the heap to minimize the stack frame size. Enough
|
|
|
|
* space is initially allocated on the stack for 16 levels of recursion.
|
|
|
|
* This change does ugly-up-the-code but it reduces the worst case
|
|
|
|
* usage from roughly 2496 bytes to 576 bytes on x86_64 archs.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
traverse_visitbp(traverse_data_t *td, const dnode_phys_t *dnp,
|
|
|
|
arc_buf_t *pbuf, blkptr_t *bp, const zbookmark_t *zb)
|
|
|
|
{
|
|
|
|
traverse_visitbp_data_t *tv;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
tv = kmem_zalloc(sizeof(traverse_visitbp_data_t) *
|
|
|
|
TRAVERSE_VISITBP_MAX_DEPTH, KM_SLEEP);
|
|
|
|
__traverse_visitbp_init(tv, td, dnp, pbuf, bp, zb, 0);
|
|
|
|
|
|
|
|
error = __traverse_visitbp(tv);
|
|
|
|
|
|
|
|
kmem_free(tv, sizeof(traverse_visitbp_data_t) *
|
|
|
|
TRAVERSE_VISITBP_MAX_DEPTH);
|
|
|
|
|
|
|
|
return (error);
|
2008-11-20 20:01:55 +00:00
|
|
|
}
|
|
|
|
|
2009-07-02 22:44:48 +00:00
|
|
|
static int
|
2010-08-26 21:24:34 +00:00
|
|
|
traverse_dnode(traverse_data_t *td, const dnode_phys_t *dnp,
|
2009-07-02 22:44:48 +00:00
|
|
|
arc_buf_t *buf, uint64_t objset, uint64_t object)
|
|
|
|
{
|
2010-05-28 20:45:14 +00:00
|
|
|
int j, err = 0, lasterr = 0;
|
2009-07-02 22:44:48 +00:00
|
|
|
zbookmark_t czb;
|
2010-05-28 20:45:14 +00:00
|
|
|
boolean_t hard = (td->td_flags & TRAVERSE_HARD);
|
2009-07-02 22:44:48 +00:00
|
|
|
|
|
|
|
for (j = 0; j < dnp->dn_nblkptr; j++) {
|
|
|
|
SET_BOOKMARK(&czb, objset, object, dnp->dn_nlevels - 1, j);
|
|
|
|
err = traverse_visitbp(td, dnp, buf,
|
|
|
|
(blkptr_t *)&dnp->dn_blkptr[j], &czb);
|
2010-05-28 20:45:14 +00:00
|
|
|
if (err) {
|
|
|
|
if (!hard)
|
|
|
|
break;
|
|
|
|
lasterr = err;
|
|
|
|
}
|
2009-07-02 22:44:48 +00:00
|
|
|
}
|
2010-05-28 20:45:14 +00:00
|
|
|
|
|
|
|
if (dnp->dn_flags & DNODE_FLAG_SPILL_BLKPTR) {
|
|
|
|
SET_BOOKMARK(&czb, objset,
|
|
|
|
object, 0, DMU_SPILL_BLKID);
|
|
|
|
err = traverse_visitbp(td, dnp, buf,
|
|
|
|
(blkptr_t *)&dnp->dn_spill, &czb);
|
|
|
|
if (err) {
|
|
|
|
if (!hard)
|
|
|
|
return (err);
|
|
|
|
lasterr = err;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return (err != 0 ? err : lasterr);
|
2009-07-02 22:44:48 +00:00
|
|
|
}
|
|
|
|
|
2008-12-03 20:09:06 +00:00
|
|
|
/* ARGSUSED */
|
|
|
|
static int
|
2010-05-28 20:45:14 +00:00
|
|
|
traverse_prefetcher(spa_t *spa, zilog_t *zilog, const blkptr_t *bp,
|
|
|
|
arc_buf_t *pbuf, const zbookmark_t *zb, const dnode_phys_t *dnp,
|
|
|
|
void *arg)
|
2008-11-20 20:01:55 +00:00
|
|
|
{
|
2010-08-26 21:24:34 +00:00
|
|
|
prefetch_data_t *pfd = arg;
|
2008-12-03 20:09:06 +00:00
|
|
|
uint32_t aflags = ARC_NOWAIT | ARC_PREFETCH;
|
2008-11-20 20:01:55 +00:00
|
|
|
|
2008-12-03 20:09:06 +00:00
|
|
|
ASSERT(pfd->pd_blks_fetched >= 0);
|
|
|
|
if (pfd->pd_cancel)
|
|
|
|
return (EINTR);
|
2008-11-20 20:01:55 +00:00
|
|
|
|
2008-12-03 20:09:06 +00:00
|
|
|
if (bp == NULL || !((pfd->pd_flags & TRAVERSE_PREFETCH_DATA) ||
|
2010-05-28 20:45:14 +00:00
|
|
|
BP_GET_TYPE(bp) == DMU_OT_DNODE || BP_GET_LEVEL(bp) > 0) ||
|
|
|
|
BP_GET_TYPE(bp) == DMU_OT_INTENT_LOG)
|
2008-11-20 20:01:55 +00:00
|
|
|
return (0);
|
|
|
|
|
2008-12-03 20:09:06 +00:00
|
|
|
mutex_enter(&pfd->pd_mtx);
|
|
|
|
while (!pfd->pd_cancel && pfd->pd_blks_fetched >= pfd->pd_blks_max)
|
|
|
|
cv_wait(&pfd->pd_cv, &pfd->pd_mtx);
|
|
|
|
pfd->pd_blks_fetched++;
|
|
|
|
cv_broadcast(&pfd->pd_cv);
|
|
|
|
mutex_exit(&pfd->pd_mtx);
|
2008-11-20 20:01:55 +00:00
|
|
|
|
2010-05-28 20:45:14 +00:00
|
|
|
(void) dsl_read(NULL, spa, bp, pbuf, NULL, NULL,
|
2008-12-03 20:09:06 +00:00
|
|
|
ZIO_PRIORITY_ASYNC_READ,
|
|
|
|
ZIO_FLAG_CANFAIL | ZIO_FLAG_SPECULATIVE,
|
|
|
|
&aflags, zb);
|
2008-11-20 20:01:55 +00:00
|
|
|
|
2008-12-03 20:09:06 +00:00
|
|
|
return (0);
|
2008-11-20 20:01:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2008-12-03 20:09:06 +00:00
|
|
|
traverse_prefetch_thread(void *arg)
|
2008-11-20 20:01:55 +00:00
|
|
|
{
|
2010-08-26 21:24:34 +00:00
|
|
|
traverse_data_t *td_main = arg;
|
|
|
|
traverse_data_t td = *td_main;
|
2008-12-03 20:09:06 +00:00
|
|
|
zbookmark_t czb;
|
2008-11-20 20:01:55 +00:00
|
|
|
|
2008-12-03 20:09:06 +00:00
|
|
|
td.td_func = traverse_prefetcher;
|
|
|
|
td.td_arg = td_main->td_pfd;
|
|
|
|
td.td_pfd = NULL;
|
2008-11-20 20:01:55 +00:00
|
|
|
|
2010-05-28 20:45:14 +00:00
|
|
|
SET_BOOKMARK(&czb, td.td_objset,
|
|
|
|
ZB_ROOT_OBJECT, ZB_ROOT_LEVEL, ZB_ROOT_BLKID);
|
2008-12-03 20:09:06 +00:00
|
|
|
(void) traverse_visitbp(&td, NULL, NULL, td.td_rootbp, &czb);
|
2008-11-20 20:01:55 +00:00
|
|
|
|
2008-12-03 20:09:06 +00:00
|
|
|
mutex_enter(&td_main->td_pfd->pd_mtx);
|
|
|
|
td_main->td_pfd->pd_exited = B_TRUE;
|
|
|
|
cv_broadcast(&td_main->td_pfd->pd_cv);
|
|
|
|
mutex_exit(&td_main->td_pfd->pd_mtx);
|
2008-11-20 20:01:55 +00:00
|
|
|
}
|
|
|
|
|
2008-12-03 20:09:06 +00:00
|
|
|
/*
|
|
|
|
* NB: dataset must not be changing on-disk (eg, is a snapshot or we are
|
|
|
|
* in syncing context).
|
|
|
|
*/
|
|
|
|
static int
|
2010-08-26 21:24:34 +00:00
|
|
|
traverse_impl(spa_t *spa, dsl_dataset_t *ds, blkptr_t *rootbp,
|
2008-12-03 20:09:06 +00:00
|
|
|
uint64_t txg_start, int flags, blkptr_cb_t func, void *arg)
|
2008-11-20 20:01:55 +00:00
|
|
|
{
|
2010-08-26 17:58:47 +00:00
|
|
|
traverse_data_t *td;
|
|
|
|
prefetch_data_t *pd;
|
|
|
|
zbookmark_t *czb;
|
2008-12-03 20:09:06 +00:00
|
|
|
int err;
|
2008-11-20 20:01:55 +00:00
|
|
|
|
2010-08-26 17:58:47 +00:00
|
|
|
td = kmem_alloc(sizeof(traverse_data_t), KM_SLEEP);
|
|
|
|
pd = kmem_zalloc(sizeof(prefetch_data_t), KM_SLEEP);
|
|
|
|
czb = kmem_alloc(sizeof(zbookmark_t), KM_SLEEP);
|
|
|
|
|
|
|
|
td->td_spa = spa;
|
|
|
|
td->td_objset = ds ? ds->ds_object : 0;
|
|
|
|
td->td_rootbp = rootbp;
|
|
|
|
td->td_min_txg = txg_start;
|
|
|
|
td->td_func = func;
|
|
|
|
td->td_arg = arg;
|
|
|
|
td->td_pfd = pd;
|
|
|
|
td->td_flags = flags;
|
2008-12-03 20:09:06 +00:00
|
|
|
|
2010-08-26 17:58:47 +00:00
|
|
|
pd->pd_blks_max = zfs_pd_blks_max;
|
|
|
|
pd->pd_flags = flags;
|
|
|
|
mutex_init(&pd->pd_mtx, NULL, MUTEX_DEFAULT, NULL);
|
|
|
|
cv_init(&pd->pd_cv, NULL, CV_DEFAULT, NULL);
|
2008-12-03 20:09:06 +00:00
|
|
|
|
2010-08-26 21:24:34 +00:00
|
|
|
/* See comment on ZIL traversal in dsl_scan_visitds. */
|
|
|
|
if (ds != NULL && !dsl_dataset_is_snapshot(ds)) {
|
|
|
|
objset_t *os;
|
|
|
|
|
|
|
|
err = dmu_objset_from_ds(ds, &os);
|
|
|
|
if (err)
|
|
|
|
return (err);
|
|
|
|
|
2010-08-26 17:58:47 +00:00
|
|
|
traverse_zil(td, &os->os_zil_header);
|
2010-08-26 21:24:34 +00:00
|
|
|
}
|
|
|
|
|
2008-12-03 20:09:06 +00:00
|
|
|
if (!(flags & TRAVERSE_PREFETCH) ||
|
|
|
|
0 == taskq_dispatch(system_taskq, traverse_prefetch_thread,
|
2010-08-26 17:58:47 +00:00
|
|
|
td, TQ_NOQUEUE))
|
|
|
|
pd->pd_exited = B_TRUE;
|
2008-12-03 20:09:06 +00:00
|
|
|
|
2010-08-26 17:58:47 +00:00
|
|
|
SET_BOOKMARK(czb, td->td_objset,
|
2010-05-28 20:45:14 +00:00
|
|
|
ZB_ROOT_OBJECT, ZB_ROOT_LEVEL, ZB_ROOT_BLKID);
|
2010-08-26 17:58:47 +00:00
|
|
|
err = traverse_visitbp(td, NULL, NULL, rootbp, czb);
|
|
|
|
|
|
|
|
mutex_enter(&pd->pd_mtx);
|
|
|
|
pd->pd_cancel = B_TRUE;
|
|
|
|
cv_broadcast(&pd->pd_cv);
|
|
|
|
while (!pd->pd_exited)
|
|
|
|
cv_wait(&pd->pd_cv, &pd->pd_mtx);
|
|
|
|
mutex_exit(&pd->pd_mtx);
|
2008-12-03 20:09:06 +00:00
|
|
|
|
2010-08-26 17:58:47 +00:00
|
|
|
mutex_destroy(&pd->pd_mtx);
|
|
|
|
cv_destroy(&pd->pd_cv);
|
2008-12-03 20:09:06 +00:00
|
|
|
|
2010-08-26 17:58:47 +00:00
|
|
|
kmem_free(czb, sizeof(zbookmark_t));
|
|
|
|
kmem_free(pd, sizeof(struct prefetch_data));
|
|
|
|
kmem_free(td, sizeof(struct traverse_data));
|
2008-11-20 20:01:55 +00:00
|
|
|
|
2008-12-03 20:09:06 +00:00
|
|
|
return (err);
|
2008-11-20 20:01:55 +00:00
|
|
|
}
|
|
|
|
|
2008-12-03 20:09:06 +00:00
|
|
|
/*
|
|
|
|
* NB: dataset must not be changing on-disk (eg, is a snapshot or we are
|
|
|
|
* in syncing context).
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
traverse_dataset(dsl_dataset_t *ds, uint64_t txg_start, int flags,
|
|
|
|
blkptr_cb_t func, void *arg)
|
2008-11-20 20:01:55 +00:00
|
|
|
{
|
2010-08-26 21:24:34 +00:00
|
|
|
return (traverse_impl(ds->ds_dir->dd_pool->dp_spa, ds,
|
2008-12-03 20:09:06 +00:00
|
|
|
&ds->ds_phys->ds_bp, txg_start, flags, func, arg));
|
2008-11-20 20:01:55 +00:00
|
|
|
}
|
|
|
|
|
2008-12-03 20:09:06 +00:00
|
|
|
/*
|
|
|
|
* NB: pool must not be changing on-disk (eg, from zdb or sync context).
|
|
|
|
*/
|
|
|
|
int
|
2010-05-28 20:45:14 +00:00
|
|
|
traverse_pool(spa_t *spa, uint64_t txg_start, int flags,
|
|
|
|
blkptr_cb_t func, void *arg)
|
2008-11-20 20:01:55 +00:00
|
|
|
{
|
2010-05-28 20:45:14 +00:00
|
|
|
int err, lasterr = 0;
|
2008-12-03 20:09:06 +00:00
|
|
|
uint64_t obj;
|
|
|
|
dsl_pool_t *dp = spa_get_dsl(spa);
|
|
|
|
objset_t *mos = dp->dp_meta_objset;
|
2010-05-28 20:45:14 +00:00
|
|
|
boolean_t hard = (flags & TRAVERSE_HARD);
|
2008-12-03 20:09:06 +00:00
|
|
|
|
|
|
|
/* visit the MOS */
|
2010-08-26 21:24:34 +00:00
|
|
|
err = traverse_impl(spa, NULL, spa_get_rootblkptr(spa),
|
2010-05-28 20:45:14 +00:00
|
|
|
txg_start, flags, func, arg);
|
2008-12-03 20:09:06 +00:00
|
|
|
if (err)
|
|
|
|
return (err);
|
|
|
|
|
|
|
|
/* visit each dataset */
|
2010-05-28 20:45:14 +00:00
|
|
|
for (obj = 1; err == 0 || (err != ESRCH && hard);
|
|
|
|
err = dmu_object_next(mos, &obj, FALSE, txg_start)) {
|
2008-12-03 20:09:06 +00:00
|
|
|
dmu_object_info_t doi;
|
|
|
|
|
|
|
|
err = dmu_object_info(mos, obj, &doi);
|
2010-05-28 20:45:14 +00:00
|
|
|
if (err) {
|
|
|
|
if (!hard)
|
|
|
|
return (err);
|
|
|
|
lasterr = err;
|
|
|
|
continue;
|
|
|
|
}
|
2008-12-03 20:09:06 +00:00
|
|
|
|
|
|
|
if (doi.doi_type == DMU_OT_DSL_DATASET) {
|
|
|
|
dsl_dataset_t *ds;
|
2010-05-28 20:45:14 +00:00
|
|
|
uint64_t txg = txg_start;
|
|
|
|
|
2008-12-03 20:09:06 +00:00
|
|
|
rw_enter(&dp->dp_config_rwlock, RW_READER);
|
|
|
|
err = dsl_dataset_hold_obj(dp, obj, FTAG, &ds);
|
|
|
|
rw_exit(&dp->dp_config_rwlock);
|
2010-05-28 20:45:14 +00:00
|
|
|
if (err) {
|
|
|
|
if (!hard)
|
|
|
|
return (err);
|
|
|
|
lasterr = err;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (ds->ds_phys->ds_prev_snap_txg > txg)
|
|
|
|
txg = ds->ds_phys->ds_prev_snap_txg;
|
|
|
|
err = traverse_dataset(ds, txg, flags, func, arg);
|
2008-12-03 20:09:06 +00:00
|
|
|
dsl_dataset_rele(ds, FTAG);
|
2010-05-28 20:45:14 +00:00
|
|
|
if (err) {
|
|
|
|
if (!hard)
|
|
|
|
return (err);
|
|
|
|
lasterr = err;
|
|
|
|
}
|
2008-12-03 20:09:06 +00:00
|
|
|
}
|
2008-11-20 20:01:55 +00:00
|
|
|
}
|
2008-12-03 20:09:06 +00:00
|
|
|
if (err == ESRCH)
|
|
|
|
err = 0;
|
2010-05-28 20:45:14 +00:00
|
|
|
return (err != 0 ? err : lasterr);
|
2008-11-20 20:01:55 +00:00
|
|
|
}
|
2010-08-26 18:49:16 +00:00
|
|
|
|
|
|
|
#if defined(_KERNEL) && defined(HAVE_SPL)
|
|
|
|
EXPORT_SYMBOL(traverse_dataset);
|
|
|
|
EXPORT_SYMBOL(traverse_pool);
|
2011-05-03 22:09:28 +00:00
|
|
|
|
|
|
|
module_param(zfs_pd_blks_max, int, 0644);
|
|
|
|
MODULE_PARM_DESC(zfs_pd_blks_max, "Max number of blocks to prefetch");
|
2010-08-26 18:49:16 +00:00
|
|
|
#endif
|