]> git.proxmox.com Git - mirror_zfs.git/blame - module/zfs/dsl_destroy.c
OpenZFS 8607 - variable set but not used
[mirror_zfs.git] / module / zfs / dsl_destroy.c
CommitLineData
13fe0198
MA
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.
241b5415 23 * Copyright (c) 2012, 2015 by Delphix. All rights reserved.
95fd54a1 24 * Copyright (c) 2013 Steven Hartland. All rights reserved.
788eb90c 25 * Copyright (c) 2013 by Joyent, Inc. All rights reserved.
a0bd735a 26 * Copyright (c) 2016 Actifio, Inc. All rights reserved.
13fe0198
MA
27 */
28
29#include <sys/zfs_context.h>
30#include <sys/dsl_userhold.h>
31#include <sys/dsl_dataset.h>
32#include <sys/dsl_synctask.h>
33#include <sys/dmu_tx.h>
34#include <sys/dsl_pool.h>
35#include <sys/dsl_dir.h>
36#include <sys/dmu_traverse.h>
37#include <sys/dsl_scan.h>
38#include <sys/dmu_objset.h>
39#include <sys/zap.h>
40#include <sys/zfeature.h>
41#include <sys/zfs_ioctl.h>
42#include <sys/dsl_deleg.h>
fa86b5db 43#include <sys/dmu_impl.h>
a0bd735a 44#include <sys/zvol.h>
13fe0198
MA
45
46typedef struct dmu_snapshots_destroy_arg {
47 nvlist_t *dsda_snaps;
48 nvlist_t *dsda_successful_snaps;
49 boolean_t dsda_defer;
50 nvlist_t *dsda_errlist;
51} dmu_snapshots_destroy_arg_t;
52
19580676 53int
13fe0198
MA
54dsl_destroy_snapshot_check_impl(dsl_dataset_t *ds, boolean_t defer)
55{
0c66c32d 56 if (!ds->ds_is_snapshot)
2e528b49 57 return (SET_ERROR(EINVAL));
13fe0198
MA
58
59 if (dsl_dataset_long_held(ds))
2e528b49 60 return (SET_ERROR(EBUSY));
13fe0198
MA
61
62 /*
63 * Only allow deferred destroy on pools that support it.
64 * NOTE: deferred destroy is only supported on snapshots.
65 */
66 if (defer) {
67 if (spa_version(ds->ds_dir->dd_pool->dp_spa) <
68 SPA_VERSION_USERREFS)
2e528b49 69 return (SET_ERROR(ENOTSUP));
13fe0198
MA
70 return (0);
71 }
72
73 /*
74 * If this snapshot has an elevated user reference count,
75 * we can't destroy it yet.
76 */
77 if (ds->ds_userrefs > 0)
2e528b49 78 return (SET_ERROR(EBUSY));
13fe0198
MA
79
80 /*
81 * Can't delete a branch point.
82 */
d683ddbb 83 if (dsl_dataset_phys(ds)->ds_num_children > 1)
2e528b49 84 return (SET_ERROR(EEXIST));
13fe0198
MA
85
86 return (0);
87}
88
89static int
90dsl_destroy_snapshot_check(void *arg, dmu_tx_t *tx)
91{
92 dmu_snapshots_destroy_arg_t *dsda = arg;
93 dsl_pool_t *dp = dmu_tx_pool(tx);
94 nvpair_t *pair;
95 int error = 0;
96
97 if (!dmu_tx_is_syncing(tx))
98 return (0);
99
100 for (pair = nvlist_next_nvpair(dsda->dsda_snaps, NULL);
101 pair != NULL; pair = nvlist_next_nvpair(dsda->dsda_snaps, pair)) {
102 dsl_dataset_t *ds;
103
104 error = dsl_dataset_hold(dp, nvpair_name(pair),
105 FTAG, &ds);
106
107 /*
108 * If the snapshot does not exist, silently ignore it
109 * (it's "already destroyed").
110 */
111 if (error == ENOENT)
112 continue;
113
114 if (error == 0) {
115 error = dsl_destroy_snapshot_check_impl(ds,
116 dsda->dsda_defer);
117 dsl_dataset_rele(ds, FTAG);
118 }
119
120 if (error == 0) {
121 fnvlist_add_boolean(dsda->dsda_successful_snaps,
122 nvpair_name(pair));
123 } else {
124 fnvlist_add_int32(dsda->dsda_errlist,
125 nvpair_name(pair), error);
126 }
127 }
128
129 pair = nvlist_next_nvpair(dsda->dsda_errlist, NULL);
130 if (pair != NULL)
131 return (fnvpair_value_int32(pair));
95fd54a1 132
13fe0198
MA
133 return (0);
134}
135
136struct process_old_arg {
137 dsl_dataset_t *ds;
138 dsl_dataset_t *ds_prev;
139 boolean_t after_branch_point;
140 zio_t *pio;
141 uint64_t used, comp, uncomp;
142};
143
144static int
145process_old_cb(void *arg, const blkptr_t *bp, dmu_tx_t *tx)
146{
147 struct process_old_arg *poa = arg;
148 dsl_pool_t *dp = poa->ds->ds_dir->dd_pool;
149
b0bc7a84
MG
150 ASSERT(!BP_IS_HOLE(bp));
151
d683ddbb 152 if (bp->blk_birth <= dsl_dataset_phys(poa->ds)->ds_prev_snap_txg) {
13fe0198
MA
153 dsl_deadlist_insert(&poa->ds->ds_deadlist, bp, tx);
154 if (poa->ds_prev && !poa->after_branch_point &&
155 bp->blk_birth >
d683ddbb
JG
156 dsl_dataset_phys(poa->ds_prev)->ds_prev_snap_txg) {
157 dsl_dataset_phys(poa->ds_prev)->ds_unique_bytes +=
13fe0198
MA
158 bp_get_dsize_sync(dp->dp_spa, bp);
159 }
160 } else {
161 poa->used += bp_get_dsize_sync(dp->dp_spa, bp);
162 poa->comp += BP_GET_PSIZE(bp);
163 poa->uncomp += BP_GET_UCSIZE(bp);
164 dsl_free_sync(poa->pio, dp, tx->tx_txg, bp);
165 }
166 return (0);
167}
168
169static void
170process_old_deadlist(dsl_dataset_t *ds, dsl_dataset_t *ds_prev,
171 dsl_dataset_t *ds_next, boolean_t after_branch_point, dmu_tx_t *tx)
172{
173 struct process_old_arg poa = { 0 };
174 dsl_pool_t *dp = ds->ds_dir->dd_pool;
175 objset_t *mos = dp->dp_meta_objset;
176 uint64_t deadlist_obj;
177
178 ASSERT(ds->ds_deadlist.dl_oldfmt);
179 ASSERT(ds_next->ds_deadlist.dl_oldfmt);
180
181 poa.ds = ds;
182 poa.ds_prev = ds_prev;
183 poa.after_branch_point = after_branch_point;
184 poa.pio = zio_root(dp->dp_spa, NULL, NULL, ZIO_FLAG_MUSTSUCCEED);
185 VERIFY0(bpobj_iterate(&ds_next->ds_deadlist.dl_bpobj,
186 process_old_cb, &poa, tx));
187 VERIFY0(zio_wait(poa.pio));
d683ddbb 188 ASSERT3U(poa.used, ==, dsl_dataset_phys(ds)->ds_unique_bytes);
13fe0198
MA
189
190 /* change snapused */
191 dsl_dir_diduse_space(ds->ds_dir, DD_USED_SNAP,
192 -poa.used, -poa.comp, -poa.uncomp, tx);
193
194 /* swap next's deadlist to our deadlist */
195 dsl_deadlist_close(&ds->ds_deadlist);
196 dsl_deadlist_close(&ds_next->ds_deadlist);
d683ddbb
JG
197 deadlist_obj = dsl_dataset_phys(ds)->ds_deadlist_obj;
198 dsl_dataset_phys(ds)->ds_deadlist_obj =
199 dsl_dataset_phys(ds_next)->ds_deadlist_obj;
200 dsl_dataset_phys(ds_next)->ds_deadlist_obj = deadlist_obj;
201 dsl_deadlist_open(&ds->ds_deadlist, mos,
202 dsl_dataset_phys(ds)->ds_deadlist_obj);
13fe0198 203 dsl_deadlist_open(&ds_next->ds_deadlist, mos,
d683ddbb 204 dsl_dataset_phys(ds_next)->ds_deadlist_obj);
13fe0198
MA
205}
206
207static void
208dsl_dataset_remove_clones_key(dsl_dataset_t *ds, uint64_t mintxg, dmu_tx_t *tx)
209{
210 objset_t *mos = ds->ds_dir->dd_pool->dp_meta_objset;
77831e17
KK
211 zap_cursor_t *zc;
212 zap_attribute_t *za;
13fe0198
MA
213
214 /*
215 * If it is the old version, dd_clones doesn't exist so we can't
216 * find the clones, but dsl_deadlist_remove_key() is a no-op so it
217 * doesn't matter.
218 */
d683ddbb 219 if (dsl_dir_phys(ds->ds_dir)->dd_clones == 0)
13fe0198
MA
220 return;
221
79c76d5b
BB
222 zc = kmem_alloc(sizeof (zap_cursor_t), KM_SLEEP);
223 za = kmem_alloc(sizeof (zap_attribute_t), KM_SLEEP);
77831e17 224
d683ddbb 225 for (zap_cursor_init(zc, mos, dsl_dir_phys(ds->ds_dir)->dd_clones);
77831e17
KK
226 zap_cursor_retrieve(zc, za) == 0;
227 zap_cursor_advance(zc)) {
13fe0198
MA
228 dsl_dataset_t *clone;
229
230 VERIFY0(dsl_dataset_hold_obj(ds->ds_dir->dd_pool,
77831e17 231 za->za_first_integer, FTAG, &clone));
13fe0198
MA
232 if (clone->ds_dir->dd_origin_txg > mintxg) {
233 dsl_deadlist_remove_key(&clone->ds_deadlist,
234 mintxg, tx);
235 dsl_dataset_remove_clones_key(clone, mintxg, tx);
236 }
237 dsl_dataset_rele(clone, FTAG);
238 }
77831e17
KK
239 zap_cursor_fini(zc);
240
241 kmem_free(za, sizeof (zap_attribute_t));
242 kmem_free(zc, sizeof (zap_cursor_t));
13fe0198
MA
243}
244
245void
246dsl_destroy_snapshot_sync_impl(dsl_dataset_t *ds, boolean_t defer, dmu_tx_t *tx)
247{
13fe0198
MA
248 int after_branch_point = FALSE;
249 dsl_pool_t *dp = ds->ds_dir->dd_pool;
250 objset_t *mos = dp->dp_meta_objset;
251 dsl_dataset_t *ds_prev = NULL;
1c27024e 252 uint64_t obj;
13fe0198
MA
253
254 ASSERT(RRW_WRITE_HELD(&dp->dp_config_rwlock));
cc9bb3e5 255 rrw_enter(&ds->ds_bp_rwlock, RW_READER, FTAG);
d683ddbb 256 ASSERT3U(dsl_dataset_phys(ds)->ds_bp.blk_birth, <=, tx->tx_txg);
cc9bb3e5 257 rrw_exit(&ds->ds_bp_rwlock, FTAG);
13fe0198
MA
258 ASSERT(refcount_is_zero(&ds->ds_longholds));
259
260 if (defer &&
d683ddbb
JG
261 (ds->ds_userrefs > 0 ||
262 dsl_dataset_phys(ds)->ds_num_children > 1)) {
13fe0198
MA
263 ASSERT(spa_version(dp->dp_spa) >= SPA_VERSION_USERREFS);
264 dmu_buf_will_dirty(ds->ds_dbuf, tx);
d683ddbb 265 dsl_dataset_phys(ds)->ds_flags |= DS_FLAG_DEFER_DESTROY;
13fe0198
MA
266 spa_history_log_internal_ds(ds, "defer_destroy", tx, "");
267 return;
268 }
269
d683ddbb 270 ASSERT3U(dsl_dataset_phys(ds)->ds_num_children, <=, 1);
13fe0198
MA
271
272 /* We need to log before removing it from the namespace. */
273 spa_history_log_internal_ds(ds, "destroy", tx, "");
274
275 dsl_scan_ds_destroyed(ds, tx);
276
277 obj = ds->ds_object;
278
1c27024e 279 for (spa_feature_t f = 0; f < SPA_FEATURES; f++) {
241b5415
MA
280 if (ds->ds_feature_inuse[f]) {
281 dsl_dataset_deactivate_feature(obj, f, tx);
282 ds->ds_feature_inuse[f] = B_FALSE;
283 }
f1512ee6 284 }
d683ddbb 285 if (dsl_dataset_phys(ds)->ds_prev_snap_obj != 0) {
13fe0198
MA
286 ASSERT3P(ds->ds_prev, ==, NULL);
287 VERIFY0(dsl_dataset_hold_obj(dp,
d683ddbb 288 dsl_dataset_phys(ds)->ds_prev_snap_obj, FTAG, &ds_prev));
13fe0198 289 after_branch_point =
d683ddbb 290 (dsl_dataset_phys(ds_prev)->ds_next_snap_obj != obj);
13fe0198
MA
291
292 dmu_buf_will_dirty(ds_prev->ds_dbuf, tx);
293 if (after_branch_point &&
d683ddbb 294 dsl_dataset_phys(ds_prev)->ds_next_clones_obj != 0) {
13fe0198 295 dsl_dataset_remove_from_next_clones(ds_prev, obj, tx);
d683ddbb 296 if (dsl_dataset_phys(ds)->ds_next_snap_obj != 0) {
13fe0198 297 VERIFY0(zap_add_int(mos,
d683ddbb
JG
298 dsl_dataset_phys(ds_prev)->
299 ds_next_clones_obj,
300 dsl_dataset_phys(ds)->ds_next_snap_obj,
301 tx));
13fe0198
MA
302 }
303 }
304 if (!after_branch_point) {
d683ddbb
JG
305 dsl_dataset_phys(ds_prev)->ds_next_snap_obj =
306 dsl_dataset_phys(ds)->ds_next_snap_obj;
13fe0198
MA
307 }
308 }
309
1c27024e
DB
310 dsl_dataset_t *ds_next;
311 uint64_t old_unique;
312 uint64_t used = 0, comp = 0, uncomp = 0;
313
13fe0198 314 VERIFY0(dsl_dataset_hold_obj(dp,
d683ddbb
JG
315 dsl_dataset_phys(ds)->ds_next_snap_obj, FTAG, &ds_next));
316 ASSERT3U(dsl_dataset_phys(ds_next)->ds_prev_snap_obj, ==, obj);
13fe0198 317
d683ddbb 318 old_unique = dsl_dataset_phys(ds_next)->ds_unique_bytes;
13fe0198
MA
319
320 dmu_buf_will_dirty(ds_next->ds_dbuf, tx);
d683ddbb
JG
321 dsl_dataset_phys(ds_next)->ds_prev_snap_obj =
322 dsl_dataset_phys(ds)->ds_prev_snap_obj;
323 dsl_dataset_phys(ds_next)->ds_prev_snap_txg =
324 dsl_dataset_phys(ds)->ds_prev_snap_txg;
325 ASSERT3U(dsl_dataset_phys(ds)->ds_prev_snap_txg, ==,
326 ds_prev ? dsl_dataset_phys(ds_prev)->ds_creation_txg : 0);
13fe0198
MA
327
328 if (ds_next->ds_deadlist.dl_oldfmt) {
329 process_old_deadlist(ds, ds_prev, ds_next,
330 after_branch_point, tx);
331 } else {
332 /* Adjust prev's unique space. */
333 if (ds_prev && !after_branch_point) {
334 dsl_deadlist_space_range(&ds_next->ds_deadlist,
d683ddbb
JG
335 dsl_dataset_phys(ds_prev)->ds_prev_snap_txg,
336 dsl_dataset_phys(ds)->ds_prev_snap_txg,
13fe0198 337 &used, &comp, &uncomp);
d683ddbb 338 dsl_dataset_phys(ds_prev)->ds_unique_bytes += used;
13fe0198
MA
339 }
340
341 /* Adjust snapused. */
342 dsl_deadlist_space_range(&ds_next->ds_deadlist,
d683ddbb 343 dsl_dataset_phys(ds)->ds_prev_snap_txg, UINT64_MAX,
13fe0198
MA
344 &used, &comp, &uncomp);
345 dsl_dir_diduse_space(ds->ds_dir, DD_USED_SNAP,
346 -used, -comp, -uncomp, tx);
347
348 /* Move blocks to be freed to pool's free list. */
349 dsl_deadlist_move_bpobj(&ds_next->ds_deadlist,
d683ddbb 350 &dp->dp_free_bpobj, dsl_dataset_phys(ds)->ds_prev_snap_txg,
13fe0198
MA
351 tx);
352 dsl_dir_diduse_space(tx->tx_pool->dp_free_dir,
353 DD_USED_HEAD, used, comp, uncomp, tx);
354
355 /* Merge our deadlist into next's and free it. */
356 dsl_deadlist_merge(&ds_next->ds_deadlist,
d683ddbb 357 dsl_dataset_phys(ds)->ds_deadlist_obj, tx);
13fe0198
MA
358 }
359 dsl_deadlist_close(&ds->ds_deadlist);
d683ddbb 360 dsl_deadlist_free(mos, dsl_dataset_phys(ds)->ds_deadlist_obj, tx);
13fe0198 361 dmu_buf_will_dirty(ds->ds_dbuf, tx);
d683ddbb 362 dsl_dataset_phys(ds)->ds_deadlist_obj = 0;
13fe0198
MA
363
364 /* Collapse range in clone heads */
365 dsl_dataset_remove_clones_key(ds,
d683ddbb 366 dsl_dataset_phys(ds)->ds_creation_txg, tx);
13fe0198 367
0c66c32d 368 if (ds_next->ds_is_snapshot) {
13fe0198
MA
369 dsl_dataset_t *ds_nextnext;
370
371 /*
372 * Update next's unique to include blocks which
373 * were previously shared by only this snapshot
374 * and it. Those blocks will be born after the
375 * prev snap and before this snap, and will have
376 * died after the next snap and before the one
377 * after that (ie. be on the snap after next's
378 * deadlist).
379 */
380 VERIFY0(dsl_dataset_hold_obj(dp,
d683ddbb
JG
381 dsl_dataset_phys(ds_next)->ds_next_snap_obj,
382 FTAG, &ds_nextnext));
13fe0198 383 dsl_deadlist_space_range(&ds_nextnext->ds_deadlist,
d683ddbb
JG
384 dsl_dataset_phys(ds)->ds_prev_snap_txg,
385 dsl_dataset_phys(ds)->ds_creation_txg,
13fe0198 386 &used, &comp, &uncomp);
d683ddbb 387 dsl_dataset_phys(ds_next)->ds_unique_bytes += used;
13fe0198
MA
388 dsl_dataset_rele(ds_nextnext, FTAG);
389 ASSERT3P(ds_next->ds_prev, ==, NULL);
390
391 /* Collapse range in this head. */
1c27024e 392 dsl_dataset_t *hds;
13fe0198 393 VERIFY0(dsl_dataset_hold_obj(dp,
d683ddbb 394 dsl_dir_phys(ds->ds_dir)->dd_head_dataset_obj, FTAG, &hds));
13fe0198 395 dsl_deadlist_remove_key(&hds->ds_deadlist,
d683ddbb 396 dsl_dataset_phys(ds)->ds_creation_txg, tx);
13fe0198
MA
397 dsl_dataset_rele(hds, FTAG);
398
399 } else {
400 ASSERT3P(ds_next->ds_prev, ==, ds);
401 dsl_dataset_rele(ds_next->ds_prev, ds_next);
402 ds_next->ds_prev = NULL;
403 if (ds_prev) {
404 VERIFY0(dsl_dataset_hold_obj(dp,
d683ddbb 405 dsl_dataset_phys(ds)->ds_prev_snap_obj,
13fe0198
MA
406 ds_next, &ds_next->ds_prev));
407 }
408
409 dsl_dataset_recalc_head_uniq(ds_next);
410
411 /*
412 * Reduce the amount of our unconsumed refreservation
413 * being charged to our parent by the amount of
414 * new unique data we have gained.
415 */
416 if (old_unique < ds_next->ds_reserved) {
417 int64_t mrsdelta;
418 uint64_t new_unique =
d683ddbb 419 dsl_dataset_phys(ds_next)->ds_unique_bytes;
13fe0198
MA
420
421 ASSERT(old_unique <= new_unique);
422 mrsdelta = MIN(new_unique - old_unique,
423 ds_next->ds_reserved - old_unique);
424 dsl_dir_diduse_space(ds->ds_dir,
425 DD_USED_REFRSRV, -mrsdelta, 0, 0, tx);
426 }
427 }
428 dsl_dataset_rele(ds_next, FTAG);
429
430 /*
431 * This must be done after the dsl_traverse(), because it will
432 * re-open the objset.
433 */
434 if (ds->ds_objset) {
435 dmu_objset_evict(ds->ds_objset);
436 ds->ds_objset = NULL;
437 }
438
439 /* remove from snapshot namespace */
1c27024e 440 dsl_dataset_t *ds_head;
d683ddbb 441 ASSERT(dsl_dataset_phys(ds)->ds_snapnames_zapobj == 0);
13fe0198 442 VERIFY0(dsl_dataset_hold_obj(dp,
d683ddbb 443 dsl_dir_phys(ds->ds_dir)->dd_head_dataset_obj, FTAG, &ds_head));
13fe0198
MA
444 VERIFY0(dsl_dataset_get_snapname(ds));
445#ifdef ZFS_DEBUG
446 {
447 uint64_t val;
a0bd735a 448 int err;
13fe0198
MA
449
450 err = dsl_dataset_snap_lookup(ds_head,
451 ds->ds_snapname, &val);
452 ASSERT0(err);
453 ASSERT3U(val, ==, obj);
454 }
455#endif
788eb90c 456 VERIFY0(dsl_dataset_snap_remove(ds_head, ds->ds_snapname, tx, B_TRUE));
13fe0198
MA
457 dsl_dataset_rele(ds_head, FTAG);
458
459 if (ds_prev != NULL)
460 dsl_dataset_rele(ds_prev, FTAG);
461
462 spa_prop_clear_bootfs(dp->dp_spa, ds->ds_object, tx);
463
d683ddbb 464 if (dsl_dataset_phys(ds)->ds_next_clones_obj != 0) {
13fe0198
MA
465 ASSERTV(uint64_t count);
466 ASSERT0(zap_count(mos,
d683ddbb
JG
467 dsl_dataset_phys(ds)->ds_next_clones_obj, &count) &&
468 count == 0);
13fe0198 469 VERIFY0(dmu_object_free(mos,
d683ddbb 470 dsl_dataset_phys(ds)->ds_next_clones_obj, tx));
13fe0198 471 }
d683ddbb
JG
472 if (dsl_dataset_phys(ds)->ds_props_obj != 0)
473 VERIFY0(zap_destroy(mos, dsl_dataset_phys(ds)->ds_props_obj,
474 tx));
475 if (dsl_dataset_phys(ds)->ds_userrefs_obj != 0)
476 VERIFY0(zap_destroy(mos, dsl_dataset_phys(ds)->ds_userrefs_obj,
477 tx));
13fe0198
MA
478 dsl_dir_rele(ds->ds_dir, ds);
479 ds->ds_dir = NULL;
fa86b5db 480 dmu_object_free_zapified(mos, obj, tx);
13fe0198
MA
481}
482
483static void
484dsl_destroy_snapshot_sync(void *arg, dmu_tx_t *tx)
485{
486 dmu_snapshots_destroy_arg_t *dsda = arg;
487 dsl_pool_t *dp = dmu_tx_pool(tx);
488 nvpair_t *pair;
489
490 for (pair = nvlist_next_nvpair(dsda->dsda_successful_snaps, NULL);
491 pair != NULL;
492 pair = nvlist_next_nvpair(dsda->dsda_successful_snaps, pair)) {
493 dsl_dataset_t *ds;
494
495 VERIFY0(dsl_dataset_hold(dp, nvpair_name(pair), FTAG, &ds));
496
497 dsl_destroy_snapshot_sync_impl(ds, dsda->dsda_defer, tx);
a0bd735a 498 zvol_remove_minors(dp->dp_spa, nvpair_name(pair), B_TRUE);
13fe0198
MA
499 dsl_dataset_rele(ds, FTAG);
500 }
501}
502
503/*
504 * The semantics of this function are described in the comment above
505 * lzc_destroy_snaps(). To summarize:
506 *
507 * The snapshots must all be in the same pool.
508 *
509 * Snapshots that don't exist will be silently ignored (considered to be
510 * "already deleted").
511 *
512 * On success, all snaps will be destroyed and this will return 0.
513 * On failure, no snaps will be destroyed, the errlist will be filled in,
514 * and this will return an errno.
515 */
516int
517dsl_destroy_snapshots_nvl(nvlist_t *snaps, boolean_t defer,
518 nvlist_t *errlist)
519{
520 dmu_snapshots_destroy_arg_t dsda;
521 int error;
522 nvpair_t *pair;
523
524 pair = nvlist_next_nvpair(snaps, NULL);
525 if (pair == NULL)
526 return (0);
527
528 dsda.dsda_snaps = snaps;
d1d7e268 529 VERIFY0(nvlist_alloc(&dsda.dsda_successful_snaps,
79c76d5b 530 NV_UNIQUE_NAME, KM_SLEEP));
13fe0198
MA
531 dsda.dsda_defer = defer;
532 dsda.dsda_errlist = errlist;
533
534 error = dsl_sync_task(nvpair_name(pair),
535 dsl_destroy_snapshot_check, dsl_destroy_snapshot_sync,
3d45fdd6 536 &dsda, 0, ZFS_SPACE_CHECK_NONE);
13fe0198
MA
537 fnvlist_free(dsda.dsda_successful_snaps);
538
539 return (error);
540}
541
542int
543dsl_destroy_snapshot(const char *name, boolean_t defer)
544{
545 int error;
79c76d5b
BB
546 nvlist_t *nvl = fnvlist_alloc();
547 nvlist_t *errlist = fnvlist_alloc();
13fe0198
MA
548
549 fnvlist_add_boolean(nvl, name);
550 error = dsl_destroy_snapshots_nvl(nvl, defer, errlist);
551 fnvlist_free(errlist);
552 fnvlist_free(nvl);
553 return (error);
554}
555
556struct killarg {
557 dsl_dataset_t *ds;
558 dmu_tx_t *tx;
559};
560
561/* ARGSUSED */
562static int
563kill_blkptr(spa_t *spa, zilog_t *zilog, const blkptr_t *bp,
5dbd68a3 564 const zbookmark_phys_t *zb, const dnode_phys_t *dnp, void *arg)
13fe0198
MA
565{
566 struct killarg *ka = arg;
567 dmu_tx_t *tx = ka->tx;
568
fcff0f35 569 if (bp == NULL || BP_IS_HOLE(bp) || BP_IS_EMBEDDED(bp))
13fe0198
MA
570 return (0);
571
572 if (zb->zb_level == ZB_ZIL_LEVEL) {
573 ASSERT(zilog != NULL);
574 /*
575 * It's a block in the intent log. It has no
576 * accounting, so just free it.
577 */
578 dsl_free(ka->tx->tx_pool, ka->tx->tx_txg, bp);
579 } else {
580 ASSERT(zilog == NULL);
d683ddbb
JG
581 ASSERT3U(bp->blk_birth, >,
582 dsl_dataset_phys(ka->ds)->ds_prev_snap_txg);
13fe0198
MA
583 (void) dsl_dataset_block_kill(ka->ds, bp, tx, B_FALSE);
584 }
585
586 return (0);
587}
588
589static void
590old_synchronous_dataset_destroy(dsl_dataset_t *ds, dmu_tx_t *tx)
591{
592 struct killarg ka;
593
594 /*
595 * Free everything that we point to (that's born after
596 * the previous snapshot, if we are a clone)
597 *
598 * NB: this should be very quick, because we already
599 * freed all the objects in open context.
600 */
601 ka.ds = ds;
602 ka.tx = tx;
603 VERIFY0(traverse_dataset(ds,
b5256303
TC
604 dsl_dataset_phys(ds)->ds_prev_snap_txg, TRAVERSE_POST |
605 TRAVERSE_NO_DECRYPT, kill_blkptr, &ka));
d683ddbb
JG
606 ASSERT(!DS_UNIQUE_IS_ACCURATE(ds) ||
607 dsl_dataset_phys(ds)->ds_unique_bytes == 0);
13fe0198
MA
608}
609
610typedef struct dsl_destroy_head_arg {
611 const char *ddha_name;
612} dsl_destroy_head_arg_t;
613
614int
615dsl_destroy_head_check_impl(dsl_dataset_t *ds, int expected_holds)
616{
617 int error;
618 uint64_t count;
619 objset_t *mos;
620
0c66c32d
JG
621 ASSERT(!ds->ds_is_snapshot);
622 if (ds->ds_is_snapshot)
2e528b49 623 return (SET_ERROR(EINVAL));
13fe0198
MA
624
625 if (refcount_count(&ds->ds_longholds) != expected_holds)
2e528b49 626 return (SET_ERROR(EBUSY));
13fe0198
MA
627
628 mos = ds->ds_dir->dd_pool->dp_meta_objset;
629
630 /*
631 * Can't delete a head dataset if there are snapshots of it.
632 * (Except if the only snapshots are from the branch we cloned
633 * from.)
634 */
635 if (ds->ds_prev != NULL &&
d683ddbb 636 dsl_dataset_phys(ds->ds_prev)->ds_next_snap_obj == ds->ds_object)
2e528b49 637 return (SET_ERROR(EBUSY));
13fe0198
MA
638
639 /*
640 * Can't delete if there are children of this fs.
641 */
642 error = zap_count(mos,
d683ddbb 643 dsl_dir_phys(ds->ds_dir)->dd_child_dir_zapobj, &count);
13fe0198
MA
644 if (error != 0)
645 return (error);
646 if (count != 0)
2e528b49 647 return (SET_ERROR(EEXIST));
13fe0198
MA
648
649 if (dsl_dir_is_clone(ds->ds_dir) && DS_IS_DEFER_DESTROY(ds->ds_prev) &&
d683ddbb 650 dsl_dataset_phys(ds->ds_prev)->ds_num_children == 2 &&
13fe0198
MA
651 ds->ds_prev->ds_userrefs == 0) {
652 /* We need to remove the origin snapshot as well. */
653 if (!refcount_is_zero(&ds->ds_prev->ds_longholds))
2e528b49 654 return (SET_ERROR(EBUSY));
13fe0198
MA
655 }
656 return (0);
657}
658
659static int
660dsl_destroy_head_check(void *arg, dmu_tx_t *tx)
661{
662 dsl_destroy_head_arg_t *ddha = arg;
663 dsl_pool_t *dp = dmu_tx_pool(tx);
664 dsl_dataset_t *ds;
665 int error;
666
667 error = dsl_dataset_hold(dp, ddha->ddha_name, FTAG, &ds);
668 if (error != 0)
669 return (error);
670
671 error = dsl_destroy_head_check_impl(ds, 0);
672 dsl_dataset_rele(ds, FTAG);
673 return (error);
674}
675
676static void
677dsl_dir_destroy_sync(uint64_t ddobj, dmu_tx_t *tx)
678{
679 dsl_dir_t *dd;
680 dsl_pool_t *dp = dmu_tx_pool(tx);
681 objset_t *mos = dp->dp_meta_objset;
682 dd_used_t t;
683
684 ASSERT(RRW_WRITE_HELD(&dmu_tx_pool(tx)->dp_config_rwlock));
685
686 VERIFY0(dsl_dir_hold_obj(dp, ddobj, NULL, FTAG, &dd));
687
d683ddbb 688 ASSERT0(dsl_dir_phys(dd)->dd_head_dataset_obj);
13fe0198 689
788eb90c
JJ
690 /*
691 * Decrement the filesystem count for all parent filesystems.
692 *
693 * When we receive an incremental stream into a filesystem that already
694 * exists, a temporary clone is created. We never count this temporary
695 * clone, whose name begins with a '%'.
696 */
697 if (dd->dd_myname[0] != '%' && dd->dd_parent != NULL)
698 dsl_fs_ss_count_adjust(dd->dd_parent, -1,
699 DD_FIELD_FILESYSTEM_COUNT, tx);
700
13fe0198
MA
701 /*
702 * Remove our reservation. The impl() routine avoids setting the
703 * actual property, which would require the (already destroyed) ds.
704 */
705 dsl_dir_set_reservation_sync_impl(dd, 0, tx);
706
d683ddbb
JG
707 ASSERT0(dsl_dir_phys(dd)->dd_used_bytes);
708 ASSERT0(dsl_dir_phys(dd)->dd_reserved);
13fe0198 709 for (t = 0; t < DD_USED_NUM; t++)
d683ddbb 710 ASSERT0(dsl_dir_phys(dd)->dd_used_breakdown[t]);
13fe0198 711
b5256303
TC
712 if (dd->dd_crypto_obj != 0) {
713 dsl_crypto_key_destroy_sync(dd->dd_crypto_obj, tx);
714 (void) spa_keystore_unload_wkey_impl(dp->dp_spa, dd->dd_object);
715 }
716
d683ddbb
JG
717 VERIFY0(zap_destroy(mos, dsl_dir_phys(dd)->dd_child_dir_zapobj, tx));
718 VERIFY0(zap_destroy(mos, dsl_dir_phys(dd)->dd_props_zapobj, tx));
719 VERIFY0(dsl_deleg_destroy(mos, dsl_dir_phys(dd)->dd_deleg_zapobj, tx));
13fe0198 720 VERIFY0(zap_remove(mos,
d683ddbb
JG
721 dsl_dir_phys(dd->dd_parent)->dd_child_dir_zapobj,
722 dd->dd_myname, tx));
13fe0198
MA
723
724 dsl_dir_rele(dd, FTAG);
fa86b5db 725 dmu_object_free_zapified(mos, ddobj, tx);
13fe0198
MA
726}
727
728void
729dsl_destroy_head_sync_impl(dsl_dataset_t *ds, dmu_tx_t *tx)
730{
731 dsl_pool_t *dp = dmu_tx_pool(tx);
732 objset_t *mos = dp->dp_meta_objset;
733 uint64_t obj, ddobj, prevobj = 0;
734 boolean_t rmorigin;
13fe0198 735
d683ddbb 736 ASSERT3U(dsl_dataset_phys(ds)->ds_num_children, <=, 1);
13fe0198 737 ASSERT(ds->ds_prev == NULL ||
d683ddbb 738 dsl_dataset_phys(ds->ds_prev)->ds_next_snap_obj != ds->ds_object);
cc9bb3e5 739 rrw_enter(&ds->ds_bp_rwlock, RW_READER, FTAG);
d683ddbb 740 ASSERT3U(dsl_dataset_phys(ds)->ds_bp.blk_birth, <=, tx->tx_txg);
cc9bb3e5 741 rrw_exit(&ds->ds_bp_rwlock, FTAG);
13fe0198
MA
742 ASSERT(RRW_WRITE_HELD(&dp->dp_config_rwlock));
743
744 /* We need to log before removing it from the namespace. */
745 spa_history_log_internal_ds(ds, "destroy", tx, "");
746
747 rmorigin = (dsl_dir_is_clone(ds->ds_dir) &&
748 DS_IS_DEFER_DESTROY(ds->ds_prev) &&
d683ddbb 749 dsl_dataset_phys(ds->ds_prev)->ds_num_children == 2 &&
13fe0198
MA
750 ds->ds_prev->ds_userrefs == 0);
751
9b67f605 752 /* Remove our reservation. */
13fe0198
MA
753 if (ds->ds_reserved != 0) {
754 dsl_dataset_set_refreservation_sync_impl(ds,
755 (ZPROP_SRC_NONE | ZPROP_SRC_LOCAL | ZPROP_SRC_RECEIVED),
756 0, tx);
757 ASSERT0(ds->ds_reserved);
758 }
759
241b5415 760 obj = ds->ds_object;
f1512ee6 761
1c27024e 762 for (spa_feature_t f = 0; f < SPA_FEATURES; f++) {
241b5415
MA
763 if (ds->ds_feature_inuse[f]) {
764 dsl_dataset_deactivate_feature(obj, f, tx);
765 ds->ds_feature_inuse[f] = B_FALSE;
766 }
767 }
13fe0198 768
241b5415 769 dsl_scan_ds_destroyed(ds, tx);
13fe0198 770
d683ddbb 771 if (dsl_dataset_phys(ds)->ds_prev_snap_obj != 0) {
13fe0198
MA
772 /* This is a clone */
773 ASSERT(ds->ds_prev != NULL);
d683ddbb
JG
774 ASSERT3U(dsl_dataset_phys(ds->ds_prev)->ds_next_snap_obj, !=,
775 obj);
776 ASSERT0(dsl_dataset_phys(ds)->ds_next_snap_obj);
13fe0198
MA
777
778 dmu_buf_will_dirty(ds->ds_prev->ds_dbuf, tx);
d683ddbb 779 if (dsl_dataset_phys(ds->ds_prev)->ds_next_clones_obj != 0) {
13fe0198
MA
780 dsl_dataset_remove_from_next_clones(ds->ds_prev,
781 obj, tx);
782 }
783
d683ddbb
JG
784 ASSERT3U(dsl_dataset_phys(ds->ds_prev)->ds_num_children, >, 1);
785 dsl_dataset_phys(ds->ds_prev)->ds_num_children--;
13fe0198
MA
786 }
787
13fe0198
MA
788 /*
789 * Destroy the deadlist. Unless it's a clone, the
790 * deadlist should be empty. (If it's a clone, it's
791 * safe to ignore the deadlist contents.)
792 */
793 dsl_deadlist_close(&ds->ds_deadlist);
d683ddbb 794 dsl_deadlist_free(mos, dsl_dataset_phys(ds)->ds_deadlist_obj, tx);
13fe0198 795 dmu_buf_will_dirty(ds->ds_dbuf, tx);
d683ddbb 796 dsl_dataset_phys(ds)->ds_deadlist_obj = 0;
13fe0198 797
1c27024e 798 objset_t *os;
13fe0198
MA
799 VERIFY0(dmu_objset_from_ds(ds, &os));
800
fa86b5db 801 if (!spa_feature_is_enabled(dp->dp_spa, SPA_FEATURE_ASYNC_DESTROY)) {
13fe0198
MA
802 old_synchronous_dataset_destroy(ds, tx);
803 } else {
804 /*
805 * Move the bptree into the pool's list of trees to
806 * clean up and update space accounting information.
807 */
808 uint64_t used, comp, uncomp;
809
810 zil_destroy_sync(dmu_objset_zil(os), tx);
811
fa86b5db
MA
812 if (!spa_feature_is_active(dp->dp_spa,
813 SPA_FEATURE_ASYNC_DESTROY)) {
2696dfaf 814 dsl_scan_t *scn = dp->dp_scan;
fa86b5db
MA
815 spa_feature_incr(dp->dp_spa, SPA_FEATURE_ASYNC_DESTROY,
816 tx);
13fe0198
MA
817 dp->dp_bptree_obj = bptree_alloc(mos, tx);
818 VERIFY0(zap_add(mos,
819 DMU_POOL_DIRECTORY_OBJECT,
820 DMU_POOL_BPTREE_OBJ, sizeof (uint64_t), 1,
821 &dp->dp_bptree_obj, tx));
2696dfaf
GW
822 ASSERT(!scn->scn_async_destroying);
823 scn->scn_async_destroying = B_TRUE;
13fe0198
MA
824 }
825
d683ddbb
JG
826 used = dsl_dir_phys(ds->ds_dir)->dd_used_bytes;
827 comp = dsl_dir_phys(ds->ds_dir)->dd_compressed_bytes;
828 uncomp = dsl_dir_phys(ds->ds_dir)->dd_uncompressed_bytes;
13fe0198
MA
829
830 ASSERT(!DS_UNIQUE_IS_ACCURATE(ds) ||
d683ddbb 831 dsl_dataset_phys(ds)->ds_unique_bytes == used);
13fe0198 832
cc9bb3e5 833 rrw_enter(&ds->ds_bp_rwlock, RW_READER, FTAG);
13fe0198 834 bptree_add(mos, dp->dp_bptree_obj,
d683ddbb
JG
835 &dsl_dataset_phys(ds)->ds_bp,
836 dsl_dataset_phys(ds)->ds_prev_snap_txg,
13fe0198 837 used, comp, uncomp, tx);
cc9bb3e5 838 rrw_exit(&ds->ds_bp_rwlock, FTAG);
13fe0198
MA
839 dsl_dir_diduse_space(ds->ds_dir, DD_USED_HEAD,
840 -used, -comp, -uncomp, tx);
841 dsl_dir_diduse_space(dp->dp_free_dir, DD_USED_HEAD,
842 used, comp, uncomp, tx);
843 }
844
845 if (ds->ds_prev != NULL) {
846 if (spa_version(dp->dp_spa) >= SPA_VERSION_DIR_CLONES) {
847 VERIFY0(zap_remove_int(mos,
d683ddbb 848 dsl_dir_phys(ds->ds_prev->ds_dir)->dd_clones,
13fe0198
MA
849 ds->ds_object, tx));
850 }
851 prevobj = ds->ds_prev->ds_object;
852 dsl_dataset_rele(ds->ds_prev, ds);
853 ds->ds_prev = NULL;
854 }
855
856 /*
857 * This must be done after the dsl_traverse(), because it will
858 * re-open the objset.
859 */
860 if (ds->ds_objset) {
861 dmu_objset_evict(ds->ds_objset);
862 ds->ds_objset = NULL;
863 }
864
865 /* Erase the link in the dir */
866 dmu_buf_will_dirty(ds->ds_dir->dd_dbuf, tx);
d683ddbb 867 dsl_dir_phys(ds->ds_dir)->dd_head_dataset_obj = 0;
13fe0198 868 ddobj = ds->ds_dir->dd_object;
d683ddbb
JG
869 ASSERT(dsl_dataset_phys(ds)->ds_snapnames_zapobj != 0);
870 VERIFY0(zap_destroy(mos,
871 dsl_dataset_phys(ds)->ds_snapnames_zapobj, tx));
13fe0198 872
da536844 873 if (ds->ds_bookmarks != 0) {
d683ddbb 874 VERIFY0(zap_destroy(mos, ds->ds_bookmarks, tx));
da536844
MA
875 spa_feature_decr(dp->dp_spa, SPA_FEATURE_BOOKMARKS, tx);
876 }
877
13fe0198
MA
878 spa_prop_clear_bootfs(dp->dp_spa, ds->ds_object, tx);
879
d683ddbb
JG
880 ASSERT0(dsl_dataset_phys(ds)->ds_next_clones_obj);
881 ASSERT0(dsl_dataset_phys(ds)->ds_props_obj);
882 ASSERT0(dsl_dataset_phys(ds)->ds_userrefs_obj);
13fe0198
MA
883 dsl_dir_rele(ds->ds_dir, ds);
884 ds->ds_dir = NULL;
fa86b5db 885 dmu_object_free_zapified(mos, obj, tx);
13fe0198
MA
886
887 dsl_dir_destroy_sync(ddobj, tx);
888
889 if (rmorigin) {
890 dsl_dataset_t *prev;
891 VERIFY0(dsl_dataset_hold_obj(dp, prevobj, FTAG, &prev));
892 dsl_destroy_snapshot_sync_impl(prev, B_FALSE, tx);
893 dsl_dataset_rele(prev, FTAG);
894 }
895}
896
897static void
898dsl_destroy_head_sync(void *arg, dmu_tx_t *tx)
899{
900 dsl_destroy_head_arg_t *ddha = arg;
901 dsl_pool_t *dp = dmu_tx_pool(tx);
902 dsl_dataset_t *ds;
903
904 VERIFY0(dsl_dataset_hold(dp, ddha->ddha_name, FTAG, &ds));
905 dsl_destroy_head_sync_impl(ds, tx);
a0bd735a 906 zvol_remove_minors(dp->dp_spa, ddha->ddha_name, B_TRUE);
13fe0198
MA
907 dsl_dataset_rele(ds, FTAG);
908}
909
910static void
911dsl_destroy_head_begin_sync(void *arg, dmu_tx_t *tx)
912{
913 dsl_destroy_head_arg_t *ddha = arg;
914 dsl_pool_t *dp = dmu_tx_pool(tx);
915 dsl_dataset_t *ds;
916
917 VERIFY0(dsl_dataset_hold(dp, ddha->ddha_name, FTAG, &ds));
918
919 /* Mark it as inconsistent on-disk, in case we crash */
920 dmu_buf_will_dirty(ds->ds_dbuf, tx);
d683ddbb 921 dsl_dataset_phys(ds)->ds_flags |= DS_FLAG_INCONSISTENT;
13fe0198
MA
922
923 spa_history_log_internal_ds(ds, "destroy begin", tx, "");
924 dsl_dataset_rele(ds, FTAG);
925}
926
927int
928dsl_destroy_head(const char *name)
929{
930 dsl_destroy_head_arg_t ddha;
931 int error;
932 spa_t *spa;
933 boolean_t isenabled;
934
935#ifdef _KERNEL
936 zfs_destroy_unmount_origin(name);
937#endif
938
939 error = spa_open(name, &spa, FTAG);
940 if (error != 0)
941 return (error);
fa86b5db 942 isenabled = spa_feature_is_enabled(spa, SPA_FEATURE_ASYNC_DESTROY);
13fe0198
MA
943 spa_close(spa, FTAG);
944
945 ddha.ddha_name = name;
946
947 if (!isenabled) {
948 objset_t *os;
949
950 error = dsl_sync_task(name, dsl_destroy_head_check,
3d45fdd6
MA
951 dsl_destroy_head_begin_sync, &ddha,
952 0, ZFS_SPACE_CHECK_NONE);
13fe0198
MA
953 if (error != 0)
954 return (error);
955
956 /*
957 * Head deletion is processed in one txg on old pools;
958 * remove the objects from open context so that the txg sync
959 * is not too long.
960 */
b5256303
TC
961 error = dmu_objset_own(name, DMU_OST_ANY, B_FALSE, B_FALSE,
962 FTAG, &os);
13fe0198 963 if (error == 0) {
13fe0198 964 uint64_t prev_snap_txg =
d683ddbb
JG
965 dsl_dataset_phys(dmu_objset_ds(os))->
966 ds_prev_snap_txg;
1c27024e 967 for (uint64_t obj = 0; error == 0;
13fe0198
MA
968 error = dmu_object_next(os, &obj, FALSE,
969 prev_snap_txg))
b663a23d 970 (void) dmu_free_long_object(os, obj);
13fe0198
MA
971 /* sync out all frees */
972 txg_wait_synced(dmu_objset_pool(os), 0);
b5256303 973 dmu_objset_disown(os, B_FALSE, FTAG);
13fe0198
MA
974 }
975 }
976
977 return (dsl_sync_task(name, dsl_destroy_head_check,
3d45fdd6 978 dsl_destroy_head_sync, &ddha, 0, ZFS_SPACE_CHECK_NONE));
13fe0198
MA
979}
980
981/*
982 * Note, this function is used as the callback for dmu_objset_find(). We
983 * always return 0 so that we will continue to find and process
984 * inconsistent datasets, even if we encounter an error trying to
985 * process one of them.
986 */
987/* ARGSUSED */
988int
989dsl_destroy_inconsistent(const char *dsname, void *arg)
990{
991 objset_t *os;
992
993 if (dmu_objset_hold(dsname, FTAG, &os) == 0) {
47dfff3b
MA
994 boolean_t need_destroy = DS_IS_INCONSISTENT(dmu_objset_ds(os));
995
996 /*
997 * If the dataset is inconsistent because a resumable receive
998 * has failed, then do not destroy it.
999 */
1000 if (dsl_dataset_has_resume_receive_state(dmu_objset_ds(os)))
1001 need_destroy = B_FALSE;
1002
13fe0198 1003 dmu_objset_rele(os, FTAG);
47dfff3b 1004 if (need_destroy)
13fe0198
MA
1005 (void) dsl_destroy_head(dsname);
1006 }
1007 return (0);
1008}
1009
1010
1011#if defined(_KERNEL) && defined(HAVE_SPL)
1012EXPORT_SYMBOL(dsl_destroy_head);
1013EXPORT_SYMBOL(dsl_destroy_head_sync_impl);
1014EXPORT_SYMBOL(dsl_dataset_user_hold_check_one);
1015EXPORT_SYMBOL(dsl_destroy_snapshot_sync_impl);
1016EXPORT_SYMBOL(dsl_destroy_inconsistent);
1017EXPORT_SYMBOL(dsl_dataset_user_release_tmp);
1018EXPORT_SYMBOL(dsl_destroy_head_check_impl);
1019#endif