diff options
author | Jerry Jelinek <jerry.jelinek@joyent.com> | 2011-09-15 18:18:16 +0000 |
---|---|---|
committer | Jerry Jelinek <jerry.jelinek@joyent.com> | 2011-09-15 18:18:16 +0000 |
commit | b20d8a86fe350baff549e5bb47a25be252c94c3c (patch) | |
tree | 907c558a54b404182eff0518825c0292d241d341 /usr/src | |
parent | e5edabf8af4430653c2189b3d23c6b9b47f2f5b7 (diff) | |
download | illumos-joyent-b20d8a86fe350baff549e5bb47a25be252c94c3c.tar.gz |
OS-609 post-install hook for adding UUID could race
Diffstat (limited to 'usr/src')
-rw-r--r-- | usr/src/cmd/zoneadm/zoneadm.c | 14 | ||||
-rw-r--r-- | usr/src/head/libzonecfg.h | 1 | ||||
-rw-r--r-- | usr/src/lib/brand/joyent/zone/Makefile | 2 | ||||
-rw-r--r-- | usr/src/lib/brand/joyent/zone/config.xml | 2 | ||||
-rw-r--r-- | usr/src/lib/brand/joyent/zone/pinstall.ksh | 71 | ||||
-rw-r--r-- | usr/src/lib/brand/kvm/zone/Makefile | 2 | ||||
-rw-r--r-- | usr/src/lib/brand/kvm/zone/config.xml | 2 | ||||
-rwxr-xr-x | usr/src/lib/brand/kvm/zone/pinstall.ksh | 71 | ||||
-rw-r--r-- | usr/src/lib/libzonecfg/common/getzoneent.c | 6 | ||||
-rw-r--r-- | usr/src/lib/libzonecfg/common/libzonecfg.c | 24 | ||||
-rw-r--r-- | usr/src/lib/libzonecfg/common/mapfile-vers | 1 |
11 files changed, 49 insertions, 147 deletions
diff --git a/usr/src/cmd/zoneadm/zoneadm.c b/usr/src/cmd/zoneadm/zoneadm.c index b63c448d9c..9d9d782d0a 100644 --- a/usr/src/cmd/zoneadm/zoneadm.c +++ b/usr/src/cmd/zoneadm/zoneadm.c @@ -2913,6 +2913,7 @@ install_func(int argc, char *argv[]) boolean_t brand_help = B_FALSE; boolean_t do_dataset = B_TRUE; char opts[128]; + char *new_uuid = NULL; if (target_zone == NULL) { sub_usage(SHELP_INSTALL, CMD_INSTALL); @@ -2955,7 +2956,7 @@ install_func(int argc, char *argv[]) if (postcmdbuf[0] != '\0') do_postinstall = B_TRUE; - (void) strcpy(opts, "?x:"); + (void) strcpy(opts, "?U:x:"); /* * Fetch the list of recognized command-line options from * the brand configuration file. @@ -2987,6 +2988,10 @@ install_func(int argc, char *argv[]) } /* Ignore unknown options - may be brand specific. */ break; + case 'U': + new_uuid = optarg; + continue; /* internal arg, don't pass thru */ + break; case 'x': if (strcmp(optarg, "nodataset") == 0) { do_dataset = B_FALSE; @@ -3072,6 +3077,13 @@ install_func(int argc, char *argv[]) goto done; } + if (new_uuid != NULL && + (err = zonecfg_set_uuid(target_zone, zonepath, new_uuid) != Z_OK)) { + errno = err; + zperror2(target_zone, gettext("could not set UUID")); + goto done; + } + if (do_postinstall) { status = do_subproc(postcmdbuf); diff --git a/usr/src/head/libzonecfg.h b/usr/src/head/libzonecfg.h index 4579a076c3..0212224de5 100644 --- a/usr/src/head/libzonecfg.h +++ b/usr/src/head/libzonecfg.h @@ -538,6 +538,7 @@ extern int zone_set_state(char *, zone_state_t); extern char *zone_state_str(zone_state_t); extern int zonecfg_get_name_by_uuid(const uuid_t, char *, size_t); extern int zonecfg_get_uuid(const char *, uuid_t); +extern int zonecfg_set_uuid(const char *, const char *, const char *); extern int zonecfg_default_brand(char *, size_t); extern int zonecfg_fix_obsolete(zone_dochandle_t); diff --git a/usr/src/lib/brand/joyent/zone/Makefile b/usr/src/lib/brand/joyent/zone/Makefile index 257a647fae..84433e60a5 100644 --- a/usr/src/lib/brand/joyent/zone/Makefile +++ b/usr/src/lib/brand/joyent/zone/Makefile @@ -24,7 +24,7 @@ # Use is subject to license terms. # -PROGS = jattach jdetach jinstall juninstall pinstall prestate \ +PROGS = jattach jdetach jinstall juninstall prestate \ poststate statechange query XMLDOCS= config.xml platform.xml common.ksh USERFILES= diff --git a/usr/src/lib/brand/joyent/zone/config.xml b/usr/src/lib/brand/joyent/zone/config.xml index 4c79e8d728..dccb68b4c3 100644 --- a/usr/src/lib/brand/joyent/zone/config.xml +++ b/usr/src/lib/brand/joyent/zone/config.xml @@ -44,7 +44,7 @@ <verify_cfg></verify_cfg> <verify_adm></verify_adm> <postclone></postclone> - <postinstall>/usr/lib/brand/joyent/pinstall -z %z -R %R</postinstall> + <postinstall></postinstall> <attach>/usr/lib/brand/joyent/jattach -z %z -R %R</attach> <detach>/usr/lib/brand/joyent/jdetach -z %z -R %R</detach> <clone></clone> diff --git a/usr/src/lib/brand/joyent/zone/pinstall.ksh b/usr/src/lib/brand/joyent/zone/pinstall.ksh deleted file mode 100644 index dd78bf6452..0000000000 --- a/usr/src/lib/brand/joyent/zone/pinstall.ksh +++ /dev/null @@ -1,71 +0,0 @@ -#!/bin/ksh -p -# -# CDDL HEADER START -# -# The contents of this file are subject to the terms of the -# Common Development and Distribution License (the "License"). -# You may not use this file except in compliance with the License. -# -# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE -# or http://www.opensolaris.org/os/licensing. -# See the License for the specific language governing permissions -# and limitations under the License. -# -# When distributing Covered Code, include this CDDL HEADER in each -# file and include the License file at usr/src/OPENSOLARIS.LICENSE. -# If applicable, add the following below this CDDL HEADER, with the -# fields enclosed by brackets "[]" replaced with your own identifying -# information: Portions Copyright [yyyy] [name of copyright owner] -# -# CDDL HEADER END -# -# Copyright 2010 Joyent, Inc. All rights reserved. -# Use is subject to license terms. -# - -unset LD_LIBRARY_PATH -PATH=/usr/bin:/usr/sbin -export PATH - -. /usr/lib/brand/shared/common.ksh - -ZONENAME="" -ZONEPATH="" -# Default to 10GB diskset quota -ZQUOTA=10 - -while getopts "R:t:U:q:z:" opt -do - case "$opt" in - R) ZONEPATH="$OPTARG";; - # template is only used in the postinstall script - t) TMPLZONE="$OPTARG";; - U) UUID="$OPTARG";; - # zquota is only used in the postinstall script - q) ZQUOTA="$OPTARG";; - z) ZONENAME="$OPTARG";; - *) printf "$m_usage\n" - exit $ZONE_SUBPROC_USAGE;; - esac -done -shift OPTIND-1 - -if [[ -z $ZONENAME ]]; then - print -u2 "Brand error: No zone name" - exit $ZONE_SUBPROC_USAGE -fi - -# If no UUID provided, then nothing to do. -[[ -z $UUID ]] && exit $ZONE_SUBPROC_OK - -nawk -F: -v zonename=$ZONENAME -v uuid=$UUID '{ - if ($1 != zonename) { - print $0 - next - } - printf("%s:%s:%s:%s\n", $1, $2, $3, uuid); -}' /etc/zones/index >/etc/zones/index.new -cp /etc/zones/index.new /etc/zones/index -rm -f /etc/zones/index.new - -exit $ZONE_SUBPROC_OK diff --git a/usr/src/lib/brand/kvm/zone/Makefile b/usr/src/lib/brand/kvm/zone/Makefile index 6a1055e36d..299ae93397 100644 --- a/usr/src/lib/brand/kvm/zone/Makefile +++ b/usr/src/lib/brand/kvm/zone/Makefile @@ -24,7 +24,7 @@ # Use is subject to license terms. # -PROGS = kattach kdetach kinstall kuninstall pinstall prestate \ +PROGS = kattach kdetach kinstall kuninstall prestate \ poststate statechange XMLDOCS= config.xml platform.xml common.ksh USERFILES= diff --git a/usr/src/lib/brand/kvm/zone/config.xml b/usr/src/lib/brand/kvm/zone/config.xml index ee26d52b89..af9b565be2 100644 --- a/usr/src/lib/brand/kvm/zone/config.xml +++ b/usr/src/lib/brand/kvm/zone/config.xml @@ -45,7 +45,7 @@ <verify_cfg></verify_cfg> <verify_adm></verify_adm> <postclone></postclone> - <postinstall>/usr/lib/brand/kvm/pinstall -z %z -R %R</postinstall> + <postinstall></postinstall> <attach>/usr/lib/brand/kvm/kattach -z %z -R %R</attach> <detach>/usr/lib/brand/kvm/kdetach -z %z -R %R</detach> <clone></clone> diff --git a/usr/src/lib/brand/kvm/zone/pinstall.ksh b/usr/src/lib/brand/kvm/zone/pinstall.ksh deleted file mode 100755 index dd78bf6452..0000000000 --- a/usr/src/lib/brand/kvm/zone/pinstall.ksh +++ /dev/null @@ -1,71 +0,0 @@ -#!/bin/ksh -p -# -# CDDL HEADER START -# -# The contents of this file are subject to the terms of the -# Common Development and Distribution License (the "License"). -# You may not use this file except in compliance with the License. -# -# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE -# or http://www.opensolaris.org/os/licensing. -# See the License for the specific language governing permissions -# and limitations under the License. -# -# When distributing Covered Code, include this CDDL HEADER in each -# file and include the License file at usr/src/OPENSOLARIS.LICENSE. -# If applicable, add the following below this CDDL HEADER, with the -# fields enclosed by brackets "[]" replaced with your own identifying -# information: Portions Copyright [yyyy] [name of copyright owner] -# -# CDDL HEADER END -# -# Copyright 2010 Joyent, Inc. All rights reserved. -# Use is subject to license terms. -# - -unset LD_LIBRARY_PATH -PATH=/usr/bin:/usr/sbin -export PATH - -. /usr/lib/brand/shared/common.ksh - -ZONENAME="" -ZONEPATH="" -# Default to 10GB diskset quota -ZQUOTA=10 - -while getopts "R:t:U:q:z:" opt -do - case "$opt" in - R) ZONEPATH="$OPTARG";; - # template is only used in the postinstall script - t) TMPLZONE="$OPTARG";; - U) UUID="$OPTARG";; - # zquota is only used in the postinstall script - q) ZQUOTA="$OPTARG";; - z) ZONENAME="$OPTARG";; - *) printf "$m_usage\n" - exit $ZONE_SUBPROC_USAGE;; - esac -done -shift OPTIND-1 - -if [[ -z $ZONENAME ]]; then - print -u2 "Brand error: No zone name" - exit $ZONE_SUBPROC_USAGE -fi - -# If no UUID provided, then nothing to do. -[[ -z $UUID ]] && exit $ZONE_SUBPROC_OK - -nawk -F: -v zonename=$ZONENAME -v uuid=$UUID '{ - if ($1 != zonename) { - print $0 - next - } - printf("%s:%s:%s:%s\n", $1, $2, $3, uuid); -}' /etc/zones/index >/etc/zones/index.new -cp /etc/zones/index.new /etc/zones/index -rm -f /etc/zones/index.new - -exit $ZONE_SUBPROC_OK diff --git a/usr/src/lib/libzonecfg/common/getzoneent.c b/usr/src/lib/libzonecfg/common/getzoneent.c index 8155f7272a..76cc918553 100644 --- a/usr/src/lib/libzonecfg/common/getzoneent.c +++ b/usr/src/lib/libzonecfg/common/getzoneent.c @@ -419,6 +419,12 @@ putzoneent(struct zoneent *ze, zoneent_op_t operation) if (ze->zone_path[0] != '\0') zone_path = ze->zone_path; + + /* If new UUID provided, replace it */ + if (!uuid_is_null(ze->zone_uuid)) { + uuid_unparse(ze->zone_uuid, uuidstr); + zone_uuid = uuidstr; + } break; case PZE_REMOVE: diff --git a/usr/src/lib/libzonecfg/common/libzonecfg.c b/usr/src/lib/libzonecfg/common/libzonecfg.c index 42312867fb..f5ac4975d8 100644 --- a/usr/src/lib/libzonecfg/common/libzonecfg.c +++ b/usr/src/lib/libzonecfg/common/libzonecfg.c @@ -6226,6 +6226,30 @@ zonecfg_get_uuid(const char *zonename, uuid_t uuid) } /* + * Changes a zone's UUID to the given value. Returns an error if the UUID is + * malformed or if the zone cannot be located. + */ +int +zonecfg_set_uuid(const char *zonename, const char *zonepath, + const char *uuid) +{ + int err; + struct zoneent ze; + + bzero(&ze, sizeof (ze)); + ze.zone_state = -1; /* Preserve existing state in index */ + (void) strlcpy(ze.zone_name, zonename, sizeof (ze.zone_name)); + (void) strlcpy(ze.zone_path, zonepath, sizeof (ze.zone_path)); + if (uuid_parse((char *)uuid, ze.zone_uuid) == -1) + return (Z_INVALID_PROPERTY); + + if ((err = putzoneent(&ze, PZE_MODIFY)) != Z_OK) + return (err); + + return (Z_OK); +} + +/* * File-system convenience functions. */ boolean_t diff --git a/usr/src/lib/libzonecfg/common/mapfile-vers b/usr/src/lib/libzonecfg/common/mapfile-vers index 2f735785ed..7265b06a1f 100644 --- a/usr/src/lib/libzonecfg/common/mapfile-vers +++ b/usr/src/lib/libzonecfg/common/mapfile-vers @@ -214,6 +214,7 @@ SYMBOL_VERSION SUNWprivate_1.1 { zonecfg_set_root; zonecfg_set_sched; zonecfg_set_swinv; + zonecfg_set_uuid; zonecfg_set_zonepath; zonecfg_strerror; zonecfg_str_to_bytes; |