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