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]
22 * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
23 * Copyright (c) 2012 by Delphix. All rights reserved.
27 * This file is intended for functions that ought to be common between user
28 * land (libzfs) and the kernel. When many common routines need to be shared
29 * then a separate file should to be created.
33 #include <sys/systm.h>
38 #include <sys/types.h>
39 #include <sys/fs/zfs.h>
40 #include <sys/int_limits.h>
41 #include <sys/nvpair.h>
42 #include "zfs_comutil.h"
45 * Are there allocatable vdevs?
48 zfs_allocatable_devs(nvlist_t
*nv
)
55 if (nvlist_lookup_nvlist_array(nv
, ZPOOL_CONFIG_CHILDREN
,
56 &child
, &children
) != 0) {
59 for (c
= 0; c
< children
; c
++) {
61 (void) nvlist_lookup_uint64(child
[c
], ZPOOL_CONFIG_IS_LOG
,
70 zpool_get_rewind_policy(nvlist_t
*nvl
, zpool_rewind_policy_t
*zrpp
)
77 zrpp
->zrp_request
= ZPOOL_NO_REWIND
;
78 zrpp
->zrp_maxmeta
= 0;
79 zrpp
->zrp_maxdata
= UINT64_MAX
;
80 zrpp
->zrp_txg
= UINT64_MAX
;
86 while ((elem
= nvlist_next_nvpair(nvl
, elem
)) != NULL
) {
87 nm
= nvpair_name(elem
);
88 if (strcmp(nm
, ZPOOL_REWIND_POLICY
) == 0) {
89 if (nvpair_value_nvlist(elem
, &policy
) == 0)
90 zpool_get_rewind_policy(policy
, zrpp
);
92 } else if (strcmp(nm
, ZPOOL_REWIND_REQUEST
) == 0) {
93 if (nvpair_value_uint32(elem
, &zrpp
->zrp_request
) == 0)
94 if (zrpp
->zrp_request
& ~ZPOOL_REWIND_POLICIES
)
95 zrpp
->zrp_request
= ZPOOL_NO_REWIND
;
96 } else if (strcmp(nm
, ZPOOL_REWIND_REQUEST_TXG
) == 0) {
97 (void) nvpair_value_uint64(elem
, &zrpp
->zrp_txg
);
98 } else if (strcmp(nm
, ZPOOL_REWIND_META_THRESH
) == 0) {
99 (void) nvpair_value_uint64(elem
, &zrpp
->zrp_maxmeta
);
100 } else if (strcmp(nm
, ZPOOL_REWIND_DATA_THRESH
) == 0) {
101 (void) nvpair_value_uint64(elem
, &zrpp
->zrp_maxdata
);
104 if (zrpp
->zrp_request
== 0)
105 zrpp
->zrp_request
= ZPOOL_NO_REWIND
;
108 typedef struct zfs_version_spa_map
{
111 } zfs_version_spa_map_t
;
114 * Keep this table in monotonically increasing version number order.
116 static zfs_version_spa_map_t zfs_version_table
[] = {
117 {ZPL_VERSION_INITIAL
, SPA_VERSION_INITIAL
},
118 {ZPL_VERSION_DIRENT_TYPE
, SPA_VERSION_INITIAL
},
119 {ZPL_VERSION_FUID
, SPA_VERSION_FUID
},
120 {ZPL_VERSION_USERSPACE
, SPA_VERSION_USERSPACE
},
121 {ZPL_VERSION_SA
, SPA_VERSION_SA
},
126 * Return the max zpl version for a corresponding spa version
127 * -1 is returned if no mapping exists.
130 zfs_zpl_version_map(int spa_version
)
135 for (i
= 0; zfs_version_table
[i
].version_spa
; i
++) {
136 if (spa_version
>= zfs_version_table
[i
].version_spa
)
137 version
= zfs_version_table
[i
].version_zpl
;
144 * Return the min spa version for a corresponding spa version
145 * -1 is returned if no mapping exists.
148 zfs_spa_version_map(int zpl_version
)
153 for (i
= 0; zfs_version_table
[i
].version_zpl
; i
++) {
154 if (zfs_version_table
[i
].version_zpl
>= zpl_version
)
155 return (zfs_version_table
[i
].version_spa
);
162 * This is the table of legacy internal event names; it should not be modified.
163 * The internal events are now stored in the history log as strings.
165 const char *zfs_history_event_names
[ZFS_NUM_LEGACY_HISTORY_EVENTS
] = {
185 "destroy_begin_sync",
191 "permission who remove",
200 "filesystem version upgrade",
202 "refreservation set",