]>
Commit | Line | Data |
---|---|---|
34dc7c2f BB |
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 | |
1d3ba0bf | 9 | * or https://opensource.org/licenses/CDDL-1.0. |
34dc7c2f BB |
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 | /* | |
428870ff | 22 | * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved. |
8a393be3 | 23 | * Copyright (c) 2012, 2017 by Delphix. All rights reserved. |
34dc7c2f BB |
24 | */ |
25 | ||
34dc7c2f BB |
26 | /* |
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 | |
bf169e9f | 29 | * then a separate file should be created. |
34dc7c2f BB |
30 | */ |
31 | ||
93ce2b4c | 32 | #if !defined(_KERNEL) |
428870ff | 33 | #include <string.h> |
34dc7c2f BB |
34 | #endif |
35 | ||
36 | #include <sys/types.h> | |
37 | #include <sys/fs/zfs.h> | |
38 | #include <sys/nvpair.h> | |
428870ff | 39 | #include "zfs_comutil.h" |
6078881a | 40 | #include <sys/zfs_ratelimit.h> |
34dc7c2f BB |
41 | |
42 | /* | |
43 | * Are there allocatable vdevs? | |
44 | */ | |
45 | boolean_t | |
46 | zfs_allocatable_devs(nvlist_t *nv) | |
47 | { | |
48 | uint64_t is_log; | |
49 | uint_t c; | |
50 | nvlist_t **child; | |
51 | uint_t children; | |
52 | ||
53 | if (nvlist_lookup_nvlist_array(nv, ZPOOL_CONFIG_CHILDREN, | |
54 | &child, &children) != 0) { | |
55 | return (B_FALSE); | |
56 | } | |
57 | for (c = 0; c < children; c++) { | |
58 | is_log = 0; | |
59 | (void) nvlist_lookup_uint64(child[c], ZPOOL_CONFIG_IS_LOG, | |
60 | &is_log); | |
61 | if (!is_log) | |
62 | return (B_TRUE); | |
63 | } | |
64 | return (B_FALSE); | |
65 | } | |
428870ff | 66 | |
715c996d | 67 | /* |
68 | * Are there special vdevs? | |
69 | */ | |
70 | boolean_t | |
a926aab9 | 71 | zfs_special_devs(nvlist_t *nv, const char *type) |
715c996d | 72 | { |
d1807f16 | 73 | const char *bias; |
715c996d | 74 | uint_t c; |
75 | nvlist_t **child; | |
76 | uint_t children; | |
77 | ||
78 | if (nvlist_lookup_nvlist_array(nv, ZPOOL_CONFIG_CHILDREN, | |
79 | &child, &children) != 0) { | |
80 | return (B_FALSE); | |
81 | } | |
82 | for (c = 0; c < children; c++) { | |
83 | if (nvlist_lookup_string(child[c], ZPOOL_CONFIG_ALLOCATION_BIAS, | |
84 | &bias) == 0) { | |
85 | if (strcmp(bias, VDEV_ALLOC_BIAS_SPECIAL) == 0 || | |
86 | strcmp(bias, VDEV_ALLOC_BIAS_DEDUP) == 0) { | |
a926aab9 AZ |
87 | if (type == NULL || |
88 | (type != NULL && strcmp(bias, type) == 0)) | |
c24fa4b1 | 89 | return (B_TRUE); |
715c996d | 90 | } |
91 | } | |
92 | } | |
93 | return (B_FALSE); | |
94 | } | |
95 | ||
428870ff | 96 | void |
8a393be3 | 97 | zpool_get_load_policy(nvlist_t *nvl, zpool_load_policy_t *zlpp) |
428870ff BB |
98 | { |
99 | nvlist_t *policy; | |
100 | nvpair_t *elem; | |
d1807f16 | 101 | const char *nm; |
428870ff BB |
102 | |
103 | /* Defaults */ | |
8a393be3 PZ |
104 | zlpp->zlp_rewind = ZPOOL_NO_REWIND; |
105 | zlpp->zlp_maxmeta = 0; | |
106 | zlpp->zlp_maxdata = UINT64_MAX; | |
107 | zlpp->zlp_txg = UINT64_MAX; | |
428870ff BB |
108 | |
109 | if (nvl == NULL) | |
110 | return; | |
111 | ||
112 | elem = NULL; | |
113 | while ((elem = nvlist_next_nvpair(nvl, elem)) != NULL) { | |
114 | nm = nvpair_name(elem); | |
8a393be3 | 115 | if (strcmp(nm, ZPOOL_LOAD_POLICY) == 0) { |
428870ff | 116 | if (nvpair_value_nvlist(elem, &policy) == 0) |
8a393be3 | 117 | zpool_get_load_policy(policy, zlpp); |
428870ff | 118 | return; |
8a393be3 PZ |
119 | } else if (strcmp(nm, ZPOOL_LOAD_REWIND_POLICY) == 0) { |
120 | if (nvpair_value_uint32(elem, &zlpp->zlp_rewind) == 0) | |
121 | if (zlpp->zlp_rewind & ~ZPOOL_REWIND_POLICIES) | |
122 | zlpp->zlp_rewind = ZPOOL_NO_REWIND; | |
123 | } else if (strcmp(nm, ZPOOL_LOAD_REQUEST_TXG) == 0) { | |
124 | (void) nvpair_value_uint64(elem, &zlpp->zlp_txg); | |
125 | } else if (strcmp(nm, ZPOOL_LOAD_META_THRESH) == 0) { | |
126 | (void) nvpair_value_uint64(elem, &zlpp->zlp_maxmeta); | |
127 | } else if (strcmp(nm, ZPOOL_LOAD_DATA_THRESH) == 0) { | |
128 | (void) nvpair_value_uint64(elem, &zlpp->zlp_maxdata); | |
428870ff BB |
129 | } |
130 | } | |
8a393be3 PZ |
131 | if (zlpp->zlp_rewind == 0) |
132 | zlpp->zlp_rewind = ZPOOL_NO_REWIND; | |
428870ff BB |
133 | } |
134 | ||
135 | typedef struct zfs_version_spa_map { | |
136 | int version_zpl; | |
137 | int version_spa; | |
138 | } zfs_version_spa_map_t; | |
139 | ||
140 | /* | |
141 | * Keep this table in monotonically increasing version number order. | |
142 | */ | |
143 | static zfs_version_spa_map_t zfs_version_table[] = { | |
144 | {ZPL_VERSION_INITIAL, SPA_VERSION_INITIAL}, | |
145 | {ZPL_VERSION_DIRENT_TYPE, SPA_VERSION_INITIAL}, | |
146 | {ZPL_VERSION_FUID, SPA_VERSION_FUID}, | |
147 | {ZPL_VERSION_USERSPACE, SPA_VERSION_USERSPACE}, | |
148 | {ZPL_VERSION_SA, SPA_VERSION_SA}, | |
149 | {0, 0} | |
150 | }; | |
151 | ||
152 | /* | |
153 | * Return the max zpl version for a corresponding spa version | |
154 | * -1 is returned if no mapping exists. | |
155 | */ | |
156 | int | |
157 | zfs_zpl_version_map(int spa_version) | |
158 | { | |
428870ff BB |
159 | int version = -1; |
160 | ||
18168da7 | 161 | for (int i = 0; zfs_version_table[i].version_spa; i++) |
428870ff BB |
162 | if (spa_version >= zfs_version_table[i].version_spa) |
163 | version = zfs_version_table[i].version_zpl; | |
428870ff BB |
164 | |
165 | return (version); | |
166 | } | |
167 | ||
168 | /* | |
169 | * Return the min spa version for a corresponding spa version | |
170 | * -1 is returned if no mapping exists. | |
171 | */ | |
172 | int | |
173 | zfs_spa_version_map(int zpl_version) | |
174 | { | |
18168da7 | 175 | for (int i = 0; zfs_version_table[i].version_zpl; i++) |
428870ff BB |
176 | if (zfs_version_table[i].version_zpl >= zpl_version) |
177 | return (zfs_version_table[i].version_spa); | |
428870ff | 178 | |
18168da7 | 179 | return (-1); |
428870ff BB |
180 | } |
181 | ||
6f1ffb06 MA |
182 | /* |
183 | * This is the table of legacy internal event names; it should not be modified. | |
184 | * The internal events are now stored in the history log as strings. | |
185 | */ | |
18168da7 | 186 | const char *const zfs_history_event_names[ZFS_NUM_LEGACY_HISTORY_EVENTS] = { |
428870ff BB |
187 | "invalid event", |
188 | "pool create", | |
189 | "vdev add", | |
190 | "pool remove", | |
191 | "pool destroy", | |
192 | "pool export", | |
193 | "pool import", | |
194 | "vdev attach", | |
195 | "vdev replace", | |
196 | "vdev detach", | |
197 | "vdev online", | |
198 | "vdev offline", | |
199 | "vdev upgrade", | |
200 | "pool clear", | |
201 | "pool scrub", | |
202 | "pool property set", | |
203 | "create", | |
204 | "clone", | |
205 | "destroy", | |
206 | "destroy_begin_sync", | |
207 | "inherit", | |
208 | "property set", | |
209 | "quota set", | |
210 | "permission update", | |
211 | "permission remove", | |
212 | "permission who remove", | |
213 | "promote", | |
214 | "receive", | |
215 | "rename", | |
216 | "reservation set", | |
217 | "replay_inc_sync", | |
218 | "replay_full_sync", | |
219 | "rollback", | |
220 | "snapshot", | |
221 | "filesystem version upgrade", | |
222 | "refquota set", | |
223 | "refreservation set", | |
224 | "pool scrub done", | |
225 | "user hold", | |
226 | "user release", | |
227 | "pool split", | |
228 | }; | |
c28b2279 | 229 | |
2e5dc449 MA |
230 | boolean_t |
231 | zfs_dataset_name_hidden(const char *name) | |
232 | { | |
233 | /* | |
234 | * Skip over datasets that are not visible in this zone, | |
235 | * internal datasets (which have a $ in their name), and | |
236 | * temporary datasets (which have a % in their name). | |
237 | */ | |
18168da7 | 238 | if (strpbrk(name, "$%") != NULL) |
2e5dc449 MA |
239 | return (B_TRUE); |
240 | if (!INGLOBALZONE(curproc) && !zone_dataset_visible(name, NULL)) | |
241 | return (B_TRUE); | |
242 | return (B_FALSE); | |
243 | } | |
244 | ||
93ce2b4c | 245 | #if defined(_KERNEL) |
c28b2279 | 246 | EXPORT_SYMBOL(zfs_allocatable_devs); |
715c996d | 247 | EXPORT_SYMBOL(zfs_special_devs); |
8a393be3 | 248 | EXPORT_SYMBOL(zpool_get_load_policy); |
c28b2279 BB |
249 | EXPORT_SYMBOL(zfs_zpl_version_map); |
250 | EXPORT_SYMBOL(zfs_spa_version_map); | |
251 | EXPORT_SYMBOL(zfs_history_event_names); | |
2e5dc449 | 252 | EXPORT_SYMBOL(zfs_dataset_name_hidden); |
c28b2279 | 253 | #endif |