]> git.proxmox.com Git - mirror_zfs.git/blame_incremental - module/zfs/dsl_userhold.c
Illumos 4757, 4913
[mirror_zfs.git] / module / zfs / dsl_userhold.c
... / ...
CommitLineData
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) 2013 by Delphix. All rights reserved.
24 * Copyright (c) 2013 Steven Hartland. All rights reserved.
25 */
26
27#include <sys/zfs_context.h>
28#include <sys/dsl_userhold.h>
29#include <sys/dsl_dataset.h>
30#include <sys/dsl_destroy.h>
31#include <sys/dsl_synctask.h>
32#include <sys/dmu_tx.h>
33#include <sys/zfs_onexit.h>
34#include <sys/dsl_pool.h>
35#include <sys/dsl_dir.h>
36#include <sys/zfs_ioctl.h>
37#include <sys/zap.h>
38
39typedef struct dsl_dataset_user_hold_arg {
40 nvlist_t *dduha_holds;
41 nvlist_t *dduha_chkholds;
42 nvlist_t *dduha_errlist;
43 minor_t dduha_minor;
44} dsl_dataset_user_hold_arg_t;
45
46/*
47 * If you add new checks here, you may need to add additional checks to the
48 * "temporary" case in snapshot_check() in dmu_objset.c.
49 */
50int
51dsl_dataset_user_hold_check_one(dsl_dataset_t *ds, const char *htag,
52 boolean_t temphold, dmu_tx_t *tx)
53{
54 dsl_pool_t *dp = dmu_tx_pool(tx);
55 objset_t *mos = dp->dp_meta_objset;
56 int error = 0;
57
58 ASSERT(dsl_pool_config_held(dp));
59
60 if (strlen(htag) > MAXNAMELEN)
61 return (SET_ERROR(E2BIG));
62 /* Tempholds have a more restricted length */
63 if (temphold && strlen(htag) + MAX_TAG_PREFIX_LEN >= MAXNAMELEN)
64 return (SET_ERROR(E2BIG));
65
66 /* tags must be unique (if ds already exists) */
67 if (ds != NULL && ds->ds_phys->ds_userrefs_obj != 0) {
68 uint64_t value;
69
70 error = zap_lookup(mos, ds->ds_phys->ds_userrefs_obj,
71 htag, 8, 1, &value);
72 if (error == 0)
73 error = SET_ERROR(EEXIST);
74 else if (error == ENOENT)
75 error = 0;
76 }
77
78 return (error);
79}
80
81static int
82dsl_dataset_user_hold_check(void *arg, dmu_tx_t *tx)
83{
84 dsl_dataset_user_hold_arg_t *dduha = arg;
85 dsl_pool_t *dp = dmu_tx_pool(tx);
86 nvpair_t *pair;
87
88 if (spa_version(dp->dp_spa) < SPA_VERSION_USERREFS)
89 return (SET_ERROR(ENOTSUP));
90
91 if (!dmu_tx_is_syncing(tx))
92 return (0);
93
94 for (pair = nvlist_next_nvpair(dduha->dduha_holds, NULL);
95 pair != NULL; pair = nvlist_next_nvpair(dduha->dduha_holds, pair)) {
96 dsl_dataset_t *ds;
97 int error = 0;
98 char *htag, *name;
99
100 /* must be a snapshot */
101 name = nvpair_name(pair);
102 if (strchr(name, '@') == NULL)
103 error = SET_ERROR(EINVAL);
104
105 if (error == 0)
106 error = nvpair_value_string(pair, &htag);
107
108 if (error == 0)
109 error = dsl_dataset_hold(dp, name, FTAG, &ds);
110
111 if (error == 0) {
112 error = dsl_dataset_user_hold_check_one(ds, htag,
113 dduha->dduha_minor != 0, tx);
114 dsl_dataset_rele(ds, FTAG);
115 }
116
117 if (error == 0) {
118 fnvlist_add_string(dduha->dduha_chkholds, name, htag);
119 } else {
120 /*
121 * We register ENOENT errors so they can be correctly
122 * reported if needed, such as when all holds fail.
123 */
124 fnvlist_add_int32(dduha->dduha_errlist, name, error);
125 if (error != ENOENT)
126 return (error);
127 }
128 }
129
130 return (0);
131}
132
133
134static void
135dsl_dataset_user_hold_sync_one_impl(nvlist_t *tmpholds, dsl_dataset_t *ds,
136 const char *htag, minor_t minor, uint64_t now, dmu_tx_t *tx)
137{
138 dsl_pool_t *dp = ds->ds_dir->dd_pool;
139 objset_t *mos = dp->dp_meta_objset;
140 uint64_t zapobj;
141
142 ASSERT(RRW_WRITE_HELD(&dp->dp_config_rwlock));
143
144 if (ds->ds_phys->ds_userrefs_obj == 0) {
145 /*
146 * This is the first user hold for this dataset. Create
147 * the userrefs zap object.
148 */
149 dmu_buf_will_dirty(ds->ds_dbuf, tx);
150 zapobj = ds->ds_phys->ds_userrefs_obj =
151 zap_create(mos, DMU_OT_USERREFS, DMU_OT_NONE, 0, tx);
152 } else {
153 zapobj = ds->ds_phys->ds_userrefs_obj;
154 }
155 ds->ds_userrefs++;
156
157 VERIFY0(zap_add(mos, zapobj, htag, 8, 1, &now, tx));
158
159 if (minor != 0) {
160 char name[MAXNAMELEN];
161 nvlist_t *tags;
162
163 VERIFY0(dsl_pool_user_hold(dp, ds->ds_object,
164 htag, now, tx));
165 (void) snprintf(name, sizeof (name), "%llx",
166 (u_longlong_t)ds->ds_object);
167
168 if (nvlist_lookup_nvlist(tmpholds, name, &tags) != 0) {
169 VERIFY0(nvlist_alloc(&tags, NV_UNIQUE_NAME,
170 KM_PUSHPAGE));
171 fnvlist_add_boolean(tags, htag);
172 fnvlist_add_nvlist(tmpholds, name, tags);
173 fnvlist_free(tags);
174 } else {
175 fnvlist_add_boolean(tags, htag);
176 }
177 }
178
179 spa_history_log_internal_ds(ds, "hold", tx,
180 "tag=%s temp=%d refs=%llu",
181 htag, minor != 0, ds->ds_userrefs);
182}
183
184typedef struct zfs_hold_cleanup_arg {
185 char zhca_spaname[MAXNAMELEN];
186 uint64_t zhca_spa_load_guid;
187 nvlist_t *zhca_holds;
188} zfs_hold_cleanup_arg_t;
189
190static void
191dsl_dataset_user_release_onexit(void *arg)
192{
193 zfs_hold_cleanup_arg_t *ca = arg;
194 spa_t *spa;
195 int error;
196
197 error = spa_open(ca->zhca_spaname, &spa, FTAG);
198 if (error != 0) {
199 zfs_dbgmsg("couldn't release holds on pool=%s "
200 "because pool is no longer loaded",
201 ca->zhca_spaname);
202 return;
203 }
204 if (spa_load_guid(spa) != ca->zhca_spa_load_guid) {
205 zfs_dbgmsg("couldn't release holds on pool=%s "
206 "because pool is no longer loaded (guid doesn't match)",
207 ca->zhca_spaname);
208 spa_close(spa, FTAG);
209 return;
210 }
211
212 (void) dsl_dataset_user_release_tmp(spa_get_dsl(spa), ca->zhca_holds);
213 fnvlist_free(ca->zhca_holds);
214 kmem_free(ca, sizeof (zfs_hold_cleanup_arg_t));
215 spa_close(spa, FTAG);
216}
217
218static void
219dsl_onexit_hold_cleanup(spa_t *spa, nvlist_t *holds, minor_t minor)
220{
221 zfs_hold_cleanup_arg_t *ca;
222
223 if (minor == 0 || nvlist_empty(holds)) {
224 fnvlist_free(holds);
225 return;
226 }
227
228 ASSERT(spa != NULL);
229 ca = kmem_alloc(sizeof (*ca), KM_PUSHPAGE);
230
231 (void) strlcpy(ca->zhca_spaname, spa_name(spa),
232 sizeof (ca->zhca_spaname));
233 ca->zhca_spa_load_guid = spa_load_guid(spa);
234 ca->zhca_holds = holds;
235 VERIFY0(zfs_onexit_add_cb(minor,
236 dsl_dataset_user_release_onexit, ca, NULL));
237}
238
239void
240dsl_dataset_user_hold_sync_one(dsl_dataset_t *ds, const char *htag,
241 minor_t minor, uint64_t now, dmu_tx_t *tx)
242{
243 nvlist_t *tmpholds;
244
245 if (minor != 0)
246 VERIFY0(nvlist_alloc(&tmpholds, NV_UNIQUE_NAME, KM_PUSHPAGE));
247 else
248 tmpholds = NULL;
249 dsl_dataset_user_hold_sync_one_impl(tmpholds, ds, htag, minor, now, tx);
250 dsl_onexit_hold_cleanup(dsl_dataset_get_spa(ds), tmpholds, minor);
251}
252
253static void
254dsl_dataset_user_hold_sync(void *arg, dmu_tx_t *tx)
255{
256 dsl_dataset_user_hold_arg_t *dduha = arg;
257 dsl_pool_t *dp = dmu_tx_pool(tx);
258 nvlist_t *tmpholds;
259 nvpair_t *pair;
260 uint64_t now = gethrestime_sec();
261
262 if (dduha->dduha_minor != 0)
263 VERIFY0(nvlist_alloc(&tmpholds, NV_UNIQUE_NAME, KM_PUSHPAGE));
264 else
265 tmpholds = NULL;
266 for (pair = nvlist_next_nvpair(dduha->dduha_chkholds, NULL);
267 pair != NULL;
268 pair = nvlist_next_nvpair(dduha->dduha_chkholds, pair)) {
269 dsl_dataset_t *ds;
270
271 VERIFY0(dsl_dataset_hold(dp, nvpair_name(pair), FTAG, &ds));
272 dsl_dataset_user_hold_sync_one_impl(tmpholds, ds,
273 fnvpair_value_string(pair), dduha->dduha_minor, now, tx);
274 dsl_dataset_rele(ds, FTAG);
275 }
276 dsl_onexit_hold_cleanup(dp->dp_spa, tmpholds, dduha->dduha_minor);
277}
278
279/*
280 * The full semantics of this function are described in the comment above
281 * lzc_hold().
282 *
283 * To summarize:
284 * holds is nvl of snapname -> holdname
285 * errlist will be filled in with snapname -> error
286 *
287 * The snaphosts must all be in the same pool.
288 *
289 * Holds for snapshots that don't exist will be skipped.
290 *
291 * If none of the snapshots for requested holds exist then ENOENT will be
292 * returned.
293 *
294 * If cleanup_minor is not 0, the holds will be temporary, which will be cleaned
295 * up when the process exits.
296 *
297 * On success all the holds, for snapshots that existed, will be created and 0
298 * will be returned.
299 *
300 * On failure no holds will be created, the errlist will be filled in,
301 * and an errno will returned.
302 *
303 * In all cases the errlist will contain entries for holds where the snapshot
304 * didn't exist.
305 */
306int
307dsl_dataset_user_hold(nvlist_t *holds, minor_t cleanup_minor, nvlist_t *errlist)
308{
309 dsl_dataset_user_hold_arg_t dduha;
310 nvpair_t *pair;
311 int ret;
312
313 pair = nvlist_next_nvpair(holds, NULL);
314 if (pair == NULL)
315 return (0);
316
317 dduha.dduha_holds = holds;
318 VERIFY0(nvlist_alloc(&dduha.dduha_chkholds, NV_UNIQUE_NAME,
319 KM_PUSHPAGE));
320 dduha.dduha_errlist = errlist;
321 dduha.dduha_minor = cleanup_minor;
322
323 ret = dsl_sync_task(nvpair_name(pair), dsl_dataset_user_hold_check,
324 dsl_dataset_user_hold_sync, &dduha, fnvlist_num_pairs(holds));
325 fnvlist_free(dduha.dduha_chkholds);
326
327 return (ret);
328}
329
330typedef int (dsl_holdfunc_t)(dsl_pool_t *dp, const char *name, void *tag,
331 dsl_dataset_t **dsp);
332
333typedef struct dsl_dataset_user_release_arg {
334 dsl_holdfunc_t *ddura_holdfunc;
335 nvlist_t *ddura_holds;
336 nvlist_t *ddura_todelete;
337 nvlist_t *ddura_errlist;
338 nvlist_t *ddura_chkholds;
339} dsl_dataset_user_release_arg_t;
340
341/* Place a dataset hold on the snapshot identified by passed dsobj string */
342static int
343dsl_dataset_hold_obj_string(dsl_pool_t *dp, const char *dsobj, void *tag,
344 dsl_dataset_t **dsp)
345{
346 return (dsl_dataset_hold_obj(dp, strtonum(dsobj, NULL), tag, dsp));
347}
348
349static int
350dsl_dataset_user_release_check_one(dsl_dataset_user_release_arg_t *ddura,
351 dsl_dataset_t *ds, nvlist_t *holds, const char *snapname)
352{
353 uint64_t zapobj;
354 nvlist_t *holds_found;
355 nvpair_t *pair;
356 objset_t *mos;
357 int numholds;
358
359 if (!dsl_dataset_is_snapshot(ds))
360 return (SET_ERROR(EINVAL));
361
362 if (nvlist_empty(holds))
363 return (0);
364
365 numholds = 0;
366 mos = ds->ds_dir->dd_pool->dp_meta_objset;
367 zapobj = ds->ds_phys->ds_userrefs_obj;
368 VERIFY0(nvlist_alloc(&holds_found, NV_UNIQUE_NAME, KM_PUSHPAGE));
369
370 for (pair = nvlist_next_nvpair(holds, NULL); pair != NULL;
371 pair = nvlist_next_nvpair(holds, pair)) {
372 uint64_t tmp;
373 int error;
374 const char *holdname = nvpair_name(pair);
375
376 if (zapobj != 0)
377 error = zap_lookup(mos, zapobj, holdname, 8, 1, &tmp);
378 else
379 error = SET_ERROR(ENOENT);
380
381 /*
382 * Non-existent holds are put on the errlist, but don't
383 * cause an overall failure.
384 */
385 if (error == ENOENT) {
386 if (ddura->ddura_errlist != NULL) {
387 char *errtag = kmem_asprintf("%s#%s",
388 snapname, holdname);
389 fnvlist_add_int32(ddura->ddura_errlist, errtag,
390 ENOENT);
391 strfree(errtag);
392 }
393 continue;
394 }
395
396 if (error != 0) {
397 fnvlist_free(holds_found);
398 return (error);
399 }
400
401 fnvlist_add_boolean(holds_found, holdname);
402 numholds++;
403 }
404
405 if (DS_IS_DEFER_DESTROY(ds) && ds->ds_phys->ds_num_children == 1 &&
406 ds->ds_userrefs == numholds) {
407 /* we need to destroy the snapshot as well */
408 if (dsl_dataset_long_held(ds)) {
409 fnvlist_free(holds_found);
410 return (SET_ERROR(EBUSY));
411 }
412 fnvlist_add_boolean(ddura->ddura_todelete, snapname);
413 }
414
415 if (numholds != 0) {
416 fnvlist_add_nvlist(ddura->ddura_chkholds, snapname,
417 holds_found);
418 }
419 fnvlist_free(holds_found);
420
421 return (0);
422}
423
424static int
425dsl_dataset_user_release_check(void *arg, dmu_tx_t *tx)
426{
427 dsl_dataset_user_release_arg_t *ddura;
428 dsl_holdfunc_t *holdfunc;
429 dsl_pool_t *dp;
430 nvpair_t *pair;
431
432 if (!dmu_tx_is_syncing(tx))
433 return (0);
434
435 dp = dmu_tx_pool(tx);
436
437 ASSERT(RRW_WRITE_HELD(&dp->dp_config_rwlock));
438
439 ddura = arg;
440 holdfunc = ddura->ddura_holdfunc;
441
442 for (pair = nvlist_next_nvpair(ddura->ddura_holds, NULL);
443 pair != NULL; pair = nvlist_next_nvpair(ddura->ddura_holds, pair)) {
444 int error;
445 dsl_dataset_t *ds;
446 nvlist_t *holds;
447 const char *snapname = nvpair_name(pair);
448
449 error = nvpair_value_nvlist(pair, &holds);
450 if (error != 0)
451 error = (SET_ERROR(EINVAL));
452 else
453 error = holdfunc(dp, snapname, FTAG, &ds);
454 if (error == 0) {
455 error = dsl_dataset_user_release_check_one(ddura, ds,
456 holds, snapname);
457 dsl_dataset_rele(ds, FTAG);
458 }
459 if (error != 0) {
460 if (ddura->ddura_errlist != NULL) {
461 fnvlist_add_int32(ddura->ddura_errlist,
462 snapname, error);
463 }
464 /*
465 * Non-existent snapshots are put on the errlist,
466 * but don't cause an overall failure.
467 */
468 if (error != ENOENT)
469 return (error);
470 }
471 }
472
473 return (0);
474}
475
476static void
477dsl_dataset_user_release_sync_one(dsl_dataset_t *ds, nvlist_t *holds,
478 dmu_tx_t *tx)
479{
480 dsl_pool_t *dp = ds->ds_dir->dd_pool;
481 objset_t *mos = dp->dp_meta_objset;
482 nvpair_t *pair;
483
484 for (pair = nvlist_next_nvpair(holds, NULL); pair != NULL;
485 pair = nvlist_next_nvpair(holds, pair)) {
486 int error;
487 const char *holdname = nvpair_name(pair);
488
489 /* Remove temporary hold if one exists. */
490 error = dsl_pool_user_release(dp, ds->ds_object, holdname, tx);
491 VERIFY(error == 0 || error == ENOENT);
492
493 VERIFY0(zap_remove(mos, ds->ds_phys->ds_userrefs_obj, holdname,
494 tx));
495 ds->ds_userrefs--;
496
497 spa_history_log_internal_ds(ds, "release", tx,
498 "tag=%s refs=%lld", holdname, (longlong_t)ds->ds_userrefs);
499 }
500}
501
502static void
503dsl_dataset_user_release_sync(void *arg, dmu_tx_t *tx)
504{
505 dsl_dataset_user_release_arg_t *ddura = arg;
506 dsl_holdfunc_t *holdfunc = ddura->ddura_holdfunc;
507 dsl_pool_t *dp = dmu_tx_pool(tx);
508 nvpair_t *pair;
509
510 ASSERT(RRW_WRITE_HELD(&dp->dp_config_rwlock));
511
512 for (pair = nvlist_next_nvpair(ddura->ddura_chkholds, NULL);
513 pair != NULL; pair = nvlist_next_nvpair(ddura->ddura_chkholds,
514 pair)) {
515 dsl_dataset_t *ds;
516 const char *name = nvpair_name(pair);
517
518 VERIFY0(holdfunc(dp, name, FTAG, &ds));
519
520 dsl_dataset_user_release_sync_one(ds,
521 fnvpair_value_nvlist(pair), tx);
522 if (nvlist_exists(ddura->ddura_todelete, name)) {
523 ASSERT(ds->ds_userrefs == 0 &&
524 ds->ds_phys->ds_num_children == 1 &&
525 DS_IS_DEFER_DESTROY(ds));
526 dsl_destroy_snapshot_sync_impl(ds, B_FALSE, tx);
527 }
528 dsl_dataset_rele(ds, FTAG);
529 }
530}
531
532/*
533 * The full semantics of this function are described in the comment above
534 * lzc_release().
535 *
536 * To summarize:
537 * Releases holds specified in the nvl holds.
538 *
539 * holds is nvl of snapname -> { holdname, ... }
540 * errlist will be filled in with snapname -> error
541 *
542 * If tmpdp is not NULL the names for holds should be the dsobj's of snapshots,
543 * otherwise they should be the names of shapshots.
544 *
545 * As a release may cause snapshots to be destroyed this trys to ensure they
546 * aren't mounted.
547 *
548 * The release of non-existent holds are skipped.
549 *
550 * At least one hold must have been released for the this function to succeed
551 * and return 0.
552 */
553static int
554dsl_dataset_user_release_impl(nvlist_t *holds, nvlist_t *errlist,
555 dsl_pool_t *tmpdp)
556{
557 dsl_dataset_user_release_arg_t ddura;
558 nvpair_t *pair;
559 char *pool;
560 int error;
561
562 pair = nvlist_next_nvpair(holds, NULL);
563 if (pair == NULL)
564 return (0);
565
566 /*
567 * The release may cause snapshots to be destroyed; make sure they
568 * are not mounted.
569 */
570 if (tmpdp != NULL) {
571 /* Temporary holds are specified by dsobj string. */
572 ddura.ddura_holdfunc = dsl_dataset_hold_obj_string;
573 pool = spa_name(tmpdp->dp_spa);
574#ifdef _KERNEL
575 for (pair = nvlist_next_nvpair(holds, NULL); pair != NULL;
576 pair = nvlist_next_nvpair(holds, pair)) {
577 dsl_dataset_t *ds;
578
579 dsl_pool_config_enter(tmpdp, FTAG);
580 error = dsl_dataset_hold_obj_string(tmpdp,
581 nvpair_name(pair), FTAG, &ds);
582 if (error == 0) {
583 char name[MAXNAMELEN];
584 dsl_dataset_name(ds, name);
585 dsl_pool_config_exit(tmpdp, FTAG);
586 dsl_dataset_rele(ds, FTAG);
587 (void) zfs_unmount_snap(name);
588 } else {
589 dsl_pool_config_exit(tmpdp, FTAG);
590 }
591 }
592#endif
593 } else {
594 /* Non-temporary holds are specified by name. */
595 ddura.ddura_holdfunc = dsl_dataset_hold;
596 pool = nvpair_name(pair);
597#ifdef _KERNEL
598 for (pair = nvlist_next_nvpair(holds, NULL); pair != NULL;
599 pair = nvlist_next_nvpair(holds, pair)) {
600 (void) zfs_unmount_snap(nvpair_name(pair));
601 }
602#endif
603 }
604
605 ddura.ddura_holds = holds;
606 ddura.ddura_errlist = errlist;
607 VERIFY0(nvlist_alloc(&ddura.ddura_todelete, NV_UNIQUE_NAME,
608 KM_PUSHPAGE));
609 VERIFY0(nvlist_alloc(&ddura.ddura_chkholds, NV_UNIQUE_NAME,
610 KM_PUSHPAGE));
611
612 error = dsl_sync_task(pool, dsl_dataset_user_release_check,
613 dsl_dataset_user_release_sync, &ddura, 0);
614 fnvlist_free(ddura.ddura_todelete);
615 fnvlist_free(ddura.ddura_chkholds);
616
617 return (error);
618}
619
620/*
621 * holds is nvl of snapname -> { holdname, ... }
622 * errlist will be filled in with snapname -> error
623 */
624int
625dsl_dataset_user_release(nvlist_t *holds, nvlist_t *errlist)
626{
627 return (dsl_dataset_user_release_impl(holds, errlist, NULL));
628}
629
630/*
631 * holds is nvl of snapdsobj -> { holdname, ... }
632 */
633void
634dsl_dataset_user_release_tmp(struct dsl_pool *dp, nvlist_t *holds)
635{
636 ASSERT(dp != NULL);
637 (void) dsl_dataset_user_release_impl(holds, NULL, dp);
638}
639
640int
641dsl_dataset_get_holds(const char *dsname, nvlist_t *nvl)
642{
643 dsl_pool_t *dp;
644 dsl_dataset_t *ds;
645 int err;
646
647 err = dsl_pool_hold(dsname, FTAG, &dp);
648 if (err != 0)
649 return (err);
650 err = dsl_dataset_hold(dp, dsname, FTAG, &ds);
651 if (err != 0) {
652 dsl_pool_rele(dp, FTAG);
653 return (err);
654 }
655
656 if (ds->ds_phys->ds_userrefs_obj != 0) {
657 zap_attribute_t *za;
658 zap_cursor_t zc;
659
660 za = kmem_alloc(sizeof (zap_attribute_t), KM_PUSHPAGE);
661 for (zap_cursor_init(&zc, ds->ds_dir->dd_pool->dp_meta_objset,
662 ds->ds_phys->ds_userrefs_obj);
663 zap_cursor_retrieve(&zc, za) == 0;
664 zap_cursor_advance(&zc)) {
665 fnvlist_add_uint64(nvl, za->za_name,
666 za->za_first_integer);
667 }
668 zap_cursor_fini(&zc);
669 kmem_free(za, sizeof (zap_attribute_t));
670 }
671 dsl_dataset_rele(ds, FTAG);
672 dsl_pool_rele(dp, FTAG);
673 return (0);
674}