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) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Copyright (c) 2013, Joyent, Inc. All rights reserved.
25 * Copyright (c) 2012 by Delphix. All rights reserved.
29 * Internal utility routines for the ZFS library.
43 #include <sys/mnttab.h>
44 #include <sys/mntent.h>
45 #include <sys/types.h>
49 #include <libzfs_core.h>
51 #include "libzfs_impl.h"
53 #include "zfeature_common.h"
56 libzfs_errno(libzfs_handle_t
*hdl
)
58 return (hdl
->libzfs_error
);
62 libzfs_error_init(int error
)
66 return (dgettext(TEXT_DOMAIN
, "The ZFS modules are not "
67 "loaded.\nTry running '/sbin/modprobe zfs' as root "
70 return (dgettext(TEXT_DOMAIN
, "The /dev/zfs device is "
71 "missing and must be created.\nTry running 'udevadm "
72 "trigger' as root to create it.\n"));
74 return (dgettext(TEXT_DOMAIN
, "The ZFS modules cannot be "
75 "auto-loaded.\nTry running '/sbin/modprobe zfs' as "
76 "root to manually load them.\n"));
78 return (dgettext(TEXT_DOMAIN
, "Permission denied the "
79 "ZFS utilities must be run as root.\n"));
81 return (dgettext(TEXT_DOMAIN
, "Failed to initialize the "
82 "libzfs library.\n"));
87 libzfs_error_action(libzfs_handle_t
*hdl
)
89 return (hdl
->libzfs_action
);
93 libzfs_error_description(libzfs_handle_t
*hdl
)
95 if (hdl
->libzfs_desc
[0] != '\0')
96 return (hdl
->libzfs_desc
);
98 switch (hdl
->libzfs_error
) {
100 return (dgettext(TEXT_DOMAIN
, "out of memory"));
102 return (dgettext(TEXT_DOMAIN
, "invalid property value"));
103 case EZFS_PROPREADONLY
:
104 return (dgettext(TEXT_DOMAIN
, "read-only property"));
106 return (dgettext(TEXT_DOMAIN
, "property doesn't apply to "
107 "datasets of this type"));
108 case EZFS_PROPNONINHERIT
:
109 return (dgettext(TEXT_DOMAIN
, "property cannot be inherited"));
111 return (dgettext(TEXT_DOMAIN
, "invalid quota or reservation"));
113 return (dgettext(TEXT_DOMAIN
, "operation not applicable to "
114 "datasets of this type"));
116 return (dgettext(TEXT_DOMAIN
, "pool or dataset is busy"));
118 return (dgettext(TEXT_DOMAIN
, "pool or dataset exists"));
120 return (dgettext(TEXT_DOMAIN
, "no such pool or dataset"));
122 return (dgettext(TEXT_DOMAIN
, "invalid backup stream"));
123 case EZFS_DSREADONLY
:
124 return (dgettext(TEXT_DOMAIN
, "dataset is read-only"));
126 return (dgettext(TEXT_DOMAIN
, "volume size exceeds limit for "
128 case EZFS_INVALIDNAME
:
129 return (dgettext(TEXT_DOMAIN
, "invalid name"));
130 case EZFS_BADRESTORE
:
131 return (dgettext(TEXT_DOMAIN
, "unable to restore to "
134 return (dgettext(TEXT_DOMAIN
, "backup failed"));
136 return (dgettext(TEXT_DOMAIN
, "invalid target vdev"));
138 return (dgettext(TEXT_DOMAIN
, "no such device in pool"));
140 return (dgettext(TEXT_DOMAIN
, "invalid device"));
141 case EZFS_NOREPLICAS
:
142 return (dgettext(TEXT_DOMAIN
, "no valid replicas"));
143 case EZFS_RESILVERING
:
144 return (dgettext(TEXT_DOMAIN
, "currently resilvering"));
145 case EZFS_BADVERSION
:
146 return (dgettext(TEXT_DOMAIN
, "unsupported version or "
148 case EZFS_POOLUNAVAIL
:
149 return (dgettext(TEXT_DOMAIN
, "pool is unavailable"));
150 case EZFS_DEVOVERFLOW
:
151 return (dgettext(TEXT_DOMAIN
, "too many devices in one vdev"));
153 return (dgettext(TEXT_DOMAIN
, "must be an absolute path"));
154 case EZFS_CROSSTARGET
:
155 return (dgettext(TEXT_DOMAIN
, "operation crosses datasets or "
158 return (dgettext(TEXT_DOMAIN
, "dataset in use by local zone"));
159 case EZFS_MOUNTFAILED
:
160 return (dgettext(TEXT_DOMAIN
, "mount failed"));
161 case EZFS_UMOUNTFAILED
:
162 return (dgettext(TEXT_DOMAIN
, "umount failed"));
163 case EZFS_UNSHARENFSFAILED
:
164 return (dgettext(TEXT_DOMAIN
, "unshare(1M) failed"));
165 case EZFS_SHARENFSFAILED
:
166 return (dgettext(TEXT_DOMAIN
, "share(1M) failed"));
167 case EZFS_UNSHARESMBFAILED
:
168 return (dgettext(TEXT_DOMAIN
, "smb remove share failed"));
169 case EZFS_SHARESMBFAILED
:
170 return (dgettext(TEXT_DOMAIN
, "smb add share failed"));
172 return (dgettext(TEXT_DOMAIN
, "permission denied"));
174 return (dgettext(TEXT_DOMAIN
, "out of space"));
176 return (dgettext(TEXT_DOMAIN
, "bad address"));
178 return (dgettext(TEXT_DOMAIN
, "I/O error"));
180 return (dgettext(TEXT_DOMAIN
, "signal received"));
182 return (dgettext(TEXT_DOMAIN
, "device is reserved as a hot "
184 case EZFS_INVALCONFIG
:
185 return (dgettext(TEXT_DOMAIN
, "invalid vdev configuration"));
187 return (dgettext(TEXT_DOMAIN
, "recursive dataset dependency"));
189 return (dgettext(TEXT_DOMAIN
, "no history available"));
191 return (dgettext(TEXT_DOMAIN
, "failed to retrieve "
193 case EZFS_POOL_NOTSUP
:
194 return (dgettext(TEXT_DOMAIN
, "operation not supported "
195 "on this type of pool"));
196 case EZFS_POOL_INVALARG
:
197 return (dgettext(TEXT_DOMAIN
, "invalid argument for "
198 "this pool operation"));
199 case EZFS_NAMETOOLONG
:
200 return (dgettext(TEXT_DOMAIN
, "dataset name is too long"));
201 case EZFS_OPENFAILED
:
202 return (dgettext(TEXT_DOMAIN
, "open failed"));
204 return (dgettext(TEXT_DOMAIN
,
205 "disk capacity information could not be retrieved"));
206 case EZFS_LABELFAILED
:
207 return (dgettext(TEXT_DOMAIN
, "write of label failed"));
209 return (dgettext(TEXT_DOMAIN
, "invalid user/group"));
211 return (dgettext(TEXT_DOMAIN
, "invalid permission"));
212 case EZFS_BADPERMSET
:
213 return (dgettext(TEXT_DOMAIN
, "invalid permission set name"));
214 case EZFS_NODELEGATION
:
215 return (dgettext(TEXT_DOMAIN
, "delegated administration is "
216 "disabled on pool"));
218 return (dgettext(TEXT_DOMAIN
, "invalid or missing cache file"));
220 return (dgettext(TEXT_DOMAIN
, "device is in use as a cache"));
221 case EZFS_VDEVNOTSUP
:
222 return (dgettext(TEXT_DOMAIN
, "vdev specification is not "
225 return (dgettext(TEXT_DOMAIN
, "operation not supported "
227 case EZFS_ACTIVE_SPARE
:
228 return (dgettext(TEXT_DOMAIN
, "pool has active shared spare "
230 case EZFS_UNPLAYED_LOGS
:
231 return (dgettext(TEXT_DOMAIN
, "log device has unplayed intent "
233 case EZFS_REFTAG_RELE
:
234 return (dgettext(TEXT_DOMAIN
, "no such tag on this dataset"));
235 case EZFS_REFTAG_HOLD
:
236 return (dgettext(TEXT_DOMAIN
, "tag already exists on this "
238 case EZFS_TAGTOOLONG
:
239 return (dgettext(TEXT_DOMAIN
, "tag too long"));
240 case EZFS_PIPEFAILED
:
241 return (dgettext(TEXT_DOMAIN
, "pipe create failed"));
242 case EZFS_THREADCREATEFAILED
:
243 return (dgettext(TEXT_DOMAIN
, "thread create failed"));
244 case EZFS_POSTSPLIT_ONLINE
:
245 return (dgettext(TEXT_DOMAIN
, "disk was split from this pool "
248 return (dgettext(TEXT_DOMAIN
, "currently scrubbing; "
249 "use 'zpool scrub -s' to cancel current scrub"));
251 return (dgettext(TEXT_DOMAIN
, "there is no active scrub"));
253 return (dgettext(TEXT_DOMAIN
, "unable to generate diffs"));
255 return (dgettext(TEXT_DOMAIN
, "invalid diff data"));
256 case EZFS_POOLREADONLY
:
257 return (dgettext(TEXT_DOMAIN
, "pool is read-only"));
259 return (dgettext(TEXT_DOMAIN
, "unknown error"));
261 assert(hdl
->libzfs_error
== 0);
262 return (dgettext(TEXT_DOMAIN
, "no error"));
268 zfs_error_aux(libzfs_handle_t
*hdl
, const char *fmt
, ...)
274 (void) vsnprintf(hdl
->libzfs_desc
, sizeof (hdl
->libzfs_desc
),
276 hdl
->libzfs_desc_active
= 1;
282 zfs_verror(libzfs_handle_t
*hdl
, int error
, const char *fmt
, va_list ap
)
284 (void) vsnprintf(hdl
->libzfs_action
, sizeof (hdl
->libzfs_action
),
286 hdl
->libzfs_error
= error
;
288 if (hdl
->libzfs_desc_active
)
289 hdl
->libzfs_desc_active
= 0;
291 hdl
->libzfs_desc
[0] = '\0';
293 if (hdl
->libzfs_printerr
) {
294 if (error
== EZFS_UNKNOWN
) {
295 (void) fprintf(stderr
, dgettext(TEXT_DOMAIN
, "internal "
296 "error: %s\n"), libzfs_error_description(hdl
));
300 (void) fprintf(stderr
, "%s: %s\n", hdl
->libzfs_action
,
301 libzfs_error_description(hdl
));
302 if (error
== EZFS_NOMEM
)
308 zfs_error(libzfs_handle_t
*hdl
, int error
, const char *msg
)
310 return (zfs_error_fmt(hdl
, error
, "%s", msg
));
315 zfs_error_fmt(libzfs_handle_t
*hdl
, int error
, const char *fmt
, ...)
321 zfs_verror(hdl
, error
, fmt
, ap
);
329 zfs_common_error(libzfs_handle_t
*hdl
, int error
, const char *fmt
,
335 zfs_verror(hdl
, EZFS_PERM
, fmt
, ap
);
339 zfs_verror(hdl
, EZFS_NODELEGATION
, fmt
, ap
);
343 zfs_verror(hdl
, EZFS_IO
, fmt
, ap
);
347 zfs_verror(hdl
, EZFS_FAULT
, fmt
, ap
);
351 zfs_verror(hdl
, EZFS_INTR
, fmt
, ap
);
359 zfs_standard_error(libzfs_handle_t
*hdl
, int error
, const char *msg
)
361 return (zfs_standard_error_fmt(hdl
, error
, "%s", msg
));
366 zfs_standard_error_fmt(libzfs_handle_t
*hdl
, int error
, const char *fmt
, ...)
372 if (zfs_common_error(hdl
, error
, fmt
, ap
) != 0) {
381 zfs_verror(hdl
, EZFS_IO
, fmt
, ap
);
385 zfs_error_aux(hdl
, dgettext(TEXT_DOMAIN
,
386 "dataset does not exist"));
387 zfs_verror(hdl
, EZFS_NOENT
, fmt
, ap
);
392 zfs_verror(hdl
, EZFS_NOSPC
, fmt
, ap
);
396 zfs_error_aux(hdl
, dgettext(TEXT_DOMAIN
,
397 "dataset already exists"));
398 zfs_verror(hdl
, EZFS_EXISTS
, fmt
, ap
);
402 zfs_error_aux(hdl
, dgettext(TEXT_DOMAIN
,
404 zfs_verror(hdl
, EZFS_BUSY
, fmt
, ap
);
407 zfs_verror(hdl
, EZFS_POOLREADONLY
, fmt
, ap
);
410 zfs_verror(hdl
, EZFS_NAMETOOLONG
, fmt
, ap
);
413 zfs_verror(hdl
, EZFS_BADVERSION
, fmt
, ap
);
416 zfs_error_aux(hdl
, dgettext(TEXT_DOMAIN
,
417 "pool I/O is currently suspended"));
418 zfs_verror(hdl
, EZFS_POOLUNAVAIL
, fmt
, ap
);
421 zfs_error_aux(hdl
, strerror(error
));
422 zfs_verror(hdl
, EZFS_UNKNOWN
, fmt
, ap
);
431 zpool_standard_error(libzfs_handle_t
*hdl
, int error
, const char *msg
)
433 return (zpool_standard_error_fmt(hdl
, error
, "%s", msg
));
438 zpool_standard_error_fmt(libzfs_handle_t
*hdl
, int error
, const char *fmt
, ...)
444 if (zfs_common_error(hdl
, error
, fmt
, ap
) != 0) {
451 zfs_verror(hdl
, EZFS_NODEVICE
, fmt
, ap
);
456 dgettext(TEXT_DOMAIN
, "no such pool or dataset"));
457 zfs_verror(hdl
, EZFS_NOENT
, fmt
, ap
);
461 zfs_error_aux(hdl
, dgettext(TEXT_DOMAIN
,
462 "pool already exists"));
463 zfs_verror(hdl
, EZFS_EXISTS
, fmt
, ap
);
467 zfs_error_aux(hdl
, dgettext(TEXT_DOMAIN
, "pool is busy"));
468 zfs_verror(hdl
, EZFS_BUSY
, fmt
, ap
);
472 zfs_error_aux(hdl
, dgettext(TEXT_DOMAIN
,
473 "one or more devices is currently unavailable"));
474 zfs_verror(hdl
, EZFS_BADDEV
, fmt
, ap
);
478 zfs_verror(hdl
, EZFS_DEVOVERFLOW
, fmt
, ap
);
482 zfs_verror(hdl
, EZFS_POOL_NOTSUP
, fmt
, ap
);
486 zfs_verror(hdl
, EZFS_POOL_INVALARG
, fmt
, ap
);
491 zfs_verror(hdl
, EZFS_NOSPC
, fmt
, ap
);
495 zfs_error_aux(hdl
, dgettext(TEXT_DOMAIN
,
496 "pool I/O is currently suspended"));
497 zfs_verror(hdl
, EZFS_POOLUNAVAIL
, fmt
, ap
);
501 zfs_verror(hdl
, EZFS_POOLREADONLY
, fmt
, ap
);
505 zfs_error_aux(hdl
, strerror(error
));
506 zfs_verror(hdl
, EZFS_UNKNOWN
, fmt
, ap
);
514 * Display an out of memory error message and abort the current program.
517 no_memory(libzfs_handle_t
*hdl
)
519 return (zfs_error(hdl
, EZFS_NOMEM
, "internal error"));
523 * A safe form of malloc() which will die if the allocation fails.
526 zfs_alloc(libzfs_handle_t
*hdl
, size_t size
)
530 if ((data
= calloc(1, size
)) == NULL
)
531 (void) no_memory(hdl
);
537 * A safe form of asprintf() which will die if the allocation fails.
541 zfs_asprintf(libzfs_handle_t
*hdl
, const char *fmt
, ...)
549 err
= vasprintf(&ret
, fmt
, ap
);
554 (void) no_memory(hdl
);
560 * A safe form of realloc(), which also zeroes newly allocated space.
563 zfs_realloc(libzfs_handle_t
*hdl
, void *ptr
, size_t oldsize
, size_t newsize
)
567 if ((ret
= realloc(ptr
, newsize
)) == NULL
) {
568 (void) no_memory(hdl
);
572 bzero((char *)ret
+ oldsize
, (newsize
- oldsize
));
577 * A safe form of strdup() which will die if the allocation fails.
580 zfs_strdup(libzfs_handle_t
*hdl
, const char *str
)
584 if ((ret
= strdup(str
)) == NULL
)
585 (void) no_memory(hdl
);
591 * Convert a number to an appropriately human-readable output.
594 zfs_nicenum(uint64_t num
, char *buf
, size_t buflen
)
600 while (n
>= 1024 && index
< 6) {
605 u
= " KMGTPE"[index
];
608 (void) snprintf(buf
, buflen
, "%llu", (u_longlong_t
) n
);
609 } else if ((num
& ((1ULL << 10 * index
) - 1)) == 0) {
611 * If this is an even multiple of the base, always display
612 * without any decimal precision.
614 (void) snprintf(buf
, buflen
, "%llu%c", (u_longlong_t
) n
, u
);
617 * We want to choose a precision that reflects the best choice
618 * for fitting in 5 characters. This can get rather tricky when
619 * we have numbers that are very close to an order of magnitude.
620 * For example, when displaying 10239 (which is really 9.999K),
621 * we want only a single place of precision for 10.0K. We could
622 * develop some complex heuristics for this, but it's much
623 * easier just to try each combination in turn.
626 for (i
= 2; i
>= 0; i
--) {
627 if (snprintf(buf
, buflen
, "%.*f%c", i
,
628 (double)num
/ (1ULL << 10 * index
), u
) <= 5)
635 libzfs_print_on_error(libzfs_handle_t
*hdl
, boolean_t printerr
)
637 hdl
->libzfs_printerr
= printerr
;
641 libzfs_module_loaded(const char *module
)
643 const char path_prefix
[] = "/sys/module/";
646 memcpy(path
, path_prefix
, sizeof (path_prefix
) - 1);
647 strcpy(path
+ sizeof (path_prefix
) - 1, module
);
649 return (access(path
, F_OK
) == 0);
653 libzfs_run_process(const char *path
, char *argv
[], int flags
)
656 int error
, devnull_fd
;
660 devnull_fd
= open("/dev/null", O_WRONLY
);
665 if (!(flags
& STDOUT_VERBOSE
))
666 (void) dup2(devnull_fd
, STDOUT_FILENO
);
668 if (!(flags
& STDERR_VERBOSE
))
669 (void) dup2(devnull_fd
, STDERR_FILENO
);
673 (void) execvp(path
, argv
);
675 } else if (pid
> 0) {
678 while ((error
= waitpid(pid
, &status
, 0)) == -1 &&
680 if (error
< 0 || !WIFEXITED(status
))
683 return (WEXITSTATUS(status
));
690 * Verify the required ZFS_DEV device is available and optionally attempt
691 * to load the ZFS modules. Under normal circumstances the modules
692 * should already have been loaded by some external mechanism.
694 * Environment variables:
695 * - ZFS_MODULE_LOADING="YES|yes|ON|on" - Attempt to load modules.
696 * - ZFS_MODULE_TIMEOUT="<seconds>" - Seconds to wait for ZFS_DEV
699 libzfs_load_module(const char *module
)
701 char *argv
[4] = {"/sbin/modprobe", "-q", (char *)module
, (char *)0};
702 char *load_str
, *timeout_str
;
703 long timeout
= 10; /* seconds */
704 long busy_timeout
= 10; /* milliseconds */
708 /* Optionally request module loading */
709 if (!libzfs_module_loaded(module
)) {
710 load_str
= getenv("ZFS_MODULE_LOADING");
712 if (!strncasecmp(load_str
, "YES", strlen("YES")) ||
713 !strncasecmp(load_str
, "ON", strlen("ON")))
719 if (load
&& libzfs_run_process("/sbin/modprobe", argv
, 0))
723 /* Module loading is synchronous it must be available */
724 if (!libzfs_module_loaded(module
))
728 * Device creation by udev is asynchronous and waiting may be
729 * required. Busy wait for 10ms and then fall back to polling every
730 * 10ms for the allowed timeout (default 10s, max 10m). This is
731 * done to optimize for the common case where the device is
732 * immediately available and to avoid penalizing the possible
733 * case where udev is slow or unable to create the device.
735 timeout_str
= getenv("ZFS_MODULE_TIMEOUT");
737 timeout
= strtol(timeout_str
, NULL
, 0);
738 timeout
= MAX(MIN(timeout
, (10 * 60)), 0); /* 0 <= N <= 600 */
743 fd
= open(ZFS_DEV
, O_RDWR
);
747 } else if (errno
!= ENOENT
) {
749 } else if (NSEC2MSEC(gethrtime() - start
) < busy_timeout
) {
752 usleep(10 * MILLISEC
);
754 } while (NSEC2MSEC(gethrtime() - start
) < (timeout
* MILLISEC
));
762 libzfs_handle_t
*hdl
;
765 error
= libzfs_load_module(ZFS_DRIVER
);
771 if ((hdl
= calloc(1, sizeof (libzfs_handle_t
))) == NULL
) {
775 if ((hdl
->libzfs_fd
= open(ZFS_DEV
, O_RDWR
)) < 0) {
780 #ifdef HAVE_SETMNTENT
781 if ((hdl
->libzfs_mnttab
= setmntent(MNTTAB
, "r")) == NULL
) {
783 if ((hdl
->libzfs_mnttab
= fopen(MNTTAB
, "r")) == NULL
) {
785 (void) close(hdl
->libzfs_fd
);
790 hdl
->libzfs_sharetab
= fopen("/etc/dfs/sharetab", "r");
792 if (libzfs_core_init() != 0) {
793 (void) close(hdl
->libzfs_fd
);
794 (void) fclose(hdl
->libzfs_mnttab
);
795 (void) fclose(hdl
->libzfs_sharetab
);
802 zpool_feature_init();
803 libzfs_mnttab_init(hdl
);
809 libzfs_fini(libzfs_handle_t
*hdl
)
811 (void) close(hdl
->libzfs_fd
);
812 if (hdl
->libzfs_mnttab
)
813 #ifdef HAVE_SETMNTENT
814 (void) endmntent(hdl
->libzfs_mnttab
);
816 (void) fclose(hdl
->libzfs_mnttab
);
818 if (hdl
->libzfs_sharetab
)
819 (void) fclose(hdl
->libzfs_sharetab
);
820 zfs_uninit_libshare(hdl
);
821 zpool_free_handles(hdl
);
822 libzfs_fru_clear(hdl
, B_TRUE
);
823 namespace_clear(hdl
);
824 libzfs_mnttab_fini(hdl
);
830 zpool_get_handle(zpool_handle_t
*zhp
)
832 return (zhp
->zpool_hdl
);
836 zfs_get_handle(zfs_handle_t
*zhp
)
838 return (zhp
->zfs_hdl
);
842 zfs_get_pool_handle(const zfs_handle_t
*zhp
)
844 return (zhp
->zpool_hdl
);
848 * Given a name, determine whether or not it's a valid path
849 * (starts with '/' or "./"). If so, walk the mnttab trying
850 * to match the device number. If not, treat the path as an
854 zfs_path_to_zhandle(libzfs_handle_t
*hdl
, char *path
, zfs_type_t argtype
)
856 struct stat64 statbuf
;
857 struct extmnttab entry
;
860 if (path
[0] != '/' && strncmp(path
, "./", strlen("./")) != 0) {
862 * It's not a valid path, assume it's a name of type 'argtype'.
864 return (zfs_open(hdl
, path
, argtype
));
867 if (stat64(path
, &statbuf
) != 0) {
868 (void) fprintf(stderr
, "%s: %s\n", path
, strerror(errno
));
872 /* Reopen MNTTAB to prevent reading stale data from open file */
873 if (freopen(MNTTAB
, "r", hdl
->libzfs_mnttab
) == NULL
)
876 while ((ret
= getextmntent(hdl
->libzfs_mnttab
, &entry
, 0)) == 0) {
877 if (makedevice(entry
.mnt_major
, entry
.mnt_minor
) ==
886 if (strcmp(entry
.mnt_fstype
, MNTTYPE_ZFS
) != 0) {
887 (void) fprintf(stderr
, gettext("'%s': not a ZFS filesystem\n"),
892 return (zfs_open(hdl
, entry
.mnt_special
, ZFS_TYPE_FILESYSTEM
));
896 * Append partition suffix to an otherwise fully qualified device path.
897 * This is used to generate the name the full path as its stored in
898 * ZPOOL_CONFIG_PATH for whole disk devices. On success the new length
899 * of 'path' will be returned on error a negative value is returned.
902 zfs_append_partition(char *path
, size_t max_len
)
904 int len
= strlen(path
);
906 if (strncmp(path
, UDISK_ROOT
, strlen(UDISK_ROOT
)) == 0) {
907 if (len
+ 6 >= max_len
)
910 (void) strcat(path
, "-part1");
913 if (len
+ 2 >= max_len
)
916 if (isdigit(path
[len
-1])) {
917 (void) strcat(path
, "p1");
920 (void) strcat(path
, "1");
929 * Given a shorthand device name check if a file by that name exists in any
930 * of the 'zpool_default_import_path' or ZPOOL_IMPORT_PATH directories. If
931 * one is found, store its fully qualified path in the 'path' buffer passed
932 * by the caller and return 0, otherwise return an error.
935 zfs_resolve_shortname(const char *name
, char *path
, size_t len
)
938 char *dir
, *env
, *envdup
;
940 env
= getenv("ZPOOL_IMPORT_PATH");
944 envdup
= strdup(env
);
945 dir
= strtok(envdup
, ":");
946 while (dir
&& error
) {
947 (void) snprintf(path
, len
, "%s/%s", dir
, name
);
948 error
= access(path
, F_OK
);
949 dir
= strtok(NULL
, ":");
953 for (i
= 0; i
< DEFAULT_IMPORT_PATH_SIZE
&& error
< 0; i
++) {
954 (void) snprintf(path
, len
, "%s/%s",
955 zpool_default_import_path
[i
], name
);
956 error
= access(path
, F_OK
);
960 return (error
? ENOENT
: 0);
964 * Given a shorthand device name look for a match against 'cmp_name'. This
965 * is done by checking all prefix expansions using either the default
966 * 'zpool_default_import_paths' or the ZPOOL_IMPORT_PATH environment
967 * variable. Proper partition suffixes will be appended if this is a
968 * whole disk. When a match is found 0 is returned otherwise ENOENT.
971 zfs_strcmp_shortname(char *name
, char *cmp_name
, int wholedisk
)
973 int path_len
, cmp_len
, i
= 0, error
= ENOENT
;
974 char *dir
, *env
, *envdup
= NULL
;
975 char path_name
[MAXPATHLEN
];
977 cmp_len
= strlen(cmp_name
);
978 env
= getenv("ZPOOL_IMPORT_PATH");
981 envdup
= strdup(env
);
982 dir
= strtok(envdup
, ":");
984 dir
= zpool_default_import_path
[i
];
988 /* Trim trailing directory slashes from ZPOOL_IMPORT_PATH */
989 while (dir
[strlen(dir
)-1] == '/')
990 dir
[strlen(dir
)-1] = '\0';
992 path_len
= snprintf(path_name
, MAXPATHLEN
, "%s/%s", dir
, name
);
994 path_len
= zfs_append_partition(path_name
, MAXPATHLEN
);
996 if ((path_len
== cmp_len
) && strcmp(path_name
, cmp_name
) == 0) {
1002 dir
= strtok(NULL
, ":");
1003 } else if (++i
< DEFAULT_IMPORT_PATH_SIZE
) {
1004 dir
= zpool_default_import_path
[i
];
1017 * Given either a shorthand or fully qualified path name look for a match
1018 * against 'cmp'. The passed name will be expanded as needed for comparison
1019 * purposes and redundant slashes stripped to ensure an accurate match.
1022 zfs_strcmp_pathname(char *name
, char *cmp
, int wholedisk
)
1024 int path_len
, cmp_len
;
1025 char path_name
[MAXPATHLEN
];
1026 char cmp_name
[MAXPATHLEN
];
1029 /* Strip redundant slashes if one exists due to ZPOOL_IMPORT_PATH */
1030 memset(cmp_name
, 0, MAXPATHLEN
);
1032 dir
= strtok(dup
, "/");
1034 strcat(cmp_name
, "/");
1035 strcat(cmp_name
, dir
);
1036 dir
= strtok(NULL
, "/");
1041 return (zfs_strcmp_shortname(name
, cmp_name
, wholedisk
));
1043 (void) strlcpy(path_name
, name
, MAXPATHLEN
);
1044 path_len
= strlen(path_name
);
1045 cmp_len
= strlen(cmp_name
);
1048 path_len
= zfs_append_partition(path_name
, MAXPATHLEN
);
1053 if ((path_len
!= cmp_len
) || strcmp(path_name
, cmp_name
))
1060 * Initialize the zc_nvlist_dst member to prepare for receiving an nvlist from
1064 zcmd_alloc_dst_nvlist(libzfs_handle_t
*hdl
, zfs_cmd_t
*zc
, size_t len
)
1068 zc
->zc_nvlist_dst_size
= len
;
1069 if ((zc
->zc_nvlist_dst
= (uint64_t)(uintptr_t)
1070 zfs_alloc(hdl
, zc
->zc_nvlist_dst_size
)) == 0)
1077 * Called when an ioctl() which returns an nvlist fails with ENOMEM. This will
1078 * expand the nvlist to the size specified in 'zc_nvlist_dst_size', which was
1079 * filled in by the kernel to indicate the actual required size.
1082 zcmd_expand_dst_nvlist(libzfs_handle_t
*hdl
, zfs_cmd_t
*zc
)
1084 free((void *)(uintptr_t)zc
->zc_nvlist_dst
);
1085 if ((zc
->zc_nvlist_dst
= (uint64_t)(uintptr_t)
1086 zfs_alloc(hdl
, zc
->zc_nvlist_dst_size
)) == 0)
1093 * Called to free the src and dst nvlists stored in the command structure.
1096 zcmd_free_nvlists(zfs_cmd_t
*zc
)
1098 free((void *)(uintptr_t)zc
->zc_nvlist_conf
);
1099 free((void *)(uintptr_t)zc
->zc_nvlist_src
);
1100 free((void *)(uintptr_t)zc
->zc_nvlist_dst
);
1104 zcmd_write_nvlist_com(libzfs_handle_t
*hdl
, uint64_t *outnv
, uint64_t *outlen
,
1110 verify(nvlist_size(nvl
, &len
, NV_ENCODE_NATIVE
) == 0);
1112 if ((packed
= zfs_alloc(hdl
, len
)) == NULL
)
1115 verify(nvlist_pack(nvl
, &packed
, &len
, NV_ENCODE_NATIVE
, 0) == 0);
1117 *outnv
= (uint64_t)(uintptr_t)packed
;
1124 zcmd_write_conf_nvlist(libzfs_handle_t
*hdl
, zfs_cmd_t
*zc
, nvlist_t
*nvl
)
1126 return (zcmd_write_nvlist_com(hdl
, &zc
->zc_nvlist_conf
,
1127 &zc
->zc_nvlist_conf_size
, nvl
));
1131 zcmd_write_src_nvlist(libzfs_handle_t
*hdl
, zfs_cmd_t
*zc
, nvlist_t
*nvl
)
1133 return (zcmd_write_nvlist_com(hdl
, &zc
->zc_nvlist_src
,
1134 &zc
->zc_nvlist_src_size
, nvl
));
1138 * Unpacks an nvlist from the ZFS ioctl command structure.
1141 zcmd_read_dst_nvlist(libzfs_handle_t
*hdl
, zfs_cmd_t
*zc
, nvlist_t
**nvlp
)
1143 if (nvlist_unpack((void *)(uintptr_t)zc
->zc_nvlist_dst
,
1144 zc
->zc_nvlist_dst_size
, nvlp
, 0) != 0)
1145 return (no_memory(hdl
));
1151 zfs_ioctl(libzfs_handle_t
*hdl
, int request
, zfs_cmd_t
*zc
)
1153 return (ioctl(hdl
->libzfs_fd
, request
, zc
));
1157 * ================================================================
1158 * API shared by zfs and zpool property management
1159 * ================================================================
1163 zprop_print_headers(zprop_get_cbdata_t
*cbp
, zfs_type_t type
)
1165 zprop_list_t
*pl
= cbp
->cb_proplist
;
1170 cbp
->cb_first
= B_FALSE
;
1171 if (cbp
->cb_scripted
)
1175 * Start with the length of the column headers.
1177 cbp
->cb_colwidths
[GET_COL_NAME
] = strlen(dgettext(TEXT_DOMAIN
, "NAME"));
1178 cbp
->cb_colwidths
[GET_COL_PROPERTY
] = strlen(dgettext(TEXT_DOMAIN
,
1180 cbp
->cb_colwidths
[GET_COL_VALUE
] = strlen(dgettext(TEXT_DOMAIN
,
1182 cbp
->cb_colwidths
[GET_COL_RECVD
] = strlen(dgettext(TEXT_DOMAIN
,
1184 cbp
->cb_colwidths
[GET_COL_SOURCE
] = strlen(dgettext(TEXT_DOMAIN
,
1187 /* first property is always NAME */
1188 assert(cbp
->cb_proplist
->pl_prop
==
1189 ((type
== ZFS_TYPE_POOL
) ? ZPOOL_PROP_NAME
: ZFS_PROP_NAME
));
1192 * Go through and calculate the widths for each column. For the
1193 * 'source' column, we kludge it up by taking the worst-case scenario of
1194 * inheriting from the longest name. This is acceptable because in the
1195 * majority of cases 'SOURCE' is the last column displayed, and we don't
1196 * use the width anyway. Note that the 'VALUE' column can be oversized,
1197 * if the name of the property is much longer than any values we find.
1199 for (pl
= cbp
->cb_proplist
; pl
!= NULL
; pl
= pl
->pl_next
) {
1203 if (pl
->pl_prop
!= ZPROP_INVAL
) {
1204 const char *propname
= (type
== ZFS_TYPE_POOL
) ?
1205 zpool_prop_to_name(pl
->pl_prop
) :
1206 zfs_prop_to_name(pl
->pl_prop
);
1208 len
= strlen(propname
);
1209 if (len
> cbp
->cb_colwidths
[GET_COL_PROPERTY
])
1210 cbp
->cb_colwidths
[GET_COL_PROPERTY
] = len
;
1212 len
= strlen(pl
->pl_user_prop
);
1213 if (len
> cbp
->cb_colwidths
[GET_COL_PROPERTY
])
1214 cbp
->cb_colwidths
[GET_COL_PROPERTY
] = len
;
1218 * 'VALUE' column. The first property is always the 'name'
1219 * property that was tacked on either by /sbin/zfs's
1220 * zfs_do_get() or when calling zprop_expand_list(), so we
1221 * ignore its width. If the user specified the name property
1222 * to display, then it will be later in the list in any case.
1224 if (pl
!= cbp
->cb_proplist
&&
1225 pl
->pl_width
> cbp
->cb_colwidths
[GET_COL_VALUE
])
1226 cbp
->cb_colwidths
[GET_COL_VALUE
] = pl
->pl_width
;
1228 /* 'RECEIVED' column. */
1229 if (pl
!= cbp
->cb_proplist
&&
1230 pl
->pl_recvd_width
> cbp
->cb_colwidths
[GET_COL_RECVD
])
1231 cbp
->cb_colwidths
[GET_COL_RECVD
] = pl
->pl_recvd_width
;
1234 * 'NAME' and 'SOURCE' columns
1236 if (pl
->pl_prop
== (type
== ZFS_TYPE_POOL
? ZPOOL_PROP_NAME
:
1238 pl
->pl_width
> cbp
->cb_colwidths
[GET_COL_NAME
]) {
1239 cbp
->cb_colwidths
[GET_COL_NAME
] = pl
->pl_width
;
1240 cbp
->cb_colwidths
[GET_COL_SOURCE
] = pl
->pl_width
+
1241 strlen(dgettext(TEXT_DOMAIN
, "inherited from"));
1246 * Now go through and print the headers.
1248 for (i
= 0; i
< ZFS_GET_NCOLS
; i
++) {
1249 switch (cbp
->cb_columns
[i
]) {
1251 title
= dgettext(TEXT_DOMAIN
, "NAME");
1253 case GET_COL_PROPERTY
:
1254 title
= dgettext(TEXT_DOMAIN
, "PROPERTY");
1257 title
= dgettext(TEXT_DOMAIN
, "VALUE");
1260 title
= dgettext(TEXT_DOMAIN
, "RECEIVED");
1262 case GET_COL_SOURCE
:
1263 title
= dgettext(TEXT_DOMAIN
, "SOURCE");
1269 if (title
!= NULL
) {
1270 if (i
== (ZFS_GET_NCOLS
- 1) ||
1271 cbp
->cb_columns
[i
+ 1] == GET_COL_NONE
)
1272 (void) printf("%s", title
);
1274 (void) printf("%-*s ",
1275 cbp
->cb_colwidths
[cbp
->cb_columns
[i
]],
1279 (void) printf("\n");
1283 * Display a single line of output, according to the settings in the callback
1287 zprop_print_one_property(const char *name
, zprop_get_cbdata_t
*cbp
,
1288 const char *propname
, const char *value
, zprop_source_t sourcetype
,
1289 const char *source
, const char *recvd_value
)
1292 const char *str
= NULL
;
1296 * Ignore those source types that the user has chosen to ignore.
1298 if ((sourcetype
& cbp
->cb_sources
) == 0)
1302 zprop_print_headers(cbp
, cbp
->cb_type
);
1304 for (i
= 0; i
< ZFS_GET_NCOLS
; i
++) {
1305 switch (cbp
->cb_columns
[i
]) {
1310 case GET_COL_PROPERTY
:
1318 case GET_COL_SOURCE
:
1319 switch (sourcetype
) {
1320 case ZPROP_SRC_NONE
:
1324 case ZPROP_SRC_DEFAULT
:
1328 case ZPROP_SRC_LOCAL
:
1332 case ZPROP_SRC_TEMPORARY
:
1336 case ZPROP_SRC_INHERITED
:
1337 (void) snprintf(buf
, sizeof (buf
),
1338 "inherited from %s", source
);
1341 case ZPROP_SRC_RECEIVED
:
1348 str
= (recvd_value
== NULL
? "-" : recvd_value
);
1355 if (cbp
->cb_columns
[i
+ 1] == GET_COL_NONE
)
1356 (void) printf("%s", str
);
1357 else if (cbp
->cb_scripted
)
1358 (void) printf("%s\t", str
);
1360 (void) printf("%-*s ",
1361 cbp
->cb_colwidths
[cbp
->cb_columns
[i
]],
1365 (void) printf("\n");
1369 * Given a numeric suffix, convert the value into a number of bits that the
1370 * resulting value must be shifted.
1373 str2shift(libzfs_handle_t
*hdl
, const char *buf
)
1375 const char *ends
= "BKMGTPEZ";
1380 for (i
= 0; i
< strlen(ends
); i
++) {
1381 if (toupper(buf
[0]) == ends
[i
])
1384 if (i
== strlen(ends
)) {
1386 zfs_error_aux(hdl
, dgettext(TEXT_DOMAIN
,
1387 "invalid numeric suffix '%s'"), buf
);
1392 * Allow 'G' = 'GB' = 'GiB', case-insensitively.
1393 * However, 'BB' and 'BiB' are disallowed.
1395 if (buf
[1] == '\0' ||
1396 (toupper(buf
[0]) != 'B' &&
1397 ((toupper(buf
[1]) == 'B' && buf
[2] == '\0') ||
1398 (toupper(buf
[1]) == 'I' && toupper(buf
[2]) == 'B' &&
1403 zfs_error_aux(hdl
, dgettext(TEXT_DOMAIN
,
1404 "invalid numeric suffix '%s'"), buf
);
1409 * Convert a string of the form '100G' into a real number. Used when setting
1410 * properties or creating a volume. 'buf' is used to place an extended error
1411 * message for the caller to use.
1414 zfs_nicestrtonum(libzfs_handle_t
*hdl
, const char *value
, uint64_t *num
)
1421 /* Check to see if this looks like a number. */
1422 if ((value
[0] < '0' || value
[0] > '9') && value
[0] != '.') {
1424 zfs_error_aux(hdl
, dgettext(TEXT_DOMAIN
,
1425 "bad numeric value '%s'"), value
);
1429 /* Rely on strtoull() to process the numeric portion. */
1431 *num
= strtoull(value
, &end
, 10);
1434 * Check for ERANGE, which indicates that the value is too large to fit
1435 * in a 64-bit value.
1437 if (errno
== ERANGE
) {
1439 zfs_error_aux(hdl
, dgettext(TEXT_DOMAIN
,
1440 "numeric value is too large"));
1445 * If we have a decimal value, then do the computation with floating
1446 * point arithmetic. Otherwise, use standard arithmetic.
1449 double fval
= strtod(value
, &end
);
1451 if ((shift
= str2shift(hdl
, end
)) == -1)
1454 fval
*= pow(2, shift
);
1456 if (fval
> UINT64_MAX
) {
1458 zfs_error_aux(hdl
, dgettext(TEXT_DOMAIN
,
1459 "numeric value is too large"));
1463 *num
= (uint64_t)fval
;
1465 if ((shift
= str2shift(hdl
, end
)) == -1)
1468 /* Check for overflow */
1469 if (shift
>= 64 || (*num
<< shift
) >> shift
!= *num
) {
1471 zfs_error_aux(hdl
, dgettext(TEXT_DOMAIN
,
1472 "numeric value is too large"));
1483 * Given a propname=value nvpair to set, parse any numeric properties
1484 * (index, boolean, etc) if they are specified as strings and add the
1485 * resulting nvpair to the returned nvlist.
1487 * At the DSL layer, all properties are either 64-bit numbers or strings.
1488 * We want the user to be able to ignore this fact and specify properties
1489 * as native values (numbers, for example) or as strings (to simplify
1490 * command line utilities). This also handles converting index types
1491 * (compression, checksum, etc) from strings to their on-disk index.
1494 zprop_parse_value(libzfs_handle_t
*hdl
, nvpair_t
*elem
, int prop
,
1495 zfs_type_t type
, nvlist_t
*ret
, char **svalp
, uint64_t *ivalp
,
1498 data_type_t datatype
= nvpair_type(elem
);
1499 zprop_type_t proptype
;
1500 const char *propname
;
1502 boolean_t isnone
= B_FALSE
;
1504 if (type
== ZFS_TYPE_POOL
) {
1505 proptype
= zpool_prop_get_type(prop
);
1506 propname
= zpool_prop_to_name(prop
);
1508 proptype
= zfs_prop_get_type(prop
);
1509 propname
= zfs_prop_to_name(prop
);
1513 * Convert any properties to the internal DSL value types.
1519 case PROP_TYPE_STRING
:
1520 if (datatype
!= DATA_TYPE_STRING
) {
1521 zfs_error_aux(hdl
, dgettext(TEXT_DOMAIN
,
1522 "'%s' must be a string"), nvpair_name(elem
));
1525 (void) nvpair_value_string(elem
, svalp
);
1526 if (strlen(*svalp
) >= ZFS_MAXPROPLEN
) {
1527 zfs_error_aux(hdl
, dgettext(TEXT_DOMAIN
,
1528 "'%s' is too long"), nvpair_name(elem
));
1533 case PROP_TYPE_NUMBER
:
1534 if (datatype
== DATA_TYPE_STRING
) {
1535 (void) nvpair_value_string(elem
, &value
);
1536 if (strcmp(value
, "none") == 0) {
1538 } else if (zfs_nicestrtonum(hdl
, value
, ivalp
)
1542 } else if (datatype
== DATA_TYPE_UINT64
) {
1543 (void) nvpair_value_uint64(elem
, ivalp
);
1545 zfs_error_aux(hdl
, dgettext(TEXT_DOMAIN
,
1546 "'%s' must be a number"), nvpair_name(elem
));
1551 * Quota special: force 'none' and don't allow 0.
1553 if ((type
& ZFS_TYPE_DATASET
) && *ivalp
== 0 && !isnone
&&
1554 (prop
== ZFS_PROP_QUOTA
|| prop
== ZFS_PROP_REFQUOTA
)) {
1555 zfs_error_aux(hdl
, dgettext(TEXT_DOMAIN
,
1556 "use 'none' to disable quota/refquota"));
1561 * Special handling for "*_limit=none". In this case it's not
1564 if ((type
& ZFS_TYPE_DATASET
) && isnone
&&
1565 (prop
== ZFS_PROP_FILESYSTEM_LIMIT
||
1566 prop
== ZFS_PROP_SNAPSHOT_LIMIT
)) {
1567 *ivalp
= UINT64_MAX
;
1571 case PROP_TYPE_INDEX
:
1572 if (datatype
!= DATA_TYPE_STRING
) {
1573 zfs_error_aux(hdl
, dgettext(TEXT_DOMAIN
,
1574 "'%s' must be a string"), nvpair_name(elem
));
1578 (void) nvpair_value_string(elem
, &value
);
1580 if (zprop_string_to_index(prop
, value
, ivalp
, type
) != 0) {
1581 zfs_error_aux(hdl
, dgettext(TEXT_DOMAIN
,
1582 "'%s' must be one of '%s'"), propname
,
1583 zprop_values(prop
, type
));
1593 * Add the result to our return set of properties.
1595 if (*svalp
!= NULL
) {
1596 if (nvlist_add_string(ret
, propname
, *svalp
) != 0) {
1597 (void) no_memory(hdl
);
1601 if (nvlist_add_uint64(ret
, propname
, *ivalp
) != 0) {
1602 (void) no_memory(hdl
);
1609 (void) zfs_error(hdl
, EZFS_BADPROP
, errbuf
);
1614 addlist(libzfs_handle_t
*hdl
, char *propname
, zprop_list_t
**listp
,
1618 zprop_list_t
*entry
;
1620 prop
= zprop_name_to_prop(propname
, type
);
1622 if (prop
!= ZPROP_INVAL
&& !zprop_valid_for_type(prop
, type
, B_FALSE
))
1626 * When no property table entry can be found, return failure if
1627 * this is a pool property or if this isn't a user-defined
1630 if (prop
== ZPROP_INVAL
&& ((type
== ZFS_TYPE_POOL
&&
1631 !zpool_prop_feature(propname
) &&
1632 !zpool_prop_unsupported(propname
)) ||
1633 (type
== ZFS_TYPE_DATASET
&& !zfs_prop_user(propname
) &&
1634 !zfs_prop_userquota(propname
) && !zfs_prop_written(propname
)))) {
1635 zfs_error_aux(hdl
, dgettext(TEXT_DOMAIN
,
1636 "invalid property '%s'"), propname
);
1637 return (zfs_error(hdl
, EZFS_BADPROP
,
1638 dgettext(TEXT_DOMAIN
, "bad property list")));
1641 if ((entry
= zfs_alloc(hdl
, sizeof (zprop_list_t
))) == NULL
)
1644 entry
->pl_prop
= prop
;
1645 if (prop
== ZPROP_INVAL
) {
1646 if ((entry
->pl_user_prop
= zfs_strdup(hdl
, propname
)) ==
1651 entry
->pl_width
= strlen(propname
);
1653 entry
->pl_width
= zprop_width(prop
, &entry
->pl_fixed
,
1663 * Given a comma-separated list of properties, construct a property list
1664 * containing both user-defined and native properties. This function will
1665 * return a NULL list if 'all' is specified, which can later be expanded
1666 * by zprop_expand_list().
1669 zprop_get_list(libzfs_handle_t
*hdl
, char *props
, zprop_list_t
**listp
,
1675 * If 'all' is specified, return a NULL list.
1677 if (strcmp(props
, "all") == 0)
1681 * If no props were specified, return an error.
1683 if (props
[0] == '\0') {
1684 zfs_error_aux(hdl
, dgettext(TEXT_DOMAIN
,
1685 "no properties specified"));
1686 return (zfs_error(hdl
, EZFS_BADPROP
, dgettext(TEXT_DOMAIN
,
1687 "bad property list")));
1691 * It would be nice to use getsubopt() here, but the inclusion of column
1692 * aliases makes this more effort than it's worth.
1694 while (*props
!= '\0') {
1699 if ((p
= strchr(props
, ',')) == NULL
) {
1700 len
= strlen(props
);
1707 * Check for empty options.
1710 zfs_error_aux(hdl
, dgettext(TEXT_DOMAIN
,
1711 "empty property name"));
1712 return (zfs_error(hdl
, EZFS_BADPROP
,
1713 dgettext(TEXT_DOMAIN
, "bad property list")));
1717 * Check all regular property names.
1722 if (strcmp(props
, "space") == 0) {
1723 static char *spaceprops
[] = {
1724 "name", "avail", "used", "usedbysnapshots",
1725 "usedbydataset", "usedbyrefreservation",
1726 "usedbychildren", NULL
1730 for (i
= 0; spaceprops
[i
]; i
++) {
1731 if (addlist(hdl
, spaceprops
[i
], listp
, type
))
1733 listp
= &(*listp
)->pl_next
;
1736 if (addlist(hdl
, props
, listp
, type
))
1738 listp
= &(*listp
)->pl_next
;
1750 zprop_free_list(zprop_list_t
*pl
)
1754 while (pl
!= NULL
) {
1756 free(pl
->pl_user_prop
);
1762 typedef struct expand_data
{
1763 zprop_list_t
**last
;
1764 libzfs_handle_t
*hdl
;
1769 zprop_expand_list_cb(int prop
, void *cb
)
1771 zprop_list_t
*entry
;
1772 expand_data_t
*edp
= cb
;
1774 if ((entry
= zfs_alloc(edp
->hdl
, sizeof (zprop_list_t
))) == NULL
)
1775 return (ZPROP_INVAL
);
1777 entry
->pl_prop
= prop
;
1778 entry
->pl_width
= zprop_width(prop
, &entry
->pl_fixed
, edp
->type
);
1779 entry
->pl_all
= B_TRUE
;
1781 *(edp
->last
) = entry
;
1782 edp
->last
= &entry
->pl_next
;
1784 return (ZPROP_CONT
);
1788 zprop_expand_list(libzfs_handle_t
*hdl
, zprop_list_t
**plp
, zfs_type_t type
)
1790 zprop_list_t
*entry
;
1791 zprop_list_t
**last
;
1796 * If this is the very first time we've been called for an 'all'
1797 * specification, expand the list to include all native
1806 if (zprop_iter_common(zprop_expand_list_cb
, &exp
, B_FALSE
,
1807 B_FALSE
, type
) == ZPROP_INVAL
)
1811 * Add 'name' to the beginning of the list, which is handled
1814 if ((entry
= zfs_alloc(hdl
, sizeof (zprop_list_t
))) == NULL
)
1817 entry
->pl_prop
= (type
== ZFS_TYPE_POOL
) ? ZPOOL_PROP_NAME
:
1819 entry
->pl_width
= zprop_width(entry
->pl_prop
,
1820 &entry
->pl_fixed
, type
);
1821 entry
->pl_all
= B_TRUE
;
1822 entry
->pl_next
= *plp
;
1829 zprop_iter(zprop_func func
, void *cb
, boolean_t show_all
, boolean_t ordered
,
1832 return (zprop_iter_common(func
, cb
, show_all
, ordered
, type
));