Print this page
*** NO COMMENTS ***
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/lib/libbe/common/be_zones.c
+++ new/usr/src/lib/libbe/common/be_zones.c
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
↓ open down ↓ |
16 lines elided |
↑ open up ↑ |
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21
22 22 /*
23 23 * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
24 24 */
25 25
26 26 /*
27 + * Copyright 2013 Nexenta Systems, Inc. All rights reserved.
28 + */
29 +
30 +/*
27 31 * System includes
28 32 */
29 33 #include <assert.h>
30 34 #include <errno.h>
31 35 #include <libintl.h>
32 36 #include <libnvpair.h>
33 37 #include <libzfs.h>
34 38 #include <stdio.h>
35 39 #include <stdlib.h>
36 40 #include <string.h>
37 41 #include <sys/mntent.h>
38 42 #include <sys/mnttab.h>
39 43 #include <sys/mount.h>
40 44 #include <sys/stat.h>
41 45 #include <sys/types.h>
42 46 #include <sys/vfstab.h>
43 47 #include <unistd.h>
44 48
45 49 #include <libbe.h>
46 50 #include <libbe_priv.h>
47 51
48 52 typedef struct active_zone_root_data {
49 53 uuid_t parent_uuid;
50 54 char *zoneroot_ds;
51 55 } active_zone_root_data_t;
52 56
53 57 typedef struct mounted_zone_root_data {
54 58 char *zone_altroot;
55 59 char *zoneroot_ds;
56 60 } mounted_zone_root_data_t;
57 61
58 62 /* Private function prototypes */
59 63 static int be_find_active_zone_root_callback(zfs_handle_t *, void *);
60 64 static int be_find_mounted_zone_root_callback(zfs_handle_t *, void *);
61 65 static boolean_t be_zone_get_active(zfs_handle_t *);
62 66
63 67
64 68 /* ******************************************************************** */
65 69 /* Semi-Private Functions */
66 70 /* ******************************************************************** */
67 71
68 72 /*
69 73 * Function: be_make_zoneroot
70 74 * Description: Generate a string for a zone's zoneroot given the
71 75 * zone's zonepath.
72 76 * Parameters:
73 77 * zonepath - pointer to zonepath
74 78 * zoneroot - pointer to buffer to retrn zoneroot in.
75 79 * zoneroot_size - size of zoneroot
76 80 * Returns:
77 81 * None
78 82 * Scope:
79 83 * Semi-private (library wise use only)
80 84 */
81 85 void
82 86 be_make_zoneroot(char *zonepath, char *zoneroot, int zoneroot_size)
83 87 {
84 88 (void) snprintf(zoneroot, zoneroot_size, "%s/root", zonepath);
85 89 }
86 90
87 91 /*
88 92 * Function: be_find_active_zone_root
89 93 * Description: This function will find the active zone root of a zone for
90 94 * a given global BE. It will iterate all of the zone roots
91 95 * under a zonepath, find the zone roots that belong to the
92 96 * specified global BE, and return the one that is active.
93 97 * Parameters:
94 98 * be_zhp - zfs handle to global BE root dataset.
95 99 * zonepath_ds - pointer to zone's zonepath dataset.
96 100 * zoneroot_ds - pointer to a buffer to store the dataset name of
97 101 * the zone's zoneroot that's currently active for this
98 102 * given global BE..
99 103 * zoneroot-ds_size - size of zoneroot_ds.
100 104 * Returns:
101 105 * BE_SUCCESS - Success
102 106 * be_errno_t - Failure
103 107 * Scope:
104 108 * Semi-private (library wide use only)
105 109 */
↓ open down ↓ |
69 lines elided |
↑ open up ↑ |
106 110 int
107 111 be_find_active_zone_root(zfs_handle_t *be_zhp, char *zonepath_ds,
108 112 char *zoneroot_ds, int zoneroot_ds_size)
109 113 {
110 114 active_zone_root_data_t azr_data = { 0 };
111 115 zfs_handle_t *zhp;
112 116 char zone_container_ds[MAXPATHLEN];
113 117 int ret = BE_SUCCESS;
114 118
115 119 /* Get the uuid of the parent global BE */
116 - if ((ret = be_get_uuid(zfs_get_name(be_zhp), &azr_data.parent_uuid))
117 - != BE_SUCCESS) {
118 - be_print_err(gettext("be_find_active_zone_root: failed to "
119 - "get uuid for BE root dataset %s\n"), zfs_get_name(be_zhp));
120 - return (ret);
120 + if (getzoneid() == GLOBAL_ZONEID) {
121 + if ((ret = be_get_uuid(zfs_get_name(be_zhp),
122 + &azr_data.parent_uuid)) != BE_SUCCESS) {
123 + be_print_err(gettext("be_find_active_zone_root: failed "
124 + "to get uuid for BE root dataset %s\n"),
125 + zfs_get_name(be_zhp));
126 + return (ret);
127 + }
128 + } else {
129 + if ((ret = be_zone_get_parent_uuid(zfs_get_name(be_zhp),
130 + &azr_data.parent_uuid)) != BE_SUCCESS) {
131 + be_print_err(gettext("be_find_active_zone_root: failed "
132 + "to get parentbe uuid for zone root dataset %s\n"),
133 + zfs_get_name(be_zhp));
134 + return (ret);
135 + }
121 136 }
122 137
123 - /* Generate string for the root container dataset for this zone. */
138 + /* Generate string for the root container dataset for this zone. */
124 139 be_make_container_ds(zonepath_ds, zone_container_ds,
125 140 sizeof (zone_container_ds));
126 141
127 142 /* Get handle to this zone's root container dataset */
128 143 if ((zhp = zfs_open(g_zfs, zone_container_ds, ZFS_TYPE_FILESYSTEM))
129 144 == NULL) {
130 145 be_print_err(gettext("be_find_active_zone_root: failed to "
131 146 "open zone root container dataset (%s): %s\n"),
132 147 zone_container_ds, libzfs_error_description(g_zfs));
133 148 return (zfs_err_to_be_err(g_zfs));
134 149 }
135 150
136 151 /*
137 152 * Iterate through all of this zone's BEs, looking for ones
138 153 * that belong to the parent global BE, and finding the one
139 154 * that is marked active.
140 155 */
141 156 if ((ret = zfs_iter_filesystems(zhp, be_find_active_zone_root_callback,
142 157 &azr_data)) != 0) {
143 158 be_print_err(gettext("be_find_active_zone_root: failed to "
144 159 "find active zone root in zonepath dataset %s: %s\n"),
145 160 zonepath_ds, be_err_to_str(ret));
146 161 goto done;
147 162 }
148 163
149 164 if (azr_data.zoneroot_ds != NULL) {
150 165 (void) strlcpy(zoneroot_ds, azr_data.zoneroot_ds,
151 166 zoneroot_ds_size);
152 167 free(azr_data.zoneroot_ds);
153 168 } else {
154 169 be_print_err(gettext("be_find_active_zone_root: failed to "
155 170 "find active zone root in zonepath dataset %s\n"),
156 171 zonepath_ds);
157 172 ret = BE_ERR_ZONE_NO_ACTIVE_ROOT;
158 173 }
159 174
160 175 done:
161 176 ZFS_CLOSE(zhp);
162 177 return (ret);
163 178 }
164 179
165 180 /*
166 181 * Function: be_find_mounted_zone_root
167 182 * Description: This function will find the dataset mounted as the zoneroot
168 183 * of a zone for a given mounted global BE.
169 184 * Parameters:
170 185 * zone_altroot - path of zoneroot wrt the mounted global BE.
171 186 * zonepath_ds - dataset of the zone's zonepath.
172 187 * zoneroot_ds - pointer to a buffer to store the dataset of
173 188 * the zoneroot that currently mounted for this zone
174 189 * in the mounted global BE.
175 190 * zoneroot_ds_size - size of zoneroot_ds
176 191 * Returns:
177 192 * BE_SUCCESS - Success
178 193 * be_errno_t - Failure
179 194 * Scope:
180 195 * Semi-private (library wide use only)
181 196 */
182 197 int
183 198 be_find_mounted_zone_root(char *zone_altroot, char *zonepath_ds,
184 199 char *zoneroot_ds, int zoneroot_ds_size)
185 200 {
186 201 mounted_zone_root_data_t mzr_data = { 0 };
187 202 zfs_handle_t *zhp = NULL;
188 203 char zone_container_ds[MAXPATHLEN];
189 204 int ret = BE_SUCCESS;
190 205 int zret = 0;
191 206
192 207 /* Generate string for the root container dataset for this zone. */
193 208 be_make_container_ds(zonepath_ds, zone_container_ds,
194 209 sizeof (zone_container_ds));
195 210
196 211 /* Get handle to this zone's root container dataset. */
197 212 if ((zhp = zfs_open(g_zfs, zone_container_ds, ZFS_TYPE_FILESYSTEM))
198 213 == NULL) {
199 214 be_print_err(gettext("be_find_mounted_zone_root: failed to "
200 215 "open zone root container dataset (%s): %s\n"),
201 216 zone_container_ds, libzfs_error_description(g_zfs));
202 217 return (zfs_err_to_be_err(g_zfs));
203 218 }
204 219
205 220 mzr_data.zone_altroot = zone_altroot;
206 221
207 222 /*
208 223 * Iterate through all of the zone's BEs, looking for the one
209 224 * that is currently mounted at the zone altroot in the mounted
210 225 * global BE.
211 226 */
212 227 if ((zret = zfs_iter_filesystems(zhp,
213 228 be_find_mounted_zone_root_callback, &mzr_data)) == 0) {
214 229 be_print_err(gettext("be_find_mounted_zone_root: did not "
215 230 "find mounted zone under altroot zonepath %s\n"),
216 231 zonepath_ds);
217 232 ret = BE_ERR_NO_MOUNTED_ZONE;
218 233 goto done;
219 234 } else if (zret < 0) {
220 235 be_print_err(gettext("be_find_mounted_zone_root: "
221 236 "zfs_iter_filesystems failed: %s\n"),
222 237 libzfs_error_description(g_zfs));
223 238 ret = zfs_err_to_be_err(g_zfs);
224 239 goto done;
225 240 }
226 241
227 242 if (mzr_data.zoneroot_ds != NULL) {
228 243 (void) strlcpy(zoneroot_ds, mzr_data.zoneroot_ds,
229 244 zoneroot_ds_size);
230 245 free(mzr_data.zoneroot_ds);
231 246 }
232 247
233 248 done:
234 249 ZFS_CLOSE(zhp);
235 250 return (ret);
236 251 }
237 252
238 253 /*
239 254 * Function: be_zone_supported
240 255 * Description: This function will determine if a zone is supported
241 256 * based on its zonepath dataset. The zonepath dataset
242 257 * must:
243 258 * - not be under any global BE root dataset.
244 259 * - have a root container dataset underneath it.
245 260 *
246 261 * Parameters:
247 262 * zonepath_ds - name of dataset of the zonepath of the
248 263 * zone to check.
249 264 * Returns:
250 265 * B_TRUE - zone is supported
251 266 * B_FALSE - zone is not supported
252 267 * Scope:
253 268 * Semi-private (library wide use only)
254 269 */
255 270 boolean_t
256 271 be_zone_supported(char *zonepath_ds)
257 272 {
258 273 char zone_container_ds[MAXPATHLEN];
259 274 int ret = 0;
260 275
261 276 /*
262 277 * Make sure the dataset for the zonepath is not hierarchically
263 278 * under any reserved BE root container dataset of any pool.
264 279 */
265 280 if ((ret = zpool_iter(g_zfs, be_check_be_roots_callback,
266 281 zonepath_ds)) > 0) {
267 282 be_print_err(gettext("be_zone_supported: "
268 283 "zonepath dataset %s not supported\n"), zonepath_ds);
269 284 return (B_FALSE);
270 285 } else if (ret < 0) {
271 286 be_print_err(gettext("be_zone_supported: "
272 287 "zpool_iter failed: %s\n"),
273 288 libzfs_error_description(g_zfs));
274 289 return (B_FALSE);
275 290 }
276 291
277 292 /*
278 293 * Make sure the zonepath has a zone root container dataset
279 294 * underneath it.
280 295 */
281 296 be_make_container_ds(zonepath_ds, zone_container_ds,
282 297 sizeof (zone_container_ds));
283 298
284 299 if (!zfs_dataset_exists(g_zfs, zone_container_ds,
285 300 ZFS_TYPE_FILESYSTEM)) {
286 301 be_print_err(gettext("be_zone_supported: "
287 302 "zonepath dataset (%s) does not have a zone root container "
288 303 "dataset, zone is not supported, skipping ...\n"),
289 304 zonepath_ds);
290 305 return (B_FALSE);
291 306 }
292 307
293 308 return (B_TRUE);
294 309 }
295 310
296 311 /*
297 312 * Function: be_get_supported_brandlist
298 313 * Desciption: This functions retuns a list of supported brands in
299 314 * a zoneBrandList_t object.
300 315 * Parameters:
301 316 * None
302 317 * Returns:
303 318 * Failure - NULL if no supported brands found.
304 319 * Success - pointer to zoneBrandList structure.
305 320 * Scope:
306 321 * Semi-private (library wide use only)
307 322 */
308 323 zoneBrandList_t *
309 324 be_get_supported_brandlist(void)
310 325 {
311 326 return (z_make_brand_list(BE_ZONE_SUPPORTED_BRANDS,
312 327 BE_ZONE_SUPPORTED_BRANDS_DELIM));
313 328 }
314 329
315 330 /*
316 331 * Function: be_zone_get_parent_uuid
317 332 * Description: This function gets the parentbe property of a zone root
318 333 * dataset, parsed it into internal uuid format, and returns
319 334 * it in the uuid_t reference pointer passed in.
320 335 * Parameters:
321 336 * root_ds - dataset name of a zone root dataset
322 337 * uu - pointer to a uuid_t to return the parentbe uuid in
323 338 * Returns:
324 339 * BE_SUCCESS - Success
325 340 * be_errno_t - Failure
326 341 * Scope:
327 342 * Private
328 343 */
329 344 int
330 345 be_zone_get_parent_uuid(const char *root_ds, uuid_t *uu)
331 346 {
332 347 zfs_handle_t *zhp = NULL;
333 348 nvlist_t *userprops = NULL;
334 349 nvlist_t *propname = NULL;
335 350 char *uu_string = NULL;
336 351 int ret = BE_SUCCESS;
337 352
338 353 /* Get handle to zone root dataset */
339 354 if ((zhp = zfs_open(g_zfs, root_ds, ZFS_TYPE_FILESYSTEM)) == NULL) {
340 355 be_print_err(gettext("be_zone_get_parent_uuid: failed to "
341 356 "open zone root dataset (%s): %s\n"), root_ds,
342 357 libzfs_error_description(g_zfs));
343 358 return (zfs_err_to_be_err(g_zfs));
344 359 }
345 360
346 361 /* Get user properties for zone root dataset */
347 362 if ((userprops = zfs_get_user_props(zhp)) == NULL) {
348 363 be_print_err(gettext("be_zone_get_parent_uuid: "
349 364 "failed to get user properties for zone root "
350 365 "dataset (%s): %s\n"), root_ds,
351 366 libzfs_error_description(g_zfs));
352 367 ret = zfs_err_to_be_err(g_zfs);
353 368 goto done;
354 369 }
355 370
356 371 /* Get UUID string from zone's root dataset user properties */
357 372 if (nvlist_lookup_nvlist(userprops, BE_ZONE_PARENTBE_PROPERTY,
358 373 &propname) != 0 || nvlist_lookup_string(propname, ZPROP_VALUE,
359 374 &uu_string) != 0) {
360 375 be_print_err(gettext("be_zone_get_parent_uuid: failed to "
361 376 "get parent uuid property from zone root dataset user "
362 377 "properties.\n"));
363 378 ret = BE_ERR_ZONE_NO_PARENTBE;
364 379 goto done;
365 380 }
366 381
367 382 /* Parse the uuid string into internal format */
368 383 if (uuid_parse(uu_string, *uu) != 0 || uuid_is_null(*uu)) {
↓ open down ↓ |
235 lines elided |
↑ open up ↑ |
369 384 be_print_err(gettext("be_zone_get_parent_uuid: failed to "
370 385 "parse parentuuid\n"));
371 386 ret = BE_ERR_PARSE_UUID;
372 387 }
373 388
374 389 done:
375 390 ZFS_CLOSE(zhp);
376 391 return (ret);
377 392 }
378 393
394 +/*
395 + * Function: be_zone_set_parent_uuid
396 + * Description: This function sets parentbe uuid into
397 + * a zfs user property for a root zone dataset.
398 + * Parameters:
399 + * root_ds - Root zone dataset of the BE to set a uuid on.
400 + * Return:
401 + * be_errno_t - Failure
402 + * BE_SUCCESS - Success
403 + * Scope:
404 + * Semi-private (library wide uses only)
405 + */
406 +int
407 +be_zone_set_parent_uuid(char *root_ds, uuid_t uu)
408 +{
409 + zfs_handle_t *zhp = NULL;
410 + char uu_string[UUID_PRINTABLE_STRING_LENGTH];
411 + int ret = BE_SUCCESS;
412 +
413 + uuid_unparse(uu, uu_string);
414 +
415 + /* Get handle to the root zone dataset. */
416 + if ((zhp = zfs_open(g_zfs, root_ds, ZFS_TYPE_FILESYSTEM)) == NULL) {
417 + be_print_err(gettext("be_zone_set_parent_uuid: failed to "
418 + "open root zone dataset (%s): %s\n"), root_ds,
419 + libzfs_error_description(g_zfs));
420 + return (zfs_err_to_be_err(g_zfs));
421 + }
422 +
423 + /* Set parentbe uuid property for the root zone dataset */
424 + if (zfs_prop_set(zhp, BE_ZONE_PARENTBE_PROPERTY, uu_string) != 0) {
425 + be_print_err(gettext("be_zone_set_parent_uuid: failed to "
426 + "set parentbe uuid property for root zone dataset: %s\n"),
427 + libzfs_error_description(g_zfs));
428 + ret = zfs_err_to_be_err(g_zfs);
429 + }
430 +
431 + ZFS_CLOSE(zhp);
432 + return (ret);
433 +}
434 +
435 +/*
436 + * Function: be_zone_compare_uuids
437 + * Description: This function compare the parentbe uuid of the
438 + * current running root zone dataset with the parentbe
439 + * uuid of the given root zone dataset.
440 + * Parameters:
441 + * root_ds - Root zone dataset of the BE to compare.
442 + * Return:
443 + * B_TRUE - root dataset has right parentbe uuid
444 + * B_FALSE - root dataset has wrong parentbe uuid
445 + * Scope:
446 + * Semi-private (library wide uses only)
447 + */
448 +boolean_t
449 +be_zone_compare_uuids(char *root_ds)
450 +{
451 + char *active_ds;
452 + uuid_t parent_uuid = {0};
453 + uuid_t cur_parent_uuid = {0};
454 +
455 + /* Get parentbe uuid from given zone root dataset */
456 + if ((be_zone_get_parent_uuid(root_ds,
457 + &parent_uuid)) != BE_SUCCESS) {
458 + be_print_err(gettext("be_zone_compare_uuids: failed to get "
459 + "parentbe uuid from the given BE\n"));
460 + return (B_FALSE);
461 + }
462 +
463 + /*
464 + * Find current running zone root dataset and get it's parentbe
465 + * uuid property.
466 + */
467 + if ((active_ds = be_get_ds_from_dir("/")) != NULL) {
468 + if ((be_zone_get_parent_uuid(active_ds,
469 + &cur_parent_uuid)) != BE_SUCCESS) {
470 + be_print_err(gettext("be_zone_compare_uuids: failed "
471 + "to get parentbe uuid from the current running zone "
472 + "root dataset\n"));
473 + return (B_FALSE);
474 + }
475 + } else {
476 + be_print_err(gettext("be_zone_compare_uuids: zone root dataset "
477 + "is not mounted\n"));
478 + return (B_FALSE);
479 + }
480 +
481 + if (uuid_compare(parent_uuid, cur_parent_uuid) != 0) {
482 + return (B_FALSE);
483 + }
484 +
485 + return (B_TRUE);
486 +}
487 +
379 488 /* ******************************************************************** */
380 489 /* Private Functions */
381 490 /* ******************************************************************** */
382 491
383 492 /*
384 493 * Function: be_find_active_zone_root_callback
385 494 * Description: This function is used as a callback to iterate over all of
386 495 * a zone's root datasets, finding the one that is marked active
387 496 * for the parent BE specified in the data passed in. The name
388 497 * of the zone's active root dataset is returned in heap storage
389 498 * in the active_zone_root_data_t structure passed in, so the
390 499 * caller is responsible for freeing it.
391 500 * Parameters:
392 501 * zhp - zfs_handle_t pointer to current dataset being processed
393 502 * data - active_zone_root_data_t pointer
394 503 * Returns:
395 504 * 0 - Success
396 505 * >0 - Failure
397 506 * Scope:
398 507 * Private
399 508 */
400 509 static int
401 510 be_find_active_zone_root_callback(zfs_handle_t *zhp, void *data)
402 511 {
403 512 active_zone_root_data_t *azr_data = data;
404 513 uuid_t parent_uuid = { 0 };
405 514 int iret = 0;
406 515 int ret = 0;
407 516
408 517 if ((iret = be_zone_get_parent_uuid(zfs_get_name(zhp), &parent_uuid))
409 518 != BE_SUCCESS) {
410 519 be_print_err(gettext("be_find_active_zone_root_callback: "
411 520 "skipping zone root dataset (%s): %s\n"),
412 521 zfs_get_name(zhp), be_err_to_str(iret));
413 522 goto done;
414 523 }
415 524
416 525 if (uuid_compare(azr_data->parent_uuid, parent_uuid) == 0) {
417 526 /*
418 527 * Found a zone root dataset belonging to the right parent,
419 528 * check if its active.
420 529 */
421 530 if (be_zone_get_active(zhp)) {
422 531 /*
423 532 * Found active zone root dataset, if its already
424 533 * set in the callback data, that means this
425 534 * is the second one we've found. Return error.
426 535 */
427 536 if (azr_data->zoneroot_ds != NULL) {
428 537 ret = BE_ERR_ZONE_MULTIPLE_ACTIVE;
429 538 goto done;
430 539 }
431 540
432 541 azr_data->zoneroot_ds = strdup(zfs_get_name(zhp));
433 542 if (azr_data->zoneroot_ds == NULL) {
434 543 ret = BE_ERR_NOMEM;
435 544 }
436 545 }
437 546 }
438 547
439 548 done:
440 549 ZFS_CLOSE(zhp);
441 550 return (ret);
442 551 }
443 552
444 553 /*
445 554 * Function: be_find_mounted_zone_root_callback
446 555 * Description: This function is used as a callback to iterate over all of
447 556 * a zone's root datasets, find the one that is currently
448 557 * mounted for the parent BE specified in the data passed in.
449 558 * The name of the zone's mounted root dataset is returned in
450 559 * heap storage the mounted_zone_data_t structure passed in,
451 560 * so the caller is responsible for freeing it.
452 561 * Parameters:
453 562 * zhp - zfs_handle_t pointer to the current dataset being
454 563 * processed
455 564 * data - mounted_zone_data_t pointer
456 565 * Returns:
457 566 * 0 - not mounted as zone's root
458 567 * 1 - this dataset is mounted as zone's root
459 568 * Scope:
460 569 * Private
461 570 */
462 571 static int
463 572 be_find_mounted_zone_root_callback(zfs_handle_t *zhp, void *data)
464 573 {
465 574 mounted_zone_root_data_t *mzr_data = data;
466 575 char *mp = NULL;
467 576
468 577 if (zfs_is_mounted(zhp, &mp) && mp != NULL &&
469 578 strcmp(mp, mzr_data->zone_altroot) == 0) {
470 579 mzr_data->zoneroot_ds = strdup(zfs_get_name(zhp));
471 580 free(mp);
472 581 return (1);
473 582 }
474 583
475 584 free(mp);
476 585 return (0);
477 586 }
478 587
479 588 /*
480 589 * Function: be_zone_get_active
481 590 * Description: This function gets the active property of a zone root
482 591 * dataset, and returns true if active property is on.
483 592 * Parameters:
484 593 * zfs - zfs_handle_t pointer to zone root dataset to check
485 594 * Returns:
486 595 * B_TRUE - zone root dataset is active
487 596 * B_FALSE - zone root dataset is not active
488 597 * Scope:
489 598 * Private
490 599 */
491 600 static boolean_t
492 601 be_zone_get_active(zfs_handle_t *zhp)
493 602 {
494 603 nvlist_t *userprops = NULL;
495 604 nvlist_t *propname = NULL;
496 605 char *active_str = NULL;
497 606
498 607 /* Get user properties for the zone root dataset */
499 608 if ((userprops = zfs_get_user_props(zhp)) == NULL) {
500 609 be_print_err(gettext("be_zone_get_active: "
501 610 "failed to get user properties for zone root "
502 611 "dataset (%s): %s\n"), zfs_get_name(zhp),
503 612 libzfs_error_description(g_zfs));
504 613 return (B_FALSE);
505 614 }
506 615
507 616 /* Get active property from the zone root dataset user properties */
508 617 if (nvlist_lookup_nvlist(userprops, BE_ZONE_ACTIVE_PROPERTY, &propname)
509 618 != 0 || nvlist_lookup_string(propname, ZPROP_VALUE, &active_str)
510 619 != 0) {
511 620 return (B_FALSE);
512 621 }
513 622
514 623 if (strcmp(active_str, "on") == 0)
515 624 return (B_TRUE);
516 625
517 626 return (B_FALSE);
518 627 }
↓ open down ↓ |
130 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX