Print this page
NEX-5553 ZFS auto-trim, manual-trim and scrub can race and deadlock
Reviewed by: Alek Pinchuk <alek.pinchuk@nexenta.com>
Reviewed by: Rob Gittins <rob.gittins@nexenta.com>
Reviewed by: Sanjay Nadkarni <sanjay.nadkarni@nexenta.com>
NEX-5064 On-demand trim should store operation start and stop time
Reviewed by: Roman Strashkin <roman.strashkin@nexenta.com>
Reviewed by: Alek Pinchuk <alek.pinchuk@nexenta.com>
NEX-3558 KRRP Integration
| Split |
Close |
| Expand all |
| Collapse all |
--- old/usr/src/uts/common/fs/zfs/dsl_synctask.c
+++ new/usr/src/uts/common/fs/zfs/dsl_synctask.c
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
|
↓ open down ↓ |
13 lines elided |
↑ open up ↑ |
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21 /*
22 22 * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
23 23 * Copyright (c) 2012, 2014 by Delphix. All rights reserved.
24 + * Copyright 2015 Nexenta Systems, Inc. All rights reserved.
24 25 */
25 26
26 27 #include <sys/dmu.h>
27 28 #include <sys/dmu_tx.h>
28 29 #include <sys/dsl_pool.h>
29 30 #include <sys/dsl_dir.h>
30 31 #include <sys/dsl_synctask.h>
31 32 #include <sys/metaslab.h>
32 33
33 -#define DST_AVG_BLKSHIFT 14
34 -
35 34 /* ARGSUSED */
36 35 static int
37 36 dsl_null_checkfunc(void *arg, dmu_tx_t *tx)
38 37 {
39 38 return (0);
40 39 }
41 40
42 41 /*
43 42 * Called from open context to perform a callback in syncing context. Waits
44 43 * for the operation to complete.
45 44 *
46 45 * The checkfunc will be called from open context as a preliminary check
47 46 * which can quickly fail. If it succeeds, it will be called again from
48 47 * syncing context. The checkfunc should generally be designed to work
49 48 * properly in either context, but if necessary it can check
50 49 * dmu_tx_is_syncing(tx).
51 50 *
52 51 * The synctask infrastructure enforces proper locking strategy with respect
53 52 * to the dp_config_rwlock -- the lock will always be held when the callbacks
54 53 * are called. It will be held for read during the open-context (preliminary)
55 54 * call to the checkfunc, and then held for write from syncing context during
56 55 * the calls to the check and sync funcs.
57 56 *
58 57 * A dataset or pool name can be passed as the first argument. Typically,
59 58 * the check func will hold, check the return value of the hold, and then
60 59 * release the dataset. The sync func will VERIFYO(hold()) the dataset.
61 60 * This is safe because no changes can be made between the check and sync funcs,
62 61 * and the sync func will only be called if the check func successfully opened
63 62 * the dataset.
64 63 */
65 64 int
66 65 dsl_sync_task(const char *pool, dsl_checkfunc_t *checkfunc,
67 66 dsl_syncfunc_t *syncfunc, void *arg,
68 67 int blocks_modified, zfs_space_check_t space_check)
69 68 {
70 69 spa_t *spa;
71 70 dmu_tx_t *tx;
72 71 int err;
73 72 dsl_sync_task_t dst = { 0 };
74 73 dsl_pool_t *dp;
75 74
76 75 err = spa_open(pool, &spa, FTAG);
77 76 if (err != 0)
78 77 return (err);
79 78 dp = spa_get_dsl(spa);
80 79
81 80 top:
82 81 tx = dmu_tx_create_dd(dp->dp_mos_dir);
83 82 VERIFY0(dmu_tx_assign(tx, TXG_WAIT));
84 83
85 84 dst.dst_pool = dp;
86 85 dst.dst_txg = dmu_tx_get_txg(tx);
87 86 dst.dst_space = blocks_modified << DST_AVG_BLKSHIFT;
88 87 dst.dst_space_check = space_check;
89 88 dst.dst_checkfunc = checkfunc != NULL ? checkfunc : dsl_null_checkfunc;
90 89 dst.dst_syncfunc = syncfunc;
91 90 dst.dst_arg = arg;
92 91 dst.dst_error = 0;
93 92 dst.dst_nowaiter = B_FALSE;
94 93
95 94 dsl_pool_config_enter(dp, FTAG);
96 95 err = dst.dst_checkfunc(arg, tx);
97 96 dsl_pool_config_exit(dp, FTAG);
98 97
99 98 if (err != 0) {
100 99 dmu_tx_commit(tx);
101 100 spa_close(spa, FTAG);
102 101 return (err);
103 102 }
104 103
|
↓ open down ↓ |
60 lines elided |
↑ open up ↑ |
105 104 VERIFY(txg_list_add_tail(&dp->dp_sync_tasks, &dst, dst.dst_txg));
106 105
107 106 dmu_tx_commit(tx);
108 107
109 108 txg_wait_synced(dp, dst.dst_txg);
110 109
111 110 if (dst.dst_error == EAGAIN) {
112 111 txg_wait_synced(dp, dst.dst_txg + TXG_DEFER_SIZE);
113 112 goto top;
114 113 }
115 -
116 114 spa_close(spa, FTAG);
117 115 return (dst.dst_error);
118 116 }
119 117
120 118 void
121 119 dsl_sync_task_nowait(dsl_pool_t *dp, dsl_syncfunc_t *syncfunc, void *arg,
122 120 int blocks_modified, zfs_space_check_t space_check, dmu_tx_t *tx)
123 121 {
124 122 dsl_sync_task_t *dst = kmem_zalloc(sizeof (*dst), KM_SLEEP);
125 123
126 124 dst->dst_pool = dp;
127 125 dst->dst_txg = dmu_tx_get_txg(tx);
128 126 dst->dst_space = blocks_modified << DST_AVG_BLKSHIFT;
129 127 dst->dst_space_check = space_check;
130 128 dst->dst_checkfunc = dsl_null_checkfunc;
131 129 dst->dst_syncfunc = syncfunc;
132 130 dst->dst_arg = arg;
133 131 dst->dst_error = 0;
134 132 dst->dst_nowaiter = B_TRUE;
135 133
136 134 VERIFY(txg_list_add_tail(&dp->dp_sync_tasks, dst, dst->dst_txg));
137 135 }
138 136
139 137 /*
140 138 * Called in syncing context to execute the synctask.
141 139 */
142 140 void
143 141 dsl_sync_task_sync(dsl_sync_task_t *dst, dmu_tx_t *tx)
144 142 {
145 143 dsl_pool_t *dp = dst->dst_pool;
146 144
147 145 ASSERT0(dst->dst_error);
148 146
149 147 /*
150 148 * Check for sufficient space.
151 149 *
152 150 * When the sync task was created, the caller specified the
153 151 * type of space checking required. See the comment in
154 152 * zfs_space_check_t for details on the semantics of each
155 153 * type of space checking.
156 154 *
157 155 * We just check against what's on-disk; we don't want any
158 156 * in-flight accounting to get in our way, because open context
159 157 * may have already used up various in-core limits
160 158 * (arc_tempreserve, dsl_pool_tempreserve).
161 159 */
162 160 if (dst->dst_space_check != ZFS_SPACE_CHECK_NONE) {
163 161 uint64_t quota = dsl_pool_adjustedsize(dp,
164 162 dst->dst_space_check == ZFS_SPACE_CHECK_RESERVED) -
165 163 metaslab_class_get_deferred(spa_normal_class(dp->dp_spa));
166 164 uint64_t used = dsl_dir_phys(dp->dp_root_dir)->dd_used_bytes;
167 165 /* MOS space is triple-dittoed, so we multiply by 3. */
168 166 if (dst->dst_space > 0 && used + dst->dst_space * 3 > quota) {
169 167 dst->dst_error = SET_ERROR(ENOSPC);
170 168 if (dst->dst_nowaiter)
171 169 kmem_free(dst, sizeof (*dst));
172 170 return;
173 171 }
174 172 }
175 173
176 174 /*
177 175 * Check for errors by calling checkfunc.
178 176 */
179 177 rrw_enter(&dp->dp_config_rwlock, RW_WRITER, FTAG);
180 178 dst->dst_error = dst->dst_checkfunc(dst->dst_arg, tx);
181 179 if (dst->dst_error == 0)
182 180 dst->dst_syncfunc(dst->dst_arg, tx);
183 181 rrw_exit(&dp->dp_config_rwlock, FTAG);
184 182 if (dst->dst_nowaiter)
185 183 kmem_free(dst, sizeof (*dst));
186 184 }
|
↓ open down ↓ |
61 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX