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