xref: /illumos-gate/usr/src/uts/common/fs/zfs/sys/dsl_synctask.h (revision f78cdc34af236a6199dd9e21376f4a46348c0d56)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
23  * Copyright (c) 2012, 2017 by Delphix. All rights reserved.
24  */
25 
26 #ifndef	_SYS_DSL_SYNCTASK_H
27 #define	_SYS_DSL_SYNCTASK_H
28 
29 #include <sys/txg.h>
30 #include <sys/zfs_context.h>
31 
32 #ifdef	__cplusplus
33 extern "C" {
34 #endif
35 
36 struct dsl_pool;
37 
38 typedef int (dsl_checkfunc_t)(void *, dmu_tx_t *);
39 typedef void (dsl_syncfunc_t)(void *, dmu_tx_t *);
40 
41 typedef enum zfs_space_check {
42 	/*
43 	 * Normal space check: if there is less than 3.2% free space,
44 	 * the operation will fail.  Operations which are logically
45 	 * creating things should use this (e.g. "zfs create", "zfs snapshot").
46 	 * User writes (via the ZPL / ZVOL) also fail at this point.
47 	 */
48 	ZFS_SPACE_CHECK_NORMAL,
49 
50 	/*
51 	 * Space check allows use of half the slop space.  If there
52 	 * is less than 1.6% free space, the operation will fail.  Most
53 	 * operations should use this (e.g. "zfs set", "zfs rename"),
54 	 * because we want them to succeed even after user writes are failing,
55 	 * so that they can be used as part of the space recovery process.
56 	 */
57 	ZFS_SPACE_CHECK_RESERVED,
58 
59 	/*
60 	 * Space check allows use of three quarters of the slop space.
61 	 * If there is less than 0.8% free space, the operation will
62 	 * fail.
63 	 */
64 	ZFS_SPACE_CHECK_EXTRA_RESERVED,
65 
66 	/*
67 	 * In all cases "zfs destroy" is expected to result in an net
68 	 * reduction of space, except one. When the pool has a
69 	 * checkpoint, space freed by "zfs destroy" will not actually
70 	 * free anything internally. Thus, it starts failing after
71 	 * three quarters of the slop space is exceeded.
72 	 */
73 	ZFS_SPACE_CHECK_DESTROY = ZFS_SPACE_CHECK_EXTRA_RESERVED,
74 
75 	/*
76 	 * A channel program can run a "zfs destroy" as part of its
77 	 * script and therefore has the same space_check policy when
78 	 * being evaluated.
79 	 */
80 	ZFS_SPACE_CHECK_ZCP_EVAL = ZFS_SPACE_CHECK_DESTROY,
81 
82 	/*
83 	 * No space check is performed. This level of space check should
84 	 * be used cautiously as operations that use it can even run when
85 	 * 0.8% capacity is left for use. In this scenario, if there is a
86 	 * checkpoint, async destroys are suspended and any kind of freeing
87 	 * can potentially add space instead of freeing it.
88 	 *
89 	 * See also the comments above spa_slop_shift.
90 	 */
91 	ZFS_SPACE_CHECK_NONE,
92 
93 	ZFS_SPACE_CHECK_DISCARD_CHECKPOINT = ZFS_SPACE_CHECK_NONE,
94 
95 } zfs_space_check_t;
96 
97 typedef struct dsl_sync_task {
98 	txg_node_t dst_node;
99 	struct dsl_pool *dst_pool;
100 	uint64_t dst_txg;
101 	int dst_space;
102 	zfs_space_check_t dst_space_check;
103 	dsl_checkfunc_t *dst_checkfunc;
104 	dsl_syncfunc_t *dst_syncfunc;
105 	void *dst_arg;
106 	int dst_error;
107 	boolean_t dst_nowaiter;
108 } dsl_sync_task_t;
109 
110 void dsl_sync_task_sync(dsl_sync_task_t *, dmu_tx_t *);
111 int dsl_sync_task(const char *, dsl_checkfunc_t *,
112     dsl_syncfunc_t *, void *, int, zfs_space_check_t);
113 void dsl_sync_task_nowait(struct dsl_pool *, dsl_syncfunc_t *,
114     void *, int, zfs_space_check_t, dmu_tx_t *);
115 int dsl_early_sync_task(const char *, dsl_checkfunc_t *,
116     dsl_syncfunc_t *, void *, int, zfs_space_check_t);
117 void dsl_early_sync_task_nowait(struct dsl_pool *, dsl_syncfunc_t *,
118     void *, int, zfs_space_check_t, dmu_tx_t *);
119 
120 #ifdef	__cplusplus
121 }
122 #endif
123 
124 #endif /* _SYS_DSL_SYNCTASK_H */
125