1*0209230bSgjelinek /*
2*0209230bSgjelinek * CDDL HEADER START
3*0209230bSgjelinek *
4*0209230bSgjelinek * The contents of this file are subject to the terms of the
5*0209230bSgjelinek * Common Development and Distribution License (the "License").
6*0209230bSgjelinek * You may not use this file except in compliance with the License.
7*0209230bSgjelinek *
8*0209230bSgjelinek * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9*0209230bSgjelinek * or http://www.opensolaris.org/os/licensing.
10*0209230bSgjelinek * See the License for the specific language governing permissions
11*0209230bSgjelinek * and limitations under the License.
12*0209230bSgjelinek *
13*0209230bSgjelinek * When distributing Covered Code, include this CDDL HEADER in each
14*0209230bSgjelinek * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15*0209230bSgjelinek * If applicable, add the following below this CDDL HEADER, with the
16*0209230bSgjelinek * fields enclosed by brackets "[]" replaced with your own identifying
17*0209230bSgjelinek * information: Portions Copyright [yyyy] [name of copyright owner]
18*0209230bSgjelinek *
19*0209230bSgjelinek * CDDL HEADER END
20*0209230bSgjelinek */
21*0209230bSgjelinek /*
22*0209230bSgjelinek * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
23*0209230bSgjelinek * Use is subject to license terms.
24*0209230bSgjelinek */
25*0209230bSgjelinek
26*0209230bSgjelinek #pragma ident "%Z%%M% %I% %E% SMI"
27*0209230bSgjelinek
28*0209230bSgjelinek #include <procfs.h>
29*0209230bSgjelinek #include <project.h>
30*0209230bSgjelinek #include <stdlib.h>
31*0209230bSgjelinek #include <strings.h>
32*0209230bSgjelinek #include <zone.h>
33*0209230bSgjelinek #include <libzonecfg.h>
34*0209230bSgjelinek #include "rcapd.h"
35*0209230bSgjelinek #include "utils.h"
36*0209230bSgjelinek
37*0209230bSgjelinek extern boolean_t gz_capped;
38*0209230bSgjelinek
39*0209230bSgjelinek /* round up to next y = 2^n */
40*0209230bSgjelinek #define ROUNDUP(x, y) (((x) + ((y) - 1)) & ~((y) - 1))
41*0209230bSgjelinek
42*0209230bSgjelinek static void
update_zone(zone_entry_t * zent,void * walk_data)43*0209230bSgjelinek update_zone(zone_entry_t *zent, void *walk_data)
44*0209230bSgjelinek {
45*0209230bSgjelinek void(*update_notification_cb)(char *, char *, int, uint64_t, int) =
46*0209230bSgjelinek (void(*)(char *, char *, int, uint64_t, int))walk_data;
47*0209230bSgjelinek int changes;
48*0209230bSgjelinek int64_t max_rss;
49*0209230bSgjelinek uint64_t mcap;
50*0209230bSgjelinek lcollection_t *lcol;
51*0209230bSgjelinek rcid_t colid;
52*0209230bSgjelinek
53*0209230bSgjelinek if (zone_getattr(zent->zid, ZONE_ATTR_PHYS_MCAP, &mcap,
54*0209230bSgjelinek sizeof (mcap)) != -1 && mcap != 0)
55*0209230bSgjelinek max_rss = ROUNDUP(mcap, 1024) / 1024;
56*0209230bSgjelinek else
57*0209230bSgjelinek max_rss = 0;
58*0209230bSgjelinek
59*0209230bSgjelinek if (zent->zid == GLOBAL_ZONEID) {
60*0209230bSgjelinek if (max_rss > 0)
61*0209230bSgjelinek gz_capped = B_TRUE;
62*0209230bSgjelinek else
63*0209230bSgjelinek gz_capped = B_FALSE;
64*0209230bSgjelinek }
65*0209230bSgjelinek
66*0209230bSgjelinek
67*0209230bSgjelinek colid.rcid_type = RCIDT_ZONE;
68*0209230bSgjelinek colid.rcid_val = zent->zid;
69*0209230bSgjelinek
70*0209230bSgjelinek lcol = lcollection_insert_update(&colid, max_rss, zent->zname,
71*0209230bSgjelinek &changes);
72*0209230bSgjelinek if (update_notification_cb != NULL)
73*0209230bSgjelinek update_notification_cb("zone", zent->zname, changes, max_rss,
74*0209230bSgjelinek (lcol != NULL) ? lcol->lcol_mark : 0);
75*0209230bSgjelinek }
76*0209230bSgjelinek
77*0209230bSgjelinek
78*0209230bSgjelinek /* ARGSUSED */
79*0209230bSgjelinek void
lcollection_update_zone(lcollection_update_type_t ut,void (* update_notification_cb)(char *,char *,int,uint64_t,int))80*0209230bSgjelinek lcollection_update_zone(lcollection_update_type_t ut,
81*0209230bSgjelinek void(*update_notification_cb)(char *, char *, int, uint64_t, int))
82*0209230bSgjelinek {
83*0209230bSgjelinek int i;
84*0209230bSgjelinek uint_t nzents;
85*0209230bSgjelinek zone_entry_t *zents;
86*0209230bSgjelinek
87*0209230bSgjelinek /*
88*0209230bSgjelinek * Enumerate running zones.
89*0209230bSgjelinek */
90*0209230bSgjelinek if (get_running_zones(&nzents, &zents) != 0)
91*0209230bSgjelinek return;
92*0209230bSgjelinek
93*0209230bSgjelinek for (i = 0; i < nzents; i++) {
94*0209230bSgjelinek update_zone(&zents[i], (void *)update_notification_cb);
95*0209230bSgjelinek
96*0209230bSgjelinek }
97*0209230bSgjelinek
98*0209230bSgjelinek free(zents);
99*0209230bSgjelinek }
100