usr/src/uts/common/fs/zfs/dsl_pool.c
author Richard Lowe <richlowe@richlowe.net>
Tue, 08 Nov 2011 17:01:06 -0500
changeset 13512 060607df0c9d
parent 13509 04570f5cbeca
child 13524 f0e12b33f77c
permissions -rw-r--r--
backout 1644/1645/1646/1647/1708: Breaks 'zfs snapshot', boot environments
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
     1
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
     2
 * CDDL HEADER START
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
     3
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
     4
 * The contents of this file are subject to the terms of the
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
     5
 * Common Development and Distribution License (the "License").
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
     6
 * You may not use this file except in compliance with the License.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
     7
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
     8
 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
     9
 * or http://www.opensolaris.org/os/licensing.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    10
 * See the License for the specific language governing permissions
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    11
 * and limitations under the License.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    12
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    13
 * When distributing Covered Code, include this CDDL HEADER in each
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    14
 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    15
 * If applicable, add the following below this CDDL HEADER, with the
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    16
 * fields enclosed by brackets "[]" replaced with your own identifying
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    17
 * information: Portions Copyright [yyyy] [name of copyright owner]
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    18
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    19
 * CDDL HEADER END
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    20
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    21
/*
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 11935
diff changeset
    22
 * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    23
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    24
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    25
#include <sys/dsl_pool.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    26
#include <sys/dsl_dataset.h>
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 11935
diff changeset
    27
#include <sys/dsl_prop.h>
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    28
#include <sys/dsl_dir.h>
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
    29
#include <sys/dsl_synctask.h>
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 11935
diff changeset
    30
#include <sys/dsl_scan.h>
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 11935
diff changeset
    31
#include <sys/dnode.h>
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    32
#include <sys/dmu_tx.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    33
#include <sys/dmu_objset.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    34
#include <sys/arc.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    35
#include <sys/zap.h>
3547
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 2856
diff changeset
    36
#include <sys/zio.h>
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    37
#include <sys/zfs_context.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    38
#include <sys/fs/zfs.h>
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6740
diff changeset
    39
#include <sys/zfs_znode.h>
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6740
diff changeset
    40
#include <sys/spa_impl.h>
12470
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
    41
#include <sys/dsl_deadlist.h>
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    42
6245
1a2a7cfb9f26 6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents: 5642
diff changeset
    43
int zfs_no_write_throttle = 0;
7468
23915842aa09 6687412 zfs stuck issuing small txg
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 7184
diff changeset
    44
int zfs_write_limit_shift = 3;			/* 1/8th of physical memory */
12586
b118bbd65be9 6494473 ZFS needs a way to slow down resilvering
George Wilson <George.Wilson@Sun.COM>
parents: 12470
diff changeset
    45
int zfs_txg_synctime_ms = 1000;		/* target millisecs to sync a txg */
7468
23915842aa09 6687412 zfs stuck issuing small txg
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 7184
diff changeset
    46
23915842aa09 6687412 zfs stuck issuing small txg
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 7184
diff changeset
    47
uint64_t zfs_write_limit_min = 32 << 20;	/* min write limit is 32MB */
23915842aa09 6687412 zfs stuck issuing small txg
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 7184
diff changeset
    48
uint64_t zfs_write_limit_max = 0;		/* max data payload per txg */
23915842aa09 6687412 zfs stuck issuing small txg
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 7184
diff changeset
    49
uint64_t zfs_write_limit_inflated = 0;
6245
1a2a7cfb9f26 6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents: 5642
diff changeset
    50
uint64_t zfs_write_limit_override = 0;
1a2a7cfb9f26 6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents: 5642
diff changeset
    51
7468
23915842aa09 6687412 zfs stuck issuing small txg
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 7184
diff changeset
    52
kmutex_t zfs_write_limit_lock;
23915842aa09 6687412 zfs stuck issuing small txg
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 7184
diff changeset
    53
23915842aa09 6687412 zfs stuck issuing small txg
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 7184
diff changeset
    54
static pgcnt_t old_physmem = 0;
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6740
diff changeset
    55
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 11935
diff changeset
    56
int
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6740
diff changeset
    57
dsl_pool_open_special_dir(dsl_pool_t *dp, const char *name, dsl_dir_t **ddp)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    58
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    59
	uint64_t obj;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    60
	int err;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    61
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    62
	err = zap_lookup(dp->dp_meta_objset,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    63
	    dp->dp_root_dir->dd_phys->dd_child_dir_zapobj,
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6740
diff changeset
    64
	    name, sizeof (obj), 1, &obj);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
    65
	if (err)
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
    66
		return (err);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    67
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6740
diff changeset
    68
	return (dsl_dir_open_obj(dp, obj, name, dp, ddp));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    69
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    70
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    71
static dsl_pool_t *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    72
dsl_pool_open_impl(spa_t *spa, uint64_t txg)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    73
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    74
	dsl_pool_t *dp;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    75
	blkptr_t *bp = spa_get_rootblkptr(spa);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    76
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    77
	dp = kmem_zalloc(sizeof (dsl_pool_t), KM_SLEEP);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    78
	dp->dp_spa = spa;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    79
	dp->dp_meta_rootbp = *bp;
2856
6f4d5ee1906a 6463348 ZFS code could be more portable
nd150628
parents: 2467
diff changeset
    80
	rw_init(&dp->dp_config_rwlock, NULL, RW_DEFAULT, NULL);
6245
1a2a7cfb9f26 6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents: 5642
diff changeset
    81
	dp->dp_write_limit = zfs_write_limit_min;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    82
	txg_init(dp, txg);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    83
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    84
	txg_list_create(&dp->dp_dirty_datasets,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    85
	    offsetof(dsl_dataset_t, ds_dirty_link));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    86
	txg_list_create(&dp->dp_dirty_dirs,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    87
	    offsetof(dsl_dir_t, dd_dirty_link));
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
    88
	txg_list_create(&dp->dp_sync_tasks,
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
    89
	    offsetof(dsl_sync_task_group_t, dstg_node));
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 3897
diff changeset
    90
	list_create(&dp->dp_synced_datasets, sizeof (dsl_dataset_t),
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    91
	    offsetof(dsl_dataset_t, ds_synced_link));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    92
6245
1a2a7cfb9f26 6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents: 5642
diff changeset
    93
	mutex_init(&dp->dp_lock, NULL, MUTEX_DEFAULT, NULL);
1a2a7cfb9f26 6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents: 5642
diff changeset
    94
9321
dca349c475c1 6591646 Hang while trying to enter a txg while holding a txg open
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 9008
diff changeset
    95
	dp->dp_vnrele_taskq = taskq_create("zfs_vn_rele_taskq", 1, minclsyspri,
dca349c475c1 6591646 Hang while trying to enter a txg while holding a txg open
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 9008
diff changeset
    96
	    1, 4, 0);
dca349c475c1 6591646 Hang while trying to enter a txg while holding a txg open
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 9008
diff changeset
    97
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    98
	return (dp);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    99
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   100
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
   101
int
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
   102
dsl_pool_open(spa_t *spa, uint64_t txg, dsl_pool_t **dpp)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   103
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   104
	int err;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   105
	dsl_pool_t *dp = dsl_pool_open_impl(spa, txg);
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6740
diff changeset
   106
	dsl_dir_t *dd;
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6740
diff changeset
   107
	dsl_dataset_t *ds;
12470
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
   108
	uint64_t obj;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   109
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6740
diff changeset
   110
	rw_enter(&dp->dp_config_rwlock, RW_WRITER);
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9396
diff changeset
   111
	err = dmu_objset_open_impl(spa, NULL, &dp->dp_meta_rootbp,
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9396
diff changeset
   112
	    &dp->dp_meta_objset);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
   113
	if (err)
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
   114
		goto out;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
   115
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   116
	err = zap_lookup(dp->dp_meta_objset, DMU_POOL_DIRECTORY_OBJECT,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   117
	    DMU_POOL_ROOT_DATASET, sizeof (uint64_t), 1,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   118
	    &dp->dp_root_dir_obj);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
   119
	if (err)
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
   120
		goto out;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
   121
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
   122
	err = dsl_dir_open_obj(dp, dp->dp_root_dir_obj,
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
   123
	    NULL, dp, &dp->dp_root_dir);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
   124
	if (err)
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
   125
		goto out;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   126
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6740
diff changeset
   127
	err = dsl_pool_open_special_dir(dp, MOS_DIR_NAME, &dp->dp_mos_dir);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
   128
	if (err)
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
   129
		goto out;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
   130
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6740
diff changeset
   131
	if (spa_version(spa) >= SPA_VERSION_ORIGIN) {
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6740
diff changeset
   132
		err = dsl_pool_open_special_dir(dp, ORIGIN_DIR_NAME, &dd);
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6740
diff changeset
   133
		if (err)
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6740
diff changeset
   134
			goto out;
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6740
diff changeset
   135
		err = dsl_dataset_hold_obj(dp, dd->dd_phys->dd_head_dataset_obj,
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6740
diff changeset
   136
		    FTAG, &ds);
9008
2bf64246f8ee 6809347 looping in dnode_special_close() at an error path of spa_tryimport()
Lin Ling <Lin.Ling@Sun.COM>
parents: 7837
diff changeset
   137
		if (err == 0) {
2bf64246f8ee 6809347 looping in dnode_special_close() at an error path of spa_tryimport()
Lin Ling <Lin.Ling@Sun.COM>
parents: 7837
diff changeset
   138
			err = dsl_dataset_hold_obj(dp,
2bf64246f8ee 6809347 looping in dnode_special_close() at an error path of spa_tryimport()
Lin Ling <Lin.Ling@Sun.COM>
parents: 7837
diff changeset
   139
			    ds->ds_phys->ds_prev_snap_obj, dp,
2bf64246f8ee 6809347 looping in dnode_special_close() at an error path of spa_tryimport()
Lin Ling <Lin.Ling@Sun.COM>
parents: 7837
diff changeset
   140
			    &dp->dp_origin_snap);
2bf64246f8ee 6809347 looping in dnode_special_close() at an error path of spa_tryimport()
Lin Ling <Lin.Ling@Sun.COM>
parents: 7837
diff changeset
   141
			dsl_dataset_rele(ds, FTAG);
2bf64246f8ee 6809347 looping in dnode_special_close() at an error path of spa_tryimport()
Lin Ling <Lin.Ling@Sun.COM>
parents: 7837
diff changeset
   142
		}
2bf64246f8ee 6809347 looping in dnode_special_close() at an error path of spa_tryimport()
Lin Ling <Lin.Ling@Sun.COM>
parents: 7837
diff changeset
   143
		dsl_dir_close(dd, dp);
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6740
diff changeset
   144
		if (err)
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6740
diff changeset
   145
			goto out;
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6740
diff changeset
   146
	}
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6740
diff changeset
   147
12470
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
   148
	if (spa_version(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
   149
		err = dsl_pool_open_special_dir(dp, FREE_DIR_NAME,
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
   150
		    &dp->dp_free_dir);
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
   151
		if (err)
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
   152
			goto out;
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
   153
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
   154
		err = zap_lookup(dp->dp_meta_objset, DMU_POOL_DIRECTORY_OBJECT,
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
   155
		    DMU_POOL_FREE_BPOBJ, sizeof (uint64_t), 1, &obj);
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
   156
		if (err)
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
   157
			goto out;
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
   158
		VERIFY3U(0, ==, bpobj_open(&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
   159
		    dp->dp_meta_objset, obj));
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
   160
	}
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
   161
10342
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
   162
	err = zap_lookup(dp->dp_meta_objset, DMU_POOL_DIRECTORY_OBJECT,
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
   163
	    DMU_POOL_TMP_USERREFS, sizeof (uint64_t), 1,
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
   164
	    &dp->dp_tmp_userrefs_obj);
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
   165
	if (err == ENOENT)
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
   166
		err = 0;
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
   167
	if (err)
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
   168
		goto out;
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
   169
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 11935
diff changeset
   170
	err = dsl_scan_init(dp, txg);
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6740
diff changeset
   171
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
   172
out:
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   173
	rw_exit(&dp->dp_config_rwlock);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
   174
	if (err)
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
   175
		dsl_pool_close(dp);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
   176
	else
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
   177
		*dpp = dp;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   178
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
   179
	return (err);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   180
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   181
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   182
void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   183
dsl_pool_close(dsl_pool_t *dp)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   184
{
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6740
diff changeset
   185
	/* drop our references from dsl_pool_open() */
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6740
diff changeset
   186
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6740
diff changeset
   187
	/*
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6740
diff changeset
   188
	 * Since we held the origin_snap from "syncing" context (which
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6740
diff changeset
   189
	 * includes pool-opening context), it actually only got a "ref"
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6740
diff changeset
   190
	 * and not a hold, so just drop that here.
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6740
diff changeset
   191
	 */
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6740
diff changeset
   192
	if (dp->dp_origin_snap)
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6740
diff changeset
   193
		dsl_dataset_drop_ref(dp->dp_origin_snap, dp);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
   194
	if (dp->dp_mos_dir)
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
   195
		dsl_dir_close(dp->dp_mos_dir, dp);
12470
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
   196
	if (dp->dp_free_dir)
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
   197
		dsl_dir_close(dp->dp_free_dir, dp);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
   198
	if (dp->dp_root_dir)
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
   199
		dsl_dir_close(dp->dp_root_dir, dp);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   200
12470
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
   201
	bpobj_close(&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
   202
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   203
	/* undo the dmu_objset_open_impl(mos) from dsl_pool_open() */
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
   204
	if (dp->dp_meta_objset)
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9396
diff changeset
   205
		dmu_objset_evict(dp->dp_meta_objset);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   206
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   207
	txg_list_destroy(&dp->dp_dirty_datasets);
11814
09d130965476 6505339 dsl_pool_close() needs to call txg_list_destroy(&dp->dp_sync_tasks) to be nice
Chris Kirby <Chris.Kirby@sun.com>
parents: 11614
diff changeset
   208
	txg_list_destroy(&dp->dp_sync_tasks);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   209
	txg_list_destroy(&dp->dp_dirty_dirs);
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 3897
diff changeset
   210
	list_destroy(&dp->dp_synced_datasets);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   211
5642
504c84876fda 6513209 Destroying pools under stress caused a hang in arc_flush
maybee
parents: 5367
diff changeset
   212
	arc_flush(dp->dp_spa);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   213
	txg_fini(dp);
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 11935
diff changeset
   214
	dsl_scan_fini(dp);
2856
6f4d5ee1906a 6463348 ZFS code could be more portable
nd150628
parents: 2467
diff changeset
   215
	rw_destroy(&dp->dp_config_rwlock);
6245
1a2a7cfb9f26 6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents: 5642
diff changeset
   216
	mutex_destroy(&dp->dp_lock);
9321
dca349c475c1 6591646 Hang while trying to enter a txg while holding a txg open
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 9008
diff changeset
   217
	taskq_destroy(dp->dp_vnrele_taskq);
7837
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7468
diff changeset
   218
	if (dp->dp_blkstats)
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7468
diff changeset
   219
		kmem_free(dp->dp_blkstats, sizeof (zfs_all_blkstats_t));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   220
	kmem_free(dp, sizeof (dsl_pool_t));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   221
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   222
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   223
dsl_pool_t *
7184
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
   224
dsl_pool_create(spa_t *spa, nvlist_t *zplprops, uint64_t txg)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   225
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   226
	int err;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   227
	dsl_pool_t *dp = dsl_pool_open_impl(spa, txg);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   228
	dmu_tx_t *tx = dmu_tx_create_assigned(dp, txg);
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9396
diff changeset
   229
	objset_t *os;
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6740
diff changeset
   230
	dsl_dataset_t *ds;
12470
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
   231
	uint64_t obj;
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6740
diff changeset
   232
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6740
diff changeset
   233
	/* create and open the MOS (meta-objset) */
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9396
diff changeset
   234
	dp->dp_meta_objset = dmu_objset_create_impl(spa,
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9396
diff changeset
   235
	    NULL, &dp->dp_meta_rootbp, DMU_OST_META, tx);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   236
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   237
	/* create the pool directory */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   238
	err = zap_create_claim(dp->dp_meta_objset, DMU_POOL_DIRECTORY_OBJECT,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   239
	    DMU_OT_OBJECT_DIRECTORY, DMU_OT_NONE, 0, tx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   240
	ASSERT3U(err, ==, 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   241
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 11935
diff changeset
   242
	/* Initialize scan structures */
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 11935
diff changeset
   243
	VERIFY3U(0, ==, dsl_scan_init(dp, txg));
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 11935
diff changeset
   244
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   245
	/* create and open the root dir */
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6740
diff changeset
   246
	dp->dp_root_dir_obj = dsl_dir_create_sync(dp, NULL, NULL, tx);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
   247
	VERIFY(0 == dsl_dir_open_obj(dp, dp->dp_root_dir_obj,
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
   248
	    NULL, dp, &dp->dp_root_dir));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   249
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   250
	/* create and open the meta-objset dir */
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6740
diff changeset
   251
	(void) dsl_dir_create_sync(dp, dp->dp_root_dir, MOS_DIR_NAME, tx);
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6740
diff changeset
   252
	VERIFY(0 == dsl_pool_open_special_dir(dp,
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6740
diff changeset
   253
	    MOS_DIR_NAME, &dp->dp_mos_dir));
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6740
diff changeset
   254
12470
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
   255
	if (spa_version(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
   256
		/* create and open the free dir */
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
   257
		(void) dsl_dir_create_sync(dp, dp->dp_root_dir,
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
   258
		    FREE_DIR_NAME, tx);
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
   259
		VERIFY(0 == dsl_pool_open_special_dir(dp,
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
   260
		    FREE_DIR_NAME, &dp->dp_free_dir));
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
   261
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
   262
		/* create and open the free_bplist */
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
   263
		obj = bpobj_alloc(dp->dp_meta_objset, SPA_MAXBLOCKSIZE, tx);
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
   264
		VERIFY(zap_add(dp->dp_meta_objset, DMU_POOL_DIRECTORY_OBJECT,
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
   265
		    DMU_POOL_FREE_BPOBJ, sizeof (uint64_t), 1, &obj, tx) == 0);
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
   266
		VERIFY3U(0, ==, bpobj_open(&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
   267
		    dp->dp_meta_objset, obj));
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
   268
	}
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
   269
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6740
diff changeset
   270
	if (spa_version(spa) >= SPA_VERSION_DSL_SCRUB)
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6740
diff changeset
   271
		dsl_pool_create_origin(dp, tx);
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6740
diff changeset
   272
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6740
diff changeset
   273
	/* create the root dataset */
12470
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
   274
	obj = dsl_dataset_create_sync_dd(dp->dp_root_dir, NULL, 0, tx);
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6740
diff changeset
   275
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6740
diff changeset
   276
	/* create the root objset */
12470
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
   277
	VERIFY(0 == dsl_dataset_hold_obj(dp, obj, FTAG, &ds));
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9396
diff changeset
   278
	os = dmu_objset_create_impl(dp->dp_spa, ds,
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6740
diff changeset
   279
	    dsl_dataset_get_blkptr(ds), DMU_OST_ZFS, tx);
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6740
diff changeset
   280
#ifdef _KERNEL
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9396
diff changeset
   281
	zfs_create_fs(os, kcred, zplprops, tx);
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6740
diff changeset
   282
#endif
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6740
diff changeset
   283
	dsl_dataset_rele(ds, FTAG);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   284
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   285
	dmu_tx_commit(tx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   286
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   287
	return (dp);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   288
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   289
12470
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
   290
static int
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
   291
deadlist_enqueue_cb(void *arg, const blkptr_t *bp, dmu_tx_t *tx)
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
   292
{
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
   293
	dsl_deadlist_t *dl = arg;
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
   294
	dsl_deadlist_insert(dl, bp, tx);
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
   295
	return (0);
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
   296
}
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
   297
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   298
void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   299
dsl_pool_sync(dsl_pool_t *dp, uint64_t txg)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   300
{
3547
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 2856
diff changeset
   301
	zio_t *zio;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   302
	dmu_tx_t *tx;
3547
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 2856
diff changeset
   303
	dsl_dir_t *dd;
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 2856
diff changeset
   304
	dsl_dataset_t *ds;
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 2856
diff changeset
   305
	dsl_sync_task_group_t *dstg;
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9396
diff changeset
   306
	objset_t *mos = dp->dp_meta_objset;
7468
23915842aa09 6687412 zfs stuck issuing small txg
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 7184
diff changeset
   307
	hrtime_t start, write_time;
23915842aa09 6687412 zfs stuck issuing small txg
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 7184
diff changeset
   308
	uint64_t data_written;
3547
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 2856
diff changeset
   309
	int err;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   310
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 11935
diff changeset
   311
	/*
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 11935
diff changeset
   312
	 * We need to copy dp_space_towrite() before doing
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 11935
diff changeset
   313
	 * dsl_sync_task_group_sync(), because
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 11935
diff changeset
   314
	 * dsl_dataset_snapshot_reserve_space() will increase
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 11935
diff changeset
   315
	 * dp_space_towrite but not actually write anything.
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 11935
diff changeset
   316
	 */
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 11935
diff changeset
   317
	data_written = dp->dp_space_towrite[txg & TXG_MASK];
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 11935
diff changeset
   318
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   319
	tx = dmu_tx_create_assigned(dp, txg);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   320
7468
23915842aa09 6687412 zfs stuck issuing small txg
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 7184
diff changeset
   321
	dp->dp_read_overhead = 0;
9366
17553395a745 6817339 pool write throughput is improperly calculated
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 9321
diff changeset
   322
	start = gethrtime();
9396
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9366
diff changeset
   323
3547
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 2856
diff changeset
   324
	zio = zio_root(dp->dp_spa, NULL, NULL, ZIO_FLAG_MUSTSUCCEED);
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 2856
diff changeset
   325
	while (ds = txg_list_remove(&dp->dp_dirty_datasets, txg)) {
9396
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9366
diff changeset
   326
		/*
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9366
diff changeset
   327
		 * We must not sync any non-MOS datasets twice, because
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9366
diff changeset
   328
		 * we may have taken a snapshot of them.  However, we
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9366
diff changeset
   329
		 * may sync newly-created datasets on pass 2.
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9366
diff changeset
   330
		 */
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9366
diff changeset
   331
		ASSERT(!list_link_active(&ds->ds_synced_link));
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9366
diff changeset
   332
		list_insert_tail(&dp->dp_synced_datasets, ds);
3547
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 2856
diff changeset
   333
		dsl_dataset_sync(ds, zio, tx);
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 2856
diff changeset
   334
	}
7468
23915842aa09 6687412 zfs stuck issuing small txg
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 7184
diff changeset
   335
	DTRACE_PROBE(pool_sync__1setup);
9396
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9366
diff changeset
   336
	err = zio_wait(zio);
7468
23915842aa09 6687412 zfs stuck issuing small txg
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 7184
diff changeset
   337
23915842aa09 6687412 zfs stuck issuing small txg
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 7184
diff changeset
   338
	write_time = gethrtime() - start;
3547
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 2856
diff changeset
   339
	ASSERT(err == 0);
7468
23915842aa09 6687412 zfs stuck issuing small txg
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 7184
diff changeset
   340
	DTRACE_PROBE(pool_sync__2rootzio);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   341
9396
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9366
diff changeset
   342
	for (ds = list_head(&dp->dp_synced_datasets); ds;
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9366
diff changeset
   343
	    ds = list_next(&dp->dp_synced_datasets, ds))
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11814
diff changeset
   344
		dmu_objset_do_userquota_updates(ds->ds_objset, tx);
9396
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9366
diff changeset
   345
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9366
diff changeset
   346
	/*
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9366
diff changeset
   347
	 * Sync the datasets again to push out the changes due to
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 11935
diff changeset
   348
	 * userspace updates.  This must be done before we process the
9396
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9366
diff changeset
   349
	 * sync tasks, because that could cause a snapshot of a dataset
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9366
diff changeset
   350
	 * whose ds_bp will be rewritten when we do this 2nd sync.
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9366
diff changeset
   351
	 */
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9366
diff changeset
   352
	zio = zio_root(dp->dp_spa, NULL, NULL, ZIO_FLAG_MUSTSUCCEED);
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9366
diff changeset
   353
	while (ds = txg_list_remove(&dp->dp_dirty_datasets, txg)) {
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9366
diff changeset
   354
		ASSERT(list_link_active(&ds->ds_synced_link));
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9366
diff changeset
   355
		dmu_buf_rele(ds->ds_dbuf, ds);
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9366
diff changeset
   356
		dsl_dataset_sync(ds, zio, tx);
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9366
diff changeset
   357
	}
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9366
diff changeset
   358
	err = zio_wait(zio);
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9366
diff changeset
   359
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10801
diff changeset
   360
	/*
12470
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
   361
	 * Move dead blocks from the pending deadlist to the on-disk
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
   362
	 * deadlist.
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10801
diff changeset
   363
	 */
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10801
diff changeset
   364
	for (ds = list_head(&dp->dp_synced_datasets); ds;
12470
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
   365
	    ds = list_next(&dp->dp_synced_datasets, ds)) {
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
   366
		bplist_iterate(&ds->ds_pending_deadlist,
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
   367
		    deadlist_enqueue_cb, &ds->ds_deadlist, tx);
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
   368
	}
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10801
diff changeset
   369
9396
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9366
diff changeset
   370
	while (dstg = txg_list_remove(&dp->dp_sync_tasks, txg)) {
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9366
diff changeset
   371
		/*
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9366
diff changeset
   372
		 * No more sync tasks should have been added while we
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9366
diff changeset
   373
		 * were syncing.
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9366
diff changeset
   374
		 */
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9366
diff changeset
   375
		ASSERT(spa_sync_pass(dp->dp_spa) == 1);
3547
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 2856
diff changeset
   376
		dsl_sync_task_group_sync(dstg, tx);
9396
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9366
diff changeset
   377
	}
7468
23915842aa09 6687412 zfs stuck issuing small txg
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 7184
diff changeset
   378
	DTRACE_PROBE(pool_sync__3task);
23915842aa09 6687412 zfs stuck issuing small txg
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 7184
diff changeset
   379
23915842aa09 6687412 zfs stuck issuing small txg
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 7184
diff changeset
   380
	start = gethrtime();
3547
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 2856
diff changeset
   381
	while (dd = txg_list_remove(&dp->dp_dirty_dirs, txg))
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 2856
diff changeset
   382
		dsl_dir_sync(dd, tx);
7468
23915842aa09 6687412 zfs stuck issuing small txg
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 7184
diff changeset
   383
	write_time += gethrtime() - start;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   384
7468
23915842aa09 6687412 zfs stuck issuing small txg
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 7184
diff changeset
   385
	start = gethrtime();
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9396
diff changeset
   386
	if (list_head(&mos->os_dirty_dnodes[txg & TXG_MASK]) != NULL ||
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9396
diff changeset
   387
	    list_head(&mos->os_free_dnodes[txg & TXG_MASK]) != NULL) {
3547
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 2856
diff changeset
   388
		zio = zio_root(dp->dp_spa, NULL, NULL, ZIO_FLAG_MUSTSUCCEED);
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9396
diff changeset
   389
		dmu_objset_sync(mos, zio, tx);
3547
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 2856
diff changeset
   390
		err = zio_wait(zio);
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 2856
diff changeset
   391
		ASSERT(err == 0);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   392
		dprintf_bp(&dp->dp_meta_rootbp, "meta objset rootbp is %s", "");
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   393
		spa_set_rootblkptr(dp->dp_spa, &dp->dp_meta_rootbp);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   394
	}
7468
23915842aa09 6687412 zfs stuck issuing small txg
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 7184
diff changeset
   395
	write_time += gethrtime() - start;
23915842aa09 6687412 zfs stuck issuing small txg
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 7184
diff changeset
   396
	DTRACE_PROBE2(pool_sync__4io, hrtime_t, write_time,
23915842aa09 6687412 zfs stuck issuing small txg
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 7184
diff changeset
   397
	    hrtime_t, dp->dp_read_overhead);
23915842aa09 6687412 zfs stuck issuing small txg
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 7184
diff changeset
   398
	write_time -= dp->dp_read_overhead;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   399
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   400
	dmu_tx_commit(tx);
7468
23915842aa09 6687412 zfs stuck issuing small txg
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 7184
diff changeset
   401
23915842aa09 6687412 zfs stuck issuing small txg
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 7184
diff changeset
   402
	dp->dp_space_towrite[txg & TXG_MASK] = 0;
23915842aa09 6687412 zfs stuck issuing small txg
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 7184
diff changeset
   403
	ASSERT(dp->dp_tempreserved[txg & TXG_MASK] == 0);
23915842aa09 6687412 zfs stuck issuing small txg
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 7184
diff changeset
   404
23915842aa09 6687412 zfs stuck issuing small txg
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 7184
diff changeset
   405
	/*
23915842aa09 6687412 zfs stuck issuing small txg
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 7184
diff changeset
   406
	 * If the write limit max has not been explicitly set, set it
23915842aa09 6687412 zfs stuck issuing small txg
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 7184
diff changeset
   407
	 * to a fraction of available physical memory (default 1/8th).
23915842aa09 6687412 zfs stuck issuing small txg
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 7184
diff changeset
   408
	 * Note that we must inflate the limit because the spa
23915842aa09 6687412 zfs stuck issuing small txg
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 7184
diff changeset
   409
	 * inflates write sizes to account for data replication.
23915842aa09 6687412 zfs stuck issuing small txg
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 7184
diff changeset
   410
	 * Check this each sync phase to catch changing memory size.
23915842aa09 6687412 zfs stuck issuing small txg
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 7184
diff changeset
   411
	 */
23915842aa09 6687412 zfs stuck issuing small txg
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 7184
diff changeset
   412
	if (physmem != old_physmem && zfs_write_limit_shift) {
23915842aa09 6687412 zfs stuck issuing small txg
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 7184
diff changeset
   413
		mutex_enter(&zfs_write_limit_lock);
23915842aa09 6687412 zfs stuck issuing small txg
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 7184
diff changeset
   414
		old_physmem = physmem;
23915842aa09 6687412 zfs stuck issuing small txg
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 7184
diff changeset
   415
		zfs_write_limit_max = ptob(physmem) >> zfs_write_limit_shift;
23915842aa09 6687412 zfs stuck issuing small txg
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 7184
diff changeset
   416
		zfs_write_limit_inflated = MAX(zfs_write_limit_min,
23915842aa09 6687412 zfs stuck issuing small txg
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 7184
diff changeset
   417
		    spa_get_asize(dp->dp_spa, zfs_write_limit_max));
23915842aa09 6687412 zfs stuck issuing small txg
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 7184
diff changeset
   418
		mutex_exit(&zfs_write_limit_lock);
23915842aa09 6687412 zfs stuck issuing small txg
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 7184
diff changeset
   419
	}
23915842aa09 6687412 zfs stuck issuing small txg
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 7184
diff changeset
   420
23915842aa09 6687412 zfs stuck issuing small txg
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 7184
diff changeset
   421
	/*
23915842aa09 6687412 zfs stuck issuing small txg
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 7184
diff changeset
   422
	 * Attempt to keep the sync time consistent by adjusting the
23915842aa09 6687412 zfs stuck issuing small txg
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 7184
diff changeset
   423
	 * amount of write traffic allowed into each transaction group.
23915842aa09 6687412 zfs stuck issuing small txg
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 7184
diff changeset
   424
	 * Weight the throughput calculation towards the current value:
23915842aa09 6687412 zfs stuck issuing small txg
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 7184
diff changeset
   425
	 * 	thru = 3/4 old_thru + 1/4 new_thru
11614
04f97eb93d43 6918925 txg sync lasts a fraction of zfs_txg_synctime
Lin Ling <Lin.Ling@Sun.COM>
parents: 11182
diff changeset
   426
	 *
04f97eb93d43 6918925 txg sync lasts a fraction of zfs_txg_synctime
Lin Ling <Lin.Ling@Sun.COM>
parents: 11182
diff changeset
   427
	 * Note: write_time is in nanosecs, so write_time/MICROSEC
04f97eb93d43 6918925 txg sync lasts a fraction of zfs_txg_synctime
Lin Ling <Lin.Ling@Sun.COM>
parents: 11182
diff changeset
   428
	 * yields millisecs
7468
23915842aa09 6687412 zfs stuck issuing small txg
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 7184
diff changeset
   429
	 */
23915842aa09 6687412 zfs stuck issuing small txg
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 7184
diff changeset
   430
	ASSERT(zfs_write_limit_min > 0);
11614
04f97eb93d43 6918925 txg sync lasts a fraction of zfs_txg_synctime
Lin Ling <Lin.Ling@Sun.COM>
parents: 11182
diff changeset
   431
	if (data_written > zfs_write_limit_min / 8 && write_time > MICROSEC) {
04f97eb93d43 6918925 txg sync lasts a fraction of zfs_txg_synctime
Lin Ling <Lin.Ling@Sun.COM>
parents: 11182
diff changeset
   432
		uint64_t throughput = data_written / (write_time / MICROSEC);
04f97eb93d43 6918925 txg sync lasts a fraction of zfs_txg_synctime
Lin Ling <Lin.Ling@Sun.COM>
parents: 11182
diff changeset
   433
7468
23915842aa09 6687412 zfs stuck issuing small txg
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 7184
diff changeset
   434
		if (dp->dp_throughput)
23915842aa09 6687412 zfs stuck issuing small txg
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 7184
diff changeset
   435
			dp->dp_throughput = throughput / 4 +
23915842aa09 6687412 zfs stuck issuing small txg
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 7184
diff changeset
   436
			    3 * dp->dp_throughput / 4;
23915842aa09 6687412 zfs stuck issuing small txg
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 7184
diff changeset
   437
		else
23915842aa09 6687412 zfs stuck issuing small txg
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 7184
diff changeset
   438
			dp->dp_throughput = throughput;
23915842aa09 6687412 zfs stuck issuing small txg
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 7184
diff changeset
   439
		dp->dp_write_limit = MIN(zfs_write_limit_inflated,
23915842aa09 6687412 zfs stuck issuing small txg
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 7184
diff changeset
   440
		    MAX(zfs_write_limit_min,
11614
04f97eb93d43 6918925 txg sync lasts a fraction of zfs_txg_synctime
Lin Ling <Lin.Ling@Sun.COM>
parents: 11182
diff changeset
   441
		    dp->dp_throughput * zfs_txg_synctime_ms));
7468
23915842aa09 6687412 zfs stuck issuing small txg
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 7184
diff changeset
   442
	}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   443
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   444
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   445
void
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10801
diff changeset
   446
dsl_pool_sync_done(dsl_pool_t *dp, uint64_t txg)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   447
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   448
	dsl_dataset_t *ds;
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10801
diff changeset
   449
	objset_t *os;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   450
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 3897
diff changeset
   451
	while (ds = list_head(&dp->dp_synced_datasets)) {
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 3897
diff changeset
   452
		list_remove(&dp->dp_synced_datasets, ds);
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10801
diff changeset
   453
		os = ds->ds_objset;
12699
36aebb51164a 6913010 assertion failed: error||lr->lr_length <= zp->z_blksz, file: ../../common/fs/zfs/zfs_vnops.c
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 12586
diff changeset
   454
		zil_clean(os->os_zil, txg);
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10801
diff changeset
   455
		ASSERT(!dmu_objset_is_dirty(os, txg));
3897
278bade789ba 6437750 panic: db->db_buf==0||arc_referenced(db->db_buf), file: dbuf.c,line:1539
maybee
parents: 3547
diff changeset
   456
		dmu_buf_rele(ds->ds_dbuf, ds);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   457
	}
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10801
diff changeset
   458
	ASSERT(!dmu_objset_is_dirty(dp->dp_meta_objset, txg));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   459
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   460
3547
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 2856
diff changeset
   461
/*
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 2856
diff changeset
   462
 * TRUE if the current thread is the tx_sync_thread or if we
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 2856
diff changeset
   463
 * are being called from SPA context during pool initialization.
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 2856
diff changeset
   464
 */
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   465
int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   466
dsl_pool_sync_context(dsl_pool_t *dp)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   467
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   468
	return (curthread == dp->dp_tx.tx_sync_thread ||
3547
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 2856
diff changeset
   469
	    spa_get_dsl(dp->dp_spa) == NULL);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   470
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   471
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   472
uint64_t
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   473
dsl_pool_adjustedsize(dsl_pool_t *dp, boolean_t netfree)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   474
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   475
	uint64_t space, resv;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   476
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   477
	/*
1775
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1544
diff changeset
   478
	 * Reserve about 1.6% (1/64), or at least 32MB, for allocation
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   479
	 * efficiency.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   480
	 * XXX The intent log is not accounted for, so it must fit
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   481
	 * within this slop.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   482
	 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   483
	 * If we're trying to assess whether it's OK to do a free,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   484
	 * cut the reservation in half to allow forward progress
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   485
	 * (e.g. make it possible to rm(1) files from a full pool).
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   486
	 */
10956
0c81acaaf614 6897693 deduplication can only go so far
George Wilson <George.Wilson@Sun.COM>
parents: 10951
diff changeset
   487
	space = spa_get_dspace(dp->dp_spa);
1775
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1544
diff changeset
   488
	resv = MAX(space >> 6, SPA_MINDEVSIZE >> 1);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   489
	if (netfree)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   490
		resv >>= 1;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   491
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   492
	return (space - resv);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   493
}
6245
1a2a7cfb9f26 6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents: 5642
diff changeset
   494
1a2a7cfb9f26 6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents: 5642
diff changeset
   495
int
1a2a7cfb9f26 6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents: 5642
diff changeset
   496
dsl_pool_tempreserve_space(dsl_pool_t *dp, uint64_t space, dmu_tx_t *tx)
1a2a7cfb9f26 6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents: 5642
diff changeset
   497
{
1a2a7cfb9f26 6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents: 5642
diff changeset
   498
	uint64_t reserved = 0;
1a2a7cfb9f26 6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents: 5642
diff changeset
   499
	uint64_t write_limit = (zfs_write_limit_override ?
1a2a7cfb9f26 6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents: 5642
diff changeset
   500
	    zfs_write_limit_override : dp->dp_write_limit);
1a2a7cfb9f26 6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents: 5642
diff changeset
   501
1a2a7cfb9f26 6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents: 5642
diff changeset
   502
	if (zfs_no_write_throttle) {
6643
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6245
diff changeset
   503
		atomic_add_64(&dp->dp_tempreserved[tx->tx_txg & TXG_MASK],
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6245
diff changeset
   504
		    space);
6245
1a2a7cfb9f26 6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents: 5642
diff changeset
   505
		return (0);
1a2a7cfb9f26 6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents: 5642
diff changeset
   506
	}
1a2a7cfb9f26 6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents: 5642
diff changeset
   507
1a2a7cfb9f26 6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents: 5642
diff changeset
   508
	/*
1a2a7cfb9f26 6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents: 5642
diff changeset
   509
	 * Check to see if we have exceeded the maximum allowed IO for
1a2a7cfb9f26 6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents: 5642
diff changeset
   510
	 * this transaction group.  We can do this without locks since
1a2a7cfb9f26 6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents: 5642
diff changeset
   511
	 * a little slop here is ok.  Note that we do the reserved check
1a2a7cfb9f26 6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents: 5642
diff changeset
   512
	 * with only half the requested reserve: this is because the
1a2a7cfb9f26 6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents: 5642
diff changeset
   513
	 * reserve requests are worst-case, and we really don't want to
1a2a7cfb9f26 6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents: 5642
diff changeset
   514
	 * throttle based off of worst-case estimates.
1a2a7cfb9f26 6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents: 5642
diff changeset
   515
	 */
1a2a7cfb9f26 6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents: 5642
diff changeset
   516
	if (write_limit > 0) {
1a2a7cfb9f26 6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents: 5642
diff changeset
   517
		reserved = dp->dp_space_towrite[tx->tx_txg & TXG_MASK]
1a2a7cfb9f26 6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents: 5642
diff changeset
   518
		    + dp->dp_tempreserved[tx->tx_txg & TXG_MASK] / 2;
1a2a7cfb9f26 6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents: 5642
diff changeset
   519
1a2a7cfb9f26 6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents: 5642
diff changeset
   520
		if (reserved && reserved > write_limit)
1a2a7cfb9f26 6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents: 5642
diff changeset
   521
			return (ERESTART);
1a2a7cfb9f26 6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents: 5642
diff changeset
   522
	}
1a2a7cfb9f26 6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents: 5642
diff changeset
   523
1a2a7cfb9f26 6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents: 5642
diff changeset
   524
	atomic_add_64(&dp->dp_tempreserved[tx->tx_txg & TXG_MASK], space);
1a2a7cfb9f26 6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents: 5642
diff changeset
   525
1a2a7cfb9f26 6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents: 5642
diff changeset
   526
	/*
1a2a7cfb9f26 6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents: 5642
diff changeset
   527
	 * If this transaction group is over 7/8ths capacity, delay
1a2a7cfb9f26 6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents: 5642
diff changeset
   528
	 * the caller 1 clock tick.  This will slow down the "fill"
1a2a7cfb9f26 6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents: 5642
diff changeset
   529
	 * rate until the sync process can catch up with us.
1a2a7cfb9f26 6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents: 5642
diff changeset
   530
	 */
6740
ca05a6828ae6 6707621 write throttle results in excessive delay
gw25295
parents: 6643
diff changeset
   531
	if (reserved && reserved > (write_limit - (write_limit >> 3)))
6245
1a2a7cfb9f26 6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents: 5642
diff changeset
   532
		txg_delay(dp, tx->tx_txg, 1);
1a2a7cfb9f26 6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents: 5642
diff changeset
   533
1a2a7cfb9f26 6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents: 5642
diff changeset
   534
	return (0);
1a2a7cfb9f26 6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents: 5642
diff changeset
   535
}
1a2a7cfb9f26 6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents: 5642
diff changeset
   536
1a2a7cfb9f26 6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents: 5642
diff changeset
   537
void
1a2a7cfb9f26 6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents: 5642
diff changeset
   538
dsl_pool_tempreserve_clear(dsl_pool_t *dp, int64_t space, dmu_tx_t *tx)
1a2a7cfb9f26 6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents: 5642
diff changeset
   539
{
1a2a7cfb9f26 6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents: 5642
diff changeset
   540
	ASSERT(dp->dp_tempreserved[tx->tx_txg & TXG_MASK] >= space);
1a2a7cfb9f26 6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents: 5642
diff changeset
   541
	atomic_add_64(&dp->dp_tempreserved[tx->tx_txg & TXG_MASK], -space);
1a2a7cfb9f26 6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents: 5642
diff changeset
   542
}
1a2a7cfb9f26 6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents: 5642
diff changeset
   543
1a2a7cfb9f26 6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents: 5642
diff changeset
   544
void
1a2a7cfb9f26 6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents: 5642
diff changeset
   545
dsl_pool_memory_pressure(dsl_pool_t *dp)
1a2a7cfb9f26 6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents: 5642
diff changeset
   546
{
1a2a7cfb9f26 6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents: 5642
diff changeset
   547
	uint64_t space_inuse = 0;
1a2a7cfb9f26 6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents: 5642
diff changeset
   548
	int i;
1a2a7cfb9f26 6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents: 5642
diff changeset
   549
1a2a7cfb9f26 6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents: 5642
diff changeset
   550
	if (dp->dp_write_limit == zfs_write_limit_min)
1a2a7cfb9f26 6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents: 5642
diff changeset
   551
		return;
1a2a7cfb9f26 6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents: 5642
diff changeset
   552
1a2a7cfb9f26 6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents: 5642
diff changeset
   553
	for (i = 0; i < TXG_SIZE; i++) {
1a2a7cfb9f26 6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents: 5642
diff changeset
   554
		space_inuse += dp->dp_space_towrite[i];
1a2a7cfb9f26 6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents: 5642
diff changeset
   555
		space_inuse += dp->dp_tempreserved[i];
1a2a7cfb9f26 6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents: 5642
diff changeset
   556
	}
1a2a7cfb9f26 6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents: 5642
diff changeset
   557
	dp->dp_write_limit = MAX(zfs_write_limit_min,
1a2a7cfb9f26 6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents: 5642
diff changeset
   558
	    MIN(dp->dp_write_limit, space_inuse / 4));
1a2a7cfb9f26 6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents: 5642
diff changeset
   559
}
1a2a7cfb9f26 6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents: 5642
diff changeset
   560
1a2a7cfb9f26 6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents: 5642
diff changeset
   561
void
1a2a7cfb9f26 6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents: 5642
diff changeset
   562
dsl_pool_willuse_space(dsl_pool_t *dp, int64_t space, dmu_tx_t *tx)
1a2a7cfb9f26 6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents: 5642
diff changeset
   563
{
1a2a7cfb9f26 6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents: 5642
diff changeset
   564
	if (space > 0) {
1a2a7cfb9f26 6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents: 5642
diff changeset
   565
		mutex_enter(&dp->dp_lock);
1a2a7cfb9f26 6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents: 5642
diff changeset
   566
		dp->dp_space_towrite[tx->tx_txg & TXG_MASK] += space;
1a2a7cfb9f26 6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents: 5642
diff changeset
   567
		mutex_exit(&dp->dp_lock);
1a2a7cfb9f26 6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents: 5642
diff changeset
   568
	}
1a2a7cfb9f26 6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents: 5642
diff changeset
   569
}
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6740
diff changeset
   570
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6740
diff changeset
   571
/* ARGSUSED */
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6740
diff changeset
   572
static int
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6740
diff changeset
   573
upgrade_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: 6740
diff changeset
   574
{
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6740
diff changeset
   575
	dmu_tx_t *tx = arg;
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6740
diff changeset
   576
	dsl_dataset_t *ds, *prev = NULL;
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6740
diff changeset
   577
	int err;
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6740
diff changeset
   578
	dsl_pool_t *dp = spa_get_dsl(spa);
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6740
diff changeset
   579
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6740
diff changeset
   580
	err = dsl_dataset_hold_obj(dp, dsobj, FTAG, &ds);
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6740
diff changeset
   581
	if (err)
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6740
diff changeset
   582
		return (err);
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6740
diff changeset
   583
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6740
diff changeset
   584
	while (ds->ds_phys->ds_prev_snap_obj != 0) {
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6740
diff changeset
   585
		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: 6740
diff changeset
   586
		    FTAG, &prev);
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6740
diff changeset
   587
		if (err) {
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6740
diff changeset
   588
			dsl_dataset_rele(ds, FTAG);
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6740
diff changeset
   589
			return (err);
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6740
diff changeset
   590
		}
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6740
diff changeset
   591
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6740
diff changeset
   592
		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: 6740
diff changeset
   593
			break;
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6740
diff changeset
   594
		dsl_dataset_rele(ds, FTAG);
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6740
diff changeset
   595
		ds = prev;
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6740
diff changeset
   596
		prev = NULL;
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6740
diff changeset
   597
	}
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6740
diff changeset
   598
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6740
diff changeset
   599
	if (prev == NULL) {
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6740
diff changeset
   600
		prev = dp->dp_origin_snap;
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6740
diff changeset
   601
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6740
diff changeset
   602
		/*
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6740
diff changeset
   603
		 * The $ORIGIN can't have any data, or the accounting
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6740
diff changeset
   604
		 * will be wrong.
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6740
diff changeset
   605
		 */
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6740
diff changeset
   606
		ASSERT(prev->ds_phys->ds_bp.blk_birth == 0);
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6740
diff changeset
   607
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6740
diff changeset
   608
		/* The origin doesn't get attached to itself */
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6740
diff changeset
   609
		if (ds->ds_object == prev->ds_object) {
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6740
diff changeset
   610
			dsl_dataset_rele(ds, FTAG);
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6740
diff changeset
   611
			return (0);
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6740
diff changeset
   612
		}
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6740
diff changeset
   613
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6740
diff changeset
   614
		dmu_buf_will_dirty(ds->ds_dbuf, tx);
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6740
diff changeset
   615
		ds->ds_phys->ds_prev_snap_obj = prev->ds_object;
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6740
diff changeset
   616
		ds->ds_phys->ds_prev_snap_txg = prev->ds_phys->ds_creation_txg;
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6740
diff changeset
   617
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6740
diff changeset
   618
		dmu_buf_will_dirty(ds->ds_dir->dd_dbuf, tx);
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6740
diff changeset
   619
		ds->ds_dir->dd_phys->dd_origin_obj = prev->ds_object;
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6740
diff changeset
   620
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6740
diff changeset
   621
		dmu_buf_will_dirty(prev->ds_dbuf, tx);
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6740
diff changeset
   622
		prev->ds_phys->ds_num_children++;
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6740
diff changeset
   623
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6740
diff changeset
   624
		if (ds->ds_phys->ds_next_snap_obj == 0) {
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6740
diff changeset
   625
			ASSERT(ds->ds_prev == NULL);
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6740
diff changeset
   626
			VERIFY(0 == dsl_dataset_hold_obj(dp,
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6740
diff changeset
   627
			    ds->ds_phys->ds_prev_snap_obj, ds, &ds->ds_prev));
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6740
diff changeset
   628
		}
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6740
diff changeset
   629
	}
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6740
diff changeset
   630
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6740
diff changeset
   631
	ASSERT(ds->ds_dir->dd_phys->dd_origin_obj == prev->ds_object);
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6740
diff changeset
   632
	ASSERT(ds->ds_phys->ds_prev_snap_obj == prev->ds_object);
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6740
diff changeset
   633
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6740
diff changeset
   634
	if (prev->ds_phys->ds_next_clones_obj == 0) {
10801
e0bf032e8673 6822816 assertion failed: zap_remove_int(ds_next_clones_obj) returns ENOENT
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10342
diff changeset
   635
		dmu_buf_will_dirty(prev->ds_dbuf, tx);
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6740
diff changeset
   636
		prev->ds_phys->ds_next_clones_obj =
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6740
diff changeset
   637
		    zap_create(dp->dp_meta_objset,
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6740
diff changeset
   638
		    DMU_OT_NEXT_CLONES, DMU_OT_NONE, 0, tx);
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6740
diff changeset
   639
	}
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6740
diff changeset
   640
	VERIFY(0 == zap_add_int(dp->dp_meta_objset,
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6740
diff changeset
   641
	    prev->ds_phys->ds_next_clones_obj, ds->ds_object, tx));
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6740
diff changeset
   642
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6740
diff changeset
   643
	dsl_dataset_rele(ds, FTAG);
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6740
diff changeset
   644
	if (prev != dp->dp_origin_snap)
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6740
diff changeset
   645
		dsl_dataset_rele(prev, FTAG);
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6740
diff changeset
   646
	return (0);
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6740
diff changeset
   647
}
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6740
diff changeset
   648
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6740
diff changeset
   649
void
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6740
diff changeset
   650
dsl_pool_upgrade_clones(dsl_pool_t *dp, dmu_tx_t *tx)
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6740
diff changeset
   651
{
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6740
diff changeset
   652
	ASSERT(dmu_tx_is_syncing(tx));
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6740
diff changeset
   653
	ASSERT(dp->dp_origin_snap != NULL);
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6740
diff changeset
   654
10801
e0bf032e8673 6822816 assertion failed: zap_remove_int(ds_next_clones_obj) returns ENOENT
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10342
diff changeset
   655
	VERIFY3U(0, ==, dmu_objset_find_spa(dp->dp_spa, NULL, upgrade_clones_cb,
e0bf032e8673 6822816 assertion failed: zap_remove_int(ds_next_clones_obj) returns ENOENT
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10342
diff changeset
   656
	    tx, DS_FIND_CHILDREN));
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6740
diff changeset
   657
}
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6740
diff changeset
   658
12470
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
   659
/* ARGSUSED */
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
   660
static int
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
   661
upgrade_dir_clones_cb(spa_t *spa, uint64_t dsobj, const char *dsname, void *arg)
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
   662
{
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
   663
	dmu_tx_t *tx = arg;
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
   664
	dsl_dataset_t *ds;
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
   665
	dsl_pool_t *dp = spa_get_dsl(spa);
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
   666
	objset_t *mos = dp->dp_meta_objset;
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
   667
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
   668
	VERIFY3U(0, ==, dsl_dataset_hold_obj(dp, dsobj, FTAG, &ds));
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
   669
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
   670
	if (ds->ds_dir->dd_phys->dd_origin_obj) {
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
   671
		dsl_dataset_t *origin;
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
   672
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
   673
		VERIFY3U(0, ==, dsl_dataset_hold_obj(dp,
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
   674
		    ds->ds_dir->dd_phys->dd_origin_obj, FTAG, &origin));
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
   675
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
   676
		if (origin->ds_dir->dd_phys->dd_clones == 0) {
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
   677
			dmu_buf_will_dirty(origin->ds_dir->dd_dbuf, tx);
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
   678
			origin->ds_dir->dd_phys->dd_clones = zap_create(mos,
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
   679
			    DMU_OT_DSL_CLONES, DMU_OT_NONE, 0, tx);
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
   680
		}
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
   681
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
   682
		VERIFY3U(0, ==, zap_add_int(dp->dp_meta_objset,
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
   683
		    origin->ds_dir->dd_phys->dd_clones, dsobj, tx));
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
   684
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
   685
		dsl_dataset_rele(origin, FTAG);
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
   686
	}
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
   687
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
   688
	dsl_dataset_rele(ds, FTAG);
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
   689
	return (0);
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
   690
}
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
   691
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
   692
void
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
   693
dsl_pool_upgrade_dir_clones(dsl_pool_t *dp, dmu_tx_t *tx)
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
   694
{
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
   695
	ASSERT(dmu_tx_is_syncing(tx));
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
   696
	uint64_t obj;
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
   697
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
   698
	(void) dsl_dir_create_sync(dp, dp->dp_root_dir, FREE_DIR_NAME, tx);
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
   699
	VERIFY(0 == dsl_pool_open_special_dir(dp,
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
   700
	    FREE_DIR_NAME, &dp->dp_free_dir));
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
   701
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
   702
	/*
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
   703
	 * We can't use bpobj_alloc(), because spa_version() still
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
   704
	 * returns the old version, and we need a new-version bpobj with
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
   705
	 * subobj support.  So call dmu_object_alloc() directly.
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
   706
	 */
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
   707
	obj = dmu_object_alloc(dp->dp_meta_objset, DMU_OT_BPOBJ,
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
   708
	    SPA_MAXBLOCKSIZE, DMU_OT_BPOBJ_HDR, sizeof (bpobj_phys_t), tx);
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
   709
	VERIFY3U(0, ==, zap_add(dp->dp_meta_objset, DMU_POOL_DIRECTORY_OBJECT,
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
   710
	    DMU_POOL_FREE_BPOBJ, sizeof (uint64_t), 1, &obj, tx));
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
   711
	VERIFY3U(0, ==, bpobj_open(&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
   712
	    dp->dp_meta_objset, obj));
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
   713
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
   714
	VERIFY3U(0, ==, dmu_objset_find_spa(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
   715
	    upgrade_dir_clones_cb, tx, DS_FIND_CHILDREN));
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
   716
}
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
   717
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6740
diff changeset
   718
void
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6740
diff changeset
   719
dsl_pool_create_origin(dsl_pool_t *dp, dmu_tx_t *tx)
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6740
diff changeset
   720
{
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6740
diff changeset
   721
	uint64_t dsobj;
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6740
diff changeset
   722
	dsl_dataset_t *ds;
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6740
diff changeset
   723
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6740
diff changeset
   724
	ASSERT(dmu_tx_is_syncing(tx));
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6740
diff changeset
   725
	ASSERT(dp->dp_origin_snap == NULL);
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6740
diff changeset
   726
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6740
diff changeset
   727
	/* create the origin dir, ds, & snap-ds */
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6740
diff changeset
   728
	rw_enter(&dp->dp_config_rwlock, RW_WRITER);
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6740
diff changeset
   729
	dsobj = dsl_dataset_create_sync(dp->dp_root_dir, ORIGIN_DIR_NAME,
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6740
diff changeset
   730
	    NULL, 0, kcred, tx);
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6740
diff changeset
   731
	VERIFY(0 == dsl_dataset_hold_obj(dp, dsobj, FTAG, &ds));
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 11935
diff changeset
   732
	dsl_dataset_snapshot_sync(ds, ORIGIN_DIR_NAME, tx);
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6740
diff changeset
   733
	VERIFY(0 == 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: 6740
diff changeset
   734
	    dp, &dp->dp_origin_snap));
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6740
diff changeset
   735
	dsl_dataset_rele(ds, FTAG);
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6740
diff changeset
   736
	rw_exit(&dp->dp_config_rwlock);
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6740
diff changeset
   737
}
9321
dca349c475c1 6591646 Hang while trying to enter a txg while holding a txg open
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 9008
diff changeset
   738
dca349c475c1 6591646 Hang while trying to enter a txg while holding a txg open
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 9008
diff changeset
   739
taskq_t *
dca349c475c1 6591646 Hang while trying to enter a txg while holding a txg open
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 9008
diff changeset
   740
dsl_pool_vnrele_taskq(dsl_pool_t *dp)
dca349c475c1 6591646 Hang while trying to enter a txg while holding a txg open
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 9008
diff changeset
   741
{
dca349c475c1 6591646 Hang while trying to enter a txg while holding a txg open
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 9008
diff changeset
   742
	return (dp->dp_vnrele_taskq);
dca349c475c1 6591646 Hang while trying to enter a txg while holding a txg open
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 9008
diff changeset
   743
}
10342
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
   744
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
   745
/*
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
   746
 * Walk through the pool-wide zap object of temporary snapshot user holds
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
   747
 * and release them.
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
   748
 */
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
   749
void
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
   750
dsl_pool_clean_tmp_userrefs(dsl_pool_t *dp)
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
   751
{
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
   752
	zap_attribute_t za;
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
   753
	zap_cursor_t zc;
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
   754
	objset_t *mos = dp->dp_meta_objset;
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
   755
	uint64_t zapobj = dp->dp_tmp_userrefs_obj;
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
   756
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
   757
	if (zapobj == 0)
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
   758
		return;
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
   759
	ASSERT(spa_version(dp->dp_spa) >= SPA_VERSION_USERREFS);
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
   760
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
   761
	for (zap_cursor_init(&zc, mos, zapobj);
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
   762
	    zap_cursor_retrieve(&zc, &za) == 0;
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
   763
	    zap_cursor_advance(&zc)) {
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
   764
		char *htag;
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
   765
		uint64_t dsobj;
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
   766
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
   767
		htag = strchr(za.za_name, '-');
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
   768
		*htag = '\0';
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
   769
		++htag;
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
   770
		dsobj = strtonum(za.za_name, NULL);
12798
f6c8601080b4 6938335 zfs send -R can still miss renamed snapshots
Chris Kirby <Chris.Kirby@oracle.com>
parents: 12699
diff changeset
   771
		(void) dsl_dataset_user_release_tmp(dp, dsobj, htag, B_FALSE);
10342
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
   772
	}
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
   773
	zap_cursor_fini(&zc);
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
   774
}
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
   775
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
   776
/*
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
   777
 * Create the pool-wide zap object for storing temporary snapshot holds.
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
   778
 */
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
   779
void
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
   780
dsl_pool_user_hold_create_obj(dsl_pool_t *dp, dmu_tx_t *tx)
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
   781
{
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
   782
	objset_t *mos = dp->dp_meta_objset;
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
   783
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
   784
	ASSERT(dp->dp_tmp_userrefs_obj == 0);
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
   785
	ASSERT(dmu_tx_is_syncing(tx));
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
   786
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
   787
	dp->dp_tmp_userrefs_obj = zap_create(mos, DMU_OT_USERREFS,
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
   788
	    DMU_OT_NONE, 0, tx);
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
   789
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
   790
	VERIFY(zap_add(mos, DMU_POOL_DIRECTORY_OBJECT, DMU_POOL_TMP_USERREFS,
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
   791
	    sizeof (uint64_t), 1, &dp->dp_tmp_userrefs_obj, tx) == 0);
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
   792
}
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
   793
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
   794
static int
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
   795
dsl_pool_user_hold_rele_impl(dsl_pool_t *dp, uint64_t dsobj,
10951
56fd5475e8fe 6896756 assertion failed: 0 == dsl_pool_user_hold(dp, ds->ds_object, htag, &now, tx)
Chris Kirby <Chris.Kirby@sun.com>
parents: 10922
diff changeset
   796
    const char *tag, uint64_t *now, dmu_tx_t *tx, boolean_t holding)
10342
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
   797
{
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
   798
	objset_t *mos = dp->dp_meta_objset;
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
   799
	uint64_t zapobj = dp->dp_tmp_userrefs_obj;
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
   800
	char *name;
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
   801
	int error;
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
   802
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
   803
	ASSERT(spa_version(dp->dp_spa) >= SPA_VERSION_USERREFS);
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
   804
	ASSERT(dmu_tx_is_syncing(tx));
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
   805
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
   806
	/*
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
   807
	 * If the pool was created prior to SPA_VERSION_USERREFS, the
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
   808
	 * zap object for temporary holds might not exist yet.
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
   809
	 */
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
   810
	if (zapobj == 0) {
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
   811
		if (holding) {
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
   812
			dsl_pool_user_hold_create_obj(dp, tx);
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
   813
			zapobj = dp->dp_tmp_userrefs_obj;
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
   814
		} else {
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
   815
			return (ENOENT);
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
   816
		}
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
   817
	}
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
   818
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
   819
	name = kmem_asprintf("%llx-%s", (u_longlong_t)dsobj, tag);
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
   820
	if (holding)
10951
56fd5475e8fe 6896756 assertion failed: 0 == dsl_pool_user_hold(dp, ds->ds_object, htag, &now, tx)
Chris Kirby <Chris.Kirby@sun.com>
parents: 10922
diff changeset
   821
		error = zap_add(mos, zapobj, name, 8, 1, now, tx);
10342
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
   822
	else
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
   823
		error = zap_remove(mos, zapobj, name, tx);
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
   824
	strfree(name);
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
   825
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
   826
	return (error);
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
   827
}
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
   828
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
   829
/*
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
   830
 * Add a temporary hold for the given dataset object and tag.
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
   831
 */
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
   832
int
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
   833
dsl_pool_user_hold(dsl_pool_t *dp, uint64_t dsobj, const char *tag,
10951
56fd5475e8fe 6896756 assertion failed: 0 == dsl_pool_user_hold(dp, ds->ds_object, htag, &now, tx)
Chris Kirby <Chris.Kirby@sun.com>
parents: 10922
diff changeset
   834
    uint64_t *now, dmu_tx_t *tx)
10342
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
   835
{
10951
56fd5475e8fe 6896756 assertion failed: 0 == dsl_pool_user_hold(dp, ds->ds_object, htag, &now, tx)
Chris Kirby <Chris.Kirby@sun.com>
parents: 10922
diff changeset
   836
	return (dsl_pool_user_hold_rele_impl(dp, dsobj, tag, now, tx, B_TRUE));
10342
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
   837
}
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
   838
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
   839
/*
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
   840
 * Release a temporary hold for the given dataset object and tag.
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
   841
 */
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
   842
int
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
   843
dsl_pool_user_release(dsl_pool_t *dp, uint64_t dsobj, const char *tag,
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
   844
    dmu_tx_t *tx)
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
   845
{
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
   846
	return (dsl_pool_user_hold_rele_impl(dp, dsobj, tag, NULL,
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
   847
	    tx, B_FALSE));
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
   848
}