diff options
| author | gjelinek <none@none> | 2006-12-14 13:35:17 -0800 |
|---|---|---|
| committer | gjelinek <none@none> | 2006-12-14 13:35:17 -0800 |
| commit | 0209230bf1261579beab4f55226bb509e6b850cb (patch) | |
| tree | c605b4105191d5a10962c524ad08019742cd52cb /usr/src/cmd/rcap/common/utils.c | |
| parent | 780774645a5b1b0176916fc66312dc1d9b4d14b4 (diff) | |
| download | illumos-joyent-0209230bf1261579beab4f55226bb509e6b850cb.tar.gz | |
PSARC 2006/496 Improved Zones/RM Integration
PSARC 2006/598 Swap resource control; locked memory RM improvements
PSARC 2006/660 rcapadm zone option
4754856 *prstat* prstat -atJTZ should count shared segments only once
4970603 RFE: should be able to persistently specify global zone's cpu shares
5026227 RFE: ability to rcap zones from global zone
5103071 RFE: local zones can run the global zone out of swap
6222025 RFE: simplify rctl syntax and improve cpu-shares/FSS interaction
6420985 rcapstat is broken on amd64
6421202 RFE: simplify and improve zones/pool integration
6442252 zonecfg's "unset" syntax is not documented and confusing
6490516 schedctl pages should not reserve swap
6490938 setproject can bind to the wrong pool
6498635 zone attach failure leaves zone in installed state
6500877 tmpfs syslogs incorrect path when non-global zone tmpfs mounts become full
Diffstat (limited to 'usr/src/cmd/rcap/common/utils.c')
| -rw-r--r-- | usr/src/cmd/rcap/common/utils.c | 81 |
1 files changed, 77 insertions, 4 deletions
diff --git a/usr/src/cmd/rcap/common/utils.c b/usr/src/cmd/rcap/common/utils.c index f9757a12f6..c01f568915 100644 --- a/usr/src/cmd/rcap/common/utils.c +++ b/usr/src/cmd/rcap/common/utils.c @@ -2,9 +2,8 @@ * CDDL HEADER START * * The contents of this file are subject to the terms of the - * Common Development and Distribution License, Version 1.0 only - * (the "License"). You may not use this file except in compliance - * with the License. + * 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. @@ -20,7 +19,7 @@ * CDDL HEADER END */ /* - * Copyright 2003 Sun Microsystems, Inc. All rights reserved. + * Copyright 2006 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -260,3 +259,77 @@ xatoi(char *p) return (i); } } + +/* + * get_running_zones() calls zone_list(2) to find out how many zones are + * running. It then calls zone_list(2) again to fetch the list of running + * zones (stored in *zents). + */ +int +get_running_zones(uint_t *nzents, zone_entry_t **zents) +{ + zoneid_t *zids; + uint_t nzents_saved; + int i; + zone_entry_t *zentp; + zone_state_t zstate; + + *zents = NULL; + if (zone_list(NULL, nzents) != 0) { + warn(gettext("could not get zoneid list\n")); + return (E_ERROR); + } + +again: + if (*nzents == 0) + return (E_SUCCESS); + + if ((zids = (zoneid_t *)calloc(*nzents, sizeof (zoneid_t))) == NULL) { + warn(gettext("out of memory: zones will not be capped\n")); + return (E_ERROR); + } + + nzents_saved = *nzents; + + if (zone_list(zids, nzents) != 0) { + warn(gettext("could not get zone list\n")); + free(zids); + return (E_ERROR); + } + if (*nzents != nzents_saved) { + /* list changed, try again */ + free(zids); + goto again; + } + + *zents = calloc(*nzents, sizeof (zone_entry_t)); + if (*zents == NULL) { + warn(gettext("out of memory: zones will not be capped\n")); + free(zids); + return (E_ERROR); + } + + zentp = *zents; + for (i = 0; i < *nzents; i++) { + char name[ZONENAME_MAX]; + + if (getzonenamebyid(zids[i], name, sizeof (name)) < 0) { + warn(gettext("could not get name for " + "zoneid %d\n"), zids[i]); + continue; + } + + (void) strlcpy(zentp->zname, name, sizeof (zentp->zname)); + zentp->zid = zids[i]; + if (zone_get_state(name, &zstate) != Z_OK || + zstate != ZONE_STATE_RUNNING) + continue; + + + zentp++; + } + *nzents = zentp - *zents; + + free(zids); + return (E_SUCCESS); +} |
