17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate * CDDL HEADER START
37c478bd9Sstevel@tonic-gate *
47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the
5*25cf1a30Sjl139090 * Common Development and Distribution License (the "License").
6*25cf1a30Sjl139090 * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate *
87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate * and limitations under the License.
127c478bd9Sstevel@tonic-gate *
137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate *
197c478bd9Sstevel@tonic-gate * CDDL HEADER END
207c478bd9Sstevel@tonic-gate */
217c478bd9Sstevel@tonic-gate /*
22*25cf1a30Sjl139090 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
23*25cf1a30Sjl139090 * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate */
257c478bd9Sstevel@tonic-gate
267c478bd9Sstevel@tonic-gate /*
277c478bd9Sstevel@tonic-gate * Routines for traversing and packing/unpacking the handle
287c478bd9Sstevel@tonic-gate * returned from ri_init.
297c478bd9Sstevel@tonic-gate */
307c478bd9Sstevel@tonic-gate
317c478bd9Sstevel@tonic-gate #include <stdlib.h>
327c478bd9Sstevel@tonic-gate #include <strings.h>
337c478bd9Sstevel@tonic-gate #include "rsrc_info.h"
347c478bd9Sstevel@tonic-gate #include "rsrc_info_impl.h"
357c478bd9Sstevel@tonic-gate
36*25cf1a30Sjl139090 static int ap_list_pack(ri_ap_t *, char **, size_t *, int);
377c478bd9Sstevel@tonic-gate static int ap_list_unpack(char *, size_t, ri_ap_t **);
38*25cf1a30Sjl139090 static int ap_pack(ri_ap_t *, char **, size_t *, int);
397c478bd9Sstevel@tonic-gate static int ap_unpack(char *, size_t, ri_ap_t *);
40*25cf1a30Sjl139090 static int dev_list_pack(ri_dev_t *, char **, size_t *, int);
417c478bd9Sstevel@tonic-gate static int dev_list_unpack(char *, size_t, ri_dev_t **);
42*25cf1a30Sjl139090 static int dev_pack(ri_dev_t *, char **, size_t *, int);
437c478bd9Sstevel@tonic-gate static int dev_unpack(char *, size_t, ri_dev_t *);
44*25cf1a30Sjl139090 static int client_list_pack(ri_client_t *, char **, size_t *, int);
457c478bd9Sstevel@tonic-gate static int client_list_unpack(char *, size_t, ri_client_t **);
46*25cf1a30Sjl139090 static int client_pack(ri_client_t *, char **, size_t *, int);
477c478bd9Sstevel@tonic-gate static int client_unpack(char *, size_t, ri_client_t *);
48*25cf1a30Sjl139090 static int pack_add_byte_array(nvlist_t *, char *, nvlist_t *, int);
497c478bd9Sstevel@tonic-gate static int lookup_unpack_byte_array(nvlist_t *, char *, nvlist_t **);
507c478bd9Sstevel@tonic-gate static void ri_ap_free(ri_ap_t *);
517c478bd9Sstevel@tonic-gate
527c478bd9Sstevel@tonic-gate void
ri_fini(ri_hdl_t * hdl)537c478bd9Sstevel@tonic-gate ri_fini(ri_hdl_t *hdl)
547c478bd9Sstevel@tonic-gate {
557c478bd9Sstevel@tonic-gate ri_ap_t *ap;
567c478bd9Sstevel@tonic-gate ri_client_t *client;
577c478bd9Sstevel@tonic-gate
587c478bd9Sstevel@tonic-gate if (hdl == NULL)
597c478bd9Sstevel@tonic-gate return;
607c478bd9Sstevel@tonic-gate
617c478bd9Sstevel@tonic-gate while ((ap = hdl->aps) != NULL) {
627c478bd9Sstevel@tonic-gate hdl->aps = ap->next;
637c478bd9Sstevel@tonic-gate ri_ap_free(ap);
647c478bd9Sstevel@tonic-gate }
657c478bd9Sstevel@tonic-gate while ((client = hdl->cpu_cap_clients) != NULL) {
667c478bd9Sstevel@tonic-gate hdl->cpu_cap_clients = client->next;
677c478bd9Sstevel@tonic-gate ri_client_free(client);
687c478bd9Sstevel@tonic-gate }
697c478bd9Sstevel@tonic-gate while ((client = hdl->mem_cap_clients) != NULL) {
707c478bd9Sstevel@tonic-gate hdl->mem_cap_clients = client->next;
717c478bd9Sstevel@tonic-gate ri_client_free(client);
727c478bd9Sstevel@tonic-gate }
737c478bd9Sstevel@tonic-gate free(hdl);
747c478bd9Sstevel@tonic-gate }
757c478bd9Sstevel@tonic-gate
767c478bd9Sstevel@tonic-gate static void
ri_ap_free(ri_ap_t * ap)777c478bd9Sstevel@tonic-gate ri_ap_free(ri_ap_t *ap)
787c478bd9Sstevel@tonic-gate {
797c478bd9Sstevel@tonic-gate ri_dev_t *dev;
807c478bd9Sstevel@tonic-gate
817c478bd9Sstevel@tonic-gate assert(ap != NULL);
827c478bd9Sstevel@tonic-gate
837c478bd9Sstevel@tonic-gate nvlist_free(ap->conf_props);
847c478bd9Sstevel@tonic-gate
857c478bd9Sstevel@tonic-gate while ((dev = ap->cpus) != NULL) {
867c478bd9Sstevel@tonic-gate ap->cpus = dev->next;
877c478bd9Sstevel@tonic-gate ri_dev_free(dev);
887c478bd9Sstevel@tonic-gate }
897c478bd9Sstevel@tonic-gate while ((dev = ap->mems) != NULL) {
907c478bd9Sstevel@tonic-gate ap->mems = dev->next;
917c478bd9Sstevel@tonic-gate ri_dev_free(dev);
927c478bd9Sstevel@tonic-gate }
937c478bd9Sstevel@tonic-gate while ((dev = ap->ios) != NULL) {
947c478bd9Sstevel@tonic-gate ap->ios = dev->next;
957c478bd9Sstevel@tonic-gate ri_dev_free(dev);
967c478bd9Sstevel@tonic-gate }
977c478bd9Sstevel@tonic-gate free(ap);
987c478bd9Sstevel@tonic-gate }
997c478bd9Sstevel@tonic-gate
1007c478bd9Sstevel@tonic-gate void
ri_dev_free(ri_dev_t * dev)1017c478bd9Sstevel@tonic-gate ri_dev_free(ri_dev_t *dev)
1027c478bd9Sstevel@tonic-gate {
1037c478bd9Sstevel@tonic-gate ri_client_t *client;
1047c478bd9Sstevel@tonic-gate
1057c478bd9Sstevel@tonic-gate assert(dev != NULL);
1067c478bd9Sstevel@tonic-gate
1077c478bd9Sstevel@tonic-gate nvlist_free(dev->conf_props);
1087c478bd9Sstevel@tonic-gate while ((client = dev->rcm_clients) != NULL) {
1097c478bd9Sstevel@tonic-gate dev->rcm_clients = client->next;
1107c478bd9Sstevel@tonic-gate ri_client_free(client);
1117c478bd9Sstevel@tonic-gate }
1127c478bd9Sstevel@tonic-gate free(dev);
1137c478bd9Sstevel@tonic-gate }
1147c478bd9Sstevel@tonic-gate
1157c478bd9Sstevel@tonic-gate void
ri_client_free(ri_client_t * client)1167c478bd9Sstevel@tonic-gate ri_client_free(ri_client_t *client)
1177c478bd9Sstevel@tonic-gate {
1187c478bd9Sstevel@tonic-gate assert(client != NULL);
1197c478bd9Sstevel@tonic-gate
1207c478bd9Sstevel@tonic-gate nvlist_free(client->usg_props);
1217c478bd9Sstevel@tonic-gate nvlist_free(client->v_props);
1227c478bd9Sstevel@tonic-gate free(client);
1237c478bd9Sstevel@tonic-gate }
1247c478bd9Sstevel@tonic-gate
1257c478bd9Sstevel@tonic-gate /*
1267c478bd9Sstevel@tonic-gate * Pack everything contained in the handle up inside out.
1277c478bd9Sstevel@tonic-gate */
1287c478bd9Sstevel@tonic-gate int
ri_pack(ri_hdl_t * hdl,caddr_t * bufp,size_t * sizep,int encoding)129*25cf1a30Sjl139090 ri_pack(ri_hdl_t *hdl, caddr_t *bufp, size_t *sizep, int encoding)
1307c478bd9Sstevel@tonic-gate {
1317c478bd9Sstevel@tonic-gate nvlist_t *nvl = NULL;
1327c478bd9Sstevel@tonic-gate char *buf = NULL;
1337c478bd9Sstevel@tonic-gate size_t size = 0;
1347c478bd9Sstevel@tonic-gate
1357c478bd9Sstevel@tonic-gate if (bufp == NULL || sizep == NULL)
1367c478bd9Sstevel@tonic-gate return (RI_INVAL);
1377c478bd9Sstevel@tonic-gate
1387c478bd9Sstevel@tonic-gate *sizep = 0;
1397c478bd9Sstevel@tonic-gate *bufp = NULL;
1407c478bd9Sstevel@tonic-gate
1417c478bd9Sstevel@tonic-gate /*
1427c478bd9Sstevel@tonic-gate * Check the handle. If it is NULL, there
1437c478bd9Sstevel@tonic-gate * is nothing to pack, so we are done.
1447c478bd9Sstevel@tonic-gate */
1457c478bd9Sstevel@tonic-gate if (hdl == NULL) {
1467c478bd9Sstevel@tonic-gate return (RI_SUCCESS);
1477c478bd9Sstevel@tonic-gate }
1487c478bd9Sstevel@tonic-gate
1497c478bd9Sstevel@tonic-gate if (nvlist_alloc(&nvl, NV_UNIQUE_NAME, 0) != 0) {
1507c478bd9Sstevel@tonic-gate dprintf((stderr, "nvlist_alloc fail\n", errno));
1517c478bd9Sstevel@tonic-gate goto fail;
1527c478bd9Sstevel@tonic-gate }
1537c478bd9Sstevel@tonic-gate
1547c478bd9Sstevel@tonic-gate if (nvlist_add_int32(nvl, RI_HDL_FLAGS, hdl->flags) != 0) {
1557c478bd9Sstevel@tonic-gate dprintf((stderr, "nvlist_add_int32 fail\n"));
1567c478bd9Sstevel@tonic-gate goto fail;
1577c478bd9Sstevel@tonic-gate }
1587c478bd9Sstevel@tonic-gate
159*25cf1a30Sjl139090 if (ap_list_pack(hdl->aps, &buf, &size, encoding) != 0 ||
1607c478bd9Sstevel@tonic-gate nvlist_add_byte_array(nvl, RI_HDL_APS, (uchar_t *)buf, size) != 0) {
1617c478bd9Sstevel@tonic-gate goto fail;
1627c478bd9Sstevel@tonic-gate }
1637c478bd9Sstevel@tonic-gate
1647c478bd9Sstevel@tonic-gate s_free(buf);
165*25cf1a30Sjl139090 if (client_list_pack(hdl->cpu_cap_clients, &buf, &size,
166*25cf1a30Sjl139090 encoding) != 0 ||
1677c478bd9Sstevel@tonic-gate nvlist_add_byte_array(nvl, RI_HDL_CPU_CAPS, (uchar_t *)buf,
1687c478bd9Sstevel@tonic-gate size) != 0) {
1697c478bd9Sstevel@tonic-gate goto fail;
1707c478bd9Sstevel@tonic-gate }
1717c478bd9Sstevel@tonic-gate
1727c478bd9Sstevel@tonic-gate s_free(buf);
173*25cf1a30Sjl139090 if (client_list_pack(hdl->mem_cap_clients, &buf, &size,
174*25cf1a30Sjl139090 encoding) != 0 ||
1757c478bd9Sstevel@tonic-gate nvlist_add_byte_array(nvl, RI_HDL_MEM_CAPS, (uchar_t *)buf,
1767c478bd9Sstevel@tonic-gate size) != 0) {
1777c478bd9Sstevel@tonic-gate goto fail;
1787c478bd9Sstevel@tonic-gate }
1797c478bd9Sstevel@tonic-gate
1807c478bd9Sstevel@tonic-gate s_free(buf);
181*25cf1a30Sjl139090 if (nvlist_pack(nvl, &buf, &size, encoding, 0) != 0) {
1827c478bd9Sstevel@tonic-gate dprintf((stderr, "nvlist_pack fail\n"));
1837c478bd9Sstevel@tonic-gate goto fail;
1847c478bd9Sstevel@tonic-gate }
1857c478bd9Sstevel@tonic-gate
1867c478bd9Sstevel@tonic-gate nvlist_free(nvl);
1877c478bd9Sstevel@tonic-gate *bufp = buf;
1887c478bd9Sstevel@tonic-gate *sizep = size;
1897c478bd9Sstevel@tonic-gate
1907c478bd9Sstevel@tonic-gate return (RI_SUCCESS);
1917c478bd9Sstevel@tonic-gate
1927c478bd9Sstevel@tonic-gate fail:
1937c478bd9Sstevel@tonic-gate s_free(buf);
1947c478bd9Sstevel@tonic-gate nvlist_free(nvl);
1957c478bd9Sstevel@tonic-gate
1967c478bd9Sstevel@tonic-gate return (RI_FAILURE);
1977c478bd9Sstevel@tonic-gate }
1987c478bd9Sstevel@tonic-gate
1997c478bd9Sstevel@tonic-gate /*
2007c478bd9Sstevel@tonic-gate * Pack a list of attachment point handles.
2017c478bd9Sstevel@tonic-gate */
2027c478bd9Sstevel@tonic-gate static int
ap_list_pack(ri_ap_t * aplist,char ** bufp,size_t * sizep,int encoding)203*25cf1a30Sjl139090 ap_list_pack(ri_ap_t *aplist, char **bufp, size_t *sizep, int encoding)
2047c478bd9Sstevel@tonic-gate {
2057c478bd9Sstevel@tonic-gate nvlist_t *nvl = NULL;
2067c478bd9Sstevel@tonic-gate char *buf = NULL;
2077c478bd9Sstevel@tonic-gate size_t size;
2087c478bd9Sstevel@tonic-gate
2097c478bd9Sstevel@tonic-gate assert(bufp != NULL && sizep != NULL);
2107c478bd9Sstevel@tonic-gate
2117c478bd9Sstevel@tonic-gate *sizep = 0;
2127c478bd9Sstevel@tonic-gate *bufp = NULL;
2137c478bd9Sstevel@tonic-gate
2147c478bd9Sstevel@tonic-gate if (nvlist_alloc(&nvl, 0, 0) != 0) {
2157c478bd9Sstevel@tonic-gate dprintf((stderr, "nvlist_alloc fail\n"));
2167c478bd9Sstevel@tonic-gate return (-1);
2177c478bd9Sstevel@tonic-gate }
2187c478bd9Sstevel@tonic-gate
2197c478bd9Sstevel@tonic-gate while (aplist != NULL) {
2207c478bd9Sstevel@tonic-gate s_free(buf);
221*25cf1a30Sjl139090 if (ap_pack(aplist, &buf, &size, encoding) != 0)
2227c478bd9Sstevel@tonic-gate goto fail;
2237c478bd9Sstevel@tonic-gate
2247c478bd9Sstevel@tonic-gate if (nvlist_add_byte_array(nvl, RI_AP_T, (uchar_t *)buf,
2257c478bd9Sstevel@tonic-gate size) != 0) {
2267c478bd9Sstevel@tonic-gate dprintf((stderr, "nvlist_add_byte_array fail "
2277c478bd9Sstevel@tonic-gate "(%s)\n", RI_AP_T));
2287c478bd9Sstevel@tonic-gate goto fail;
2297c478bd9Sstevel@tonic-gate }
2307c478bd9Sstevel@tonic-gate aplist = aplist->next;
2317c478bd9Sstevel@tonic-gate }
2327c478bd9Sstevel@tonic-gate
2337c478bd9Sstevel@tonic-gate s_free(buf);
234*25cf1a30Sjl139090 if (nvlist_pack(nvl, &buf, &size, encoding, 0) != 0) {
2357c478bd9Sstevel@tonic-gate dprintf((stderr, "nvlist_pack fail\n"));
2367c478bd9Sstevel@tonic-gate goto fail;
2377c478bd9Sstevel@tonic-gate }
2387c478bd9Sstevel@tonic-gate
2397c478bd9Sstevel@tonic-gate nvlist_free(nvl);
2407c478bd9Sstevel@tonic-gate *bufp = buf;
2417c478bd9Sstevel@tonic-gate *sizep = size;
2427c478bd9Sstevel@tonic-gate
2437c478bd9Sstevel@tonic-gate return (0);
2447c478bd9Sstevel@tonic-gate
2457c478bd9Sstevel@tonic-gate fail:
2467c478bd9Sstevel@tonic-gate s_free(buf);
2477c478bd9Sstevel@tonic-gate nvlist_free(nvl);
2487c478bd9Sstevel@tonic-gate
2497c478bd9Sstevel@tonic-gate return (-1);
2507c478bd9Sstevel@tonic-gate }
2517c478bd9Sstevel@tonic-gate
2527c478bd9Sstevel@tonic-gate /*
2537c478bd9Sstevel@tonic-gate * Pack a list of ri_dev_t's.
2547c478bd9Sstevel@tonic-gate */
2557c478bd9Sstevel@tonic-gate static int
dev_list_pack(ri_dev_t * devlist,char ** bufp,size_t * sizep,int encoding)256*25cf1a30Sjl139090 dev_list_pack(ri_dev_t *devlist, char **bufp, size_t *sizep, int encoding)
2577c478bd9Sstevel@tonic-gate {
2587c478bd9Sstevel@tonic-gate nvlist_t *nvl = NULL;
2597c478bd9Sstevel@tonic-gate char *buf = NULL;
2607c478bd9Sstevel@tonic-gate size_t size = 0;
2617c478bd9Sstevel@tonic-gate
2627c478bd9Sstevel@tonic-gate assert(bufp != NULL && sizep != NULL);
2637c478bd9Sstevel@tonic-gate
2647c478bd9Sstevel@tonic-gate *sizep = 0;
2657c478bd9Sstevel@tonic-gate *bufp = NULL;
2667c478bd9Sstevel@tonic-gate
2677c478bd9Sstevel@tonic-gate if (nvlist_alloc(&nvl, 0, 0) != 0) {
2687c478bd9Sstevel@tonic-gate dprintf((stderr, "nvlist_alloc fail\n"));
2697c478bd9Sstevel@tonic-gate return (-1);
2707c478bd9Sstevel@tonic-gate }
2717c478bd9Sstevel@tonic-gate
2727c478bd9Sstevel@tonic-gate while (devlist != NULL) {
2737c478bd9Sstevel@tonic-gate s_free(buf);
274*25cf1a30Sjl139090 if (dev_pack(devlist, &buf, &size, encoding) != 0)
2757c478bd9Sstevel@tonic-gate goto fail;
2767c478bd9Sstevel@tonic-gate
2777c478bd9Sstevel@tonic-gate if (nvlist_add_byte_array(nvl, RI_DEV_T, (uchar_t *)buf,
2787c478bd9Sstevel@tonic-gate size) != 0) {
2797c478bd9Sstevel@tonic-gate dprintf((stderr, "nvlist_add_byte_array fail "
2807c478bd9Sstevel@tonic-gate "(%s)\n", RI_DEV_T));
2817c478bd9Sstevel@tonic-gate goto fail;
2827c478bd9Sstevel@tonic-gate }
2837c478bd9Sstevel@tonic-gate devlist = devlist->next;
2847c478bd9Sstevel@tonic-gate }
2857c478bd9Sstevel@tonic-gate
2867c478bd9Sstevel@tonic-gate s_free(buf);
287*25cf1a30Sjl139090 if (nvlist_pack(nvl, &buf, &size, encoding, 0) != 0) {
2887c478bd9Sstevel@tonic-gate dprintf((stderr, "nvlist_pack fail\n"));
2897c478bd9Sstevel@tonic-gate goto fail;
2907c478bd9Sstevel@tonic-gate }
2917c478bd9Sstevel@tonic-gate
2927c478bd9Sstevel@tonic-gate nvlist_free(nvl);
2937c478bd9Sstevel@tonic-gate *bufp = buf;
2947c478bd9Sstevel@tonic-gate *sizep = size;
2957c478bd9Sstevel@tonic-gate
2967c478bd9Sstevel@tonic-gate return (0);
2977c478bd9Sstevel@tonic-gate
2987c478bd9Sstevel@tonic-gate fail:
2997c478bd9Sstevel@tonic-gate s_free(buf);
3007c478bd9Sstevel@tonic-gate nvlist_free(nvl);
3017c478bd9Sstevel@tonic-gate
3027c478bd9Sstevel@tonic-gate return (-1);
3037c478bd9Sstevel@tonic-gate }
3047c478bd9Sstevel@tonic-gate
3057c478bd9Sstevel@tonic-gate /*
3067c478bd9Sstevel@tonic-gate * Pack a list of ri_client_t's.
3077c478bd9Sstevel@tonic-gate */
3087c478bd9Sstevel@tonic-gate static int
client_list_pack(ri_client_t * client_list,char ** bufp,size_t * sizep,int encoding)309*25cf1a30Sjl139090 client_list_pack(ri_client_t *client_list, char **bufp, size_t *sizep,
310*25cf1a30Sjl139090 int encoding)
3117c478bd9Sstevel@tonic-gate {
3127c478bd9Sstevel@tonic-gate nvlist_t *nvl = NULL;
3137c478bd9Sstevel@tonic-gate char *buf = NULL;
3147c478bd9Sstevel@tonic-gate size_t size = 0;
3157c478bd9Sstevel@tonic-gate
3167c478bd9Sstevel@tonic-gate assert(bufp != NULL && sizep != NULL);
3177c478bd9Sstevel@tonic-gate
3187c478bd9Sstevel@tonic-gate *sizep = 0;
3197c478bd9Sstevel@tonic-gate *bufp = NULL;
3207c478bd9Sstevel@tonic-gate
3217c478bd9Sstevel@tonic-gate if (nvlist_alloc(&nvl, 0, 0) != 0) {
3227c478bd9Sstevel@tonic-gate dprintf((stderr, "nvlist_alloc fail\n"));
3237c478bd9Sstevel@tonic-gate return (-1);
3247c478bd9Sstevel@tonic-gate }
3257c478bd9Sstevel@tonic-gate
3267c478bd9Sstevel@tonic-gate while (client_list != NULL) {
3277c478bd9Sstevel@tonic-gate s_free(buf);
328*25cf1a30Sjl139090 if (client_pack(client_list, &buf, &size, encoding) != 0)
3297c478bd9Sstevel@tonic-gate goto fail;
3307c478bd9Sstevel@tonic-gate
3317c478bd9Sstevel@tonic-gate if (nvlist_add_byte_array(nvl, RI_CLIENT_T, (uchar_t *)buf,
3327c478bd9Sstevel@tonic-gate size) != 0) {
3337c478bd9Sstevel@tonic-gate dprintf((stderr, "nvlist_add_byte_array fail "
3347c478bd9Sstevel@tonic-gate "(%s)\n", RI_CLIENT_T));
3357c478bd9Sstevel@tonic-gate goto fail;
3367c478bd9Sstevel@tonic-gate }
3377c478bd9Sstevel@tonic-gate client_list = client_list->next;
3387c478bd9Sstevel@tonic-gate }
3397c478bd9Sstevel@tonic-gate
3407c478bd9Sstevel@tonic-gate s_free(buf);
341*25cf1a30Sjl139090 if (nvlist_pack(nvl, &buf, &size, encoding, 0) != 0) {
3427c478bd9Sstevel@tonic-gate dprintf((stderr, "nvlist_pack fail\n"));
3437c478bd9Sstevel@tonic-gate goto fail;
3447c478bd9Sstevel@tonic-gate }
3457c478bd9Sstevel@tonic-gate
3467c478bd9Sstevel@tonic-gate nvlist_free(nvl);
3477c478bd9Sstevel@tonic-gate *bufp = buf;
3487c478bd9Sstevel@tonic-gate *sizep = size;
3497c478bd9Sstevel@tonic-gate
3507c478bd9Sstevel@tonic-gate return (0);
3517c478bd9Sstevel@tonic-gate
3527c478bd9Sstevel@tonic-gate fail:
3537c478bd9Sstevel@tonic-gate s_free(buf);
3547c478bd9Sstevel@tonic-gate nvlist_free(nvl);
3557c478bd9Sstevel@tonic-gate
3567c478bd9Sstevel@tonic-gate return (-1);
3577c478bd9Sstevel@tonic-gate }
3587c478bd9Sstevel@tonic-gate
3597c478bd9Sstevel@tonic-gate static int
ap_pack(ri_ap_t * ap,char ** bufp,size_t * sizep,int encoding)360*25cf1a30Sjl139090 ap_pack(ri_ap_t *ap, char **bufp, size_t *sizep, int encoding)
3617c478bd9Sstevel@tonic-gate {
3627c478bd9Sstevel@tonic-gate nvlist_t *nvl = NULL;
3637c478bd9Sstevel@tonic-gate char *buf = NULL;
3647c478bd9Sstevel@tonic-gate size_t size = 0;
3657c478bd9Sstevel@tonic-gate
3667c478bd9Sstevel@tonic-gate if (nvlist_alloc(&nvl, NV_UNIQUE_NAME, 0) != 0) {
3677c478bd9Sstevel@tonic-gate dprintf((stderr, "nvlist_alloc fail\n"));
3687c478bd9Sstevel@tonic-gate return (-1);
3697c478bd9Sstevel@tonic-gate }
3707c478bd9Sstevel@tonic-gate
371*25cf1a30Sjl139090 if (pack_add_byte_array(ap->conf_props, RI_AP_PROPS, nvl,
372*25cf1a30Sjl139090 encoding) != 0)
3737c478bd9Sstevel@tonic-gate goto fail;
3747c478bd9Sstevel@tonic-gate
375*25cf1a30Sjl139090 if (dev_list_pack(ap->cpus, &buf, &size, encoding) != 0)
3767c478bd9Sstevel@tonic-gate goto fail;
3777c478bd9Sstevel@tonic-gate
3787c478bd9Sstevel@tonic-gate if (nvlist_add_byte_array(nvl, RI_AP_CPUS, (uchar_t *)buf,
3797c478bd9Sstevel@tonic-gate size) != 0) {
3807c478bd9Sstevel@tonic-gate dprintf((stderr, "nvlist_add_byte_array (%s)\n", RI_AP_CPUS));
3817c478bd9Sstevel@tonic-gate goto fail;
3827c478bd9Sstevel@tonic-gate }
3837c478bd9Sstevel@tonic-gate
3847c478bd9Sstevel@tonic-gate s_free(buf);
385*25cf1a30Sjl139090 if (dev_list_pack(ap->mems, &buf, &size, encoding) != 0)
3867c478bd9Sstevel@tonic-gate goto fail;
3877c478bd9Sstevel@tonic-gate
3887c478bd9Sstevel@tonic-gate if (nvlist_add_byte_array(nvl, RI_AP_MEMS, (uchar_t *)buf,
3897c478bd9Sstevel@tonic-gate size) != 0) {
3907c478bd9Sstevel@tonic-gate dprintf((stderr, "nvlist_add_byte_array (%s)n", RI_AP_MEMS));
3917c478bd9Sstevel@tonic-gate goto fail;
3927c478bd9Sstevel@tonic-gate }
3937c478bd9Sstevel@tonic-gate
3947c478bd9Sstevel@tonic-gate s_free(buf);
395*25cf1a30Sjl139090 if (dev_list_pack(ap->ios, &buf, &size, encoding) != 0)
3967c478bd9Sstevel@tonic-gate goto fail;
3977c478bd9Sstevel@tonic-gate
3987c478bd9Sstevel@tonic-gate if (nvlist_add_byte_array(nvl, RI_AP_IOS, (uchar_t *)buf,
3997c478bd9Sstevel@tonic-gate size) != 0) {
4007c478bd9Sstevel@tonic-gate dprintf((stderr, "nvlist_add_byte_array (%s)n", RI_AP_IOS));
4017c478bd9Sstevel@tonic-gate goto fail;
4027c478bd9Sstevel@tonic-gate }
4037c478bd9Sstevel@tonic-gate
4047c478bd9Sstevel@tonic-gate s_free(buf);
405*25cf1a30Sjl139090 if (nvlist_pack(nvl, &buf, &size, encoding, 0) != 0) {
4067c478bd9Sstevel@tonic-gate dprintf((stderr, "nvlist_pack fail\n"));
4077c478bd9Sstevel@tonic-gate goto fail;
4087c478bd9Sstevel@tonic-gate }
4097c478bd9Sstevel@tonic-gate
4107c478bd9Sstevel@tonic-gate nvlist_free(nvl);
4117c478bd9Sstevel@tonic-gate *bufp = buf;
4127c478bd9Sstevel@tonic-gate *sizep = size;
4137c478bd9Sstevel@tonic-gate
4147c478bd9Sstevel@tonic-gate return (0);
4157c478bd9Sstevel@tonic-gate
4167c478bd9Sstevel@tonic-gate fail:
4177c478bd9Sstevel@tonic-gate s_free(buf);
4187c478bd9Sstevel@tonic-gate nvlist_free(nvl);
4197c478bd9Sstevel@tonic-gate
4207c478bd9Sstevel@tonic-gate return (-1);
4217c478bd9Sstevel@tonic-gate }
4227c478bd9Sstevel@tonic-gate
4237c478bd9Sstevel@tonic-gate static int
dev_pack(ri_dev_t * dev,char ** bufp,size_t * sizep,int encoding)424*25cf1a30Sjl139090 dev_pack(ri_dev_t *dev, char **bufp, size_t *sizep, int encoding)
4257c478bd9Sstevel@tonic-gate {
4267c478bd9Sstevel@tonic-gate nvlist_t *nvl = NULL;
4277c478bd9Sstevel@tonic-gate char *buf = NULL;
4287c478bd9Sstevel@tonic-gate size_t size = 0;
4297c478bd9Sstevel@tonic-gate
4307c478bd9Sstevel@tonic-gate if (nvlist_alloc(&nvl, NV_UNIQUE_NAME, 0) != 0) {
4317c478bd9Sstevel@tonic-gate dprintf((stderr, "nvlist_alloc fail\n"));
4327c478bd9Sstevel@tonic-gate return (-1);
4337c478bd9Sstevel@tonic-gate }
4347c478bd9Sstevel@tonic-gate
435*25cf1a30Sjl139090 if (pack_add_byte_array(dev->conf_props, RI_DEV_PROPS, nvl,
436*25cf1a30Sjl139090 encoding) != 0)
4377c478bd9Sstevel@tonic-gate goto fail;
4387c478bd9Sstevel@tonic-gate
439*25cf1a30Sjl139090 if (client_list_pack(dev->rcm_clients, &buf, &size, encoding) != 0)
4407c478bd9Sstevel@tonic-gate goto fail;
4417c478bd9Sstevel@tonic-gate
4427c478bd9Sstevel@tonic-gate if (nvlist_add_byte_array(nvl, RI_DEV_CLIENTS, (uchar_t *)buf,
4437c478bd9Sstevel@tonic-gate size) != 0) {
4447c478bd9Sstevel@tonic-gate dprintf((stderr, "nvlist_add_byte_array (%s)n",
4457c478bd9Sstevel@tonic-gate RI_DEV_CLIENTS));
4467c478bd9Sstevel@tonic-gate goto fail;
4477c478bd9Sstevel@tonic-gate }
4487c478bd9Sstevel@tonic-gate
4497c478bd9Sstevel@tonic-gate s_free(buf);
450*25cf1a30Sjl139090 if (nvlist_pack(nvl, &buf, &size, encoding, 0) != 0) {
4517c478bd9Sstevel@tonic-gate dprintf((stderr, "nvlist_pack fail\n"));
4527c478bd9Sstevel@tonic-gate goto fail;
4537c478bd9Sstevel@tonic-gate }
4547c478bd9Sstevel@tonic-gate
4557c478bd9Sstevel@tonic-gate nvlist_free(nvl);
4567c478bd9Sstevel@tonic-gate *bufp = buf;
4577c478bd9Sstevel@tonic-gate *sizep = size;
4587c478bd9Sstevel@tonic-gate
4597c478bd9Sstevel@tonic-gate return (0);
4607c478bd9Sstevel@tonic-gate
4617c478bd9Sstevel@tonic-gate fail:
4627c478bd9Sstevel@tonic-gate s_free(buf);
4637c478bd9Sstevel@tonic-gate nvlist_free(nvl);
4647c478bd9Sstevel@tonic-gate
4657c478bd9Sstevel@tonic-gate return (-1);
4667c478bd9Sstevel@tonic-gate }
4677c478bd9Sstevel@tonic-gate
4687c478bd9Sstevel@tonic-gate static int
client_pack(ri_client_t * client,char ** bufp,size_t * sizep,int encoding)469*25cf1a30Sjl139090 client_pack(ri_client_t *client, char **bufp, size_t *sizep, int encoding)
4707c478bd9Sstevel@tonic-gate {
4717c478bd9Sstevel@tonic-gate nvlist_t *nvl = NULL;
4727c478bd9Sstevel@tonic-gate char *buf = NULL;
4737c478bd9Sstevel@tonic-gate size_t size = 0;
4747c478bd9Sstevel@tonic-gate
4757c478bd9Sstevel@tonic-gate if (nvlist_alloc(&nvl, NV_UNIQUE_NAME, 0) != 0) {
4767c478bd9Sstevel@tonic-gate dprintf((stderr, "nvlist_alloc fail\n"));
4777c478bd9Sstevel@tonic-gate return (-1);
4787c478bd9Sstevel@tonic-gate }
4797c478bd9Sstevel@tonic-gate
4807c478bd9Sstevel@tonic-gate if (pack_add_byte_array(client->usg_props, RI_CLIENT_USAGE_PROPS,
481*25cf1a30Sjl139090 nvl, encoding) != 0) {
4827c478bd9Sstevel@tonic-gate goto fail;
4837c478bd9Sstevel@tonic-gate }
4847c478bd9Sstevel@tonic-gate
4857c478bd9Sstevel@tonic-gate /*
4867c478bd9Sstevel@tonic-gate * This will only be present if RI_VERBOSE was specified
4877c478bd9Sstevel@tonic-gate * in the call to ri_init.
4887c478bd9Sstevel@tonic-gate */
4897c478bd9Sstevel@tonic-gate if (client->v_props != NULL && pack_add_byte_array(client->v_props,
490*25cf1a30Sjl139090 RI_CLIENT_VERB_PROPS, nvl, encoding) != 0) {
4917c478bd9Sstevel@tonic-gate goto fail;
4927c478bd9Sstevel@tonic-gate }
4937c478bd9Sstevel@tonic-gate
494*25cf1a30Sjl139090 if (nvlist_pack(nvl, &buf, &size, encoding, 0) != 0) {
4957c478bd9Sstevel@tonic-gate dprintf((stderr, "nvlist_pack fail\n"));
4967c478bd9Sstevel@tonic-gate goto fail;
4977c478bd9Sstevel@tonic-gate }
4987c478bd9Sstevel@tonic-gate
4997c478bd9Sstevel@tonic-gate nvlist_free(nvl);
5007c478bd9Sstevel@tonic-gate *bufp = buf;
5017c478bd9Sstevel@tonic-gate *sizep = size;
5027c478bd9Sstevel@tonic-gate
5037c478bd9Sstevel@tonic-gate return (0);
5047c478bd9Sstevel@tonic-gate
5057c478bd9Sstevel@tonic-gate fail:
5067c478bd9Sstevel@tonic-gate s_free(buf);
5077c478bd9Sstevel@tonic-gate nvlist_free(nvl);
5087c478bd9Sstevel@tonic-gate
5097c478bd9Sstevel@tonic-gate return (-1);
5107c478bd9Sstevel@tonic-gate }
5117c478bd9Sstevel@tonic-gate
5127c478bd9Sstevel@tonic-gate /*
5137c478bd9Sstevel@tonic-gate * Pack nvlist_t and add as byte array to another nvlist_t.
5147c478bd9Sstevel@tonic-gate */
5157c478bd9Sstevel@tonic-gate static int
pack_add_byte_array(nvlist_t * nvl_packme,char * name,nvlist_t * nvl,int encoding)516*25cf1a30Sjl139090 pack_add_byte_array(nvlist_t *nvl_packme, char *name, nvlist_t *nvl,
517*25cf1a30Sjl139090 int encoding)
5187c478bd9Sstevel@tonic-gate {
5197c478bd9Sstevel@tonic-gate char *buf = NULL;
5207c478bd9Sstevel@tonic-gate size_t size = 0;
5217c478bd9Sstevel@tonic-gate
522*25cf1a30Sjl139090 if (nvlist_pack(nvl_packme, &buf, &size, encoding, 0) != 0) {
5237c478bd9Sstevel@tonic-gate dprintf((stderr, "nvlist_pack fail (%s)\n", name));
5247c478bd9Sstevel@tonic-gate s_free(buf);
5257c478bd9Sstevel@tonic-gate return (-1);
5267c478bd9Sstevel@tonic-gate }
5277c478bd9Sstevel@tonic-gate
5287c478bd9Sstevel@tonic-gate if (nvlist_add_byte_array(nvl, name, (uchar_t *)buf, size) != 0) {
5297c478bd9Sstevel@tonic-gate dprintf((stderr, "nvlist_add_byte_array fail (%s)\n", name));
5307c478bd9Sstevel@tonic-gate return (-1);
5317c478bd9Sstevel@tonic-gate }
5327c478bd9Sstevel@tonic-gate
5337c478bd9Sstevel@tonic-gate s_free(buf);
5347c478bd9Sstevel@tonic-gate return (0);
5357c478bd9Sstevel@tonic-gate }
5367c478bd9Sstevel@tonic-gate
5377c478bd9Sstevel@tonic-gate /*
5387c478bd9Sstevel@tonic-gate * Unpack buf into ri_hdl_t.
5397c478bd9Sstevel@tonic-gate */
5407c478bd9Sstevel@tonic-gate int
ri_unpack(caddr_t buf,size_t size,ri_hdl_t ** hdlp)5417c478bd9Sstevel@tonic-gate ri_unpack(caddr_t buf, size_t size, ri_hdl_t **hdlp)
5427c478bd9Sstevel@tonic-gate {
5437c478bd9Sstevel@tonic-gate ri_hdl_t *ri_hdl = NULL;
5447c478bd9Sstevel@tonic-gate nvlist_t *nvl = NULL;
5457c478bd9Sstevel@tonic-gate
5467c478bd9Sstevel@tonic-gate if (hdlp == NULL)
5477c478bd9Sstevel@tonic-gate return (RI_INVAL);
5487c478bd9Sstevel@tonic-gate
5497c478bd9Sstevel@tonic-gate *hdlp = NULL;
5507c478bd9Sstevel@tonic-gate if ((ri_hdl = calloc(1, sizeof (*ri_hdl))) == NULL) {
5517c478bd9Sstevel@tonic-gate dprintf((stderr, "calloc: %s\n", strerror(errno)));
5527c478bd9Sstevel@tonic-gate return (RI_FAILURE);
5537c478bd9Sstevel@tonic-gate }
5547c478bd9Sstevel@tonic-gate
5557c478bd9Sstevel@tonic-gate if (nvlist_unpack(buf, size, &nvl, 0) != 0) {
5567c478bd9Sstevel@tonic-gate dprintf((stderr, "nvlist_unpack fail\n"));
5577c478bd9Sstevel@tonic-gate goto fail;
5587c478bd9Sstevel@tonic-gate }
5597c478bd9Sstevel@tonic-gate
5607c478bd9Sstevel@tonic-gate if (nvlist_lookup_int32(nvl, RI_HDL_FLAGS, &ri_hdl->flags) != 0) {
5617c478bd9Sstevel@tonic-gate dprintf((stderr, "nvlist_lookup_int32 fail (%s)\n",
5627c478bd9Sstevel@tonic-gate RI_HDL_FLAGS));
5637c478bd9Sstevel@tonic-gate goto fail;
5647c478bd9Sstevel@tonic-gate }
5657c478bd9Sstevel@tonic-gate
5667c478bd9Sstevel@tonic-gate buf = NULL;
5677c478bd9Sstevel@tonic-gate size = 0;
5687c478bd9Sstevel@tonic-gate if (nvlist_lookup_byte_array(nvl, RI_HDL_APS, (uchar_t **)&buf,
5697c478bd9Sstevel@tonic-gate (uint_t *)&size) != 0) {
5707c478bd9Sstevel@tonic-gate dprintf((stderr, "nvlist_lookup_int32 fail (%s)\n",
5717c478bd9Sstevel@tonic-gate RI_HDL_APS));
5727c478bd9Sstevel@tonic-gate goto fail;
5737c478bd9Sstevel@tonic-gate }
5747c478bd9Sstevel@tonic-gate
5757c478bd9Sstevel@tonic-gate if (ap_list_unpack(buf, size, &ri_hdl->aps) != 0)
5767c478bd9Sstevel@tonic-gate goto fail;
5777c478bd9Sstevel@tonic-gate
5787c478bd9Sstevel@tonic-gate buf = NULL;
5797c478bd9Sstevel@tonic-gate size = 0;
5807c478bd9Sstevel@tonic-gate if (nvlist_lookup_byte_array(nvl, RI_HDL_CPU_CAPS, (uchar_t **)&buf,
5817c478bd9Sstevel@tonic-gate (uint_t *)&size) != 0) {
5827c478bd9Sstevel@tonic-gate dprintf((stderr, "nvlist_lookup_byte_array fail (%s)\n",
5837c478bd9Sstevel@tonic-gate RI_HDL_CPU_CAPS));
5847c478bd9Sstevel@tonic-gate goto fail;
5857c478bd9Sstevel@tonic-gate }
5867c478bd9Sstevel@tonic-gate
5877c478bd9Sstevel@tonic-gate if (client_list_unpack(buf, size, &ri_hdl->cpu_cap_clients) != 0)
5887c478bd9Sstevel@tonic-gate goto fail;
5897c478bd9Sstevel@tonic-gate
5907c478bd9Sstevel@tonic-gate buf = NULL;
5917c478bd9Sstevel@tonic-gate size = 0;
5927c478bd9Sstevel@tonic-gate if (nvlist_lookup_byte_array(nvl, RI_HDL_MEM_CAPS, (uchar_t **)&buf,
5937c478bd9Sstevel@tonic-gate (uint_t *)&size) != 0) {
5947c478bd9Sstevel@tonic-gate dprintf((stderr, "nvlist_lookup_byte_array fail (%s)\n",
5957c478bd9Sstevel@tonic-gate RI_HDL_MEM_CAPS));
5967c478bd9Sstevel@tonic-gate goto fail;
5977c478bd9Sstevel@tonic-gate }
5987c478bd9Sstevel@tonic-gate
5997c478bd9Sstevel@tonic-gate if (client_list_unpack(buf, size, &ri_hdl->mem_cap_clients) != 0)
6007c478bd9Sstevel@tonic-gate goto fail;
6017c478bd9Sstevel@tonic-gate
6027c478bd9Sstevel@tonic-gate *hdlp = ri_hdl;
6037c478bd9Sstevel@tonic-gate
6047c478bd9Sstevel@tonic-gate return (0);
6057c478bd9Sstevel@tonic-gate
6067c478bd9Sstevel@tonic-gate fail:
6077c478bd9Sstevel@tonic-gate free(ri_hdl);
6087c478bd9Sstevel@tonic-gate nvlist_free(nvl);
6097c478bd9Sstevel@tonic-gate
6107c478bd9Sstevel@tonic-gate return (-1);
6117c478bd9Sstevel@tonic-gate }
6127c478bd9Sstevel@tonic-gate
6137c478bd9Sstevel@tonic-gate static int
ap_list_unpack(char * buf,size_t size,ri_ap_t ** aps)6147c478bd9Sstevel@tonic-gate ap_list_unpack(char *buf, size_t size, ri_ap_t **aps)
6157c478bd9Sstevel@tonic-gate {
6167c478bd9Sstevel@tonic-gate nvpair_t *nvp = NULL;
6177c478bd9Sstevel@tonic-gate nvlist_t *nvl;
6187c478bd9Sstevel@tonic-gate ri_ap_t *aplist = NULL;
6197c478bd9Sstevel@tonic-gate ri_ap_t *prev = NULL;
6207c478bd9Sstevel@tonic-gate ri_ap_t *tmp = NULL;
6217c478bd9Sstevel@tonic-gate
6227c478bd9Sstevel@tonic-gate if (nvlist_unpack(buf, size, &nvl, 0) != 0) {
6237c478bd9Sstevel@tonic-gate dprintf((stderr, "nvlist_unpack fail\n"));
6247c478bd9Sstevel@tonic-gate return (-1);
6257c478bd9Sstevel@tonic-gate }
6267c478bd9Sstevel@tonic-gate
6277c478bd9Sstevel@tonic-gate while ((nvp = nvlist_next_nvpair(nvl, nvp)) != NULL) {
6287c478bd9Sstevel@tonic-gate assert(strcmp(nvpair_name(nvp), RI_AP_T) == 0 &&
6297c478bd9Sstevel@tonic-gate nvpair_type(nvp) == DATA_TYPE_BYTE_ARRAY);
6307c478bd9Sstevel@tonic-gate
6317c478bd9Sstevel@tonic-gate if ((tmp = calloc(1, sizeof (*tmp))) == NULL) {
6327c478bd9Sstevel@tonic-gate dprintf((stderr, "calloc: %s\n", strerror(errno)));
6337c478bd9Sstevel@tonic-gate goto fail;
6347c478bd9Sstevel@tonic-gate }
6357c478bd9Sstevel@tonic-gate
6367c478bd9Sstevel@tonic-gate buf = NULL;
6377c478bd9Sstevel@tonic-gate size = 0;
6387c478bd9Sstevel@tonic-gate if (nvpair_value_byte_array(nvp, (uchar_t **)&buf,
6397c478bd9Sstevel@tonic-gate (uint_t *)&size) != 0) {
6407c478bd9Sstevel@tonic-gate dprintf((stderr, "nvpair_value_byte_array fail\n"));
6417c478bd9Sstevel@tonic-gate goto fail;
6427c478bd9Sstevel@tonic-gate }
6437c478bd9Sstevel@tonic-gate
6447c478bd9Sstevel@tonic-gate if (ap_unpack(buf, size, tmp) != 0)
6457c478bd9Sstevel@tonic-gate goto fail;
6467c478bd9Sstevel@tonic-gate
6477c478bd9Sstevel@tonic-gate if (aplist == NULL) {
6487c478bd9Sstevel@tonic-gate prev = aplist = tmp;
6497c478bd9Sstevel@tonic-gate } else {
6507c478bd9Sstevel@tonic-gate prev->next = tmp;
6517c478bd9Sstevel@tonic-gate prev = tmp;
6527c478bd9Sstevel@tonic-gate }
6537c478bd9Sstevel@tonic-gate }
6547c478bd9Sstevel@tonic-gate
6557c478bd9Sstevel@tonic-gate nvlist_free(nvl);
6567c478bd9Sstevel@tonic-gate *aps = aplist;
6577c478bd9Sstevel@tonic-gate
6587c478bd9Sstevel@tonic-gate return (0);
6597c478bd9Sstevel@tonic-gate
6607c478bd9Sstevel@tonic-gate fail:
6617c478bd9Sstevel@tonic-gate nvlist_free(nvl);
6627c478bd9Sstevel@tonic-gate if (aplist != NULL) {
6637c478bd9Sstevel@tonic-gate while ((tmp = aplist) != NULL) {
6647c478bd9Sstevel@tonic-gate aplist = aplist->next;
6657c478bd9Sstevel@tonic-gate ri_ap_free(tmp);
6667c478bd9Sstevel@tonic-gate }
6677c478bd9Sstevel@tonic-gate }
6687c478bd9Sstevel@tonic-gate
6697c478bd9Sstevel@tonic-gate return (-1);
6707c478bd9Sstevel@tonic-gate }
6717c478bd9Sstevel@tonic-gate
6727c478bd9Sstevel@tonic-gate static int
dev_list_unpack(char * buf,size_t size,ri_dev_t ** devs)6737c478bd9Sstevel@tonic-gate dev_list_unpack(char *buf, size_t size, ri_dev_t **devs)
6747c478bd9Sstevel@tonic-gate {
6757c478bd9Sstevel@tonic-gate nvpair_t *nvp = NULL;
6767c478bd9Sstevel@tonic-gate nvlist_t *nvl;
6777c478bd9Sstevel@tonic-gate ri_dev_t *devlist = NULL;
6787c478bd9Sstevel@tonic-gate ri_dev_t *prev = NULL;
6797c478bd9Sstevel@tonic-gate ri_dev_t *tmp = NULL;
6807c478bd9Sstevel@tonic-gate
6817c478bd9Sstevel@tonic-gate if (nvlist_unpack(buf, size, &nvl, 0) != 0) {
6827c478bd9Sstevel@tonic-gate dprintf((stderr, "nvlist_unpack fail\n"));
6837c478bd9Sstevel@tonic-gate return (-1);
6847c478bd9Sstevel@tonic-gate }
6857c478bd9Sstevel@tonic-gate
6867c478bd9Sstevel@tonic-gate while ((nvp = nvlist_next_nvpair(nvl, nvp)) != NULL) {
6877c478bd9Sstevel@tonic-gate assert(strcmp(nvpair_name(nvp), RI_DEV_T) == 0 &&
6887c478bd9Sstevel@tonic-gate nvpair_type(nvp) == DATA_TYPE_BYTE_ARRAY);
6897c478bd9Sstevel@tonic-gate
6907c478bd9Sstevel@tonic-gate if ((tmp = calloc(1, sizeof (*tmp))) == NULL) {
6917c478bd9Sstevel@tonic-gate dprintf((stderr, "calloc: %s\n", strerror(errno)));
6927c478bd9Sstevel@tonic-gate goto fail;
6937c478bd9Sstevel@tonic-gate }
6947c478bd9Sstevel@tonic-gate
6957c478bd9Sstevel@tonic-gate if (nvpair_value_byte_array(nvp, (uchar_t **)&buf,
6967c478bd9Sstevel@tonic-gate (uint_t *)&size) != 0) {
6977c478bd9Sstevel@tonic-gate dprintf((stderr, "nvpair_value_byte_array fail\n"));
6987c478bd9Sstevel@tonic-gate goto fail;
6997c478bd9Sstevel@tonic-gate }
7007c478bd9Sstevel@tonic-gate
7017c478bd9Sstevel@tonic-gate if (dev_unpack(buf, size, tmp) != 0)
7027c478bd9Sstevel@tonic-gate goto fail;
7037c478bd9Sstevel@tonic-gate
7047c478bd9Sstevel@tonic-gate if (devlist == NULL) {
7057c478bd9Sstevel@tonic-gate prev = devlist = tmp;
7067c478bd9Sstevel@tonic-gate } else {
7077c478bd9Sstevel@tonic-gate prev->next = tmp;
7087c478bd9Sstevel@tonic-gate prev = tmp;
7097c478bd9Sstevel@tonic-gate }
7107c478bd9Sstevel@tonic-gate }
7117c478bd9Sstevel@tonic-gate
7127c478bd9Sstevel@tonic-gate nvlist_free(nvl);
7137c478bd9Sstevel@tonic-gate *devs = devlist;
7147c478bd9Sstevel@tonic-gate
7157c478bd9Sstevel@tonic-gate return (0);
7167c478bd9Sstevel@tonic-gate
7177c478bd9Sstevel@tonic-gate fail:
7187c478bd9Sstevel@tonic-gate nvlist_free(nvl);
7197c478bd9Sstevel@tonic-gate if (devlist != NULL) {
7207c478bd9Sstevel@tonic-gate while ((tmp = devlist) != NULL) {
7217c478bd9Sstevel@tonic-gate devlist = devlist->next;
7227c478bd9Sstevel@tonic-gate ri_dev_free(tmp);
7237c478bd9Sstevel@tonic-gate }
7247c478bd9Sstevel@tonic-gate }
7257c478bd9Sstevel@tonic-gate
7267c478bd9Sstevel@tonic-gate return (-1);
7277c478bd9Sstevel@tonic-gate }
7287c478bd9Sstevel@tonic-gate
7297c478bd9Sstevel@tonic-gate static int
client_list_unpack(char * buf,size_t size,ri_client_t ** clients)7307c478bd9Sstevel@tonic-gate client_list_unpack(char *buf, size_t size, ri_client_t **clients)
7317c478bd9Sstevel@tonic-gate {
7327c478bd9Sstevel@tonic-gate nvpair_t *nvp = NULL;
7337c478bd9Sstevel@tonic-gate nvlist_t *nvl;
7347c478bd9Sstevel@tonic-gate ri_client_t *client_list = NULL;
7357c478bd9Sstevel@tonic-gate ri_client_t *prev = NULL;
7367c478bd9Sstevel@tonic-gate ri_client_t *tmp = NULL;
7377c478bd9Sstevel@tonic-gate
7387c478bd9Sstevel@tonic-gate if (nvlist_unpack(buf, size, &nvl, 0) != 0) {
7397c478bd9Sstevel@tonic-gate dprintf((stderr, "nvlist_unpack fail\n"));
7407c478bd9Sstevel@tonic-gate return (-1);
7417c478bd9Sstevel@tonic-gate }
7427c478bd9Sstevel@tonic-gate
7437c478bd9Sstevel@tonic-gate while ((nvp = nvlist_next_nvpair(nvl, nvp)) != NULL) {
7447c478bd9Sstevel@tonic-gate assert(strcmp(nvpair_name(nvp), RI_CLIENT_T) == 0);
7457c478bd9Sstevel@tonic-gate assert(nvpair_type(nvp) == DATA_TYPE_BYTE_ARRAY);
7467c478bd9Sstevel@tonic-gate
7477c478bd9Sstevel@tonic-gate if ((tmp = calloc(1, sizeof (*tmp))) == NULL) {
7487c478bd9Sstevel@tonic-gate dprintf((stderr, "calloc: %s\n", strerror(errno)));
7497c478bd9Sstevel@tonic-gate goto fail;
7507c478bd9Sstevel@tonic-gate }
7517c478bd9Sstevel@tonic-gate
7527c478bd9Sstevel@tonic-gate buf = NULL;
7537c478bd9Sstevel@tonic-gate size = 0;
7547c478bd9Sstevel@tonic-gate if (nvpair_value_byte_array(nvp, (uchar_t **)&buf,
7557c478bd9Sstevel@tonic-gate (uint_t *)&size) != 0) {
7567c478bd9Sstevel@tonic-gate dprintf((stderr, "nvpair_value_byte_array fail\n"));
7577c478bd9Sstevel@tonic-gate goto fail;
7587c478bd9Sstevel@tonic-gate }
7597c478bd9Sstevel@tonic-gate
7607c478bd9Sstevel@tonic-gate if (client_unpack(buf, size, tmp) != 0)
7617c478bd9Sstevel@tonic-gate goto fail;
7627c478bd9Sstevel@tonic-gate
7637c478bd9Sstevel@tonic-gate if (client_list == NULL) {
7647c478bd9Sstevel@tonic-gate prev = client_list = tmp;
7657c478bd9Sstevel@tonic-gate } else {
7667c478bd9Sstevel@tonic-gate prev->next = tmp;
7677c478bd9Sstevel@tonic-gate prev = tmp;
7687c478bd9Sstevel@tonic-gate }
7697c478bd9Sstevel@tonic-gate }
7707c478bd9Sstevel@tonic-gate
7717c478bd9Sstevel@tonic-gate nvlist_free(nvl);
7727c478bd9Sstevel@tonic-gate *clients = client_list;
7737c478bd9Sstevel@tonic-gate
7747c478bd9Sstevel@tonic-gate return (0);
7757c478bd9Sstevel@tonic-gate
7767c478bd9Sstevel@tonic-gate fail:
7777c478bd9Sstevel@tonic-gate nvlist_free(nvl);
7787c478bd9Sstevel@tonic-gate if (client_list != NULL) {
7797c478bd9Sstevel@tonic-gate while ((tmp = client_list) != NULL) {
7807c478bd9Sstevel@tonic-gate client_list = client_list->next;
7817c478bd9Sstevel@tonic-gate ri_client_free(tmp);
7827c478bd9Sstevel@tonic-gate }
7837c478bd9Sstevel@tonic-gate }
7847c478bd9Sstevel@tonic-gate
7857c478bd9Sstevel@tonic-gate return (-1);
7867c478bd9Sstevel@tonic-gate }
7877c478bd9Sstevel@tonic-gate
7887c478bd9Sstevel@tonic-gate static int
client_unpack(char * buf,size_t size,ri_client_t * client)7897c478bd9Sstevel@tonic-gate client_unpack(char *buf, size_t size, ri_client_t *client)
7907c478bd9Sstevel@tonic-gate {
7917c478bd9Sstevel@tonic-gate nvlist_t *nvl;
7927c478bd9Sstevel@tonic-gate
7937c478bd9Sstevel@tonic-gate if (nvlist_unpack(buf, size, &nvl, 0) != 0) {
7947c478bd9Sstevel@tonic-gate dprintf((stderr, "nvlist_unpack fail\n"));
7957c478bd9Sstevel@tonic-gate return (-1);
7967c478bd9Sstevel@tonic-gate }
7977c478bd9Sstevel@tonic-gate
7987c478bd9Sstevel@tonic-gate if (lookup_unpack_byte_array(nvl, RI_CLIENT_USAGE_PROPS,
7997c478bd9Sstevel@tonic-gate &client->usg_props) != 0) {
8007c478bd9Sstevel@tonic-gate nvlist_free(nvl);
8017c478bd9Sstevel@tonic-gate return (-1);
8027c478bd9Sstevel@tonic-gate }
8037c478bd9Sstevel@tonic-gate
8047c478bd9Sstevel@tonic-gate #ifdef DEBUG
8057c478bd9Sstevel@tonic-gate nvlist_print(stderr, client->usg_props);
8067c478bd9Sstevel@tonic-gate #endif /* DEBUG */
8077c478bd9Sstevel@tonic-gate
8087c478bd9Sstevel@tonic-gate /*
8097c478bd9Sstevel@tonic-gate * Verbose properties for RCM clients only present if
8107c478bd9Sstevel@tonic-gate * RI_VERBOSE was specified for ri_init.
8117c478bd9Sstevel@tonic-gate */
8127c478bd9Sstevel@tonic-gate buf = NULL;
8137c478bd9Sstevel@tonic-gate size = 0;
8147c478bd9Sstevel@tonic-gate if (nvlist_lookup_byte_array(nvl, RI_CLIENT_VERB_PROPS,
8157c478bd9Sstevel@tonic-gate (uchar_t **)&buf, (uint_t *)&size) == 0) {
8167c478bd9Sstevel@tonic-gate if (nvlist_unpack(buf, size, &client->v_props, 0) != 0) {
8177c478bd9Sstevel@tonic-gate dprintf((stderr, "nvlist_unpack fail (%s)\n",
8187c478bd9Sstevel@tonic-gate RI_CLIENT_VERB_PROPS));
8197c478bd9Sstevel@tonic-gate nvlist_free(nvl);
8207c478bd9Sstevel@tonic-gate return (-1);
8217c478bd9Sstevel@tonic-gate }
8227c478bd9Sstevel@tonic-gate }
8237c478bd9Sstevel@tonic-gate
8247c478bd9Sstevel@tonic-gate nvlist_free(nvl);
8257c478bd9Sstevel@tonic-gate
8267c478bd9Sstevel@tonic-gate return (0);
8277c478bd9Sstevel@tonic-gate }
8287c478bd9Sstevel@tonic-gate
8297c478bd9Sstevel@tonic-gate static int
dev_unpack(char * buf,size_t size,ri_dev_t * dev)8307c478bd9Sstevel@tonic-gate dev_unpack(char *buf, size_t size, ri_dev_t *dev)
8317c478bd9Sstevel@tonic-gate {
8327c478bd9Sstevel@tonic-gate nvlist_t *nvl;
8337c478bd9Sstevel@tonic-gate
8347c478bd9Sstevel@tonic-gate if (nvlist_unpack(buf, size, &nvl, 0) != 0) {
8357c478bd9Sstevel@tonic-gate dprintf((stderr, "nvlist_unpack fail\n"));
8367c478bd9Sstevel@tonic-gate return (-1);
8377c478bd9Sstevel@tonic-gate }
8387c478bd9Sstevel@tonic-gate
8397c478bd9Sstevel@tonic-gate if (lookup_unpack_byte_array(nvl, RI_DEV_PROPS,
8407c478bd9Sstevel@tonic-gate &dev->conf_props) != 0) {
8417c478bd9Sstevel@tonic-gate nvlist_free(nvl);
8427c478bd9Sstevel@tonic-gate return (-1);
8437c478bd9Sstevel@tonic-gate }
8447c478bd9Sstevel@tonic-gate
8457c478bd9Sstevel@tonic-gate #ifdef DEBUG
8467c478bd9Sstevel@tonic-gate nvlist_print(stderr, dev->conf_props);
8477c478bd9Sstevel@tonic-gate #endif /* DEBUG */
8487c478bd9Sstevel@tonic-gate
8497c478bd9Sstevel@tonic-gate if (nvlist_lookup_byte_array(nvl, RI_DEV_CLIENTS, (uchar_t **)&buf,
8507c478bd9Sstevel@tonic-gate (uint_t *)&size) != 0) {
8517c478bd9Sstevel@tonic-gate dprintf((stderr, "nvlist_lookup_byte_array fail (%s)\n",
8527c478bd9Sstevel@tonic-gate RI_DEV_CLIENTS));
8537c478bd9Sstevel@tonic-gate nvlist_free(nvl);
8547c478bd9Sstevel@tonic-gate return (-1);
8557c478bd9Sstevel@tonic-gate }
8567c478bd9Sstevel@tonic-gate
8577c478bd9Sstevel@tonic-gate if (client_list_unpack(buf, size, &dev->rcm_clients) != 0) {
8587c478bd9Sstevel@tonic-gate nvlist_free(nvl);
8597c478bd9Sstevel@tonic-gate return (-1);
8607c478bd9Sstevel@tonic-gate }
8617c478bd9Sstevel@tonic-gate
8627c478bd9Sstevel@tonic-gate nvlist_free(nvl);
8637c478bd9Sstevel@tonic-gate
8647c478bd9Sstevel@tonic-gate return (0);
8657c478bd9Sstevel@tonic-gate }
8667c478bd9Sstevel@tonic-gate
8677c478bd9Sstevel@tonic-gate static int
ap_unpack(char * buf,size_t size,ri_ap_t * ap)8687c478bd9Sstevel@tonic-gate ap_unpack(char *buf, size_t size, ri_ap_t *ap)
8697c478bd9Sstevel@tonic-gate {
8707c478bd9Sstevel@tonic-gate nvlist_t *nvl;
8717c478bd9Sstevel@tonic-gate
8727c478bd9Sstevel@tonic-gate if (nvlist_unpack(buf, size, &nvl, 0) != 0) {
8737c478bd9Sstevel@tonic-gate dprintf((stderr, "nvlist_unpack fail\n"));
8747c478bd9Sstevel@tonic-gate return (-1);
8757c478bd9Sstevel@tonic-gate }
8767c478bd9Sstevel@tonic-gate
8777c478bd9Sstevel@tonic-gate if (lookup_unpack_byte_array(nvl, RI_AP_PROPS, &ap->conf_props) != 0) {
8787c478bd9Sstevel@tonic-gate nvlist_free(nvl);
8797c478bd9Sstevel@tonic-gate return (-1);
8807c478bd9Sstevel@tonic-gate }
8817c478bd9Sstevel@tonic-gate
8827c478bd9Sstevel@tonic-gate #ifdef DEBUG
8837c478bd9Sstevel@tonic-gate nvlist_print(stderr, ap->conf_props);
8847c478bd9Sstevel@tonic-gate #endif /* DEBUG */
8857c478bd9Sstevel@tonic-gate
8867c478bd9Sstevel@tonic-gate if (nvlist_lookup_byte_array(nvl, RI_AP_CPUS, (uchar_t **)&buf,
8877c478bd9Sstevel@tonic-gate (uint_t *)&size) != 0) {
8887c478bd9Sstevel@tonic-gate dprintf((stderr, "nvlist_lookup_byte_array fail (%s)\n",
8897c478bd9Sstevel@tonic-gate RI_AP_CPUS));
8907c478bd9Sstevel@tonic-gate nvlist_free(nvl);
8917c478bd9Sstevel@tonic-gate return (-1);
8927c478bd9Sstevel@tonic-gate }
8937c478bd9Sstevel@tonic-gate
8947c478bd9Sstevel@tonic-gate if (dev_list_unpack(buf, size, &ap->cpus) != 0) {
8957c478bd9Sstevel@tonic-gate nvlist_free(nvl);
8967c478bd9Sstevel@tonic-gate return (-1);
8977c478bd9Sstevel@tonic-gate }
8987c478bd9Sstevel@tonic-gate
8997c478bd9Sstevel@tonic-gate if (nvlist_lookup_byte_array(nvl, RI_AP_MEMS, (uchar_t **)&buf,
9007c478bd9Sstevel@tonic-gate (uint_t *)&size) != 0) {
9017c478bd9Sstevel@tonic-gate dprintf((stderr, "nvlist_lookup_byte_array fail (%s)\n",
9027c478bd9Sstevel@tonic-gate RI_AP_MEMS));
9037c478bd9Sstevel@tonic-gate nvlist_free(nvl);
9047c478bd9Sstevel@tonic-gate return (-1);
9057c478bd9Sstevel@tonic-gate }
9067c478bd9Sstevel@tonic-gate
9077c478bd9Sstevel@tonic-gate if (dev_list_unpack(buf, size, &ap->mems) != 0) {
9087c478bd9Sstevel@tonic-gate nvlist_free(nvl);
9097c478bd9Sstevel@tonic-gate return (-1);
9107c478bd9Sstevel@tonic-gate }
9117c478bd9Sstevel@tonic-gate
9127c478bd9Sstevel@tonic-gate if (nvlist_lookup_byte_array(nvl, RI_AP_IOS, (uchar_t **)&buf,
9137c478bd9Sstevel@tonic-gate (uint_t *)&size) != 0) {
9147c478bd9Sstevel@tonic-gate dprintf((stderr, "nvlist_lookup_byte_array fail (%s)\n",
9157c478bd9Sstevel@tonic-gate RI_AP_IOS));
9167c478bd9Sstevel@tonic-gate nvlist_free(nvl);
9177c478bd9Sstevel@tonic-gate return (-1);
9187c478bd9Sstevel@tonic-gate }
9197c478bd9Sstevel@tonic-gate
9207c478bd9Sstevel@tonic-gate if (dev_list_unpack(buf, size, &ap->ios) != 0) {
9217c478bd9Sstevel@tonic-gate nvlist_free(nvl);
9227c478bd9Sstevel@tonic-gate return (-1);
9237c478bd9Sstevel@tonic-gate }
9247c478bd9Sstevel@tonic-gate
9257c478bd9Sstevel@tonic-gate nvlist_free(nvl);
9267c478bd9Sstevel@tonic-gate
9277c478bd9Sstevel@tonic-gate return (0);
9287c478bd9Sstevel@tonic-gate }
9297c478bd9Sstevel@tonic-gate
9307c478bd9Sstevel@tonic-gate /*
9317c478bd9Sstevel@tonic-gate * Lookup byte array in old nvlist_t and unpack into new nvlist_t.
9327c478bd9Sstevel@tonic-gate */
9337c478bd9Sstevel@tonic-gate static int
lookup_unpack_byte_array(nvlist_t * old_nvl,char * name,nvlist_t ** new_nvl)9347c478bd9Sstevel@tonic-gate lookup_unpack_byte_array(nvlist_t *old_nvl, char *name, nvlist_t **new_nvl)
9357c478bd9Sstevel@tonic-gate {
9367c478bd9Sstevel@tonic-gate char *buf = NULL;
9377c478bd9Sstevel@tonic-gate size_t size = 0;
9387c478bd9Sstevel@tonic-gate
9397c478bd9Sstevel@tonic-gate if (nvlist_lookup_byte_array(old_nvl, name, (uchar_t **)&buf,
9407c478bd9Sstevel@tonic-gate (uint_t *)&size) != 0) {
9417c478bd9Sstevel@tonic-gate dprintf((stderr, "nvlist_lookup_byte_array fail (%s)\n",
9427c478bd9Sstevel@tonic-gate name));
9437c478bd9Sstevel@tonic-gate return (-1);
9447c478bd9Sstevel@tonic-gate }
9457c478bd9Sstevel@tonic-gate
9467c478bd9Sstevel@tonic-gate if (nvlist_unpack(buf, size, new_nvl, 0) != 0) {
9477c478bd9Sstevel@tonic-gate dprintf((stderr, "nvlist_unpack fail (%s)\n", name));
9487c478bd9Sstevel@tonic-gate return (-1);
9497c478bd9Sstevel@tonic-gate }
9507c478bd9Sstevel@tonic-gate
9517c478bd9Sstevel@tonic-gate return (0);
9527c478bd9Sstevel@tonic-gate }
9537c478bd9Sstevel@tonic-gate
9547c478bd9Sstevel@tonic-gate ri_ap_t *
ri_ap_next(ri_hdl_t * hdl,ri_ap_t * ap)9557c478bd9Sstevel@tonic-gate ri_ap_next(ri_hdl_t *hdl, ri_ap_t *ap)
9567c478bd9Sstevel@tonic-gate {
9577c478bd9Sstevel@tonic-gate if (hdl == NULL) {
9587c478bd9Sstevel@tonic-gate errno = EINVAL;
9597c478bd9Sstevel@tonic-gate return (NULL);
9607c478bd9Sstevel@tonic-gate }
9617c478bd9Sstevel@tonic-gate return ((ap == NULL) ? hdl->aps : ap->next);
9627c478bd9Sstevel@tonic-gate }
9637c478bd9Sstevel@tonic-gate
9647c478bd9Sstevel@tonic-gate nvlist_t *
ri_ap_conf_props(ri_ap_t * ap)9657c478bd9Sstevel@tonic-gate ri_ap_conf_props(ri_ap_t *ap)
9667c478bd9Sstevel@tonic-gate {
9677c478bd9Sstevel@tonic-gate if (ap == NULL) {
9687c478bd9Sstevel@tonic-gate errno = EINVAL;
9697c478bd9Sstevel@tonic-gate return (NULL);
9707c478bd9Sstevel@tonic-gate }
9717c478bd9Sstevel@tonic-gate return (ap->conf_props);
9727c478bd9Sstevel@tonic-gate }
9737c478bd9Sstevel@tonic-gate
9747c478bd9Sstevel@tonic-gate ri_dev_t *
ri_cpu_next(ri_ap_t * ap,ri_dev_t * cpu)9757c478bd9Sstevel@tonic-gate ri_cpu_next(ri_ap_t *ap, ri_dev_t *cpu)
9767c478bd9Sstevel@tonic-gate {
9777c478bd9Sstevel@tonic-gate if (ap == NULL) {
9787c478bd9Sstevel@tonic-gate errno = EINVAL;
9797c478bd9Sstevel@tonic-gate return (NULL);
9807c478bd9Sstevel@tonic-gate }
9817c478bd9Sstevel@tonic-gate return ((cpu == NULL) ? ap->cpus : cpu->next);
9827c478bd9Sstevel@tonic-gate }
9837c478bd9Sstevel@tonic-gate
9847c478bd9Sstevel@tonic-gate ri_dev_t *
ri_mem_next(ri_ap_t * ap,ri_dev_t * mem)9857c478bd9Sstevel@tonic-gate ri_mem_next(ri_ap_t *ap, ri_dev_t *mem)
9867c478bd9Sstevel@tonic-gate {
9877c478bd9Sstevel@tonic-gate if (ap == NULL) {
9887c478bd9Sstevel@tonic-gate errno = EINVAL;
9897c478bd9Sstevel@tonic-gate return (NULL);
9907c478bd9Sstevel@tonic-gate }
9917c478bd9Sstevel@tonic-gate return ((mem == NULL) ? ap->mems : mem->next);
9927c478bd9Sstevel@tonic-gate }
9937c478bd9Sstevel@tonic-gate
9947c478bd9Sstevel@tonic-gate ri_dev_t *
ri_io_next(ri_ap_t * ap,ri_dev_t * io)9957c478bd9Sstevel@tonic-gate ri_io_next(ri_ap_t *ap, ri_dev_t *io)
9967c478bd9Sstevel@tonic-gate {
9977c478bd9Sstevel@tonic-gate if (ap == NULL) {
9987c478bd9Sstevel@tonic-gate errno = EINVAL;
9997c478bd9Sstevel@tonic-gate return (NULL);
10007c478bd9Sstevel@tonic-gate }
10017c478bd9Sstevel@tonic-gate return ((io == NULL) ? ap->ios : io->next);
10027c478bd9Sstevel@tonic-gate }
10037c478bd9Sstevel@tonic-gate
10047c478bd9Sstevel@tonic-gate ri_client_t *
ri_client_next(ri_dev_t * dev,ri_client_t * rcm_client)10057c478bd9Sstevel@tonic-gate ri_client_next(ri_dev_t *dev, ri_client_t *rcm_client)
10067c478bd9Sstevel@tonic-gate {
10077c478bd9Sstevel@tonic-gate if (dev == NULL) {
10087c478bd9Sstevel@tonic-gate errno = EINVAL;
10097c478bd9Sstevel@tonic-gate return (NULL);
10107c478bd9Sstevel@tonic-gate }
10117c478bd9Sstevel@tonic-gate return ((rcm_client == NULL) ? dev->rcm_clients : rcm_client->next);
10127c478bd9Sstevel@tonic-gate }
10137c478bd9Sstevel@tonic-gate
10147c478bd9Sstevel@tonic-gate nvlist_t *
ri_dev_conf_props(ri_dev_t * dev)10157c478bd9Sstevel@tonic-gate ri_dev_conf_props(ri_dev_t *dev)
10167c478bd9Sstevel@tonic-gate {
10177c478bd9Sstevel@tonic-gate if (dev == NULL) {
10187c478bd9Sstevel@tonic-gate errno = EINVAL;
10197c478bd9Sstevel@tonic-gate return (NULL);
10207c478bd9Sstevel@tonic-gate }
10217c478bd9Sstevel@tonic-gate return (dev->conf_props);
10227c478bd9Sstevel@tonic-gate }
10237c478bd9Sstevel@tonic-gate
10247c478bd9Sstevel@tonic-gate nvlist_t *
ri_client_usage_props(ri_client_t * rcm_client)10257c478bd9Sstevel@tonic-gate ri_client_usage_props(ri_client_t *rcm_client)
10267c478bd9Sstevel@tonic-gate {
10277c478bd9Sstevel@tonic-gate if (rcm_client == NULL) {
10287c478bd9Sstevel@tonic-gate errno = EINVAL;
10297c478bd9Sstevel@tonic-gate return (NULL);
10307c478bd9Sstevel@tonic-gate }
10317c478bd9Sstevel@tonic-gate return (rcm_client->usg_props);
10327c478bd9Sstevel@tonic-gate }
10337c478bd9Sstevel@tonic-gate
10347c478bd9Sstevel@tonic-gate nvlist_t *
ri_client_verbose_props(ri_client_t * rcm_client)10357c478bd9Sstevel@tonic-gate ri_client_verbose_props(ri_client_t *rcm_client)
10367c478bd9Sstevel@tonic-gate {
10377c478bd9Sstevel@tonic-gate if (rcm_client == NULL) {
10387c478bd9Sstevel@tonic-gate errno = EINVAL;
10397c478bd9Sstevel@tonic-gate return (NULL);
10407c478bd9Sstevel@tonic-gate }
10417c478bd9Sstevel@tonic-gate return (rcm_client->v_props);
10427c478bd9Sstevel@tonic-gate }
10437c478bd9Sstevel@tonic-gate
10447c478bd9Sstevel@tonic-gate ri_client_t *
ri_cpu_cap_client_next(ri_hdl_t * hdl,ri_client_t * rcm_client)10457c478bd9Sstevel@tonic-gate ri_cpu_cap_client_next(ri_hdl_t *hdl, ri_client_t *rcm_client)
10467c478bd9Sstevel@tonic-gate {
10477c478bd9Sstevel@tonic-gate if (hdl == NULL) {
10487c478bd9Sstevel@tonic-gate errno = EINVAL;
10497c478bd9Sstevel@tonic-gate return (NULL);
10507c478bd9Sstevel@tonic-gate }
10517c478bd9Sstevel@tonic-gate return ((rcm_client == NULL) ? hdl->cpu_cap_clients : rcm_client->next);
10527c478bd9Sstevel@tonic-gate }
10537c478bd9Sstevel@tonic-gate
10547c478bd9Sstevel@tonic-gate ri_client_t *
ri_mem_cap_client_next(ri_hdl_t * hdl,ri_client_t * rcm_client)10557c478bd9Sstevel@tonic-gate ri_mem_cap_client_next(ri_hdl_t *hdl, ri_client_t *rcm_client)
10567c478bd9Sstevel@tonic-gate {
10577c478bd9Sstevel@tonic-gate if (hdl == NULL) {
10587c478bd9Sstevel@tonic-gate errno = EINVAL;
10597c478bd9Sstevel@tonic-gate return (NULL);
10607c478bd9Sstevel@tonic-gate }
10617c478bd9Sstevel@tonic-gate return ((rcm_client == NULL) ? hdl->mem_cap_clients : rcm_client->next);
10627c478bd9Sstevel@tonic-gate }
1063