summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Mustacchi <rm@joyent.com>2013-03-11 17:58:25 +0000
committerRobert Mustacchi <rm@joyent.com>2013-03-13 17:15:25 +0000
commitad7b383f89e555af29cc3897dd966af7c567b805 (patch)
tree29c07aeb6052ec798b9057da9dd909e60e528ada
parentb63b6f0204a00edd3eea013cdcbb9b0eaf5d2f33 (diff)
downloadillumos-joyent-ad7b383f89e555af29cc3897dd966af7c567b805.tar.gz
OS-2013 psrset should support specifying a zone to bind
OS-2018 zoneadmd should export all attributes to brand statechange scripts
-rw-r--r--usr/src/cmd/psrset/psrset.c64
-rw-r--r--usr/src/cmd/zoneadmd/zoneadmd.c18
-rw-r--r--usr/src/man/man1m/psrset.1m13
3 files changed, 80 insertions, 15 deletions
diff --git a/usr/src/cmd/psrset/psrset.c b/usr/src/cmd/psrset/psrset.c
index 35585499a9..41724137ef 100644
--- a/usr/src/cmd/psrset/psrset.c
+++ b/usr/src/cmd/psrset/psrset.c
@@ -22,6 +22,9 @@
* Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
+/*
+ * Copyright (c) 2013, Joyent, Inc. All rights reserved.
+ */
/*
* psrset - create and manage processor sets
@@ -41,6 +44,7 @@
#include <procfs.h>
#include <libproc.h>
#include <stdarg.h>
+#include <zone.h>
#if !defined(TEXT_DOMAIN) /* should be defined by cc -D */
#define TEXT_DOMAIN "SYS_TEST" /* Use this only if it wasn't */
@@ -69,6 +73,8 @@ static char nflag;
static char fflag;
static char Fflag;
static char eflag;
+static char zflag;
+static const char *zname;
extern int pset_assign_forced(psetid_t, processorid_t, psetid_t *);
@@ -128,7 +134,7 @@ rele_proc(struct ps_prochandle *Pr)
}
static void
-bind_err(psetid_t pset, id_t pid, id_t lwpid, int err)
+bind_err(psetid_t pset, const char *zname, id_t pid, id_t lwpid, int err)
{
char *msg;
@@ -145,7 +151,9 @@ bind_err(psetid_t pset, id_t pid, id_t lwpid, int err)
}
errno = err;
- if (lwpid == -1)
+ if (zname != NULL)
+ warn(gettext("cannot %s zone %s"), msg, zname);
+ else if (lwpid == -1)
warn(gettext("cannot %s pid %d"), msg, pid);
else
warn(gettext("cannot %s lwpid %d/%d"), msg, pid, lwpid);
@@ -281,7 +289,7 @@ bind_lwp(id_t pid, id_t lwpid, psetid_t pset)
psetid_t old_pset;
if (pset_bind_lwp(pset, lwpid, pid, &old_pset) != 0) {
- bind_err(pset, pid, lwpid, errno);
+ bind_err(pset, NULL, pid, lwpid, errno);
errors = ERR_FAIL;
}
if (errors != ERR_FAIL) {
@@ -491,7 +499,7 @@ query_all_proc(psinfo_t *psinfo, lwpsinfo_t *lwpsinfo, void *arg)
*/
if (errno == ESRCH)
return (0);
- bind_err(PS_QUERY, pid, -1, errno);
+ bind_err(PS_QUERY, NULL, pid, -1, errno);
errors = ERR_FAIL;
return (0);
}
@@ -542,6 +550,7 @@ usage(void)
"\t%1$s -r [-F] processor_id ...\n"
"\t%1$s -p [processorid ...]\n"
"\t%1$s -b processor_set_id pid[/lwpids] ...\n"
+ "\t%1$s -b -z zonename processor_set_id\n"
"\t%1$s -u pid[/lwpids] ...\n"
"\t%1$s -q [pid[/lwpids] ...]\n"
"\t%1$s -U [processor_set_id] ...\n"
@@ -574,23 +583,23 @@ do_lwps(id_t pid, const char *range, psetid_t pset)
if ((fd = open(procfile, O_RDONLY)) < 0) {
if (errno == ENOENT)
errno = ESRCH;
- bind_err(pset, pid, -1, errno);
+ bind_err(pset, NULL, pid, -1, errno);
return (ERR_FAIL);
}
if (pread(fd, &header, sizeof (header), 0) != sizeof (header)) {
(void) close(fd);
- bind_err(pset, pid, -1, errno);
+ bind_err(pset, NULL, pid, -1, errno);
return (ERR_FAIL);
}
nent = header.pr_nent;
size = header.pr_entsize * nent;
ptr = lpsinfo = malloc(size);
if (lpsinfo == NULL) {
- bind_err(pset, pid, -1, errno);
+ bind_err(pset, NULL, pid, -1, errno);
return (ERR_FAIL);
}
if (pread(fd, lpsinfo, size, sizeof (header)) != size) {
- bind_err(pset, pid, -1, errno);
+ bind_err(pset, NULL, pid, -1, errno);
free(lpsinfo);
(void) close(fd);
return (ERR_FAIL);
@@ -635,6 +644,7 @@ main(int argc, char *argv[])
id_t pid;
processorid_t cpu;
psetid_t pset, old_pset;
+ zoneid_t zid;
char *errptr;
progname = argv[0]; /* put actual command name in messages */
@@ -642,7 +652,7 @@ main(int argc, char *argv[])
(void) setlocale(LC_ALL, ""); /* setup localization */
(void) textdomain(TEXT_DOMAIN);
- while ((c = getopt(argc, argv, "cdFarpibqQuUnfe")) != EOF) {
+ while ((c = getopt(argc, argv, "cdFarpibqQuUnfez:")) != EOF) {
switch (c) {
case 'c':
cflag = 1;
@@ -693,6 +703,19 @@ main(int argc, char *argv[])
case 'n':
nflag = 1;
break;
+ case 'z':
+ if (!bflag) {
+ warn(gettext("-z can only be used after -b\n"));
+ return (usage());
+ }
+ if (zflag) {
+ warn(gettext("-z can only be specified "
+ "once\n"));
+ return (usage());
+ }
+ zflag = 1;
+ zname = optarg;
+ break;
default:
return (usage());
}
@@ -859,9 +882,28 @@ main(int argc, char *argv[])
/*
* Perform function for each pid/lwpid specified.
*/
- if (argc == 0) {
+ if (argc == 0 && !zflag) {
warn(gettext("must specify at least one pid\n"));
return (usage());
+ } else if (argc > 0 && zflag) {
+ warn(gettext("cannot specify extra pids with -z\n"));
+ return (usage());
+ }
+
+ if (zflag) {
+ zid = getzoneidbyname(zname);
+ if (zid < 0) {
+ warn(gettext("invalid zone name: %s\n"),
+ zname);
+ errors = ERR_FAIL;
+ } else if (pset_bind(pset, P_ZONEID, zid,
+ &old_pset) < 0) {
+ bind_err(pset, zname, -1, -1, errno);
+ errors = ERR_FAIL;
+ } else {
+ (void) printf(gettext("zone %s: bound to %d\n"),
+ zname, pset);
+ }
}
/*
@@ -902,7 +944,7 @@ main(int argc, char *argv[])
*/
if (pset_bind(pset, P_PID, pid,
&old_pset) < 0) {
- bind_err(pset, pid, -1, errno);
+ bind_err(pset, NULL, pid, -1, errno);
errors = ERR_FAIL;
continue;
}
diff --git a/usr/src/cmd/zoneadmd/zoneadmd.c b/usr/src/cmd/zoneadmd/zoneadmd.c
index 91c6f1764b..bfa3b937ca 100644
--- a/usr/src/cmd/zoneadmd/zoneadmd.c
+++ b/usr/src/cmd/zoneadmd/zoneadmd.c
@@ -770,7 +770,12 @@ set_zonecfg_env(char *rsrc, char *attr, char *name, char *val)
char *p;
char nm[MAXNAMELEN];
- (void) snprintf(nm, sizeof (nm), "_ZONECFG_%s_%s_%s", rsrc, attr, name);
+ if (attr == NULL)
+ (void) snprintf(nm, sizeof (nm), "_ZONECFG_%s_%s", rsrc,
+ name);
+ else
+ (void) snprintf(nm, sizeof (nm), "_ZONECFG_%s_%s_%s", rsrc,
+ attr, name);
p = nm;
while ((p = strchr(p, '-')) != NULL)
@@ -792,6 +797,7 @@ setup_subproc_env(boolean_t debug)
int res;
struct zone_nwiftab ntab;
struct zone_devtab dtab;
+ struct zone_attrtab atab;
char net_resources[MAXNAMELEN * 2];
char dev_resources[MAXNAMELEN * 2];
@@ -857,6 +863,16 @@ setup_subproc_env(boolean_t debug)
(void) zonecfg_enddevent(snap_hndl);
+ if ((res = zonecfg_setattrent(snap_hndl)) != Z_OK)
+ goto done;
+
+ while (zonecfg_getattrent(snap_hndl, &atab) == Z_OK) {
+ set_zonecfg_env("attr", NULL, atab.zone_attr_name,
+ atab.zone_attr_value);
+ }
+
+ (void) zonecfg_endattrent(snap_hndl);
+
if (debug)
(void) setenv("_ZONEADMD_brand_debug", "1", 1);
else
diff --git a/usr/src/man/man1m/psrset.1m b/usr/src/man/man1m/psrset.1m
index 0212e6fa07..519d2c1e5c 100644
--- a/usr/src/man/man1m/psrset.1m
+++ b/usr/src/man/man1m/psrset.1m
@@ -1,9 +1,10 @@
'\" te
+.\" Copyright (c) 2013, Joyent, Inc. All Rights Reserved
.\" Copyright (c) 2008, Sun Microsystems, Inc. All Rights Reserved
.\" 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]
-.TH PSRSET 1M "Feb 25, 2008"
+.TH PSRSET 1M "Mar 11, 2013"
.SH NAME
psrset \- creation and management of processor sets
.SH SYNOPSIS
@@ -19,6 +20,11 @@ psrset \- creation and management of processor sets
.LP
.nf
+\fBpsrset\fR \fB-b\fR \fB-z\fR \fIzone name\fR \fIprocessor_set_id\fR
+.fi
+
+.LP
+.nf
\fBpsrset\fR \fB-c\fR [\fB-F\fR] [\fIprocessor_id\fR]...
.fi
@@ -110,11 +116,12 @@ privilege.
.sp
.ne 2
.na
-\fB\fB-b\fR\fR
+\fB\fB-b\fR [\fB-z\fr \fIzonename\fR]\fR
.ad
.RS 6n
Bind all or a subset of the \fBLWP\fRs of the specified processes to the
-specified processor set.
+specified processor set. If \fB-z\fR is specified, all processes and threads
+inside the specified zone are bound to the processor set.
.sp
LWPs bound to a processor set are restricted to run only on the processors in
that set. Processes can only be bound to non-empty processor sets, that is,