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