xref: /onnv-gate/usr/src/cmd/stat/common/walkers.c (revision 2907:d11defc6b41b)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*2907Scth  * Common Development and Distribution License (the "License").
6*2907Scth  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
210Sstevel@tonic-gate /*
22*2907Scth  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
230Sstevel@tonic-gate  * Use is subject to license terms.
240Sstevel@tonic-gate  */
250Sstevel@tonic-gate 
260Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
270Sstevel@tonic-gate 
280Sstevel@tonic-gate #include "statcommon.h"
290Sstevel@tonic-gate 
300Sstevel@tonic-gate #include <string.h>
310Sstevel@tonic-gate #include <errno.h>
320Sstevel@tonic-gate 
330Sstevel@tonic-gate /* max size of report change annotations */
340Sstevel@tonic-gate #define	LIST_SIZE 512
350Sstevel@tonic-gate 
360Sstevel@tonic-gate static char cpus_added[LIST_SIZE];
370Sstevel@tonic-gate static char cpus_removed[LIST_SIZE];
380Sstevel@tonic-gate 
390Sstevel@tonic-gate static int
cpu_walk(struct snapshot * old,struct snapshot * new,snapshot_cb cb,void * data)400Sstevel@tonic-gate cpu_walk(struct snapshot *old, struct snapshot *new,
410Sstevel@tonic-gate     snapshot_cb cb, void *data)
420Sstevel@tonic-gate {
430Sstevel@tonic-gate 	int changed = 0;
440Sstevel@tonic-gate 	int i;
450Sstevel@tonic-gate 
460Sstevel@tonic-gate 	/* CPUs can change state but not re-order */
470Sstevel@tonic-gate 	for (i = 0; i < new->s_nr_cpus; i++) {
480Sstevel@tonic-gate 		struct cpu_snapshot *cpu = NULL;
490Sstevel@tonic-gate 		struct cpu_snapshot *newcpu = &new->s_cpus[i];
500Sstevel@tonic-gate 		if (old)
510Sstevel@tonic-gate 			cpu = &old->s_cpus[i];
520Sstevel@tonic-gate 		cb(cpu, newcpu, data);
530Sstevel@tonic-gate 		if (cpu == NULL)
540Sstevel@tonic-gate 			changed = 1;
550Sstevel@tonic-gate 		else {
560Sstevel@tonic-gate 			/*
570Sstevel@tonic-gate 			 * We only care about off/on line transitions
580Sstevel@tonic-gate 			 */
590Sstevel@tonic-gate 			if ((CPU_ACTIVE(cpu) && !CPU_ACTIVE(newcpu)) ||
600Sstevel@tonic-gate 			    (!CPU_ACTIVE(cpu) && CPU_ACTIVE(newcpu)))
610Sstevel@tonic-gate 				changed = 1;
620Sstevel@tonic-gate 			if ((new->s_types & SNAP_PSETS) &&
630Sstevel@tonic-gate 				cpu->cs_pset_id != newcpu->cs_pset_id)
640Sstevel@tonic-gate 				changed = 1;
650Sstevel@tonic-gate 		}
660Sstevel@tonic-gate 
670Sstevel@tonic-gate 	}
680Sstevel@tonic-gate 
690Sstevel@tonic-gate 	return (changed);
700Sstevel@tonic-gate }
710Sstevel@tonic-gate 
720Sstevel@tonic-gate static int
pset_walk(struct snapshot * old,struct snapshot * new,snapshot_cb cb,void * data)730Sstevel@tonic-gate pset_walk(struct snapshot *old, struct snapshot *new,
740Sstevel@tonic-gate     snapshot_cb cb, void *data)
750Sstevel@tonic-gate {
760Sstevel@tonic-gate 	int i = 0;
770Sstevel@tonic-gate 	int j = 0;
780Sstevel@tonic-gate 	int changed = 0;
790Sstevel@tonic-gate 
800Sstevel@tonic-gate 	while (old && i < old->s_nr_psets && j < new->s_nr_psets) {
810Sstevel@tonic-gate 		if (old->s_psets[i].ps_id < new->s_psets[j].ps_id) {
820Sstevel@tonic-gate 			cb(&old->s_psets[i], NULL, data);
830Sstevel@tonic-gate 			i++;
840Sstevel@tonic-gate 			changed = 1;
850Sstevel@tonic-gate 		} else if (old->s_psets[i].ps_id > new->s_psets[j].ps_id) {
860Sstevel@tonic-gate 			cb(NULL, &new->s_psets[j], data);
870Sstevel@tonic-gate 			j++;
880Sstevel@tonic-gate 			changed = 1;
890Sstevel@tonic-gate 		} else {
900Sstevel@tonic-gate 			cb(&old->s_psets[i], &new->s_psets[j], data);
910Sstevel@tonic-gate 			i++;
920Sstevel@tonic-gate 			j++;
930Sstevel@tonic-gate 		}
940Sstevel@tonic-gate 	}
950Sstevel@tonic-gate 
960Sstevel@tonic-gate 	while (old && i < old->s_nr_psets) {
970Sstevel@tonic-gate 		cb(&old->s_psets[i], NULL, data);
980Sstevel@tonic-gate 		i++;
990Sstevel@tonic-gate 		changed = 1;
1000Sstevel@tonic-gate 	}
1010Sstevel@tonic-gate 
1020Sstevel@tonic-gate 	while (j < new->s_nr_psets) {
1030Sstevel@tonic-gate 		cb(NULL, &new->s_psets[j], data);
1040Sstevel@tonic-gate 		j++;
1050Sstevel@tonic-gate 		changed = 1;
1060Sstevel@tonic-gate 	}
1070Sstevel@tonic-gate 
1080Sstevel@tonic-gate 	return (changed);
1090Sstevel@tonic-gate }
1100Sstevel@tonic-gate 
1110Sstevel@tonic-gate static int
iodev_walk(struct iodev_snapshot * d1,struct iodev_snapshot * d2,snapshot_cb cb,void * data)1120Sstevel@tonic-gate iodev_walk(struct iodev_snapshot *d1, struct iodev_snapshot *d2,
1130Sstevel@tonic-gate     snapshot_cb cb, void *data)
1140Sstevel@tonic-gate {
1150Sstevel@tonic-gate 	int changed = 0;
1160Sstevel@tonic-gate 
1170Sstevel@tonic-gate 	while (d1 && d2) {
1180Sstevel@tonic-gate 		if (strcmp(d1->is_name, d2->is_name) < 0) {
1190Sstevel@tonic-gate 			changed = 1;
1200Sstevel@tonic-gate 			cb(d1, NULL, data);
1210Sstevel@tonic-gate 			(void) iodev_walk(d1->is_children, NULL, cb, data);
1220Sstevel@tonic-gate 			d1 = d1->is_next;
1230Sstevel@tonic-gate 		} else if (strcmp(d1->is_name, d2->is_name) > 0) {
1240Sstevel@tonic-gate 			changed = 1;
1250Sstevel@tonic-gate 			cb(NULL, d2, data);
1260Sstevel@tonic-gate 			(void) iodev_walk(NULL, d2->is_children, cb, data);
1270Sstevel@tonic-gate 			d2 = d2->is_next;
1280Sstevel@tonic-gate 		} else {
1290Sstevel@tonic-gate 			cb(d1, d2, data);
1300Sstevel@tonic-gate 			changed |= iodev_walk(d1->is_children,
1310Sstevel@tonic-gate 					d2->is_children, cb, data);
1320Sstevel@tonic-gate 			d1 = d1->is_next;
1330Sstevel@tonic-gate 			d2 = d2->is_next;
1340Sstevel@tonic-gate 		}
1350Sstevel@tonic-gate 	}
1360Sstevel@tonic-gate 
1370Sstevel@tonic-gate 	while (d1) {
1380Sstevel@tonic-gate 		changed = 1;
1390Sstevel@tonic-gate 		cb(d1, NULL, data);
1400Sstevel@tonic-gate 		(void) iodev_walk(d1->is_children, NULL, cb, data);
1410Sstevel@tonic-gate 		d1 = d1->is_next;
1420Sstevel@tonic-gate 	}
1430Sstevel@tonic-gate 
1440Sstevel@tonic-gate 	while (d2) {
1450Sstevel@tonic-gate 		changed = 1;
1460Sstevel@tonic-gate 		cb(NULL, d2, data);
1470Sstevel@tonic-gate 		(void) iodev_walk(NULL, d2->is_children, cb, data);
1480Sstevel@tonic-gate 		d2 = d2->is_next;
1490Sstevel@tonic-gate 	}
1500Sstevel@tonic-gate 
1510Sstevel@tonic-gate 	return (changed);
1520Sstevel@tonic-gate }
1530Sstevel@tonic-gate 
1540Sstevel@tonic-gate int
snapshot_walk(enum snapshot_types type,struct snapshot * old,struct snapshot * new,snapshot_cb cb,void * data)1550Sstevel@tonic-gate snapshot_walk(enum snapshot_types type, struct snapshot *old,
1560Sstevel@tonic-gate     struct snapshot *new, snapshot_cb cb, void *data)
1570Sstevel@tonic-gate {
1580Sstevel@tonic-gate 	int changed = 0;
1590Sstevel@tonic-gate 
1600Sstevel@tonic-gate 	switch (type) {
1610Sstevel@tonic-gate 	case SNAP_CPUS:
1620Sstevel@tonic-gate 		changed = cpu_walk(old, new, cb, data);
1630Sstevel@tonic-gate 		break;
1640Sstevel@tonic-gate 
1650Sstevel@tonic-gate 	case SNAP_PSETS:
1660Sstevel@tonic-gate 		changed = pset_walk(old, new, cb, data);
1670Sstevel@tonic-gate 		break;
1680Sstevel@tonic-gate 
1690Sstevel@tonic-gate 	case SNAP_CONTROLLERS:
1700Sstevel@tonic-gate 	case SNAP_IODEVS:
171*2907Scth 	case SNAP_IOPATHS_LI:
172*2907Scth 	case SNAP_IOPATHS_LTI:
1730Sstevel@tonic-gate 		changed = iodev_walk(old ? old->s_iodevs : NULL,
1740Sstevel@tonic-gate 		    new->s_iodevs, cb, data);
1750Sstevel@tonic-gate 		break;
1760Sstevel@tonic-gate 
1770Sstevel@tonic-gate 	default:
1780Sstevel@tonic-gate 		break;
1790Sstevel@tonic-gate 	}
1800Sstevel@tonic-gate 
1810Sstevel@tonic-gate 	return (changed);
1820Sstevel@tonic-gate }
1830Sstevel@tonic-gate 
1840Sstevel@tonic-gate static void
add_nr_to_list(char * buf,unsigned long nr)1850Sstevel@tonic-gate add_nr_to_list(char *buf, unsigned long nr)
1860Sstevel@tonic-gate {
1870Sstevel@tonic-gate 	char tmp[LIST_SIZE];
1880Sstevel@tonic-gate 
1890Sstevel@tonic-gate 	(void) snprintf(tmp, LIST_SIZE, "%lu", nr);
1900Sstevel@tonic-gate 
1910Sstevel@tonic-gate 	if (strlen(buf))
1920Sstevel@tonic-gate 		(void) strlcat(buf, ", ", LIST_SIZE);
1930Sstevel@tonic-gate 
1940Sstevel@tonic-gate 	(void) strlcat(buf, tmp, LIST_SIZE);
1950Sstevel@tonic-gate }
1960Sstevel@tonic-gate 
1970Sstevel@tonic-gate static void
cpu_report(void * v1,void * v2,void * data)1980Sstevel@tonic-gate cpu_report(void *v1, void *v2, void *data)
1990Sstevel@tonic-gate {
2000Sstevel@tonic-gate 	int *pset = (int *)data;
2010Sstevel@tonic-gate 	struct cpu_snapshot *c1 = (struct cpu_snapshot *)v1;
2020Sstevel@tonic-gate 	struct cpu_snapshot *c2 = (struct cpu_snapshot *)v2;
2030Sstevel@tonic-gate 
2040Sstevel@tonic-gate 	if (*pset && c1->cs_pset_id != c2->cs_pset_id) {
2050Sstevel@tonic-gate 		(void) printf("<<processor %d moved from pset: %d to: %d>>\n",
2060Sstevel@tonic-gate 		    c1->cs_id, c1->cs_pset_id, c2->cs_pset_id);
2070Sstevel@tonic-gate 	}
2080Sstevel@tonic-gate 
2090Sstevel@tonic-gate 	if (c1->cs_state == c2->cs_state)
2100Sstevel@tonic-gate 		return;
2110Sstevel@tonic-gate 
2120Sstevel@tonic-gate 	if (CPU_ONLINE(c1->cs_state) && !CPU_ONLINE(c2->cs_state))
2130Sstevel@tonic-gate 		add_nr_to_list(cpus_removed, c1->cs_id);
2140Sstevel@tonic-gate 
2150Sstevel@tonic-gate 	if (!CPU_ONLINE(c1->cs_state) && CPU_ONLINE(c2->cs_state))
2160Sstevel@tonic-gate 		add_nr_to_list(cpus_added, c2->cs_id);
2170Sstevel@tonic-gate }
2180Sstevel@tonic-gate 
2190Sstevel@tonic-gate /*ARGSUSED*/
2200Sstevel@tonic-gate static void
pset_report(void * v1,void * v2,void * data)2210Sstevel@tonic-gate pset_report(void *v1, void *v2, void *data)
2220Sstevel@tonic-gate {
2230Sstevel@tonic-gate 	struct pset_snapshot *p1 = (struct pset_snapshot *)v1;
2240Sstevel@tonic-gate 	struct pset_snapshot *p2 = (struct pset_snapshot *)v2;
2250Sstevel@tonic-gate 
2260Sstevel@tonic-gate 	if (p2 == NULL) {
2270Sstevel@tonic-gate 		(void) printf("<<pset destroyed: %u>>\n", p1->ps_id);
2280Sstevel@tonic-gate 		return;
2290Sstevel@tonic-gate 	}
2300Sstevel@tonic-gate 
2310Sstevel@tonic-gate 	if (p1 == NULL)
2320Sstevel@tonic-gate 		(void) printf("<<pset created: %u>>\n", p2->ps_id);
2330Sstevel@tonic-gate }
2340Sstevel@tonic-gate 
2350Sstevel@tonic-gate static void
get_child_list(struct iodev_snapshot * iodev,char * buf)2360Sstevel@tonic-gate get_child_list(struct iodev_snapshot *iodev, char *buf)
2370Sstevel@tonic-gate {
2380Sstevel@tonic-gate 	char tmp[LIST_SIZE];
2390Sstevel@tonic-gate 	struct iodev_snapshot *pos = iodev->is_children;
2400Sstevel@tonic-gate 
2410Sstevel@tonic-gate 	while (pos) {
2420Sstevel@tonic-gate 		if (pos->is_type == IODEV_PARTITION) {
2430Sstevel@tonic-gate 			add_nr_to_list(buf, pos->is_id.id);
2440Sstevel@tonic-gate 		} else if (pos->is_type == IODEV_DISK) {
2450Sstevel@tonic-gate 			if (strlen(buf))
2460Sstevel@tonic-gate 				(void) strlcat(buf, ", ", LIST_SIZE);
2470Sstevel@tonic-gate 			(void) strlcat(buf, "t", LIST_SIZE);
2480Sstevel@tonic-gate 			(void) strlcat(buf, pos->is_id.tid, LIST_SIZE);
2490Sstevel@tonic-gate 			(void) strlcat(buf, "d", LIST_SIZE);
2500Sstevel@tonic-gate 			*tmp = '\0';
2510Sstevel@tonic-gate 			add_nr_to_list(tmp, pos->is_id.id);
2520Sstevel@tonic-gate 			(void) strlcat(buf, tmp, LIST_SIZE);
2530Sstevel@tonic-gate 		}
2540Sstevel@tonic-gate 		pos = pos->is_next;
2550Sstevel@tonic-gate 	}
2560Sstevel@tonic-gate }
2570Sstevel@tonic-gate 
2580Sstevel@tonic-gate static void
iodev_changed(struct iodev_snapshot * iodev,int added)2590Sstevel@tonic-gate iodev_changed(struct iodev_snapshot *iodev, int added)
2600Sstevel@tonic-gate {
2610Sstevel@tonic-gate 	char tmp[LIST_SIZE];
2620Sstevel@tonic-gate 	int is_disk = iodev->is_type == IODEV_DISK;
2630Sstevel@tonic-gate 	char *name = iodev->is_name;
2640Sstevel@tonic-gate 
2650Sstevel@tonic-gate 	if (iodev->is_pretty)
2660Sstevel@tonic-gate 		name = iodev->is_pretty;
2670Sstevel@tonic-gate 
2680Sstevel@tonic-gate 	switch (iodev->is_type) {
269*2907Scth 	case IODEV_IOPATH_LT:
270*2907Scth 	case IODEV_IOPATH_LI:
271*2907Scth 	case IODEV_IOPATH_LTI:
2720Sstevel@tonic-gate 		(void) printf("<<multi-path %s: %s>>\n",
2730Sstevel@tonic-gate 		    added ? "added" : "removed", name);
2740Sstevel@tonic-gate 		break;
2750Sstevel@tonic-gate 	case IODEV_PARTITION:
2760Sstevel@tonic-gate 		(void) printf("<<partition %s: %s>>\n",
2770Sstevel@tonic-gate 		    added ? "added" : "removed", name);
2780Sstevel@tonic-gate 		break;
2790Sstevel@tonic-gate 	case IODEV_NFS:
2800Sstevel@tonic-gate 		(void) printf("<<NFS %s: %s>>\n",
2810Sstevel@tonic-gate 		    added ? "mounted" : "unmounted", name);
2820Sstevel@tonic-gate 		break;
2830Sstevel@tonic-gate 	case IODEV_TAPE:
2840Sstevel@tonic-gate 		(void) printf("<<device %s: %s>>\n",
2850Sstevel@tonic-gate 		    added ? "added" : "removed", name);
2860Sstevel@tonic-gate 		break;
2870Sstevel@tonic-gate 	case IODEV_CONTROLLER:
2880Sstevel@tonic-gate 	case IODEV_DISK:
2890Sstevel@tonic-gate 		*tmp = '\0';
2900Sstevel@tonic-gate 		get_child_list(iodev, tmp);
2910Sstevel@tonic-gate 		(void) printf("<<%s %s: %s", is_disk ? "disk" : "controller",
2920Sstevel@tonic-gate 		    added ? "added" : "removed", name);
2930Sstevel@tonic-gate 		if (!*tmp) {
2940Sstevel@tonic-gate 			(void) printf(">>\n");
2950Sstevel@tonic-gate 			return;
2960Sstevel@tonic-gate 		}
2970Sstevel@tonic-gate 		(void) printf(" (%s %s)>>\n", is_disk ? "slices" : "disks",
2980Sstevel@tonic-gate 		    tmp);
2990Sstevel@tonic-gate 		break;
3000Sstevel@tonic-gate 	};
3010Sstevel@tonic-gate }
3020Sstevel@tonic-gate 
3030Sstevel@tonic-gate static void
iodev_report(struct iodev_snapshot * d1,struct iodev_snapshot * d2)3040Sstevel@tonic-gate iodev_report(struct iodev_snapshot *d1, struct iodev_snapshot *d2)
3050Sstevel@tonic-gate {
3060Sstevel@tonic-gate 	while (d1 && d2) {
3070Sstevel@tonic-gate 		if (iodev_cmp(d1, d2) < 0) {
3080Sstevel@tonic-gate 			iodev_changed(d1, 0);
3090Sstevel@tonic-gate 			d1 = d1->is_next;
3100Sstevel@tonic-gate 		} else if (iodev_cmp(d1, d2) > 0) {
3110Sstevel@tonic-gate 			iodev_changed(d2, 1);
3120Sstevel@tonic-gate 			d2 = d2->is_next;
3130Sstevel@tonic-gate 		} else {
3140Sstevel@tonic-gate 			iodev_report(d1->is_children, d2->is_children);
3150Sstevel@tonic-gate 			d1 = d1->is_next;
3160Sstevel@tonic-gate 			d2 = d2->is_next;
3170Sstevel@tonic-gate 		}
3180Sstevel@tonic-gate 	}
3190Sstevel@tonic-gate 
3200Sstevel@tonic-gate 	while (d1) {
3210Sstevel@tonic-gate 		iodev_changed(d1, 0);
3220Sstevel@tonic-gate 		d1 = d1->is_next;
3230Sstevel@tonic-gate 	}
3240Sstevel@tonic-gate 
3250Sstevel@tonic-gate 	while (d2) {
3260Sstevel@tonic-gate 		iodev_changed(d2, 1);
3270Sstevel@tonic-gate 		d2 = d2->is_next;
3280Sstevel@tonic-gate 	}
3290Sstevel@tonic-gate }
3300Sstevel@tonic-gate 
3310Sstevel@tonic-gate void
snapshot_report_changes(struct snapshot * old,struct snapshot * new)3320Sstevel@tonic-gate snapshot_report_changes(struct snapshot *old, struct snapshot *new)
3330Sstevel@tonic-gate {
3340Sstevel@tonic-gate 	int pset;
3350Sstevel@tonic-gate 
3360Sstevel@tonic-gate 	if (old == NULL || new == NULL)
3370Sstevel@tonic-gate 		return;
3380Sstevel@tonic-gate 
3390Sstevel@tonic-gate 	if (old->s_types != new->s_types)
3400Sstevel@tonic-gate 		return;
3410Sstevel@tonic-gate 
3420Sstevel@tonic-gate 	pset = old->s_types & SNAP_PSETS;
3430Sstevel@tonic-gate 
3440Sstevel@tonic-gate 	cpus_removed[0] = '\0';
3450Sstevel@tonic-gate 	cpus_added[0] = '\0';
3460Sstevel@tonic-gate 
3470Sstevel@tonic-gate 	if (old->s_types & SNAP_CPUS)
3480Sstevel@tonic-gate 		(void) snapshot_walk(SNAP_CPUS, old, new, cpu_report, &pset);
3490Sstevel@tonic-gate 
3500Sstevel@tonic-gate 	if (cpus_added[0]) {
3510Sstevel@tonic-gate 		(void) printf("<<processors added: %s>>\n",
3520Sstevel@tonic-gate 		    cpus_added);
3530Sstevel@tonic-gate 	}
3540Sstevel@tonic-gate 	if (cpus_removed[0]) {
3550Sstevel@tonic-gate 		(void) printf("<<processors removed: %s>>\n",
3560Sstevel@tonic-gate 		    cpus_removed);
3570Sstevel@tonic-gate 	}
3580Sstevel@tonic-gate 	if (pset) {
3590Sstevel@tonic-gate 		(void) snapshot_walk(SNAP_PSETS, old, new,
3600Sstevel@tonic-gate 		    pset_report, NULL);
3610Sstevel@tonic-gate 	}
3620Sstevel@tonic-gate 
3630Sstevel@tonic-gate 	iodev_report(old->s_iodevs, new->s_iodevs);
3640Sstevel@tonic-gate }
3650Sstevel@tonic-gate 
3660Sstevel@tonic-gate /*ARGSUSED*/
3670Sstevel@tonic-gate static void
dummy_cb(void * v1,void * v2,void * data)3680Sstevel@tonic-gate dummy_cb(void *v1, void *v2, void *data)
3690Sstevel@tonic-gate {
3700Sstevel@tonic-gate }
3710Sstevel@tonic-gate 
3720Sstevel@tonic-gate int
snapshot_has_changed(struct snapshot * old,struct snapshot * new)3730Sstevel@tonic-gate snapshot_has_changed(struct snapshot *old, struct snapshot *new)
3740Sstevel@tonic-gate {
3750Sstevel@tonic-gate 	int ret = 0;
3760Sstevel@tonic-gate 	int cpu_mask = SNAP_CPUS | SNAP_PSETS | SNAP_SYSTEM;
377*2907Scth 	int iodev_mask = SNAP_CONTROLLERS | SNAP_IODEVS |
378*2907Scth 			SNAP_IOPATHS_LI | SNAP_IOPATHS_LTI;
3790Sstevel@tonic-gate 
3800Sstevel@tonic-gate 	if (old == NULL)
3810Sstevel@tonic-gate 		return (1);
3820Sstevel@tonic-gate 
3830Sstevel@tonic-gate 	if (new == NULL)
3840Sstevel@tonic-gate 		return (EINVAL);
3850Sstevel@tonic-gate 
3860Sstevel@tonic-gate 	if (old->s_types != new->s_types)
3870Sstevel@tonic-gate 		return (EINVAL);
3880Sstevel@tonic-gate 
3890Sstevel@tonic-gate 	if (!ret && (old->s_types & cpu_mask))
3900Sstevel@tonic-gate 		ret = snapshot_walk(SNAP_CPUS, old, new, dummy_cb, NULL);
3910Sstevel@tonic-gate 	if (!ret && (old->s_types & SNAP_PSETS))
3920Sstevel@tonic-gate 		ret = snapshot_walk(SNAP_PSETS, old, new, dummy_cb, NULL);
3930Sstevel@tonic-gate 	if (!ret && (old->s_types & iodev_mask))
3940Sstevel@tonic-gate 		ret = snapshot_walk(SNAP_IODEVS, old, new, dummy_cb, NULL);
3950Sstevel@tonic-gate 
3960Sstevel@tonic-gate 	return (ret);
3970Sstevel@tonic-gate }
398