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