usr/src/uts/common/fs/zfs/dsl_scan.c
author Christopher Siden <chris.siden@delphix.com>
Mon, 21 May 2012 12:11:39 -0700
changeset 13700 2889e2596bd6
parent 12839 1eab9192da8b
child 13743 95aba6e49b9f
permissions -rw-r--r--
2619 asynchronous destruction of ZFS file systems 2747 SPA versioning with zfs feature flags Reviewed by: Matt Ahrens <[email protected]> Reviewed by: George Wilson <[email protected]> Reviewed by: Richard Lowe <[email protected]> Reviewed by: Dan Kruchinin <[email protected]> Approved by: Eric Schrock <[email protected]>
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
     1
/*
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
     2
 * CDDL HEADER START
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
     3
 *
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
     4
 * The contents of this file are subject to the terms of the
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
     5
 * Common Development and Distribution License (the "License").
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
     6
 * You may not use this file except in compliance with the License.
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
     7
 *
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
     8
 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
     9
 * or http://www.opensolaris.org/os/licensing.
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
    10
 * See the License for the specific language governing permissions
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
    11
 * and limitations under the License.
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
    12
 *
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
    13
 * When distributing Covered Code, include this CDDL HEADER in each
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
    14
 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
    15
 * If applicable, add the following below this CDDL HEADER, with the
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
    16
 * fields enclosed by brackets "[]" replaced with your own identifying
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
    17
 * information: Portions Copyright [yyyy] [name of copyright owner]
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
    18
 *
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
    19
 * CDDL HEADER END
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
    20
 */
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
    21
/*
12295
e16f396f04a1 6948911 snapshot deletion can induce unsatisfiable allocations in txg sync
George Wilson <George.Wilson@Sun.COM>
parents: 11935
diff changeset
    22
 * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
13700
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 12839
diff changeset
    23
 * Copyright (c) 2012 by Delphix. All rights reserved.
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
    24
 */
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
    25
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
    26
#include <sys/dsl_scan.h>
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
    27
#include <sys/dsl_pool.h>
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
    28
#include <sys/dsl_dataset.h>
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
    29
#include <sys/dsl_prop.h>
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
    30
#include <sys/dsl_dir.h>
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
    31
#include <sys/dsl_synctask.h>
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
    32
#include <sys/dnode.h>
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
    33
#include <sys/dmu_tx.h>
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
    34
#include <sys/dmu_objset.h>
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
    35
#include <sys/arc.h>
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
    36
#include <sys/zap.h>
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
    37
#include <sys/zio.h>
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
    38
#include <sys/zfs_context.h>
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
    39
#include <sys/fs/zfs.h>
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
    40
#include <sys/zfs_znode.h>
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
    41
#include <sys/spa_impl.h>
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
    42
#include <sys/vdev_impl.h>
7160
12f467ba43f4 6725330 'zpool scrub -v' doesn't show data errors after scrub completes
ahrens
parents: 7046
diff changeset
    43
#include <sys/zil_impl.h>
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
    44
#include <sys/zio_checksum.h>
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
    45
#include <sys/ddt.h>
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11815
diff changeset
    46
#include <sys/sa.h>
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11815
diff changeset
    47
#include <sys/sa_impl.h>
13700
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 12839
diff changeset
    48
#include <sys/zfeature.h>
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
    49
#ifdef _KERNEL
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
    50
#include <sys/zfs_vfsops.h>
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
    51
#endif
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
    52
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
    53
typedef int (scan_cb_t)(dsl_pool_t *, const blkptr_t *, const zbookmark_t *);
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
    54
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
    55
static scan_cb_t dsl_scan_defrag_cb;
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
    56
static scan_cb_t dsl_scan_scrub_cb;
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
    57
static scan_cb_t dsl_scan_remove_cb;
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
    58
static dsl_syncfunc_t dsl_scan_cancel_sync;
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
    59
static void dsl_scan_sync_state(dsl_scan_t *, dmu_tx_t *tx);
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
    60
12586
b118bbd65be9 6494473 ZFS needs a way to slow down resilvering
George Wilson <George.Wilson@Sun.COM>
parents: 12470
diff changeset
    61
int zfs_top_maxinflight = 32;		/* maximum I/Os per top-level */
b118bbd65be9 6494473 ZFS needs a way to slow down resilvering
George Wilson <George.Wilson@Sun.COM>
parents: 12470
diff changeset
    62
int zfs_resilver_delay = 2;		/* number of ticks to delay resilver */
b118bbd65be9 6494473 ZFS needs a way to slow down resilvering
George Wilson <George.Wilson@Sun.COM>
parents: 12470
diff changeset
    63
int zfs_scrub_delay = 4;		/* number of ticks to delay scrub */
b118bbd65be9 6494473 ZFS needs a way to slow down resilvering
George Wilson <George.Wilson@Sun.COM>
parents: 12470
diff changeset
    64
int zfs_scan_idle = 50;			/* idle window in clock ticks */
b118bbd65be9 6494473 ZFS needs a way to slow down resilvering
George Wilson <George.Wilson@Sun.COM>
parents: 12470
diff changeset
    65
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
    66
int zfs_scan_min_time_ms = 1000; /* min millisecs to scrub per txg */
12470
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
    67
int zfs_free_min_time_ms = 1000; /* min millisecs to free per txg */
11182
5997a9e6e9e7 6904168 change zfs_txg_synctime (etc.) tunables to zfs_txg_synctime_ms
Lin Ling <Lin.Ling@Sun.COM>
parents: 11147
diff changeset
    68
int zfs_resilver_min_time_ms = 3000; /* min millisecs to resilver per txg */
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
    69
boolean_t zfs_no_scrub_io = B_FALSE; /* set to disable scrub i/o */
11147
74e8c05021f1 6678033 resilver code should prefetch
George Wilson <George.Wilson@Sun.COM>
parents: 11137
diff changeset
    70
boolean_t zfs_no_scrub_prefetch = B_FALSE; /* set to disable srub prefetching */
11125
fca3e6d28599 6899923 vdev_offline/vdev_add deadlock
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 11066
diff changeset
    71
enum ddt_class zfs_scrub_ddt_class_max = DDT_CLASS_DUPLICATE;
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
    72
int dsl_scan_delay_completion = B_FALSE; /* set to delay scan completion */
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
    73
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
    74
#define	DSL_SCAN_IS_SCRUB_RESILVER(scn) \
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
    75
	((scn)->scn_phys.scn_func == POOL_SCAN_SCRUB || \
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
    76
	(scn)->scn_phys.scn_func == POOL_SCAN_RESILVER)
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
    77
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
    78
extern int zfs_txg_timeout;
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
    79
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
    80
/* the order has to match pool_scan_type */
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
    81
static scan_cb_t *scan_funcs[POOL_SCAN_FUNCS] = {
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
    82
	NULL,
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
    83
	dsl_scan_scrub_cb,	/* POOL_SCAN_SCRUB */
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
    84
	dsl_scan_scrub_cb,	/* POOL_SCAN_RESILVER */
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
    85
};
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
    86
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
    87
int
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
    88
dsl_scan_init(dsl_pool_t *dp, uint64_t txg)
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
    89
{
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
    90
	int err;
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
    91
	dsl_scan_t *scn;
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
    92
	spa_t *spa = dp->dp_spa;
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
    93
	uint64_t f;
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
    94
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
    95
	scn = dp->dp_scan = kmem_zalloc(sizeof (dsl_scan_t), KM_SLEEP);
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
    96
	scn->scn_dp = dp;
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
    97
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
    98
	err = zap_lookup(dp->dp_meta_objset, DMU_POOL_DIRECTORY_OBJECT,
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
    99
	    "scrub_func", sizeof (uint64_t), 1, &f);
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   100
	if (err == 0) {
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   101
		/*
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   102
		 * There was an old-style scrub in progress.  Restart a
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   103
		 * new-style scrub from the beginning.
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   104
		 */
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   105
		scn->scn_restart_txg = txg;
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   106
		zfs_dbgmsg("old-style scrub was in progress; "
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   107
		    "restarting new-style scrub in txg %llu",
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   108
		    scn->scn_restart_txg);
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   109
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   110
		/*
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   111
		 * Load the queue obj from the old location so that it
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   112
		 * can be freed by dsl_scan_done().
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   113
		 */
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   114
		(void) zap_lookup(dp->dp_meta_objset, DMU_POOL_DIRECTORY_OBJECT,
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   115
		    "scrub_queue", sizeof (uint64_t), 1,
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   116
		    &scn->scn_phys.scn_queue_obj);
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   117
	} else {
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   118
		err = zap_lookup(dp->dp_meta_objset, DMU_POOL_DIRECTORY_OBJECT,
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   119
		    DMU_POOL_SCAN, sizeof (uint64_t), SCAN_PHYS_NUMINTS,
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   120
		    &scn->scn_phys);
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   121
		if (err == ENOENT)
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   122
			return (0);
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   123
		else if (err)
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   124
			return (err);
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   125
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   126
		if (scn->scn_phys.scn_state == DSS_SCANNING &&
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   127
		    spa_prev_software_version(dp->dp_spa) < SPA_VERSION_SCAN) {
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   128
			/*
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   129
			 * A new-type scrub was in progress on an old
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   130
			 * pool, and the pool was accessed by old
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   131
			 * software.  Restart from the beginning, since
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   132
			 * the old software may have changed the pool in
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   133
			 * the meantime.
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   134
			 */
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   135
			scn->scn_restart_txg = txg;
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   136
			zfs_dbgmsg("new-style scrub was modified "
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   137
			    "by old software; restarting in txg %llu",
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   138
			    scn->scn_restart_txg);
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   139
		}
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   140
	}
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   141
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   142
	spa_scan_stat_init(spa);
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   143
	return (0);
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   144
}
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   145
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   146
void
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   147
dsl_scan_fini(dsl_pool_t *dp)
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   148
{
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   149
	if (dp->dp_scan) {
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   150
		kmem_free(dp->dp_scan, sizeof (dsl_scan_t));
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   151
		dp->dp_scan = NULL;
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   152
	}
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   153
}
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   154
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   155
/* ARGSUSED */
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   156
static int
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   157
dsl_scan_setup_check(void *arg1, void *arg2, dmu_tx_t *tx)
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   158
{
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   159
	dsl_scan_t *scn = arg1;
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   160
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   161
	if (scn->scn_phys.scn_state == DSS_SCANNING)
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   162
		return (EBUSY);
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   163
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   164
	return (0);
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   165
}
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   166
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   167
/* ARGSUSED */
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   168
static void
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   169
dsl_scan_setup_sync(void *arg1, void *arg2, dmu_tx_t *tx)
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   170
{
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   171
	dsl_scan_t *scn = arg1;
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   172
	pool_scan_func_t *funcp = arg2;
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   173
	dmu_object_type_t ot = 0;
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   174
	dsl_pool_t *dp = scn->scn_dp;
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   175
	spa_t *spa = dp->dp_spa;
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   176
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   177
	ASSERT(scn->scn_phys.scn_state != DSS_SCANNING);
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   178
	ASSERT(*funcp > POOL_SCAN_NONE && *funcp < POOL_SCAN_FUNCS);
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   179
	bzero(&scn->scn_phys, sizeof (scn->scn_phys));
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   180
	scn->scn_phys.scn_func = *funcp;
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   181
	scn->scn_phys.scn_state = DSS_SCANNING;
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   182
	scn->scn_phys.scn_min_txg = 0;
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   183
	scn->scn_phys.scn_max_txg = tx->tx_txg;
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   184
	scn->scn_phys.scn_ddt_class_max = DDT_CLASSES - 1; /* the entire DDT */
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   185
	scn->scn_phys.scn_start_time = gethrestime_sec();
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   186
	scn->scn_phys.scn_errors = 0;
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   187
	scn->scn_phys.scn_to_examine = spa->spa_root_vdev->vdev_stat.vs_alloc;
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   188
	scn->scn_restart_txg = 0;
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   189
	spa_scan_stat_init(spa);
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   190
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   191
	if (DSL_SCAN_IS_SCRUB_RESILVER(scn)) {
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   192
		scn->scn_phys.scn_ddt_class_max = zfs_scrub_ddt_class_max;
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   193
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   194
		/* rewrite all disk labels */
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   195
		vdev_config_dirty(spa->spa_root_vdev);
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   196
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   197
		if (vdev_resilver_needed(spa->spa_root_vdev,
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   198
		    &scn->scn_phys.scn_min_txg, &scn->scn_phys.scn_max_txg)) {
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   199
			spa_event_notify(spa, NULL, ESC_ZFS_RESILVER_START);
8525
e0e0e525d0f8 6788830 set large value to reservation cause core dump
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 8274
diff changeset
   200
		} else {
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   201
			spa_event_notify(spa, NULL, ESC_ZFS_SCRUB_START);
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   202
		}
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   203
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   204
		spa->spa_scrub_started = B_TRUE;
11125
fca3e6d28599 6899923 vdev_offline/vdev_add deadlock
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 11066
diff changeset
   205
		/*
fca3e6d28599 6899923 vdev_offline/vdev_add deadlock
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 11066
diff changeset
   206
		 * If this is an incremental scrub, limit the DDT scrub phase
fca3e6d28599 6899923 vdev_offline/vdev_add deadlock
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 11066
diff changeset
   207
		 * to just the auto-ditto class (for correctness); the rest
fca3e6d28599 6899923 vdev_offline/vdev_add deadlock
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 11066
diff changeset
   208
		 * of the scrub should go faster using top-down pruning.
fca3e6d28599 6899923 vdev_offline/vdev_add deadlock
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 11066
diff changeset
   209
		 */
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   210
		if (scn->scn_phys.scn_min_txg > TXG_INITIAL)
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   211
			scn->scn_phys.scn_ddt_class_max = DDT_CLASS_DITTO;
11125
fca3e6d28599 6899923 vdev_offline/vdev_add deadlock
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 11066
diff changeset
   212
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   213
	}
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   214
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   215
	/* back to the generic stuff */
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   216
7837
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
   217
	if (dp->dp_blkstats == NULL) {
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
   218
		dp->dp_blkstats =
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
   219
		    kmem_alloc(sizeof (zfs_all_blkstats_t), KM_SLEEP);
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
   220
	}
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
   221
	bzero(dp->dp_blkstats, sizeof (zfs_all_blkstats_t));
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
   222
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   223
	if (spa_version(spa) < SPA_VERSION_DSL_SCRUB)
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   224
		ot = DMU_OT_ZAP_OTHER;
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   225
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   226
	scn->scn_phys.scn_queue_obj = zap_create(dp->dp_meta_objset,
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   227
	    ot ? ot : DMU_OT_SCAN_QUEUE, DMU_OT_NONE, 0, tx);
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   228
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   229
	dsl_scan_sync_state(scn, tx);
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   230
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   231
	spa_history_log_internal(LOG_POOL_SCAN, spa, tx,
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   232
	    "func=%u mintxg=%llu maxtxg=%llu",
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   233
	    *funcp, scn->scn_phys.scn_min_txg, scn->scn_phys.scn_max_txg);
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   234
}
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   235
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   236
/* ARGSUSED */
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   237
static void
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   238
dsl_scan_done(dsl_scan_t *scn, boolean_t complete, dmu_tx_t *tx)
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   239
{
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   240
	static const char *old_names[] = {
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   241
		"scrub_bookmark",
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   242
		"scrub_ddt_bookmark",
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   243
		"scrub_ddt_class_max",
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   244
		"scrub_queue",
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   245
		"scrub_min_txg",
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   246
		"scrub_max_txg",
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   247
		"scrub_func",
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   248
		"scrub_errors",
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   249
		NULL
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   250
	};
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   251
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   252
	dsl_pool_t *dp = scn->scn_dp;
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   253
	spa_t *spa = dp->dp_spa;
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   254
	int i;
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   255
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   256
	/* Remove any remnants of an old-style scrub. */
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   257
	for (i = 0; old_names[i]; i++) {
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   258
		(void) zap_remove(dp->dp_meta_objset,
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   259
		    DMU_POOL_DIRECTORY_OBJECT, old_names[i], tx);
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   260
	}
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   261
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   262
	if (scn->scn_phys.scn_queue_obj != 0) {
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   263
		VERIFY(0 == dmu_object_free(dp->dp_meta_objset,
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   264
		    scn->scn_phys.scn_queue_obj, tx));
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   265
		scn->scn_phys.scn_queue_obj = 0;
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   266
	}
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   267
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   268
	/*
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   269
	 * If we were "restarted" from a stopped state, don't bother
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   270
	 * with anything else.
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   271
	 */
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   272
	if (scn->scn_phys.scn_state != DSS_SCANNING)
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   273
		return;
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   274
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   275
	if (complete)
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   276
		scn->scn_phys.scn_state = DSS_FINISHED;
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   277
	else
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   278
		scn->scn_phys.scn_state = DSS_CANCELED;
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   279
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   280
	spa_history_log_internal(LOG_POOL_SCAN_DONE, spa, tx,
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   281
	    "complete=%u", complete);
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   282
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   283
	if (DSL_SCAN_IS_SCRUB_RESILVER(scn)) {
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   284
		mutex_enter(&spa->spa_scrub_lock);
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   285
		while (spa->spa_scrub_inflight > 0) {
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   286
			cv_wait(&spa->spa_scrub_io_cv,
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   287
			    &spa->spa_scrub_lock);
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   288
		}
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   289
		mutex_exit(&spa->spa_scrub_lock);
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   290
		spa->spa_scrub_started = B_FALSE;
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   291
		spa->spa_scrub_active = B_FALSE;
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   292
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   293
		/*
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   294
		 * If the scrub/resilver completed, update all DTLs to
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   295
		 * reflect this.  Whether it succeeded or not, vacate
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   296
		 * all temporary scrub DTLs.
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   297
		 */
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   298
		vdev_dtl_reassess(spa->spa_root_vdev, tx->tx_txg,
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   299
		    complete ? scn->scn_phys.scn_max_txg : 0, B_TRUE);
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   300
		if (complete) {
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   301
			spa_event_notify(spa, NULL, scn->scn_phys.scn_min_txg ?
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   302
			    ESC_ZFS_RESILVER_FINISH : ESC_ZFS_SCRUB_FINISH);
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   303
		}
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   304
		spa_errlog_rotate(spa);
11125
fca3e6d28599 6899923 vdev_offline/vdev_add deadlock
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 11066
diff changeset
   305
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   306
		/*
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   307
		 * We may have finished replacing a device.
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   308
		 * Let the async thread assess this and handle the detach.
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   309
		 */
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   310
		spa_async_request(spa, SPA_ASYNC_RESILVER_DONE);
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   311
	}
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   312
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   313
	scn->scn_phys.scn_end_time = gethrestime_sec();
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   314
}
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   315
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   316
/* ARGSUSED */
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   317
static int
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   318
dsl_scan_cancel_check(void *arg1, void *arg2, dmu_tx_t *tx)
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   319
{
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   320
	dsl_scan_t *scn = arg1;
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   321
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   322
	if (scn->scn_phys.scn_state != DSS_SCANNING)
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   323
		return (ENOENT);
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   324
	return (0);
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   325
}
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   326
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   327
/* ARGSUSED */
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   328
static void
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   329
dsl_scan_cancel_sync(void *arg1, void *arg2, dmu_tx_t *tx)
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   330
{
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   331
	dsl_scan_t *scn = arg1;
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   332
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   333
	dsl_scan_done(scn, B_FALSE, tx);
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   334
	dsl_scan_sync_state(scn, tx);
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   335
}
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   336
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   337
int
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   338
dsl_scan_cancel(dsl_pool_t *dp)
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   339
{
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   340
	boolean_t complete = B_FALSE;
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   341
	int err;
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   342
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   343
	err = dsl_sync_task_do(dp, dsl_scan_cancel_check,
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   344
	    dsl_scan_cancel_sync, dp->dp_scan, &complete, 3);
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   345
	return (err);
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   346
}
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   347
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   348
static void dsl_scan_visitbp(blkptr_t *bp,
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   349
    const zbookmark_t *zb, dnode_phys_t *dnp, arc_buf_t *pbuf,
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   350
    dsl_dataset_t *ds, dsl_scan_t *scn, dmu_objset_type_t ostype,
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   351
    dmu_tx_t *tx);
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   352
static void dsl_scan_visitdnode(dsl_scan_t *, dsl_dataset_t *ds,
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   353
    dmu_objset_type_t ostype,
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   354
    dnode_phys_t *dnp, arc_buf_t *buf, uint64_t object, dmu_tx_t *tx);
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   355
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   356
void
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   357
dsl_free(dsl_pool_t *dp, uint64_t txg, const blkptr_t *bp)
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   358
{
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   359
	zio_free(dp->dp_spa, txg, bp);
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   360
}
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   361
12295
e16f396f04a1 6948911 snapshot deletion can induce unsatisfiable allocations in txg sync
George Wilson <George.Wilson@Sun.COM>
parents: 11935
diff changeset
   362
void
e16f396f04a1 6948911 snapshot deletion can induce unsatisfiable allocations in txg sync
George Wilson <George.Wilson@Sun.COM>
parents: 11935
diff changeset
   363
dsl_free_sync(zio_t *pio, dsl_pool_t *dp, uint64_t txg, const blkptr_t *bpp)
e16f396f04a1 6948911 snapshot deletion can induce unsatisfiable allocations in txg sync
George Wilson <George.Wilson@Sun.COM>
parents: 11935
diff changeset
   364
{
e16f396f04a1 6948911 snapshot deletion can induce unsatisfiable allocations in txg sync
George Wilson <George.Wilson@Sun.COM>
parents: 11935
diff changeset
   365
	ASSERT(dsl_pool_sync_context(dp));
e16f396f04a1 6948911 snapshot deletion can induce unsatisfiable allocations in txg sync
George Wilson <George.Wilson@Sun.COM>
parents: 11935
diff changeset
   366
	zio_nowait(zio_free_sync(pio, dp->dp_spa, txg, bpp, pio->io_flags));
e16f396f04a1 6948911 snapshot deletion can induce unsatisfiable allocations in txg sync
George Wilson <George.Wilson@Sun.COM>
parents: 11935
diff changeset
   367
}
e16f396f04a1 6948911 snapshot deletion can induce unsatisfiable allocations in txg sync
George Wilson <George.Wilson@Sun.COM>
parents: 11935
diff changeset
   368
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   369
int
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   370
dsl_read(zio_t *pio, spa_t *spa, const blkptr_t *bpp, arc_buf_t *pbuf,
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   371
    arc_done_func_t *done, void *private, int priority, int zio_flags,
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   372
    uint32_t *arc_flags, const zbookmark_t *zb)
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   373
{
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   374
	return (arc_read(pio, spa, bpp, pbuf, done, private,
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   375
	    priority, zio_flags, arc_flags, zb));
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   376
}
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   377
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   378
int
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   379
dsl_read_nolock(zio_t *pio, spa_t *spa, const blkptr_t *bpp,
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   380
    arc_done_func_t *done, void *private, int priority, int zio_flags,
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   381
    uint32_t *arc_flags, const zbookmark_t *zb)
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   382
{
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   383
	return (arc_read_nolock(pio, spa, bpp, done, private,
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   384
	    priority, zio_flags, arc_flags, zb));
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   385
}
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   386
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   387
static uint64_t
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   388
dsl_scan_ds_maxtxg(dsl_dataset_t *ds)
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   389
{
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   390
	uint64_t smt = ds->ds_dir->dd_pool->dp_scan->scn_phys.scn_max_txg;
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   391
	if (dsl_dataset_is_snapshot(ds))
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   392
		return (MIN(smt, ds->ds_phys->ds_creation_txg));
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   393
	return (smt);
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   394
}
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   395
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   396
static void
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   397
dsl_scan_sync_state(dsl_scan_t *scn, dmu_tx_t *tx)
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   398
{
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   399
	VERIFY(0 == zap_update(scn->scn_dp->dp_meta_objset,
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   400
	    DMU_POOL_DIRECTORY_OBJECT,
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   401
	    DMU_POOL_SCAN, sizeof (uint64_t), SCAN_PHYS_NUMINTS,
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   402
	    &scn->scn_phys, tx));
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   403
}
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   404
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   405
static boolean_t
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   406
dsl_scan_check_pause(dsl_scan_t *scn, const zbookmark_t *zb)
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   407
{
11137
0a1ed2ae30eb 6899862 ZFS txg time tunables should be more flexible
Lin Ling <Lin.Ling@Sun.COM>
parents: 11125
diff changeset
   408
	uint64_t elapsed_nanosecs;
7160
12f467ba43f4 6725330 'zpool scrub -v' doesn't show data errors after scrub completes
ahrens
parents: 7046
diff changeset
   409
	int mintime;
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   410
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   411
	/* we never skip user/group accounting objects */
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   412
	if (zb && (int64_t)zb->zb_object < 0)
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   413
		return (B_FALSE);
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   414
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   415
	if (scn->scn_pausing)
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   416
		return (B_TRUE); /* we're already pausing */
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   417
13700
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 12839
diff changeset
   418
	if (!ZB_IS_ZERO(&scn->scn_phys.scn_bookmark))
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   419
		return (B_FALSE); /* we're resuming */
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   420
7182
30fd179c7fc1 6728594 scrub can block the sync thread for 100s or more
ahrens
parents: 7160
diff changeset
   421
	/* We only know how to resume from level-0 blocks. */
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   422
	if (zb && zb->zb_level != 0)
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   423
		return (B_FALSE);
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   424
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   425
	mintime = (scn->scn_phys.scn_func == POOL_SCAN_RESILVER) ?
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   426
	    zfs_resilver_min_time_ms : zfs_scan_min_time_ms;
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   427
	elapsed_nanosecs = gethrtime() - scn->scn_sync_start_time;
11137
0a1ed2ae30eb 6899862 ZFS txg time tunables should be more flexible
Lin Ling <Lin.Ling@Sun.COM>
parents: 11125
diff changeset
   428
	if (elapsed_nanosecs / NANOSEC > zfs_txg_timeout ||
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   429
	    (elapsed_nanosecs / MICROSEC > mintime &&
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   430
	    txg_sync_waiting(scn->scn_dp)) ||
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   431
	    spa_shutting_down(scn->scn_dp->dp_spa)) {
11125
fca3e6d28599 6899923 vdev_offline/vdev_add deadlock
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 11066
diff changeset
   432
		if (zb) {
fca3e6d28599 6899923 vdev_offline/vdev_add deadlock
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 11066
diff changeset
   433
			dprintf("pausing at bookmark %llx/%llx/%llx/%llx\n",
fca3e6d28599 6899923 vdev_offline/vdev_add deadlock
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 11066
diff changeset
   434
			    (longlong_t)zb->zb_objset,
fca3e6d28599 6899923 vdev_offline/vdev_add deadlock
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 11066
diff changeset
   435
			    (longlong_t)zb->zb_object,
fca3e6d28599 6899923 vdev_offline/vdev_add deadlock
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 11066
diff changeset
   436
			    (longlong_t)zb->zb_level,
fca3e6d28599 6899923 vdev_offline/vdev_add deadlock
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 11066
diff changeset
   437
			    (longlong_t)zb->zb_blkid);
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   438
			scn->scn_phys.scn_bookmark = *zb;
11125
fca3e6d28599 6899923 vdev_offline/vdev_add deadlock
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 11066
diff changeset
   439
		}
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   440
		dprintf("pausing at DDT bookmark %llx/%llx/%llx/%llx\n",
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   441
		    (longlong_t)scn->scn_phys.scn_ddt_bookmark.ddb_class,
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   442
		    (longlong_t)scn->scn_phys.scn_ddt_bookmark.ddb_type,
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   443
		    (longlong_t)scn->scn_phys.scn_ddt_bookmark.ddb_checksum,
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   444
		    (longlong_t)scn->scn_phys.scn_ddt_bookmark.ddb_cursor);
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   445
		scn->scn_pausing = B_TRUE;
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   446
		return (B_TRUE);
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   447
	}
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   448
	return (B_FALSE);
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   449
}
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   450
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   451
typedef struct zil_scan_arg {
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   452
	dsl_pool_t	*zsa_dp;
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   453
	zil_header_t	*zsa_zh;
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   454
} zil_scan_arg_t;
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7182
diff changeset
   455
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   456
/* ARGSUSED */
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   457
static int
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   458
dsl_scan_zil_block(zilog_t *zilog, blkptr_t *bp, void *arg, uint64_t claim_txg)
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   459
{
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   460
	zil_scan_arg_t *zsa = arg;
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   461
	dsl_pool_t *dp = zsa->zsa_dp;
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   462
	dsl_scan_t *scn = dp->dp_scan;
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   463
	zil_header_t *zh = zsa->zsa_zh;
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7182
diff changeset
   464
	zbookmark_t zb;
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   465
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   466
	if (bp->blk_birth <= scn->scn_phys.scn_cur_min_txg)
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   467
		return (0);
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   468
8746
e1d96ca6808c 6796377 panic on rollback in space_map_add()
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8525
diff changeset
   469
	/*
9701
cc5b64682e64 6803605 should be able to offline log devices
George Wilson <George.Wilson@Sun.COM>
parents: 9396
diff changeset
   470
	 * One block ("stubby") can be allocated a long time ago; we
8746
e1d96ca6808c 6796377 panic on rollback in space_map_add()
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8525
diff changeset
   471
	 * want to visit that one because it has been allocated
e1d96ca6808c 6796377 panic on rollback in space_map_add()
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8525
diff changeset
   472
	 * (on-disk) even if it hasn't been claimed (even though for
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   473
	 * scrub there's nothing to do to it).
8746
e1d96ca6808c 6796377 panic on rollback in space_map_add()
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8525
diff changeset
   474
	 */
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7182
diff changeset
   475
	if (claim_txg == 0 && bp->blk_birth >= spa_first_txg(dp->dp_spa))
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   476
		return (0);
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7182
diff changeset
   477
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   478
	SET_BOOKMARK(&zb, zh->zh_log.blk_cksum.zc_word[ZIL_ZC_OBJSET],
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   479
	    ZB_ZIL_OBJECT, ZB_ZIL_LEVEL, bp->blk_cksum.zc_word[ZIL_ZC_SEQ]);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   480
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   481
	VERIFY(0 == scan_funcs[scn->scn_phys.scn_func](dp, bp, &zb));
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   482
	return (0);
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   483
}
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   484
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   485
/* ARGSUSED */
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   486
static int
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   487
dsl_scan_zil_record(zilog_t *zilog, lr_t *lrc, void *arg, uint64_t claim_txg)
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   488
{
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   489
	if (lrc->lrc_txtype == TX_WRITE) {
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   490
		zil_scan_arg_t *zsa = arg;
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   491
		dsl_pool_t *dp = zsa->zsa_dp;
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   492
		dsl_scan_t *scn = dp->dp_scan;
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   493
		zil_header_t *zh = zsa->zsa_zh;
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   494
		lr_write_t *lr = (lr_write_t *)lrc;
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   495
		blkptr_t *bp = &lr->lr_blkptr;
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7182
diff changeset
   496
		zbookmark_t zb;
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   497
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   498
		if (bp->blk_birth <= scn->scn_phys.scn_cur_min_txg)
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   499
			return (0);
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   500
8746
e1d96ca6808c 6796377 panic on rollback in space_map_add()
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8525
diff changeset
   501
		/*
e1d96ca6808c 6796377 panic on rollback in space_map_add()
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8525
diff changeset
   502
		 * birth can be < claim_txg if this record's txg is
e1d96ca6808c 6796377 panic on rollback in space_map_add()
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8525
diff changeset
   503
		 * already txg sync'ed (but this log block contains
e1d96ca6808c 6796377 panic on rollback in space_map_add()
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8525
diff changeset
   504
		 * other records that are not synced)
e1d96ca6808c 6796377 panic on rollback in space_map_add()
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8525
diff changeset
   505
		 */
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7182
diff changeset
   506
		if (claim_txg == 0 || bp->blk_birth < claim_txg)
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   507
			return (0);
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7182
diff changeset
   508
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   509
		SET_BOOKMARK(&zb, zh->zh_log.blk_cksum.zc_word[ZIL_ZC_OBJSET],
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   510
		    lr->lr_foid, ZB_ZIL_LEVEL,
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   511
		    lr->lr_offset / BP_GET_LSIZE(bp));
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   512
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   513
		VERIFY(0 == scan_funcs[scn->scn_phys.scn_func](dp, bp, &zb));
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   514
	}
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   515
	return (0);
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   516
}
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   517
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   518
static void
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   519
dsl_scan_zil(dsl_pool_t *dp, zil_header_t *zh)
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   520
{
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   521
	uint64_t claim_txg = zh->zh_claim_txg;
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   522
	zil_scan_arg_t zsa = { dp, zh };
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   523
	zilog_t *zilog;
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   524
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   525
	/*
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   526
	 * We only want to visit blocks that have been claimed but not yet
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   527
	 * replayed (or, in read-only mode, blocks that *would* be claimed).
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   528
	 */
8241
5a60f16123ba 6328632 zpool offline is a bit too conservative
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7837
diff changeset
   529
	if (claim_txg == 0 && spa_writeable(dp->dp_spa))
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   530
		return;
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   531
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   532
	zilog = zil_alloc(dp->dp_meta_objset, zh);
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   533
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   534
	(void) zil_parse(zilog, dsl_scan_zil_block, dsl_scan_zil_record, &zsa,
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   535
	    claim_txg);
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   536
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   537
	zil_free(zilog);
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   538
}
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   539
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   540
/* ARGSUSED */
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   541
static void
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   542
dsl_scan_prefetch(dsl_scan_t *scn, arc_buf_t *buf, blkptr_t *bp,
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   543
    uint64_t objset, uint64_t object, uint64_t blkid)
11147
74e8c05021f1 6678033 resilver code should prefetch
George Wilson <George.Wilson@Sun.COM>
parents: 11137
diff changeset
   544
{
74e8c05021f1 6678033 resilver code should prefetch
George Wilson <George.Wilson@Sun.COM>
parents: 11137
diff changeset
   545
	zbookmark_t czb;
74e8c05021f1 6678033 resilver code should prefetch
George Wilson <George.Wilson@Sun.COM>
parents: 11137
diff changeset
   546
	uint32_t flags = ARC_NOWAIT | ARC_PREFETCH;
74e8c05021f1 6678033 resilver code should prefetch
George Wilson <George.Wilson@Sun.COM>
parents: 11137
diff changeset
   547
74e8c05021f1 6678033 resilver code should prefetch
George Wilson <George.Wilson@Sun.COM>
parents: 11137
diff changeset
   548
	if (zfs_no_scrub_prefetch)
74e8c05021f1 6678033 resilver code should prefetch
George Wilson <George.Wilson@Sun.COM>
parents: 11137
diff changeset
   549
		return;
74e8c05021f1 6678033 resilver code should prefetch
George Wilson <George.Wilson@Sun.COM>
parents: 11137
diff changeset
   550
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   551
	if (BP_IS_HOLE(bp) || bp->blk_birth <= scn->scn_phys.scn_min_txg ||
11147
74e8c05021f1 6678033 resilver code should prefetch
George Wilson <George.Wilson@Sun.COM>
parents: 11137
diff changeset
   552
	    (BP_GET_LEVEL(bp) == 0 && BP_GET_TYPE(bp) != DMU_OT_DNODE))
74e8c05021f1 6678033 resilver code should prefetch
George Wilson <George.Wilson@Sun.COM>
parents: 11137
diff changeset
   553
		return;
74e8c05021f1 6678033 resilver code should prefetch
George Wilson <George.Wilson@Sun.COM>
parents: 11137
diff changeset
   554
74e8c05021f1 6678033 resilver code should prefetch
George Wilson <George.Wilson@Sun.COM>
parents: 11137
diff changeset
   555
	SET_BOOKMARK(&czb, objset, object, BP_GET_LEVEL(bp), blkid);
74e8c05021f1 6678033 resilver code should prefetch
George Wilson <George.Wilson@Sun.COM>
parents: 11137
diff changeset
   556
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   557
	/*
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   558
	 * XXX need to make sure all of these arc_read() prefetches are
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   559
	 * done before setting xlateall (similar to dsl_read())
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   560
	 */
12470
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
   561
	(void) arc_read(scn->scn_zio_root, scn->scn_dp->dp_spa, bp,
12586
b118bbd65be9 6494473 ZFS needs a way to slow down resilvering
George Wilson <George.Wilson@Sun.COM>
parents: 12470
diff changeset
   562
	    buf, NULL, NULL, ZIO_PRIORITY_ASYNC_READ,
b118bbd65be9 6494473 ZFS needs a way to slow down resilvering
George Wilson <George.Wilson@Sun.COM>
parents: 12470
diff changeset
   563
	    ZIO_FLAG_CANFAIL | ZIO_FLAG_SCAN_THREAD, &flags, &czb);
11147
74e8c05021f1 6678033 resilver code should prefetch
George Wilson <George.Wilson@Sun.COM>
parents: 11137
diff changeset
   564
}
74e8c05021f1 6678033 resilver code should prefetch
George Wilson <George.Wilson@Sun.COM>
parents: 11137
diff changeset
   565
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   566
static boolean_t
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   567
dsl_scan_check_resume(dsl_scan_t *scn, const dnode_phys_t *dnp,
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   568
    const zbookmark_t *zb)
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   569
{
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   570
	/*
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   571
	 * We never skip over user/group accounting objects (obj<0)
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   572
	 */
13700
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 12839
diff changeset
   573
	if (!ZB_IS_ZERO(&scn->scn_phys.scn_bookmark) &&
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   574
	    (int64_t)zb->zb_object >= 0) {
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   575
		/*
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   576
		 * If we already visited this bp & everything below (in
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   577
		 * a prior txg sync), don't bother doing it again.
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   578
		 */
13700
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 12839
diff changeset
   579
		if (zbookmark_is_before(dnp, zb, &scn->scn_phys.scn_bookmark))
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   580
			return (B_TRUE);
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   581
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   582
		/*
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   583
		 * If we found the block we're trying to resume from, or
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   584
		 * we went past it to a different object, zero it out to
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   585
		 * indicate that it's OK to start checking for pausing
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   586
		 * again.
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   587
		 */
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   588
		if (bcmp(zb, &scn->scn_phys.scn_bookmark, sizeof (*zb)) == 0 ||
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   589
		    zb->zb_object > scn->scn_phys.scn_bookmark.zb_object) {
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   590
			dprintf("resuming at %llx/%llx/%llx/%llx\n",
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   591
			    (longlong_t)zb->zb_objset,
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   592
			    (longlong_t)zb->zb_object,
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   593
			    (longlong_t)zb->zb_level,
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   594
			    (longlong_t)zb->zb_blkid);
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   595
			bzero(&scn->scn_phys.scn_bookmark, sizeof (*zb));
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   596
		}
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   597
	}
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   598
	return (B_FALSE);
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   599
}
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   600
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   601
/*
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   602
 * Return nonzero on i/o error.
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   603
 * Return new buf to write out in *bufp.
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   604
 */
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   605
static int
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   606
dsl_scan_recurse(dsl_scan_t *scn, dsl_dataset_t *ds, dmu_objset_type_t ostype,
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   607
    dnode_phys_t *dnp, const blkptr_t *bp,
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   608
    const zbookmark_t *zb, dmu_tx_t *tx, arc_buf_t **bufp)
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   609
{
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   610
	dsl_pool_t *dp = scn->scn_dp;
12586
b118bbd65be9 6494473 ZFS needs a way to slow down resilvering
George Wilson <George.Wilson@Sun.COM>
parents: 12470
diff changeset
   611
	int zio_flags = ZIO_FLAG_CANFAIL | ZIO_FLAG_SCAN_THREAD;
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   612
	int err;
11147
74e8c05021f1 6678033 resilver code should prefetch
George Wilson <George.Wilson@Sun.COM>
parents: 11137
diff changeset
   613
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   614
	if (BP_GET_LEVEL(bp) > 0) {
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   615
		uint32_t flags = ARC_WAIT;
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   616
		int i;
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   617
		blkptr_t *cbp;
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   618
		int epb = BP_GET_LSIZE(bp) >> SPA_BLKPTRSHIFT;
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   619
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   620
		err = arc_read_nolock(NULL, dp->dp_spa, bp,
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   621
		    arc_getbuf_func, bufp,
12586
b118bbd65be9 6494473 ZFS needs a way to slow down resilvering
George Wilson <George.Wilson@Sun.COM>
parents: 12470
diff changeset
   622
		    ZIO_PRIORITY_ASYNC_READ, zio_flags, &flags, zb);
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   623
		if (err) {
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   624
			scn->scn_phys.scn_errors++;
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   625
			return (err);
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   626
		}
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   627
		for (i = 0, cbp = (*bufp)->b_data; i < epb; i++, cbp++) {
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   628
			dsl_scan_prefetch(scn, *bufp, cbp, zb->zb_objset,
11147
74e8c05021f1 6678033 resilver code should prefetch
George Wilson <George.Wilson@Sun.COM>
parents: 11137
diff changeset
   629
			    zb->zb_object, zb->zb_blkid * epb + i);
74e8c05021f1 6678033 resilver code should prefetch
George Wilson <George.Wilson@Sun.COM>
parents: 11137
diff changeset
   630
		}
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   631
		for (i = 0, cbp = (*bufp)->b_data; i < epb; i++, cbp++) {
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   632
			zbookmark_t czb;
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   633
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   634
			SET_BOOKMARK(&czb, zb->zb_objset, zb->zb_object,
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   635
			    zb->zb_level - 1,
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   636
			    zb->zb_blkid * epb + i);
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   637
			dsl_scan_visitbp(cbp, &czb, dnp,
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   638
			    *bufp, ds, scn, ostype, tx);
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   639
		}
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   640
	} else if (BP_GET_TYPE(bp) == DMU_OT_USERGROUP_USED) {
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   641
		uint32_t flags = ARC_WAIT;
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   642
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   643
		err = arc_read_nolock(NULL, dp->dp_spa, bp,
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   644
		    arc_getbuf_func, bufp,
12586
b118bbd65be9 6494473 ZFS needs a way to slow down resilvering
George Wilson <George.Wilson@Sun.COM>
parents: 12470
diff changeset
   645
		    ZIO_PRIORITY_ASYNC_READ, zio_flags, &flags, zb);
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   646
		if (err) {
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   647
			scn->scn_phys.scn_errors++;
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   648
			return (err);
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   649
		}
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   650
	} else if (BP_GET_TYPE(bp) == DMU_OT_DNODE) {
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   651
		uint32_t flags = ARC_WAIT;
11147
74e8c05021f1 6678033 resilver code should prefetch
George Wilson <George.Wilson@Sun.COM>
parents: 11137
diff changeset
   652
		dnode_phys_t *cdnp;
74e8c05021f1 6678033 resilver code should prefetch
George Wilson <George.Wilson@Sun.COM>
parents: 11137
diff changeset
   653
		int i, j;
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   654
		int epb = BP_GET_LSIZE(bp) >> DNODE_SHIFT;
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   655
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   656
		err = arc_read_nolock(NULL, dp->dp_spa, bp,
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   657
		    arc_getbuf_func, bufp,
12586
b118bbd65be9 6494473 ZFS needs a way to slow down resilvering
George Wilson <George.Wilson@Sun.COM>
parents: 12470
diff changeset
   658
		    ZIO_PRIORITY_ASYNC_READ, zio_flags, &flags, zb);
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   659
		if (err) {
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   660
			scn->scn_phys.scn_errors++;
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   661
			return (err);
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   662
		}
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   663
		for (i = 0, cdnp = (*bufp)->b_data; i < epb; i++, cdnp++) {
11147
74e8c05021f1 6678033 resilver code should prefetch
George Wilson <George.Wilson@Sun.COM>
parents: 11137
diff changeset
   664
			for (j = 0; j < cdnp->dn_nblkptr; j++) {
74e8c05021f1 6678033 resilver code should prefetch
George Wilson <George.Wilson@Sun.COM>
parents: 11137
diff changeset
   665
				blkptr_t *cbp = &cdnp->dn_blkptr[j];
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   666
				dsl_scan_prefetch(scn, *bufp, cbp,
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   667
				    zb->zb_objset, zb->zb_blkid * epb + i, j);
11147
74e8c05021f1 6678033 resilver code should prefetch
George Wilson <George.Wilson@Sun.COM>
parents: 11137
diff changeset
   668
			}
74e8c05021f1 6678033 resilver code should prefetch
George Wilson <George.Wilson@Sun.COM>
parents: 11137
diff changeset
   669
		}
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   670
		for (i = 0, cdnp = (*bufp)->b_data; i < epb; i++, cdnp++) {
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   671
			dsl_scan_visitdnode(scn, ds, ostype,
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   672
			    cdnp, *bufp, zb->zb_blkid * epb + i, tx);
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   673
		}
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   674
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   675
	} else if (BP_GET_TYPE(bp) == DMU_OT_OBJSET) {
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   676
		uint32_t flags = ARC_WAIT;
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   677
		objset_phys_t *osp;
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   678
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   679
		err = arc_read_nolock(NULL, dp->dp_spa, bp,
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   680
		    arc_getbuf_func, bufp,
12586
b118bbd65be9 6494473 ZFS needs a way to slow down resilvering
George Wilson <George.Wilson@Sun.COM>
parents: 12470
diff changeset
   681
		    ZIO_PRIORITY_ASYNC_READ, zio_flags, &flags, zb);
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   682
		if (err) {
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   683
			scn->scn_phys.scn_errors++;
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   684
			return (err);
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   685
		}
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   686
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   687
		osp = (*bufp)->b_data;
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   688
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   689
		dsl_scan_visitdnode(scn, ds, osp->os_type,
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   690
		    &osp->os_meta_dnode, *bufp, DMU_META_DNODE_OBJECT, tx);
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   691
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   692
		if (OBJSET_BUF_HAS_USERUSED(*bufp)) {
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   693
			/*
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   694
			 * We also always visit user/group accounting
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   695
			 * objects, and never skip them, even if we are
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   696
			 * pausing.  This is necessary so that the space
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   697
			 * deltas from this txg get integrated.
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   698
			 */
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   699
			dsl_scan_visitdnode(scn, ds, osp->os_type,
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   700
			    &osp->os_groupused_dnode, *bufp,
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   701
			    DMU_GROUPUSED_OBJECT, tx);
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   702
			dsl_scan_visitdnode(scn, ds, osp->os_type,
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   703
			    &osp->os_userused_dnode, *bufp,
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   704
			    DMU_USERUSED_OBJECT, tx);
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   705
		}
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   706
	}
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   707
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   708
	return (0);
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   709
}
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   710
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   711
static void
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   712
dsl_scan_visitdnode(dsl_scan_t *scn, dsl_dataset_t *ds,
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   713
    dmu_objset_type_t ostype, dnode_phys_t *dnp, arc_buf_t *buf,
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   714
    uint64_t object, dmu_tx_t *tx)
9396
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8746
diff changeset
   715
{
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8746
diff changeset
   716
	int j;
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8746
diff changeset
   717
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8746
diff changeset
   718
	for (j = 0; j < dnp->dn_nblkptr; j++) {
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8746
diff changeset
   719
		zbookmark_t czb;
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8746
diff changeset
   720
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   721
		SET_BOOKMARK(&czb, ds ? ds->ds_object : 0, object,
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   722
		    dnp->dn_nlevels - 1, j);
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   723
		dsl_scan_visitbp(&dnp->dn_blkptr[j],
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   724
		    &czb, dnp, buf, ds, scn, ostype, tx);
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   725
	}
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11815
diff changeset
   726
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   727
	if (dnp->dn_flags & DNODE_FLAG_SPILL_BLKPTR) {
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   728
		zbookmark_t czb;
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   729
		SET_BOOKMARK(&czb, ds ? ds->ds_object : 0, object,
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   730
		    0, DMU_SPILL_BLKID);
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   731
		dsl_scan_visitbp(&dnp->dn_spill,
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   732
		    &czb, dnp, buf, ds, scn, ostype, tx);
9396
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8746
diff changeset
   733
	}
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8746
diff changeset
   734
}
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8746
diff changeset
   735
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   736
/*
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   737
 * The arguments are in this order because mdb can only print the
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   738
 * first 5; we want them to be useful.
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   739
 */
9396
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8746
diff changeset
   740
static void
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   741
dsl_scan_visitbp(blkptr_t *bp, const zbookmark_t *zb,
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   742
    dnode_phys_t *dnp, arc_buf_t *pbuf,
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   743
    dsl_dataset_t *ds, dsl_scan_t *scn, dmu_objset_type_t ostype,
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   744
    dmu_tx_t *tx)
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   745
{
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   746
	dsl_pool_t *dp = scn->scn_dp;
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   747
	arc_buf_t *buf = NULL;
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   748
	blkptr_t bp_toread = *bp;
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   749
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   750
	/* ASSERT(pbuf == NULL || arc_released(pbuf)); */
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   751
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   752
	if (dsl_scan_check_pause(scn, zb))
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   753
		return;
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   754
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   755
	if (dsl_scan_check_resume(scn, dnp, zb))
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   756
		return;
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   757
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   758
	if (bp->blk_birth == 0)
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   759
		return;
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   760
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   761
	scn->scn_visited_this_txg++;
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   762
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   763
	dprintf_bp(bp,
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   764
	    "visiting ds=%p/%llu zb=%llx/%llx/%llx/%llx buf=%p bp=%p",
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   765
	    ds, ds ? ds->ds_object : 0,
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   766
	    zb->zb_objset, zb->zb_object, zb->zb_level, zb->zb_blkid,
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   767
	    pbuf, bp);
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   768
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   769
	if (bp->blk_birth <= scn->scn_phys.scn_cur_min_txg)
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   770
		return;
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   771
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   772
	if (dsl_scan_recurse(scn, ds, ostype, dnp, &bp_toread, zb, tx,
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   773
	    &buf) != 0)
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   774
		return;
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   775
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   776
	/*
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   777
	 * If dsl_scan_ddt() has aready visited this block, it will have
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   778
	 * already done any translations or scrubbing, so don't call the
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   779
	 * callback again.
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   780
	 */
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   781
	if (ddt_class_contains(dp->dp_spa,
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   782
	    scn->scn_phys.scn_ddt_class_max, bp)) {
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   783
		ASSERT(buf == NULL);
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   784
		return;
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   785
	}
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   786
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   787
	/*
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   788
	 * If this block is from the future (after cur_max_txg), then we
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   789
	 * are doing this on behalf of a deleted snapshot, and we will
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   790
	 * revisit the future block on the next pass of this dataset.
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   791
	 * Don't scan it now unless we need to because something
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   792
	 * under it was modified.
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   793
	 */
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   794
	if (bp->blk_birth <= scn->scn_phys.scn_cur_max_txg) {
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   795
		scan_funcs[scn->scn_phys.scn_func](dp, bp, zb);
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   796
	}
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   797
	if (buf)
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   798
		(void) arc_buf_remove_ref(buf, &buf);
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   799
}
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   800
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   801
static void
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   802
dsl_scan_visit_rootbp(dsl_scan_t *scn, dsl_dataset_t *ds, blkptr_t *bp,
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   803
    dmu_tx_t *tx)
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   804
{
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   805
	zbookmark_t zb;
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   806
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   807
	SET_BOOKMARK(&zb, ds ? ds->ds_object : DMU_META_OBJSET,
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   808
	    ZB_ROOT_OBJECT, ZB_ROOT_LEVEL, ZB_ROOT_BLKID);
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   809
	dsl_scan_visitbp(bp, &zb, NULL, NULL,
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   810
	    ds, scn, DMU_OST_NONE, tx);
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   811
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   812
	dprintf_ds(ds, "finished scan%s", "");
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   813
}
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   814
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   815
void
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   816
dsl_scan_ds_destroyed(dsl_dataset_t *ds, dmu_tx_t *tx)
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   817
{
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   818
	dsl_pool_t *dp = ds->ds_dir->dd_pool;
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   819
	dsl_scan_t *scn = dp->dp_scan;
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   820
	uint64_t mintxg;
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   821
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   822
	if (scn->scn_phys.scn_state != DSS_SCANNING)
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   823
		return;
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   824
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   825
	if (scn->scn_phys.scn_bookmark.zb_objset == ds->ds_object) {
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   826
		if (dsl_dataset_is_snapshot(ds)) {
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   827
			/* Note, scn_cur_{min,max}_txg stays the same. */
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   828
			scn->scn_phys.scn_bookmark.zb_objset =
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   829
			    ds->ds_phys->ds_next_snap_obj;
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   830
			zfs_dbgmsg("destroying ds %llu; currently traversing; "
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   831
			    "reset zb_objset to %llu",
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   832
			    (u_longlong_t)ds->ds_object,
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   833
			    (u_longlong_t)ds->ds_phys->ds_next_snap_obj);
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   834
			scn->scn_phys.scn_flags |= DSF_VISIT_DS_AGAIN;
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   835
		} else {
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   836
			SET_BOOKMARK(&scn->scn_phys.scn_bookmark,
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   837
			    ZB_DESTROYED_OBJSET, 0, 0, 0);
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   838
			zfs_dbgmsg("destroying ds %llu; currently traversing; "
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   839
			    "reset bookmark to -1,0,0,0",
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   840
			    (u_longlong_t)ds->ds_object);
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   841
		}
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   842
	} else if (zap_lookup_int_key(dp->dp_meta_objset,
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   843
	    scn->scn_phys.scn_queue_obj, ds->ds_object, &mintxg) == 0) {
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   844
		ASSERT3U(ds->ds_phys->ds_num_children, <=, 1);
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   845
		VERIFY3U(0, ==, zap_remove_int(dp->dp_meta_objset,
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   846
		    scn->scn_phys.scn_queue_obj, ds->ds_object, tx));
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   847
		if (dsl_dataset_is_snapshot(ds)) {
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   848
			/*
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   849
			 * We keep the same mintxg; it could be >
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   850
			 * ds_creation_txg if the previous snapshot was
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   851
			 * deleted too.
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   852
			 */
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   853
			VERIFY(zap_add_int_key(dp->dp_meta_objset,
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   854
			    scn->scn_phys.scn_queue_obj,
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   855
			    ds->ds_phys->ds_next_snap_obj, mintxg, tx) == 0);
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   856
			zfs_dbgmsg("destroying ds %llu; in queue; "
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   857
			    "replacing with %llu",
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   858
			    (u_longlong_t)ds->ds_object,
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   859
			    (u_longlong_t)ds->ds_phys->ds_next_snap_obj);
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   860
		} else {
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   861
			zfs_dbgmsg("destroying ds %llu; in queue; removing",
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   862
			    (u_longlong_t)ds->ds_object);
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   863
		}
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   864
	} else {
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   865
		zfs_dbgmsg("destroying ds %llu; ignoring",
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   866
		    (u_longlong_t)ds->ds_object);
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   867
	}
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   868
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   869
	/*
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   870
	 * dsl_scan_sync() should be called after this, and should sync
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   871
	 * out our changed state, but just to be safe, do it here.
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   872
	 */
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   873
	dsl_scan_sync_state(scn, tx);
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   874
}
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   875
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   876
void
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   877
dsl_scan_ds_snapshotted(dsl_dataset_t *ds, dmu_tx_t *tx)
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   878
{
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   879
	dsl_pool_t *dp = ds->ds_dir->dd_pool;
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   880
	dsl_scan_t *scn = dp->dp_scan;
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   881
	uint64_t mintxg;
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   882
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   883
	if (scn->scn_phys.scn_state != DSS_SCANNING)
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   884
		return;
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   885
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   886
	ASSERT(ds->ds_phys->ds_prev_snap_obj != 0);
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   887
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   888
	if (scn->scn_phys.scn_bookmark.zb_objset == ds->ds_object) {
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   889
		scn->scn_phys.scn_bookmark.zb_objset =
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   890
		    ds->ds_phys->ds_prev_snap_obj;
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   891
		zfs_dbgmsg("snapshotting ds %llu; currently traversing; "
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   892
		    "reset zb_objset to %llu",
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   893
		    (u_longlong_t)ds->ds_object,
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   894
		    (u_longlong_t)ds->ds_phys->ds_prev_snap_obj);
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   895
	} else if (zap_lookup_int_key(dp->dp_meta_objset,
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   896
	    scn->scn_phys.scn_queue_obj, ds->ds_object, &mintxg) == 0) {
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   897
		VERIFY3U(0, ==, zap_remove_int(dp->dp_meta_objset,
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   898
		    scn->scn_phys.scn_queue_obj, ds->ds_object, tx));
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   899
		VERIFY(zap_add_int_key(dp->dp_meta_objset,
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   900
		    scn->scn_phys.scn_queue_obj,
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   901
		    ds->ds_phys->ds_prev_snap_obj, mintxg, tx) == 0);
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   902
		zfs_dbgmsg("snapshotting ds %llu; in queue; "
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   903
		    "replacing with %llu",
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   904
		    (u_longlong_t)ds->ds_object,
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   905
		    (u_longlong_t)ds->ds_phys->ds_prev_snap_obj);
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   906
	}
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   907
	dsl_scan_sync_state(scn, tx);
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   908
}
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   909
7837
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
   910
void
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   911
dsl_scan_ds_clone_swapped(dsl_dataset_t *ds1, dsl_dataset_t *ds2, dmu_tx_t *tx)
7837
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
   912
{
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
   913
	dsl_pool_t *dp = ds1->ds_dir->dd_pool;
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   914
	dsl_scan_t *scn = dp->dp_scan;
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   915
	uint64_t mintxg;
7837
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
   916
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   917
	if (scn->scn_phys.scn_state != DSS_SCANNING)
7837
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
   918
		return;
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
   919
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   920
	if (scn->scn_phys.scn_bookmark.zb_objset == ds1->ds_object) {
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   921
		scn->scn_phys.scn_bookmark.zb_objset = ds2->ds_object;
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   922
		zfs_dbgmsg("clone_swap ds %llu; currently traversing; "
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   923
		    "reset zb_objset to %llu",
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   924
		    (u_longlong_t)ds1->ds_object,
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   925
		    (u_longlong_t)ds2->ds_object);
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   926
	} else if (scn->scn_phys.scn_bookmark.zb_objset == ds2->ds_object) {
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   927
		scn->scn_phys.scn_bookmark.zb_objset = ds1->ds_object;
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   928
		zfs_dbgmsg("clone_swap ds %llu; currently traversing; "
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   929
		    "reset zb_objset to %llu",
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   930
		    (u_longlong_t)ds2->ds_object,
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   931
		    (u_longlong_t)ds1->ds_object);
7837
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
   932
	}
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
   933
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   934
	if (zap_lookup_int_key(dp->dp_meta_objset, scn->scn_phys.scn_queue_obj,
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   935
	    ds1->ds_object, &mintxg) == 0) {
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   936
		int err;
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   937
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   938
		ASSERT3U(mintxg, ==, ds1->ds_phys->ds_prev_snap_txg);
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   939
		ASSERT3U(mintxg, ==, ds2->ds_phys->ds_prev_snap_txg);
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   940
		VERIFY3U(0, ==, zap_remove_int(dp->dp_meta_objset,
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   941
		    scn->scn_phys.scn_queue_obj, ds1->ds_object, tx));
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   942
		err = zap_add_int_key(dp->dp_meta_objset,
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   943
		    scn->scn_phys.scn_queue_obj, ds2->ds_object, mintxg, tx);
7837
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
   944
		VERIFY(err == 0 || err == EEXIST);
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
   945
		if (err == EEXIST) {
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
   946
			/* Both were there to begin with */
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   947
			VERIFY(0 == zap_add_int_key(dp->dp_meta_objset,
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   948
			    scn->scn_phys.scn_queue_obj,
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   949
			    ds1->ds_object, mintxg, tx));
7837
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
   950
		}
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   951
		zfs_dbgmsg("clone_swap ds %llu; in queue; "
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   952
		    "replacing with %llu",
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   953
		    (u_longlong_t)ds1->ds_object,
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   954
		    (u_longlong_t)ds2->ds_object);
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   955
	} else if (zap_lookup_int_key(dp->dp_meta_objset,
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   956
	    scn->scn_phys.scn_queue_obj, ds2->ds_object, &mintxg) == 0) {
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   957
		ASSERT3U(mintxg, ==, ds1->ds_phys->ds_prev_snap_txg);
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   958
		ASSERT3U(mintxg, ==, ds2->ds_phys->ds_prev_snap_txg);
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   959
		VERIFY3U(0, ==, zap_remove_int(dp->dp_meta_objset,
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   960
		    scn->scn_phys.scn_queue_obj, ds2->ds_object, tx));
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   961
		VERIFY(0 == zap_add_int_key(dp->dp_meta_objset,
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   962
		    scn->scn_phys.scn_queue_obj, ds1->ds_object, mintxg, tx));
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   963
		zfs_dbgmsg("clone_swap ds %llu; in queue; "
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   964
		    "replacing with %llu",
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   965
		    (u_longlong_t)ds2->ds_object,
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   966
		    (u_longlong_t)ds1->ds_object);
7837
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
   967
	}
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   968
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   969
	dsl_scan_sync_state(scn, tx);
7837
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
   970
}
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
   971
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   972
struct enqueue_clones_arg {
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   973
	dmu_tx_t *tx;
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   974
	uint64_t originobj;
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   975
};
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   976
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   977
/* ARGSUSED */
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   978
static int
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   979
enqueue_clones_cb(spa_t *spa, uint64_t dsobj, const char *dsname, void *arg)
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   980
{
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   981
	struct enqueue_clones_arg *eca = arg;
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   982
	dsl_dataset_t *ds;
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   983
	int err;
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   984
	dsl_pool_t *dp = spa->spa_dsl_pool;
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   985
	dsl_scan_t *scn = dp->dp_scan;
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   986
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
   987
	err = dsl_dataset_hold_obj(dp, dsobj, FTAG, &ds);
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   988
	if (err)
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   989
		return (err);
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   990
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   991
	if (ds->ds_dir->dd_phys->dd_origin_obj == eca->originobj) {
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   992
		while (ds->ds_phys->ds_prev_snap_obj != eca->originobj) {
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   993
			dsl_dataset_t *prev;
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   994
			err = dsl_dataset_hold_obj(dp,
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   995
			    ds->ds_phys->ds_prev_snap_obj, FTAG, &prev);
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   996
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   997
			dsl_dataset_rele(ds, FTAG);
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   998
			if (err)
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
   999
				return (err);
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
  1000
			ds = prev;
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
  1001
		}
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1002
		VERIFY(zap_add_int_key(dp->dp_meta_objset,
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1003
		    scn->scn_phys.scn_queue_obj, ds->ds_object,
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1004
		    ds->ds_phys->ds_prev_snap_txg, eca->tx) == 0);
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
  1005
	}
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
  1006
	dsl_dataset_rele(ds, FTAG);
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
  1007
	return (0);
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
  1008
}
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
  1009
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
  1010
static void
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1011
dsl_scan_visitds(dsl_scan_t *scn, uint64_t dsobj, dmu_tx_t *tx)
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
  1012
{
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1013
	dsl_pool_t *dp = scn->scn_dp;
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
  1014
	dsl_dataset_t *ds;
12839
1eab9192da8b 6844896 recursive snapshots take a long time
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12586
diff changeset
  1015
	objset_t *os;
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
  1016
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
  1017
	VERIFY3U(0, ==, dsl_dataset_hold_obj(dp, dsobj, FTAG, &ds));
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
  1018
12839
1eab9192da8b 6844896 recursive snapshots take a long time
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12586
diff changeset
  1019
	if (dmu_objset_from_ds(ds, &os))
1eab9192da8b 6844896 recursive snapshots take a long time
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12586
diff changeset
  1020
		goto out;
1eab9192da8b 6844896 recursive snapshots take a long time
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12586
diff changeset
  1021
1eab9192da8b 6844896 recursive snapshots take a long time
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12586
diff changeset
  1022
	/*
1eab9192da8b 6844896 recursive snapshots take a long time
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12586
diff changeset
  1023
	 * Only the ZIL in the head (non-snapshot) is valid.  Even though
1eab9192da8b 6844896 recursive snapshots take a long time
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12586
diff changeset
  1024
	 * snapshots can have ZIL block pointers (which may be the same
1eab9192da8b 6844896 recursive snapshots take a long time
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12586
diff changeset
  1025
	 * BP as in the head), they must be ignored.  So we traverse the
1eab9192da8b 6844896 recursive snapshots take a long time
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12586
diff changeset
  1026
	 * ZIL here, rather than in scan_recurse(), because the regular
1eab9192da8b 6844896 recursive snapshots take a long time
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12586
diff changeset
  1027
	 * snapshot block-sharing rules don't apply to it.
1eab9192da8b 6844896 recursive snapshots take a long time
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12586
diff changeset
  1028
	 */
1eab9192da8b 6844896 recursive snapshots take a long time
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12586
diff changeset
  1029
	if (DSL_SCAN_IS_SCRUB_RESILVER(scn) && !dsl_dataset_is_snapshot(ds))
1eab9192da8b 6844896 recursive snapshots take a long time
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12586
diff changeset
  1030
		dsl_scan_zil(dp, &os->os_zil_header);
1eab9192da8b 6844896 recursive snapshots take a long time
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12586
diff changeset
  1031
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
  1032
	/*
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
  1033
	 * Iterate over the bps in this ds.
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
  1034
	 */
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1035
	dmu_buf_will_dirty(ds->ds_dbuf, tx);
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1036
	dsl_scan_visit_rootbp(scn, ds, &ds->ds_phys->ds_bp, tx);
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1037
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1038
	char *dsname = kmem_alloc(ZFS_MAXNAMELEN, KM_SLEEP);
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1039
	dsl_dataset_name(ds, dsname);
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1040
	zfs_dbgmsg("scanned dataset %llu (%s) with min=%llu max=%llu; "
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1041
	    "pausing=%u",
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1042
	    (longlong_t)dsobj, dsname,
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1043
	    (longlong_t)scn->scn_phys.scn_cur_min_txg,
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1044
	    (longlong_t)scn->scn_phys.scn_cur_max_txg,
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1045
	    (int)scn->scn_pausing);
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1046
	kmem_free(dsname, ZFS_MAXNAMELEN);
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1047
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1048
	if (scn->scn_pausing)
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1049
		goto out;
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
  1050
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1051
	/*
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1052
	 * We've finished this pass over this dataset.
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1053
	 */
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1054
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1055
	/*
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1056
	 * If we did not completely visit this dataset, do another pass.
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1057
	 */
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1058
	if (scn->scn_phys.scn_flags & DSF_VISIT_DS_AGAIN) {
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1059
		zfs_dbgmsg("incomplete pass; visiting again");
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1060
		scn->scn_phys.scn_flags &= ~DSF_VISIT_DS_AGAIN;
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1061
		VERIFY(zap_add_int_key(dp->dp_meta_objset,
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1062
		    scn->scn_phys.scn_queue_obj, ds->ds_object,
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1063
		    scn->scn_phys.scn_cur_max_txg, tx) == 0);
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
  1064
		goto out;
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1065
	}
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
  1066
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
  1067
	/*
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
  1068
	 * Add descendent datasets to work queue.
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
  1069
	 */
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
  1070
	if (ds->ds_phys->ds_next_snap_obj != 0) {
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1071
		VERIFY(zap_add_int_key(dp->dp_meta_objset,
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1072
		    scn->scn_phys.scn_queue_obj, ds->ds_phys->ds_next_snap_obj,
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1073
		    ds->ds_phys->ds_creation_txg, tx) == 0);
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
  1074
	}
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
  1075
	if (ds->ds_phys->ds_num_children > 1) {
10801
e0bf032e8673 6822816 assertion failed: zap_remove_int(ds_next_clones_obj) returns ENOENT
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10685
diff changeset
  1076
		boolean_t usenext = B_FALSE;
e0bf032e8673 6822816 assertion failed: zap_remove_int(ds_next_clones_obj) returns ENOENT
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10685
diff changeset
  1077
		if (ds->ds_phys->ds_next_clones_obj != 0) {
e0bf032e8673 6822816 assertion failed: zap_remove_int(ds_next_clones_obj) returns ENOENT
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10685
diff changeset
  1078
			uint64_t count;
e0bf032e8673 6822816 assertion failed: zap_remove_int(ds_next_clones_obj) returns ENOENT
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10685
diff changeset
  1079
			/*
e0bf032e8673 6822816 assertion failed: zap_remove_int(ds_next_clones_obj) returns ENOENT
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10685
diff changeset
  1080
			 * A bug in a previous version of the code could
e0bf032e8673 6822816 assertion failed: zap_remove_int(ds_next_clones_obj) returns ENOENT
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10685
diff changeset
  1081
			 * cause upgrade_clones_cb() to not set
e0bf032e8673 6822816 assertion failed: zap_remove_int(ds_next_clones_obj) returns ENOENT
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10685
diff changeset
  1082
			 * ds_next_snap_obj when it should, leading to a
e0bf032e8673 6822816 assertion failed: zap_remove_int(ds_next_clones_obj) returns ENOENT
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10685
diff changeset
  1083
			 * missing entry.  Therefore we can only use the
e0bf032e8673 6822816 assertion failed: zap_remove_int(ds_next_clones_obj) returns ENOENT
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10685
diff changeset
  1084
			 * next_clones_obj when its count is correct.
e0bf032e8673 6822816 assertion failed: zap_remove_int(ds_next_clones_obj) returns ENOENT
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10685
diff changeset
  1085
			 */
e0bf032e8673 6822816 assertion failed: zap_remove_int(ds_next_clones_obj) returns ENOENT
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10685
diff changeset
  1086
			int err = zap_count(dp->dp_meta_objset,
e0bf032e8673 6822816 assertion failed: zap_remove_int(ds_next_clones_obj) returns ENOENT
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10685
diff changeset
  1087
			    ds->ds_phys->ds_next_clones_obj, &count);
e0bf032e8673 6822816 assertion failed: zap_remove_int(ds_next_clones_obj) returns ENOENT
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10685
diff changeset
  1088
			if (err == 0 &&
e0bf032e8673 6822816 assertion failed: zap_remove_int(ds_next_clones_obj) returns ENOENT
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10685
diff changeset
  1089
			    count == ds->ds_phys->ds_num_children - 1)
e0bf032e8673 6822816 assertion failed: zap_remove_int(ds_next_clones_obj) returns ENOENT
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10685
diff changeset
  1090
				usenext = B_TRUE;
e0bf032e8673 6822816 assertion failed: zap_remove_int(ds_next_clones_obj) returns ENOENT
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10685
diff changeset
  1091
		}
e0bf032e8673 6822816 assertion failed: zap_remove_int(ds_next_clones_obj) returns ENOENT
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10685
diff changeset
  1092
e0bf032e8673 6822816 assertion failed: zap_remove_int(ds_next_clones_obj) returns ENOENT
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10685
diff changeset
  1093
		if (usenext) {
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1094
			VERIFY(zap_join_key(dp->dp_meta_objset,
10801
e0bf032e8673 6822816 assertion failed: zap_remove_int(ds_next_clones_obj) returns ENOENT
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10685
diff changeset
  1095
			    ds->ds_phys->ds_next_clones_obj,
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1096
			    scn->scn_phys.scn_queue_obj,
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1097
			    ds->ds_phys->ds_creation_txg, tx) == 0);
10801
e0bf032e8673 6822816 assertion failed: zap_remove_int(ds_next_clones_obj) returns ENOENT
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10685
diff changeset
  1098
		} else {
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
  1099
			struct enqueue_clones_arg eca;
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
  1100
			eca.tx = tx;
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
  1101
			eca.originobj = ds->ds_object;
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
  1102
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
  1103
			(void) dmu_objset_find_spa(ds->ds_dir->dd_pool->dp_spa,
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
  1104
			    NULL, enqueue_clones_cb, &eca, DS_FIND_CHILDREN);
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
  1105
		}
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
  1106
	}
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
  1107
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
  1108
out:
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
  1109
	dsl_dataset_rele(ds, FTAG);
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
  1110
}
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
  1111
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
  1112
/* ARGSUSED */
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
  1113
static int
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
  1114
enqueue_cb(spa_t *spa, uint64_t dsobj, const char *dsname, void *arg)
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
  1115
{
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
  1116
	dmu_tx_t *tx = arg;
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
  1117
	dsl_dataset_t *ds;
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
  1118
	int err;
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1119
	dsl_pool_t *dp = spa->spa_dsl_pool;
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1120
	dsl_scan_t *scn = dp->dp_scan;
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
  1121
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1122
	err = dsl_dataset_hold_obj(dp, dsobj, FTAG, &ds);
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
  1123
	if (err)
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
  1124
		return (err);
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
  1125
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
  1126
	while (ds->ds_phys->ds_prev_snap_obj != 0) {
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
  1127
		dsl_dataset_t *prev;
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
  1128
		err = dsl_dataset_hold_obj(dp, ds->ds_phys->ds_prev_snap_obj,
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
  1129
		    FTAG, &prev);
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
  1130
		if (err) {
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
  1131
			dsl_dataset_rele(ds, FTAG);
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
  1132
			return (err);
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
  1133
		}
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
  1134
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
  1135
		/*
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
  1136
		 * If this is a clone, we don't need to worry about it for now.
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
  1137
		 */
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
  1138
		if (prev->ds_phys->ds_next_snap_obj != ds->ds_object) {
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
  1139
			dsl_dataset_rele(ds, FTAG);
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
  1140
			dsl_dataset_rele(prev, FTAG);
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
  1141
			return (0);
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
  1142
		}
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
  1143
		dsl_dataset_rele(ds, FTAG);
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
  1144
		ds = prev;
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
  1145
	}
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
  1146
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1147
	VERIFY(zap_add_int_key(dp->dp_meta_objset, scn->scn_phys.scn_queue_obj,
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1148
	    ds->ds_object, ds->ds_phys->ds_prev_snap_txg, tx) == 0);
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
  1149
	dsl_dataset_rele(ds, FTAG);
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
  1150
	return (0);
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
  1151
}
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
  1152
11125
fca3e6d28599 6899923 vdev_offline/vdev_add deadlock
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 11066
diff changeset
  1153
/*
fca3e6d28599 6899923 vdev_offline/vdev_add deadlock
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 11066
diff changeset
  1154
 * Scrub/dedup interaction.
fca3e6d28599 6899923 vdev_offline/vdev_add deadlock
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 11066
diff changeset
  1155
 *
fca3e6d28599 6899923 vdev_offline/vdev_add deadlock
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 11066
diff changeset
  1156
 * If there are N references to a deduped block, we don't want to scrub it
fca3e6d28599 6899923 vdev_offline/vdev_add deadlock
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 11066
diff changeset
  1157
 * N times -- ideally, we should scrub it exactly once.
fca3e6d28599 6899923 vdev_offline/vdev_add deadlock
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 11066
diff changeset
  1158
 *
11619
d3fb7ae6fe56 6909744 dedup should be set to off when a ZVOL is dumpified
George Wilson <George.Wilson@Sun.COM>
parents: 11182
diff changeset
  1159
 * We leverage the fact that the dde's replication class (enum ddt_class)
d3fb7ae6fe56 6909744 dedup should be set to off when a ZVOL is dumpified
George Wilson <George.Wilson@Sun.COM>
parents: 11182
diff changeset
  1160
 * is ordered from highest replication class (DDT_CLASS_DITTO) to lowest
d3fb7ae6fe56 6909744 dedup should be set to off when a ZVOL is dumpified
George Wilson <George.Wilson@Sun.COM>
parents: 11182
diff changeset
  1161
 * (DDT_CLASS_UNIQUE) so that we may walk the DDT in that order.
d3fb7ae6fe56 6909744 dedup should be set to off when a ZVOL is dumpified
George Wilson <George.Wilson@Sun.COM>
parents: 11182
diff changeset
  1162
 *
11125
fca3e6d28599 6899923 vdev_offline/vdev_add deadlock
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 11066
diff changeset
  1163
 * To prevent excess scrubbing, the scrub begins by walking the DDT
fca3e6d28599 6899923 vdev_offline/vdev_add deadlock
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 11066
diff changeset
  1164
 * to find all blocks with refcnt > 1, and scrubs each of these once.
11619
d3fb7ae6fe56 6909744 dedup should be set to off when a ZVOL is dumpified
George Wilson <George.Wilson@Sun.COM>
parents: 11182
diff changeset
  1165
 * Since there are two replication classes which contain blocks with
d3fb7ae6fe56 6909744 dedup should be set to off when a ZVOL is dumpified
George Wilson <George.Wilson@Sun.COM>
parents: 11182
diff changeset
  1166
 * refcnt > 1, we scrub the highest replication class (DDT_CLASS_DITTO) first.
d3fb7ae6fe56 6909744 dedup should be set to off when a ZVOL is dumpified
George Wilson <George.Wilson@Sun.COM>
parents: 11182
diff changeset
  1167
 * Finally the top-down scrub begins, only visiting blocks with refcnt == 1.
11125
fca3e6d28599 6899923 vdev_offline/vdev_add deadlock
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 11066
diff changeset
  1168
 *
fca3e6d28599 6899923 vdev_offline/vdev_add deadlock
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 11066
diff changeset
  1169
 * There would be nothing more to say if a block's refcnt couldn't change
11619
d3fb7ae6fe56 6909744 dedup should be set to off when a ZVOL is dumpified
George Wilson <George.Wilson@Sun.COM>
parents: 11182
diff changeset
  1170
 * during a scrub, but of course it can so we must account for changes
d3fb7ae6fe56 6909744 dedup should be set to off when a ZVOL is dumpified
George Wilson <George.Wilson@Sun.COM>
parents: 11182
diff changeset
  1171
 * in a block's replication class.
d3fb7ae6fe56 6909744 dedup should be set to off when a ZVOL is dumpified
George Wilson <George.Wilson@Sun.COM>
parents: 11182
diff changeset
  1172
 *
d3fb7ae6fe56 6909744 dedup should be set to off when a ZVOL is dumpified
George Wilson <George.Wilson@Sun.COM>
parents: 11182
diff changeset
  1173
 * Here's an example of what can occur:
11125
fca3e6d28599 6899923 vdev_offline/vdev_add deadlock
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 11066
diff changeset
  1174
 *
fca3e6d28599 6899923 vdev_offline/vdev_add deadlock
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 11066
diff changeset
  1175
 * If a block has refcnt > 1 during the DDT scrub phase, but has refcnt == 1
fca3e6d28599 6899923 vdev_offline/vdev_add deadlock
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 11066
diff changeset
  1176
 * when visited during the top-down scrub phase, it will be scrubbed twice.
fca3e6d28599 6899923 vdev_offline/vdev_add deadlock
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 11066
diff changeset
  1177
 * This negates our scrub optimization, but is otherwise harmless.
fca3e6d28599 6899923 vdev_offline/vdev_add deadlock
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 11066
diff changeset
  1178
 *
fca3e6d28599 6899923 vdev_offline/vdev_add deadlock
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 11066
diff changeset
  1179
 * If a block has refcnt == 1 during the DDT scrub phase, but has refcnt > 1
fca3e6d28599 6899923 vdev_offline/vdev_add deadlock
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 11066
diff changeset
  1180
 * on each visit during the top-down scrub phase, it will never be scrubbed.
fca3e6d28599 6899923 vdev_offline/vdev_add deadlock
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 11066
diff changeset
  1181
 * To catch this, ddt_sync_entry() notifies the scrub code whenever a block's
11619
d3fb7ae6fe56 6909744 dedup should be set to off when a ZVOL is dumpified
George Wilson <George.Wilson@Sun.COM>
parents: 11182
diff changeset
  1182
 * reference class transitions to a higher level (i.e DDT_CLASS_UNIQUE to
d3fb7ae6fe56 6909744 dedup should be set to off when a ZVOL is dumpified
George Wilson <George.Wilson@Sun.COM>
parents: 11182
diff changeset
  1183
 * DDT_CLASS_DUPLICATE); if it transitions from refcnt == 1 to refcnt > 1
11125
fca3e6d28599 6899923 vdev_offline/vdev_add deadlock
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 11066
diff changeset
  1184
 * while a scrub is in progress, it scrubs the block right then.
fca3e6d28599 6899923 vdev_offline/vdev_add deadlock
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 11066
diff changeset
  1185
 */
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1186
static void
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1187
dsl_scan_ddt(dsl_scan_t *scn, dmu_tx_t *tx)
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1188
{
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1189
	ddt_bookmark_t *ddb = &scn->scn_phys.scn_ddt_bookmark;
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1190
	ddt_entry_t dde = { 0 };
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1191
	int error;
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1192
	uint64_t n = 0;
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1193
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1194
	while ((error = ddt_walk(scn->scn_dp->dp_spa, ddb, &dde)) == 0) {
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1195
		ddt_t *ddt;
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1196
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1197
		if (ddb->ddb_class > scn->scn_phys.scn_ddt_class_max)
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1198
			break;
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1199
		dprintf("visiting ddb=%llu/%llu/%llu/%llx\n",
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1200
		    (longlong_t)ddb->ddb_class,
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1201
		    (longlong_t)ddb->ddb_type,
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1202
		    (longlong_t)ddb->ddb_checksum,
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1203
		    (longlong_t)ddb->ddb_cursor);
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1204
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1205
		/* There should be no pending changes to the dedup table */
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1206
		ddt = scn->scn_dp->dp_spa->spa_ddt[ddb->ddb_checksum];
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1207
		ASSERT(avl_first(&ddt->ddt_tree) == NULL);
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1208
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1209
		dsl_scan_ddt_entry(scn, ddb->ddb_checksum, &dde, tx);
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1210
		n++;
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1211
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1212
		if (dsl_scan_check_pause(scn, NULL))
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1213
			break;
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1214
	}
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1215
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1216
	zfs_dbgmsg("scanned %llu ddt entries with class_max = %u; pausing=%u",
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1217
	    (longlong_t)n, (int)scn->scn_phys.scn_ddt_class_max,
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1218
	    (int)scn->scn_pausing);
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1219
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1220
	ASSERT(error == 0 || error == ENOENT);
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1221
	ASSERT(error != ENOENT ||
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1222
	    ddb->ddb_class > scn->scn_phys.scn_ddt_class_max);
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1223
}
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1224
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1225
/* ARGSUSED */
11125
fca3e6d28599 6899923 vdev_offline/vdev_add deadlock
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 11066
diff changeset
  1226
void
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1227
dsl_scan_ddt_entry(dsl_scan_t *scn, enum zio_checksum checksum,
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1228
    ddt_entry_t *dde, dmu_tx_t *tx)
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1229
{
11125
fca3e6d28599 6899923 vdev_offline/vdev_add deadlock
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 11066
diff changeset
  1230
	const ddt_key_t *ddk = &dde->dde_key;
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1231
	ddt_phys_t *ddp = dde->dde_phys;
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1232
	blkptr_t bp;
11125
fca3e6d28599 6899923 vdev_offline/vdev_add deadlock
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 11066
diff changeset
  1233
	zbookmark_t zb = { 0 };
fca3e6d28599 6899923 vdev_offline/vdev_add deadlock
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 11066
diff changeset
  1234
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1235
	if (scn->scn_phys.scn_state != DSS_SCANNING)
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1236
		return;
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1237
11125
fca3e6d28599 6899923 vdev_offline/vdev_add deadlock
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 11066
diff changeset
  1238
	for (int p = 0; p < DDT_PHYS_TYPES; p++, ddp++) {
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1239
		if (ddp->ddp_phys_birth == 0 ||
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1240
		    ddp->ddp_phys_birth > scn->scn_phys.scn_cur_max_txg)
11125
fca3e6d28599 6899923 vdev_offline/vdev_add deadlock
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 11066
diff changeset
  1241
			continue;
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1242
		ddt_bp_create(checksum, ddk, ddp, &bp);
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1243
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1244
		scn->scn_visited_this_txg++;
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1245
		scan_funcs[scn->scn_phys.scn_func](scn->scn_dp, &bp, &zb);
11125
fca3e6d28599 6899923 vdev_offline/vdev_add deadlock
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 11066
diff changeset
  1246
	}
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1247
}
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1248
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1249
static void
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1250
dsl_scan_visit(dsl_scan_t *scn, dmu_tx_t *tx)
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
  1251
{
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1252
	dsl_pool_t *dp = scn->scn_dp;
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
  1253
	zap_cursor_t zc;
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
  1254
	zap_attribute_t za;
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
  1255
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1256
	if (scn->scn_phys.scn_ddt_bookmark.ddb_class <=
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1257
	    scn->scn_phys.scn_ddt_class_max) {
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1258
		scn->scn_phys.scn_cur_min_txg = scn->scn_phys.scn_min_txg;
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1259
		scn->scn_phys.scn_cur_max_txg = scn->scn_phys.scn_max_txg;
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1260
		dsl_scan_ddt(scn, tx);
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1261
		if (scn->scn_pausing)
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1262
			return;
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
  1263
	}
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
  1264
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1265
	if (scn->scn_phys.scn_bookmark.zb_objset == DMU_META_OBJSET) {
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1266
		/* First do the MOS & ORIGIN */
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
  1267
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1268
		scn->scn_phys.scn_cur_min_txg = scn->scn_phys.scn_min_txg;
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1269
		scn->scn_phys.scn_cur_max_txg = scn->scn_phys.scn_max_txg;
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1270
		dsl_scan_visit_rootbp(scn, NULL,
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1271
		    &dp->dp_meta_rootbp, tx);
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1272
		spa_set_rootblkptr(dp->dp_spa, &dp->dp_meta_rootbp);
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1273
		if (scn->scn_pausing)
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1274
			return;
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1275
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1276
		if (spa_version(dp->dp_spa) < SPA_VERSION_DSL_SCRUB) {
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1277
			VERIFY(0 == dmu_objset_find_spa(dp->dp_spa,
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
  1278
			    NULL, enqueue_cb, tx, DS_FIND_CHILDREN));
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
  1279
		} else {
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1280
			dsl_scan_visitds(scn,
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1281
			    dp->dp_origin_snap->ds_object, tx);
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
  1282
		}
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1283
		ASSERT(!scn->scn_pausing);
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1284
	} else if (scn->scn_phys.scn_bookmark.zb_objset !=
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1285
	    ZB_DESTROYED_OBJSET) {
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
  1286
		/*
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1287
		 * If we were paused, continue from here.  Note if the
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1288
		 * ds we were paused on was deleted, the zb_objset may
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1289
		 * be -1, so we will skip this and find a new objset
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1290
		 * below.
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
  1291
		 */
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1292
		dsl_scan_visitds(scn, scn->scn_phys.scn_bookmark.zb_objset, tx);
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1293
		if (scn->scn_pausing)
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1294
			return;
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
  1295
	}
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
  1296
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
  1297
	/*
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
  1298
	 * In case we were paused right at the end of the ds, zero the
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
  1299
	 * bookmark so we don't think that we're still trying to resume.
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
  1300
	 */
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1301
	bzero(&scn->scn_phys.scn_bookmark, sizeof (zbookmark_t));
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
  1302
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
  1303
	/* keep pulling things out of the zap-object-as-queue */
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1304
	while (zap_cursor_init(&zc, dp->dp_meta_objset,
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1305
	    scn->scn_phys.scn_queue_obj),
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
  1306
	    zap_cursor_retrieve(&zc, &za) == 0) {
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1307
		dsl_dataset_t *ds;
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1308
		uint64_t dsobj;
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1309
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1310
		dsobj = strtonum(za.za_name, NULL);
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1311
		VERIFY3U(0, ==, zap_remove_int(dp->dp_meta_objset,
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1312
		    scn->scn_phys.scn_queue_obj, dsobj, tx));
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1313
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1314
		/* Set up min/max txg */
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1315
		VERIFY3U(0, ==, dsl_dataset_hold_obj(dp, dsobj, FTAG, &ds));
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1316
		if (za.za_first_integer != 0) {
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1317
			scn->scn_phys.scn_cur_min_txg =
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1318
			    MAX(scn->scn_phys.scn_min_txg,
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1319
			    za.za_first_integer);
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1320
		} else {
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1321
			scn->scn_phys.scn_cur_min_txg =
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1322
			    MAX(scn->scn_phys.scn_min_txg,
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1323
			    ds->ds_phys->ds_prev_snap_txg);
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1324
		}
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1325
		scn->scn_phys.scn_cur_max_txg = dsl_scan_ds_maxtxg(ds);
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1326
		dsl_dataset_rele(ds, FTAG);
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1327
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1328
		dsl_scan_visitds(scn, dsobj, tx);
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
  1329
		zap_cursor_fini(&zc);
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1330
		if (scn->scn_pausing)
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1331
			return;
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
  1332
	}
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
  1333
	zap_cursor_fini(&zc);
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
  1334
}
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
  1335
13700
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 12839
diff changeset
  1336
static boolean_t
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 12839
diff changeset
  1337
dsl_scan_free_should_pause(dsl_scan_t *scn)
12470
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
  1338
{
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
  1339
	uint64_t elapsed_nanosecs;
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
  1340
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
  1341
	elapsed_nanosecs = gethrtime() - scn->scn_sync_start_time;
13700
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 12839
diff changeset
  1342
	return (elapsed_nanosecs / NANOSEC > zfs_txg_timeout ||
12470
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
  1343
	    (elapsed_nanosecs / MICROSEC > zfs_free_min_time_ms &&
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
  1344
	    txg_sync_waiting(scn->scn_dp)) ||
13700
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 12839
diff changeset
  1345
	    spa_shutting_down(scn->scn_dp->dp_spa));
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 12839
diff changeset
  1346
}
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 12839
diff changeset
  1347
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 12839
diff changeset
  1348
static int
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 12839
diff changeset
  1349
dsl_scan_free_block_cb(void *arg, const blkptr_t *bp, dmu_tx_t *tx)
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 12839
diff changeset
  1350
{
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 12839
diff changeset
  1351
	dsl_scan_t *scn = arg;
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 12839
diff changeset
  1352
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 12839
diff changeset
  1353
	if (!scn->scn_is_bptree ||
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 12839
diff changeset
  1354
	    (BP_GET_LEVEL(bp) == 0 && BP_GET_TYPE(bp) != DMU_OT_OBJSET)) {
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 12839
diff changeset
  1355
		if (dsl_scan_free_should_pause(scn))
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 12839
diff changeset
  1356
			return (ERESTART);
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 12839
diff changeset
  1357
	}
12470
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
  1358
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
  1359
	zio_nowait(zio_free_sync(scn->scn_zio_root, scn->scn_dp->dp_spa,
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
  1360
	    dmu_tx_get_txg(tx), bp, 0));
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
  1361
	dsl_dir_diduse_space(tx->tx_pool->dp_free_dir, DD_USED_HEAD,
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
  1362
	    -bp_get_dsize_sync(scn->scn_dp->dp_spa, bp),
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
  1363
	    -BP_GET_PSIZE(bp), -BP_GET_UCSIZE(bp), tx);
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
  1364
	scn->scn_visited_this_txg++;
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
  1365
	return (0);
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
  1366
}
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
  1367
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
  1368
boolean_t
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
  1369
dsl_scan_active(dsl_scan_t *scn)
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
  1370
{
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
  1371
	spa_t *spa = scn->scn_dp->dp_spa;
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
  1372
	uint64_t used = 0, comp, uncomp;
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
  1373
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
  1374
	if (spa->spa_load_state != SPA_LOAD_NONE)
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
  1375
		return (B_FALSE);
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
  1376
	if (spa_shutting_down(spa))
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
  1377
		return (B_FALSE);
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
  1378
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
  1379
	if (scn->scn_phys.scn_state == DSS_SCANNING)
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
  1380
		return (B_TRUE);
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
  1381
13700
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 12839
diff changeset
  1382
	if (spa_feature_is_active(spa,
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 12839
diff changeset
  1383
	    &spa_feature_table[SPA_FEATURE_ASYNC_DESTROY])) {
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 12839
diff changeset
  1384
		return (B_TRUE);
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 12839
diff changeset
  1385
	}
12470
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
  1386
	if (spa_version(scn->scn_dp->dp_spa) >= SPA_VERSION_DEADLISTS) {
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
  1387
		(void) bpobj_space(&scn->scn_dp->dp_free_bpobj,
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
  1388
		    &used, &comp, &uncomp);
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
  1389
	}
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
  1390
	return (used != 0);
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
  1391
}
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
  1392
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
  1393
void
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1394
dsl_scan_sync(dsl_pool_t *dp, dmu_tx_t *tx)
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
  1395
{
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1396
	dsl_scan_t *scn = dp->dp_scan;
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1397
	spa_t *spa = dp->dp_spa;
12470
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
  1398
	int err;
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1399
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1400
	/*
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1401
	 * Check for scn_restart_txg before checking spa_load_state, so
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1402
	 * that we can restart an old-style scan while the pool is being
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1403
	 * imported (see dsl_scan_init).
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1404
	 */
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1405
	if (scn->scn_restart_txg != 0 &&
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1406
	    scn->scn_restart_txg <= tx->tx_txg) {
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1407
		pool_scan_func_t func = POOL_SCAN_SCRUB;
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1408
		dsl_scan_done(scn, B_FALSE, tx);
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1409
		if (vdev_resilver_needed(spa->spa_root_vdev, NULL, NULL))
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1410
			func = POOL_SCAN_RESILVER;
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1411
		zfs_dbgmsg("restarting scan func=%u txg=%llu",
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1412
		    func, tx->tx_txg);
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1413
		dsl_scan_setup_sync(scn, &func, tx);
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1414
	}
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1415
12470
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
  1416
	if (!dsl_scan_active(scn) ||
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
  1417
	    spa_sync_pass(dp->dp_spa) > 1)
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1418
		return;
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1419
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1420
	scn->scn_visited_this_txg = 0;
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1421
	scn->scn_pausing = B_FALSE;
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1422
	scn->scn_sync_start_time = gethrtime();
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1423
	spa->spa_scrub_active = B_TRUE;
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1424
12470
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
  1425
	/*
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
  1426
	 * First process the free list.  If we pause the free, don't do
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
  1427
	 * any scanning.  This ensures that there is no free list when
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
  1428
	 * we are scanning, so the scan code doesn't have to worry about
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
  1429
	 * traversing it.
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
  1430
	 */
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
  1431
	if (spa_version(dp->dp_spa) >= SPA_VERSION_DEADLISTS) {
13700
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 12839
diff changeset
  1432
		scn->scn_is_bptree = B_FALSE;
12470
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
  1433
		scn->scn_zio_root = zio_root(dp->dp_spa, NULL,
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
  1434
		    NULL, ZIO_FLAG_MUSTSUCCEED);
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
  1435
		err = bpobj_iterate(&dp->dp_free_bpobj,
13700
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 12839
diff changeset
  1436
		    dsl_scan_free_block_cb, scn, tx);
12470
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
  1437
		VERIFY3U(0, ==, zio_wait(scn->scn_zio_root));
13700
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 12839
diff changeset
  1438
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 12839
diff changeset
  1439
		if (err == 0 && spa_feature_is_active(spa,
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 12839
diff changeset
  1440
		    &spa_feature_table[SPA_FEATURE_ASYNC_DESTROY])) {
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 12839
diff changeset
  1441
			scn->scn_is_bptree = B_TRUE;
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 12839
diff changeset
  1442
			scn->scn_zio_root = zio_root(dp->dp_spa, NULL,
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 12839
diff changeset
  1443
			    NULL, ZIO_FLAG_MUSTSUCCEED);
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 12839
diff changeset
  1444
			err = bptree_iterate(dp->dp_meta_objset,
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 12839
diff changeset
  1445
			    dp->dp_bptree_obj, B_TRUE, dsl_scan_free_block_cb,
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 12839
diff changeset
  1446
			    scn, tx);
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 12839
diff changeset
  1447
			VERIFY3U(0, ==, zio_wait(scn->scn_zio_root));
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 12839
diff changeset
  1448
			if (err != 0)
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 12839
diff changeset
  1449
				return;
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 12839
diff changeset
  1450
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 12839
diff changeset
  1451
			/* disable async destroy feature */
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 12839
diff changeset
  1452
			spa_feature_decr(spa,
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 12839
diff changeset
  1453
			    &spa_feature_table[SPA_FEATURE_ASYNC_DESTROY], tx);
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 12839
diff changeset
  1454
			ASSERT(!spa_feature_is_active(spa,
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 12839
diff changeset
  1455
			    &spa_feature_table[SPA_FEATURE_ASYNC_DESTROY]));
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 12839
diff changeset
  1456
			VERIFY3U(0, ==, zap_remove(dp->dp_meta_objset,
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 12839
diff changeset
  1457
			    DMU_POOL_DIRECTORY_OBJECT,
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 12839
diff changeset
  1458
			    DMU_POOL_BPTREE_OBJ, tx));
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 12839
diff changeset
  1459
			VERIFY3U(0, ==, bptree_free(dp->dp_meta_objset,
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 12839
diff changeset
  1460
			    dp->dp_bptree_obj, tx));
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 12839
diff changeset
  1461
			dp->dp_bptree_obj = 0;
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 12839
diff changeset
  1462
		}
12470
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
  1463
		if (scn->scn_visited_this_txg) {
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
  1464
			zfs_dbgmsg("freed %llu blocks in %llums from "
13700
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 12839
diff changeset
  1465
			    "free_bpobj/bptree txg %llu",
12470
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
  1466
			    (longlong_t)scn->scn_visited_this_txg,
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
  1467
			    (longlong_t)
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
  1468
			    (gethrtime() - scn->scn_sync_start_time) / MICROSEC,
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
  1469
			    (longlong_t)tx->tx_txg);
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
  1470
			scn->scn_visited_this_txg = 0;
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
  1471
			/*
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
  1472
			 * Re-sync the ddt so that we can further modify
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
  1473
			 * it when doing bprewrite.
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
  1474
			 */
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
  1475
			ddt_sync(spa, tx->tx_txg);
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
  1476
		}
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
  1477
		if (err == ERESTART)
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
  1478
			return;
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
  1479
	}
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
  1480
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
  1481
	if (scn->scn_phys.scn_state != DSS_SCANNING)
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
  1482
		return;
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
  1483
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1484
	if (scn->scn_phys.scn_ddt_bookmark.ddb_class <=
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1485
	    scn->scn_phys.scn_ddt_class_max) {
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1486
		zfs_dbgmsg("doing scan sync txg %llu; "
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1487
		    "ddt bm=%llu/%llu/%llu/%llx",
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1488
		    (longlong_t)tx->tx_txg,
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1489
		    (longlong_t)scn->scn_phys.scn_ddt_bookmark.ddb_class,
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1490
		    (longlong_t)scn->scn_phys.scn_ddt_bookmark.ddb_type,
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1491
		    (longlong_t)scn->scn_phys.scn_ddt_bookmark.ddb_checksum,
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1492
		    (longlong_t)scn->scn_phys.scn_ddt_bookmark.ddb_cursor);
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1493
		ASSERT(scn->scn_phys.scn_bookmark.zb_objset == 0);
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1494
		ASSERT(scn->scn_phys.scn_bookmark.zb_object == 0);
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1495
		ASSERT(scn->scn_phys.scn_bookmark.zb_level == 0);
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1496
		ASSERT(scn->scn_phys.scn_bookmark.zb_blkid == 0);
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1497
	} else {
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1498
		zfs_dbgmsg("doing scan sync txg %llu; bm=%llu/%llu/%llu/%llu",
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1499
		    (longlong_t)tx->tx_txg,
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1500
		    (longlong_t)scn->scn_phys.scn_bookmark.zb_objset,
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1501
		    (longlong_t)scn->scn_phys.scn_bookmark.zb_object,
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1502
		    (longlong_t)scn->scn_phys.scn_bookmark.zb_level,
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1503
		    (longlong_t)scn->scn_phys.scn_bookmark.zb_blkid);
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1504
	}
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1505
12470
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
  1506
	scn->scn_zio_root = zio_root(dp->dp_spa, NULL,
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1507
	    NULL, ZIO_FLAG_CANFAIL);
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1508
	dsl_scan_visit(scn, tx);
12470
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
  1509
	(void) zio_wait(scn->scn_zio_root);
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
  1510
	scn->scn_zio_root = NULL;
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1511
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1512
	zfs_dbgmsg("visited %llu blocks in %llums",
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1513
	    (longlong_t)scn->scn_visited_this_txg,
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1514
	    (longlong_t)(gethrtime() - scn->scn_sync_start_time) / MICROSEC);
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1515
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1516
	if (!scn->scn_pausing) {
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1517
		/* finished with scan. */
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1518
		zfs_dbgmsg("finished scan txg %llu", (longlong_t)tx->tx_txg);
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1519
		dsl_scan_done(scn, B_TRUE, tx);
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1520
	}
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1521
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1522
	if (DSL_SCAN_IS_SCRUB_RESILVER(scn)) {
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1523
		mutex_enter(&spa->spa_scrub_lock);
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1524
		while (spa->spa_scrub_inflight > 0) {
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1525
			cv_wait(&spa->spa_scrub_io_cv,
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1526
			    &spa->spa_scrub_lock);
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1527
		}
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1528
		mutex_exit(&spa->spa_scrub_lock);
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1529
	}
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1530
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1531
	dsl_scan_sync_state(scn, tx);
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1532
}
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1533
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1534
/*
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1535
 * This will start a new scan, or restart an existing one.
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1536
 */
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1537
void
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1538
dsl_resilver_restart(dsl_pool_t *dp, uint64_t txg)
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1539
{
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1540
	if (txg == 0) {
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1541
		dmu_tx_t *tx;
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1542
		tx = dmu_tx_create_dd(dp->dp_mos_dir);
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1543
		VERIFY(0 == dmu_tx_assign(tx, TXG_WAIT));
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1544
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1545
		txg = dmu_tx_get_txg(tx);
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1546
		dp->dp_scan->scn_restart_txg = txg;
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1547
		dmu_tx_commit(tx);
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1548
	} else {
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1549
		dp->dp_scan->scn_restart_txg = txg;
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1550
	}
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1551
	zfs_dbgmsg("restarting resilver txg=%llu", txg);
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1552
}
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1553
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1554
boolean_t
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1555
dsl_scan_resilvering(dsl_pool_t *dp)
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1556
{
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1557
	return (dp->dp_scan->scn_phys.scn_state == DSS_SCANNING &&
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1558
	    dp->dp_scan->scn_phys.scn_func == POOL_SCAN_RESILVER);
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
  1559
}
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
  1560
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
  1561
/*
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
  1562
 * scrub consumers
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
  1563
 */
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
  1564
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
  1565
static void
7837
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  1566
count_block(zfs_all_blkstats_t *zab, const blkptr_t *bp)
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  1567
{
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  1568
	int i;
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  1569
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  1570
	/*
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  1571
	 * If we resume after a reboot, zab will be NULL; don't record
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  1572
	 * incomplete stats in that case.
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  1573
	 */
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  1574
	if (zab == NULL)
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  1575
		return;
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  1576
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  1577
	for (i = 0; i < 4; i++) {
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  1578
		int l = (i < 2) ? BP_GET_LEVEL(bp) : DN_MAX_LEVELS;
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  1579
		int t = (i & 1) ? BP_GET_TYPE(bp) : DMU_OT_TOTAL;
13700
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 12839
diff changeset
  1580
		if (t & DMU_OT_NEWTYPE)
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 12839
diff changeset
  1581
			t = DMU_OT_OTHER;
7837
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  1582
		zfs_blkstat_t *zb = &zab->zab_type[l][t];
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  1583
		int equal;
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  1584
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  1585
		zb->zb_count++;
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  1586
		zb->zb_asize += BP_GET_ASIZE(bp);
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  1587
		zb->zb_lsize += BP_GET_LSIZE(bp);
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  1588
		zb->zb_psize += BP_GET_PSIZE(bp);
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  1589
		zb->zb_gangs += BP_COUNT_GANG(bp);
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  1590
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  1591
		switch (BP_GET_NDVAS(bp)) {
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  1592
		case 2:
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  1593
			if (DVA_GET_VDEV(&bp->blk_dva[0]) ==
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  1594
			    DVA_GET_VDEV(&bp->blk_dva[1]))
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  1595
				zb->zb_ditto_2_of_2_samevdev++;
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  1596
			break;
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  1597
		case 3:
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  1598
			equal = (DVA_GET_VDEV(&bp->blk_dva[0]) ==
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  1599
			    DVA_GET_VDEV(&bp->blk_dva[1])) +
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  1600
			    (DVA_GET_VDEV(&bp->blk_dva[0]) ==
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  1601
			    DVA_GET_VDEV(&bp->blk_dva[2])) +
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  1602
			    (DVA_GET_VDEV(&bp->blk_dva[1]) ==
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  1603
			    DVA_GET_VDEV(&bp->blk_dva[2]));
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  1604
			if (equal == 1)
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  1605
				zb->zb_ditto_2_of_3_samevdev++;
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  1606
			else if (equal == 3)
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  1607
				zb->zb_ditto_3_of_3_samevdev++;
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  1608
			break;
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  1609
		}
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  1610
	}
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  1611
}
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  1612
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  1613
static void
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1614
dsl_scan_scrub_done(zio_t *zio)
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
  1615
{
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
  1616
	spa_t *spa = zio->io_spa;
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
  1617
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
  1618
	zio_data_buf_free(zio->io_data, zio->io_size);
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
  1619
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
  1620
	mutex_enter(&spa->spa_scrub_lock);
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
  1621
	spa->spa_scrub_inflight--;
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
  1622
	cv_broadcast(&spa->spa_scrub_io_cv);
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
  1623
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7182
diff changeset
  1624
	if (zio->io_error && (zio->io_error != ECKSUM ||
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1625
	    !(zio->io_flags & ZIO_FLAG_SPECULATIVE))) {
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1626
		spa->spa_dsl_pool->dp_scan->scn_phys.scn_errors++;
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1627
	}
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
  1628
	mutex_exit(&spa->spa_scrub_lock);
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
  1629
}
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
  1630
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
  1631
static int
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1632
dsl_scan_scrub_cb(dsl_pool_t *dp,
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
  1633
    const blkptr_t *bp, const zbookmark_t *zb)
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
  1634
{
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1635
	dsl_scan_t *scn = dp->dp_scan;
8274
846b39508aff 6713916 scrub/resilver needlessly decompress data
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 8241
diff changeset
  1636
	size_t size = BP_GET_PSIZE(bp);
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
  1637
	spa_t *spa = dp->dp_spa;
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1638
	uint64_t phys_birth = BP_PHYSICAL_BIRTH(bp);
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
  1639
	boolean_t needs_io;
12586
b118bbd65be9 6494473 ZFS needs a way to slow down resilvering
George Wilson <George.Wilson@Sun.COM>
parents: 12470
diff changeset
  1640
	int zio_flags = ZIO_FLAG_SCAN_THREAD | ZIO_FLAG_RAW | ZIO_FLAG_CANFAIL;
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
  1641
	int zio_priority;
12586
b118bbd65be9 6494473 ZFS needs a way to slow down resilvering
George Wilson <George.Wilson@Sun.COM>
parents: 12470
diff changeset
  1642
	int scan_delay = 0;
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
  1643
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1644
	if (phys_birth <= scn->scn_phys.scn_min_txg ||
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1645
	    phys_birth >= scn->scn_phys.scn_max_txg)
8241
5a60f16123ba 6328632 zpool offline is a bit too conservative
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7837
diff changeset
  1646
		return (0);
5a60f16123ba 6328632 zpool offline is a bit too conservative
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7837
diff changeset
  1647
7837
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  1648
	count_block(dp->dp_blkstats, bp);
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  1649
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1650
	ASSERT(DSL_SCAN_IS_SCRUB_RESILVER(scn));
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1651
	if (scn->scn_phys.scn_func == POOL_SCAN_SCRUB) {
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
  1652
		zio_flags |= ZIO_FLAG_SCRUB;
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
  1653
		zio_priority = ZIO_PRIORITY_SCRUB;
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
  1654
		needs_io = B_TRUE;
12586
b118bbd65be9 6494473 ZFS needs a way to slow down resilvering
George Wilson <George.Wilson@Sun.COM>
parents: 12470
diff changeset
  1655
		scan_delay = zfs_scrub_delay;
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1656
	} else if (scn->scn_phys.scn_func == POOL_SCAN_RESILVER) {
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
  1657
		zio_flags |= ZIO_FLAG_RESILVER;
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
  1658
		zio_priority = ZIO_PRIORITY_RESILVER;
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
  1659
		needs_io = B_FALSE;
12586
b118bbd65be9 6494473 ZFS needs a way to slow down resilvering
George Wilson <George.Wilson@Sun.COM>
parents: 12470
diff changeset
  1660
		scan_delay = zfs_resilver_delay;
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
  1661
	}
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
  1662
7160
12f467ba43f4 6725330 'zpool scrub -v' doesn't show data errors after scrub completes
ahrens
parents: 7046
diff changeset
  1663
	/* If it's an intent log block, failure is expected. */
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1664
	if (zb->zb_level == ZB_ZIL_LEVEL)
7160
12f467ba43f4 6725330 'zpool scrub -v' doesn't show data errors after scrub completes
ahrens
parents: 7046
diff changeset
  1665
		zio_flags |= ZIO_FLAG_SPECULATIVE;
12f467ba43f4 6725330 'zpool scrub -v' doesn't show data errors after scrub completes
ahrens
parents: 7046
diff changeset
  1666
8241
5a60f16123ba 6328632 zpool offline is a bit too conservative
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7837
diff changeset
  1667
	for (int d = 0; d < BP_GET_NDVAS(bp); d++) {
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
  1668
		vdev_t *vd = vdev_lookup_top(spa,
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
  1669
		    DVA_GET_VDEV(&bp->blk_dva[d]));
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
  1670
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
  1671
		/*
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
  1672
		 * Keep track of how much data we've examined so that
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
  1673
		 * zpool(1M) status can make useful progress reports.
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
  1674
		 */
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1675
		scn->scn_phys.scn_examined += DVA_GET_ASIZE(&bp->blk_dva[d]);
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1676
		spa->spa_scan_pass_exam += DVA_GET_ASIZE(&bp->blk_dva[d]);
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
  1677
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
  1678
		/* if it's a resilver, this may not be in the target range */
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
  1679
		if (!needs_io) {
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
  1680
			if (DVA_GET_GANG(&bp->blk_dva[d])) {
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
  1681
				/*
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
  1682
				 * Gang members may be spread across multiple
8241
5a60f16123ba 6328632 zpool offline is a bit too conservative
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7837
diff changeset
  1683
				 * vdevs, so the best estimate we have is the
5a60f16123ba 6328632 zpool offline is a bit too conservative
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7837
diff changeset
  1684
				 * scrub range, which has already been checked.
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
  1685
				 * XXX -- it would be better to change our
8241
5a60f16123ba 6328632 zpool offline is a bit too conservative
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7837
diff changeset
  1686
				 * allocation policy to ensure that all
5a60f16123ba 6328632 zpool offline is a bit too conservative
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7837
diff changeset
  1687
				 * gang members reside on the same vdev.
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
  1688
				 */
8241
5a60f16123ba 6328632 zpool offline is a bit too conservative
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7837
diff changeset
  1689
				needs_io = B_TRUE;
5a60f16123ba 6328632 zpool offline is a bit too conservative
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7837
diff changeset
  1690
			} else {
5a60f16123ba 6328632 zpool offline is a bit too conservative
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7837
diff changeset
  1691
				needs_io = vdev_dtl_contains(vd, DTL_PARTIAL,
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1692
				    phys_birth, 1);
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
  1693
			}
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
  1694
		}
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
  1695
	}
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
  1696
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
  1697
	if (needs_io && !zfs_no_scrub_io) {
12586
b118bbd65be9 6494473 ZFS needs a way to slow down resilvering
George Wilson <George.Wilson@Sun.COM>
parents: 12470
diff changeset
  1698
		vdev_t *rvd = spa->spa_root_vdev;
b118bbd65be9 6494473 ZFS needs a way to slow down resilvering
George Wilson <George.Wilson@Sun.COM>
parents: 12470
diff changeset
  1699
		uint64_t maxinflight = rvd->vdev_children * zfs_top_maxinflight;
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
  1700
		void *data = zio_data_buf_alloc(size);
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
  1701
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
  1702
		mutex_enter(&spa->spa_scrub_lock);
12586
b118bbd65be9 6494473 ZFS needs a way to slow down resilvering
George Wilson <George.Wilson@Sun.COM>
parents: 12470
diff changeset
  1703
		while (spa->spa_scrub_inflight >= maxinflight)
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
  1704
			cv_wait(&spa->spa_scrub_io_cv, &spa->spa_scrub_lock);
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
  1705
		spa->spa_scrub_inflight++;
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
  1706
		mutex_exit(&spa->spa_scrub_lock);
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
  1707
12586
b118bbd65be9 6494473 ZFS needs a way to slow down resilvering
George Wilson <George.Wilson@Sun.COM>
parents: 12470
diff changeset
  1708
		/*
b118bbd65be9 6494473 ZFS needs a way to slow down resilvering
George Wilson <George.Wilson@Sun.COM>
parents: 12470
diff changeset
  1709
		 * If we're seeing recent (zfs_scan_idle) "important" I/Os
b118bbd65be9 6494473 ZFS needs a way to slow down resilvering
George Wilson <George.Wilson@Sun.COM>
parents: 12470
diff changeset
  1710
		 * then throttle our workload to limit the impact of a scan.
b118bbd65be9 6494473 ZFS needs a way to slow down resilvering
George Wilson <George.Wilson@Sun.COM>
parents: 12470
diff changeset
  1711
		 */
b118bbd65be9 6494473 ZFS needs a way to slow down resilvering
George Wilson <George.Wilson@Sun.COM>
parents: 12470
diff changeset
  1712
		if (ddi_get_lbolt64() - spa->spa_last_io <= zfs_scan_idle)
b118bbd65be9 6494473 ZFS needs a way to slow down resilvering
George Wilson <George.Wilson@Sun.COM>
parents: 12470
diff changeset
  1713
			delay(scan_delay);
b118bbd65be9 6494473 ZFS needs a way to slow down resilvering
George Wilson <George.Wilson@Sun.COM>
parents: 12470
diff changeset
  1714
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
  1715
		zio_nowait(zio_read(NULL, spa, bp, data, size,
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1716
		    dsl_scan_scrub_done, NULL, zio_priority,
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
  1717
		    zio_flags, zb));
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
  1718
	}
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
  1719
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
  1720
	/* do not relocate this block */
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
  1721
	return (0);
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
  1722
}
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
  1723
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
  1724
int
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1725
dsl_scan(dsl_pool_t *dp, pool_scan_func_t func)
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
  1726
{
9997
174d75a29a1c 6843235 zpool resilver stalls with spa_scrub_thread in a 3 way deadlock
George Wilson <George.Wilson@Sun.COM>
parents: 9701
diff changeset
  1727
	spa_t *spa = dp->dp_spa;
174d75a29a1c 6843235 zpool resilver stalls with spa_scrub_thread in a 3 way deadlock
George Wilson <George.Wilson@Sun.COM>
parents: 9701
diff changeset
  1728
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
  1729
	/*
10850
bb29ac73664d 6840704 osol_0906 PV guests sometimes hang at login prompt
George Wilson <George.Wilson@Sun.COM>
parents: 10801
diff changeset
  1730
	 * Purge all vdev caches and probe all devices.  We do this here
bb29ac73664d 6840704 osol_0906 PV guests sometimes hang at login prompt
George Wilson <George.Wilson@Sun.COM>
parents: 10801
diff changeset
  1731
	 * rather than in sync context because this requires a writer lock
bb29ac73664d 6840704 osol_0906 PV guests sometimes hang at login prompt
George Wilson <George.Wilson@Sun.COM>
parents: 10801
diff changeset
  1732
	 * on the spa_config lock, which we can't do from sync context.  The
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
  1733
	 * spa_scrub_reopen flag indicates that vdev_open() should not
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
  1734
	 * attempt to start another scrub.
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
  1735
	 */
10685
931790026ac6 6846163 ZFS continues to use faulted logzilla, bringing system to a crawl
George Wilson <George.Wilson@Sun.COM>
parents: 9997
diff changeset
  1736
	spa_vdev_state_enter(spa, SCL_NONE);
9997
174d75a29a1c 6843235 zpool resilver stalls with spa_scrub_thread in a 3 way deadlock
George Wilson <George.Wilson@Sun.COM>
parents: 9701
diff changeset
  1737
	spa->spa_scrub_reopen = B_TRUE;
174d75a29a1c 6843235 zpool resilver stalls with spa_scrub_thread in a 3 way deadlock
George Wilson <George.Wilson@Sun.COM>
parents: 9701
diff changeset
  1738
	vdev_reopen(spa->spa_root_vdev);
174d75a29a1c 6843235 zpool resilver stalls with spa_scrub_thread in a 3 way deadlock
George Wilson <George.Wilson@Sun.COM>
parents: 9701
diff changeset
  1739
	spa->spa_scrub_reopen = B_FALSE;
174d75a29a1c 6843235 zpool resilver stalls with spa_scrub_thread in a 3 way deadlock
George Wilson <George.Wilson@Sun.COM>
parents: 9701
diff changeset
  1740
	(void) spa_vdev_state_exit(spa, NULL, 0);
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
  1741
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1742
	return (dsl_sync_task_do(dp, dsl_scan_setup_check,
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12295
diff changeset
  1743
	    dsl_scan_setup_sync, dp->dp_scan, &func, 0));
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
diff changeset
  1744
}