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