summaryrefslogtreecommitdiff
path: root/usr/src/lib/libbe/common/be_zones.c
diff options
context:
space:
mode:
authorAlexander Eremin <a.eremin@nexenta.com>2013-08-26 13:52:20 -0400
committerDan McDonald <danmcd@nexenta.com>2013-08-26 13:52:20 -0400
commit7e0e2549bfaa531aff576083ab0c07f84fa8fb27 (patch)
tree8ff03f4c47f8e6e89174466a5cc6e6b8fc631070 /usr/src/lib/libbe/common/be_zones.c
parentdc986d9f4cb40f3ff88fe0d9c9fb3a51ad50f0d9 (diff)
downloadillumos-joyent-7e0e2549bfaa531aff576083ab0c07f84fa8fb27.tar.gz
3845 beadm doesn't work in non-global zones
Reviewed by: Hans Rosenfeld <hans.rosenfeld@nexenta.com> Reviewed by: Andrew Stormont <andyjstormont@gmail.com> Reviewed by: Richard Lowe <richlowe@richlowe.net> Approved by: Dan McDonald <danmcd@nexenta.com>
Diffstat (limited to 'usr/src/lib/libbe/common/be_zones.c')
-rw-r--r--usr/src/lib/libbe/common/be_zones.c121
1 files changed, 115 insertions, 6 deletions
diff --git a/usr/src/lib/libbe/common/be_zones.c b/usr/src/lib/libbe/common/be_zones.c
index 886b0dacad..8b2af7efee 100644
--- a/usr/src/lib/libbe/common/be_zones.c
+++ b/usr/src/lib/libbe/common/be_zones.c
@@ -24,6 +24,10 @@
*/
/*
+ * Copyright 2013 Nexenta Systems, Inc. All rights reserved.
+ */
+
+/*
* System includes
*/
#include <assert.h>
@@ -113,14 +117,25 @@ be_find_active_zone_root(zfs_handle_t *be_zhp, char *zonepath_ds,
int ret = BE_SUCCESS;
/* Get the uuid of the parent global BE */
- if ((ret = be_get_uuid(zfs_get_name(be_zhp), &azr_data.parent_uuid))
- != BE_SUCCESS) {
- be_print_err(gettext("be_find_active_zone_root: failed to "
- "get uuid for BE root dataset %s\n"), zfs_get_name(be_zhp));
- return (ret);
+ if (getzoneid() == GLOBAL_ZONEID) {
+ if ((ret = be_get_uuid(zfs_get_name(be_zhp),
+ &azr_data.parent_uuid)) != BE_SUCCESS) {
+ be_print_err(gettext("be_find_active_zone_root: failed "
+ "to get uuid for BE root dataset %s\n"),
+ zfs_get_name(be_zhp));
+ return (ret);
+ }
+ } else {
+ if ((ret = be_zone_get_parent_uuid(zfs_get_name(be_zhp),
+ &azr_data.parent_uuid)) != BE_SUCCESS) {
+ be_print_err(gettext("be_find_active_zone_root: failed "
+ "to get parentbe uuid for zone root dataset %s\n"),
+ zfs_get_name(be_zhp));
+ return (ret);
+ }
}
- /* Generate string for the root container dataset for this zone. */
+ /* Generate string for the root container dataset for this zone. */
be_make_container_ds(zonepath_ds, zone_container_ds,
sizeof (zone_container_ds));
@@ -376,6 +391,100 @@ done:
return (ret);
}
+/*
+ * Function: be_zone_set_parent_uuid
+ * Description: This function sets parentbe uuid into
+ * a zfs user property for a root zone dataset.
+ * Parameters:
+ * root_ds - Root zone dataset of the BE to set a uuid on.
+ * Return:
+ * be_errno_t - Failure
+ * BE_SUCCESS - Success
+ * Scope:
+ * Semi-private (library wide uses only)
+ */
+int
+be_zone_set_parent_uuid(char *root_ds, uuid_t uu)
+{
+ zfs_handle_t *zhp = NULL;
+ char uu_string[UUID_PRINTABLE_STRING_LENGTH];
+ int ret = BE_SUCCESS;
+
+ uuid_unparse(uu, uu_string);
+
+ /* Get handle to the root zone dataset. */
+ if ((zhp = zfs_open(g_zfs, root_ds, ZFS_TYPE_FILESYSTEM)) == NULL) {
+ be_print_err(gettext("be_zone_set_parent_uuid: failed to "
+ "open root zone dataset (%s): %s\n"), root_ds,
+ libzfs_error_description(g_zfs));
+ return (zfs_err_to_be_err(g_zfs));
+ }
+
+ /* Set parentbe uuid property for the root zone dataset */
+ if (zfs_prop_set(zhp, BE_ZONE_PARENTBE_PROPERTY, uu_string) != 0) {
+ be_print_err(gettext("be_zone_set_parent_uuid: failed to "
+ "set parentbe uuid property for root zone dataset: %s\n"),
+ libzfs_error_description(g_zfs));
+ ret = zfs_err_to_be_err(g_zfs);
+ }
+
+ ZFS_CLOSE(zhp);
+ return (ret);
+}
+
+/*
+ * Function: be_zone_compare_uuids
+ * Description: This function compare the parentbe uuid of the
+ * current running root zone dataset with the parentbe
+ * uuid of the given root zone dataset.
+ * Parameters:
+ * root_ds - Root zone dataset of the BE to compare.
+ * Return:
+ * B_TRUE - root dataset has right parentbe uuid
+ * B_FALSE - root dataset has wrong parentbe uuid
+ * Scope:
+ * Semi-private (library wide uses only)
+ */
+boolean_t
+be_zone_compare_uuids(char *root_ds)
+{
+ char *active_ds;
+ uuid_t parent_uuid = {0};
+ uuid_t cur_parent_uuid = {0};
+
+ /* Get parentbe uuid from given zone root dataset */
+ if ((be_zone_get_parent_uuid(root_ds,
+ &parent_uuid)) != BE_SUCCESS) {
+ be_print_err(gettext("be_zone_compare_uuids: failed to get "
+ "parentbe uuid from the given BE\n"));
+ return (B_FALSE);
+ }
+
+ /*
+ * Find current running zone root dataset and get it's parentbe
+ * uuid property.
+ */
+ if ((active_ds = be_get_ds_from_dir("/")) != NULL) {
+ if ((be_zone_get_parent_uuid(active_ds,
+ &cur_parent_uuid)) != BE_SUCCESS) {
+ be_print_err(gettext("be_zone_compare_uuids: failed "
+ "to get parentbe uuid from the current running zone "
+ "root dataset\n"));
+ return (B_FALSE);
+ }
+ } else {
+ be_print_err(gettext("be_zone_compare_uuids: zone root dataset "
+ "is not mounted\n"));
+ return (B_FALSE);
+ }
+
+ if (uuid_compare(parent_uuid, cur_parent_uuid) != 0) {
+ return (B_FALSE);
+ }
+
+ return (B_TRUE);
+}
+
/* ******************************************************************** */
/* Private Functions */
/* ******************************************************************** */