3f9d6ad73e45c6823b409f93b0c8d4f62861d2d5Lin Ling/*
3f9d6ad73e45c6823b409f93b0c8d4f62861d2d5Lin Ling * CDDL HEADER START
3f9d6ad73e45c6823b409f93b0c8d4f62861d2d5Lin Ling *
3f9d6ad73e45c6823b409f93b0c8d4f62861d2d5Lin Ling * The contents of this file are subject to the terms of the
3f9d6ad73e45c6823b409f93b0c8d4f62861d2d5Lin Ling * Common Development and Distribution License (the "License").
3f9d6ad73e45c6823b409f93b0c8d4f62861d2d5Lin Ling * You may not use this file except in compliance with the License.
3f9d6ad73e45c6823b409f93b0c8d4f62861d2d5Lin Ling *
3f9d6ad73e45c6823b409f93b0c8d4f62861d2d5Lin Ling * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
3f9d6ad73e45c6823b409f93b0c8d4f62861d2d5Lin Ling * or http://www.opensolaris.org/os/licensing.
3f9d6ad73e45c6823b409f93b0c8d4f62861d2d5Lin Ling * See the License for the specific language governing permissions
3f9d6ad73e45c6823b409f93b0c8d4f62861d2d5Lin Ling * and limitations under the License.
3f9d6ad73e45c6823b409f93b0c8d4f62861d2d5Lin Ling *
3f9d6ad73e45c6823b409f93b0c8d4f62861d2d5Lin Ling * When distributing Covered Code, include this CDDL HEADER in each
3f9d6ad73e45c6823b409f93b0c8d4f62861d2d5Lin Ling * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
3f9d6ad73e45c6823b409f93b0c8d4f62861d2d5Lin Ling * If applicable, add the following below this CDDL HEADER, with the
3f9d6ad73e45c6823b409f93b0c8d4f62861d2d5Lin Ling * fields enclosed by brackets "[]" replaced with your own identifying
3f9d6ad73e45c6823b409f93b0c8d4f62861d2d5Lin Ling * information: Portions Copyright [yyyy] [name of copyright owner]
3f9d6ad73e45c6823b409f93b0c8d4f62861d2d5Lin Ling *
3f9d6ad73e45c6823b409f93b0c8d4f62861d2d5Lin Ling * CDDL HEADER END
3f9d6ad73e45c6823b409f93b0c8d4f62861d2d5Lin Ling */
3f9d6ad73e45c6823b409f93b0c8d4f62861d2d5Lin Ling/*
3f9d6ad73e45c6823b409f93b0c8d4f62861d2d5Lin Ling * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
7802d7bf98dec568dadf72286893b1fe5abd8602Matthew Ahrens * Copyright (c) 2012, 2014 by Delphix. All rights reserved.
3f9d6ad73e45c6823b409f93b0c8d4f62861d2d5Lin Ling */
3f9d6ad73e45c6823b409f93b0c8d4f62861d2d5Lin Ling
3f9d6ad73e45c6823b409f93b0c8d4f62861d2d5Lin Ling#ifndef _SYS_DSL_SCAN_H
3f9d6ad73e45c6823b409f93b0c8d4f62861d2d5Lin Ling#define _SYS_DSL_SCAN_H
3f9d6ad73e45c6823b409f93b0c8d4f62861d2d5Lin Ling
3f9d6ad73e45c6823b409f93b0c8d4f62861d2d5Lin Ling#include <sys/zfs_context.h>
3f9d6ad73e45c6823b409f93b0c8d4f62861d2d5Lin Ling#include <sys/zio.h>
3f9d6ad73e45c6823b409f93b0c8d4f62861d2d5Lin Ling#include <sys/ddt.h>
3f9d6ad73e45c6823b409f93b0c8d4f62861d2d5Lin Ling#include <sys/bplist.h>
3f9d6ad73e45c6823b409f93b0c8d4f62861d2d5Lin Ling
3f9d6ad73e45c6823b409f93b0c8d4f62861d2d5Lin Ling#ifdef __cplusplus
3f9d6ad73e45c6823b409f93b0c8d4f62861d2d5Lin Lingextern "C" {
3f9d6ad73e45c6823b409f93b0c8d4f62861d2d5Lin Ling#endif
3f9d6ad73e45c6823b409f93b0c8d4f62861d2d5Lin Ling
3f9d6ad73e45c6823b409f93b0c8d4f62861d2d5Lin Lingstruct objset;
3f9d6ad73e45c6823b409f93b0c8d4f62861d2d5Lin Lingstruct dsl_dir;
3f9d6ad73e45c6823b409f93b0c8d4f62861d2d5Lin Lingstruct dsl_dataset;
3f9d6ad73e45c6823b409f93b0c8d4f62861d2d5Lin Lingstruct dsl_pool;
3f9d6ad73e45c6823b409f93b0c8d4f62861d2d5Lin Lingstruct dmu_tx;
3f9d6ad73e45c6823b409f93b0c8d4f62861d2d5Lin Ling
3f9d6ad73e45c6823b409f93b0c8d4f62861d2d5Lin Ling/*
3f9d6ad73e45c6823b409f93b0c8d4f62861d2d5Lin Ling * All members of this structure must be uint64_t, for byteswap
3f9d6ad73e45c6823b409f93b0c8d4f62861d2d5Lin Ling * purposes.
3f9d6ad73e45c6823b409f93b0c8d4f62861d2d5Lin Ling */
3f9d6ad73e45c6823b409f93b0c8d4f62861d2d5Lin Lingtypedef struct dsl_scan_phys {
3f9d6ad73e45c6823b409f93b0c8d4f62861d2d5Lin Ling uint64_t scn_func; /* pool_scan_func_t */
3f9d6ad73e45c6823b409f93b0c8d4f62861d2d5Lin Ling uint64_t scn_state; /* dsl_scan_state_t */
3f9d6ad73e45c6823b409f93b0c8d4f62861d2d5Lin Ling uint64_t scn_queue_obj;
3f9d6ad73e45c6823b409f93b0c8d4f62861d2d5Lin Ling uint64_t scn_min_txg;
3f9d6ad73e45c6823b409f93b0c8d4f62861d2d5Lin Ling uint64_t scn_max_txg;
3f9d6ad73e45c6823b409f93b0c8d4f62861d2d5Lin Ling uint64_t scn_cur_min_txg;
3f9d6ad73e45c6823b409f93b0c8d4f62861d2d5Lin Ling uint64_t scn_cur_max_txg;
3f9d6ad73e45c6823b409f93b0c8d4f62861d2d5Lin Ling uint64_t scn_start_time;
3f9d6ad73e45c6823b409f93b0c8d4f62861d2d5Lin Ling uint64_t scn_end_time;
3f9d6ad73e45c6823b409f93b0c8d4f62861d2d5Lin Ling uint64_t scn_to_examine; /* total bytes to be scanned */
3f9d6ad73e45c6823b409f93b0c8d4f62861d2d5Lin Ling uint64_t scn_examined; /* bytes scanned so far */
3f9d6ad73e45c6823b409f93b0c8d4f62861d2d5Lin Ling uint64_t scn_to_process;
3f9d6ad73e45c6823b409f93b0c8d4f62861d2d5Lin Ling uint64_t scn_processed;
3f9d6ad73e45c6823b409f93b0c8d4f62861d2d5Lin Ling uint64_t scn_errors; /* scan I/O error count */
3f9d6ad73e45c6823b409f93b0c8d4f62861d2d5Lin Ling uint64_t scn_ddt_class_max;
3f9d6ad73e45c6823b409f93b0c8d4f62861d2d5Lin Ling ddt_bookmark_t scn_ddt_bookmark;
7802d7bf98dec568dadf72286893b1fe5abd8602Matthew Ahrens zbookmark_phys_t scn_bookmark;
3f9d6ad73e45c6823b409f93b0c8d4f62861d2d5Lin Ling uint64_t scn_flags; /* dsl_scan_flags_t */
3f9d6ad73e45c6823b409f93b0c8d4f62861d2d5Lin Ling} dsl_scan_phys_t;
3f9d6ad73e45c6823b409f93b0c8d4f62861d2d5Lin Ling
3f9d6ad73e45c6823b409f93b0c8d4f62861d2d5Lin Ling#define SCAN_PHYS_NUMINTS (sizeof (dsl_scan_phys_t) / sizeof (uint64_t))
3f9d6ad73e45c6823b409f93b0c8d4f62861d2d5Lin Ling
3f9d6ad73e45c6823b409f93b0c8d4f62861d2d5Lin Lingtypedef enum dsl_scan_flags {
3f9d6ad73e45c6823b409f93b0c8d4f62861d2d5Lin Ling DSF_VISIT_DS_AGAIN = 1<<0,
3f9d6ad73e45c6823b409f93b0c8d4f62861d2d5Lin Ling} dsl_scan_flags_t;
3f9d6ad73e45c6823b409f93b0c8d4f62861d2d5Lin Ling
b4952e17e8858d3225793b28788278de9fe6038dGeorge Wilson/*
b4952e17e8858d3225793b28788278de9fe6038dGeorge Wilson * Every pool will have one dsl_scan_t and this structure will contain
b4952e17e8858d3225793b28788278de9fe6038dGeorge Wilson * in-memory information about the scan and a pointer to the on-disk
b4952e17e8858d3225793b28788278de9fe6038dGeorge Wilson * representation (i.e. dsl_scan_phys_t). Most of the state of the scan
b4952e17e8858d3225793b28788278de9fe6038dGeorge Wilson * is contained on-disk to allow the scan to resume in the event of a reboot
b4952e17e8858d3225793b28788278de9fe6038dGeorge Wilson * or panic. This structure maintains information about the behavior of a
b4952e17e8858d3225793b28788278de9fe6038dGeorge Wilson * running scan, some caching information, and how it should traverse the pool.
b4952e17e8858d3225793b28788278de9fe6038dGeorge Wilson *
b4952e17e8858d3225793b28788278de9fe6038dGeorge Wilson * The following members of this structure direct the behavior of the scan:
b4952e17e8858d3225793b28788278de9fe6038dGeorge Wilson *
b4952e17e8858d3225793b28788278de9fe6038dGeorge Wilson * scn_pausing - a scan that cannot be completed in a single txg or
b4952e17e8858d3225793b28788278de9fe6038dGeorge Wilson * has exceeded its allotted time will need to pause.
b4952e17e8858d3225793b28788278de9fe6038dGeorge Wilson * When this flag is set the scanner will stop traversing
b4952e17e8858d3225793b28788278de9fe6038dGeorge Wilson * the pool and write out the current state to disk.
b4952e17e8858d3225793b28788278de9fe6038dGeorge Wilson *
b4952e17e8858d3225793b28788278de9fe6038dGeorge Wilson * scn_restart_txg - directs the scanner to either restart or start a
b4952e17e8858d3225793b28788278de9fe6038dGeorge Wilson * a scan at the specified txg value.
b4952e17e8858d3225793b28788278de9fe6038dGeorge Wilson *
b4952e17e8858d3225793b28788278de9fe6038dGeorge Wilson * scn_done_txg - when a scan completes its traversal it will set
b4952e17e8858d3225793b28788278de9fe6038dGeorge Wilson * the completion txg to the next txg. This is necessary
b4952e17e8858d3225793b28788278de9fe6038dGeorge Wilson * to ensure that any blocks that were freed during
b4952e17e8858d3225793b28788278de9fe6038dGeorge Wilson * the scan but have not yet been processed (i.e deferred
b4952e17e8858d3225793b28788278de9fe6038dGeorge Wilson * frees) are accounted for.
b4952e17e8858d3225793b28788278de9fe6038dGeorge Wilson *
b4952e17e8858d3225793b28788278de9fe6038dGeorge Wilson * This structure also maintains information about deferred frees which are
b4952e17e8858d3225793b28788278de9fe6038dGeorge Wilson * a special kind of traversal. Deferred free can exist in either a bptree or
b4952e17e8858d3225793b28788278de9fe6038dGeorge Wilson * a bpobj structure. The scn_is_bptree flag will indicate the type of
b4952e17e8858d3225793b28788278de9fe6038dGeorge Wilson * deferred free that is in progress. If the deferred free is part of an
b4952e17e8858d3225793b28788278de9fe6038dGeorge Wilson * asynchronous destroy then the scn_async_destroying flag will be set.
b4952e17e8858d3225793b28788278de9fe6038dGeorge Wilson */
3f9d6ad73e45c6823b409f93b0c8d4f62861d2d5Lin Lingtypedef struct dsl_scan {
3f9d6ad73e45c6823b409f93b0c8d4f62861d2d5Lin Ling struct dsl_pool *scn_dp;
3f9d6ad73e45c6823b409f93b0c8d4f62861d2d5Lin Ling
3f9d6ad73e45c6823b409f93b0c8d4f62861d2d5Lin Ling boolean_t scn_pausing;
3f9d6ad73e45c6823b409f93b0c8d4f62861d2d5Lin Ling uint64_t scn_restart_txg;
b4952e17e8858d3225793b28788278de9fe6038dGeorge Wilson uint64_t scn_done_txg;
3f9d6ad73e45c6823b409f93b0c8d4f62861d2d5Lin Ling uint64_t scn_sync_start_time;
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrens zio_t *scn_zio_root;
3f9d6ad73e45c6823b409f93b0c8d4f62861d2d5Lin Ling
ad135b5d644628e791c3188a6ecbd9c257961ef8Christopher Siden /* for freeing blocks */
ad135b5d644628e791c3188a6ecbd9c257961ef8Christopher Siden boolean_t scn_is_bptree;
4a92375985c37d61406d66cd2b10ee642eb1f5e7George Wilson boolean_t scn_async_destroying;
7fd05ac4dec0c343d2f68f310d3718b715ecfbafMatthew Ahrens boolean_t scn_async_stalled;
ad135b5d644628e791c3188a6ecbd9c257961ef8Christopher Siden
3f9d6ad73e45c6823b409f93b0c8d4f62861d2d5Lin Ling /* for debugging / information */
3f9d6ad73e45c6823b409f93b0c8d4f62861d2d5Lin Ling uint64_t scn_visited_this_txg;
3f9d6ad73e45c6823b409f93b0c8d4f62861d2d5Lin Ling
3f9d6ad73e45c6823b409f93b0c8d4f62861d2d5Lin Ling dsl_scan_phys_t scn_phys;
3f9d6ad73e45c6823b409f93b0c8d4f62861d2d5Lin Ling} dsl_scan_t;
3f9d6ad73e45c6823b409f93b0c8d4f62861d2d5Lin Ling
3f9d6ad73e45c6823b409f93b0c8d4f62861d2d5Lin Lingint dsl_scan_init(struct dsl_pool *dp, uint64_t txg);
3f9d6ad73e45c6823b409f93b0c8d4f62861d2d5Lin Lingvoid dsl_scan_fini(struct dsl_pool *dp);
3f9d6ad73e45c6823b409f93b0c8d4f62861d2d5Lin Lingvoid dsl_scan_sync(struct dsl_pool *, dmu_tx_t *);
3f9d6ad73e45c6823b409f93b0c8d4f62861d2d5Lin Lingint dsl_scan_cancel(struct dsl_pool *);
3f9d6ad73e45c6823b409f93b0c8d4f62861d2d5Lin Lingint dsl_scan(struct dsl_pool *, pool_scan_func_t);
3f9d6ad73e45c6823b409f93b0c8d4f62861d2d5Lin Lingvoid dsl_resilver_restart(struct dsl_pool *, uint64_t txg);
3f9d6ad73e45c6823b409f93b0c8d4f62861d2d5Lin Lingboolean_t dsl_scan_resilvering(struct dsl_pool *dp);
3f9d6ad73e45c6823b409f93b0c8d4f62861d2d5Lin Lingboolean_t dsl_dataset_unstable(struct dsl_dataset *ds);
3f9d6ad73e45c6823b409f93b0c8d4f62861d2d5Lin Lingvoid dsl_scan_ddt_entry(dsl_scan_t *scn, enum zio_checksum checksum,
3f9d6ad73e45c6823b409f93b0c8d4f62861d2d5Lin Ling ddt_entry_t *dde, dmu_tx_t *tx);
3f9d6ad73e45c6823b409f93b0c8d4f62861d2d5Lin Lingvoid dsl_scan_ds_destroyed(struct dsl_dataset *ds, struct dmu_tx *tx);
3f9d6ad73e45c6823b409f93b0c8d4f62861d2d5Lin Lingvoid dsl_scan_ds_snapshotted(struct dsl_dataset *ds, struct dmu_tx *tx);
3f9d6ad73e45c6823b409f93b0c8d4f62861d2d5Lin Lingvoid dsl_scan_ds_clone_swapped(struct dsl_dataset *ds1, struct dsl_dataset *ds2,
3f9d6ad73e45c6823b409f93b0c8d4f62861d2d5Lin Ling struct dmu_tx *tx);
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrensboolean_t dsl_scan_active(dsl_scan_t *scn);
3f9d6ad73e45c6823b409f93b0c8d4f62861d2d5Lin Ling
3f9d6ad73e45c6823b409f93b0c8d4f62861d2d5Lin Ling#ifdef __cplusplus
3f9d6ad73e45c6823b409f93b0c8d4f62861d2d5Lin Ling}
3f9d6ad73e45c6823b409f93b0c8d4f62861d2d5Lin Ling#endif
3f9d6ad73e45c6823b409f93b0c8d4f62861d2d5Lin Ling
3f9d6ad73e45c6823b409f93b0c8d4f62861d2d5Lin Ling#endif /* _SYS_DSL_SCAN_H */