xref: /illumos-gate/usr/src/cmd/stat/common/walkers.c (revision 7c478bd9)
1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate  * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate  *
4*7c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate  * with the License.
8*7c478bd9Sstevel@tonic-gate  *
9*7c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate  * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate  *
14*7c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate  *
20*7c478bd9Sstevel@tonic-gate  * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate  */
22*7c478bd9Sstevel@tonic-gate /*
23*7c478bd9Sstevel@tonic-gate  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
24*7c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
25*7c478bd9Sstevel@tonic-gate  */
26*7c478bd9Sstevel@tonic-gate 
27*7c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
28*7c478bd9Sstevel@tonic-gate 
29*7c478bd9Sstevel@tonic-gate #include "statcommon.h"
30*7c478bd9Sstevel@tonic-gate 
31*7c478bd9Sstevel@tonic-gate #include <string.h>
32*7c478bd9Sstevel@tonic-gate #include <errno.h>
33*7c478bd9Sstevel@tonic-gate 
34*7c478bd9Sstevel@tonic-gate /* max size of report change annotations */
35*7c478bd9Sstevel@tonic-gate #define	LIST_SIZE 512
36*7c478bd9Sstevel@tonic-gate 
37*7c478bd9Sstevel@tonic-gate static char cpus_added[LIST_SIZE];
38*7c478bd9Sstevel@tonic-gate static char cpus_removed[LIST_SIZE];
39*7c478bd9Sstevel@tonic-gate 
40*7c478bd9Sstevel@tonic-gate static int
41*7c478bd9Sstevel@tonic-gate cpu_walk(struct snapshot *old, struct snapshot *new,
42*7c478bd9Sstevel@tonic-gate     snapshot_cb cb, void *data)
43*7c478bd9Sstevel@tonic-gate {
44*7c478bd9Sstevel@tonic-gate 	int changed = 0;
45*7c478bd9Sstevel@tonic-gate 	int i;
46*7c478bd9Sstevel@tonic-gate 
47*7c478bd9Sstevel@tonic-gate 	/* CPUs can change state but not re-order */
48*7c478bd9Sstevel@tonic-gate 	for (i = 0; i < new->s_nr_cpus; i++) {
49*7c478bd9Sstevel@tonic-gate 		struct cpu_snapshot *cpu = NULL;
50*7c478bd9Sstevel@tonic-gate 		struct cpu_snapshot *newcpu = &new->s_cpus[i];
51*7c478bd9Sstevel@tonic-gate 		if (old)
52*7c478bd9Sstevel@tonic-gate 			cpu = &old->s_cpus[i];
53*7c478bd9Sstevel@tonic-gate 		cb(cpu, newcpu, data);
54*7c478bd9Sstevel@tonic-gate 		if (cpu == NULL)
55*7c478bd9Sstevel@tonic-gate 			changed = 1;
56*7c478bd9Sstevel@tonic-gate 		else {
57*7c478bd9Sstevel@tonic-gate 			/*
58*7c478bd9Sstevel@tonic-gate 			 * We only care about off/on line transitions
59*7c478bd9Sstevel@tonic-gate 			 */
60*7c478bd9Sstevel@tonic-gate 			if ((CPU_ACTIVE(cpu) && !CPU_ACTIVE(newcpu)) ||
61*7c478bd9Sstevel@tonic-gate 			    (!CPU_ACTIVE(cpu) && CPU_ACTIVE(newcpu)))
62*7c478bd9Sstevel@tonic-gate 				changed = 1;
63*7c478bd9Sstevel@tonic-gate 			if ((new->s_types & SNAP_PSETS) &&
64*7c478bd9Sstevel@tonic-gate 				cpu->cs_pset_id != newcpu->cs_pset_id)
65*7c478bd9Sstevel@tonic-gate 				changed = 1;
66*7c478bd9Sstevel@tonic-gate 		}
67*7c478bd9Sstevel@tonic-gate 
68*7c478bd9Sstevel@tonic-gate 	}
69*7c478bd9Sstevel@tonic-gate 
70*7c478bd9Sstevel@tonic-gate 	return (changed);
71*7c478bd9Sstevel@tonic-gate }
72*7c478bd9Sstevel@tonic-gate 
73*7c478bd9Sstevel@tonic-gate static int
74*7c478bd9Sstevel@tonic-gate pset_walk(struct snapshot *old, struct snapshot *new,
75*7c478bd9Sstevel@tonic-gate     snapshot_cb cb, void *data)
76*7c478bd9Sstevel@tonic-gate {
77*7c478bd9Sstevel@tonic-gate 	int i = 0;
78*7c478bd9Sstevel@tonic-gate 	int j = 0;
79*7c478bd9Sstevel@tonic-gate 	int changed = 0;
80*7c478bd9Sstevel@tonic-gate 
81*7c478bd9Sstevel@tonic-gate 	while (old && i < old->s_nr_psets && j < new->s_nr_psets) {
82*7c478bd9Sstevel@tonic-gate 		if (old->s_psets[i].ps_id < new->s_psets[j].ps_id) {
83*7c478bd9Sstevel@tonic-gate 			cb(&old->s_psets[i], NULL, data);
84*7c478bd9Sstevel@tonic-gate 			i++;
85*7c478bd9Sstevel@tonic-gate 			changed = 1;
86*7c478bd9Sstevel@tonic-gate 		} else if (old->s_psets[i].ps_id > new->s_psets[j].ps_id) {
87*7c478bd9Sstevel@tonic-gate 			cb(NULL, &new->s_psets[j], data);
88*7c478bd9Sstevel@tonic-gate 			j++;
89*7c478bd9Sstevel@tonic-gate 			changed = 1;
90*7c478bd9Sstevel@tonic-gate 		} else {
91*7c478bd9Sstevel@tonic-gate 			cb(&old->s_psets[i], &new->s_psets[j], data);
92*7c478bd9Sstevel@tonic-gate 			i++;
93*7c478bd9Sstevel@tonic-gate 			j++;
94*7c478bd9Sstevel@tonic-gate 		}
95*7c478bd9Sstevel@tonic-gate 	}
96*7c478bd9Sstevel@tonic-gate 
97*7c478bd9Sstevel@tonic-gate 	while (old && i < old->s_nr_psets) {
98*7c478bd9Sstevel@tonic-gate 		cb(&old->s_psets[i], NULL, data);
99*7c478bd9Sstevel@tonic-gate 		i++;
100*7c478bd9Sstevel@tonic-gate 		changed = 1;
101*7c478bd9Sstevel@tonic-gate 	}
102*7c478bd9Sstevel@tonic-gate 
103*7c478bd9Sstevel@tonic-gate 	while (j < new->s_nr_psets) {
104*7c478bd9Sstevel@tonic-gate 		cb(NULL, &new->s_psets[j], data);
105*7c478bd9Sstevel@tonic-gate 		j++;
106*7c478bd9Sstevel@tonic-gate 		changed = 1;
107*7c478bd9Sstevel@tonic-gate 	}
108*7c478bd9Sstevel@tonic-gate 
109*7c478bd9Sstevel@tonic-gate 	return (changed);
110*7c478bd9Sstevel@tonic-gate }
111*7c478bd9Sstevel@tonic-gate 
112*7c478bd9Sstevel@tonic-gate static int
113*7c478bd9Sstevel@tonic-gate iodev_walk(struct iodev_snapshot *d1, struct iodev_snapshot *d2,
114*7c478bd9Sstevel@tonic-gate     snapshot_cb cb, void *data)
115*7c478bd9Sstevel@tonic-gate {
116*7c478bd9Sstevel@tonic-gate 	int changed = 0;
117*7c478bd9Sstevel@tonic-gate 
118*7c478bd9Sstevel@tonic-gate 	while (d1 && d2) {
119*7c478bd9Sstevel@tonic-gate 		if (strcmp(d1->is_name, d2->is_name) < 0) {
120*7c478bd9Sstevel@tonic-gate 			changed = 1;
121*7c478bd9Sstevel@tonic-gate 			cb(d1, NULL, data);
122*7c478bd9Sstevel@tonic-gate 			(void) iodev_walk(d1->is_children, NULL, cb, data);
123*7c478bd9Sstevel@tonic-gate 			d1 = d1->is_next;
124*7c478bd9Sstevel@tonic-gate 		} else if (strcmp(d1->is_name, d2->is_name) > 0) {
125*7c478bd9Sstevel@tonic-gate 			changed = 1;
126*7c478bd9Sstevel@tonic-gate 			cb(NULL, d2, data);
127*7c478bd9Sstevel@tonic-gate 			(void) iodev_walk(NULL, d2->is_children, cb, data);
128*7c478bd9Sstevel@tonic-gate 			d2 = d2->is_next;
129*7c478bd9Sstevel@tonic-gate 		} else {
130*7c478bd9Sstevel@tonic-gate 			cb(d1, d2, data);
131*7c478bd9Sstevel@tonic-gate 			changed |= iodev_walk(d1->is_children,
132*7c478bd9Sstevel@tonic-gate 					d2->is_children, cb, data);
133*7c478bd9Sstevel@tonic-gate 			d1 = d1->is_next;
134*7c478bd9Sstevel@tonic-gate 			d2 = d2->is_next;
135*7c478bd9Sstevel@tonic-gate 		}
136*7c478bd9Sstevel@tonic-gate 	}
137*7c478bd9Sstevel@tonic-gate 
138*7c478bd9Sstevel@tonic-gate 	while (d1) {
139*7c478bd9Sstevel@tonic-gate 		changed = 1;
140*7c478bd9Sstevel@tonic-gate 		cb(d1, NULL, data);
141*7c478bd9Sstevel@tonic-gate 		(void) iodev_walk(d1->is_children, NULL, cb, data);
142*7c478bd9Sstevel@tonic-gate 		d1 = d1->is_next;
143*7c478bd9Sstevel@tonic-gate 	}
144*7c478bd9Sstevel@tonic-gate 
145*7c478bd9Sstevel@tonic-gate 	while (d2) {
146*7c478bd9Sstevel@tonic-gate 		changed = 1;
147*7c478bd9Sstevel@tonic-gate 		cb(NULL, d2, data);
148*7c478bd9Sstevel@tonic-gate 		(void) iodev_walk(NULL, d2->is_children, cb, data);
149*7c478bd9Sstevel@tonic-gate 		d2 = d2->is_next;
150*7c478bd9Sstevel@tonic-gate 	}
151*7c478bd9Sstevel@tonic-gate 
152*7c478bd9Sstevel@tonic-gate 	return (changed);
153*7c478bd9Sstevel@tonic-gate }
154*7c478bd9Sstevel@tonic-gate 
155*7c478bd9Sstevel@tonic-gate int
156*7c478bd9Sstevel@tonic-gate snapshot_walk(enum snapshot_types type, struct snapshot *old,
157*7c478bd9Sstevel@tonic-gate     struct snapshot *new, snapshot_cb cb, void *data)
158*7c478bd9Sstevel@tonic-gate {
159*7c478bd9Sstevel@tonic-gate 	int changed = 0;
160*7c478bd9Sstevel@tonic-gate 
161*7c478bd9Sstevel@tonic-gate 	switch (type) {
162*7c478bd9Sstevel@tonic-gate 	case SNAP_CPUS:
163*7c478bd9Sstevel@tonic-gate 		changed = cpu_walk(old, new, cb, data);
164*7c478bd9Sstevel@tonic-gate 		break;
165*7c478bd9Sstevel@tonic-gate 
166*7c478bd9Sstevel@tonic-gate 	case SNAP_PSETS:
167*7c478bd9Sstevel@tonic-gate 		changed = pset_walk(old, new, cb, data);
168*7c478bd9Sstevel@tonic-gate 		break;
169*7c478bd9Sstevel@tonic-gate 
170*7c478bd9Sstevel@tonic-gate 	case SNAP_CONTROLLERS:
171*7c478bd9Sstevel@tonic-gate 	case SNAP_IODEVS:
172*7c478bd9Sstevel@tonic-gate 	case SNAP_IOPATHS:
173*7c478bd9Sstevel@tonic-gate 		changed = iodev_walk(old ? old->s_iodevs : NULL,
174*7c478bd9Sstevel@tonic-gate 		    new->s_iodevs, cb, data);
175*7c478bd9Sstevel@tonic-gate 		break;
176*7c478bd9Sstevel@tonic-gate 
177*7c478bd9Sstevel@tonic-gate 	default:
178*7c478bd9Sstevel@tonic-gate 		break;
179*7c478bd9Sstevel@tonic-gate 	}
180*7c478bd9Sstevel@tonic-gate 
181*7c478bd9Sstevel@tonic-gate 	return (changed);
182*7c478bd9Sstevel@tonic-gate }
183*7c478bd9Sstevel@tonic-gate 
184*7c478bd9Sstevel@tonic-gate static void
185*7c478bd9Sstevel@tonic-gate add_nr_to_list(char *buf, unsigned long nr)
186*7c478bd9Sstevel@tonic-gate {
187*7c478bd9Sstevel@tonic-gate 	char tmp[LIST_SIZE];
188*7c478bd9Sstevel@tonic-gate 
189*7c478bd9Sstevel@tonic-gate 	(void) snprintf(tmp, LIST_SIZE, "%lu", nr);
190*7c478bd9Sstevel@tonic-gate 
191*7c478bd9Sstevel@tonic-gate 	if (strlen(buf))
192*7c478bd9Sstevel@tonic-gate 		(void) strlcat(buf, ", ", LIST_SIZE);
193*7c478bd9Sstevel@tonic-gate 
194*7c478bd9Sstevel@tonic-gate 	(void) strlcat(buf, tmp, LIST_SIZE);
195*7c478bd9Sstevel@tonic-gate }
196*7c478bd9Sstevel@tonic-gate 
197*7c478bd9Sstevel@tonic-gate static void
198*7c478bd9Sstevel@tonic-gate cpu_report(void *v1, void *v2, void *data)
199*7c478bd9Sstevel@tonic-gate {
200*7c478bd9Sstevel@tonic-gate 	int *pset = (int *)data;
201*7c478bd9Sstevel@tonic-gate 	struct cpu_snapshot *c1 = (struct cpu_snapshot *)v1;
202*7c478bd9Sstevel@tonic-gate 	struct cpu_snapshot *c2 = (struct cpu_snapshot *)v2;
203*7c478bd9Sstevel@tonic-gate 
204*7c478bd9Sstevel@tonic-gate 	if (*pset && c1->cs_pset_id != c2->cs_pset_id) {
205*7c478bd9Sstevel@tonic-gate 		(void) printf("<<processor %d moved from pset: %d to: %d>>\n",
206*7c478bd9Sstevel@tonic-gate 		    c1->cs_id, c1->cs_pset_id, c2->cs_pset_id);
207*7c478bd9Sstevel@tonic-gate 	}
208*7c478bd9Sstevel@tonic-gate 
209*7c478bd9Sstevel@tonic-gate 	if (c1->cs_state == c2->cs_state)
210*7c478bd9Sstevel@tonic-gate 		return;
211*7c478bd9Sstevel@tonic-gate 
212*7c478bd9Sstevel@tonic-gate 	if (CPU_ONLINE(c1->cs_state) && !CPU_ONLINE(c2->cs_state))
213*7c478bd9Sstevel@tonic-gate 		add_nr_to_list(cpus_removed, c1->cs_id);
214*7c478bd9Sstevel@tonic-gate 
215*7c478bd9Sstevel@tonic-gate 	if (!CPU_ONLINE(c1->cs_state) && CPU_ONLINE(c2->cs_state))
216*7c478bd9Sstevel@tonic-gate 		add_nr_to_list(cpus_added, c2->cs_id);
217*7c478bd9Sstevel@tonic-gate }
218*7c478bd9Sstevel@tonic-gate 
219*7c478bd9Sstevel@tonic-gate /*ARGSUSED*/
220*7c478bd9Sstevel@tonic-gate static void
221*7c478bd9Sstevel@tonic-gate pset_report(void *v1, void *v2, void *data)
222*7c478bd9Sstevel@tonic-gate {
223*7c478bd9Sstevel@tonic-gate 	struct pset_snapshot *p1 = (struct pset_snapshot *)v1;
224*7c478bd9Sstevel@tonic-gate 	struct pset_snapshot *p2 = (struct pset_snapshot *)v2;
225*7c478bd9Sstevel@tonic-gate 
226*7c478bd9Sstevel@tonic-gate 	if (p2 == NULL) {
227*7c478bd9Sstevel@tonic-gate 		(void) printf("<<pset destroyed: %u>>\n", p1->ps_id);
228*7c478bd9Sstevel@tonic-gate 		return;
229*7c478bd9Sstevel@tonic-gate 	}
230*7c478bd9Sstevel@tonic-gate 
231*7c478bd9Sstevel@tonic-gate 	if (p1 == NULL)
232*7c478bd9Sstevel@tonic-gate 		(void) printf("<<pset created: %u>>\n", p2->ps_id);
233*7c478bd9Sstevel@tonic-gate }
234*7c478bd9Sstevel@tonic-gate 
235*7c478bd9Sstevel@tonic-gate static void
236*7c478bd9Sstevel@tonic-gate get_child_list(struct iodev_snapshot *iodev, char *buf)
237*7c478bd9Sstevel@tonic-gate {
238*7c478bd9Sstevel@tonic-gate 	char tmp[LIST_SIZE];
239*7c478bd9Sstevel@tonic-gate 	struct iodev_snapshot *pos = iodev->is_children;
240*7c478bd9Sstevel@tonic-gate 
241*7c478bd9Sstevel@tonic-gate 	while (pos) {
242*7c478bd9Sstevel@tonic-gate 		if (pos->is_type == IODEV_PARTITION) {
243*7c478bd9Sstevel@tonic-gate 			add_nr_to_list(buf, pos->is_id.id);
244*7c478bd9Sstevel@tonic-gate 		} else if (pos->is_type == IODEV_DISK) {
245*7c478bd9Sstevel@tonic-gate 			if (strlen(buf))
246*7c478bd9Sstevel@tonic-gate 				(void) strlcat(buf, ", ", LIST_SIZE);
247*7c478bd9Sstevel@tonic-gate 			(void) strlcat(buf, "t", LIST_SIZE);
248*7c478bd9Sstevel@tonic-gate 			(void) strlcat(buf, pos->is_id.tid, LIST_SIZE);
249*7c478bd9Sstevel@tonic-gate 			(void) strlcat(buf, "d", LIST_SIZE);
250*7c478bd9Sstevel@tonic-gate 			*tmp = '\0';
251*7c478bd9Sstevel@tonic-gate 			add_nr_to_list(tmp, pos->is_id.id);
252*7c478bd9Sstevel@tonic-gate 			(void) strlcat(buf, tmp, LIST_SIZE);
253*7c478bd9Sstevel@tonic-gate 		}
254*7c478bd9Sstevel@tonic-gate 		pos = pos->is_next;
255*7c478bd9Sstevel@tonic-gate 	}
256*7c478bd9Sstevel@tonic-gate }
257*7c478bd9Sstevel@tonic-gate 
258*7c478bd9Sstevel@tonic-gate static void
259*7c478bd9Sstevel@tonic-gate iodev_changed(struct iodev_snapshot *iodev, int added)
260*7c478bd9Sstevel@tonic-gate {
261*7c478bd9Sstevel@tonic-gate 	char tmp[LIST_SIZE];
262*7c478bd9Sstevel@tonic-gate 	int is_disk = iodev->is_type == IODEV_DISK;
263*7c478bd9Sstevel@tonic-gate 	char *name = iodev->is_name;
264*7c478bd9Sstevel@tonic-gate 
265*7c478bd9Sstevel@tonic-gate 	if (iodev->is_pretty)
266*7c478bd9Sstevel@tonic-gate 		name = iodev->is_pretty;
267*7c478bd9Sstevel@tonic-gate 
268*7c478bd9Sstevel@tonic-gate 	switch (iodev->is_type) {
269*7c478bd9Sstevel@tonic-gate 	case IODEV_IOPATH:
270*7c478bd9Sstevel@tonic-gate 		(void) printf("<<multi-path %s: %s>>\n",
271*7c478bd9Sstevel@tonic-gate 		    added ? "added" : "removed", name);
272*7c478bd9Sstevel@tonic-gate 		break;
273*7c478bd9Sstevel@tonic-gate 	case IODEV_PARTITION:
274*7c478bd9Sstevel@tonic-gate 		(void) printf("<<partition %s: %s>>\n",
275*7c478bd9Sstevel@tonic-gate 		    added ? "added" : "removed", name);
276*7c478bd9Sstevel@tonic-gate 		break;
277*7c478bd9Sstevel@tonic-gate 	case IODEV_NFS:
278*7c478bd9Sstevel@tonic-gate 		(void) printf("<<NFS %s: %s>>\n",
279*7c478bd9Sstevel@tonic-gate 		    added ? "mounted" : "unmounted", name);
280*7c478bd9Sstevel@tonic-gate 		break;
281*7c478bd9Sstevel@tonic-gate 	case IODEV_TAPE:
282*7c478bd9Sstevel@tonic-gate 		(void) printf("<<device %s: %s>>\n",
283*7c478bd9Sstevel@tonic-gate 		    added ? "added" : "removed", name);
284*7c478bd9Sstevel@tonic-gate 		break;
285*7c478bd9Sstevel@tonic-gate 	case IODEV_CONTROLLER:
286*7c478bd9Sstevel@tonic-gate 	case IODEV_DISK:
287*7c478bd9Sstevel@tonic-gate 		*tmp = '\0';
288*7c478bd9Sstevel@tonic-gate 		get_child_list(iodev, tmp);
289*7c478bd9Sstevel@tonic-gate 		(void) printf("<<%s %s: %s", is_disk ? "disk" : "controller",
290*7c478bd9Sstevel@tonic-gate 		    added ? "added" : "removed", name);
291*7c478bd9Sstevel@tonic-gate 		if (!*tmp) {
292*7c478bd9Sstevel@tonic-gate 			(void) printf(">>\n");
293*7c478bd9Sstevel@tonic-gate 			return;
294*7c478bd9Sstevel@tonic-gate 		}
295*7c478bd9Sstevel@tonic-gate 		(void) printf(" (%s %s)>>\n", is_disk ? "slices" : "disks",
296*7c478bd9Sstevel@tonic-gate 		    tmp);
297*7c478bd9Sstevel@tonic-gate 		break;
298*7c478bd9Sstevel@tonic-gate 	};
299*7c478bd9Sstevel@tonic-gate }
300*7c478bd9Sstevel@tonic-gate 
301*7c478bd9Sstevel@tonic-gate static void
302*7c478bd9Sstevel@tonic-gate iodev_report(struct iodev_snapshot *d1, struct iodev_snapshot *d2)
303*7c478bd9Sstevel@tonic-gate {
304*7c478bd9Sstevel@tonic-gate 	while (d1 && d2) {
305*7c478bd9Sstevel@tonic-gate 		if (iodev_cmp(d1, d2) < 0) {
306*7c478bd9Sstevel@tonic-gate 			iodev_changed(d1, 0);
307*7c478bd9Sstevel@tonic-gate 			d1 = d1->is_next;
308*7c478bd9Sstevel@tonic-gate 		} else if (iodev_cmp(d1, d2) > 0) {
309*7c478bd9Sstevel@tonic-gate 			iodev_changed(d2, 1);
310*7c478bd9Sstevel@tonic-gate 			d2 = d2->is_next;
311*7c478bd9Sstevel@tonic-gate 		} else {
312*7c478bd9Sstevel@tonic-gate 			iodev_report(d1->is_children, d2->is_children);
313*7c478bd9Sstevel@tonic-gate 			d1 = d1->is_next;
314*7c478bd9Sstevel@tonic-gate 			d2 = d2->is_next;
315*7c478bd9Sstevel@tonic-gate 		}
316*7c478bd9Sstevel@tonic-gate 	}
317*7c478bd9Sstevel@tonic-gate 
318*7c478bd9Sstevel@tonic-gate 	while (d1) {
319*7c478bd9Sstevel@tonic-gate 		iodev_changed(d1, 0);
320*7c478bd9Sstevel@tonic-gate 		d1 = d1->is_next;
321*7c478bd9Sstevel@tonic-gate 	}
322*7c478bd9Sstevel@tonic-gate 
323*7c478bd9Sstevel@tonic-gate 	while (d2) {
324*7c478bd9Sstevel@tonic-gate 		iodev_changed(d2, 1);
325*7c478bd9Sstevel@tonic-gate 		d2 = d2->is_next;
326*7c478bd9Sstevel@tonic-gate 	}
327*7c478bd9Sstevel@tonic-gate }
328*7c478bd9Sstevel@tonic-gate 
329*7c478bd9Sstevel@tonic-gate void
330*7c478bd9Sstevel@tonic-gate snapshot_report_changes(struct snapshot *old, struct snapshot *new)
331*7c478bd9Sstevel@tonic-gate {
332*7c478bd9Sstevel@tonic-gate 	int pset;
333*7c478bd9Sstevel@tonic-gate 
334*7c478bd9Sstevel@tonic-gate 	if (old == NULL || new == NULL)
335*7c478bd9Sstevel@tonic-gate 		return;
336*7c478bd9Sstevel@tonic-gate 
337*7c478bd9Sstevel@tonic-gate 	if (old->s_types != new->s_types)
338*7c478bd9Sstevel@tonic-gate 		return;
339*7c478bd9Sstevel@tonic-gate 
340*7c478bd9Sstevel@tonic-gate 	pset = old->s_types & SNAP_PSETS;
341*7c478bd9Sstevel@tonic-gate 
342*7c478bd9Sstevel@tonic-gate 	cpus_removed[0] = '\0';
343*7c478bd9Sstevel@tonic-gate 	cpus_added[0] = '\0';
344*7c478bd9Sstevel@tonic-gate 
345*7c478bd9Sstevel@tonic-gate 	if (old->s_types & SNAP_CPUS)
346*7c478bd9Sstevel@tonic-gate 		(void) snapshot_walk(SNAP_CPUS, old, new, cpu_report, &pset);
347*7c478bd9Sstevel@tonic-gate 
348*7c478bd9Sstevel@tonic-gate 	if (cpus_added[0]) {
349*7c478bd9Sstevel@tonic-gate 		(void) printf("<<processors added: %s>>\n",
350*7c478bd9Sstevel@tonic-gate 		    cpus_added);
351*7c478bd9Sstevel@tonic-gate 	}
352*7c478bd9Sstevel@tonic-gate 	if (cpus_removed[0]) {
353*7c478bd9Sstevel@tonic-gate 		(void) printf("<<processors removed: %s>>\n",
354*7c478bd9Sstevel@tonic-gate 		    cpus_removed);
355*7c478bd9Sstevel@tonic-gate 	}
356*7c478bd9Sstevel@tonic-gate 	if (pset) {
357*7c478bd9Sstevel@tonic-gate 		(void) snapshot_walk(SNAP_PSETS, old, new,
358*7c478bd9Sstevel@tonic-gate 		    pset_report, NULL);
359*7c478bd9Sstevel@tonic-gate 	}
360*7c478bd9Sstevel@tonic-gate 
361*7c478bd9Sstevel@tonic-gate 	iodev_report(old->s_iodevs, new->s_iodevs);
362*7c478bd9Sstevel@tonic-gate }
363*7c478bd9Sstevel@tonic-gate 
364*7c478bd9Sstevel@tonic-gate /*ARGSUSED*/
365*7c478bd9Sstevel@tonic-gate static void
366*7c478bd9Sstevel@tonic-gate dummy_cb(void *v1, void *v2, void *data)
367*7c478bd9Sstevel@tonic-gate {
368*7c478bd9Sstevel@tonic-gate }
369*7c478bd9Sstevel@tonic-gate 
370*7c478bd9Sstevel@tonic-gate int
371*7c478bd9Sstevel@tonic-gate snapshot_has_changed(struct snapshot *old, struct snapshot *new)
372*7c478bd9Sstevel@tonic-gate {
373*7c478bd9Sstevel@tonic-gate 	int ret = 0;
374*7c478bd9Sstevel@tonic-gate 	int cpu_mask = SNAP_CPUS | SNAP_PSETS | SNAP_SYSTEM;
375*7c478bd9Sstevel@tonic-gate 	int iodev_mask = SNAP_CONTROLLERS | SNAP_IODEVS | SNAP_IOPATHS;
376*7c478bd9Sstevel@tonic-gate 
377*7c478bd9Sstevel@tonic-gate 	if (old == NULL)
378*7c478bd9Sstevel@tonic-gate 		return (1);
379*7c478bd9Sstevel@tonic-gate 
380*7c478bd9Sstevel@tonic-gate 	if (new == NULL)
381*7c478bd9Sstevel@tonic-gate 		return (EINVAL);
382*7c478bd9Sstevel@tonic-gate 
383*7c478bd9Sstevel@tonic-gate 	if (old->s_types != new->s_types)
384*7c478bd9Sstevel@tonic-gate 		return (EINVAL);
385*7c478bd9Sstevel@tonic-gate 
386*7c478bd9Sstevel@tonic-gate 	if (!ret && (old->s_types & cpu_mask))
387*7c478bd9Sstevel@tonic-gate 		ret = snapshot_walk(SNAP_CPUS, old, new, dummy_cb, NULL);
388*7c478bd9Sstevel@tonic-gate 	if (!ret && (old->s_types & SNAP_PSETS))
389*7c478bd9Sstevel@tonic-gate 		ret = snapshot_walk(SNAP_PSETS, old, new, dummy_cb, NULL);
390*7c478bd9Sstevel@tonic-gate 	if (!ret && (old->s_types & iodev_mask))
391*7c478bd9Sstevel@tonic-gate 		ret = snapshot_walk(SNAP_IODEVS, old, new, dummy_cb, NULL);
392*7c478bd9Sstevel@tonic-gate 
393*7c478bd9Sstevel@tonic-gate 	return (ret);
394*7c478bd9Sstevel@tonic-gate }
395