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