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.
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.
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]
23 * Copyright (c) 2012, 2014 by Delphix. All rights reserved.
24 * Copyright (c) 2013 Steven Hartland. All rights reserved.
25 * Copyright (c) 2014 Integros [integros.com]
26 * Copyright 2017 RackTop Systems.
30 * LibZFS_Core (lzc) is intended to replace most functionality in libzfs.
31 * It has the following characteristics:
33 * - Thread Safe. libzfs_core is accessible concurrently from multiple
34 * threads. This is accomplished primarily by avoiding global data
35 * (e.g. caching). Since it's thread-safe, there is no reason for a
36 * process to have multiple libzfs "instances". Therefore, we store
37 * our few pieces of data (e.g. the file descriptor) in global
38 * variables. The fd is reference-counted so that the libzfs_core
39 * library can be "initialized" multiple times (e.g. by different
40 * consumers within the same process).
42 * - Committed Interface. The libzfs_core interface will be committed,
43 * therefore consumers can compile against it and be confident that
44 * their code will continue to work on future releases of this code.
45 * Currently, the interface is Evolving (not Committed), but we intend
46 * to commit to it once it is more complete and we determine that it
47 * meets the needs of all consumers.
49 * - Programatic Error Handling. libzfs_core communicates errors with
50 * defined error numbers, and doesn't print anything to stdout/stderr.
52 * - Thin Layer. libzfs_core is a thin layer, marshaling arguments
53 * to/from the kernel ioctls. There is generally a 1:1 correspondence
54 * between libzfs_core functions and ioctls to /dev/zfs.
56 * - Clear Atomicity. Because libzfs_core functions are generally 1:1
57 * with kernel ioctls, and kernel ioctls are general atomic, each
58 * libzfs_core function is atomic. For example, creating multiple
59 * snapshots with a single call to lzc_snapshot() is atomic -- it
60 * can't fail with only some of the requested snapshots created, even
61 * in the event of power loss or system crash.
63 * - Continued libzfs Support. Some higher-level operations (e.g.
64 * support for "zfs send -R") are too complicated to fit the scope of
65 * libzfs_core. This functionality will continue to live in libzfs.
66 * Where appropriate, libzfs will use the underlying atomic operations
67 * of libzfs_core. For example, libzfs may implement "zfs send -R |
68 * zfs receive" by using individual "send one snapshot", rename,
69 * destroy, and "receive one snapshot" operations in libzfs_core.
70 * /sbin/zfs and /zbin/zpool will link with both libzfs and
71 * libzfs_core. Other consumers should aim to use only libzfs_core,
72 * since that will be the supported, stable interface going forwards.
75 #define _IN_LIBZFS_CORE_
77 #include <libzfs_core.h>
85 #include <sys/nvpair.h>
86 #include <sys/param.h>
87 #include <sys/types.h>
89 #include <sys/zfs_ioctl.h>
90 #include "libzfs_core_compat.h"
91 #include "libzfs_compat.h"
94 extern int zfs_ioctl_version;
98 static pthread_mutex_t g_lock = PTHREAD_MUTEX_INITIALIZER;
99 static int g_refcount;
102 libzfs_core_init(void)
104 (void) pthread_mutex_lock(&g_lock);
105 if (g_refcount == 0) {
106 g_fd = open("/dev/zfs", O_RDWR);
108 (void) pthread_mutex_unlock(&g_lock);
113 (void) pthread_mutex_unlock(&g_lock);
119 libzfs_core_fini(void)
121 (void) pthread_mutex_lock(&g_lock);
122 ASSERT3S(g_refcount, >, 0);
126 (void) pthread_mutex_unlock(&g_lock);
130 lzc_ioctl(zfs_ioc_t ioc, const char *name,
131 nvlist_t *source, nvlist_t **resultp)
133 zfs_cmd_t zc = { 0 };
141 ASSERT3S(g_refcount, >, 0);
143 (void) strlcpy(zc.zc_name, name, sizeof (zc.zc_name));
146 if (zfs_ioctl_version == ZFS_IOCVER_UNDEF)
147 zfs_ioctl_version = get_zfs_ioctl_version();
149 if (zfs_ioctl_version < ZFS_IOCVER_LZC) {
151 error = lzc_compat_pre(&zc, &ioc, &source);
157 packed = fnvlist_pack(source, &size);
158 zc.zc_nvlist_src = (uint64_t)(uintptr_t)packed;
159 zc.zc_nvlist_src_size = size;
161 if (resultp != NULL) {
163 zc.zc_nvlist_dst_size = MAX(size * 2, 128 * 1024);
164 zc.zc_nvlist_dst = (uint64_t)(uintptr_t)
165 malloc(zc.zc_nvlist_dst_size);
167 if (zc.zc_nvlist_dst == NULL) {
169 if (zc.zc_nvlist_dst == 0) {
176 while (ioctl(g_fd, ioc, &zc) != 0) {
177 if (errno == ENOMEM && resultp != NULL) {
178 free((void *)(uintptr_t)zc.zc_nvlist_dst);
179 zc.zc_nvlist_dst_size *= 2;
180 zc.zc_nvlist_dst = (uint64_t)(uintptr_t)
181 malloc(zc.zc_nvlist_dst_size);
183 if (zc.zc_nvlist_dst == NULL) {
185 if (zc.zc_nvlist_dst == 0) {
197 if (zfs_ioctl_version < ZFS_IOCVER_LZC)
198 lzc_compat_post(&zc, ioc);
200 if (zc.zc_nvlist_dst_filled) {
201 *resultp = fnvlist_unpack((void *)(uintptr_t)zc.zc_nvlist_dst,
202 zc.zc_nvlist_dst_size);
205 if (zfs_ioctl_version < ZFS_IOCVER_LZC)
206 lzc_compat_outnvl(&zc, ioc, resultp);
210 if (zfs_ioctl_version < ZFS_IOCVER_LZC) {
211 if (source != oldsource)
216 fnvlist_pack_free(packed, size);
217 free((void *)(uintptr_t)zc.zc_nvlist_dst);
222 lzc_create(const char *fsname, enum lzc_dataset_type type, nvlist_t *props)
225 nvlist_t *args = fnvlist_alloc();
226 fnvlist_add_int32(args, "type", (dmu_objset_type_t)type);
228 fnvlist_add_nvlist(args, "props", props);
229 error = lzc_ioctl(ZFS_IOC_CREATE, fsname, args, NULL);
235 lzc_clone(const char *fsname, const char *origin,
239 nvlist_t *args = fnvlist_alloc();
240 fnvlist_add_string(args, "origin", origin);
242 fnvlist_add_nvlist(args, "props", props);
243 error = lzc_ioctl(ZFS_IOC_CLONE, fsname, args, NULL);
249 lzc_promote(const char *fsname, char *snapnamebuf, int snapnamelen)
252 * The promote ioctl is still legacy, so we need to construct our
253 * own zfs_cmd_t rather than using lzc_ioctl().
255 zfs_cmd_t zc = { 0 };
257 ASSERT3S(g_refcount, >, 0);
258 VERIFY3S(g_fd, !=, -1);
260 (void) strlcpy(zc.zc_name, fsname, sizeof (zc.zc_name));
261 if (ioctl(g_fd, ZFS_IOC_PROMOTE, &zc) != 0) {
263 if (error == EEXIST && snapnamebuf != NULL)
264 (void) strlcpy(snapnamebuf, zc.zc_string, snapnamelen);
273 * The keys in the snaps nvlist are the snapshots to be created.
274 * They must all be in the same pool.
276 * The props nvlist is properties to set. Currently only user properties
277 * are supported. { user:prop_name -> string value }
279 * The returned results nvlist will have an entry for each snapshot that failed.
280 * The value will be the (int32) error code.
282 * The return value will be 0 if all snapshots were created, otherwise it will
283 * be the errno of a (unspecified) snapshot that failed.
286 lzc_snapshot(nvlist_t *snaps, nvlist_t *props, nvlist_t **errlist)
291 char pool[ZFS_MAX_DATASET_NAME_LEN];
295 /* determine the pool name */
296 elem = nvlist_next_nvpair(snaps, NULL);
299 (void) strlcpy(pool, nvpair_name(elem), sizeof (pool));
300 pool[strcspn(pool, "/@")] = '\0';
302 args = fnvlist_alloc();
303 fnvlist_add_nvlist(args, "snaps", snaps);
305 fnvlist_add_nvlist(args, "props", props);
307 error = lzc_ioctl(ZFS_IOC_SNAPSHOT, pool, args, errlist);
314 * Destroys snapshots.
316 * The keys in the snaps nvlist are the snapshots to be destroyed.
317 * They must all be in the same pool.
319 * Snapshots that do not exist will be silently ignored.
321 * If 'defer' is not set, and a snapshot has user holds or clones, the
322 * destroy operation will fail and none of the snapshots will be
325 * If 'defer' is set, and a snapshot has user holds or clones, it will be
326 * marked for deferred destruction, and will be destroyed when the last hold
327 * or clone is removed/destroyed.
329 * The return value will be 0 if all snapshots were destroyed (or marked for
330 * later destruction if 'defer' is set) or didn't exist to begin with.
332 * Otherwise the return value will be the errno of a (unspecified) snapshot
333 * that failed, no snapshots will be destroyed, and the errlist will have an
334 * entry for each snapshot that failed. The value in the errlist will be
335 * the (int32) error code.
338 lzc_destroy_snaps(nvlist_t *snaps, boolean_t defer, nvlist_t **errlist)
343 char pool[ZFS_MAX_DATASET_NAME_LEN];
345 /* determine the pool name */
346 elem = nvlist_next_nvpair(snaps, NULL);
349 (void) strlcpy(pool, nvpair_name(elem), sizeof (pool));
350 pool[strcspn(pool, "/@")] = '\0';
352 args = fnvlist_alloc();
353 fnvlist_add_nvlist(args, "snaps", snaps);
355 fnvlist_add_boolean(args, "defer");
357 error = lzc_ioctl(ZFS_IOC_DESTROY_SNAPS, pool, args, errlist);
364 lzc_snaprange_space(const char *firstsnap, const char *lastsnap,
370 char fs[ZFS_MAX_DATASET_NAME_LEN];
373 /* determine the fs name */
374 (void) strlcpy(fs, firstsnap, sizeof (fs));
375 atp = strchr(fs, '@');
380 args = fnvlist_alloc();
381 fnvlist_add_string(args, "firstsnap", firstsnap);
383 err = lzc_ioctl(ZFS_IOC_SPACE_SNAPS, lastsnap, args, &result);
386 *usedp = fnvlist_lookup_uint64(result, "used");
387 fnvlist_free(result);
393 lzc_exists(const char *dataset)
396 * The objset_stats ioctl is still legacy, so we need to construct our
397 * own zfs_cmd_t rather than using lzc_ioctl().
399 zfs_cmd_t zc = { 0 };
401 (void) strlcpy(zc.zc_name, dataset, sizeof (zc.zc_name));
402 return (ioctl(g_fd, ZFS_IOC_OBJSET_STATS, &zc) == 0);
406 * Create "user holds" on snapshots. If there is a hold on a snapshot,
407 * the snapshot can not be destroyed. (However, it can be marked for deletion
408 * by lzc_destroy_snaps(defer=B_TRUE).)
410 * The keys in the nvlist are snapshot names.
411 * The snapshots must all be in the same pool.
412 * The value is the name of the hold (string type).
414 * If cleanup_fd is not -1, it must be the result of open("/dev/zfs", O_EXCL).
415 * In this case, when the cleanup_fd is closed (including on process
416 * termination), the holds will be released. If the system is shut down
417 * uncleanly, the holds will be released when the pool is next opened
420 * Holds for snapshots which don't exist will be skipped and have an entry
421 * added to errlist, but will not cause an overall failure.
423 * The return value will be 0 if all holds, for snapshots that existed,
424 * were succesfully created.
426 * Otherwise the return value will be the errno of a (unspecified) hold that
427 * failed and no holds will be created.
429 * In all cases the errlist will have an entry for each hold that failed
430 * (name = snapshot), with its value being the error code (int32).
433 lzc_hold(nvlist_t *holds, int cleanup_fd, nvlist_t **errlist)
435 char pool[ZFS_MAX_DATASET_NAME_LEN];
440 /* determine the pool name */
441 elem = nvlist_next_nvpair(holds, NULL);
444 (void) strlcpy(pool, nvpair_name(elem), sizeof (pool));
445 pool[strcspn(pool, "/@")] = '\0';
447 args = fnvlist_alloc();
448 fnvlist_add_nvlist(args, "holds", holds);
449 if (cleanup_fd != -1)
450 fnvlist_add_int32(args, "cleanup_fd", cleanup_fd);
452 error = lzc_ioctl(ZFS_IOC_HOLD, pool, args, errlist);
458 * Release "user holds" on snapshots. If the snapshot has been marked for
459 * deferred destroy (by lzc_destroy_snaps(defer=B_TRUE)), it does not have
460 * any clones, and all the user holds are removed, then the snapshot will be
463 * The keys in the nvlist are snapshot names.
464 * The snapshots must all be in the same pool.
465 * The value is a nvlist whose keys are the holds to remove.
467 * Holds which failed to release because they didn't exist will have an entry
468 * added to errlist, but will not cause an overall failure.
470 * The return value will be 0 if the nvl holds was empty or all holds that
471 * existed, were successfully removed.
473 * Otherwise the return value will be the errno of a (unspecified) hold that
474 * failed to release and no holds will be released.
476 * In all cases the errlist will have an entry for each hold that failed to
480 lzc_release(nvlist_t *holds, nvlist_t **errlist)
482 char pool[ZFS_MAX_DATASET_NAME_LEN];
485 /* determine the pool name */
486 elem = nvlist_next_nvpair(holds, NULL);
489 (void) strlcpy(pool, nvpair_name(elem), sizeof (pool));
490 pool[strcspn(pool, "/@")] = '\0';
492 return (lzc_ioctl(ZFS_IOC_RELEASE, pool, holds, errlist));
496 * Retrieve list of user holds on the specified snapshot.
498 * On success, *holdsp will be set to a nvlist which the caller must free.
499 * The keys are the names of the holds, and the value is the creation time
500 * of the hold (uint64) in seconds since the epoch.
503 lzc_get_holds(const char *snapname, nvlist_t **holdsp)
506 nvlist_t *innvl = fnvlist_alloc();
507 error = lzc_ioctl(ZFS_IOC_GET_HOLDS, snapname, innvl, holdsp);
513 * Generate a zfs send stream for the specified snapshot and write it to
514 * the specified file descriptor.
516 * "snapname" is the full name of the snapshot to send (e.g. "pool/fs@snap")
518 * If "from" is NULL, a full (non-incremental) stream will be sent.
519 * If "from" is non-NULL, it must be the full name of a snapshot or
520 * bookmark to send an incremental from (e.g. "pool/fs@earlier_snap" or
521 * "pool/fs#earlier_bmark"). If non-NULL, the specified snapshot or
522 * bookmark must represent an earlier point in the history of "snapname").
523 * It can be an earlier snapshot in the same filesystem or zvol as "snapname",
524 * or it can be the origin of "snapname"'s filesystem, or an earlier
525 * snapshot in the origin, etc.
527 * "fd" is the file descriptor to write the send stream to.
529 * If "flags" contains LZC_SEND_FLAG_LARGE_BLOCK, the stream is permitted
530 * to contain DRR_WRITE records with drr_length > 128K, and DRR_OBJECT
531 * records with drr_blksz > 128K.
533 * If "flags" contains LZC_SEND_FLAG_EMBED_DATA, the stream is permitted
534 * to contain DRR_WRITE_EMBEDDED records with drr_etype==BP_EMBEDDED_TYPE_DATA,
535 * which the receiving system must support (as indicated by support
536 * for the "embedded_data" feature).
539 lzc_send(const char *snapname, const char *from, int fd,
540 enum lzc_send_flags flags)
542 return (lzc_send_resume(snapname, from, fd, flags, 0, 0));
546 lzc_send_resume(const char *snapname, const char *from, int fd,
547 enum lzc_send_flags flags, uint64_t resumeobj, uint64_t resumeoff)
552 args = fnvlist_alloc();
553 fnvlist_add_int32(args, "fd", fd);
555 fnvlist_add_string(args, "fromsnap", from);
556 if (flags & LZC_SEND_FLAG_LARGE_BLOCK)
557 fnvlist_add_boolean(args, "largeblockok");
558 if (flags & LZC_SEND_FLAG_EMBED_DATA)
559 fnvlist_add_boolean(args, "embedok");
560 if (flags & LZC_SEND_FLAG_COMPRESS)
561 fnvlist_add_boolean(args, "compressok");
562 if (resumeobj != 0 || resumeoff != 0) {
563 fnvlist_add_uint64(args, "resume_object", resumeobj);
564 fnvlist_add_uint64(args, "resume_offset", resumeoff);
566 err = lzc_ioctl(ZFS_IOC_SEND_NEW, snapname, args, NULL);
572 * "from" can be NULL, a snapshot, or a bookmark.
574 * If from is NULL, a full (non-incremental) stream will be estimated. This
575 * is calculated very efficiently.
577 * If from is a snapshot, lzc_send_space uses the deadlists attached to
578 * each snapshot to efficiently estimate the stream size.
580 * If from is a bookmark, the indirect blocks in the destination snapshot
581 * are traversed, looking for blocks with a birth time since the creation TXG of
582 * the snapshot this bookmark was created from. This will result in
583 * significantly more I/O and be less efficient than a send space estimation on
584 * an equivalent snapshot.
587 lzc_send_space(const char *snapname, const char *from,
588 enum lzc_send_flags flags, uint64_t *spacep)
594 args = fnvlist_alloc();
596 fnvlist_add_string(args, "from", from);
597 if (flags & LZC_SEND_FLAG_LARGE_BLOCK)
598 fnvlist_add_boolean(args, "largeblockok");
599 if (flags & LZC_SEND_FLAG_EMBED_DATA)
600 fnvlist_add_boolean(args, "embedok");
601 if (flags & LZC_SEND_FLAG_COMPRESS)
602 fnvlist_add_boolean(args, "compressok");
603 err = lzc_ioctl(ZFS_IOC_SEND_SPACE, snapname, args, &result);
606 *spacep = fnvlist_lookup_uint64(result, "space");
612 recv_read(int fd, void *buf, int ilen)
619 rv = read(fd, cp, len);
624 if (rv < 0 || len != 0)
631 recv_impl(const char *snapname, nvlist_t *props, const char *origin,
632 boolean_t force, boolean_t resumable, int fd,
633 const dmu_replay_record_t *begin_record)
636 * The receive ioctl is still legacy, so we need to construct our own
637 * zfs_cmd_t rather than using zfsc_ioctl().
639 zfs_cmd_t zc = { 0 };
645 ASSERT3S(g_refcount, >, 0);
647 /* zc_name is name of containing filesystem */
648 (void) strlcpy(zc.zc_name, snapname, sizeof (zc.zc_name));
649 atp = strchr(zc.zc_name, '@');
654 /* if the fs does not exist, try its parent. */
655 if (!lzc_exists(zc.zc_name)) {
656 char *slashp = strrchr(zc.zc_name, '/');
663 /* zc_value is full name of the snapshot to create */
664 (void) strlcpy(zc.zc_value, snapname, sizeof (zc.zc_value));
667 /* zc_nvlist_src is props to set */
668 packed = fnvlist_pack(props, &size);
669 zc.zc_nvlist_src = (uint64_t)(uintptr_t)packed;
670 zc.zc_nvlist_src_size = size;
673 /* zc_string is name of clone origin (if DRR_FLAG_CLONE) */
675 (void) strlcpy(zc.zc_string, origin, sizeof (zc.zc_string));
677 /* zc_begin_record is non-byteswapped BEGIN record */
678 if (begin_record == NULL) {
679 error = recv_read(fd, &zc.zc_begin_record,
680 sizeof (zc.zc_begin_record));
684 zc.zc_begin_record = *begin_record;
687 /* zc_cookie is fd to read from */
690 /* zc guid is force flag */
693 zc.zc_resumable = resumable;
695 /* zc_cleanup_fd is unused */
696 zc.zc_cleanup_fd = -1;
698 error = ioctl(g_fd, ZFS_IOC_RECV, &zc);
704 fnvlist_pack_free(packed, size);
705 free((void*)(uintptr_t)zc.zc_nvlist_dst);
710 * The simplest receive case: receive from the specified fd, creating the
711 * specified snapshot. Apply the specified properties as "received" properties
712 * (which can be overridden by locally-set properties). If the stream is a
713 * clone, its origin snapshot must be specified by 'origin'. The 'force'
714 * flag will cause the target filesystem to be rolled back or destroyed if
715 * necessary to receive.
717 * Return 0 on success or an errno on failure.
719 * Note: this interface does not work on dedup'd streams
720 * (those with DMU_BACKUP_FEATURE_DEDUP).
723 lzc_receive(const char *snapname, nvlist_t *props, const char *origin,
724 boolean_t force, int fd)
726 return (recv_impl(snapname, props, origin, force, B_FALSE, fd, NULL));
730 * Like lzc_receive, but if the receive fails due to premature stream
731 * termination, the intermediate state will be preserved on disk. In this
732 * case, ECKSUM will be returned. The receive may subsequently be resumed
733 * with a resuming send stream generated by lzc_send_resume().
736 lzc_receive_resumable(const char *snapname, nvlist_t *props, const char *origin,
737 boolean_t force, int fd)
739 return (recv_impl(snapname, props, origin, force, B_TRUE, fd, NULL));
743 * Like lzc_receive, but allows the caller to read the begin record and then to
744 * pass it in. That could be useful if the caller wants to derive, for example,
745 * the snapname or the origin parameters based on the information contained in
747 * The begin record must be in its original form as read from the stream,
748 * in other words, it should not be byteswapped.
750 * The 'resumable' parameter allows to obtain the same behavior as with
751 * lzc_receive_resumable.
754 lzc_receive_with_header(const char *snapname, nvlist_t *props,
755 const char *origin, boolean_t force, boolean_t resumable, int fd,
756 const dmu_replay_record_t *begin_record)
758 if (begin_record == NULL)
760 return (recv_impl(snapname, props, origin, force, resumable, fd,
765 * Roll back this filesystem or volume to its most recent snapshot.
766 * If snapnamebuf is not NULL, it will be filled in with the name
767 * of the most recent snapshot.
769 * Return 0 on success or an errno on failure.
772 lzc_rollback(const char *fsname, char *snapnamebuf, int snapnamelen)
778 args = fnvlist_alloc();
779 err = lzc_ioctl(ZFS_IOC_ROLLBACK, fsname, args, &result);
781 if (err == 0 && snapnamebuf != NULL) {
782 const char *snapname = fnvlist_lookup_string(result, "target");
783 (void) strlcpy(snapnamebuf, snapname, snapnamelen);
793 * The bookmarks nvlist maps from name of the bookmark (e.g. "pool/fs#bmark") to
794 * the name of the snapshot (e.g. "pool/fs@snap"). All the bookmarks and
795 * snapshots must be in the same pool.
797 * The returned results nvlist will have an entry for each bookmark that failed.
798 * The value will be the (int32) error code.
800 * The return value will be 0 if all bookmarks were created, otherwise it will
801 * be the errno of a (undetermined) bookmarks that failed.
804 lzc_bookmark(nvlist_t *bookmarks, nvlist_t **errlist)
808 char pool[ZFS_MAX_DATASET_NAME_LEN];
810 /* determine the pool name */
811 elem = nvlist_next_nvpair(bookmarks, NULL);
814 (void) strlcpy(pool, nvpair_name(elem), sizeof (pool));
815 pool[strcspn(pool, "/#")] = '\0';
817 error = lzc_ioctl(ZFS_IOC_BOOKMARK, pool, bookmarks, errlist);
823 * Retrieve bookmarks.
825 * Retrieve the list of bookmarks for the given file system. The props
826 * parameter is an nvlist of property names (with no values) that will be
827 * returned for each bookmark.
829 * The following are valid properties on bookmarks, all of which are numbers
830 * (represented as uint64 in the nvlist)
832 * "guid" - globally unique identifier of the snapshot it refers to
833 * "createtxg" - txg when the snapshot it refers to was created
834 * "creation" - timestamp when the snapshot it refers to was created
836 * The format of the returned nvlist as follows:
837 * <short name of bookmark> -> {
838 * <name of property> -> {
844 lzc_get_bookmarks(const char *fsname, nvlist_t *props, nvlist_t **bmarks)
846 return (lzc_ioctl(ZFS_IOC_GET_BOOKMARKS, fsname, props, bmarks));
850 * Destroys bookmarks.
852 * The keys in the bmarks nvlist are the bookmarks to be destroyed.
853 * They must all be in the same pool. Bookmarks are specified as
856 * Bookmarks that do not exist will be silently ignored.
858 * The return value will be 0 if all bookmarks that existed were destroyed.
860 * Otherwise the return value will be the errno of a (undetermined) bookmark
861 * that failed, no bookmarks will be destroyed, and the errlist will have an
862 * entry for each bookmarks that failed. The value in the errlist will be
863 * the (int32) error code.
866 lzc_destroy_bookmarks(nvlist_t *bmarks, nvlist_t **errlist)
870 char pool[ZFS_MAX_DATASET_NAME_LEN];
872 /* determine the pool name */
873 elem = nvlist_next_nvpair(bmarks, NULL);
876 (void) strlcpy(pool, nvpair_name(elem), sizeof (pool));
877 pool[strcspn(pool, "/#")] = '\0';
879 error = lzc_ioctl(ZFS_IOC_DESTROY_BOOKMARKS, pool, bmarks, errlist);