summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJerry Jelinek <jerry.jelinek@joyent.com>2014-11-13 10:33:48 -0800
committerRobert Mustacchi <rm@joyent.com>2014-12-05 14:57:33 -0800
commitbafd1f1462c49949e0251d74b4fbfa24d29bc79a (patch)
tree03049033757285b88f8fb6ace7da16e061199c5c
parent156d6b3a5d0ba06e75f7973c6ba994107ae8df0e (diff)
downloadillumos-joyent-bafd1f1462c49949e0251d74b4fbfa24d29bc79a.tar.gz
5330 zone brands could control init restart behavior
Reviewed by: Igor Kozhukhov <ikozhukhov@gmail.com> Reviewed by: Gordon Ross <gwr@nexenta.com> Reviewed by: Josef 'Jeff' Sipek <josef.sipek@nexenta.com> Reviewed by: Richard Lowe <richlowe@richlowe.net> Approved by: Dan McDonald <danmcd@omniti.com>
-rw-r--r--usr/src/cmd/zoneadmd/zoneadmd.c10
-rw-r--r--usr/src/lib/libbrand/common/libbrand.c17
-rw-r--r--usr/src/lib/libbrand/common/libbrand.h2
-rw-r--r--usr/src/lib/libbrand/common/mapfile-vers2
-rw-r--r--usr/src/lib/libbrand/dtd/brand.dtd.118
-rw-r--r--usr/src/uts/common/os/exit.c15
-rw-r--r--usr/src/uts/common/os/zone.c4
-rw-r--r--usr/src/uts/common/sys/zone.h1
8 files changed, 63 insertions, 6 deletions
diff --git a/usr/src/cmd/zoneadmd/zoneadmd.c b/usr/src/cmd/zoneadmd/zoneadmd.c
index 7a9d88410d..cb81b77727 100644
--- a/usr/src/cmd/zoneadmd/zoneadmd.c
+++ b/usr/src/cmd/zoneadmd/zoneadmd.c
@@ -817,6 +817,7 @@ zone_bootup(zlog_t *zlogp, const char *bootargs, int zstate)
dladm_status_t status;
char errmsg[DLADM_STRSIZE];
int err;
+ boolean_t restart_init;
if (brand_prestatechg(zlogp, zstate, Z_BOOT) != 0)
return (-1);
@@ -873,6 +874,9 @@ zone_bootup(zlog_t *zlogp, const char *bootargs, int zstate)
goto bad;
}
+ /* See if this zone's brand should restart init if it dies. */
+ restart_init = brand_restartinit(bh);
+
brand_close(bh);
err = filter_bootargs(zlogp, bootargs, nbootargs, init_file,
@@ -939,6 +943,12 @@ zone_bootup(zlog_t *zlogp, const char *bootargs, int zstate)
goto bad;
}
+ if (!restart_init && zone_setattr(zoneid, ZONE_ATTR_INITNORESTART,
+ NULL, 0) == -1) {
+ zerror(zlogp, B_TRUE, "could not set zone init-no-restart");
+ goto bad;
+ }
+
/*
* Inform zonestatd of a new zone so that it can install a door for
* the zone to contact it.
diff --git a/usr/src/lib/libbrand/common/libbrand.c b/usr/src/lib/libbrand/common/libbrand.c
index 6cbc90eb59..7d34df9e58 100644
--- a/usr/src/lib/libbrand/common/libbrand.c
+++ b/usr/src/lib/libbrand/common/libbrand.c
@@ -21,6 +21,7 @@
/*
* Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, Joyent, Inc. All rights reserved.
* Copyright 2014 Nexenta Systems, Inc. All rights reserved.
*/
@@ -61,6 +62,7 @@
#define DTD_ELEM_FORCELOGIN_CMD ((const xmlChar *) "forcedlogin_cmd")
#define DTD_ELEM_MODNAME ((const xmlChar *) "modname")
#define DTD_ELEM_MOUNT ((const xmlChar *) "mount")
+#define DTD_ELEM_RESTARTINIT ((const xmlChar *) "restartinit")
#define DTD_ELEM_POSTATTACH ((const xmlChar *) "postattach")
#define DTD_ELEM_POSTCLONE ((const xmlChar *) "postclone")
#define DTD_ELEM_POSTINSTALL ((const xmlChar *) "postinstall")
@@ -520,6 +522,21 @@ brand_get_initname(brand_handle_t bh, char *buf, size_t len)
buf, len, DTD_ELEM_INITNAME, B_FALSE, B_FALSE));
}
+boolean_t
+brand_restartinit(brand_handle_t bh)
+{
+ struct brand_handle *bhp = (struct brand_handle *)bh;
+ char val[80];
+
+ if (brand_get_value(bhp, NULL, NULL, NULL, NULL,
+ val, sizeof (val), DTD_ELEM_RESTARTINIT, B_FALSE, B_FALSE) != 0)
+ return (B_TRUE);
+
+ if (strcmp(val, "false") == 0)
+ return (B_FALSE);
+ return (B_TRUE);
+}
+
int
brand_get_login_cmd(brand_handle_t bh, const char *username,
char *buf, size_t len)
diff --git a/usr/src/lib/libbrand/common/libbrand.h b/usr/src/lib/libbrand/common/libbrand.h
index 6e8a596b3a..5c5fb1b42e 100644
--- a/usr/src/lib/libbrand/common/libbrand.h
+++ b/usr/src/lib/libbrand/common/libbrand.h
@@ -21,6 +21,7 @@
/*
* Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, Joyent, Inc. All rights reserved.
* Copyright 2014 Nexenta Systems, Inc. All rights reserved.
*/
@@ -60,6 +61,7 @@ extern int brand_get_shutdown(brand_handle_t, const char *, const char *,
extern int brand_get_halt(brand_handle_t, const char *, const char *,
char *, size_t);
extern int brand_get_initname(brand_handle_t, char *, size_t);
+extern boolean_t brand_restartinit(brand_handle_t);
extern int brand_get_install(brand_handle_t, const char *, const char *,
char *, size_t);
extern int brand_get_installopts(brand_handle_t, char *, size_t);
diff --git a/usr/src/lib/libbrand/common/mapfile-vers b/usr/src/lib/libbrand/common/mapfile-vers
index 7b932b927f..be79ae12b7 100644
--- a/usr/src/lib/libbrand/common/mapfile-vers
+++ b/usr/src/lib/libbrand/common/mapfile-vers
@@ -20,6 +20,7 @@
#
#
# Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved.
+# Copyright (c) 2011, Joyent, Inc. All rights reserved.
# Copyright 2014 Nexenta Systems, Inc. All rights reserved.
#
@@ -78,6 +79,7 @@ SYMBOL_VERSION SUNWprivate {
brand_platform_iter_gmounts;
brand_platform_iter_link;
brand_platform_iter_mounts;
+ brand_restartinit;
local:
*;
};
diff --git a/usr/src/lib/libbrand/dtd/brand.dtd.1 b/usr/src/lib/libbrand/dtd/brand.dtd.1
index 86c0085d51..a579bee93c 100644
--- a/usr/src/lib/libbrand/dtd/brand.dtd.1
+++ b/usr/src/lib/libbrand/dtd/brand.dtd.1
@@ -21,6 +21,7 @@
CDDL HEADER END
Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved.
+ Copyright (c) 2011, Joyent, Inc. All rights reserved.
DO NOT EDIT THIS FILE.
@@ -211,6 +212,19 @@
<!ATTLIST initname>
<!--
+ restartinit
+
+ Boolean indicating that the program specified by the initname attr
+ should be restarted, or not, if it exits. By default, the init program
+ will be restarted if this attribute is not provided. Specifying false
+ for this attr will prevent that.
+
+ It has no attributes.
+-->
+<!ELEMENT restartinit (#PCDATA) >
+<!ATTLIST restartinit>
+
+<!--
login_cmd
Path to the initial login binary that should be executed when
@@ -628,8 +642,8 @@
directory in which the configuration file is stored.
-->
-<!ELEMENT brand (modname?, initname, login_cmd, forcedlogin_cmd,
- user_cmd, install,
+<!ELEMENT brand (modname?, initname, restartinit?, login_cmd,
+ forcedlogin_cmd, user_cmd, install,
installopts?, boot?, sysboot?, halt?, shutdown?,
verify_cfg?, verify_adm?, postattach?, postclone?,
postinstall?, predetach?, attach?, detach?, clone?,
diff --git a/usr/src/uts/common/os/exit.c b/usr/src/uts/common/os/exit.c
index 21360145bc..c5d54b5978 100644
--- a/usr/src/uts/common/os/exit.c
+++ b/usr/src/uts/common/os/exit.c
@@ -21,6 +21,7 @@
/*
* Copyright (c) 1988, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, Joyent, Inc. All rights reserved.
*/
/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
@@ -388,10 +389,16 @@ proc_exit(int why, int what)
if (p->p_pid == z->zone_proc_initpid) {
if (z->zone_boot_err == 0 &&
zone_status_get(z) < ZONE_IS_SHUTTING_DOWN &&
- zone_status_get(global_zone) < ZONE_IS_SHUTTING_DOWN &&
- z->zone_restart_init == B_TRUE &&
- restart_init(what, why) == 0)
- return (0);
+ zone_status_get(global_zone) < ZONE_IS_SHUTTING_DOWN) {
+ if (z->zone_restart_init == B_TRUE) {
+ if (restart_init(what, why) == 0)
+ return (0);
+ } else {
+ (void) zone_kadmin(A_SHUTDOWN, AD_HALT, NULL,
+ CRED());
+ }
+ }
+
/*
* Since we didn't or couldn't restart init, we clear
* the zone's init state and proceed with exit
diff --git a/usr/src/uts/common/os/zone.c b/usr/src/uts/common/os/zone.c
index 884d52b224..5d146c03b5 100644
--- a/usr/src/uts/common/os/zone.c
+++ b/usr/src/uts/common/os/zone.c
@@ -5525,6 +5525,10 @@ zone_setattr(zoneid_t zoneid, int attr, void *buf, size_t bufsize)
case ZONE_ATTR_INITNAME:
err = zone_set_initname(zone, (const char *)buf);
break;
+ case ZONE_ATTR_INITNORESTART:
+ zone->zone_restart_init = B_FALSE;
+ err = 0;
+ break;
case ZONE_ATTR_BOOTARGS:
err = zone_set_bootargs(zone, (const char *)buf);
break;
diff --git a/usr/src/uts/common/sys/zone.h b/usr/src/uts/common/sys/zone.h
index cb701bc713..7e567c0cdb 100644
--- a/usr/src/uts/common/sys/zone.h
+++ b/usr/src/uts/common/sys/zone.h
@@ -103,6 +103,7 @@ extern "C" {
#define ZONE_ATTR_HOSTID 15
#define ZONE_ATTR_FS_ALLOWED 16
#define ZONE_ATTR_NETWORK 17
+#define ZONE_ATTR_INITNORESTART 20
/* Start of the brand-specific attribute namespace */
#define ZONE_ATTR_BRAND_ATTRS 32768