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 #include <procfs.h>
27*0209230bSgjelinek #include <project.h>
28*0209230bSgjelinek #include <stdlib.h>
29*0209230bSgjelinek #include <strings.h>
30*0209230bSgjelinek #include <zone.h>
31*0209230bSgjelinek #include <libzonecfg.h>
32*0209230bSgjelinek #include "rcapd.h"
33*0209230bSgjelinek #include "utils.h"
34*0209230bSgjelinek
35*0209230bSgjelinek extern boolean_t gz_capped;
36*0209230bSgjelinek
37*0209230bSgjelinek /* round up to next y = 2^n */
38*0209230bSgjelinek #define ROUNDUP(x, y) (((x) + ((y) - 1)) & ~((y) - 1))
39*0209230bSgjelinek
40*0209230bSgjelinek static void
update_zone(zone_entry_t * zent,void * walk_data)41*0209230bSgjelinek update_zone(zone_entry_t *zent, void *walk_data)
42*0209230bSgjelinek {
43*0209230bSgjelinek void(*update_notification_cb)(char *, char *, int, uint64_t, int) =
44*0209230bSgjelinek (void(*)(char *, char *, int, uint64_t, int))walk_data;
45*0209230bSgjelinek int changes;
46*0209230bSgjelinek int64_t max_rss;
47*0209230bSgjelinek uint64_t mcap;
48*0209230bSgjelinek lcollection_t *lcol;
49*0209230bSgjelinek rcid_t colid;
50*0209230bSgjelinek
51*0209230bSgjelinek if (zone_getattr(zent->zid, ZONE_ATTR_PHYS_MCAP, &mcap,
52*0209230bSgjelinek sizeof (mcap)) != -1 && mcap != 0)
53*0209230bSgjelinek max_rss = ROUNDUP(mcap, 1024) / 1024;
54*0209230bSgjelinek else
55*0209230bSgjelinek max_rss = 0;
56*0209230bSgjelinek
57*0209230bSgjelinek if (zent->zid == GLOBAL_ZONEID) {
58*0209230bSgjelinek if (max_rss > 0)
59*0209230bSgjelinek gz_capped = B_TRUE;
60*0209230bSgjelinek else
61*0209230bSgjelinek gz_capped = B_FALSE;
62*0209230bSgjelinek }
63*0209230bSgjelinek
64*0209230bSgjelinek
65*0209230bSgjelinek colid.rcid_type = RCIDT_ZONE;
66*0209230bSgjelinek colid.rcid_val = zent->zid;
67*0209230bSgjelinek
68*0209230bSgjelinek lcol = lcollection_insert_update(&colid, max_rss, zent->zname,
69*0209230bSgjelinek &changes);
70*0209230bSgjelinek if (update_notification_cb != NULL)
71*0209230bSgjelinek update_notification_cb("zone", zent->zname, changes, max_rss,
72*0209230bSgjelinek (lcol != NULL) ? lcol->lcol_mark : 0);
73*0209230bSgjelinek }
74*0209230bSgjelinek
75*0209230bSgjelinek
76*0209230bSgjelinek /* ARGSUSED */
77*0209230bSgjelinek void
lcollection_update_zone(lcollection_update_type_t ut,void (* update_notification_cb)(char *,char *,int,uint64_t,int))78*0209230bSgjelinek lcollection_update_zone(lcollection_update_type_t ut,
79*0209230bSgjelinek void(*update_notification_cb)(char *, char *, int, uint64_t, int))
80*0209230bSgjelinek {
81*0209230bSgjelinek int i;
82*0209230bSgjelinek uint_t nzents;
83*0209230bSgjelinek zone_entry_t *zents;
84*0209230bSgjelinek
85*0209230bSgjelinek /*
86*0209230bSgjelinek * Enumerate running zones.
87*0209230bSgjelinek */
88*0209230bSgjelinek if (get_running_zones(&nzents, &zents) != 0)
89*0209230bSgjelinek return;
90*0209230bSgjelinek
91*0209230bSgjelinek for (i = 0; i < nzents; i++) {
92*0209230bSgjelinek update_zone(&zents[i], (void *)update_notification_cb);
93*0209230bSgjelinek
94*0209230bSgjelinek }
95*0209230bSgjelinek
96*0209230bSgjelinek free(zents);
97*0209230bSgjelinek }
98