2017-11-27 15:37:16 +00:00
|
|
|
/*-
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause-FreeBSD
|
|
|
|
*
|
2008-03-02 07:51:29 +00:00
|
|
|
* Copyright (c) 2007, 2008 Jeffrey Roberson <jeff@freebsd.org>
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
2008-04-11 03:27:42 +00:00
|
|
|
* Copyright (c) 2008 Nokia Corporation
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
2008-03-02 07:51:29 +00:00
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/time.h>
|
|
|
|
#include <sys/resource.h>
|
|
|
|
#include <sys/cpuset.h>
|
2018-01-12 22:48:23 +00:00
|
|
|
#include <sys/domainset.h>
|
2008-03-02 07:51:29 +00:00
|
|
|
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <err.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <limits.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <unistd.h>
|
2009-12-13 03:14:06 +00:00
|
|
|
#include <string.h>
|
2008-03-02 07:51:29 +00:00
|
|
|
|
2011-11-06 08:14:40 +00:00
|
|
|
static int Cflag;
|
|
|
|
static int cflag;
|
2015-01-08 15:53:13 +00:00
|
|
|
static int dflag;
|
2011-11-06 08:14:40 +00:00
|
|
|
static int gflag;
|
|
|
|
static int iflag;
|
|
|
|
static int jflag;
|
|
|
|
static int lflag;
|
2018-01-12 22:48:23 +00:00
|
|
|
static int nflag;
|
2011-11-06 08:14:40 +00:00
|
|
|
static int pflag;
|
|
|
|
static int rflag;
|
|
|
|
static int sflag;
|
|
|
|
static int tflag;
|
|
|
|
static int xflag;
|
|
|
|
static id_t id;
|
|
|
|
static cpulevel_t level;
|
|
|
|
static cpuwhich_t which;
|
2008-03-02 07:51:29 +00:00
|
|
|
|
2011-11-06 08:14:40 +00:00
|
|
|
static void usage(void);
|
2008-03-02 07:51:29 +00:00
|
|
|
|
2018-01-12 22:48:23 +00:00
|
|
|
struct numa_policy {
|
|
|
|
const char *name;
|
|
|
|
int policy;
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct numa_policy policies[] = {
|
|
|
|
{ "round-robin", DOMAINSET_POLICY_ROUNDROBIN },
|
|
|
|
{ "rr", DOMAINSET_POLICY_ROUNDROBIN },
|
|
|
|
{ "first-touch", DOMAINSET_POLICY_FIRSTTOUCH },
|
|
|
|
{ "ft", DOMAINSET_POLICY_FIRSTTOUCH },
|
|
|
|
{ "prefer", DOMAINSET_POLICY_PREFER },
|
2018-03-29 02:54:50 +00:00
|
|
|
{ "interleave", DOMAINSET_POLICY_INTERLEAVE},
|
|
|
|
{ "il", DOMAINSET_POLICY_INTERLEAVE},
|
2018-01-12 22:48:23 +00:00
|
|
|
{ NULL, DOMAINSET_POLICY_INVALID }
|
|
|
|
};
|
|
|
|
|
|
|
|
static void printset(struct bitset *mask, int size);
|
2008-03-02 07:51:29 +00:00
|
|
|
|
|
|
|
static void
|
2018-01-12 22:48:23 +00:00
|
|
|
parselist(char *list, struct bitset *mask, int size)
|
2008-03-02 07:51:29 +00:00
|
|
|
{
|
|
|
|
enum { NONE, NUM, DASH } state;
|
|
|
|
int lastnum;
|
|
|
|
int curnum;
|
|
|
|
char *l;
|
|
|
|
|
|
|
|
state = NONE;
|
|
|
|
curnum = lastnum = 0;
|
|
|
|
for (l = list; *l != '\0';) {
|
|
|
|
if (isdigit(*l)) {
|
|
|
|
curnum = atoi(l);
|
2018-01-12 22:48:23 +00:00
|
|
|
if (curnum > size)
|
2008-03-02 07:51:29 +00:00
|
|
|
errx(EXIT_FAILURE,
|
2018-01-12 22:48:23 +00:00
|
|
|
"List entry %d exceeds maximum of %d",
|
|
|
|
curnum, size);
|
2008-03-02 07:51:29 +00:00
|
|
|
while (isdigit(*l))
|
|
|
|
l++;
|
|
|
|
switch (state) {
|
|
|
|
case NONE:
|
|
|
|
lastnum = curnum;
|
|
|
|
state = NUM;
|
|
|
|
break;
|
|
|
|
case DASH:
|
|
|
|
for (; lastnum <= curnum; lastnum++)
|
2018-01-12 22:48:23 +00:00
|
|
|
BIT_SET(size, lastnum, mask);
|
2008-03-02 07:51:29 +00:00
|
|
|
state = NONE;
|
|
|
|
break;
|
|
|
|
case NUM:
|
|
|
|
default:
|
|
|
|
goto parserr;
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
switch (*l) {
|
|
|
|
case ',':
|
|
|
|
switch (state) {
|
|
|
|
case NONE:
|
|
|
|
break;
|
|
|
|
case NUM:
|
2018-01-12 22:48:23 +00:00
|
|
|
BIT_SET(size, curnum, mask);
|
2008-03-02 07:51:29 +00:00
|
|
|
state = NONE;
|
|
|
|
break;
|
|
|
|
case DASH:
|
|
|
|
goto parserr;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case '-':
|
|
|
|
if (state != NUM)
|
|
|
|
goto parserr;
|
|
|
|
state = DASH;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
goto parserr;
|
|
|
|
}
|
|
|
|
l++;
|
|
|
|
}
|
|
|
|
switch (state) {
|
|
|
|
case NONE:
|
|
|
|
break;
|
|
|
|
case NUM:
|
2018-01-12 22:48:23 +00:00
|
|
|
BIT_SET(size, curnum, mask);
|
2008-03-02 07:51:29 +00:00
|
|
|
break;
|
|
|
|
case DASH:
|
|
|
|
goto parserr;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
parserr:
|
2018-01-12 22:48:23 +00:00
|
|
|
errx(EXIT_FAILURE, "Malformed list %s", list);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
parsecpulist(char *list, cpuset_t *mask)
|
|
|
|
{
|
|
|
|
|
|
|
|
if (strcasecmp(list, "all") == 0) {
|
|
|
|
if (cpuset_getaffinity(CPU_LEVEL_ROOT, CPU_WHICH_PID, -1,
|
|
|
|
sizeof(*mask), mask) != 0)
|
|
|
|
err(EXIT_FAILURE, "getaffinity");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
parselist(list, (struct bitset *)mask, CPU_SETSIZE);
|
2008-03-02 07:51:29 +00:00
|
|
|
}
|
|
|
|
|
2018-01-12 22:48:23 +00:00
|
|
|
/*
|
|
|
|
* permissively parse policy:domain list
|
|
|
|
* allow:
|
|
|
|
* round-robin:0-4 explicit
|
|
|
|
* round-robin:all explicit root domains
|
|
|
|
* 0-4 implicit root policy
|
|
|
|
* round-robin implicit root domains
|
|
|
|
* all explicit root domains and implicit policy
|
|
|
|
*/
|
2008-03-02 07:51:29 +00:00
|
|
|
static void
|
2018-01-12 22:48:23 +00:00
|
|
|
parsedomainlist(char *list, domainset_t *mask, int *policyp)
|
|
|
|
{
|
|
|
|
domainset_t rootmask;
|
|
|
|
struct numa_policy *policy;
|
|
|
|
char *l;
|
|
|
|
int p;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Use the rootset's policy as the default for unspecified policies.
|
|
|
|
*/
|
|
|
|
if (cpuset_getdomain(CPU_LEVEL_ROOT, CPU_WHICH_PID, -1,
|
|
|
|
sizeof(rootmask), &rootmask, &p) != 0)
|
|
|
|
err(EXIT_FAILURE, "getdomain");
|
|
|
|
|
|
|
|
l = list;
|
|
|
|
for (policy = &policies[0]; policy->name != NULL; policy++) {
|
|
|
|
if (strncasecmp(l, policy->name, strlen(policy->name)) == 0) {
|
|
|
|
p = policy->policy;
|
|
|
|
l += strlen(policy->name);
|
|
|
|
if (*l != ':' && *l != '\0')
|
|
|
|
errx(EXIT_FAILURE, "Malformed list %s", list);
|
|
|
|
if (*l == ':')
|
|
|
|
l++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*policyp = p;
|
|
|
|
if (strcasecmp(l, "all") == 0 || *l == '\0') {
|
|
|
|
DOMAINSET_COPY(&rootmask, mask);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
parselist(l, (struct bitset *)mask, DOMAINSET_SETSIZE);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
printset(struct bitset *mask, int size)
|
2008-03-02 07:51:29 +00:00
|
|
|
{
|
|
|
|
int once;
|
2018-01-12 22:48:23 +00:00
|
|
|
int bit;
|
2008-03-02 07:51:29 +00:00
|
|
|
|
2018-01-12 22:48:23 +00:00
|
|
|
for (once = 0, bit = 0; bit < size; bit++) {
|
|
|
|
if (BIT_ISSET(size, bit, mask)) {
|
2008-03-02 07:51:29 +00:00
|
|
|
if (once == 0) {
|
2018-01-12 22:48:23 +00:00
|
|
|
printf("%d", bit);
|
2008-03-02 07:51:29 +00:00
|
|
|
once = 1;
|
|
|
|
} else
|
2018-01-12 22:48:23 +00:00
|
|
|
printf(", %d", bit);
|
2008-03-02 07:51:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
|
2015-01-08 15:53:13 +00:00
|
|
|
static const char *whichnames[] = { NULL, "tid", "pid", "cpuset", "irq", "jail",
|
|
|
|
"domain" };
|
2011-11-06 08:14:40 +00:00
|
|
|
static const char *levelnames[] = { NULL, " root", " cpuset", "" };
|
2018-01-12 22:48:23 +00:00
|
|
|
static const char *policynames[] = { "invalid", "round-robin", "first-touch",
|
2018-03-29 02:54:50 +00:00
|
|
|
"prefer", "interleave" };
|
2008-03-02 07:51:29 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
printaffinity(void)
|
|
|
|
{
|
2018-01-12 22:48:23 +00:00
|
|
|
domainset_t domain;
|
2008-03-02 07:51:29 +00:00
|
|
|
cpuset_t mask;
|
2018-01-12 22:48:23 +00:00
|
|
|
int policy;
|
2008-03-02 07:51:29 +00:00
|
|
|
|
2008-03-05 01:49:20 +00:00
|
|
|
if (cpuset_getaffinity(level, which, id, sizeof(mask), &mask) != 0)
|
2008-03-02 07:51:29 +00:00
|
|
|
err(EXIT_FAILURE, "getaffinity");
|
|
|
|
printf("%s %jd%s mask: ", whichnames[which], (intmax_t)id,
|
|
|
|
levelnames[level]);
|
2018-01-12 22:48:23 +00:00
|
|
|
printset((struct bitset *)&mask, CPU_SETSIZE);
|
|
|
|
if (dflag)
|
|
|
|
goto out;
|
|
|
|
if (cpuset_getdomain(level, which, id, sizeof(domain), &domain,
|
|
|
|
&policy) != 0)
|
|
|
|
err(EXIT_FAILURE, "getdomain");
|
|
|
|
printf("%s %jd%s domain policy: %s mask: ", whichnames[which],
|
|
|
|
(intmax_t)id, levelnames[level], policynames[policy]);
|
|
|
|
printset((struct bitset *)&domain, DOMAINSET_SETSIZE);
|
|
|
|
out:
|
2008-03-02 07:51:29 +00:00
|
|
|
exit(EXIT_SUCCESS);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
printsetid(void)
|
|
|
|
{
|
|
|
|
cpusetid_t setid;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Only LEVEL_WHICH && WHICH_CPUSET has a numbered id.
|
|
|
|
*/
|
|
|
|
if (level == CPU_LEVEL_WHICH && !sflag)
|
|
|
|
level = CPU_LEVEL_CPUSET;
|
|
|
|
if (cpuset_getid(level, which, id, &setid))
|
|
|
|
err(errno, "getid");
|
|
|
|
printf("%s %jd%s id: %d\n", whichnames[which], (intmax_t)id,
|
|
|
|
levelnames[level], setid);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
main(int argc, char *argv[])
|
|
|
|
{
|
2018-01-12 22:48:23 +00:00
|
|
|
domainset_t domains;
|
2008-03-02 07:51:29 +00:00
|
|
|
cpusetid_t setid;
|
|
|
|
cpuset_t mask;
|
2018-01-12 22:48:23 +00:00
|
|
|
int policy;
|
2008-03-02 07:51:29 +00:00
|
|
|
lwpid_t tid;
|
|
|
|
pid_t pid;
|
|
|
|
int ch;
|
|
|
|
|
|
|
|
CPU_ZERO(&mask);
|
2018-01-12 22:48:23 +00:00
|
|
|
DOMAINSET_ZERO(&domains);
|
|
|
|
policy = DOMAINSET_POLICY_INVALID;
|
2008-03-02 07:51:29 +00:00
|
|
|
level = CPU_LEVEL_WHICH;
|
|
|
|
which = CPU_WHICH_PID;
|
|
|
|
id = pid = tid = setid = -1;
|
2018-01-12 22:48:23 +00:00
|
|
|
while ((ch = getopt(argc, argv, "Ccd:gij:l:n:p:rs:t:x:")) != -1) {
|
2008-03-02 07:51:29 +00:00
|
|
|
switch (ch) {
|
2011-01-14 19:57:28 +00:00
|
|
|
case 'C':
|
|
|
|
Cflag = 1;
|
|
|
|
break;
|
2008-03-02 07:51:29 +00:00
|
|
|
case 'c':
|
|
|
|
cflag = 1;
|
|
|
|
level = CPU_LEVEL_CPUSET;
|
|
|
|
break;
|
2015-01-08 15:53:13 +00:00
|
|
|
case 'd':
|
|
|
|
dflag = 1;
|
|
|
|
which = CPU_WHICH_DOMAIN;
|
|
|
|
id = atoi(optarg);
|
|
|
|
break;
|
2008-03-02 07:51:29 +00:00
|
|
|
case 'g':
|
|
|
|
gflag = 1;
|
|
|
|
break;
|
|
|
|
case 'i':
|
|
|
|
iflag = 1;
|
|
|
|
break;
|
MFp4:
Bring in updated jail support from bz_jail branch.
This enhances the current jail implementation to permit multiple
addresses per jail. In addtion to IPv4, IPv6 is supported as well.
Due to updated checks it is even possible to have jails without
an IP address at all, which basically gives one a chroot with
restricted process view, no networking,..
SCTP support was updated and supports IPv6 in jails as well.
Cpuset support permits jails to be bound to specific processor
sets after creation.
Jails can have an unrestricted (no duplicate protection, etc.) name
in addition to the hostname. The jail name cannot be changed from
within a jail and is considered to be used for management purposes
or as audit-token in the future.
DDB 'show jails' command was added to aid debugging.
Proper compat support permits 32bit jail binaries to be used on 64bit
systems to manage jails. Also backward compatibility was preserved where
possible: for jail v1 syscalls, as well as with user space management
utilities.
Both jail as well as prison version were updated for the new features.
A gap was intentionally left as the intermediate versions had been
used by various patches floating around the last years.
Bump __FreeBSD_version for the afore mentioned and in kernel changes.
Special thanks to:
- Pawel Jakub Dawidek (pjd) for his multi-IPv4 patches
and Olivier Houchard (cognet) for initial single-IPv6 patches.
- Jeff Roberson (jeff) and Randall Stewart (rrs) for their
help, ideas and review on cpuset and SCTP support.
- Robert Watson (rwatson) for lots and lots of help, discussions,
suggestions and review of most of the patch at various stages.
- John Baldwin (jhb) for his help.
- Simon L. Nielsen (simon) as early adopter testing changes
on cluster machines as well as all the testers and people
who provided feedback the last months on freebsd-jail and
other channels.
- My employer, CK Software GmbH, for the support so I could work on this.
Reviewed by: (see above)
MFC after: 3 months (this is just so that I get the mail)
X-MFC Before: 7.2-RELEASE if possible
2008-11-29 14:32:14 +00:00
|
|
|
case 'j':
|
|
|
|
jflag = 1;
|
|
|
|
which = CPU_WHICH_JAIL;
|
|
|
|
id = atoi(optarg);
|
|
|
|
break;
|
2008-03-02 07:51:29 +00:00
|
|
|
case 'l':
|
|
|
|
lflag = 1;
|
2018-01-12 22:48:23 +00:00
|
|
|
parsecpulist(optarg, &mask);
|
|
|
|
break;
|
|
|
|
case 'n':
|
|
|
|
nflag = 1;
|
|
|
|
parsedomainlist(optarg, &domains, &policy);
|
2008-03-02 07:51:29 +00:00
|
|
|
break;
|
|
|
|
case 'p':
|
|
|
|
pflag = 1;
|
|
|
|
which = CPU_WHICH_PID;
|
|
|
|
id = pid = atoi(optarg);
|
|
|
|
break;
|
|
|
|
case 'r':
|
|
|
|
level = CPU_LEVEL_ROOT;
|
|
|
|
rflag = 1;
|
|
|
|
break;
|
|
|
|
case 's':
|
|
|
|
sflag = 1;
|
|
|
|
which = CPU_WHICH_CPUSET;
|
|
|
|
id = setid = atoi(optarg);
|
|
|
|
break;
|
|
|
|
case 't':
|
|
|
|
tflag = 1;
|
|
|
|
which = CPU_WHICH_TID;
|
|
|
|
id = tid = atoi(optarg);
|
|
|
|
break;
|
2008-04-11 03:27:42 +00:00
|
|
|
case 'x':
|
|
|
|
xflag = 1;
|
|
|
|
which = CPU_WHICH_IRQ;
|
|
|
|
id = atoi(optarg);
|
|
|
|
break;
|
2008-03-02 07:51:29 +00:00
|
|
|
default:
|
|
|
|
usage();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
argc -= optind;
|
|
|
|
argv += optind;
|
|
|
|
if (gflag) {
|
2018-01-12 22:48:23 +00:00
|
|
|
if (argc || Cflag || lflag || nflag)
|
2008-03-02 07:51:29 +00:00
|
|
|
usage();
|
|
|
|
/* Only one identity specifier. */
|
2015-01-08 15:53:13 +00:00
|
|
|
if (dflag + jflag + xflag + sflag + pflag + tflag > 1)
|
2008-03-02 07:51:29 +00:00
|
|
|
usage();
|
|
|
|
if (iflag)
|
|
|
|
printsetid();
|
|
|
|
else
|
|
|
|
printaffinity();
|
|
|
|
exit(EXIT_SUCCESS);
|
|
|
|
}
|
2018-01-12 22:48:23 +00:00
|
|
|
|
2015-01-08 15:53:13 +00:00
|
|
|
if (dflag || iflag || rflag)
|
2008-03-05 02:10:43 +00:00
|
|
|
usage();
|
2008-03-02 07:51:29 +00:00
|
|
|
/*
|
|
|
|
* The user wants to run a command with a set and possibly cpumask.
|
|
|
|
*/
|
|
|
|
if (argc) {
|
2015-01-08 15:53:13 +00:00
|
|
|
if (Cflag || pflag || tflag || xflag || jflag)
|
2008-03-02 07:51:29 +00:00
|
|
|
usage();
|
|
|
|
if (sflag) {
|
|
|
|
if (cpuset_setid(CPU_WHICH_PID, -1, setid))
|
|
|
|
err(argc, "setid");
|
2008-03-05 02:10:43 +00:00
|
|
|
} else {
|
2008-03-02 07:51:29 +00:00
|
|
|
if (cpuset(&setid))
|
|
|
|
err(argc, "newid");
|
|
|
|
}
|
|
|
|
if (lflag) {
|
2008-03-12 23:54:40 +00:00
|
|
|
if (cpuset_setaffinity(level, CPU_WHICH_PID,
|
2008-03-05 02:10:43 +00:00
|
|
|
-1, sizeof(mask), &mask) != 0)
|
2008-03-02 07:51:29 +00:00
|
|
|
err(EXIT_FAILURE, "setaffinity");
|
|
|
|
}
|
2018-01-12 22:48:23 +00:00
|
|
|
if (nflag) {
|
|
|
|
if (cpuset_setdomain(level, CPU_WHICH_PID,
|
|
|
|
-1, sizeof(domains), &domains, policy) != 0)
|
|
|
|
err(EXIT_FAILURE, "setdomain");
|
|
|
|
}
|
2008-03-02 07:51:29 +00:00
|
|
|
errno = 0;
|
|
|
|
execvp(*argv, argv);
|
|
|
|
err(errno == ENOENT ? 127 : 126, "%s", *argv);
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* We're modifying something that presently exists.
|
|
|
|
*/
|
2015-01-08 15:53:13 +00:00
|
|
|
if (Cflag && (jflag || !pflag || sflag || tflag || xflag))
|
2011-01-14 19:57:28 +00:00
|
|
|
usage();
|
2018-01-12 22:48:23 +00:00
|
|
|
if ((!lflag && !nflag) && cflag)
|
2008-03-02 07:51:29 +00:00
|
|
|
usage();
|
2018-01-12 22:48:23 +00:00
|
|
|
if ((!lflag && !nflag) && !(Cflag || sflag))
|
2008-03-02 07:51:29 +00:00
|
|
|
usage();
|
|
|
|
/* You can only set a mask on a thread. */
|
MFp4:
Bring in updated jail support from bz_jail branch.
This enhances the current jail implementation to permit multiple
addresses per jail. In addtion to IPv4, IPv6 is supported as well.
Due to updated checks it is even possible to have jails without
an IP address at all, which basically gives one a chroot with
restricted process view, no networking,..
SCTP support was updated and supports IPv6 in jails as well.
Cpuset support permits jails to be bound to specific processor
sets after creation.
Jails can have an unrestricted (no duplicate protection, etc.) name
in addition to the hostname. The jail name cannot be changed from
within a jail and is considered to be used for management purposes
or as audit-token in the future.
DDB 'show jails' command was added to aid debugging.
Proper compat support permits 32bit jail binaries to be used on 64bit
systems to manage jails. Also backward compatibility was preserved where
possible: for jail v1 syscalls, as well as with user space management
utilities.
Both jail as well as prison version were updated for the new features.
A gap was intentionally left as the intermediate versions had been
used by various patches floating around the last years.
Bump __FreeBSD_version for the afore mentioned and in kernel changes.
Special thanks to:
- Pawel Jakub Dawidek (pjd) for his multi-IPv4 patches
and Olivier Houchard (cognet) for initial single-IPv6 patches.
- Jeff Roberson (jeff) and Randall Stewart (rrs) for their
help, ideas and review on cpuset and SCTP support.
- Robert Watson (rwatson) for lots and lots of help, discussions,
suggestions and review of most of the patch at various stages.
- John Baldwin (jhb) for his help.
- Simon L. Nielsen (simon) as early adopter testing changes
on cluster machines as well as all the testers and people
who provided feedback the last months on freebsd-jail and
other channels.
- My employer, CK Software GmbH, for the support so I could work on this.
Reviewed by: (see above)
MFC after: 3 months (this is just so that I get the mail)
X-MFC Before: 7.2-RELEASE if possible
2008-11-29 14:32:14 +00:00
|
|
|
if (tflag && (sflag | pflag | xflag | jflag))
|
2008-04-11 03:27:42 +00:00
|
|
|
usage();
|
|
|
|
/* You can only set a mask on an irq. */
|
MFp4:
Bring in updated jail support from bz_jail branch.
This enhances the current jail implementation to permit multiple
addresses per jail. In addtion to IPv4, IPv6 is supported as well.
Due to updated checks it is even possible to have jails without
an IP address at all, which basically gives one a chroot with
restricted process view, no networking,..
SCTP support was updated and supports IPv6 in jails as well.
Cpuset support permits jails to be bound to specific processor
sets after creation.
Jails can have an unrestricted (no duplicate protection, etc.) name
in addition to the hostname. The jail name cannot be changed from
within a jail and is considered to be used for management purposes
or as audit-token in the future.
DDB 'show jails' command was added to aid debugging.
Proper compat support permits 32bit jail binaries to be used on 64bit
systems to manage jails. Also backward compatibility was preserved where
possible: for jail v1 syscalls, as well as with user space management
utilities.
Both jail as well as prison version were updated for the new features.
A gap was intentionally left as the intermediate versions had been
used by various patches floating around the last years.
Bump __FreeBSD_version for the afore mentioned and in kernel changes.
Special thanks to:
- Pawel Jakub Dawidek (pjd) for his multi-IPv4 patches
and Olivier Houchard (cognet) for initial single-IPv6 patches.
- Jeff Roberson (jeff) and Randall Stewart (rrs) for their
help, ideas and review on cpuset and SCTP support.
- Robert Watson (rwatson) for lots and lots of help, discussions,
suggestions and review of most of the patch at various stages.
- John Baldwin (jhb) for his help.
- Simon L. Nielsen (simon) as early adopter testing changes
on cluster machines as well as all the testers and people
who provided feedback the last months on freebsd-jail and
other channels.
- My employer, CK Software GmbH, for the support so I could work on this.
Reviewed by: (see above)
MFC after: 3 months (this is just so that I get the mail)
X-MFC Before: 7.2-RELEASE if possible
2008-11-29 14:32:14 +00:00
|
|
|
if (xflag && (jflag | pflag | sflag | tflag))
|
2008-03-02 07:51:29 +00:00
|
|
|
usage();
|
2011-01-14 19:57:28 +00:00
|
|
|
if (Cflag) {
|
|
|
|
/*
|
|
|
|
* Create a new cpuset and move the specified process
|
|
|
|
* into the set.
|
|
|
|
*/
|
|
|
|
if (cpuset(&setid) < 0)
|
|
|
|
err(EXIT_FAILURE, "newid");
|
|
|
|
sflag = 1;
|
|
|
|
}
|
2008-03-02 07:51:29 +00:00
|
|
|
if (pflag && sflag) {
|
|
|
|
if (cpuset_setid(CPU_WHICH_PID, pid, setid))
|
|
|
|
err(EXIT_FAILURE, "setid");
|
|
|
|
/*
|
|
|
|
* If the user specifies a set and a list we want the mask
|
|
|
|
* to effect the pid and not the set.
|
|
|
|
*/
|
|
|
|
which = CPU_WHICH_PID;
|
|
|
|
id = pid;
|
|
|
|
}
|
|
|
|
if (lflag) {
|
2008-03-05 01:49:20 +00:00
|
|
|
if (cpuset_setaffinity(level, which, id, sizeof(mask),
|
2008-03-02 07:51:29 +00:00
|
|
|
&mask) != 0)
|
|
|
|
err(EXIT_FAILURE, "setaffinity");
|
|
|
|
}
|
2018-01-12 22:48:23 +00:00
|
|
|
if (nflag) {
|
|
|
|
if (cpuset_setdomain(level, which, id, sizeof(domains),
|
|
|
|
&domains, policy) != 0)
|
|
|
|
err(EXIT_FAILURE, "setdomain");
|
|
|
|
}
|
2008-03-02 07:51:29 +00:00
|
|
|
|
|
|
|
exit(EXIT_SUCCESS);
|
|
|
|
}
|
|
|
|
|
2011-11-06 08:14:40 +00:00
|
|
|
static void
|
2008-03-02 07:51:29 +00:00
|
|
|
usage(void)
|
|
|
|
{
|
|
|
|
|
|
|
|
fprintf(stderr,
|
2008-03-05 02:10:43 +00:00
|
|
|
"usage: cpuset [-l cpu-list] [-s setid] cmd ...\n");
|
2008-03-02 07:51:29 +00:00
|
|
|
fprintf(stderr,
|
2008-03-05 01:49:20 +00:00
|
|
|
" cpuset [-l cpu-list] [-s setid] -p pid\n");
|
2011-01-14 19:57:28 +00:00
|
|
|
fprintf(stderr,
|
|
|
|
" cpuset [-c] [-l cpu-list] -C -p pid\n");
|
2008-03-02 07:51:29 +00:00
|
|
|
fprintf(stderr,
|
2015-01-08 15:53:13 +00:00
|
|
|
" cpuset [-c] [-l cpu-list] [-j jailid | -p pid | -t tid | -s setid | -x irq]\n");
|
2008-03-02 07:51:29 +00:00
|
|
|
fprintf(stderr,
|
2015-01-08 15:53:13 +00:00
|
|
|
" cpuset -g [-cir] [-d domain | -j jailid | -p pid | -t tid | -s setid |\n"
|
|
|
|
" -x irq]\n");
|
2008-03-02 07:51:29 +00:00
|
|
|
exit(1);
|
|
|
|
}
|