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