xref: /titanic_51/usr/src/cmd/isns/isnsd/admintf.c (revision 5fbbe9c6367b156920d72becff64235e6274db32)
1fcf3ce44SJohn Forte /*
2fcf3ce44SJohn Forte  * CDDL HEADER START
3fcf3ce44SJohn Forte  *
4fcf3ce44SJohn Forte  * The contents of this file are subject to the terms of the
5fcf3ce44SJohn Forte  * Common Development and Distribution License (the "License").
6fcf3ce44SJohn Forte  * You may not use this file except in compliance with the License.
7fcf3ce44SJohn Forte  *
8fcf3ce44SJohn Forte  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9fcf3ce44SJohn Forte  * or http://www.opensolaris.org/os/licensing.
10fcf3ce44SJohn Forte  * See the License for the specific language governing permissions
11fcf3ce44SJohn Forte  * and limitations under the License.
12fcf3ce44SJohn Forte  *
13fcf3ce44SJohn Forte  * When distributing Covered Code, include this CDDL HEADER in each
14fcf3ce44SJohn Forte  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15fcf3ce44SJohn Forte  * If applicable, add the following below this CDDL HEADER, with the
16fcf3ce44SJohn Forte  * fields enclosed by brackets "[]" replaced with your own identifying
17fcf3ce44SJohn Forte  * information: Portions Copyright [yyyy] [name of copyright owner]
18fcf3ce44SJohn Forte  *
19fcf3ce44SJohn Forte  * CDDL HEADER END
20fcf3ce44SJohn Forte  */
21fcf3ce44SJohn Forte 
22fcf3ce44SJohn Forte /*
23*5fbbe9c6Swl202157@icefox  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
24fcf3ce44SJohn Forte  * Use is subject to license terms.
25fcf3ce44SJohn Forte  */
26fcf3ce44SJohn Forte 
27fcf3ce44SJohn Forte #include <stdio.h>
28fcf3ce44SJohn Forte #include <stdlib.h>
29fcf3ce44SJohn Forte #include <string.h>
30fcf3ce44SJohn Forte #include <libxml/xmlreader.h>
31fcf3ce44SJohn Forte #include <libxml/xmlwriter.h>
32fcf3ce44SJohn Forte #include <libxml/tree.h>
33fcf3ce44SJohn Forte #include <sys/types.h>
34fcf3ce44SJohn Forte #include <sys/socket.h>
35fcf3ce44SJohn Forte #include <netinet/in.h>
36fcf3ce44SJohn Forte #include <arpa/inet.h>
37fcf3ce44SJohn Forte #include <pthread.h>
38fcf3ce44SJohn Forte 
39fcf3ce44SJohn Forte #include "isns_server.h"
40fcf3ce44SJohn Forte #include "isns_cfg.h"
41fcf3ce44SJohn Forte #include "isns_htab.h"
42fcf3ce44SJohn Forte #include "isns_cache.h"
43fcf3ce44SJohn Forte #include "isns_obj.h"
44fcf3ce44SJohn Forte #include "isns_dd.h"
45fcf3ce44SJohn Forte #include "isns_utils.h"
46fcf3ce44SJohn Forte #include "isns_mgmt.h"
47fcf3ce44SJohn Forte #include "isns_protocol.h"
48fcf3ce44SJohn Forte #include "admintf.h"
49fcf3ce44SJohn Forte 
50fcf3ce44SJohn Forte extern const int UID_ATTR_INDEX[MAX_OBJ_TYPE_FOR_SIZE];
51fcf3ce44SJohn Forte 
52fcf3ce44SJohn Forte static isns_type_t
53fcf3ce44SJohn Forte get_lc_type(
54fcf3ce44SJohn Forte 	object_type obj
55fcf3ce44SJohn Forte )
56fcf3ce44SJohn Forte {
57fcf3ce44SJohn Forte 	isns_type_t type;
58fcf3ce44SJohn Forte 
59fcf3ce44SJohn Forte 	switch (obj) {
60fcf3ce44SJohn Forte 	case Node:
61fcf3ce44SJohn Forte 		type = OBJ_ISCSI;
62fcf3ce44SJohn Forte 		break;
63fcf3ce44SJohn Forte 	case DiscoveryDomain:
64fcf3ce44SJohn Forte 	case DiscoveryDomainMember:
65fcf3ce44SJohn Forte 		type = OBJ_DD;
66fcf3ce44SJohn Forte 		break;
67fcf3ce44SJohn Forte 	case DiscoveryDomainSet:
68fcf3ce44SJohn Forte 	case DiscoveryDomainSetMember:
69fcf3ce44SJohn Forte 		type = OBJ_DDS;
70fcf3ce44SJohn Forte 		break;
71fcf3ce44SJohn Forte 	default:
72fcf3ce44SJohn Forte 		ASSERT(0);
73fcf3ce44SJohn Forte 		break;
74fcf3ce44SJohn Forte 	}
75fcf3ce44SJohn Forte 
76fcf3ce44SJohn Forte 	return (type);
77fcf3ce44SJohn Forte }
78fcf3ce44SJohn Forte 
79fcf3ce44SJohn Forte static uint32_t
80fcf3ce44SJohn Forte get_lc_id(
81fcf3ce44SJohn Forte 	object_type obj
82fcf3ce44SJohn Forte )
83fcf3ce44SJohn Forte {
84fcf3ce44SJohn Forte 	uint32_t id;
85fcf3ce44SJohn Forte 
86fcf3ce44SJohn Forte 	switch (obj) {
87fcf3ce44SJohn Forte 	case Node:
88fcf3ce44SJohn Forte 		id = ATTR_INDEX_ISCSI(ISNS_ISCSI_NAME_ATTR_ID);
89fcf3ce44SJohn Forte 		break;
90fcf3ce44SJohn Forte 	case DiscoveryDomain:
91fcf3ce44SJohn Forte 	case DiscoveryDomainMember:
92fcf3ce44SJohn Forte 		id = ATTR_INDEX_DD(ISNS_DD_NAME_ATTR_ID);
93fcf3ce44SJohn Forte 		break;
94fcf3ce44SJohn Forte 	case DiscoveryDomainSet:
95fcf3ce44SJohn Forte 	case DiscoveryDomainSetMember:
96fcf3ce44SJohn Forte 		id = ATTR_INDEX_DDS(ISNS_DD_SET_NAME_ATTR_ID);
97fcf3ce44SJohn Forte 		break;
98fcf3ce44SJohn Forte 	default:
99fcf3ce44SJohn Forte 		ASSERT(0);
100fcf3ce44SJohn Forte 		break;
101fcf3ce44SJohn Forte 	}
102fcf3ce44SJohn Forte 
103fcf3ce44SJohn Forte 	return (id);
104fcf3ce44SJohn Forte }
105fcf3ce44SJohn Forte 
106fcf3ce44SJohn Forte /*
107fcf3ce44SJohn Forte  * ****************************************************************************
108fcf3ce44SJohn Forte  *
109fcf3ce44SJohn Forte  * cb_get_node_info: callback for get_node_op
110fcf3ce44SJohn Forte  *	The routine process matching node and add a Node object elements
111fcf3ce44SJohn Forte  *	to the response doc.
112fcf3ce44SJohn Forte  *
113fcf3ce44SJohn Forte  * p1	- matching node object
114fcf3ce44SJohn Forte  * p2	- lookup control data that was used for node look up
115fcf3ce44SJohn Forte  *	    returns parent index(newtork entity) in look up control.
116fcf3ce44SJohn Forte  * return - error code
117fcf3ce44SJohn Forte  *
118fcf3ce44SJohn Forte  * ****************************************************************************
119fcf3ce44SJohn Forte  */
120fcf3ce44SJohn Forte static int
121fcf3ce44SJohn Forte cb_get_node_info(
122fcf3ce44SJohn Forte 	void *p1,
123fcf3ce44SJohn Forte 	void *p2
124fcf3ce44SJohn Forte )
125fcf3ce44SJohn Forte {
126fcf3ce44SJohn Forte 	xmlNodePtr	n_obj, n_node, sub_node, root;
127fcf3ce44SJohn Forte 	xmlAttrPtr	n_attr;
128fcf3ce44SJohn Forte 	isns_attr_t *attr;
129fcf3ce44SJohn Forte 
130fcf3ce44SJohn Forte 	isns_obj_t *obj = (isns_obj_t *)p1;
131fcf3ce44SJohn Forte 	lookup_ctrl_t *lcp = (lookup_ctrl_t *)p2;
132fcf3ce44SJohn Forte 	xmlDocPtr doc = (xmlDocPtr)lcp->data[1].ptr;
133fcf3ce44SJohn Forte 
134fcf3ce44SJohn Forte 	root = xmlDocGetRootElement(doc);
135fcf3ce44SJohn Forte 	if (root == NULL) {
136fcf3ce44SJohn Forte 	    return (ERR_XML_ADDCHILD_FAILED);
137fcf3ce44SJohn Forte 	}
138fcf3ce44SJohn Forte 
139fcf3ce44SJohn Forte 	n_obj = xmlNewNode(NULL, (xmlChar *)ISNSOBJECT);
140fcf3ce44SJohn Forte 	if (n_obj) {
141fcf3ce44SJohn Forte 	    n_obj = xmlAddChild(root, n_obj);
142fcf3ce44SJohn Forte 	    if (n_obj == NULL) {
143fcf3ce44SJohn Forte 		return (ERR_XML_ADDCHILD_FAILED);
144fcf3ce44SJohn Forte 	    }
145fcf3ce44SJohn Forte 	} else {
146fcf3ce44SJohn Forte 	    return (ERR_XML_ADDCHILD_FAILED);
147fcf3ce44SJohn Forte 	}
148fcf3ce44SJohn Forte 
149fcf3ce44SJohn Forte 	n_node = xmlNewNode(NULL, (xmlChar *)NODEOBJECT);
150fcf3ce44SJohn Forte 	if (n_node) {
151fcf3ce44SJohn Forte 	    n_node = xmlAddChild(n_obj, n_node);
152fcf3ce44SJohn Forte 	    if (n_node == NULL) {
153fcf3ce44SJohn Forte 		return (ERR_XML_ADDCHILD_FAILED);
154fcf3ce44SJohn Forte 	    }
155fcf3ce44SJohn Forte 	} else {
156fcf3ce44SJohn Forte 	    return (ERR_XML_ADDCHILD_FAILED);
157fcf3ce44SJohn Forte 	}
158fcf3ce44SJohn Forte 
159fcf3ce44SJohn Forte 	/* get node name, alias, type and generate xml info */
160fcf3ce44SJohn Forte 	attr = &obj->attrs[ATTR_INDEX_ISCSI(ISNS_ISCSI_NAME_ATTR_ID)];
161fcf3ce44SJohn Forte 	n_attr = xmlSetProp(n_node, (xmlChar *)NAMEATTR,
162fcf3ce44SJohn Forte 		(xmlChar *)attr->value.ptr);
163fcf3ce44SJohn Forte 	if (n_attr == NULL) {
164fcf3ce44SJohn Forte 	    return (ERR_XML_SETPROP_FAILED);
165fcf3ce44SJohn Forte 	}
166fcf3ce44SJohn Forte 
167fcf3ce44SJohn Forte 	attr = &obj->attrs[ATTR_INDEX_ISCSI(ISNS_ISCSI_NODE_TYPE_ATTR_ID)];
168fcf3ce44SJohn Forte 	switch (attr->value.ui) {
169fcf3ce44SJohn Forte 	    case ISNS_CONTROL_NODE_TYPE | ISNS_INITIATOR_NODE_TYPE:
170fcf3ce44SJohn Forte 		n_attr = xmlSetProp(n_node, (xmlChar *)TYPEATTR,
171fcf3ce44SJohn Forte 		    (xmlChar *)CONTROLNODEINITIATORTYPE);
172fcf3ce44SJohn Forte 		break;
173fcf3ce44SJohn Forte 	    case ISNS_CONTROL_NODE_TYPE | ISNS_TARGET_NODE_TYPE:
174fcf3ce44SJohn Forte 		n_attr = xmlSetProp(n_node, (xmlChar *)TYPEATTR,
175fcf3ce44SJohn Forte 		    (xmlChar *)CONTROLNODETARGETTYPE);
176fcf3ce44SJohn Forte 		break;
177fcf3ce44SJohn Forte 	    case ISNS_TARGET_NODE_TYPE:
178fcf3ce44SJohn Forte 		n_attr = xmlSetProp(n_node, (xmlChar *)TYPEATTR,
179fcf3ce44SJohn Forte 		    (xmlChar *)TARGETTYPE);
180fcf3ce44SJohn Forte 		break;
181fcf3ce44SJohn Forte 	    case ISNS_INITIATOR_NODE_TYPE:
182fcf3ce44SJohn Forte 		n_attr = xmlSetProp(n_node, (xmlChar *)TYPEATTR,
183fcf3ce44SJohn Forte 		    (xmlChar *)INITIATORTYPE);
184fcf3ce44SJohn Forte 		break;
185fcf3ce44SJohn Forte 	    case ISNS_CONTROL_NODE_TYPE:
186fcf3ce44SJohn Forte 		n_attr = xmlSetProp(n_node, (xmlChar *)TYPEATTR,
187fcf3ce44SJohn Forte 		    (xmlChar *)CONTROLNODETYPE);
188fcf3ce44SJohn Forte 		break;
189fcf3ce44SJohn Forte 	    default:
190fcf3ce44SJohn Forte 		n_attr = xmlSetProp(n_node, (xmlChar *)TYPEATTR,
191fcf3ce44SJohn Forte 		    (xmlChar *)UNKNOWNTYPE);
192fcf3ce44SJohn Forte 	}
193fcf3ce44SJohn Forte 	if (n_attr == NULL) {
194fcf3ce44SJohn Forte 	    return (ERR_XML_SETPROP_FAILED);
195fcf3ce44SJohn Forte 	}
196fcf3ce44SJohn Forte 
197fcf3ce44SJohn Forte 	attr = &obj->attrs[ATTR_INDEX_ISCSI(ISNS_ISCSI_ALIAS_ATTR_ID)];
198fcf3ce44SJohn Forte 	n_attr = xmlSetProp(n_node, (xmlChar *)ALIASATTR,
199fcf3ce44SJohn Forte 		(xmlChar *)attr->value.ptr);
200fcf3ce44SJohn Forte 	if (n_attr == NULL) {
201fcf3ce44SJohn Forte 	    return (ERR_XML_SETPROP_FAILED);
202fcf3ce44SJohn Forte 	}
203fcf3ce44SJohn Forte 
204fcf3ce44SJohn Forte 	/*
205fcf3ce44SJohn Forte 	 * A node can have all or no SCN subsribtion.
206fcf3ce44SJohn Forte 	 * May avoid redundant code with scsusrciption table.
207fcf3ce44SJohn Forte 	 */
208fcf3ce44SJohn Forte 	attr = &obj->attrs[ATTR_INDEX_ISCSI(ISNS_ISCSI_SCN_BITMAP_ATTR_ID)];
209fcf3ce44SJohn Forte 	if (IS_SCN_INIT_SELF_INFO_ONLY(attr->value.ui)) {
210fcf3ce44SJohn Forte 	    sub_node = xmlNewChild(n_node, NULL, (xmlChar *)SCNSUBSCRIPTION,
211fcf3ce44SJohn Forte 		(xmlChar *)SCNINITSELFONLY);
212fcf3ce44SJohn Forte 	    if (sub_node == NULL) {
213fcf3ce44SJohn Forte 		return (ERR_XML_NEWCHILD_FAILED);
214fcf3ce44SJohn Forte 	    }
215fcf3ce44SJohn Forte 	}
216fcf3ce44SJohn Forte 	if (IS_SCN_TARGET_SELF_INFO_ONLY(attr->value.ui)) {
217fcf3ce44SJohn Forte 	    sub_node = xmlNewChild(n_node, NULL, (xmlChar *)SCNSUBSCRIPTION,
218fcf3ce44SJohn Forte 		(xmlChar *)SCNTARGETSELFONLY);
219fcf3ce44SJohn Forte 	    if (sub_node == NULL) {
220fcf3ce44SJohn Forte 		return (ERR_XML_NEWCHILD_FAILED);
221fcf3ce44SJohn Forte 	    }
222fcf3ce44SJohn Forte 	}
223fcf3ce44SJohn Forte 	if (IS_SCN_MGMT_REG(attr->value.ui)) {
224fcf3ce44SJohn Forte 	    sub_node = xmlNewChild(n_node, NULL, (xmlChar *)SCNSUBSCRIPTION,
225fcf3ce44SJohn Forte 		(xmlChar *)SCNTARGETSELFONLY);
226fcf3ce44SJohn Forte 	    if (sub_node == NULL) {
227fcf3ce44SJohn Forte 		return (ERR_XML_NEWCHILD_FAILED);
228fcf3ce44SJohn Forte 	    }
229fcf3ce44SJohn Forte 	}
230fcf3ce44SJohn Forte 	if (IS_SCN_OBJ_REMOVED(attr->value.ui)) {
231fcf3ce44SJohn Forte 	    sub_node = xmlNewChild(n_node, NULL, (xmlChar *)SCNSUBSCRIPTION,
232fcf3ce44SJohn Forte 		(xmlChar *)SCNOBJECTREMOVED);
233fcf3ce44SJohn Forte 	    if (sub_node == NULL) {
234fcf3ce44SJohn Forte 		return (ERR_XML_NEWCHILD_FAILED);
235fcf3ce44SJohn Forte 	    }
236fcf3ce44SJohn Forte 	}
237fcf3ce44SJohn Forte 	if (IS_SCN_OBJ_ADDED(attr->value.ui)) {
238fcf3ce44SJohn Forte 	    sub_node = xmlNewChild(n_node, NULL, (xmlChar *)SCNSUBSCRIPTION,
239fcf3ce44SJohn Forte 		(xmlChar *)SCNOBJECTADDED);
240fcf3ce44SJohn Forte 	    if (sub_node == NULL) {
241fcf3ce44SJohn Forte 		return (ERR_XML_NEWCHILD_FAILED);
242fcf3ce44SJohn Forte 	    }
243fcf3ce44SJohn Forte 	}
244fcf3ce44SJohn Forte 	if (IS_SCN_OBJ_UPDATED(attr->value.ui)) {
245fcf3ce44SJohn Forte 	    sub_node = xmlNewChild(n_node, NULL, (xmlChar *)SCNSUBSCRIPTION,
246fcf3ce44SJohn Forte 		(xmlChar *)SCNOBJECTUPDATED);
247fcf3ce44SJohn Forte 	    if (sub_node == NULL) {
248fcf3ce44SJohn Forte 		return (ERR_XML_NEWCHILD_FAILED);
249fcf3ce44SJohn Forte 	    }
250fcf3ce44SJohn Forte 	}
251fcf3ce44SJohn Forte 	if (IS_SCN_MEMBER_REMOVED(attr->value.ui)) {
252fcf3ce44SJohn Forte 	    sub_node = xmlNewChild(n_node, NULL, (xmlChar *)SCNSUBSCRIPTION,
253fcf3ce44SJohn Forte 		(xmlChar *)SCNMEMBERREMOVED);
254fcf3ce44SJohn Forte 	    if (sub_node == NULL) {
255fcf3ce44SJohn Forte 		return (ERR_XML_NEWCHILD_FAILED);
256fcf3ce44SJohn Forte 	    }
257fcf3ce44SJohn Forte 	}
258fcf3ce44SJohn Forte 	if (IS_SCN_MEMBER_ADDED(attr->value.ui)) {
259fcf3ce44SJohn Forte 	    sub_node = xmlNewChild(n_node, NULL, (xmlChar *)SCNSUBSCRIPTION,
260fcf3ce44SJohn Forte 		(xmlChar *)SCNMEMBERADDED);
261fcf3ce44SJohn Forte 	    if (sub_node == NULL) {
262fcf3ce44SJohn Forte 		return (ERR_XML_NEWCHILD_FAILED);
263fcf3ce44SJohn Forte 	    }
264fcf3ce44SJohn Forte 	}
265fcf3ce44SJohn Forte 
266fcf3ce44SJohn Forte 	/* set the parent object id, i.e. the network entity object id */
267fcf3ce44SJohn Forte 	lcp->id[2] = get_parent_uid(obj);
268fcf3ce44SJohn Forte 	/* pass back the node object element to add entity, portal info to it */
269fcf3ce44SJohn Forte 	lcp->data[2].ptr =  (uchar_t *)n_node;
270fcf3ce44SJohn Forte 
271fcf3ce44SJohn Forte 	/* successful */
272fcf3ce44SJohn Forte 	return (0);
273fcf3ce44SJohn Forte }
274fcf3ce44SJohn Forte 
275fcf3ce44SJohn Forte /*
276fcf3ce44SJohn Forte  * ****************************************************************************
277fcf3ce44SJohn Forte  *
278fcf3ce44SJohn Forte  * cb_get_entity_info: callback for get_node_op
279fcf3ce44SJohn Forte  *	The routine process matching network entity and add children elements
280fcf3ce44SJohn Forte  *	to a Node object for given entity.
281fcf3ce44SJohn Forte  *
282fcf3ce44SJohn Forte  * p1	- matching entity object
283fcf3ce44SJohn Forte  * p2	- lookup control data that was used for node look up
284fcf3ce44SJohn Forte  *	    returns parent index(newtork entity) in look up control.
285fcf3ce44SJohn Forte  * return - error code
286fcf3ce44SJohn Forte  *
287fcf3ce44SJohn Forte  * ****************************************************************************
288fcf3ce44SJohn Forte  */
289fcf3ce44SJohn Forte static int
290fcf3ce44SJohn Forte cb_get_entity_info(
291fcf3ce44SJohn Forte 	void *p1,
292fcf3ce44SJohn Forte 	void *p2
293fcf3ce44SJohn Forte )
294fcf3ce44SJohn Forte {
295fcf3ce44SJohn Forte 	isns_obj_t *obj = (isns_obj_t *)p1;
296fcf3ce44SJohn Forte 	lookup_ctrl_t *lcp = (lookup_ctrl_t *)p2;
297fcf3ce44SJohn Forte 	xmlNodePtr n_node = (xmlNodePtr)lcp->data[2].ptr;
298fcf3ce44SJohn Forte 	xmlNodePtr sub_node, subchild_node, subgrandchild_node;
299fcf3ce44SJohn Forte 	char numbuf[32];
300fcf3ce44SJohn Forte 	char buff[INET6_ADDRSTRLEN + 1] = { 0 };
301fcf3ce44SJohn Forte 	isns_attr_t *attr;
302fcf3ce44SJohn Forte 
303fcf3ce44SJohn Forte 	sub_node = xmlNewChild(n_node, NULL, (xmlChar *)NETWORKENTITY, NULL);
304fcf3ce44SJohn Forte 
305fcf3ce44SJohn Forte 	if (sub_node) {
306fcf3ce44SJohn Forte 	    attr = &obj->attrs[ATTR_INDEX_ENTITY(ISNS_EID_ATTR_ID)];
307fcf3ce44SJohn Forte 	    subchild_node = xmlNewChild(sub_node, NULL,
308fcf3ce44SJohn Forte 		(xmlChar *)ENTITYID, (xmlChar *)attr->value.ptr);
309fcf3ce44SJohn Forte 	    if (subchild_node == NULL) {
310fcf3ce44SJohn Forte 		return (ERR_XML_NEWCHILD_FAILED);
311fcf3ce44SJohn Forte 	    }
312fcf3ce44SJohn Forte 	    attr = &obj->attrs[ATTR_INDEX_ENTITY(ISNS_ENTITY_PROTOCOL_ATTR_ID)];
313fcf3ce44SJohn Forte 	    (void) sprintf(numbuf, "%u", attr->value.ui);
314fcf3ce44SJohn Forte 	    subchild_node = xmlNewChild(sub_node, NULL,
315fcf3ce44SJohn Forte 		(xmlChar *)ENTITYPROTOCOL, (xmlChar *)numbuf);
316fcf3ce44SJohn Forte 	    if (subchild_node == NULL) {
317fcf3ce44SJohn Forte 		return (ERR_XML_NEWCHILD_FAILED);
318fcf3ce44SJohn Forte 	    }
319fcf3ce44SJohn Forte 	    attr = &obj->attrs[ATTR_INDEX_ENTITY(ISNS_MGMT_IP_ADDR_ATTR_ID)];
320fcf3ce44SJohn Forte 	    if (attr->value.ip) {
321fcf3ce44SJohn Forte 		/* convert the ipv6 to ipv4 */
322fcf3ce44SJohn Forte 		if (((int *)attr->value.ip)[0] == 0x00 &&
323fcf3ce44SJohn Forte 		    ((int *)attr->value.ip)[1] == 0x00 &&
324fcf3ce44SJohn Forte 		    ((uchar_t *)attr->value.ip)[8] == 0x00 &&
325fcf3ce44SJohn Forte 		    ((uchar_t *)attr->value.ip)[9] == 0x00 &&
326fcf3ce44SJohn Forte 		    ((uchar_t *)attr->value.ip)[10] == 0xFF &&
327fcf3ce44SJohn Forte 		    ((uchar_t *)attr->value.ip)[11] == 0xFF) {
328fcf3ce44SJohn Forte 		    subchild_node = xmlNewChild(sub_node, NULL,
329fcf3ce44SJohn Forte 			(xmlChar *)MANAGEMENTIPADDR,
330fcf3ce44SJohn Forte 			(xmlChar *)inet_ntop(AF_INET,
331fcf3ce44SJohn Forte 			(void *)&(((uint32_t *)attr->value.ip)[3]),
332fcf3ce44SJohn Forte 			buff, sizeof (buff)));
333fcf3ce44SJohn Forte 		} else {
334fcf3ce44SJohn Forte 		    subchild_node = xmlNewChild(sub_node, NULL,
335fcf3ce44SJohn Forte 			(xmlChar *)MANAGEMENTIPADDR,
336fcf3ce44SJohn Forte 			(xmlChar *)inet_ntop(AF_INET6,
337fcf3ce44SJohn Forte 			(void *)attr->value.ip, buff, sizeof (buff)));
338fcf3ce44SJohn Forte 		}
339fcf3ce44SJohn Forte 		if (subchild_node == NULL) {
340fcf3ce44SJohn Forte 		    return (ERR_XML_NEWCHILD_FAILED);
341fcf3ce44SJohn Forte 		}
342fcf3ce44SJohn Forte 	    }
343fcf3ce44SJohn Forte 	    attr = &obj->attrs[ATTR_INDEX_ENTITY(ISNS_TIMESTAMP_ATTR_ID)];
344fcf3ce44SJohn Forte 	    if (attr->value.ui) {
345fcf3ce44SJohn Forte 		(void) sprintf(numbuf, "%u", attr->value.ui);
346fcf3ce44SJohn Forte 		subchild_node = xmlNewChild(sub_node, NULL,
347fcf3ce44SJohn Forte 		(xmlChar *)ENTITYREGTIMESTAMP, (xmlChar *)numbuf);
348fcf3ce44SJohn Forte 		if (subchild_node == NULL) {
349fcf3ce44SJohn Forte 		    return (ERR_XML_NEWCHILD_FAILED);
350fcf3ce44SJohn Forte 		}
351fcf3ce44SJohn Forte 	    }
352fcf3ce44SJohn Forte 	    attr = &obj->attrs[ATTR_INDEX_ENTITY(ISNS_VERSION_RANGE_ATTR_ID)];
353fcf3ce44SJohn Forte 	    if (attr->value.ui) {
354fcf3ce44SJohn Forte 		subchild_node = xmlNewNode(NULL,
355fcf3ce44SJohn Forte 		    (xmlChar *)PROTOCOLVERSIONRANGE);
356fcf3ce44SJohn Forte 		subchild_node = xmlAddChild(sub_node, subchild_node);
357fcf3ce44SJohn Forte 		if (subchild_node == NULL) {
358fcf3ce44SJohn Forte 		    return (ERR_XML_NEWCHILD_FAILED);
359fcf3ce44SJohn Forte 		}
360fcf3ce44SJohn Forte 
361fcf3ce44SJohn Forte 		(void) sprintf(numbuf, "%u",
362fcf3ce44SJohn Forte 		    (attr->value.ui >> ISNS_VER_SHIFT) & ISNS_VERSION);
363fcf3ce44SJohn Forte 		subgrandchild_node = xmlNewChild(subchild_node, NULL,
364fcf3ce44SJohn Forte 		    (xmlChar *)PROTOCOLMAXVERSION, (xmlChar *)numbuf);
365fcf3ce44SJohn Forte 		if (subgrandchild_node == NULL) {
366fcf3ce44SJohn Forte 		    return (ERR_XML_NEWCHILD_FAILED);
367fcf3ce44SJohn Forte 		}
368fcf3ce44SJohn Forte 		(void) sprintf(numbuf, "%u", attr->value.ui & ISNS_VERSION);
369fcf3ce44SJohn Forte 		subgrandchild_node = xmlNewChild(subchild_node, NULL,
370fcf3ce44SJohn Forte 		    (xmlChar *)PROTOCOLMINVERSION, (xmlChar *)numbuf);
371fcf3ce44SJohn Forte 		if (subgrandchild_node == NULL) {
372fcf3ce44SJohn Forte 		    return (ERR_XML_NEWCHILD_FAILED);
373fcf3ce44SJohn Forte 		}
374fcf3ce44SJohn Forte 	    }
375fcf3ce44SJohn Forte 	    attr =
376fcf3ce44SJohn Forte 		&obj->attrs[ATTR_INDEX_ENTITY(ISNS_ENTITY_REG_PERIOD_ATTR_ID)];
377fcf3ce44SJohn Forte 	    if (attr->value.ui) {
378fcf3ce44SJohn Forte 		(void) sprintf(numbuf, "%u", attr->value.ui);
379fcf3ce44SJohn Forte 		subchild_node = xmlNewChild(sub_node, NULL,
380fcf3ce44SJohn Forte 		(xmlChar *)REGISTRATIONPERIOD, (xmlChar *)numbuf);
381fcf3ce44SJohn Forte 		if (subchild_node == NULL) {
382fcf3ce44SJohn Forte 		    return (ERR_XML_NEWCHILD_FAILED);
383fcf3ce44SJohn Forte 		}
384fcf3ce44SJohn Forte 	    }
385fcf3ce44SJohn Forte 	} else {
386fcf3ce44SJohn Forte 	    return (ERR_XML_NEWCHILD_FAILED);
387fcf3ce44SJohn Forte 	}
388fcf3ce44SJohn Forte 
389fcf3ce44SJohn Forte 	/* successful */
390fcf3ce44SJohn Forte 	return (0);
391fcf3ce44SJohn Forte }
392fcf3ce44SJohn Forte 
393fcf3ce44SJohn Forte /*
394fcf3ce44SJohn Forte  * ****************************************************************************
395fcf3ce44SJohn Forte  *
396fcf3ce44SJohn Forte  * cb_get_pg_info: callback for get_node_op
397fcf3ce44SJohn Forte  *	The routine process matching portal group and returns ip address
398fcf3ce44SJohn Forte  *	and port number for further portal processing.
399fcf3ce44SJohn Forte  *
400fcf3ce44SJohn Forte  * p1	- matching portal group object
401fcf3ce44SJohn Forte  * p2	- lookup control data that was used for portal group look up
402fcf3ce44SJohn Forte  *	    returns portal ip address, port and group tag in look up control.
403fcf3ce44SJohn Forte  * return - error code
404fcf3ce44SJohn Forte  *
405fcf3ce44SJohn Forte  * ****************************************************************************
406fcf3ce44SJohn Forte  */
407fcf3ce44SJohn Forte static int
408fcf3ce44SJohn Forte cb_get_pg_info(
409fcf3ce44SJohn Forte 	void *p1,
410fcf3ce44SJohn Forte 	void *p2
411fcf3ce44SJohn Forte )
412fcf3ce44SJohn Forte {
413fcf3ce44SJohn Forte 	isns_obj_t *obj = (isns_obj_t *)p1;
414fcf3ce44SJohn Forte 	lookup_ctrl_t *lcp = (lookup_ctrl_t *)p2;
415fcf3ce44SJohn Forte 
416fcf3ce44SJohn Forte 	isns_attr_t *attr;
417fcf3ce44SJohn Forte 
418fcf3ce44SJohn Forte 	/* get pg portal ip address and port attributes */
419fcf3ce44SJohn Forte 	attr = &obj->attrs[ATTR_INDEX_PG(ISNS_PG_PORTAL_IP_ADDR_ATTR_ID)];
420fcf3ce44SJohn Forte 	(void) memcpy(lcp->data[1].ip, attr->value.ip, sizeof (in6_addr_t));
421fcf3ce44SJohn Forte 	attr = &obj->attrs[ATTR_INDEX_PG(ISNS_PG_PORTAL_PORT_ATTR_ID)];
422fcf3ce44SJohn Forte 	lcp->data[2].ui = attr->value.ui;
423fcf3ce44SJohn Forte 	attr = &obj->attrs[ATTR_INDEX_PG(ISNS_PG_TAG_ATTR_ID)];
424fcf3ce44SJohn Forte 	lcp->id[2] = attr->value.ui;
425fcf3ce44SJohn Forte 
426fcf3ce44SJohn Forte 	/* successful */
427fcf3ce44SJohn Forte 	return (0);
428fcf3ce44SJohn Forte }
429fcf3ce44SJohn Forte 
430fcf3ce44SJohn Forte /*
431fcf3ce44SJohn Forte  * ****************************************************************************
432fcf3ce44SJohn Forte  *
433fcf3ce44SJohn Forte  * cb_get_portal_info: callback for get_node_op
434fcf3ce44SJohn Forte  *	The routine process matching portal and add portal object info to
435fcf3ce44SJohn Forte  *	the node object.
436fcf3ce44SJohn Forte  *
437fcf3ce44SJohn Forte  * p1	- matching portal object
438fcf3ce44SJohn Forte  * p2	- lookup control data that was used for portal look up
439fcf3ce44SJohn Forte  * return - error code
440fcf3ce44SJohn Forte  *
441fcf3ce44SJohn Forte  * ****************************************************************************
442fcf3ce44SJohn Forte  */
443fcf3ce44SJohn Forte static int
444fcf3ce44SJohn Forte cb_get_portal_info(
445fcf3ce44SJohn Forte 	void *p1,
446fcf3ce44SJohn Forte 	void *p2
447fcf3ce44SJohn Forte )
448fcf3ce44SJohn Forte {
449fcf3ce44SJohn Forte 	isns_obj_t *obj = (isns_obj_t *)p1;
450fcf3ce44SJohn Forte 	lookup_ctrl_t *lcp = (lookup_ctrl_t *)p2;
451fcf3ce44SJohn Forte 	xmlNodePtr n_node = (xmlNodePtr)lcp->data[2].ptr;
452fcf3ce44SJohn Forte 	uint32_t    tag = lcp->id[2];
453fcf3ce44SJohn Forte 	xmlNodePtr sub_node, subchild_node, subgrandchild_node;
454fcf3ce44SJohn Forte 	char numbuf[32];
455fcf3ce44SJohn Forte 	char buff[INET6_ADDRSTRLEN + 1] = { 0 };
456fcf3ce44SJohn Forte 	isns_attr_t *attr;
457fcf3ce44SJohn Forte 
458fcf3ce44SJohn Forte 	sub_node = xmlNewChild(n_node, NULL, (xmlChar *)PORTAL, NULL);
459fcf3ce44SJohn Forte 
460fcf3ce44SJohn Forte 	/* get portal object attributes. */
461fcf3ce44SJohn Forte 	if (sub_node) {
462fcf3ce44SJohn Forte 	    attr = &obj->attrs[ATTR_INDEX_PORTAL(ISNS_PORTAL_IP_ADDR_ATTR_ID)];
463fcf3ce44SJohn Forte 	    if (attr->value.ip) {
464fcf3ce44SJohn Forte 		/* convert the ipv6 to ipv4 */
465fcf3ce44SJohn Forte 		if (((int *)attr->value.ip)[0] == 0x00 &&
466fcf3ce44SJohn Forte 		    ((int *)attr->value.ip)[1] == 0x00 &&
467fcf3ce44SJohn Forte 		    ((uchar_t *)attr->value.ip)[8] == 0x00 &&
468fcf3ce44SJohn Forte 		    ((uchar_t *)attr->value.ip)[9] == 0x00 &&
469fcf3ce44SJohn Forte 		    ((uchar_t *)attr->value.ip)[10] == 0xFF &&
470fcf3ce44SJohn Forte 		    ((uchar_t *)attr->value.ip)[11] == 0xFF) {
471fcf3ce44SJohn Forte 		    subchild_node = xmlNewChild(sub_node, NULL,
472fcf3ce44SJohn Forte 			(xmlChar *)IPADDR,
473fcf3ce44SJohn Forte 			(xmlChar *)inet_ntop(AF_INET,
474fcf3ce44SJohn Forte 			(void *)&(((uint32_t *)attr->value.ip)[3]),
475fcf3ce44SJohn Forte 			buff, sizeof (buff)));
476fcf3ce44SJohn Forte 		} else {
477fcf3ce44SJohn Forte 		    subchild_node = xmlNewChild(sub_node, NULL,
478fcf3ce44SJohn Forte 			(xmlChar *)IPADDR,
479fcf3ce44SJohn Forte 			(xmlChar *)inet_ntop(AF_INET6,
480fcf3ce44SJohn Forte 			(void *)attr->value.ip, buff, sizeof (buff)));
481fcf3ce44SJohn Forte 		}
482fcf3ce44SJohn Forte 		if (subchild_node == NULL) {
483fcf3ce44SJohn Forte 		    return (ERR_XML_NEWCHILD_FAILED);
484fcf3ce44SJohn Forte 		}
485fcf3ce44SJohn Forte 	    }
486fcf3ce44SJohn Forte 	    subchild_node = xmlNewChild(sub_node, NULL, (xmlChar *)UDPTCPPORT,
487fcf3ce44SJohn Forte 		NULL);
488fcf3ce44SJohn Forte 	    if (subchild_node) {
489fcf3ce44SJohn Forte 		attr = &obj->attrs[ATTR_INDEX_PORTAL(ISNS_PORTAL_PORT_ATTR_ID)];
490fcf3ce44SJohn Forte 		subgrandchild_node = xmlNewChild(subchild_node, NULL,
491fcf3ce44SJohn Forte 		    (xmlChar *)PORTTYPE, IS_PORT_UDP(attr->value.ui) ?
492fcf3ce44SJohn Forte 		    (xmlChar *)UDPPORT : (xmlChar *)TCPPORT);
493fcf3ce44SJohn Forte 		if (subgrandchild_node == NULL) {
494fcf3ce44SJohn Forte 		    return (ERR_XML_NEWCHILD_FAILED);
495fcf3ce44SJohn Forte 		}
496fcf3ce44SJohn Forte 		(void) sprintf(numbuf, "%u", PORT_NUMBER(attr->value.ui));
497fcf3ce44SJohn Forte 		subgrandchild_node = xmlNewChild(subchild_node, NULL,
498fcf3ce44SJohn Forte 		    (xmlChar *)PORTNUMBER, (xmlChar *)numbuf);
499fcf3ce44SJohn Forte 		if (subgrandchild_node == NULL) {
500fcf3ce44SJohn Forte 		    return (ERR_XML_NEWCHILD_FAILED);
501fcf3ce44SJohn Forte 		}
502fcf3ce44SJohn Forte 	    } else {
503fcf3ce44SJohn Forte 		return (ERR_XML_NEWCHILD_FAILED);
504fcf3ce44SJohn Forte 	    }
505fcf3ce44SJohn Forte 	    (void) sprintf(numbuf, "%u", tag);
506fcf3ce44SJohn Forte 	    subchild_node = xmlNewChild(sub_node, NULL, (xmlChar *)GROUPTAG,
507fcf3ce44SJohn Forte 		(xmlChar *)numbuf);
508fcf3ce44SJohn Forte 	    if (subchild_node == NULL) {
509fcf3ce44SJohn Forte 		return (ERR_XML_NEWCHILD_FAILED);
510fcf3ce44SJohn Forte 	    }
511fcf3ce44SJohn Forte 	    attr = &obj->attrs[ATTR_INDEX_PORTAL(ISNS_PORTAL_NAME_ATTR_ID)];
512fcf3ce44SJohn Forte 	    if (attr->value.ptr) {
513fcf3ce44SJohn Forte 		subchild_node = xmlNewChild(sub_node, NULL,
514fcf3ce44SJohn Forte 		(xmlChar *)SYMBOLICNAME, (xmlChar *)attr->value.ptr);
515fcf3ce44SJohn Forte 		if (subchild_node == NULL) {
516fcf3ce44SJohn Forte 		    return (ERR_XML_NEWCHILD_FAILED);
517fcf3ce44SJohn Forte 		}
518fcf3ce44SJohn Forte 	    }
519fcf3ce44SJohn Forte 	    attr = &obj->attrs[ATTR_INDEX_PORTAL(ISNS_ESI_INTERVAL_ATTR_ID)];
520fcf3ce44SJohn Forte 	    if (attr->value.ui) {
521fcf3ce44SJohn Forte 		(void) sprintf(numbuf, "%u", attr->value.ui);
522fcf3ce44SJohn Forte 		subchild_node = xmlNewChild(sub_node, NULL,
523fcf3ce44SJohn Forte 		(xmlChar *)ESIINTERVAL, (xmlChar *)numbuf);
524fcf3ce44SJohn Forte 		if (subchild_node == NULL) {
525fcf3ce44SJohn Forte 		    return (ERR_XML_NEWCHILD_FAILED);
526fcf3ce44SJohn Forte 		}
527fcf3ce44SJohn Forte 	    }
528fcf3ce44SJohn Forte 	    attr = &obj->attrs[ATTR_INDEX_PORTAL(ISNS_ESI_PORT_ATTR_ID)];
529fcf3ce44SJohn Forte 	    if (attr->value.ui) {
530fcf3ce44SJohn Forte 		subchild_node = xmlNewChild(sub_node, NULL,
531fcf3ce44SJohn Forte 		    (xmlChar *)ESIPORT, NULL);
532fcf3ce44SJohn Forte 		if (subchild_node) {
533fcf3ce44SJohn Forte 		    subgrandchild_node = xmlNewChild(subchild_node, NULL,
534fcf3ce44SJohn Forte 			(xmlChar *)PORTTYPE, IS_PORT_UDP(attr->value.ui) ?
535fcf3ce44SJohn Forte 			(xmlChar *)UDPPORT : (xmlChar *)TCPPORT);
536fcf3ce44SJohn Forte 		    if (subgrandchild_node == NULL) {
537fcf3ce44SJohn Forte 			return (ERR_XML_NEWCHILD_FAILED);
538fcf3ce44SJohn Forte 		    }
539fcf3ce44SJohn Forte 		    (void) sprintf(numbuf, "%u", PORT_NUMBER(attr->value.ui));
540fcf3ce44SJohn Forte 		    subgrandchild_node = xmlNewChild(subchild_node, NULL,
541fcf3ce44SJohn Forte 			(xmlChar *)PORTNUMBER, (xmlChar *)numbuf);
542fcf3ce44SJohn Forte 		    if (subgrandchild_node == NULL) {
543fcf3ce44SJohn Forte 			return (ERR_XML_NEWCHILD_FAILED);
544fcf3ce44SJohn Forte 		    }
545fcf3ce44SJohn Forte 		} else {
546fcf3ce44SJohn Forte 		    return (ERR_XML_NEWCHILD_FAILED);
547fcf3ce44SJohn Forte 		}
548fcf3ce44SJohn Forte 	    }
549fcf3ce44SJohn Forte 	    attr = &obj->attrs[ATTR_INDEX_PORTAL(ISNS_SCN_PORT_ATTR_ID)];
550fcf3ce44SJohn Forte 	    if (attr->value.ui) {
551fcf3ce44SJohn Forte 		subchild_node = xmlNewChild(sub_node, NULL,
552fcf3ce44SJohn Forte 		    (xmlChar *)SCNPORT, NULL);
553fcf3ce44SJohn Forte 		if (subchild_node) {
554fcf3ce44SJohn Forte 		    subgrandchild_node = xmlNewChild(subchild_node, NULL,
555fcf3ce44SJohn Forte 			(xmlChar *)PORTTYPE, IS_PORT_UDP(attr->value.ui) ?
556fcf3ce44SJohn Forte 			(xmlChar *)UDPPORT : (xmlChar *)TCPPORT);
557fcf3ce44SJohn Forte 		    (void) sprintf(numbuf, "%u", PORT_NUMBER(attr->value.ui));
558fcf3ce44SJohn Forte 		    if (subgrandchild_node == NULL) {
559fcf3ce44SJohn Forte 			return (ERR_XML_NEWCHILD_FAILED);
560fcf3ce44SJohn Forte 		    }
561fcf3ce44SJohn Forte 		    subgrandchild_node = xmlNewChild(subchild_node, NULL,
562fcf3ce44SJohn Forte 			(xmlChar *)PORTNUMBER, (xmlChar *)numbuf);
563fcf3ce44SJohn Forte 		    if (subgrandchild_node == NULL) {
564fcf3ce44SJohn Forte 			return (ERR_XML_NEWCHILD_FAILED);
565fcf3ce44SJohn Forte 		    }
566fcf3ce44SJohn Forte 		} else {
567fcf3ce44SJohn Forte 		    return (ERR_XML_NEWCHILD_FAILED);
568fcf3ce44SJohn Forte 		}
569fcf3ce44SJohn Forte 	    }
570fcf3ce44SJohn Forte 	} else if (sub_node == NULL) {
571fcf3ce44SJohn Forte 		return (ERR_XML_NEWCHILD_FAILED);
572fcf3ce44SJohn Forte 	}
573fcf3ce44SJohn Forte 
574fcf3ce44SJohn Forte 	/* successful */
575fcf3ce44SJohn Forte 	return (0);
576fcf3ce44SJohn Forte }
577fcf3ce44SJohn Forte 
578fcf3ce44SJohn Forte /*
579fcf3ce44SJohn Forte  * ****************************************************************************
580fcf3ce44SJohn Forte  *
581fcf3ce44SJohn Forte  * cb_get_dd_info: callback for get_dd_op
582fcf3ce44SJohn Forte  *	The routine process matching dd object
583fcf3ce44SJohn Forte  *
584fcf3ce44SJohn Forte  * p1	- matching dd object
585fcf3ce44SJohn Forte  * p2	- lookup control data that was used for dd look up
586fcf3ce44SJohn Forte  * return - error code
587fcf3ce44SJohn Forte  *
588fcf3ce44SJohn Forte  * ****************************************************************************
589fcf3ce44SJohn Forte  */
590fcf3ce44SJohn Forte static int
591fcf3ce44SJohn Forte cb_get_dd_info(
592fcf3ce44SJohn Forte 	void *p1,
593fcf3ce44SJohn Forte 	void *p2
594fcf3ce44SJohn Forte )
595fcf3ce44SJohn Forte {
596fcf3ce44SJohn Forte 	xmlNodePtr	n_obj, n_node, sub_node, root;
597fcf3ce44SJohn Forte 	xmlAttrPtr	n_attr;
598fcf3ce44SJohn Forte 	isns_attr_t *attr;
599fcf3ce44SJohn Forte 	char numbuf[32];
600fcf3ce44SJohn Forte 
601fcf3ce44SJohn Forte 	isns_obj_t *obj = (isns_obj_t *)p1;
602fcf3ce44SJohn Forte 	lookup_ctrl_t *lcp = (lookup_ctrl_t *)p2;
603fcf3ce44SJohn Forte 	xmlDocPtr doc = (xmlDocPtr)lcp->data[1].ptr;
604fcf3ce44SJohn Forte 
605fcf3ce44SJohn Forte 	root = xmlDocGetRootElement(doc);
606fcf3ce44SJohn Forte 	if (root == NULL) {
607fcf3ce44SJohn Forte 	    return (ERR_SYNTAX_MISSING_ROOT);
608fcf3ce44SJohn Forte 	}
609fcf3ce44SJohn Forte 	n_obj = xmlNewNode(NULL, (xmlChar *)ISNSOBJECT);
610fcf3ce44SJohn Forte 	if (n_obj) {
611fcf3ce44SJohn Forte 	    n_obj = xmlAddChild(root, n_obj);
612fcf3ce44SJohn Forte 	    if (n_obj == NULL) {
613fcf3ce44SJohn Forte 		return (ERR_XML_ADDCHILD_FAILED);
614fcf3ce44SJohn Forte 	    }
615fcf3ce44SJohn Forte 	} else {
616fcf3ce44SJohn Forte 	    return (ERR_XML_ADDCHILD_FAILED);
617fcf3ce44SJohn Forte 	}
618fcf3ce44SJohn Forte 
619fcf3ce44SJohn Forte 	n_node = xmlNewNode(NULL, (xmlChar *)DDOBJECT);
620fcf3ce44SJohn Forte 	if (n_node) {
621fcf3ce44SJohn Forte 	    n_node = xmlAddChild(n_obj, n_node);
622fcf3ce44SJohn Forte 	    if (n_node == NULL) {
623fcf3ce44SJohn Forte 		return (ERR_XML_ADDCHILD_FAILED);
624fcf3ce44SJohn Forte 	    }
625fcf3ce44SJohn Forte 	} else {
626fcf3ce44SJohn Forte 	    return (ERR_XML_ADDCHILD_FAILED);
627fcf3ce44SJohn Forte 	}
628fcf3ce44SJohn Forte 
629fcf3ce44SJohn Forte 	attr = &obj->attrs[ATTR_INDEX_DD(ISNS_DD_NAME_ATTR_ID)];
630fcf3ce44SJohn Forte 	n_attr = xmlSetProp(n_node, (xmlChar *)NAMEATTR,
631fcf3ce44SJohn Forte 		(xmlChar *)attr->value.ptr);
632fcf3ce44SJohn Forte 	if (n_attr == NULL) {
633fcf3ce44SJohn Forte 	    return (ERR_XML_SETPROP_FAILED);
634fcf3ce44SJohn Forte 	}
635fcf3ce44SJohn Forte 	attr = &obj->attrs[ATTR_INDEX_DD(ISNS_DD_ID_ATTR_ID)];
636fcf3ce44SJohn Forte 	(void) sprintf(numbuf, "%u", attr->value.ui);
637fcf3ce44SJohn Forte 	n_attr = xmlSetProp(n_node, (xmlChar *)IDATTR,
638fcf3ce44SJohn Forte 		(xmlChar *)numbuf);
639fcf3ce44SJohn Forte 	if (n_attr == NULL) {
640fcf3ce44SJohn Forte 	    return (ERR_XML_SETPROP_FAILED);
641fcf3ce44SJohn Forte 	}
642fcf3ce44SJohn Forte 	attr = &obj->attrs[ATTR_INDEX_DD(ISNS_DD_FEATURES_ATTR_ID)];
643fcf3ce44SJohn Forte 	if (DD_BOOTLIST_ENABLED(attr->value.ui)) {
644fcf3ce44SJohn Forte 	    sub_node = xmlNewChild(n_node, NULL, (xmlChar *)BOOTLISTENABLEDELEM,
645fcf3ce44SJohn Forte 		(xmlChar *)XMLTRUE);
646fcf3ce44SJohn Forte 	    if (sub_node == NULL) {
647fcf3ce44SJohn Forte 		return (ERR_XML_NEWCHILD_FAILED);
648fcf3ce44SJohn Forte 	    }
649fcf3ce44SJohn Forte 	} else {
650fcf3ce44SJohn Forte 	    sub_node = xmlNewChild(n_node, NULL, (xmlChar *)BOOTLISTENABLEDELEM,
651fcf3ce44SJohn Forte 		(xmlChar *)XMLFALSE);
652fcf3ce44SJohn Forte 	    if (sub_node == NULL) {
653fcf3ce44SJohn Forte 		return (ERR_XML_NEWCHILD_FAILED);
654fcf3ce44SJohn Forte 	    }
655fcf3ce44SJohn Forte 	}
656fcf3ce44SJohn Forte 
657fcf3ce44SJohn Forte 	/* successful */
658fcf3ce44SJohn Forte 	return (0);
659fcf3ce44SJohn Forte }
660fcf3ce44SJohn Forte 
661fcf3ce44SJohn Forte /*
662fcf3ce44SJohn Forte  * ****************************************************************************
663fcf3ce44SJohn Forte  *
664fcf3ce44SJohn Forte  * cb_get_ddset_info: callback for get_ddset_op
665fcf3ce44SJohn Forte  *	The routine process matching dd object
666fcf3ce44SJohn Forte  *
667fcf3ce44SJohn Forte  * p1	- matching dds object
668fcf3ce44SJohn Forte  * p2	- lookup control data that was used for dd set look up
669fcf3ce44SJohn Forte  * return - error code
670fcf3ce44SJohn Forte  *
671fcf3ce44SJohn Forte  * ****************************************************************************
672fcf3ce44SJohn Forte  */
673fcf3ce44SJohn Forte static int
674fcf3ce44SJohn Forte cb_get_ddset_info(
675fcf3ce44SJohn Forte 	void *p1,
676fcf3ce44SJohn Forte 	void *p2
677fcf3ce44SJohn Forte )
678fcf3ce44SJohn Forte {
679fcf3ce44SJohn Forte 	xmlNodePtr	n_obj, n_node, sub_node, root;
680fcf3ce44SJohn Forte 	xmlAttrPtr	n_attr;
681fcf3ce44SJohn Forte 	isns_attr_t *attr;
682fcf3ce44SJohn Forte 	char numbuf[32];
683fcf3ce44SJohn Forte 
684fcf3ce44SJohn Forte 	isns_obj_t *obj = (isns_obj_t *)p1;
685fcf3ce44SJohn Forte 	lookup_ctrl_t *lcp = (lookup_ctrl_t *)p2;
686fcf3ce44SJohn Forte 	xmlDocPtr doc = (xmlDocPtr)lcp->data[1].ptr;
687fcf3ce44SJohn Forte 
688fcf3ce44SJohn Forte 	root = xmlDocGetRootElement(doc);
689fcf3ce44SJohn Forte 	if (root == NULL) {
690fcf3ce44SJohn Forte 	    return (ERR_SYNTAX_MISSING_ROOT);
691fcf3ce44SJohn Forte 	}
692fcf3ce44SJohn Forte 
693fcf3ce44SJohn Forte 	n_obj = xmlNewNode(NULL, (xmlChar *)ISNSOBJECT);
694fcf3ce44SJohn Forte 	if (n_obj) {
695fcf3ce44SJohn Forte 	    n_obj = xmlAddChild(root, n_obj);
696fcf3ce44SJohn Forte 	    if (n_obj == NULL) {
697fcf3ce44SJohn Forte 		return (ERR_XML_NEWCHILD_FAILED);
698fcf3ce44SJohn Forte 	    }
699fcf3ce44SJohn Forte 	} else {
700fcf3ce44SJohn Forte 	    return (ERR_XML_NEWNODE_FAILED);
701fcf3ce44SJohn Forte 	}
702fcf3ce44SJohn Forte 
703fcf3ce44SJohn Forte 	n_node = xmlNewNode(NULL, (xmlChar *)DDSETOBJECT);
704fcf3ce44SJohn Forte 	if (n_node) {
705fcf3ce44SJohn Forte 	    n_node = xmlAddChild(n_obj, n_node);
706fcf3ce44SJohn Forte 	    if (n_node == NULL) {
707fcf3ce44SJohn Forte 		return (ERR_XML_ADDCHILD_FAILED);
708fcf3ce44SJohn Forte 	    }
709fcf3ce44SJohn Forte 	} else {
710fcf3ce44SJohn Forte 	    return (ERR_XML_NEWNODE_FAILED);
711fcf3ce44SJohn Forte 	}
712fcf3ce44SJohn Forte 
713fcf3ce44SJohn Forte 	/* get node name, alias, type and generate xml info */
714fcf3ce44SJohn Forte 	attr = &obj->attrs[ATTR_INDEX_DDS(ISNS_DD_SET_NAME_ATTR_ID)];
715fcf3ce44SJohn Forte 	n_attr = xmlSetProp(n_node, (xmlChar *)NAMEATTR,
716fcf3ce44SJohn Forte 		(xmlChar *)attr->value.ptr);
717fcf3ce44SJohn Forte 	if (n_attr == NULL) {
718fcf3ce44SJohn Forte 	    return (ERR_XML_SETPROP_FAILED);
719fcf3ce44SJohn Forte 	}
720fcf3ce44SJohn Forte 	attr = &obj->attrs[ATTR_INDEX_DDS(ISNS_DD_SET_ID_ATTR_ID)];
721fcf3ce44SJohn Forte 	(void) sprintf(numbuf, "%u", attr->value.ui);
722fcf3ce44SJohn Forte 	n_attr = xmlSetProp(n_node, (xmlChar *)IDATTR,
723fcf3ce44SJohn Forte 		(xmlChar *)numbuf);
724fcf3ce44SJohn Forte 	if (n_attr == NULL) {
725fcf3ce44SJohn Forte 	    return (ERR_XML_SETPROP_FAILED);
726fcf3ce44SJohn Forte 	}
727fcf3ce44SJohn Forte 	attr = &obj->attrs[ATTR_INDEX_DDS(ISNS_DD_SET_STATUS_ATTR_ID)];
728fcf3ce44SJohn Forte 	if (DDS_ENABLED(attr->value.ui)) {
729fcf3ce44SJohn Forte 	    sub_node = xmlNewChild(n_node, NULL, (xmlChar *)ENABLEDELEM,
730fcf3ce44SJohn Forte 		(xmlChar *)XMLTRUE);
731fcf3ce44SJohn Forte 	    if (sub_node == NULL) {
732fcf3ce44SJohn Forte 		return (ERR_XML_NEWCHILD_FAILED);
733fcf3ce44SJohn Forte 	    }
734fcf3ce44SJohn Forte 	} else {
735fcf3ce44SJohn Forte 	    sub_node = xmlNewChild(n_node, NULL, (xmlChar *)ENABLEDELEM,
736fcf3ce44SJohn Forte 		(xmlChar *)XMLFALSE);
737fcf3ce44SJohn Forte 	    if (sub_node == NULL) {
738fcf3ce44SJohn Forte 		return (ERR_XML_NEWCHILD_FAILED);
739fcf3ce44SJohn Forte 	    }
740fcf3ce44SJohn Forte 	}
741fcf3ce44SJohn Forte 
742fcf3ce44SJohn Forte 	/* successful */
743fcf3ce44SJohn Forte 	return (0);
744fcf3ce44SJohn Forte }
745fcf3ce44SJohn Forte 
746fcf3ce44SJohn Forte /*
747fcf3ce44SJohn Forte  * ****************************************************************************
748fcf3ce44SJohn Forte  *
749fcf3ce44SJohn Forte  * cb_enumerate_node_info: callback for enumerate_node_op
750fcf3ce44SJohn Forte  *	The routine is invoked for each node object.
751fcf3ce44SJohn Forte  *
752fcf3ce44SJohn Forte  * p1	- node object
753fcf3ce44SJohn Forte  * p2	- lookup control data that was used for node look up
754fcf3ce44SJohn Forte  * return - error code
755fcf3ce44SJohn Forte  *
756fcf3ce44SJohn Forte  * ****************************************************************************
757fcf3ce44SJohn Forte  */
758fcf3ce44SJohn Forte static int
759fcf3ce44SJohn Forte cb_enumerate_node_info(
760fcf3ce44SJohn Forte 	void *p1,
761fcf3ce44SJohn Forte 	void *p2
762fcf3ce44SJohn Forte )
763fcf3ce44SJohn Forte {
764fcf3ce44SJohn Forte 	xmlNodePtr	n_obj, n_node, root;
765fcf3ce44SJohn Forte 	xmlAttrPtr	n_attr;
766fcf3ce44SJohn Forte 	isns_attr_t *attr;
767fcf3ce44SJohn Forte 
768fcf3ce44SJohn Forte 	isns_obj_t *obj = (isns_obj_t *)p1;
769fcf3ce44SJohn Forte 	lookup_ctrl_t *lcp = (lookup_ctrl_t *)p2;
770fcf3ce44SJohn Forte 	xmlDocPtr doc = (xmlDocPtr)lcp->data[1].ptr;
771fcf3ce44SJohn Forte 
772fcf3ce44SJohn Forte 	root = xmlDocGetRootElement(doc);
773fcf3ce44SJohn Forte 	if (root == NULL) {
774fcf3ce44SJohn Forte 	    return (ERR_SYNTAX_MISSING_ROOT);
775fcf3ce44SJohn Forte 	}
776fcf3ce44SJohn Forte 
777fcf3ce44SJohn Forte 	n_obj = xmlNewNode(NULL, (xmlChar *)ISNSOBJECT);
778fcf3ce44SJohn Forte 	if (n_obj) {
779fcf3ce44SJohn Forte 	    n_obj = xmlAddChild(root, n_obj);
780fcf3ce44SJohn Forte 	    if (n_obj == NULL) {
781fcf3ce44SJohn Forte 		return (ERR_XML_ADDCHILD_FAILED);
782fcf3ce44SJohn Forte 	    }
783fcf3ce44SJohn Forte 	} else {
784fcf3ce44SJohn Forte 	    return (ERR_XML_NEWNODE_FAILED);
785fcf3ce44SJohn Forte 	}
786fcf3ce44SJohn Forte 
787fcf3ce44SJohn Forte 	n_node = xmlNewNode(NULL, (xmlChar *)NODEOBJECT);
788fcf3ce44SJohn Forte 	if (n_node) {
789fcf3ce44SJohn Forte 	    n_node = xmlAddChild(n_obj, n_node);
790fcf3ce44SJohn Forte 	    if (n_node == NULL) {
791fcf3ce44SJohn Forte 		return (ERR_XML_ADDCHILD_FAILED);
792fcf3ce44SJohn Forte 	    }
793fcf3ce44SJohn Forte 	} else {
794fcf3ce44SJohn Forte 	    return (ERR_XML_NEWNODE_FAILED);
795fcf3ce44SJohn Forte 	}
796fcf3ce44SJohn Forte 
797fcf3ce44SJohn Forte 	/* get node name, alias, type and generate xml info */
798fcf3ce44SJohn Forte 	attr = &obj->attrs[ATTR_INDEX_ISCSI(ISNS_ISCSI_NAME_ATTR_ID)];
799fcf3ce44SJohn Forte 	n_attr = xmlSetProp(n_node, (xmlChar *)NAMEATTR,
800fcf3ce44SJohn Forte 		(xmlChar *)attr->value.ptr);
801fcf3ce44SJohn Forte 	if (n_attr == NULL) {
802fcf3ce44SJohn Forte 	    return (ERR_XML_SETPROP_FAILED);
803fcf3ce44SJohn Forte 	}
804fcf3ce44SJohn Forte 	attr = &obj->attrs[ATTR_INDEX_ISCSI(ISNS_ISCSI_NODE_TYPE_ATTR_ID)];
805fcf3ce44SJohn Forte 	switch (attr->value.ui) {
806fcf3ce44SJohn Forte 	    case ISNS_CONTROL_NODE_TYPE | ISNS_INITIATOR_NODE_TYPE:
807fcf3ce44SJohn Forte 		n_attr = xmlSetProp(n_node, (xmlChar *)TYPEATTR,
808fcf3ce44SJohn Forte 		    (xmlChar *)CONTROLNODEINITIATORTYPE);
809fcf3ce44SJohn Forte 		break;
810fcf3ce44SJohn Forte 	    case ISNS_CONTROL_NODE_TYPE | ISNS_TARGET_NODE_TYPE:
811fcf3ce44SJohn Forte 		n_attr = xmlSetProp(n_node, (xmlChar *)TYPEATTR,
812fcf3ce44SJohn Forte 		    (xmlChar *)CONTROLNODETARGETTYPE);
813fcf3ce44SJohn Forte 		break;
814fcf3ce44SJohn Forte 	    case ISNS_TARGET_NODE_TYPE:
815fcf3ce44SJohn Forte 		n_attr = xmlSetProp(n_node, (xmlChar *)TYPEATTR,
816fcf3ce44SJohn Forte 		    (xmlChar *)TARGETTYPE);
817fcf3ce44SJohn Forte 		break;
818fcf3ce44SJohn Forte 	    case ISNS_INITIATOR_NODE_TYPE:
819fcf3ce44SJohn Forte 		n_attr = xmlSetProp(n_node, (xmlChar *)TYPEATTR,
820fcf3ce44SJohn Forte 		    (xmlChar *)INITIATORTYPE);
821fcf3ce44SJohn Forte 		break;
822fcf3ce44SJohn Forte 	    case ISNS_CONTROL_NODE_TYPE:
823fcf3ce44SJohn Forte 		n_attr = xmlSetProp(n_node, (xmlChar *)TYPEATTR,
824fcf3ce44SJohn Forte 		    (xmlChar *)CONTROLNODETYPE);
825fcf3ce44SJohn Forte 		break;
826fcf3ce44SJohn Forte 	    default:
827fcf3ce44SJohn Forte 	    n_attr = xmlSetProp(n_node, (xmlChar *)TYPEATTR,
828fcf3ce44SJohn Forte 		    (xmlChar *)UNKNOWNTYPE);
829fcf3ce44SJohn Forte 	}
830fcf3ce44SJohn Forte 	if (n_attr == NULL) {
831fcf3ce44SJohn Forte 	    return (ERR_XML_SETPROP_FAILED);
832fcf3ce44SJohn Forte 	}
833fcf3ce44SJohn Forte 	attr = &obj->attrs[ATTR_INDEX_ISCSI(ISNS_ISCSI_ALIAS_ATTR_ID)];
834fcf3ce44SJohn Forte 	n_attr = xmlSetProp(n_node, (xmlChar *)ALIASATTR,
835fcf3ce44SJohn Forte 		(xmlChar *)attr->value.ptr);
836fcf3ce44SJohn Forte 	if (n_attr == NULL) {
837fcf3ce44SJohn Forte 	    return (ERR_XML_SETPROP_FAILED);
838fcf3ce44SJohn Forte 	}
839fcf3ce44SJohn Forte 
840fcf3ce44SJohn Forte 	/* successful */
841fcf3ce44SJohn Forte 	return (0);
842fcf3ce44SJohn Forte }
843fcf3ce44SJohn Forte 
844fcf3ce44SJohn Forte /*
845fcf3ce44SJohn Forte  * ****************************************************************************
846fcf3ce44SJohn Forte  *
847fcf3ce44SJohn Forte  * i_enumerate_dd_dds_info:
848fcf3ce44SJohn Forte  *	The routine is implemnetation for enumerate dd and enumerate dds.
849fcf3ce44SJohn Forte  *
850fcf3ce44SJohn Forte  * p1	- dd or dd set object
851fcf3ce44SJohn Forte  * p2	- lookup control data that was used for dd and dd set look up
852fcf3ce44SJohn Forte  * return - error code
853fcf3ce44SJohn Forte  *
854fcf3ce44SJohn Forte  * ****************************************************************************
855fcf3ce44SJohn Forte  */
856fcf3ce44SJohn Forte static int
857fcf3ce44SJohn Forte i_enumerate_dd_dds_info(
858fcf3ce44SJohn Forte 	void *p1,
859fcf3ce44SJohn Forte 	void *p2,
860fcf3ce44SJohn Forte 	isns_type_t obj_type
861fcf3ce44SJohn Forte )
862fcf3ce44SJohn Forte {
863fcf3ce44SJohn Forte 	xmlNodePtr	n_obj, n_node, sub_node, root;
864fcf3ce44SJohn Forte 	xmlAttrPtr	n_attr;
865fcf3ce44SJohn Forte 	isns_attr_t *attr;
866fcf3ce44SJohn Forte 	char numbuf[32];
867fcf3ce44SJohn Forte 
868fcf3ce44SJohn Forte 	isns_obj_t *obj = (isns_obj_t *)p1;
869fcf3ce44SJohn Forte 	lookup_ctrl_t *lcp = (lookup_ctrl_t *)p2;
870fcf3ce44SJohn Forte 	xmlDocPtr doc = (xmlDocPtr)lcp->data[1].ptr;
871fcf3ce44SJohn Forte 
872fcf3ce44SJohn Forte 	root = xmlDocGetRootElement(doc);
873fcf3ce44SJohn Forte 	if (root == NULL) {
874fcf3ce44SJohn Forte 	    return (ERR_SYNTAX_MISSING_ROOT);
875fcf3ce44SJohn Forte 	}
876fcf3ce44SJohn Forte 
877fcf3ce44SJohn Forte 	n_obj = xmlNewNode(NULL, (xmlChar *)ISNSOBJECT);
878fcf3ce44SJohn Forte 	if (n_obj) {
879fcf3ce44SJohn Forte 	    n_obj = xmlAddChild(root, n_obj);
880fcf3ce44SJohn Forte 	    if (n_obj == NULL) {
881fcf3ce44SJohn Forte 		return (ERR_XML_ADDCHILD_FAILED);
882fcf3ce44SJohn Forte 	    }
883fcf3ce44SJohn Forte 	} else {
884fcf3ce44SJohn Forte 	    return (ERR_XML_NEWNODE_FAILED);
885fcf3ce44SJohn Forte 	}
886fcf3ce44SJohn Forte 
887fcf3ce44SJohn Forte 	if (obj_type == OBJ_DD) {
888fcf3ce44SJohn Forte 	    n_node = xmlNewNode(NULL, (xmlChar *)DDOBJECT);
889fcf3ce44SJohn Forte 	} else {
890fcf3ce44SJohn Forte 	    n_node = xmlNewNode(NULL, (xmlChar *)DDSETOBJECT);
891fcf3ce44SJohn Forte 	}
892fcf3ce44SJohn Forte 
893fcf3ce44SJohn Forte 	if (n_node) {
894fcf3ce44SJohn Forte 	    n_node = xmlAddChild(n_obj, n_node);
895fcf3ce44SJohn Forte 	    if (n_node == NULL) {
896fcf3ce44SJohn Forte 		return (ERR_XML_ADDCHILD_FAILED);
897fcf3ce44SJohn Forte 	    }
898fcf3ce44SJohn Forte 	} else {
899fcf3ce44SJohn Forte 	    return (ERR_XML_NEWNODE_FAILED);
900fcf3ce44SJohn Forte 	}
901fcf3ce44SJohn Forte 
902fcf3ce44SJohn Forte 	if (obj_type == OBJ_DD) {
903fcf3ce44SJohn Forte 	    /* get name, id, feaure and generate xml info */
904fcf3ce44SJohn Forte 	    attr = &obj->attrs[ATTR_INDEX_DD(ISNS_DD_NAME_ATTR_ID)];
905fcf3ce44SJohn Forte 	    n_attr = xmlSetProp(n_node, (xmlChar *)NAMEATTR,
906fcf3ce44SJohn Forte 		(xmlChar *)attr->value.ptr);
907fcf3ce44SJohn Forte 	    if (n_attr == NULL) {
908fcf3ce44SJohn Forte 		return (ERR_XML_SETPROP_FAILED);
909fcf3ce44SJohn Forte 	    }
910fcf3ce44SJohn Forte 	    attr = &obj->attrs[ATTR_INDEX_DD(ISNS_DD_ID_ATTR_ID)];
911fcf3ce44SJohn Forte 	    (void) sprintf(numbuf, "%u", attr->value.ui);
912fcf3ce44SJohn Forte 	    n_attr = xmlSetProp(n_node, (xmlChar *)IDATTR,
913fcf3ce44SJohn Forte 		(xmlChar *)numbuf);
914fcf3ce44SJohn Forte 	    if (n_attr == NULL) {
915fcf3ce44SJohn Forte 		return (ERR_XML_SETPROP_FAILED);
916fcf3ce44SJohn Forte 	    }
917fcf3ce44SJohn Forte 	    attr = &obj->attrs[ATTR_INDEX_DD(ISNS_DD_FEATURES_ATTR_ID)];
918fcf3ce44SJohn Forte 	    if (DD_BOOTLIST_ENABLED(attr->value.ui)) {
919fcf3ce44SJohn Forte 		sub_node = xmlNewChild(n_node, NULL,
920fcf3ce44SJohn Forte 		    (xmlChar *)BOOTLISTENABLEDELEM, (xmlChar *)XMLTRUE);
921fcf3ce44SJohn Forte 		if (sub_node == NULL) {
922fcf3ce44SJohn Forte 		    return (ERR_XML_NEWCHILD_FAILED);
923fcf3ce44SJohn Forte 		}
924fcf3ce44SJohn Forte 	    } else {
925fcf3ce44SJohn Forte 		sub_node = xmlNewChild(n_node, NULL,
926fcf3ce44SJohn Forte 		    (xmlChar *)BOOTLISTENABLEDELEM, (xmlChar *)XMLFALSE);
927fcf3ce44SJohn Forte 		if (sub_node == NULL) {
928fcf3ce44SJohn Forte 		    return (ERR_XML_NEWCHILD_FAILED);
929fcf3ce44SJohn Forte 		}
930fcf3ce44SJohn Forte 	    }
931fcf3ce44SJohn Forte 	} else {
932fcf3ce44SJohn Forte 	    /* get name, id, status and generate xml info */
933fcf3ce44SJohn Forte 	    attr = &obj->attrs[ATTR_INDEX_DDS(ISNS_DD_SET_NAME_ATTR_ID)];
934fcf3ce44SJohn Forte 	    n_attr = xmlSetProp(n_node, (xmlChar *)NAMEATTR,
935fcf3ce44SJohn Forte 		(xmlChar *)attr->value.ptr);
936fcf3ce44SJohn Forte 	    if (n_attr == NULL) {
937fcf3ce44SJohn Forte 		return (ERR_XML_SETPROP_FAILED);
938fcf3ce44SJohn Forte 	    }
939fcf3ce44SJohn Forte 	    attr = &obj->attrs[ATTR_INDEX_DDS(ISNS_DD_SET_ID_ATTR_ID)];
940fcf3ce44SJohn Forte 	    (void) sprintf(numbuf, "%u", attr->value.ui);
941fcf3ce44SJohn Forte 	    n_attr = xmlSetProp(n_node, (xmlChar *)IDATTR,
942fcf3ce44SJohn Forte 		(xmlChar *)numbuf);
943fcf3ce44SJohn Forte 	    if (n_attr == NULL) {
944fcf3ce44SJohn Forte 		return (ERR_XML_SETPROP_FAILED);
945fcf3ce44SJohn Forte 	    }
946fcf3ce44SJohn Forte 	    attr = &obj->attrs[ATTR_INDEX_DDS(ISNS_DD_SET_STATUS_ATTR_ID)];
947fcf3ce44SJohn Forte 	    if (DDS_ENABLED(attr->value.ui)) {
948fcf3ce44SJohn Forte 		sub_node = xmlNewChild(n_node, NULL,
949fcf3ce44SJohn Forte 		    (xmlChar *)ENABLEDELEM, (xmlChar *)XMLTRUE);
950fcf3ce44SJohn Forte 		if (sub_node == NULL) {
951fcf3ce44SJohn Forte 		    return (ERR_XML_NEWCHILD_FAILED);
952fcf3ce44SJohn Forte 		}
953fcf3ce44SJohn Forte 	    } else {
954fcf3ce44SJohn Forte 		sub_node = xmlNewChild(n_node, NULL,
955fcf3ce44SJohn Forte 		    (xmlChar *)ENABLEDELEM, (xmlChar *)XMLFALSE);
956fcf3ce44SJohn Forte 		if (sub_node == NULL) {
957fcf3ce44SJohn Forte 		    return (ERR_XML_NEWCHILD_FAILED);
958fcf3ce44SJohn Forte 		}
959fcf3ce44SJohn Forte 	    }
960fcf3ce44SJohn Forte 	}
961fcf3ce44SJohn Forte 
962fcf3ce44SJohn Forte 	/* successful */
963fcf3ce44SJohn Forte 	return (0);
964fcf3ce44SJohn Forte }
965fcf3ce44SJohn Forte 
966fcf3ce44SJohn Forte /*
967fcf3ce44SJohn Forte  * ****************************************************************************
968fcf3ce44SJohn Forte  *
969fcf3ce44SJohn Forte  * cb_enumerate_dd_info: callback for enumerate_dd_op
970fcf3ce44SJohn Forte  *	The routine is invoked for each dd object.
971fcf3ce44SJohn Forte  *
972fcf3ce44SJohn Forte  * p1	- dd object
973fcf3ce44SJohn Forte  * p2	- lookup control data that was used for dd look up
974fcf3ce44SJohn Forte  * return - error code
975fcf3ce44SJohn Forte  *
976fcf3ce44SJohn Forte  * ****************************************************************************
977fcf3ce44SJohn Forte  */
978fcf3ce44SJohn Forte static int
979fcf3ce44SJohn Forte cb_enumerate_dd_info(
980fcf3ce44SJohn Forte 	void *p1,
981fcf3ce44SJohn Forte 	void *p2
982fcf3ce44SJohn Forte )
983fcf3ce44SJohn Forte {
984fcf3ce44SJohn Forte 	return (i_enumerate_dd_dds_info(p1, p2, OBJ_DD));
985fcf3ce44SJohn Forte }
986fcf3ce44SJohn Forte 
987fcf3ce44SJohn Forte /*
988fcf3ce44SJohn Forte  * ****************************************************************************
989fcf3ce44SJohn Forte  *
990fcf3ce44SJohn Forte  * cb_enumerate_ddset_info: callback for enumerate_dd_op
991fcf3ce44SJohn Forte  *	The routine is invoked for each dd object.
992fcf3ce44SJohn Forte  *
993fcf3ce44SJohn Forte  * p1	- dd object
994fcf3ce44SJohn Forte  * p2	- lookup control data that was used for dd set look up
995fcf3ce44SJohn Forte  * return - error code
996fcf3ce44SJohn Forte  *
997fcf3ce44SJohn Forte  * ****************************************************************************
998fcf3ce44SJohn Forte  */
999fcf3ce44SJohn Forte static int
1000fcf3ce44SJohn Forte cb_enumerate_ddset_info(
1001fcf3ce44SJohn Forte 	void *p1,
1002fcf3ce44SJohn Forte 	void *p2
1003fcf3ce44SJohn Forte )
1004fcf3ce44SJohn Forte {
1005fcf3ce44SJohn Forte 	return (i_enumerate_dd_dds_info(p1, p2, OBJ_DDS));
1006fcf3ce44SJohn Forte }
1007fcf3ce44SJohn Forte 
1008fcf3ce44SJohn Forte /*
1009fcf3ce44SJohn Forte  * ****************************************************************************
1010fcf3ce44SJohn Forte  *
1011fcf3ce44SJohn Forte  * cb_getAssociated_node_info:
1012fcf3ce44SJohn Forte  *	The routine is implemnetation for enumerate dd and enumerate dds.
1013fcf3ce44SJohn Forte  *
1014fcf3ce44SJohn Forte  * p1	- dd or dd set object
1015fcf3ce44SJohn Forte  * p2	- lookup control data that was used for dd and dd set look up
1016fcf3ce44SJohn Forte  * return - error code
1017fcf3ce44SJohn Forte  *
1018fcf3ce44SJohn Forte  * ****************************************************************************
1019fcf3ce44SJohn Forte  */
1020fcf3ce44SJohn Forte static int
1021fcf3ce44SJohn Forte cb_getAssociated_node_info(
1022fcf3ce44SJohn Forte 	void *p1,
1023fcf3ce44SJohn Forte 	void *p2
1024fcf3ce44SJohn Forte )
1025fcf3ce44SJohn Forte {
1026fcf3ce44SJohn Forte 	xmlNodePtr	n_obj, n_node, root;
1027fcf3ce44SJohn Forte 	xmlAttrPtr	n_attr;
1028fcf3ce44SJohn Forte 	isns_attr_t *attr;
1029fcf3ce44SJohn Forte 
1030fcf3ce44SJohn Forte 	isns_obj_t *obj = (isns_obj_t *)p1;
1031fcf3ce44SJohn Forte 	lookup_ctrl_t *lcp = (lookup_ctrl_t *)p2;
1032fcf3ce44SJohn Forte 	xmlDocPtr doc = (xmlDocPtr)lcp->data[1].ptr;
1033fcf3ce44SJohn Forte 	uchar_t *ddname = lcp->data[2].ptr;
1034fcf3ce44SJohn Forte 
1035fcf3ce44SJohn Forte 	root = xmlDocGetRootElement(doc);
1036fcf3ce44SJohn Forte 	if (root == NULL) {
1037fcf3ce44SJohn Forte 	    return (ERR_SYNTAX_MISSING_ROOT);
1038fcf3ce44SJohn Forte 	}
1039fcf3ce44SJohn Forte 	n_obj = xmlNewNode(NULL, (xmlChar *)ASSOCIATION);
1040fcf3ce44SJohn Forte 	if (n_obj) {
1041fcf3ce44SJohn Forte 	    n_obj = xmlAddChild(root, n_obj);
1042fcf3ce44SJohn Forte 	    if (n_obj == NULL) {
1043fcf3ce44SJohn Forte 		return (ERR_XML_ADDCHILD_FAILED);
1044fcf3ce44SJohn Forte 	    }
1045fcf3ce44SJohn Forte 	} else {
1046fcf3ce44SJohn Forte 	    return (ERR_XML_NEWNODE_FAILED);
1047fcf3ce44SJohn Forte 	}
1048fcf3ce44SJohn Forte 
1049fcf3ce44SJohn Forte 	n_node = xmlNewNode(NULL, (xmlChar *)DDOBJECTMEMBER);
1050fcf3ce44SJohn Forte 	if (n_node) {
1051fcf3ce44SJohn Forte 	    n_node = xmlAddChild(n_obj, n_node);
1052fcf3ce44SJohn Forte 	    if (n_node == NULL) {
1053fcf3ce44SJohn Forte 		return (ERR_XML_ADDCHILD_FAILED);
1054fcf3ce44SJohn Forte 	    }
1055fcf3ce44SJohn Forte 	} else {
1056fcf3ce44SJohn Forte 	    return (ERR_XML_NEWNODE_FAILED);
1057fcf3ce44SJohn Forte 	}
1058fcf3ce44SJohn Forte 
1059fcf3ce44SJohn Forte 	/* get node name, alias, type and generate xml info */
1060fcf3ce44SJohn Forte 	attr = &obj->attrs[ATTR_INDEX_ISCSI(ISNS_ISCSI_NAME_ATTR_ID)];
1061fcf3ce44SJohn Forte 	n_attr = xmlSetProp(n_node, (xmlChar *)NODENAMEATTR,
1062fcf3ce44SJohn Forte 		(xmlChar *)attr->value.ptr);
1063fcf3ce44SJohn Forte 	if (n_attr == NULL) {
1064fcf3ce44SJohn Forte 	    return (ERR_XML_SETPROP_FAILED);
1065fcf3ce44SJohn Forte 	}
1066fcf3ce44SJohn Forte 	n_attr = xmlSetProp(n_node, (xmlChar *)DDNAMEATTR,
1067fcf3ce44SJohn Forte 		(xmlChar *)ddname);
1068fcf3ce44SJohn Forte 	if (n_attr == NULL) {
1069fcf3ce44SJohn Forte 	    return (ERR_XML_SETPROP_FAILED);
1070fcf3ce44SJohn Forte 	}
1071fcf3ce44SJohn Forte 
1072fcf3ce44SJohn Forte 	/* successful */
1073fcf3ce44SJohn Forte 	return (0);
1074fcf3ce44SJohn Forte }
1075fcf3ce44SJohn Forte 
1076fcf3ce44SJohn Forte /*
1077fcf3ce44SJohn Forte  * ****************************************************************************
1078fcf3ce44SJohn Forte  *
1079fcf3ce44SJohn Forte  * cb_getAssociated_node_to_dd_info:
1080fcf3ce44SJohn Forte  *	The routine is implemnetation for enumerate dd and enumerate dds.
1081fcf3ce44SJohn Forte  *
1082fcf3ce44SJohn Forte  * p1	- dd or dd set object
1083fcf3ce44SJohn Forte  * p2	- lookup control data that was used for dd and dd set look up
1084fcf3ce44SJohn Forte  * return - error code
1085fcf3ce44SJohn Forte  *
1086fcf3ce44SJohn Forte  * ****************************************************************************
1087fcf3ce44SJohn Forte  */
1088fcf3ce44SJohn Forte static int
1089fcf3ce44SJohn Forte cb_getAssociated_node_to_dd_info(
1090fcf3ce44SJohn Forte 	void *p1,
1091fcf3ce44SJohn Forte 	void *p2
1092fcf3ce44SJohn Forte )
1093fcf3ce44SJohn Forte {
1094fcf3ce44SJohn Forte 	xmlNodePtr	n_obj, n_node, root;
1095fcf3ce44SJohn Forte 	xmlAttrPtr	n_attr;
1096fcf3ce44SJohn Forte 	isns_attr_t *attr;
1097fcf3ce44SJohn Forte 
1098fcf3ce44SJohn Forte 	isns_obj_t *obj = (isns_obj_t *)p1;
1099fcf3ce44SJohn Forte 	lookup_ctrl_t *lcp = (lookup_ctrl_t *)p2;
1100fcf3ce44SJohn Forte 	xmlDocPtr doc = (xmlDocPtr)lcp->data[1].ptr;
1101fcf3ce44SJohn Forte 	uchar_t *nodename = lcp->data[2].ptr;
1102fcf3ce44SJohn Forte 
1103fcf3ce44SJohn Forte 	root = xmlDocGetRootElement(doc);
1104fcf3ce44SJohn Forte 	if (root == NULL) {
1105fcf3ce44SJohn Forte 	    return (ERR_SYNTAX_MISSING_ROOT);
1106fcf3ce44SJohn Forte 	}
1107fcf3ce44SJohn Forte 	n_obj = xmlNewNode(NULL, (xmlChar *)ASSOCIATION);
1108fcf3ce44SJohn Forte 	if (n_obj) {
1109fcf3ce44SJohn Forte 	    n_obj = xmlAddChild(root, n_obj);
1110fcf3ce44SJohn Forte 	    if (n_obj == NULL) {
1111fcf3ce44SJohn Forte 		return (ERR_XML_ADDCHILD_FAILED);
1112fcf3ce44SJohn Forte 	    }
1113fcf3ce44SJohn Forte 	} else {
1114fcf3ce44SJohn Forte 	    return (ERR_XML_NEWNODE_FAILED);
1115fcf3ce44SJohn Forte 	}
1116fcf3ce44SJohn Forte 
1117fcf3ce44SJohn Forte 	n_node = xmlNewNode(NULL, (xmlChar *)DDOBJECTMEMBER);
1118fcf3ce44SJohn Forte 	if (n_node) {
1119fcf3ce44SJohn Forte 	    n_node = xmlAddChild(n_obj, n_node);
1120fcf3ce44SJohn Forte 	    if (n_node == NULL) {
1121fcf3ce44SJohn Forte 		return (ERR_XML_ADDCHILD_FAILED);
1122fcf3ce44SJohn Forte 	    }
1123fcf3ce44SJohn Forte 	} else {
1124fcf3ce44SJohn Forte 	    return (ERR_XML_NEWNODE_FAILED);
1125fcf3ce44SJohn Forte 	}
1126fcf3ce44SJohn Forte 
1127fcf3ce44SJohn Forte 	/* get node name, alias, type and generate xml info */
1128fcf3ce44SJohn Forte 	n_attr = xmlSetProp(n_node, (xmlChar *)NODENAMEATTR,
1129fcf3ce44SJohn Forte 		(xmlChar *)nodename);
1130fcf3ce44SJohn Forte 	if (n_attr == NULL) {
1131fcf3ce44SJohn Forte 	    return (ERR_XML_SETPROP_FAILED);
1132fcf3ce44SJohn Forte 	}
1133fcf3ce44SJohn Forte 	attr = &obj->attrs[ATTR_INDEX_DD(ISNS_DD_NAME_ATTR_ID)];
1134fcf3ce44SJohn Forte 	n_attr = xmlSetProp(n_node, (xmlChar *)DDNAMEATTR,
1135fcf3ce44SJohn Forte 		(xmlChar *)attr->value.ptr);
1136fcf3ce44SJohn Forte 	if (n_attr == NULL) {
1137fcf3ce44SJohn Forte 	    return (ERR_XML_SETPROP_FAILED);
1138fcf3ce44SJohn Forte 	}
1139fcf3ce44SJohn Forte 
1140fcf3ce44SJohn Forte 	/* successful */
1141fcf3ce44SJohn Forte 	return (0);
1142fcf3ce44SJohn Forte }
1143fcf3ce44SJohn Forte 
1144fcf3ce44SJohn Forte /*
1145fcf3ce44SJohn Forte  * ****************************************************************************
1146fcf3ce44SJohn Forte  *
1147fcf3ce44SJohn Forte  * cb_getAssociated_dd_info:
1148fcf3ce44SJohn Forte  *	The routine is implemnetation for getting dds membership.
1149fcf3ce44SJohn Forte  *
1150fcf3ce44SJohn Forte  * p1	- dd or dd set object
1151fcf3ce44SJohn Forte  * p2	- lookup control data that was used for dd and dd set look up
1152fcf3ce44SJohn Forte  * return - error code
1153fcf3ce44SJohn Forte  *
1154fcf3ce44SJohn Forte  * ****************************************************************************
1155fcf3ce44SJohn Forte  */
1156fcf3ce44SJohn Forte static int
1157fcf3ce44SJohn Forte cb_getAssociated_dd_info(
1158fcf3ce44SJohn Forte 	void *p1,
1159fcf3ce44SJohn Forte 	void *p2
1160fcf3ce44SJohn Forte )
1161fcf3ce44SJohn Forte {
1162fcf3ce44SJohn Forte 	xmlNodePtr	n_obj, n_node, root;
1163fcf3ce44SJohn Forte 	xmlAttrPtr	n_attr;
1164fcf3ce44SJohn Forte 	isns_attr_t *attr;
1165fcf3ce44SJohn Forte 
1166fcf3ce44SJohn Forte 	isns_obj_t *obj = (isns_obj_t *)p1;
1167fcf3ce44SJohn Forte 	lookup_ctrl_t *lcp = (lookup_ctrl_t *)p2;
1168fcf3ce44SJohn Forte 	xmlDocPtr doc = (xmlDocPtr)lcp->data[1].ptr;
1169fcf3ce44SJohn Forte 	uchar_t *ddsetname = lcp->data[2].ptr;
1170fcf3ce44SJohn Forte 
1171fcf3ce44SJohn Forte 	root = xmlDocGetRootElement(doc);
1172fcf3ce44SJohn Forte 	if (root == NULL) {
1173fcf3ce44SJohn Forte 	    return (ERR_SYNTAX_MISSING_ROOT);
1174fcf3ce44SJohn Forte 	}
1175fcf3ce44SJohn Forte 	n_obj = xmlNewNode(NULL, (xmlChar *)ASSOCIATION);
1176fcf3ce44SJohn Forte 	if (n_obj) {
1177fcf3ce44SJohn Forte 	    n_obj = xmlAddChild(root, n_obj);
1178fcf3ce44SJohn Forte 	    if (n_obj == NULL) {
1179fcf3ce44SJohn Forte 		return (ERR_XML_ADDCHILD_FAILED);
1180fcf3ce44SJohn Forte 	    }
1181fcf3ce44SJohn Forte 	} else {
1182fcf3ce44SJohn Forte 	    return (ERR_XML_NEWNODE_FAILED);
1183fcf3ce44SJohn Forte 	}
1184fcf3ce44SJohn Forte 
1185fcf3ce44SJohn Forte 	n_node = xmlNewNode(NULL, (xmlChar *)DDSETOBJECTMEMBER);
1186fcf3ce44SJohn Forte 	if (n_node) {
1187fcf3ce44SJohn Forte 	    n_node = xmlAddChild(n_obj, n_node);
1188fcf3ce44SJohn Forte 	    if (n_node == NULL) {
1189fcf3ce44SJohn Forte 		return (ERR_XML_ADDCHILD_FAILED);
1190fcf3ce44SJohn Forte 	    }
1191fcf3ce44SJohn Forte 	} else {
1192fcf3ce44SJohn Forte 	    return (ERR_XML_NEWNODE_FAILED);
1193fcf3ce44SJohn Forte 	}
1194fcf3ce44SJohn Forte 
1195fcf3ce44SJohn Forte 	/* get node name, alias, type and generate xml info */
1196fcf3ce44SJohn Forte 	attr = &obj->attrs[ATTR_INDEX_DD(ISNS_DD_NAME_ATTR_ID)];
1197fcf3ce44SJohn Forte 	n_attr = xmlSetProp(n_node, (xmlChar *)DDNAMEATTR,
1198fcf3ce44SJohn Forte 		(xmlChar *)attr->value.ptr);
1199fcf3ce44SJohn Forte 	if (n_attr == NULL) {
1200fcf3ce44SJohn Forte 	    return (ERR_XML_SETPROP_FAILED);
1201fcf3ce44SJohn Forte 	}
1202fcf3ce44SJohn Forte 	n_attr = xmlSetProp(n_node, (xmlChar *)DDSETNAMEATTR,
1203fcf3ce44SJohn Forte 		(xmlChar *)ddsetname);
1204fcf3ce44SJohn Forte 	if (n_attr == NULL) {
1205fcf3ce44SJohn Forte 	    return (ERR_XML_SETPROP_FAILED);
1206fcf3ce44SJohn Forte 	}
1207fcf3ce44SJohn Forte 
1208fcf3ce44SJohn Forte 	/* successful */
1209fcf3ce44SJohn Forte 	return (0);
1210fcf3ce44SJohn Forte }
1211fcf3ce44SJohn Forte 
1212fcf3ce44SJohn Forte /*
1213fcf3ce44SJohn Forte  * ****************************************************************************
1214fcf3ce44SJohn Forte  *
1215fcf3ce44SJohn Forte  * cb_getAssociated_dd_to_ddset_info:
1216fcf3ce44SJohn Forte  *	The routine is implemnetation for enumerate dd and enumerate dds.
1217fcf3ce44SJohn Forte  *
1218fcf3ce44SJohn Forte  * p1	- dd or dd set object
1219fcf3ce44SJohn Forte  * p2	- lookup control data that was used for dd and dd set look up
1220fcf3ce44SJohn Forte  * return - error code
1221fcf3ce44SJohn Forte  *
1222fcf3ce44SJohn Forte  * ****************************************************************************
1223fcf3ce44SJohn Forte  */
1224fcf3ce44SJohn Forte static int
1225fcf3ce44SJohn Forte cb_getAssociated_dd_to_ddset_info(
1226fcf3ce44SJohn Forte 	void *p1,
1227fcf3ce44SJohn Forte 	void *p2
1228fcf3ce44SJohn Forte )
1229fcf3ce44SJohn Forte {
1230fcf3ce44SJohn Forte 	xmlNodePtr	n_obj, n_node, root;
1231fcf3ce44SJohn Forte 	xmlAttrPtr	n_attr;
1232fcf3ce44SJohn Forte 	isns_attr_t *attr;
1233fcf3ce44SJohn Forte 
1234fcf3ce44SJohn Forte 	isns_obj_t *obj = (isns_obj_t *)p1;
1235fcf3ce44SJohn Forte 	lookup_ctrl_t *lcp = (lookup_ctrl_t *)p2;
1236fcf3ce44SJohn Forte 	xmlDocPtr doc = (xmlDocPtr)lcp->data[1].ptr;
1237fcf3ce44SJohn Forte 	uchar_t *ddname = lcp->data[2].ptr;
1238fcf3ce44SJohn Forte 
1239fcf3ce44SJohn Forte 	root = xmlDocGetRootElement(doc);
1240fcf3ce44SJohn Forte 	if (root == NULL) {
1241fcf3ce44SJohn Forte 	    return (ERR_SYNTAX_MISSING_ROOT);
1242fcf3ce44SJohn Forte 	}
1243fcf3ce44SJohn Forte 	n_obj = xmlNewNode(NULL, (xmlChar *)ASSOCIATION);
1244fcf3ce44SJohn Forte 	if (n_obj) {
1245fcf3ce44SJohn Forte 	    n_obj = xmlAddChild(root, n_obj);
1246fcf3ce44SJohn Forte 	    if (n_obj == NULL) {
1247fcf3ce44SJohn Forte 		return (ERR_XML_ADDCHILD_FAILED);
1248fcf3ce44SJohn Forte 	    }
1249fcf3ce44SJohn Forte 	} else {
1250fcf3ce44SJohn Forte 	    return (ERR_XML_NEWNODE_FAILED);
1251fcf3ce44SJohn Forte 	}
1252fcf3ce44SJohn Forte 
1253fcf3ce44SJohn Forte 	n_node = xmlNewNode(NULL, (xmlChar *)DDSETOBJECTMEMBER);
1254fcf3ce44SJohn Forte 	if (n_node) {
1255fcf3ce44SJohn Forte 	    n_node = xmlAddChild(n_obj, n_node);
1256fcf3ce44SJohn Forte 	    if (n_node == NULL) {
1257fcf3ce44SJohn Forte 		return (ERR_XML_ADDCHILD_FAILED);
1258fcf3ce44SJohn Forte 	    }
1259fcf3ce44SJohn Forte 	} else {
1260fcf3ce44SJohn Forte 	    return (ERR_XML_NEWNODE_FAILED);
1261fcf3ce44SJohn Forte 	}
1262fcf3ce44SJohn Forte 
1263fcf3ce44SJohn Forte 	/* get node name, alias, type and generate xml info */
1264fcf3ce44SJohn Forte 	n_attr = xmlSetProp(n_node, (xmlChar *)DDNAMEATTR,
1265fcf3ce44SJohn Forte 		(xmlChar *)ddname);
1266fcf3ce44SJohn Forte 	if (n_attr == NULL) {
1267fcf3ce44SJohn Forte 	    return (ERR_XML_SETPROP_FAILED);
1268fcf3ce44SJohn Forte 	}
1269fcf3ce44SJohn Forte 	attr = &obj->attrs[ATTR_INDEX_DDS(ISNS_DD_SET_NAME_ATTR_ID)];
1270fcf3ce44SJohn Forte 	n_attr = xmlSetProp(n_node, (xmlChar *)DDSETNAMEATTR,
1271fcf3ce44SJohn Forte 		(xmlChar *)attr->value.ptr);
1272fcf3ce44SJohn Forte 	if (n_attr == NULL) {
1273fcf3ce44SJohn Forte 	    return (ERR_XML_SETPROP_FAILED);
1274fcf3ce44SJohn Forte 	}
1275fcf3ce44SJohn Forte 
1276fcf3ce44SJohn Forte 	/* successful */
1277fcf3ce44SJohn Forte 	return (0);
1278fcf3ce44SJohn Forte }
1279fcf3ce44SJohn Forte 
1280fcf3ce44SJohn Forte /*
1281fcf3ce44SJohn Forte  * ****************************************************************************
1282fcf3ce44SJohn Forte  *
1283fcf3ce44SJohn Forte  * handle_partial_success:
1284fcf3ce44SJohn Forte  *
1285fcf3ce44SJohn Forte  * doc	- response doc to fill up
1286fcf3ce44SJohn Forte  * ret	- return code from the caller.
1287fcf3ce44SJohn Forte  *
1288fcf3ce44SJohn Forte  * ****************************************************************************
1289fcf3ce44SJohn Forte  */
1290fcf3ce44SJohn Forte static int
1291fcf3ce44SJohn Forte handle_partial_success(
1292fcf3ce44SJohn Forte 	xmlDocPtr doc,
1293fcf3ce44SJohn Forte 	int ret
1294fcf3ce44SJohn Forte )
1295fcf3ce44SJohn Forte {
1296fcf3ce44SJohn Forte 	xmlNodePtr	n_obj, n_node, root;
1297fcf3ce44SJohn Forte 	char numbuf[32];
1298fcf3ce44SJohn Forte 
1299fcf3ce44SJohn Forte 	root = xmlDocGetRootElement(doc);
1300fcf3ce44SJohn Forte 	if (root == NULL) {
1301fcf3ce44SJohn Forte 	    return (ERR_SYNTAX_MISSING_ROOT);
1302fcf3ce44SJohn Forte 	}
1303fcf3ce44SJohn Forte 	n_obj = xmlNewNode(NULL, (xmlChar *)RESULTELEMENT);
1304fcf3ce44SJohn Forte 	if (n_obj) {
1305fcf3ce44SJohn Forte 	    if (root->children) {
1306fcf3ce44SJohn Forte 		n_obj = xmlAddPrevSibling(root->children, n_obj);
1307fcf3ce44SJohn Forte 		(void) sprintf(numbuf, "%d", (ret != 0) ? PARTIAL_SUCCESS : 0);
1308fcf3ce44SJohn Forte 		n_node = xmlNewChild(n_obj, NULL, (xmlChar *)STATUSELEMENT,
1309fcf3ce44SJohn Forte 		    (xmlChar *)numbuf);
1310fcf3ce44SJohn Forte 		if (n_node == NULL) {
1311fcf3ce44SJohn Forte 		    return (ERR_XML_NEWCHILD_FAILED);
1312fcf3ce44SJohn Forte 		}
1313fcf3ce44SJohn Forte 		n_node = xmlNewChild(n_obj, NULL, (xmlChar *)MESSAGEELEMENT,
1314fcf3ce44SJohn Forte 		    (xmlChar *)result_code_to_str((ret != 0) ?
1315fcf3ce44SJohn Forte 			PARTIAL_SUCCESS : 0));
1316fcf3ce44SJohn Forte 		if (n_node == NULL) {
1317fcf3ce44SJohn Forte 		    return (ERR_XML_NEWCHILD_FAILED);
1318fcf3ce44SJohn Forte 		}
1319fcf3ce44SJohn Forte 	    } else {
1320fcf3ce44SJohn Forte 		n_obj = xmlAddChild(root, n_obj);
1321fcf3ce44SJohn Forte 		if (n_obj == NULL) {
1322fcf3ce44SJohn Forte 		    return (ERR_XML_ADDCHILD_FAILED);
1323fcf3ce44SJohn Forte 		}
1324fcf3ce44SJohn Forte 		(void) sprintf(numbuf, "%d", ret);
1325fcf3ce44SJohn Forte 		n_node = xmlNewChild(n_obj, NULL, (xmlChar *)STATUSELEMENT,
1326fcf3ce44SJohn Forte 		    (xmlChar *)numbuf);
1327fcf3ce44SJohn Forte 		if (n_node == NULL) {
1328fcf3ce44SJohn Forte 		    return (ERR_XML_NEWCHILD_FAILED);
1329fcf3ce44SJohn Forte 		}
1330fcf3ce44SJohn Forte 		n_node = xmlNewChild(n_obj, NULL, (xmlChar *)MESSAGEELEMENT,
1331fcf3ce44SJohn Forte 		    (xmlChar *)result_code_to_str(ret));
1332fcf3ce44SJohn Forte 		if (n_node == NULL) {
1333fcf3ce44SJohn Forte 		    return (ERR_XML_NEWCHILD_FAILED);
1334fcf3ce44SJohn Forte 		}
1335fcf3ce44SJohn Forte 	    }
1336fcf3ce44SJohn Forte 	} else {
1337fcf3ce44SJohn Forte 	    return (ERR_XML_NEWNODE_FAILED);
1338fcf3ce44SJohn Forte 	}
1339fcf3ce44SJohn Forte 
1340fcf3ce44SJohn Forte 	return (0);
1341fcf3ce44SJohn Forte }
1342fcf3ce44SJohn Forte 
1343fcf3ce44SJohn Forte /*
1344fcf3ce44SJohn Forte  * ****************************************************************************
1345fcf3ce44SJohn Forte  *
1346fcf3ce44SJohn Forte  * handle_partial_failure:
1347fcf3ce44SJohn Forte  *
1348fcf3ce44SJohn Forte  * doc	- response doc to fill up
1349fcf3ce44SJohn Forte  * ret	- return code from the caller.
1350fcf3ce44SJohn Forte  *
1351fcf3ce44SJohn Forte  * ****************************************************************************
1352fcf3ce44SJohn Forte  */
1353fcf3ce44SJohn Forte static int
1354fcf3ce44SJohn Forte handle_partial_failure(
1355fcf3ce44SJohn Forte 	xmlDocPtr doc,
1356fcf3ce44SJohn Forte 	int ret,
1357fcf3ce44SJohn Forte 	boolean_t all_failed
1358fcf3ce44SJohn Forte )
1359fcf3ce44SJohn Forte {
1360fcf3ce44SJohn Forte 	xmlNodePtr	n_obj, n_node, root;
1361fcf3ce44SJohn Forte 	char numbuf[32];
1362fcf3ce44SJohn Forte 
1363fcf3ce44SJohn Forte 	root = xmlDocGetRootElement(doc);
1364fcf3ce44SJohn Forte 	if (root == NULL) {
1365fcf3ce44SJohn Forte 	    return (ERR_SYNTAX_MISSING_ROOT);
1366fcf3ce44SJohn Forte 	}
1367fcf3ce44SJohn Forte 	n_obj = xmlNewNode(NULL, (xmlChar *)RESULTELEMENT);
1368fcf3ce44SJohn Forte 	if (n_obj) {
1369fcf3ce44SJohn Forte 	    if (root->children) {
1370fcf3ce44SJohn Forte 		/* some or all associations failed to create */
1371fcf3ce44SJohn Forte 		n_obj = xmlAddPrevSibling(root->children, n_obj);
1372fcf3ce44SJohn Forte 		/* capture last error. should come up with all failed?? */
1373fcf3ce44SJohn Forte 		(void) sprintf(numbuf, "%d",
1374fcf3ce44SJohn Forte 		    all_failed ? ret : PARTIAL_FAILURE);
1375fcf3ce44SJohn Forte 		n_node = xmlNewChild(n_obj, NULL, (xmlChar *)STATUSELEMENT,
1376fcf3ce44SJohn Forte 		    (xmlChar *)numbuf);
1377fcf3ce44SJohn Forte 		if (n_node == NULL) {
1378fcf3ce44SJohn Forte 			return (ERR_XML_NEWCHILD_FAILED);
1379fcf3ce44SJohn Forte 		}
1380fcf3ce44SJohn Forte 		n_node = xmlNewChild(n_obj, NULL, (xmlChar *)MESSAGEELEMENT,
1381fcf3ce44SJohn Forte 		    (xmlChar *)result_code_to_str(all_failed ? ret :
1382fcf3ce44SJohn Forte 			PARTIAL_FAILURE));
1383fcf3ce44SJohn Forte 		if (n_node == NULL) {
1384fcf3ce44SJohn Forte 		    return (ERR_XML_NEWCHILD_FAILED);
1385fcf3ce44SJohn Forte 		}
1386fcf3ce44SJohn Forte 	    } else {
1387fcf3ce44SJohn Forte 		n_obj = xmlAddChild(root, n_obj);
1388fcf3ce44SJohn Forte 		if (n_obj == NULL) {
1389fcf3ce44SJohn Forte 		    return (ERR_XML_ADDCHILD_FAILED);
1390fcf3ce44SJohn Forte 		}
1391fcf3ce44SJohn Forte 		(void) sprintf(numbuf, "%d", (ret != 0) ? ret : 0);
1392fcf3ce44SJohn Forte 		n_node = xmlNewChild(n_obj, NULL, (xmlChar *)STATUSELEMENT,
1393fcf3ce44SJohn Forte 		    (xmlChar *)numbuf);
1394fcf3ce44SJohn Forte 		if (n_node == NULL) {
1395fcf3ce44SJohn Forte 		    return (ERR_XML_NEWCHILD_FAILED);
1396fcf3ce44SJohn Forte 		}
1397fcf3ce44SJohn Forte 		n_node = xmlNewChild(n_obj, NULL, (xmlChar *)MESSAGEELEMENT,
1398fcf3ce44SJohn Forte 		    (xmlChar *)result_code_to_str((ret != 0) ? ret : 0));
1399fcf3ce44SJohn Forte 		if (n_node == NULL) {
1400fcf3ce44SJohn Forte 		    return (ERR_XML_NEWCHILD_FAILED);
1401fcf3ce44SJohn Forte 		}
1402fcf3ce44SJohn Forte 	    }
1403fcf3ce44SJohn Forte 	} else {
1404fcf3ce44SJohn Forte 	    return (ERR_XML_NEWNODE_FAILED);
1405fcf3ce44SJohn Forte 	}
1406fcf3ce44SJohn Forte 
1407fcf3ce44SJohn Forte 	return (0);
1408fcf3ce44SJohn Forte }
1409fcf3ce44SJohn Forte 
1410fcf3ce44SJohn Forte /*
1411fcf3ce44SJohn Forte  * ****************************************************************************
1412fcf3ce44SJohn Forte  *
1413fcf3ce44SJohn Forte  * get_serverconfig_op:
1414fcf3ce44SJohn Forte  *	The routine process server administrative setting.
1415fcf3ce44SJohn Forte  *
1416fcf3ce44SJohn Forte  * doc	- response doc to fill up.
1417fcf3ce44SJohn Forte  *
1418fcf3ce44SJohn Forte  * ****************************************************************************
1419fcf3ce44SJohn Forte  */
1420fcf3ce44SJohn Forte int
1421fcf3ce44SJohn Forte get_serverconfig_op(
1422fcf3ce44SJohn Forte 	xmlDocPtr doc
1423fcf3ce44SJohn Forte )
1424fcf3ce44SJohn Forte {
1425fcf3ce44SJohn Forte 	extern uint64_t esi_threshold;
1426fcf3ce44SJohn Forte 	extern uint8_t mgmt_scn;
1427fcf3ce44SJohn Forte 	extern ctrl_node_t *control_nodes;
1428fcf3ce44SJohn Forte 	extern pthread_mutex_t ctrl_node_mtx;
1429fcf3ce44SJohn Forte 	extern char data_store[MAXPATHLEN];
1430fcf3ce44SJohn Forte 
1431fcf3ce44SJohn Forte 	xmlNodePtr	n_obj, root;
1432fcf3ce44SJohn Forte 	char numbuf[32];
1433fcf3ce44SJohn Forte 	ctrl_node_t *ctrl_node_p;
1434fcf3ce44SJohn Forte 	int ret = 0;
1435fcf3ce44SJohn Forte 
1436fcf3ce44SJohn Forte 	root = xmlDocGetRootElement(doc);
1437fcf3ce44SJohn Forte 	if (root == NULL) {
1438fcf3ce44SJohn Forte 	    return (ERR_SYNTAX_MISSING_ROOT);
1439fcf3ce44SJohn Forte 	}
1440fcf3ce44SJohn Forte 	n_obj = xmlNewNode(NULL, (xmlChar *)ISNSSERVER);
1441fcf3ce44SJohn Forte 	if (n_obj) {
1442fcf3ce44SJohn Forte 	    n_obj = xmlAddChild(root, n_obj);
1443fcf3ce44SJohn Forte 	    if (n_obj == NULL) {
1444fcf3ce44SJohn Forte 		return (ERR_XML_ADDCHILD_FAILED);
1445fcf3ce44SJohn Forte 	    }
1446fcf3ce44SJohn Forte 	} else {
1447fcf3ce44SJohn Forte 	    return (ERR_XML_ADDCHILD_FAILED);
1448fcf3ce44SJohn Forte 	}
1449fcf3ce44SJohn Forte 
1450fcf3ce44SJohn Forte 	if (xmlNewChild(n_obj, NULL, (xmlChar *)DATASTORELOCATION,
1451fcf3ce44SJohn Forte 	    (xmlChar *)data_store) == NULL) {
1452fcf3ce44SJohn Forte 	    return (ERR_XML_NEWCHILD_FAILED);
1453fcf3ce44SJohn Forte 	}
1454fcf3ce44SJohn Forte 
1455fcf3ce44SJohn Forte 	(void) sprintf(numbuf, "%llu", esi_threshold);
1456fcf3ce44SJohn Forte 	if (xmlNewChild(n_obj, NULL, (xmlChar *)ESIRETRYTHRESHOLD,
1457fcf3ce44SJohn Forte 	    (xmlChar *)numbuf) == NULL) {
1458fcf3ce44SJohn Forte 	    return (ERR_XML_NEWCHILD_FAILED);
1459fcf3ce44SJohn Forte 	}
1460fcf3ce44SJohn Forte 	if (xmlNewChild(n_obj, NULL, (xmlChar *)MANAGEMENTSCNENABLED,
1461fcf3ce44SJohn Forte 	    (mgmt_scn) ? (uchar_t *)XMLTRUE : (uchar_t *)XMLFALSE) == NULL) {
1462fcf3ce44SJohn Forte 	    return (ERR_XML_NEWCHILD_FAILED);
1463fcf3ce44SJohn Forte 	}
1464fcf3ce44SJohn Forte 
1465fcf3ce44SJohn Forte 	(void) pthread_mutex_lock(&ctrl_node_mtx);
1466fcf3ce44SJohn Forte 	if (control_nodes == NULL) {
1467fcf3ce44SJohn Forte 	    if (xmlNewChild(n_obj, NULL, (xmlChar *)CONTROLNODENAME,
1468fcf3ce44SJohn Forte 		    (xmlChar *)NULL) == NULL) {
1469fcf3ce44SJohn Forte 		    (void) pthread_mutex_unlock(&ctrl_node_mtx);
1470fcf3ce44SJohn Forte 		    return (ERR_XML_NEWCHILD_FAILED);
1471fcf3ce44SJohn Forte 	    }
1472fcf3ce44SJohn Forte 	} else {
1473fcf3ce44SJohn Forte 	    ctrl_node_p = control_nodes;
1474fcf3ce44SJohn Forte 	    while (ctrl_node_p != NULL) {
1475fcf3ce44SJohn Forte 		if (xmlNewChild(n_obj, NULL, (xmlChar *)CONTROLNODENAME,
1476fcf3ce44SJohn Forte 		    (xmlChar *)ctrl_node_p->name) == NULL) {
1477fcf3ce44SJohn Forte 		    (void) pthread_mutex_unlock(&ctrl_node_mtx);
1478fcf3ce44SJohn Forte 		    return (ERR_XML_NEWCHILD_FAILED);
1479fcf3ce44SJohn Forte 		}
1480fcf3ce44SJohn Forte 		ctrl_node_p = ctrl_node_p->next;
1481fcf3ce44SJohn Forte 	    }
1482fcf3ce44SJohn Forte 	}
1483fcf3ce44SJohn Forte 	(void) pthread_mutex_unlock(&ctrl_node_mtx);
1484fcf3ce44SJohn Forte 
1485fcf3ce44SJohn Forte 	return (handle_partial_success(doc, ret));
1486fcf3ce44SJohn Forte }
1487fcf3ce44SJohn Forte 
1488fcf3ce44SJohn Forte /*
1489fcf3ce44SJohn Forte  * ****************************************************************************
1490fcf3ce44SJohn Forte  *
1491fcf3ce44SJohn Forte  * get_node_op:
1492fcf3ce44SJohn Forte  *	service get operation on a given node.
1493fcf3ce44SJohn Forte  *
1494fcf3ce44SJohn Forte  * req	- contains all info for a request.
1495fcf3ce44SJohn Forte  * doc	- response doc to fill up
1496fcf3ce44SJohn Forte  *
1497fcf3ce44SJohn Forte  * ****************************************************************************
1498fcf3ce44SJohn Forte  */
1499fcf3ce44SJohn Forte int
1500fcf3ce44SJohn Forte get_node_op(
1501fcf3ce44SJohn Forte 	request_t *req,
1502fcf3ce44SJohn Forte 	xmlDocPtr doc
1503fcf3ce44SJohn Forte 	/* any additional arguments go here */
1504fcf3ce44SJohn Forte )
1505fcf3ce44SJohn Forte {
1506fcf3ce44SJohn Forte 	int ret = 0, ret_save = 0;
1507fcf3ce44SJohn Forte 	int i = 0;
1508fcf3ce44SJohn Forte 	lookup_ctrl_t lc, lc2, lc3;
1509fcf3ce44SJohn Forte 	uint32_t uid;
1510fcf3ce44SJohn Forte 	char buff2[INET6_ADDRSTRLEN];
1511fcf3ce44SJohn Forte 
1512fcf3ce44SJohn Forte 	/* prepare lookup ctrl data for looking for the node object */
1513fcf3ce44SJohn Forte 	lc.curr_uid = 0;
1514fcf3ce44SJohn Forte 	lc.type = get_lc_type(req->op_info.obj);
1515fcf3ce44SJohn Forte 	lc.id[0] = get_lc_id(req->op_info.obj);
1516fcf3ce44SJohn Forte 	lc.op[0] = OP_STRING;
1517fcf3ce44SJohn Forte 	lc.op[1] = 0;
1518fcf3ce44SJohn Forte 	lc.data[1].ptr = (uchar_t *)doc; /* xml writer descriptor */
1519fcf3ce44SJohn Forte 	while (i < req->count) {
1520fcf3ce44SJohn Forte 		lc.data[0].ptr = (uchar_t *)req->req_data.data[i];
1521fcf3ce44SJohn Forte 		ret = cache_lookup(&lc, &uid, cb_get_node_info);
1522fcf3ce44SJohn Forte 		if (uid == 0) {
1523fcf3ce44SJohn Forte 		    ret = ERR_MATCHING_ISCSI_NODE_NOT_FOUND;
1524fcf3ce44SJohn Forte 		}
1525fcf3ce44SJohn Forte 
1526fcf3ce44SJohn Forte 		/* generate network entity object information */
1527fcf3ce44SJohn Forte 		if (ret == 0 && lc.id[2] != 0) {
1528fcf3ce44SJohn Forte 			/*
1529fcf3ce44SJohn Forte 			 * !!! there might be no entity and portal info for
1530fcf3ce44SJohn Forte 			 * !!! the node if it is not a registered node
1531fcf3ce44SJohn Forte 			 */
1532fcf3ce44SJohn Forte 			/* prepare lookup ctrl data for looking for entity */
1533fcf3ce44SJohn Forte 			SET_UID_LCP(&lc2, OBJ_ENTITY, lc.id[2]);
1534fcf3ce44SJohn Forte 
1535fcf3ce44SJohn Forte 			lc2.data[1].ptr = (uchar_t *)doc;
1536fcf3ce44SJohn Forte 			/* cb_get_node_info callback returned Node object. */
1537fcf3ce44SJohn Forte 			lc2.data[2].ptr = lc.data[2].ptr;
1538fcf3ce44SJohn Forte 			ret = cache_lookup(&lc2, &uid, cb_get_entity_info);
1539fcf3ce44SJohn Forte 			if (uid == 0) {
1540fcf3ce44SJohn Forte 			    ret = ERR_MATCHING_NETWORK_ENTITY_NOT_FOUND;
1541fcf3ce44SJohn Forte 			}
1542fcf3ce44SJohn Forte 		}
1543fcf3ce44SJohn Forte 
1544fcf3ce44SJohn Forte 		/* generate portal information */
1545fcf3ce44SJohn Forte 		if (ret == 0 && lc.id[2] != 0) {
1546fcf3ce44SJohn Forte 			/* prepare lookup ctrl data for looking for pg */
1547fcf3ce44SJohn Forte 			lc2.curr_uid = 0;
1548fcf3ce44SJohn Forte 			lc2.type = OBJ_PG;
1549fcf3ce44SJohn Forte 			lc2.id[0] = ATTR_INDEX_PG(ISNS_PG_ISCSI_NAME_ATTR_ID);
1550fcf3ce44SJohn Forte 			lc2.op[0] = OP_STRING;
1551fcf3ce44SJohn Forte 			/* lc.data[0].ptr contains node name */
1552fcf3ce44SJohn Forte 			lc2.data[0].ptr = lc.data[0].ptr;
1553fcf3ce44SJohn Forte 			lc2.op[1] = 0;
1554fcf3ce44SJohn Forte 			lc2.data[1].ip = (in6_addr_t *)buff2;
1555fcf3ce44SJohn Forte 
1556fcf3ce44SJohn Forte 			/* prepare lookup ctrl data for looking for portal */
1557fcf3ce44SJohn Forte 			lc3.curr_uid = 0;
1558fcf3ce44SJohn Forte 			lc3.type = OBJ_PORTAL;
1559fcf3ce44SJohn Forte 			lc3.id[0] = ATTR_INDEX_PORTAL(
1560fcf3ce44SJohn Forte 				ISNS_PORTAL_IP_ADDR_ATTR_ID);
1561fcf3ce44SJohn Forte 			lc3.op[0] = OP_MEMORY_IP6;
1562fcf3ce44SJohn Forte 			lc3.id[1] = ATTR_INDEX_PORTAL(
1563fcf3ce44SJohn Forte 				ISNS_PORTAL_PORT_ATTR_ID);
1564fcf3ce44SJohn Forte 			lc3.op[1] = OP_INTEGER;
1565fcf3ce44SJohn Forte 			lc3.op[2] = 0;
1566fcf3ce44SJohn Forte 			/* cb_get_node_info callback returned Node object. */
1567fcf3ce44SJohn Forte 			lc3.data[2].ptr = lc.data[2].ptr;
1568fcf3ce44SJohn Forte 			for (;;) {
1569fcf3ce44SJohn Forte 				ret = cache_lookup(&lc2, &uid, cb_get_pg_info);
1570fcf3ce44SJohn Forte 				if (uid != 0) {
1571fcf3ce44SJohn Forte 					/* we found a portal group */
1572fcf3ce44SJohn Forte 					lc2.curr_uid = uid;
1573*5fbbe9c6Swl202157@icefox 					/* it is a null pg if pgt is zero. */
1574*5fbbe9c6Swl202157@icefox 					if (lc2.id[2] != 0) {
1575*5fbbe9c6Swl202157@icefox 						/* pass ip addr */
1576fcf3ce44SJohn Forte 						lc3.data[0].ip = lc2.data[1].ip;
1577*5fbbe9c6Swl202157@icefox 						/* pass port num */
1578fcf3ce44SJohn Forte 						lc3.data[1].ui = lc2.data[2].ui;
1579*5fbbe9c6Swl202157@icefox 						/* pass pgt */
1580fcf3ce44SJohn Forte 						lc3.id[2] = lc2.id[2];
1581fcf3ce44SJohn Forte 						ret = cache_lookup(&lc3, &uid,
1582fcf3ce44SJohn Forte 						    cb_get_portal_info);
1583*5fbbe9c6Swl202157@icefox 					}
1584fcf3ce44SJohn Forte 				} else {
1585fcf3ce44SJohn Forte 					/*
1586fcf3ce44SJohn Forte 					 * no more portal group which is
1587fcf3ce44SJohn Forte 					 * tied to this stroage node object.
1588fcf3ce44SJohn Forte 					 */
1589fcf3ce44SJohn Forte 					break;
1590fcf3ce44SJohn Forte 				}
1591fcf3ce44SJohn Forte 			}
1592fcf3ce44SJohn Forte 		}
1593fcf3ce44SJohn Forte 		/* save error for this iteration */
1594fcf3ce44SJohn Forte 		if (ret != 0) {
1595fcf3ce44SJohn Forte 		    ret_save = ret;
1596fcf3ce44SJohn Forte 		}
1597fcf3ce44SJohn Forte 		ret = 0;
1598fcf3ce44SJohn Forte 		i++;
1599fcf3ce44SJohn Forte 	}
1600fcf3ce44SJohn Forte 
1601fcf3ce44SJohn Forte 	return (handle_partial_success(doc, ret_save));
1602fcf3ce44SJohn Forte }
1603fcf3ce44SJohn Forte 
1604fcf3ce44SJohn Forte /*
1605fcf3ce44SJohn Forte  * ****************************************************************************
1606fcf3ce44SJohn Forte  *
1607fcf3ce44SJohn Forte  * i_get_dd_dds_op:
1608fcf3ce44SJohn Forte  *	serves get operatrion on dd or dds.
1609fcf3ce44SJohn Forte  *
1610fcf3ce44SJohn Forte  * req	- contains all info for a request.
1611fcf3ce44SJohn Forte  * doc	- response doc to fill up
1612fcf3ce44SJohn Forte  * obj_type	- object type(either dd or dd set)
1613fcf3ce44SJohn Forte  *
1614fcf3ce44SJohn Forte  * ****************************************************************************
1615fcf3ce44SJohn Forte  */
1616fcf3ce44SJohn Forte static int
1617fcf3ce44SJohn Forte i_get_dd_dds_op(
1618fcf3ce44SJohn Forte 	request_t *req,
1619fcf3ce44SJohn Forte 	xmlDocPtr doc,
1620fcf3ce44SJohn Forte 	isns_type_t obj_type
1621fcf3ce44SJohn Forte 	/* any additional arguments go here */
1622fcf3ce44SJohn Forte )
1623fcf3ce44SJohn Forte {
1624fcf3ce44SJohn Forte 	result_code_t ret = 0, ret_save = 0;
1625fcf3ce44SJohn Forte 	int i = 0;
1626fcf3ce44SJohn Forte 	lookup_ctrl_t lc;
1627fcf3ce44SJohn Forte 	uint32_t uid;
1628fcf3ce44SJohn Forte 
1629fcf3ce44SJohn Forte 	if ((obj_type != OBJ_DD) && (obj_type != OBJ_DDS)) {
1630fcf3ce44SJohn Forte 	    return (ERR_INVALID_MGMT_REQUEST);
1631fcf3ce44SJohn Forte 	}
1632fcf3ce44SJohn Forte 
1633fcf3ce44SJohn Forte 	/* prepare lookup ctrl data for looking for the node object */
1634fcf3ce44SJohn Forte 	lc.curr_uid = 0;
1635fcf3ce44SJohn Forte 	lc.type = obj_type;
1636fcf3ce44SJohn Forte 	lc.id[0] = get_lc_id(req->op_info.obj);
1637fcf3ce44SJohn Forte 	lc.op[0] = OP_STRING;
1638fcf3ce44SJohn Forte 	lc.op[1] = 0;
1639fcf3ce44SJohn Forte 	lc.data[1].ptr = (uchar_t *)doc; /* xml writer descriptor */
1640fcf3ce44SJohn Forte 	while (i < req->count) {
1641fcf3ce44SJohn Forte 		if (obj_type == OBJ_DD) {
1642fcf3ce44SJohn Forte 		    lc.data[0].ptr = (uchar_t *)req->req_data.data[i];
1643fcf3ce44SJohn Forte 		    ret = cache_lookup(&lc, &uid, cb_get_dd_info);
1644fcf3ce44SJohn Forte 		    if (uid == 0) {
1645fcf3ce44SJohn Forte 			/* set an error and continue. */
1646fcf3ce44SJohn Forte 			ret = ERR_MATCHING_DD_NOT_FOUND;
1647fcf3ce44SJohn Forte 		    }
1648fcf3ce44SJohn Forte 		} else {
1649fcf3ce44SJohn Forte 		    lc.data[0].ptr = (uchar_t *)req->req_data.data[i];
1650fcf3ce44SJohn Forte 		    ret = cache_lookup(&lc, &uid, cb_get_ddset_info);
1651fcf3ce44SJohn Forte 		    if (uid == 0) {
1652fcf3ce44SJohn Forte 			/* set an error and continue. */
1653fcf3ce44SJohn Forte 			ret = ERR_MATCHING_DDSET_NOT_FOUND;
1654fcf3ce44SJohn Forte 		    }
1655fcf3ce44SJohn Forte 		}
1656fcf3ce44SJohn Forte 		/* save error for this iteration */
1657fcf3ce44SJohn Forte 		if (ret != 0) {
1658fcf3ce44SJohn Forte 		    ret_save = ret;
1659fcf3ce44SJohn Forte 		}
1660fcf3ce44SJohn Forte 		ret = 0;
1661fcf3ce44SJohn Forte 		i++;
1662fcf3ce44SJohn Forte 	}
1663fcf3ce44SJohn Forte 
1664fcf3ce44SJohn Forte 	return (handle_partial_success(doc, ret_save));
1665fcf3ce44SJohn Forte }
1666fcf3ce44SJohn Forte 
1667fcf3ce44SJohn Forte /*
1668fcf3ce44SJohn Forte  * ****************************************************************************
1669fcf3ce44SJohn Forte  *
1670fcf3ce44SJohn Forte  * i_delete_ddmember_op:
1671fcf3ce44SJohn Forte  *	serves delete member operatrion on dd.
1672fcf3ce44SJohn Forte  *
1673fcf3ce44SJohn Forte  * container	- dd name
1674fcf3ce44SJohn Forte  * member	- node name
1675fcf3ce44SJohn Forte  *
1676fcf3ce44SJohn Forte  * ****************************************************************************
1677fcf3ce44SJohn Forte  */
1678fcf3ce44SJohn Forte static int
1679fcf3ce44SJohn Forte i_delete_ddmember_op(
1680fcf3ce44SJohn Forte 	uchar_t *container,
1681fcf3ce44SJohn Forte 	uchar_t *member
1682fcf3ce44SJohn Forte )
1683fcf3ce44SJohn Forte {
1684fcf3ce44SJohn Forte 	int ret = 0;
1685fcf3ce44SJohn Forte 
1686fcf3ce44SJohn Forte 	isns_assoc_iscsi_t aiscsi;
1687fcf3ce44SJohn Forte 	isns_obj_t *assoc;
1688fcf3ce44SJohn Forte 	isns_attr_t *attr;
1689fcf3ce44SJohn Forte 	int len;
1690fcf3ce44SJohn Forte 
1691fcf3ce44SJohn Forte 	lookup_ctrl_t lc;
1692fcf3ce44SJohn Forte 	uint32_t dd_id;
1693fcf3ce44SJohn Forte 
1694fcf3ce44SJohn Forte 	/* prepare lookup ctrl data for looking for the dd object */
1695fcf3ce44SJohn Forte 	lc.curr_uid = 0;
1696fcf3ce44SJohn Forte 	lc.type = OBJ_DD;
1697fcf3ce44SJohn Forte 	lc.id[0] = ATTR_INDEX_DD(ISNS_DD_NAME_ATTR_ID);
1698fcf3ce44SJohn Forte 	lc.op[0] = OP_STRING;
1699fcf3ce44SJohn Forte 	lc.data[0].ptr = container;
1700fcf3ce44SJohn Forte 	lc.op[1] = 0;
1701fcf3ce44SJohn Forte 
1702fcf3ce44SJohn Forte 	if ((dd_id = is_obj_there(&lc)) != 0) {
1703fcf3ce44SJohn Forte 	    aiscsi.type = OBJ_ASSOC_ISCSI;
1704fcf3ce44SJohn Forte 	    aiscsi.puid = dd_id;
1705fcf3ce44SJohn Forte 
1706fcf3ce44SJohn Forte 	    len = strlen((char *)member) + 1;
1707fcf3ce44SJohn Forte 	    len += 4 - (len % 4);
1708fcf3ce44SJohn Forte 
1709fcf3ce44SJohn Forte 	    attr = &aiscsi.attrs[ATTR_INDEX_ASSOC_ISCSI(
1710fcf3ce44SJohn Forte 		ISNS_DD_ISCSI_NAME_ATTR_ID)];
1711fcf3ce44SJohn Forte 	    attr->tag = ISNS_DD_ISCSI_NAME_ATTR_ID;
1712fcf3ce44SJohn Forte 	    attr->len = len;
1713fcf3ce44SJohn Forte 	    attr->value.ptr = (uchar_t *)member;
1714fcf3ce44SJohn Forte 	    attr = &aiscsi.attrs[ATTR_INDEX_ASSOC_ISCSI(
1715fcf3ce44SJohn Forte 		ISNS_DD_ISCSI_INDEX_ATTR_ID)];
1716fcf3ce44SJohn Forte 	    attr->tag = 0; /* clear it */
1717fcf3ce44SJohn Forte 	    assoc = (isns_obj_t *)&aiscsi;
1718fcf3ce44SJohn Forte 	    ret = remove_dd_member(assoc);
1719fcf3ce44SJohn Forte 	} else {
1720fcf3ce44SJohn Forte 	    ret = ERR_MATCHING_DD_NOT_FOUND;
1721fcf3ce44SJohn Forte 	}
1722fcf3ce44SJohn Forte 
1723fcf3ce44SJohn Forte 	return (ret);
1724fcf3ce44SJohn Forte }
1725fcf3ce44SJohn Forte 
1726fcf3ce44SJohn Forte /*
1727fcf3ce44SJohn Forte  * ****************************************************************************
1728fcf3ce44SJohn Forte  *
1729fcf3ce44SJohn Forte  * i_delete_ddsetmember_op:
1730fcf3ce44SJohn Forte  *	serves delete member operatrion on dd set.
1731fcf3ce44SJohn Forte  *
1732fcf3ce44SJohn Forte  * container	- dd set name
1733fcf3ce44SJohn Forte  * member	- dd name
1734fcf3ce44SJohn Forte  *
1735fcf3ce44SJohn Forte  * ****************************************************************************
1736fcf3ce44SJohn Forte  */
1737fcf3ce44SJohn Forte static int
1738fcf3ce44SJohn Forte i_delete_ddsetmember_op(
1739fcf3ce44SJohn Forte 	uchar_t *container,
1740fcf3ce44SJohn Forte 	uchar_t *member
1741fcf3ce44SJohn Forte )
1742fcf3ce44SJohn Forte {
1743fcf3ce44SJohn Forte 	int ret = 0;
1744fcf3ce44SJohn Forte 
1745fcf3ce44SJohn Forte 	lookup_ctrl_t lc, lc2;
1746fcf3ce44SJohn Forte 	uint32_t container_id, member_id;
1747fcf3ce44SJohn Forte 
1748fcf3ce44SJohn Forte 	/* prepare lookup ctrl data for looking for the dd-set object */
1749fcf3ce44SJohn Forte 	lc.curr_uid = 0;
1750fcf3ce44SJohn Forte 	lc.type = OBJ_DDS;
1751fcf3ce44SJohn Forte 	lc.id[0] = ATTR_INDEX_DDS(ISNS_DD_SET_NAME_ATTR_ID);
1752fcf3ce44SJohn Forte 	lc.op[0] = OP_STRING;
1753fcf3ce44SJohn Forte 	lc.data[0].ptr = container;
1754fcf3ce44SJohn Forte 	lc.op[1] = 0;
1755fcf3ce44SJohn Forte 
1756fcf3ce44SJohn Forte 	/* prepare lookup ctrl data for looking for the dd object */
1757fcf3ce44SJohn Forte 	lc2.curr_uid = 0;
1758fcf3ce44SJohn Forte 	lc2.type = OBJ_DD;
1759fcf3ce44SJohn Forte 	lc2.id[0] = ATTR_INDEX_DD(ISNS_DD_NAME_ATTR_ID);
1760fcf3ce44SJohn Forte 	lc2.op[0] = OP_STRING;
1761fcf3ce44SJohn Forte 	lc2.data[0].ptr = member;
1762fcf3ce44SJohn Forte 	lc2.op[1] = 0;
1763fcf3ce44SJohn Forte 
1764fcf3ce44SJohn Forte 	if ((container_id = is_obj_there(&lc)) != 0) {
1765fcf3ce44SJohn Forte 	    if ((member_id = is_obj_there(&lc2)) != 0) {
1766fcf3ce44SJohn Forte 		ret = remove_dds_member(container_id, member_id);
1767fcf3ce44SJohn Forte 	    } else {
1768fcf3ce44SJohn Forte 		ret = ERR_MATCHING_DD_NOT_FOUND;
1769fcf3ce44SJohn Forte 	    }
1770fcf3ce44SJohn Forte 	} else {
1771fcf3ce44SJohn Forte 	    ret = ERR_MATCHING_DDSET_NOT_FOUND;
1772fcf3ce44SJohn Forte 	}
1773fcf3ce44SJohn Forte 
1774fcf3ce44SJohn Forte 	return (ret);
1775fcf3ce44SJohn Forte }
1776fcf3ce44SJohn Forte 
1777fcf3ce44SJohn Forte /*
1778fcf3ce44SJohn Forte  * ****************************************************************************
1779fcf3ce44SJohn Forte  *
1780fcf3ce44SJohn Forte  * get_dd_op:
1781fcf3ce44SJohn Forte  *	service get operation on given dd(s).
1782fcf3ce44SJohn Forte  *
1783fcf3ce44SJohn Forte  * req	- contains all info for a request.
1784fcf3ce44SJohn Forte  * doc	- response doc to fill up
1785fcf3ce44SJohn Forte  *
1786fcf3ce44SJohn Forte  * ****************************************************************************
1787fcf3ce44SJohn Forte  */
1788fcf3ce44SJohn Forte int
1789fcf3ce44SJohn Forte get_dd_op(
1790fcf3ce44SJohn Forte 	request_t *req,
1791fcf3ce44SJohn Forte 	xmlDocPtr doc
1792fcf3ce44SJohn Forte 	/* any additional arguments go here */
1793fcf3ce44SJohn Forte )
1794fcf3ce44SJohn Forte {
1795fcf3ce44SJohn Forte 	return (i_get_dd_dds_op(req, doc, OBJ_DD));
1796fcf3ce44SJohn Forte }
1797fcf3ce44SJohn Forte 
1798fcf3ce44SJohn Forte /*
1799fcf3ce44SJohn Forte  * ****************************************************************************
1800fcf3ce44SJohn Forte  *
1801fcf3ce44SJohn Forte  * get_ddset_op:
1802fcf3ce44SJohn Forte  *	service get operation on given dd set(s).
1803fcf3ce44SJohn Forte  *
1804fcf3ce44SJohn Forte  * req	- contains all info for a request.
1805fcf3ce44SJohn Forte  * doc	- response doc to fill up
1806fcf3ce44SJohn Forte  *
1807fcf3ce44SJohn Forte  * ****************************************************************************
1808fcf3ce44SJohn Forte  */
1809fcf3ce44SJohn Forte int
1810fcf3ce44SJohn Forte get_ddset_op(
1811fcf3ce44SJohn Forte 	request_t *req,
1812fcf3ce44SJohn Forte 	xmlDocPtr doc
1813fcf3ce44SJohn Forte 	/* any additional arguments go here */
1814fcf3ce44SJohn Forte )
1815fcf3ce44SJohn Forte {
1816fcf3ce44SJohn Forte 	return (i_get_dd_dds_op(req, doc, OBJ_DDS));
1817fcf3ce44SJohn Forte }
1818fcf3ce44SJohn Forte 
1819fcf3ce44SJohn Forte /*
1820fcf3ce44SJohn Forte  * ****************************************************************************
1821fcf3ce44SJohn Forte  *
1822fcf3ce44SJohn Forte  * enumerate_node_op:
1823fcf3ce44SJohn Forte  *	services enumerate node op.
1824fcf3ce44SJohn Forte  *
1825fcf3ce44SJohn Forte  * req	- contains enumerate request info.
1826fcf3ce44SJohn Forte  * doc	- response doc to fill up
1827fcf3ce44SJohn Forte  *
1828fcf3ce44SJohn Forte  * ****************************************************************************
1829fcf3ce44SJohn Forte  */
1830fcf3ce44SJohn Forte int
1831fcf3ce44SJohn Forte enumerate_node_op(
1832fcf3ce44SJohn Forte 	xmlDocPtr   doc
1833fcf3ce44SJohn Forte 	/* any additional arguments go here */
1834fcf3ce44SJohn Forte )
1835fcf3ce44SJohn Forte {
1836fcf3ce44SJohn Forte 	htab_t *htab = cache_get_htab(OBJ_ISCSI);
1837fcf3ce44SJohn Forte 	uint32_t uid = 0;
1838fcf3ce44SJohn Forte 	lookup_ctrl_t lc;
1839fcf3ce44SJohn Forte 	int	    ret = 0, ret_save = 0;
1840fcf3ce44SJohn Forte 
1841fcf3ce44SJohn Forte 	SET_UID_LCP(&lc, OBJ_ISCSI, 0);
1842fcf3ce44SJohn Forte 
1843fcf3ce44SJohn Forte 	lc.data[1].ptr = (uchar_t *)doc;
1844fcf3ce44SJohn Forte 	lc.data[2].ui = 0;
1845fcf3ce44SJohn Forte 
1846fcf3ce44SJohn Forte 	FOR_EACH_ITEM(htab, uid, {
1847fcf3ce44SJohn Forte 		lc.data[0].ui = uid;
1848fcf3ce44SJohn Forte 		ret = cache_lookup(&lc, NULL, cb_enumerate_node_info);
1849fcf3ce44SJohn Forte 		if (ret != 0) {
1850fcf3ce44SJohn Forte 		    ret_save = ret;
1851fcf3ce44SJohn Forte 		}
1852fcf3ce44SJohn Forte 	});
1853fcf3ce44SJohn Forte 
1854fcf3ce44SJohn Forte 	return (handle_partial_success(doc, ret_save));
1855fcf3ce44SJohn Forte }
1856fcf3ce44SJohn Forte 
1857fcf3ce44SJohn Forte /*
1858fcf3ce44SJohn Forte  * ****************************************************************************
1859fcf3ce44SJohn Forte  *
1860fcf3ce44SJohn Forte  * enumerate_dd_op:
1861fcf3ce44SJohn Forte  *	services enumerate discovery domain op.
1862fcf3ce44SJohn Forte  *
1863fcf3ce44SJohn Forte  * req	- contains enumerate request info.
1864fcf3ce44SJohn Forte  * doc	- response doc to fill up
1865fcf3ce44SJohn Forte  *
1866fcf3ce44SJohn Forte  * ****************************************************************************
1867fcf3ce44SJohn Forte  */
1868fcf3ce44SJohn Forte int
1869fcf3ce44SJohn Forte enumerate_dd_op(
1870fcf3ce44SJohn Forte 	xmlDocPtr   doc
1871fcf3ce44SJohn Forte 	/* any additional arguments go here */
1872fcf3ce44SJohn Forte )
1873fcf3ce44SJohn Forte {
1874fcf3ce44SJohn Forte 
1875fcf3ce44SJohn Forte 	htab_t *htab = cache_get_htab(OBJ_DD);
1876fcf3ce44SJohn Forte 	uint32_t uid = 0;
1877fcf3ce44SJohn Forte 	lookup_ctrl_t lc;
1878fcf3ce44SJohn Forte 	int	    ret = 0, ret_save = 0;
1879fcf3ce44SJohn Forte 
1880fcf3ce44SJohn Forte 	SET_UID_LCP(&lc, OBJ_DD, 0);
1881fcf3ce44SJohn Forte 
1882fcf3ce44SJohn Forte 	lc.data[1].ptr = (uchar_t *)doc;
1883fcf3ce44SJohn Forte 	lc.data[2].ui = 0;
1884fcf3ce44SJohn Forte 
1885fcf3ce44SJohn Forte 	FOR_EACH_ITEM(htab, uid, {
1886fcf3ce44SJohn Forte 		lc.data[0].ui = uid;
1887fcf3ce44SJohn Forte 		ret = cache_lookup(&lc, NULL, cb_enumerate_dd_info);
1888fcf3ce44SJohn Forte 		if (ret != 0) {
1889fcf3ce44SJohn Forte 		    ret_save = ret;
1890fcf3ce44SJohn Forte 		}
1891fcf3ce44SJohn Forte 	});
1892fcf3ce44SJohn Forte 
1893fcf3ce44SJohn Forte 	return (handle_partial_success(doc, ret_save));
1894fcf3ce44SJohn Forte }
1895fcf3ce44SJohn Forte 
1896fcf3ce44SJohn Forte /*
1897fcf3ce44SJohn Forte  * ****************************************************************************
1898fcf3ce44SJohn Forte  *
1899fcf3ce44SJohn Forte  * enumerate_ddset_op:
1900fcf3ce44SJohn Forte  *	services enumerate discovery domain set op.
1901fcf3ce44SJohn Forte  *
1902fcf3ce44SJohn Forte  * req	- contains enumerate request info.
1903fcf3ce44SJohn Forte  * doc	- response doc to fill up
1904fcf3ce44SJohn Forte  *
1905fcf3ce44SJohn Forte  * ****************************************************************************
1906fcf3ce44SJohn Forte  */
1907fcf3ce44SJohn Forte int
1908fcf3ce44SJohn Forte enumerate_ddset_op(
1909fcf3ce44SJohn Forte 	xmlDocPtr   doc
1910fcf3ce44SJohn Forte 	/* any additional arguments go here */
1911fcf3ce44SJohn Forte )
1912fcf3ce44SJohn Forte {
1913fcf3ce44SJohn Forte 	htab_t *htab = cache_get_htab(OBJ_DDS);
1914fcf3ce44SJohn Forte 	uint32_t uid = 0;
1915fcf3ce44SJohn Forte 	lookup_ctrl_t lc;
1916fcf3ce44SJohn Forte 	int	    ret = 0, ret_save = 0;
1917fcf3ce44SJohn Forte 
1918fcf3ce44SJohn Forte 	SET_UID_LCP(&lc, OBJ_DDS, 0);
1919fcf3ce44SJohn Forte 
1920fcf3ce44SJohn Forte 	lc.data[1].ptr = (uchar_t *)doc;
1921fcf3ce44SJohn Forte 	lc.data[2].ui = 0;
1922fcf3ce44SJohn Forte 
1923fcf3ce44SJohn Forte 	FOR_EACH_ITEM(htab, uid, {
1924fcf3ce44SJohn Forte 		lc.data[0].ui = uid;
1925fcf3ce44SJohn Forte 		ret = cache_lookup(&lc, NULL, cb_enumerate_ddset_info);
1926fcf3ce44SJohn Forte 		if (ret != 0) {
1927fcf3ce44SJohn Forte 		    ret_save = ret;
1928fcf3ce44SJohn Forte 		}
1929fcf3ce44SJohn Forte 	});
1930fcf3ce44SJohn Forte 
1931fcf3ce44SJohn Forte 	return (handle_partial_success(doc, ret_save));
1932fcf3ce44SJohn Forte }
1933fcf3ce44SJohn Forte 
1934fcf3ce44SJohn Forte /*
1935fcf3ce44SJohn Forte  * ****************************************************************************
1936fcf3ce44SJohn Forte  *
1937fcf3ce44SJohn Forte  * getassociated_dd_to_node_op:
1938fcf3ce44SJohn Forte  *	construct a list of node that is associated with a given Discovery
1939fcf3ce44SJohn Forte  *	Domain.
1940fcf3ce44SJohn Forte  *
1941fcf3ce44SJohn Forte  * req	- contains getAssociated request info.
1942fcf3ce44SJohn Forte  * doc	- response doc to fill up
1943fcf3ce44SJohn Forte  *
1944fcf3ce44SJohn Forte  * ****************************************************************************
1945fcf3ce44SJohn Forte  */
1946fcf3ce44SJohn Forte int
1947fcf3ce44SJohn Forte getAssociated_dd_to_node_op(
1948fcf3ce44SJohn Forte 	request_t *req,
1949fcf3ce44SJohn Forte 	xmlDocPtr   doc
1950fcf3ce44SJohn Forte 	/* any additional arguments go here */
1951fcf3ce44SJohn Forte )
1952fcf3ce44SJohn Forte {
1953fcf3ce44SJohn Forte 	uint32_t uid = 0, n;
1954fcf3ce44SJohn Forte 	lookup_ctrl_t lc, lc2;
1955fcf3ce44SJohn Forte 	int	i = 0, ret = 0, ret_save = 0;
1956fcf3ce44SJohn Forte 	bmp_t	*p;
1957fcf3ce44SJohn Forte 
1958fcf3ce44SJohn Forte 	lc.curr_uid = 0;
1959fcf3ce44SJohn Forte 	lc.type = OBJ_DD;
1960fcf3ce44SJohn Forte 	lc.id[0] = ATTR_INDEX_DD(ISNS_DD_NAME_ATTR_ID);
1961fcf3ce44SJohn Forte 	lc.op[0] = OP_STRING;
1962fcf3ce44SJohn Forte 	lc.op[1] = 0;
1963fcf3ce44SJohn Forte 
1964fcf3ce44SJohn Forte 	SET_UID_LCP(&lc2, OBJ_ISCSI, 0);
1965fcf3ce44SJohn Forte 
1966fcf3ce44SJohn Forte 	lc2.data[1].ptr = (uchar_t *)doc;
1967fcf3ce44SJohn Forte 
1968fcf3ce44SJohn Forte 	while (i < req->count) {
1969fcf3ce44SJohn Forte 		lc.data[0].ptr = (uchar_t *)req->req_data.data[i];
1970fcf3ce44SJohn Forte 		if ((uid = is_obj_there(&lc)) != 0) {
1971fcf3ce44SJohn Forte 		    ret = get_dd_matrix(uid, &p, &n);
1972fcf3ce44SJohn Forte 		    FOR_EACH_MEMBER(p, n, uid, {
1973fcf3ce44SJohn Forte 			lc2.data[0].ui = uid;
1974fcf3ce44SJohn Forte 			lc2.data[2].ptr = (uchar_t *)req->req_data.data[i];
1975fcf3ce44SJohn Forte 			ret = cache_lookup(&lc2, NULL,
1976fcf3ce44SJohn Forte 			    cb_getAssociated_node_info);
1977fcf3ce44SJohn Forte 		    });
1978fcf3ce44SJohn Forte 		    free(p);
1979fcf3ce44SJohn Forte 		} else {
1980fcf3ce44SJohn Forte 		    ret = ERR_MATCHING_DD_NOT_FOUND;
1981fcf3ce44SJohn Forte 		}
1982fcf3ce44SJohn Forte 		/* save error for this iteration */
1983fcf3ce44SJohn Forte 		if (ret != 0) {
1984fcf3ce44SJohn Forte 		    ret_save = ret;
1985fcf3ce44SJohn Forte 		}
1986fcf3ce44SJohn Forte 		ret = 0;
1987fcf3ce44SJohn Forte 		i++;
1988fcf3ce44SJohn Forte 	}
1989fcf3ce44SJohn Forte 
1990fcf3ce44SJohn Forte 	return (handle_partial_success(doc, ret_save));
1991fcf3ce44SJohn Forte }
1992fcf3ce44SJohn Forte 
1993fcf3ce44SJohn Forte /*
1994fcf3ce44SJohn Forte  * ****************************************************************************
1995fcf3ce44SJohn Forte  *
1996fcf3ce44SJohn Forte  * getassociated_node_to_dd_op:
1997fcf3ce44SJohn Forte  *	construct a list of Discovery Doamins that is associated with a given
1998fcf3ce44SJohn Forte  *	node.
1999fcf3ce44SJohn Forte  *
2000fcf3ce44SJohn Forte  * req	- contains getAssociated request info.
2001fcf3ce44SJohn Forte  * doc	- response doc to fill up
2002fcf3ce44SJohn Forte  *
2003fcf3ce44SJohn Forte  * ****************************************************************************
2004fcf3ce44SJohn Forte  */
2005fcf3ce44SJohn Forte int
2006fcf3ce44SJohn Forte getAssociated_node_to_dd_op(
2007fcf3ce44SJohn Forte 	request_t *req,
2008fcf3ce44SJohn Forte 	xmlDocPtr   doc
2009fcf3ce44SJohn Forte 	/* any additional arguments go here */
2010fcf3ce44SJohn Forte )
2011fcf3ce44SJohn Forte {
2012fcf3ce44SJohn Forte 	uint32_t uid = 0, dd_id;
2013fcf3ce44SJohn Forte 	lookup_ctrl_t lc, lc2;
2014fcf3ce44SJohn Forte 	int	i = 0, ret = 0, ret_save = 0;
2015fcf3ce44SJohn Forte 
2016fcf3ce44SJohn Forte 	lc.curr_uid = 0;
2017fcf3ce44SJohn Forte 	lc.type = OBJ_ISCSI;
2018fcf3ce44SJohn Forte 	lc.id[0] = ATTR_INDEX_ISCSI(ISNS_ISCSI_NAME_ATTR_ID);
2019fcf3ce44SJohn Forte 	lc.op[0] = OP_STRING;
2020fcf3ce44SJohn Forte 	lc.op[1] = 0;
2021fcf3ce44SJohn Forte 
2022fcf3ce44SJohn Forte 	SET_UID_LCP(&lc2, OBJ_DD, 0);
2023fcf3ce44SJohn Forte 
2024fcf3ce44SJohn Forte 	lc2.data[1].ptr = (uchar_t *)doc;
2025fcf3ce44SJohn Forte 
2026fcf3ce44SJohn Forte 	while (i < req->count) {
2027fcf3ce44SJohn Forte 		lc.data[0].ptr = (uchar_t *)req->req_data.data[i];
2028fcf3ce44SJohn Forte 		if ((uid = is_obj_there(&lc)) != 0) {
2029fcf3ce44SJohn Forte 		    if ((dd_id = get_dd_id(uid, 0)) == 0) {
2030fcf3ce44SJohn Forte 			ret = ERR_NO_ASSOCIATED_DD_FOUND;
2031fcf3ce44SJohn Forte 			i++;
2032fcf3ce44SJohn Forte 			continue;
2033fcf3ce44SJohn Forte 		    } else {
2034fcf3ce44SJohn Forte 			do {
2035fcf3ce44SJohn Forte 			    lc2.data[0].ui = dd_id;
2036fcf3ce44SJohn Forte 			    lc2.data[2].ptr = (uchar_t *)req->req_data.data[i];
2037fcf3ce44SJohn Forte 			    ret = cache_lookup(&lc2, NULL,
2038fcf3ce44SJohn Forte 				cb_getAssociated_node_to_dd_info);
2039fcf3ce44SJohn Forte 			    dd_id = get_dd_id(uid, dd_id);
2040fcf3ce44SJohn Forte 			} while (dd_id != 0);
2041fcf3ce44SJohn Forte 		    };
2042fcf3ce44SJohn Forte 		} else {
2043fcf3ce44SJohn Forte 		    ret = ERR_MATCHING_NODE_NOT_FOUND;
2044fcf3ce44SJohn Forte 		}
2045fcf3ce44SJohn Forte 		/* save error for this iteration */
2046fcf3ce44SJohn Forte 		if (ret != 0) {
2047fcf3ce44SJohn Forte 		    ret_save = ret;
2048fcf3ce44SJohn Forte 		}
2049fcf3ce44SJohn Forte 		ret = 0;
2050fcf3ce44SJohn Forte 		i++;
2051fcf3ce44SJohn Forte 	}
2052fcf3ce44SJohn Forte 
2053fcf3ce44SJohn Forte 	return (handle_partial_success(doc, ret_save));
2054fcf3ce44SJohn Forte }
2055fcf3ce44SJohn Forte 
2056fcf3ce44SJohn Forte /*
2057fcf3ce44SJohn Forte  * ****************************************************************************
2058fcf3ce44SJohn Forte  *
2059fcf3ce44SJohn Forte  * getassociated_ddset_to_dd_op:
2060fcf3ce44SJohn Forte  *	construct a list of Discovery Doamins that is associated with a given
2061fcf3ce44SJohn Forte  *	Discover Domain set.
2062fcf3ce44SJohn Forte  *
2063fcf3ce44SJohn Forte  * req	- contains getAssociated request info.
2064fcf3ce44SJohn Forte  * doc	- response doc to fill up
2065fcf3ce44SJohn Forte  *
2066fcf3ce44SJohn Forte  * ****************************************************************************
2067fcf3ce44SJohn Forte  */
2068fcf3ce44SJohn Forte int
2069fcf3ce44SJohn Forte getAssociated_ddset_to_dd_op(
2070fcf3ce44SJohn Forte 	request_t *req,
2071fcf3ce44SJohn Forte 	xmlDocPtr   doc
2072fcf3ce44SJohn Forte 	/* any additional arguments go here */
2073fcf3ce44SJohn Forte )
2074fcf3ce44SJohn Forte {
2075fcf3ce44SJohn Forte 	uint32_t uid = 0, n;
2076fcf3ce44SJohn Forte 	lookup_ctrl_t lc, lc2;
2077fcf3ce44SJohn Forte 	int	i = 0, ret = 0, ret_save = 0;
2078fcf3ce44SJohn Forte 	bmp_t	*p;
2079fcf3ce44SJohn Forte 
2080fcf3ce44SJohn Forte 	lc.curr_uid = 0;
2081fcf3ce44SJohn Forte 	lc.type = OBJ_DDS;
2082fcf3ce44SJohn Forte 	lc.id[0] = ATTR_INDEX_DDS(ISNS_DD_SET_NAME_ATTR_ID);
2083fcf3ce44SJohn Forte 	lc.op[0] = OP_STRING;
2084fcf3ce44SJohn Forte 	lc.op[1] = 0;
2085fcf3ce44SJohn Forte 
2086fcf3ce44SJohn Forte 	SET_UID_LCP(&lc2, OBJ_DD, 0);
2087fcf3ce44SJohn Forte 
2088fcf3ce44SJohn Forte 	lc2.data[1].ptr = (uchar_t *)doc;
2089fcf3ce44SJohn Forte 
2090fcf3ce44SJohn Forte 	while (i < req->count) {
2091fcf3ce44SJohn Forte 		lc.data[0].ptr = (uchar_t *)req->req_data.data[i];
2092fcf3ce44SJohn Forte 		if ((uid = is_obj_there(&lc)) != 0) {
2093fcf3ce44SJohn Forte 		    ret = get_dds_matrix(uid, &p, &n);
2094fcf3ce44SJohn Forte 		    FOR_EACH_MEMBER(p, n, uid, {
2095fcf3ce44SJohn Forte 			lc2.data[0].ui = uid;
2096fcf3ce44SJohn Forte 			lc2.data[2].ptr = (uchar_t *)req->req_data.data[i];
2097fcf3ce44SJohn Forte 			ret = cache_lookup(&lc2, NULL,
2098fcf3ce44SJohn Forte 			    cb_getAssociated_dd_info);
2099fcf3ce44SJohn Forte 		    });
2100fcf3ce44SJohn Forte 		    free(p);
2101fcf3ce44SJohn Forte 		} else {
2102fcf3ce44SJohn Forte 		    ret = ERR_MATCHING_DDSET_NOT_FOUND;
2103fcf3ce44SJohn Forte 		}
2104fcf3ce44SJohn Forte 		/* save error for this iteration */
2105fcf3ce44SJohn Forte 		if (ret != 0) {
2106fcf3ce44SJohn Forte 		    ret_save = ret;
2107fcf3ce44SJohn Forte 		}
2108fcf3ce44SJohn Forte 		ret = 0;
2109fcf3ce44SJohn Forte 		i++;
2110fcf3ce44SJohn Forte 	}
2111fcf3ce44SJohn Forte 
2112fcf3ce44SJohn Forte 	return (handle_partial_success(doc, ret_save));
2113fcf3ce44SJohn Forte }
2114fcf3ce44SJohn Forte 
2115fcf3ce44SJohn Forte /*
2116fcf3ce44SJohn Forte  * ****************************************************************************
2117fcf3ce44SJohn Forte  *
2118fcf3ce44SJohn Forte  * getassociated_dd_to_ddset_op:
2119fcf3ce44SJohn Forte  *	construct a list of Discovery Doamin sets that is associated with a
2120fcf3ce44SJohn Forte  *	given Discovery Domain.
2121fcf3ce44SJohn Forte  *
2122fcf3ce44SJohn Forte  * req	- contains getAssociated request info.
2123fcf3ce44SJohn Forte  * doc	- response doc to fill up
2124fcf3ce44SJohn Forte  *
2125fcf3ce44SJohn Forte  * ****************************************************************************
2126fcf3ce44SJohn Forte  */
2127fcf3ce44SJohn Forte int
2128fcf3ce44SJohn Forte getAssociated_dd_to_ddset_op(
2129fcf3ce44SJohn Forte 	request_t *req,
2130fcf3ce44SJohn Forte 	xmlDocPtr   doc
2131fcf3ce44SJohn Forte 	/* any additional arguments go here */
2132fcf3ce44SJohn Forte )
2133fcf3ce44SJohn Forte {
2134fcf3ce44SJohn Forte 	uint32_t uid = 0, ddset_id;
2135fcf3ce44SJohn Forte 	lookup_ctrl_t lc, lc2;
2136fcf3ce44SJohn Forte 	int	i = 0, ret = 0, ret_save = 0;
2137fcf3ce44SJohn Forte 
2138fcf3ce44SJohn Forte 	lc.curr_uid = 0;
2139fcf3ce44SJohn Forte 	lc.type = OBJ_DD;
2140fcf3ce44SJohn Forte 	lc.id[0] = ATTR_INDEX_DD(ISNS_DD_NAME_ATTR_ID);
2141fcf3ce44SJohn Forte 	lc.op[0] = OP_STRING;
2142fcf3ce44SJohn Forte 	lc.op[1] = 0;
2143fcf3ce44SJohn Forte 
2144fcf3ce44SJohn Forte 	SET_UID_LCP(&lc2, OBJ_DDS, 0);
2145fcf3ce44SJohn Forte 
2146fcf3ce44SJohn Forte 	lc2.data[1].ptr = (uchar_t *)doc;
2147fcf3ce44SJohn Forte 
2148fcf3ce44SJohn Forte 	while (i < req->count) {
2149fcf3ce44SJohn Forte 		lc.data[0].ptr = (uchar_t *)req->req_data.data[i];
2150fcf3ce44SJohn Forte 		if ((uid = is_obj_there(&lc)) != 0) {
2151fcf3ce44SJohn Forte 		    lc2.data[2].ui = 0;
2152fcf3ce44SJohn Forte 		    if ((ddset_id = get_dds_id(uid, 0)) == 0) {
2153fcf3ce44SJohn Forte 			ret = ERR_NO_ASSOCIATED_DDSET_FOUND;
2154fcf3ce44SJohn Forte 			i++;
2155fcf3ce44SJohn Forte 			continue;
2156fcf3ce44SJohn Forte 		    } else {
2157fcf3ce44SJohn Forte 			do {
2158fcf3ce44SJohn Forte 			    lc2.data[0].ui = ddset_id;
2159fcf3ce44SJohn Forte 			    lc2.data[2].ptr = (uchar_t *)req->req_data.data[i];
2160fcf3ce44SJohn Forte 			    ret = cache_lookup(&lc2, NULL,
2161fcf3ce44SJohn Forte 				cb_getAssociated_dd_to_ddset_info);
2162fcf3ce44SJohn Forte 			    ddset_id = get_dds_id(uid, ddset_id);
2163fcf3ce44SJohn Forte 			} while (ddset_id != 0);
2164fcf3ce44SJohn Forte 		    };
2165fcf3ce44SJohn Forte 		} else {
2166fcf3ce44SJohn Forte 		    ret = ERR_MATCHING_DD_NOT_FOUND;
2167fcf3ce44SJohn Forte 		}
2168fcf3ce44SJohn Forte 		if (ret != 0) {
2169fcf3ce44SJohn Forte 		    ret_save = ret;
2170fcf3ce44SJohn Forte 		}
2171fcf3ce44SJohn Forte 		i++;
2172fcf3ce44SJohn Forte 	}
2173fcf3ce44SJohn Forte 
2174fcf3ce44SJohn Forte 	return (handle_partial_success(doc, ret_save));
2175fcf3ce44SJohn Forte }
2176fcf3ce44SJohn Forte 
2177fcf3ce44SJohn Forte /*
2178fcf3ce44SJohn Forte  * ****************************************************************************
2179fcf3ce44SJohn Forte  *
2180fcf3ce44SJohn Forte  * delete_dd_ddset_op:
2181fcf3ce44SJohn Forte  *	removes a list of dd or dd set.
2182fcf3ce44SJohn Forte  *
2183fcf3ce44SJohn Forte  * req	- contains delete request info.
2184fcf3ce44SJohn Forte  * doc	- response doc to fill up
2185fcf3ce44SJohn Forte  * obj_type	- object type(either dd or dd set)
2186fcf3ce44SJohn Forte  *
2187fcf3ce44SJohn Forte  * ****************************************************************************
2188fcf3ce44SJohn Forte  */
2189fcf3ce44SJohn Forte int
2190fcf3ce44SJohn Forte delete_dd_ddset_op(
2191fcf3ce44SJohn Forte 	request_t *req,
2192fcf3ce44SJohn Forte 	xmlDocPtr doc,
2193fcf3ce44SJohn Forte 	object_type type
2194fcf3ce44SJohn Forte 	/* any additional arguments go here */
2195fcf3ce44SJohn Forte )
2196fcf3ce44SJohn Forte {
2197fcf3ce44SJohn Forte 	result_code_t ret = 0, ret_save = 0;
2198fcf3ce44SJohn Forte 	isns_type_t lc_type;
2199fcf3ce44SJohn Forte 	int i = 0, err_count = 0;
2200fcf3ce44SJohn Forte 	lookup_ctrl_t lc;
2201fcf3ce44SJohn Forte 	uint32_t uid;
2202fcf3ce44SJohn Forte 	xmlNodePtr	n_obj, n_node, root;
2203fcf3ce44SJohn Forte 	xmlAttrPtr	n_attr;
2204fcf3ce44SJohn Forte 	int different_err = 0;
2205fcf3ce44SJohn Forte 
2206fcf3ce44SJohn Forte 	root = xmlDocGetRootElement(doc);
2207fcf3ce44SJohn Forte 	if (root == NULL) {
2208fcf3ce44SJohn Forte 	    return (ERR_SYNTAX_MISSING_ROOT);
2209fcf3ce44SJohn Forte 	}
2210fcf3ce44SJohn Forte 	lc_type = get_lc_type(type);
2211fcf3ce44SJohn Forte 	if ((lc_type != OBJ_DD) && (lc_type != OBJ_DDS)) {
2212fcf3ce44SJohn Forte 	    return (ERR_INVALID_MGMT_REQUEST);
2213fcf3ce44SJohn Forte 	}
2214fcf3ce44SJohn Forte 
2215fcf3ce44SJohn Forte 	/* prepare lookup ctrl data for looking for the node object */
2216fcf3ce44SJohn Forte 	lc.curr_uid = 0;
2217fcf3ce44SJohn Forte 	lc.type = lc_type;
2218fcf3ce44SJohn Forte 	lc.id[0] = get_lc_id(req->op_info.obj);
2219fcf3ce44SJohn Forte 	lc.op[0] = OP_STRING;
2220fcf3ce44SJohn Forte 	lc.op[1] = 0;
2221fcf3ce44SJohn Forte 	lc.data[1].ptr = (uchar_t *)doc; /* xml writer descriptor */
2222fcf3ce44SJohn Forte 	while (i < req->count) {
2223fcf3ce44SJohn Forte 		lc.data[0].ptr = (uchar_t *)req->req_data.data[i];
2224fcf3ce44SJohn Forte 
2225fcf3ce44SJohn Forte 		/* lock the cache for writing */
2226fcf3ce44SJohn Forte 		(void) cache_lock_write();
2227fcf3ce44SJohn Forte 
2228fcf3ce44SJohn Forte 		if ((uid = is_obj_there(&lc)) != 0) {
2229fcf3ce44SJohn Forte 		    /* remove the dd/ddset */
2230fcf3ce44SJohn Forte 		    ret = (lc_type == OBJ_DD) ?
2231fcf3ce44SJohn Forte 			remove_dd_object(uid) :
2232fcf3ce44SJohn Forte 			remove_dds_object(uid);
2233fcf3ce44SJohn Forte 		    /* unlock the cache and sync the data */
2234fcf3ce44SJohn Forte 		    ret = cache_unlock_sync(ret);
2235fcf3ce44SJohn Forte 		} else {
2236fcf3ce44SJohn Forte 		    /* unlock the cache and no need to sync data */
2237fcf3ce44SJohn Forte 		    (void) cache_unlock_nosync();
2238fcf3ce44SJohn Forte 		    /* set an error and continue. */
2239*5fbbe9c6Swl202157@icefox 		    ret = (lc_type == OBJ_DD) ?  ERR_MATCHING_DD_NOT_FOUND :
2240*5fbbe9c6Swl202157@icefox 			ERR_MATCHING_DDSET_NOT_FOUND;
2241fcf3ce44SJohn Forte 		}
2242fcf3ce44SJohn Forte 
2243fcf3ce44SJohn Forte 		if (ret != 0) {
2244fcf3ce44SJohn Forte 		/* keep track if there are different errors encountered. */
2245fcf3ce44SJohn Forte 		    if (ret_save != 0 && ret != ret_save) {
2246fcf3ce44SJohn Forte 			different_err++;
2247fcf3ce44SJohn Forte 		    }
2248fcf3ce44SJohn Forte 		    err_count++;
2249fcf3ce44SJohn Forte 		    n_obj = xmlNewNode(NULL, (xmlChar *)ISNSOBJECT);
2250fcf3ce44SJohn Forte 		    if (n_obj) {
2251fcf3ce44SJohn Forte 			if ((n_obj = xmlAddChild(root, n_obj)) == NULL) {
2252fcf3ce44SJohn Forte 			    return (ERR_XML_ADDCHILD_FAILED);
2253fcf3ce44SJohn Forte 			}
2254fcf3ce44SJohn Forte 		    } else {
2255fcf3ce44SJohn Forte 			return (ERR_XML_NEWNODE_FAILED);
2256fcf3ce44SJohn Forte 		    }
2257fcf3ce44SJohn Forte 
2258fcf3ce44SJohn Forte 		    n_node = (lc_type == OBJ_DD) ?
2259fcf3ce44SJohn Forte 			xmlNewNode(NULL, (xmlChar *)DDOBJECT) :
2260fcf3ce44SJohn Forte 			xmlNewNode(NULL, (xmlChar *)DDSETOBJECT);
2261fcf3ce44SJohn Forte 		    if (n_node) {
2262fcf3ce44SJohn Forte 			if ((n_node = xmlAddChild(n_obj, n_node)) == NULL) {
2263fcf3ce44SJohn Forte 			    return (ERR_XML_ADDCHILD_FAILED);
2264fcf3ce44SJohn Forte 			}
2265fcf3ce44SJohn Forte 			n_attr = xmlSetProp(n_node, (xmlChar *)NAMEATTR,
2266fcf3ce44SJohn Forte 				(xmlChar *)req->req_data.data[i]);
2267fcf3ce44SJohn Forte 			if (n_attr == NULL) {
2268fcf3ce44SJohn Forte 			    return (ERR_XML_SETPROP_FAILED);
2269fcf3ce44SJohn Forte 			}
2270fcf3ce44SJohn Forte 		    } else {
2271fcf3ce44SJohn Forte 			return (ERR_XML_NEWNODE_FAILED);
2272fcf3ce44SJohn Forte 		    }
2273fcf3ce44SJohn Forte 		    ret_save = ret;
2274fcf3ce44SJohn Forte 		}
2275fcf3ce44SJohn Forte 		i ++;
2276fcf3ce44SJohn Forte 	}
2277fcf3ce44SJohn Forte 
2278fcf3ce44SJohn Forte 	return (handle_partial_failure(doc, ret_save,
2279fcf3ce44SJohn Forte 	    (req->count == err_count && !different_err) ? B_TRUE : B_FALSE));
2280fcf3ce44SJohn Forte }
2281fcf3ce44SJohn Forte 
2282fcf3ce44SJohn Forte /*
2283fcf3ce44SJohn Forte  * ****************************************************************************
2284fcf3ce44SJohn Forte  *
2285fcf3ce44SJohn Forte  * delete_ddmember_ddsetmember_op:
2286fcf3ce44SJohn Forte  *	removes a list of dd memeber or dd seti member.
2287fcf3ce44SJohn Forte  *
2288fcf3ce44SJohn Forte  * req	- contains delete request info.
2289fcf3ce44SJohn Forte  * doc	- response doc to fill up
2290fcf3ce44SJohn Forte  * type	- object type(either dd or dd set)
2291fcf3ce44SJohn Forte  *
2292fcf3ce44SJohn Forte  * ****************************************************************************
2293fcf3ce44SJohn Forte  */
2294fcf3ce44SJohn Forte int
2295fcf3ce44SJohn Forte delete_ddmember_ddsetmember_op(
2296fcf3ce44SJohn Forte 	request_t *req,
2297fcf3ce44SJohn Forte 	xmlDocPtr doc,
2298fcf3ce44SJohn Forte 	object_type type
2299fcf3ce44SJohn Forte 	/* any additional arguments go here */
2300fcf3ce44SJohn Forte )
2301fcf3ce44SJohn Forte {
2302fcf3ce44SJohn Forte 	result_code_t ret = 0, ret_save = 0;
2303fcf3ce44SJohn Forte 	isns_type_t lc_type;
2304fcf3ce44SJohn Forte 	int i = 0, err_count = 0;
2305fcf3ce44SJohn Forte 	lookup_ctrl_t lc, lc2;
2306fcf3ce44SJohn Forte 	uint32_t container_id, member_id;
2307fcf3ce44SJohn Forte 	xmlNodePtr	n_node, n_obj, root;
2308fcf3ce44SJohn Forte 	xmlAttrPtr	n_attr;
2309fcf3ce44SJohn Forte 	int different_err = 0;
2310fcf3ce44SJohn Forte 	int is_a_member;
2311fcf3ce44SJohn Forte 
2312fcf3ce44SJohn Forte 	lc_type = get_lc_type(type);
2313fcf3ce44SJohn Forte 	if ((lc_type != OBJ_DD) && (lc_type != OBJ_DDS)) {
2314fcf3ce44SJohn Forte 	    return (ERR_INVALID_MGMT_REQUEST);
2315fcf3ce44SJohn Forte 	}
2316fcf3ce44SJohn Forte 
2317fcf3ce44SJohn Forte 	/* prepare lookup ctrl data for looking for the node object */
2318fcf3ce44SJohn Forte 	lc.curr_uid = 0;
2319fcf3ce44SJohn Forte 	lc.type = lc_type;
2320fcf3ce44SJohn Forte 	lc.id[0] = get_lc_id(req->op_info.obj);
2321fcf3ce44SJohn Forte 	lc.op[0] = OP_STRING;
2322fcf3ce44SJohn Forte 	lc.op[1] = 0;
2323fcf3ce44SJohn Forte 
2324fcf3ce44SJohn Forte 	lc2.curr_uid = 0;
2325fcf3ce44SJohn Forte 	if (lc_type == OBJ_DD) {
2326fcf3ce44SJohn Forte 	    lc2.type = OBJ_ISCSI;
2327fcf3ce44SJohn Forte 	    lc2.id[0] = ATTR_INDEX_ISCSI(ISNS_ISCSI_NAME_ATTR_ID);
2328fcf3ce44SJohn Forte 	} else {
2329fcf3ce44SJohn Forte 	    lc2.type = OBJ_DD;
2330fcf3ce44SJohn Forte 	    lc2.id[0] = ATTR_INDEX_DD(ISNS_DD_NAME_ATTR_ID);
2331fcf3ce44SJohn Forte 	}
2332fcf3ce44SJohn Forte 	lc2.op[0] = OP_STRING;
2333fcf3ce44SJohn Forte 	lc2.op[1] = 0;
2334fcf3ce44SJohn Forte 
2335fcf3ce44SJohn Forte 	root = xmlDocGetRootElement(doc);
2336fcf3ce44SJohn Forte 	if (root == NULL) {
2337fcf3ce44SJohn Forte 	    return (ERR_SYNTAX_MISSING_ROOT);
2338fcf3ce44SJohn Forte 	}
2339fcf3ce44SJohn Forte 
2340fcf3ce44SJohn Forte 	while (i < req->count) {
2341fcf3ce44SJohn Forte 		lc.data[0].ptr = (uchar_t *)req->req_data.pair[i]->container;
2342fcf3ce44SJohn Forte 
2343fcf3ce44SJohn Forte 		/* get the dd_id/dds_id */
2344fcf3ce44SJohn Forte 		(void) cache_lock_write();
2345fcf3ce44SJohn Forte 		container_id = is_obj_there(&lc);
2346fcf3ce44SJohn Forte 
2347fcf3ce44SJohn Forte 		if (container_id != 0) {
2348fcf3ce44SJohn Forte 		    lc2.data[0].ptr = (uchar_t *)req->req_data.pair[i]->member;
2349fcf3ce44SJohn Forte 
2350fcf3ce44SJohn Forte 		    member_id = is_obj_there(&lc2);
2351fcf3ce44SJohn Forte 		    if (member_id != 0) {
2352fcf3ce44SJohn Forte 			is_a_member =
2353fcf3ce44SJohn Forte 			    (container_id ==
2354fcf3ce44SJohn Forte 			    ((lc_type == OBJ_DD) ?
2355fcf3ce44SJohn Forte 			    get_dd_id(member_id, container_id - 1) :
2356fcf3ce44SJohn Forte 			    get_dds_id(member_id, container_id - 1)));
2357fcf3ce44SJohn Forte 		    }
2358fcf3ce44SJohn Forte 		    if (member_id != 0 && is_a_member != 0) {
2359fcf3ce44SJohn Forte 			/* delete the dd member */
2360fcf3ce44SJohn Forte 			ret = (lc_type == OBJ_DD) ?
2361fcf3ce44SJohn Forte 			    i_delete_ddmember_op(
2362fcf3ce44SJohn Forte 				(uchar_t *)req->req_data.pair[i]->container,
2363fcf3ce44SJohn Forte 				(uchar_t *)req->req_data.pair[i]->member) :
2364fcf3ce44SJohn Forte 			    i_delete_ddsetmember_op(
2365fcf3ce44SJohn Forte 				(uchar_t *)req->req_data.pair[i]->container,
2366fcf3ce44SJohn Forte 				(uchar_t *)req->req_data.pair[i]->member);
2367fcf3ce44SJohn Forte 			/* unlock the cache and sync the data */
2368fcf3ce44SJohn Forte 			ret = cache_unlock_sync(ret);
2369fcf3ce44SJohn Forte 		    } else {
2370fcf3ce44SJohn Forte 			/* unlock the cache and no need to sync */
2371fcf3ce44SJohn Forte 			(void) cache_unlock_nosync();
2372fcf3ce44SJohn Forte 			ret = ERR_NO_SUCH_ASSOCIATION;
2373fcf3ce44SJohn Forte 		    }
2374fcf3ce44SJohn Forte 		} else {
2375fcf3ce44SJohn Forte 		    /* unlock the cache and no need to sync */
2376fcf3ce44SJohn Forte 		    (void) cache_unlock_nosync();
2377fcf3ce44SJohn Forte 		    ret = (lc_type == OBJ_DD) ?  ERR_MATCHING_DD_NOT_FOUND :
2378fcf3ce44SJohn Forte 			ERR_MATCHING_DDSET_NOT_FOUND;
2379fcf3ce44SJohn Forte 		}
2380fcf3ce44SJohn Forte 
2381fcf3ce44SJohn Forte 		if (ret != 0) {
2382fcf3ce44SJohn Forte 		/* keep track if there are different errors encountered. */
2383fcf3ce44SJohn Forte 		    if (ret_save != 0 && ret != ret_save) {
2384fcf3ce44SJohn Forte 			different_err++;
2385fcf3ce44SJohn Forte 		    }
2386fcf3ce44SJohn Forte 		    ret_save = ret;
2387fcf3ce44SJohn Forte 		    err_count++;
2388fcf3ce44SJohn Forte 		    n_obj = xmlNewNode(NULL, (xmlChar *)ASSOCIATION);
2389fcf3ce44SJohn Forte 		    if (n_obj) {
2390fcf3ce44SJohn Forte 			n_obj = xmlAddChild(root, n_obj);
2391fcf3ce44SJohn Forte 			if (n_obj == NULL) {
2392fcf3ce44SJohn Forte 			    return (ERR_XML_ADDCHILD_FAILED);
2393fcf3ce44SJohn Forte 			}
2394fcf3ce44SJohn Forte 		    } else {
2395fcf3ce44SJohn Forte 			return (ERR_XML_NEWNODE_FAILED);
2396fcf3ce44SJohn Forte 		    }
2397fcf3ce44SJohn Forte 		    if (lc_type == OBJ_DD) {
2398fcf3ce44SJohn Forte 			n_node =
2399fcf3ce44SJohn Forte 			    xmlNewNode(NULL, (xmlChar *)DDOBJECTMEMBER);
2400fcf3ce44SJohn Forte 			n_attr = xmlSetProp(n_node, (xmlChar *)NODENAMEATTR,
2401fcf3ce44SJohn Forte 			    (xmlChar *)req->req_data.pair[i]->member);
2402fcf3ce44SJohn Forte 			if (n_attr == NULL) {
2403fcf3ce44SJohn Forte 			    return (ERR_XML_SETPROP_FAILED);
2404fcf3ce44SJohn Forte 			}
2405fcf3ce44SJohn Forte 			n_attr = xmlSetProp(n_node, (xmlChar *)DDNAMEATTR,
2406fcf3ce44SJohn Forte 			    (xmlChar *)req->req_data.pair[i]->container);
2407fcf3ce44SJohn Forte 			if (n_attr == NULL) {
2408fcf3ce44SJohn Forte 			    return (ERR_XML_SETPROP_FAILED);
2409fcf3ce44SJohn Forte 			}
2410fcf3ce44SJohn Forte 		    } else {
2411fcf3ce44SJohn Forte 			n_node =
2412fcf3ce44SJohn Forte 			    xmlNewNode(NULL, (xmlChar *)DDSETOBJECTMEMBER);
2413fcf3ce44SJohn Forte 			n_attr = xmlSetProp(n_node, (xmlChar *)DDNAMEATTR,
2414fcf3ce44SJohn Forte 			    (xmlChar *)req->req_data.pair[i]->member);
2415fcf3ce44SJohn Forte 			if (n_attr == NULL) {
2416fcf3ce44SJohn Forte 			    return (ERR_XML_SETPROP_FAILED);
2417fcf3ce44SJohn Forte 			}
2418fcf3ce44SJohn Forte 			n_attr = xmlSetProp(n_node, (xmlChar *)DDSETNAMEATTR,
2419fcf3ce44SJohn Forte 			    (xmlChar *)req->req_data.pair[i]->container);
2420fcf3ce44SJohn Forte 			if (n_attr == NULL) {
2421fcf3ce44SJohn Forte 			    return (ERR_XML_SETPROP_FAILED);
2422fcf3ce44SJohn Forte 			}
2423fcf3ce44SJohn Forte 		    }
2424fcf3ce44SJohn Forte 		    if (xmlAddChild(n_obj, n_node) == NULL) {
2425fcf3ce44SJohn Forte 			return (ERR_XML_ADDCHILD_FAILED);
2426fcf3ce44SJohn Forte 		    }
2427fcf3ce44SJohn Forte 		}
2428fcf3ce44SJohn Forte 		i++;
2429fcf3ce44SJohn Forte 	}
2430fcf3ce44SJohn Forte 
2431fcf3ce44SJohn Forte 	return (handle_partial_failure(doc, ret_save,
2432fcf3ce44SJohn Forte 	    (req->count == err_count && !different_err) ? B_TRUE : B_FALSE));
2433fcf3ce44SJohn Forte }
2434fcf3ce44SJohn Forte 
2435fcf3ce44SJohn Forte /*
2436fcf3ce44SJohn Forte  * ****************************************************************************
2437fcf3ce44SJohn Forte  *
2438fcf3ce44SJohn Forte  * create_ddmember_ddsetmember_op:
2439fcf3ce44SJohn Forte  *	removes a list of dd memeber or dd seti member.
2440fcf3ce44SJohn Forte  *
2441fcf3ce44SJohn Forte  * req	- contains delete request info.
2442fcf3ce44SJohn Forte  * doc	- response doc to fill up
2443fcf3ce44SJohn Forte  * type	- object type(either dd or dd set)
2444fcf3ce44SJohn Forte  *
2445fcf3ce44SJohn Forte  * ****************************************************************************
2446fcf3ce44SJohn Forte  */
2447fcf3ce44SJohn Forte int
2448fcf3ce44SJohn Forte create_ddmember_ddsetmember_op(
2449fcf3ce44SJohn Forte 	request_t *req,
2450fcf3ce44SJohn Forte 	xmlDocPtr doc,
2451fcf3ce44SJohn Forte 	object_type type
2452fcf3ce44SJohn Forte 	/* any additional arguments go here */
2453fcf3ce44SJohn Forte )
2454fcf3ce44SJohn Forte {
2455fcf3ce44SJohn Forte 	result_code_t ret = 0, ret_save = 0;
2456fcf3ce44SJohn Forte 	isns_type_t lc_type;
2457fcf3ce44SJohn Forte 	int i = 0, err_count = 0;
2458fcf3ce44SJohn Forte 	lookup_ctrl_t lc, lc2;
2459fcf3ce44SJohn Forte 	uint32_t container_id, member_id;
2460fcf3ce44SJohn Forte 	xmlNodePtr	n_node, n_obj, root;
2461fcf3ce44SJohn Forte 	isns_assoc_iscsi_t aiscsi = { 0 };
2462fcf3ce44SJohn Forte 	isns_assoc_dd_t add = { 0 };
2463fcf3ce44SJohn Forte 	isns_obj_t *assoc;
2464fcf3ce44SJohn Forte 	isns_attr_t *attr;
2465fcf3ce44SJohn Forte 	uint32_t len;
2466fcf3ce44SJohn Forte 	int different_err = 0;
2467fcf3ce44SJohn Forte 
2468fcf3ce44SJohn Forte 	lc_type = get_lc_type(type);
2469fcf3ce44SJohn Forte 	if ((lc_type != OBJ_DD) && (lc_type != OBJ_DDS)) {
2470fcf3ce44SJohn Forte 	    return (ERR_INVALID_MGMT_REQUEST);
2471fcf3ce44SJohn Forte 	}
2472fcf3ce44SJohn Forte 
2473fcf3ce44SJohn Forte 	/* prepare lookup ctrl data for looking for the node object */
2474fcf3ce44SJohn Forte 	lc.curr_uid = 0;
2475fcf3ce44SJohn Forte 	lc.type = lc_type;
2476fcf3ce44SJohn Forte 	lc.id[0] = get_lc_id(req->op_info.obj);
2477fcf3ce44SJohn Forte 	lc.op[0] = OP_STRING;
2478fcf3ce44SJohn Forte 	lc.op[1] = 0;
2479fcf3ce44SJohn Forte 
2480fcf3ce44SJohn Forte 	lc2.curr_uid = 0;
2481fcf3ce44SJohn Forte 	if (lc_type == OBJ_DD) {
2482fcf3ce44SJohn Forte 	    lc2.type = OBJ_ISCSI;
2483fcf3ce44SJohn Forte 	    lc2.id[0] = ATTR_INDEX_ISCSI(ISNS_ISCSI_NAME_ATTR_ID);
2484fcf3ce44SJohn Forte 	} else {
2485fcf3ce44SJohn Forte 	    lc2.type = OBJ_DD;
2486fcf3ce44SJohn Forte 	    lc2.id[0] = ATTR_INDEX_DD(ISNS_DD_NAME_ATTR_ID);
2487fcf3ce44SJohn Forte 	}
2488fcf3ce44SJohn Forte 	lc2.op[0] = OP_STRING;
2489fcf3ce44SJohn Forte 	lc2.op[1] = 0;
2490fcf3ce44SJohn Forte 
2491fcf3ce44SJohn Forte 	root = xmlDocGetRootElement(doc);
2492fcf3ce44SJohn Forte 	if (root == NULL) {
2493fcf3ce44SJohn Forte 	    return (ERR_SYNTAX_MISSING_ROOT);
2494fcf3ce44SJohn Forte 	}
2495fcf3ce44SJohn Forte 
2496fcf3ce44SJohn Forte 	while (i < req->count) {
2497fcf3ce44SJohn Forte 		lc.data[0].ptr = (uchar_t *)req->req_data.pair[i]->container;
2498fcf3ce44SJohn Forte 
2499fcf3ce44SJohn Forte 		/* get the dd_id/dds_id */
2500fcf3ce44SJohn Forte 		(void) cache_lock_write();
2501fcf3ce44SJohn Forte 		container_id = is_obj_there(&lc);
2502fcf3ce44SJohn Forte 
2503fcf3ce44SJohn Forte 		if (container_id != 0) {
2504fcf3ce44SJohn Forte 		    (void) memset(&aiscsi, 0, sizeof (aiscsi));
2505fcf3ce44SJohn Forte 		    if (lc_type == OBJ_DD) {
2506fcf3ce44SJohn Forte 			aiscsi.puid = container_id;
2507fcf3ce44SJohn Forte 			aiscsi.type = OBJ_ASSOC_ISCSI;
2508fcf3ce44SJohn Forte 			attr = &aiscsi.attrs[ATTR_INDEX_ASSOC_ISCSI(
2509fcf3ce44SJohn Forte 			    ISNS_DD_ISCSI_NAME_ATTR_ID)];
2510fcf3ce44SJohn Forte 			attr->tag = ISNS_DD_ISCSI_NAME_ATTR_ID;
2511fcf3ce44SJohn Forte 			len = xmlStrlen(
2512fcf3ce44SJohn Forte 			    (xmlChar *)req->req_data.pair[i]->member) + 1;
2513fcf3ce44SJohn Forte 			len += 4 - (len % 4); /* on 4 bytes aligned */
2514fcf3ce44SJohn Forte 			attr->len = len;
2515fcf3ce44SJohn Forte 			attr->value.ptr =
2516fcf3ce44SJohn Forte 			    (uchar_t *)req->req_data.pair[i]->member;
2517fcf3ce44SJohn Forte 			assoc = (isns_obj_t *)&aiscsi;
2518fcf3ce44SJohn Forte 
2519fcf3ce44SJohn Forte 			/* add the dd member */
2520fcf3ce44SJohn Forte 			ret = add_dd_member(assoc);
2521fcf3ce44SJohn Forte 
2522fcf3ce44SJohn Forte 			/* unlock the cache and sync the data */
2523fcf3ce44SJohn Forte 			ret = cache_unlock_sync(ret);
2524fcf3ce44SJohn Forte 		    } else {
2525fcf3ce44SJohn Forte 			lc2.data[0].ptr =
2526fcf3ce44SJohn Forte 			    (uchar_t *)req->req_data.pair[i]->member;
2527fcf3ce44SJohn Forte 
2528fcf3ce44SJohn Forte 			if ((member_id = is_obj_there(&lc2)) != 0) {
2529fcf3ce44SJohn Forte 			    add.puid = container_id;
2530fcf3ce44SJohn Forte 			    add.type = OBJ_ASSOC_DD;
2531fcf3ce44SJohn Forte 			    attr = &add.attrs[ATTR_INDEX_ASSOC_DD(
2532fcf3ce44SJohn Forte 				ISNS_DD_ID_ATTR_ID)];
2533fcf3ce44SJohn Forte 			    attr->tag = ISNS_DD_ID_ATTR_ID;
2534fcf3ce44SJohn Forte 			    attr->len = 4;
2535fcf3ce44SJohn Forte 			    attr->value.ui = member_id;
2536fcf3ce44SJohn Forte 			    assoc = (isns_obj_t *)&add;
2537fcf3ce44SJohn Forte 
2538fcf3ce44SJohn Forte 			    /* add the dd-set member */
2539fcf3ce44SJohn Forte 			    ret = add_dds_member(assoc);
2540fcf3ce44SJohn Forte 
2541fcf3ce44SJohn Forte 			    /* unlock the cache and sync the data */
2542fcf3ce44SJohn Forte 			    ret = cache_unlock_sync(ret);
2543fcf3ce44SJohn Forte 			} else {
2544fcf3ce44SJohn Forte 			    /* unlock the cache and no need to sync */
2545fcf3ce44SJohn Forte 			    (void) cache_unlock_nosync();
2546fcf3ce44SJohn Forte 			    ret = ERR_MATCHING_DD_NOT_FOUND;
2547fcf3ce44SJohn Forte 			}
2548fcf3ce44SJohn Forte 		    }
2549fcf3ce44SJohn Forte 		} else {
2550fcf3ce44SJohn Forte 		    /* unlock the cache and no need to sync */
2551fcf3ce44SJohn Forte 		    (void) cache_unlock_nosync();
2552fcf3ce44SJohn Forte 		    ret = (lc_type == OBJ_DD) ?  ERR_MATCHING_DD_NOT_FOUND :
2553fcf3ce44SJohn Forte 			ERR_MATCHING_DDSET_NOT_FOUND;
2554fcf3ce44SJohn Forte 		}
2555fcf3ce44SJohn Forte 		if (ret != 0) {
2556fcf3ce44SJohn Forte 		/* keep track if there are different errors encountered. */
2557fcf3ce44SJohn Forte 		    if (ret_save != 0 && ret != ret_save) {
2558fcf3ce44SJohn Forte 			different_err++;
2559fcf3ce44SJohn Forte 		    }
2560fcf3ce44SJohn Forte 		    err_count++;
2561fcf3ce44SJohn Forte 		    n_obj = xmlNewNode(NULL, (xmlChar *)ASSOCIATION);
2562fcf3ce44SJohn Forte 		    if (n_obj) {
2563fcf3ce44SJohn Forte 			n_obj = xmlAddChild(root, n_obj);
2564fcf3ce44SJohn Forte 			if (n_obj == NULL) {
2565fcf3ce44SJohn Forte 			    return (ERR_XML_ADDCHILD_FAILED);
2566fcf3ce44SJohn Forte 			}
2567fcf3ce44SJohn Forte 		    } else {
2568fcf3ce44SJohn Forte 			return (ERR_XML_NEWNODE_FAILED);
2569fcf3ce44SJohn Forte 		    }
2570fcf3ce44SJohn Forte 		    if (lc_type == OBJ_DD) {
2571fcf3ce44SJohn Forte 			n_node =
2572fcf3ce44SJohn Forte 			    xmlNewNode(NULL, (xmlChar *)DDOBJECTMEMBER);
2573fcf3ce44SJohn Forte 			if (xmlSetProp(n_node, (xmlChar *)NODENAMEATTR,
2574fcf3ce44SJohn Forte 			    (xmlChar *)req->req_data.pair[i]->member) == NULL) {
2575fcf3ce44SJohn Forte 			    return (ERR_XML_SETPROP_FAILED);
2576fcf3ce44SJohn Forte 			}
2577fcf3ce44SJohn Forte 			if (xmlSetProp(n_node, (xmlChar *)DDNAMEATTR,
2578fcf3ce44SJohn Forte 			    (xmlChar *)req->req_data.pair[i]->container) ==
2579fcf3ce44SJohn Forte 			    NULL) {
2580fcf3ce44SJohn Forte 			    return (ERR_XML_SETPROP_FAILED);
2581fcf3ce44SJohn Forte 			}
2582fcf3ce44SJohn Forte 		    } else {
2583fcf3ce44SJohn Forte 			n_node =
2584fcf3ce44SJohn Forte 			    xmlNewNode(NULL, (xmlChar *)DDSETOBJECTMEMBER);
2585fcf3ce44SJohn Forte 			if (xmlSetProp(n_node, (xmlChar *)DDNAMEATTR,
2586fcf3ce44SJohn Forte 			    (xmlChar *)req->req_data.pair[i]->member) == NULL) {
2587fcf3ce44SJohn Forte 			    return (ERR_XML_SETPROP_FAILED);
2588fcf3ce44SJohn Forte 			}
2589fcf3ce44SJohn Forte 			if (xmlSetProp(n_node, (xmlChar *)DDSETNAMEATTR,
2590fcf3ce44SJohn Forte 			    (xmlChar *)req->req_data.pair[i]->container) ==
2591fcf3ce44SJohn Forte 			    NULL) {
2592fcf3ce44SJohn Forte 			    return (ERR_XML_SETPROP_FAILED);
2593fcf3ce44SJohn Forte 			}
2594fcf3ce44SJohn Forte 		    }
2595fcf3ce44SJohn Forte 		    if (xmlAddChild(n_obj, n_node) == NULL) {
2596fcf3ce44SJohn Forte 			return (ERR_XML_ADDCHILD_FAILED);
2597fcf3ce44SJohn Forte 		    }
2598fcf3ce44SJohn Forte 		    ret_save = ret;
2599fcf3ce44SJohn Forte 		}
2600fcf3ce44SJohn Forte 		i++;
2601fcf3ce44SJohn Forte 	}
2602fcf3ce44SJohn Forte 
2603fcf3ce44SJohn Forte 	return (handle_partial_failure(doc, ret_save,
2604fcf3ce44SJohn Forte 	    (req->count == err_count && !different_err) ? B_TRUE : B_FALSE));
2605fcf3ce44SJohn Forte }
2606fcf3ce44SJohn Forte 
2607fcf3ce44SJohn Forte /*
2608fcf3ce44SJohn Forte  * ****************************************************************************
2609fcf3ce44SJohn Forte  *
2610fcf3ce44SJohn Forte  * rename_dd_ddset_op:
2611fcf3ce44SJohn Forte  *	removes a list of dd memeber or dd seti member.
2612fcf3ce44SJohn Forte  *
2613fcf3ce44SJohn Forte  * req	- contains delete request info.
2614fcf3ce44SJohn Forte  * doc	- response doc to fill up
2615fcf3ce44SJohn Forte  * type	- object type(either dd or dd set)
2616fcf3ce44SJohn Forte  *
2617fcf3ce44SJohn Forte  * ****************************************************************************
2618fcf3ce44SJohn Forte  */
2619fcf3ce44SJohn Forte static int
2620fcf3ce44SJohn Forte rename_dd_ddset_op(
2621fcf3ce44SJohn Forte 	request_t *req,
2622fcf3ce44SJohn Forte 	xmlDocPtr doc,
2623fcf3ce44SJohn Forte 	object_type type
2624fcf3ce44SJohn Forte 	/* any additional arguments go here */
2625fcf3ce44SJohn Forte )
2626fcf3ce44SJohn Forte {
2627fcf3ce44SJohn Forte 	result_code_t ret = 0, ret_save = 0;
2628fcf3ce44SJohn Forte 	isns_type_t lc_type;
2629fcf3ce44SJohn Forte 	int i = 0, err_count = 0;
2630fcf3ce44SJohn Forte 	lookup_ctrl_t lc;
2631fcf3ce44SJohn Forte 	uint32_t container_id;
2632fcf3ce44SJohn Forte 	xmlNodePtr	n_node, n_obj, root;
2633fcf3ce44SJohn Forte 	uchar_t *name;
2634fcf3ce44SJohn Forte 	uint32_t len;
2635fcf3ce44SJohn Forte 	int different_err = 0;
2636fcf3ce44SJohn Forte 
2637fcf3ce44SJohn Forte 	lc_type = get_lc_type(type);
2638fcf3ce44SJohn Forte 	if ((lc_type != OBJ_DD) && (lc_type != OBJ_DDS)) {
2639fcf3ce44SJohn Forte 	    return (ERR_INVALID_MGMT_REQUEST);
2640fcf3ce44SJohn Forte 	}
2641fcf3ce44SJohn Forte 
2642fcf3ce44SJohn Forte 	/* prepare lookup ctrl data for looking for the node object */
2643fcf3ce44SJohn Forte 	SET_UID_LCP(&lc, lc_type, 0);
2644fcf3ce44SJohn Forte 
2645fcf3ce44SJohn Forte 	root = xmlDocGetRootElement(doc);
2646fcf3ce44SJohn Forte 	if (root == NULL) {
2647fcf3ce44SJohn Forte 	    return (ERR_SYNTAX_MISSING_ROOT);
2648fcf3ce44SJohn Forte 	}
2649fcf3ce44SJohn Forte 
2650fcf3ce44SJohn Forte 	while (i < req->count) {
2651fcf3ce44SJohn Forte 		/* id is checked to be not NULL before calling this routine. */
2652fcf3ce44SJohn Forte 		lc.data[0].ui = *(req->req_data.attrlist[i]->id);
2653fcf3ce44SJohn Forte 
2654fcf3ce44SJohn Forte 		/* get the dd_id/dds_id */
2655fcf3ce44SJohn Forte 		(void) cache_lock_write();
2656fcf3ce44SJohn Forte 
2657fcf3ce44SJohn Forte 		if ((container_id = is_obj_there(&lc)) != 0) {
2658fcf3ce44SJohn Forte 		    name = (uchar_t *)req->req_data.attrlist[i]->name;
2659fcf3ce44SJohn Forte 		    /* the length of the name need to include the */
2660fcf3ce44SJohn Forte 		    /* null terminator and be on 4 bytes aligned */
2661fcf3ce44SJohn Forte 		    len = xmlStrlen(name) + 1;
2662fcf3ce44SJohn Forte 		    len += 4 - (len % 4);
2663fcf3ce44SJohn Forte 
2664fcf3ce44SJohn Forte 		    /* rename the dd/dds */
2665fcf3ce44SJohn Forte 		    ret = (lc_type == OBJ_DD) ?
2666fcf3ce44SJohn Forte 			update_dd_name(container_id, len, name) :
2667fcf3ce44SJohn Forte 			update_dds_name(container_id, len, name);
2668fcf3ce44SJohn Forte 
2669fcf3ce44SJohn Forte 		    /* release the lock and sync the data */
2670fcf3ce44SJohn Forte 		    ret = cache_unlock_sync(ret);
2671fcf3ce44SJohn Forte 		} else {
2672fcf3ce44SJohn Forte 		    /* release the lock and no need to sync */
2673fcf3ce44SJohn Forte 		    (void) cache_unlock_nosync();
2674fcf3ce44SJohn Forte 		    ret = (lc_type == OBJ_DD) ?  ERR_MATCHING_DD_NOT_FOUND :
2675fcf3ce44SJohn Forte 			ERR_MATCHING_DDSET_NOT_FOUND;
2676fcf3ce44SJohn Forte 		}
2677fcf3ce44SJohn Forte 		if (ret != 0) {
2678fcf3ce44SJohn Forte 		/* keep track if there are different errors encountered. */
2679fcf3ce44SJohn Forte 		    if (ret_save != 0 && ret != ret_save) {
2680fcf3ce44SJohn Forte 			different_err++;
2681fcf3ce44SJohn Forte 		    }
2682fcf3ce44SJohn Forte 		    ret_save = ret;
2683fcf3ce44SJohn Forte 		    err_count++;
2684fcf3ce44SJohn Forte 		    n_obj = xmlNewNode(NULL, (xmlChar *)ISNSOBJECT);
2685fcf3ce44SJohn Forte 		    if (n_obj) {
2686fcf3ce44SJohn Forte 			if ((n_obj = xmlAddChild(root, n_obj)) == NULL) {
2687fcf3ce44SJohn Forte 			    return (ERR_XML_ADDCHILD_FAILED);
2688fcf3ce44SJohn Forte 			}
2689fcf3ce44SJohn Forte 		    } else {
2690fcf3ce44SJohn Forte 			return (ERR_XML_NEWNODE_FAILED);
2691fcf3ce44SJohn Forte 		    }
2692fcf3ce44SJohn Forte 
2693fcf3ce44SJohn Forte 		    n_node = (lc_type == OBJ_DD) ?
2694fcf3ce44SJohn Forte 			xmlNewNode(NULL, (xmlChar *)DDOBJECT) :
2695fcf3ce44SJohn Forte 			xmlNewNode(NULL, (xmlChar *)DDSETOBJECT);
2696fcf3ce44SJohn Forte 		    if (n_node) {
2697fcf3ce44SJohn Forte 			if ((n_node = xmlAddChild(n_obj, n_node)) == NULL) {
2698fcf3ce44SJohn Forte 			    return (ERR_XML_ADDCHILD_FAILED);
2699fcf3ce44SJohn Forte 			} else {
2700fcf3ce44SJohn Forte 			    if (xmlSetProp(n_node, (xmlChar *)NAMEATTR,
2701fcf3ce44SJohn Forte 				(xmlChar *)req->req_data.attrlist[i]->name) ==
2702fcf3ce44SJohn Forte 				NULL) {
2703fcf3ce44SJohn Forte 				return (ERR_XML_SETPROP_FAILED);
2704fcf3ce44SJohn Forte 			    }
2705fcf3ce44SJohn Forte 			}
2706fcf3ce44SJohn Forte 		    } else {
2707fcf3ce44SJohn Forte 			return (ERR_XML_NEWNODE_FAILED);
2708fcf3ce44SJohn Forte 		    }
2709fcf3ce44SJohn Forte 
2710fcf3ce44SJohn Forte 		}
2711fcf3ce44SJohn Forte 		i++;
2712fcf3ce44SJohn Forte 	}
2713fcf3ce44SJohn Forte 
2714fcf3ce44SJohn Forte 	return (handle_partial_failure(doc, ret_save,
2715fcf3ce44SJohn Forte 	    (req->count == err_count && !different_err) ? B_TRUE : B_FALSE));
2716fcf3ce44SJohn Forte }
2717fcf3ce44SJohn Forte 
2718fcf3ce44SJohn Forte /*
2719fcf3ce44SJohn Forte  * ****************************************************************************
2720fcf3ce44SJohn Forte  *
2721fcf3ce44SJohn Forte  * update_dd_ddset_op:
2722fcf3ce44SJohn Forte  *	removes a list of dd memeber or dd seti member.
2723fcf3ce44SJohn Forte  *
2724fcf3ce44SJohn Forte  * req	- contains delete request info.
2725fcf3ce44SJohn Forte  * doc	- response doc to fill up
2726fcf3ce44SJohn Forte  * type	- object type(either dd or dd set)
2727fcf3ce44SJohn Forte  *
2728fcf3ce44SJohn Forte  * ****************************************************************************
2729fcf3ce44SJohn Forte  */
2730fcf3ce44SJohn Forte static int
2731fcf3ce44SJohn Forte update_dd_ddset_op(
2732fcf3ce44SJohn Forte 	request_t *req,
2733fcf3ce44SJohn Forte 	xmlDocPtr doc,
2734fcf3ce44SJohn Forte 	object_type type
2735fcf3ce44SJohn Forte 	/* any additional arguments go here */
2736fcf3ce44SJohn Forte )
2737fcf3ce44SJohn Forte {
2738fcf3ce44SJohn Forte 	result_code_t ret = 0, ret_save = 0;
2739fcf3ce44SJohn Forte 	isns_type_t lc_type;
2740fcf3ce44SJohn Forte 	int i = 0, err_count = 0;
2741fcf3ce44SJohn Forte 	lookup_ctrl_t lc;
2742fcf3ce44SJohn Forte 	uint32_t container_id;
2743fcf3ce44SJohn Forte 	xmlNodePtr	n_node, n_obj, root;
2744fcf3ce44SJohn Forte 	int different_err = 0;
2745fcf3ce44SJohn Forte 
2746fcf3ce44SJohn Forte 	lc_type = get_lc_type(type);
2747fcf3ce44SJohn Forte 	if ((lc_type != OBJ_DD) && (lc_type != OBJ_DDS)) {
2748fcf3ce44SJohn Forte 	    return (ERR_INVALID_MGMT_REQUEST);
2749fcf3ce44SJohn Forte 	}
2750fcf3ce44SJohn Forte 
2751fcf3ce44SJohn Forte 	/* prepare lookup ctrl data for looking for the node object */
2752fcf3ce44SJohn Forte 	lc.curr_uid = 0;
2753fcf3ce44SJohn Forte 	lc.type = lc_type;
2754fcf3ce44SJohn Forte 	lc.id[0] = get_lc_id(req->op_info.obj);
2755fcf3ce44SJohn Forte 	lc.op[0] = OP_STRING;
2756fcf3ce44SJohn Forte 	lc.op[1] = 0;
2757fcf3ce44SJohn Forte 
2758fcf3ce44SJohn Forte 	root = xmlDocGetRootElement(doc);
2759fcf3ce44SJohn Forte 	if (root == NULL) {
2760fcf3ce44SJohn Forte 	    return (ERR_SYNTAX_MISSING_ROOT);
2761fcf3ce44SJohn Forte 	}
2762fcf3ce44SJohn Forte 
2763fcf3ce44SJohn Forte 	while (i < req->count) {
2764fcf3ce44SJohn Forte 		lc.data[0].ptr = req->req_data.attrlist[i]->name;
2765fcf3ce44SJohn Forte 
2766fcf3ce44SJohn Forte 		/* lock the cache for writing */
2767fcf3ce44SJohn Forte 		(void) cache_lock_write();
2768fcf3ce44SJohn Forte 
2769fcf3ce44SJohn Forte 		if ((container_id = is_obj_there(&lc)) != 0) {
2770fcf3ce44SJohn Forte 		    ret = (lc_type == OBJ_DD) ?
2771fcf3ce44SJohn Forte 			/* enabled is checked to be not NULL before calling. */
2772fcf3ce44SJohn Forte 			update_dd_features(container_id,
2773fcf3ce44SJohn Forte 			*(req->req_data.attrlist[i]->enabled) ? 1 : 0):
2774fcf3ce44SJohn Forte 			update_dds_status(container_id,
2775fcf3ce44SJohn Forte 			*(req->req_data.attrlist[i]->enabled) ? 1 : 0);
2776fcf3ce44SJohn Forte 		    /* unlock the cache and sync the data */
2777fcf3ce44SJohn Forte 		    ret = cache_unlock_sync(ret);
2778fcf3ce44SJohn Forte 		} else {
2779fcf3ce44SJohn Forte 		    (void) cache_unlock_nosync();
2780fcf3ce44SJohn Forte 		    ret = (lc_type == OBJ_DD) ?  ERR_MATCHING_DD_NOT_FOUND :
2781fcf3ce44SJohn Forte 			ERR_MATCHING_DDSET_NOT_FOUND;
2782fcf3ce44SJohn Forte 		}
2783fcf3ce44SJohn Forte 		if (ret != 0) {
2784fcf3ce44SJohn Forte 		/* keep track if there are different errors encountered. */
2785fcf3ce44SJohn Forte 		    if (ret_save != 0 && ret != ret_save) {
2786fcf3ce44SJohn Forte 			different_err++;
2787fcf3ce44SJohn Forte 		    }
2788fcf3ce44SJohn Forte 		    ret_save = ret;
2789fcf3ce44SJohn Forte 		    err_count++;
2790fcf3ce44SJohn Forte 		    n_obj = xmlNewNode(NULL, (xmlChar *)ISNSOBJECT);
2791fcf3ce44SJohn Forte 		    if (n_obj) {
2792fcf3ce44SJohn Forte 			if ((n_obj = xmlAddChild(root, n_obj)) == NULL) {
2793fcf3ce44SJohn Forte 			    return (ERR_XML_ADDCHILD_FAILED);
2794fcf3ce44SJohn Forte 			}
2795fcf3ce44SJohn Forte 		    } else {
2796fcf3ce44SJohn Forte 			return (ERR_XML_NEWNODE_FAILED);
2797fcf3ce44SJohn Forte 		    }
2798fcf3ce44SJohn Forte 
2799fcf3ce44SJohn Forte 		    n_node = (lc_type == OBJ_DD) ?
2800fcf3ce44SJohn Forte 			xmlNewNode(NULL, (xmlChar *)DDOBJECT) :
2801fcf3ce44SJohn Forte 			xmlNewNode(NULL, (xmlChar *)DDSETOBJECT);
2802fcf3ce44SJohn Forte 		    if (n_node) {
2803fcf3ce44SJohn Forte 			if ((n_node = xmlAddChild(n_obj, n_node)) == NULL) {
2804fcf3ce44SJohn Forte 			    return (ERR_XML_ADDCHILD_FAILED);
2805fcf3ce44SJohn Forte 			} else {
2806fcf3ce44SJohn Forte 			    if (xmlSetProp(n_node, (xmlChar *)NAMEATTR,
2807fcf3ce44SJohn Forte 				(xmlChar *)req->req_data.attrlist[i]->name) ==
2808fcf3ce44SJohn Forte 				NULL) {
2809fcf3ce44SJohn Forte 				return (ERR_XML_SETPROP_FAILED);
2810fcf3ce44SJohn Forte 			    }
2811fcf3ce44SJohn Forte 			}
2812fcf3ce44SJohn Forte 		    } else {
2813fcf3ce44SJohn Forte 			    return (ERR_XML_NEWNODE_FAILED);
2814fcf3ce44SJohn Forte 		    }
2815fcf3ce44SJohn Forte 		}
2816fcf3ce44SJohn Forte 		i++;
2817fcf3ce44SJohn Forte 	}
2818fcf3ce44SJohn Forte 
2819fcf3ce44SJohn Forte 	return (handle_partial_failure(doc, ret_save,
2820fcf3ce44SJohn Forte 	    (req->count == err_count && !different_err) ? B_TRUE : B_FALSE));
2821fcf3ce44SJohn Forte }
2822fcf3ce44SJohn Forte 
2823fcf3ce44SJohn Forte /*
2824fcf3ce44SJohn Forte  * ****************************************************************************
2825fcf3ce44SJohn Forte  *
2826fcf3ce44SJohn Forte  * createModify_dd_ddset_op:
2827fcf3ce44SJohn Forte  *	removes a list of dd memeber or dd seti member.
2828fcf3ce44SJohn Forte  *
2829fcf3ce44SJohn Forte  * req	- contains delete request info.
2830fcf3ce44SJohn Forte  * doc	- response doc to fill up
2831fcf3ce44SJohn Forte  *
2832fcf3ce44SJohn Forte  * ****************************************************************************
2833fcf3ce44SJohn Forte  */
2834fcf3ce44SJohn Forte static int
2835fcf3ce44SJohn Forte create_dd_ddset_op(
2836fcf3ce44SJohn Forte 	request_t *req,
2837fcf3ce44SJohn Forte 	xmlDocPtr doc,
2838fcf3ce44SJohn Forte 	object_type type
2839fcf3ce44SJohn Forte 	/* any additional arguments go here */
2840fcf3ce44SJohn Forte )
2841fcf3ce44SJohn Forte {
2842fcf3ce44SJohn Forte 	isns_obj_t  *obj;
2843fcf3ce44SJohn Forte 	result_code_t ret = 0, ret_save = 0;
2844fcf3ce44SJohn Forte 	isns_type_t lc_type;
2845fcf3ce44SJohn Forte 	lookup_ctrl_t lc;
2846fcf3ce44SJohn Forte 	uint32_t uid;
2847fcf3ce44SJohn Forte 	int i = 0, err_count = 0;
2848fcf3ce44SJohn Forte 	xmlNodePtr	n_obj, n_node, root;
2849fcf3ce44SJohn Forte 	int different_err = 0;
2850fcf3ce44SJohn Forte 
2851fcf3ce44SJohn Forte 	lc_type = get_lc_type(type);
2852fcf3ce44SJohn Forte 	if ((lc_type != OBJ_DD) && (lc_type != OBJ_DDS)) {
2853fcf3ce44SJohn Forte 	    return (ERR_INVALID_MGMT_REQUEST);
2854fcf3ce44SJohn Forte 	}
2855fcf3ce44SJohn Forte 
2856fcf3ce44SJohn Forte 	root = xmlDocGetRootElement(doc);
2857fcf3ce44SJohn Forte 	if (root == NULL) {
2858fcf3ce44SJohn Forte 	    return (ERR_SYNTAX_MISSING_ROOT);
2859fcf3ce44SJohn Forte 	}
2860fcf3ce44SJohn Forte 	lc_type = get_lc_type(type);
2861fcf3ce44SJohn Forte 	if ((lc_type != OBJ_DD) && (lc_type != OBJ_DDS)) {
2862fcf3ce44SJohn Forte 	    return (ERR_INVALID_MGMT_REQUEST);
2863fcf3ce44SJohn Forte 	}
2864fcf3ce44SJohn Forte 
2865fcf3ce44SJohn Forte 	/* prepare lookup ctrl data for looking for the node object */
2866fcf3ce44SJohn Forte 	lc.curr_uid = 0;
2867fcf3ce44SJohn Forte 	lc.type = lc_type;
2868fcf3ce44SJohn Forte 	lc.id[0] = get_lc_id(req->op_info.obj);
2869fcf3ce44SJohn Forte 	lc.op[0] = OP_STRING;
2870fcf3ce44SJohn Forte 	lc.op[1] = 0;
2871fcf3ce44SJohn Forte 	lc.data[1].ptr = (uchar_t *)doc; /* xml writer descriptor */
2872fcf3ce44SJohn Forte 	while (i < req->count) {
2873fcf3ce44SJohn Forte 		lc.data[0].ptr = req->req_data.attrlist[i]->name,
2874fcf3ce44SJohn Forte 		/* grab the write lock */
2875fcf3ce44SJohn Forte 		(void) cache_lock_write();
2876fcf3ce44SJohn Forte 
2877fcf3ce44SJohn Forte 		uid = is_obj_there(&lc);
2878fcf3ce44SJohn Forte 		if (uid == 0) {
2879fcf3ce44SJohn Forte 		    ret = (lc_type == OBJ_DD) ?
2880fcf3ce44SJohn Forte 			adm_create_dd(&obj, req->req_data.attrlist[i]->name,
2881fcf3ce44SJohn Forte 			0, 0) :
2882fcf3ce44SJohn Forte 			adm_create_dds(&obj, req->req_data.attrlist[i]->name,
2883fcf3ce44SJohn Forte 			0, 0);
2884fcf3ce44SJohn Forte 		    if (ret == 0) {
2885fcf3ce44SJohn Forte 			ret = register_object(obj, NULL, NULL);
2886fcf3ce44SJohn Forte 			if (ret != 0) {
2887fcf3ce44SJohn Forte 			    free_object(obj);
2888fcf3ce44SJohn Forte 			}
2889fcf3ce44SJohn Forte 			/* release the lock and sync the cache and data store */
2890fcf3ce44SJohn Forte 			ret = cache_unlock_sync(ret);
2891fcf3ce44SJohn Forte 		    }
2892fcf3ce44SJohn Forte 		} else {
2893fcf3ce44SJohn Forte 			/* release the lock and no need to sync the data */
2894fcf3ce44SJohn Forte 			(void) cache_unlock_nosync();
2895fcf3ce44SJohn Forte 			ret = ERR_NAME_IN_USE;
2896fcf3ce44SJohn Forte 		}
2897fcf3ce44SJohn Forte 
2898fcf3ce44SJohn Forte 		if (ret != 0) {
2899fcf3ce44SJohn Forte 		/* keep track if there are different errors encountered. */
2900fcf3ce44SJohn Forte 		    if (ret_save != 0 && ret != ret_save) {
2901fcf3ce44SJohn Forte 			different_err++;
2902fcf3ce44SJohn Forte 		    }
2903fcf3ce44SJohn Forte 		    ret_save = ret;
2904fcf3ce44SJohn Forte 		    err_count++;
2905fcf3ce44SJohn Forte 		    n_obj = xmlNewNode(NULL, (xmlChar *)ISNSOBJECT);
2906fcf3ce44SJohn Forte 		    if (n_obj) {
2907fcf3ce44SJohn Forte 			if ((n_obj = xmlAddChild(root, n_obj)) == NULL) {
2908fcf3ce44SJohn Forte 			    return (ERR_XML_ADDCHILD_FAILED);
2909fcf3ce44SJohn Forte 			}
2910fcf3ce44SJohn Forte 		    } else {
2911fcf3ce44SJohn Forte 			return (ERR_XML_ADDCHILD_FAILED);
2912fcf3ce44SJohn Forte 		    }
2913fcf3ce44SJohn Forte 
2914fcf3ce44SJohn Forte 		    n_node = (lc_type == OBJ_DD) ?
2915fcf3ce44SJohn Forte 			xmlNewNode(NULL, (xmlChar *)DDOBJECT) :
2916fcf3ce44SJohn Forte 			xmlNewNode(NULL, (xmlChar *)DDSETOBJECT);
2917fcf3ce44SJohn Forte 		    if (n_node) {
2918fcf3ce44SJohn Forte 			if ((n_node = xmlAddChild(n_obj, n_node)) == NULL) {
2919fcf3ce44SJohn Forte 			    return (ERR_XML_ADDCHILD_FAILED);
2920fcf3ce44SJohn Forte 			} else {
2921fcf3ce44SJohn Forte 			    if (xmlSetProp(n_node, (xmlChar *)NAMEATTR,
2922fcf3ce44SJohn Forte 				(xmlChar *)req->req_data.attrlist[i]->name) ==
2923fcf3ce44SJohn Forte 				NULL) {
2924fcf3ce44SJohn Forte 				return (ERR_XML_SETPROP_FAILED);
2925fcf3ce44SJohn Forte 			    }
2926fcf3ce44SJohn Forte 			}
2927fcf3ce44SJohn Forte 		    } else {
2928fcf3ce44SJohn Forte 			return (ERR_XML_NEWNODE_FAILED);
2929fcf3ce44SJohn Forte 		    }
2930fcf3ce44SJohn Forte 		}
2931fcf3ce44SJohn Forte 		i++;
2932fcf3ce44SJohn Forte 	}
2933fcf3ce44SJohn Forte 
2934fcf3ce44SJohn Forte 	return (handle_partial_failure(doc, ret_save,
2935fcf3ce44SJohn Forte 	    (req->count == err_count && !different_err) ? B_TRUE : B_FALSE));
2936fcf3ce44SJohn Forte }
2937fcf3ce44SJohn Forte 
2938fcf3ce44SJohn Forte /*
2939fcf3ce44SJohn Forte  * ****************************************************************************
2940fcf3ce44SJohn Forte  *
2941fcf3ce44SJohn Forte  * createModify_dd_ddset_op:
2942fcf3ce44SJohn Forte  *	removes a list of dd memeber or dd seti member.
2943fcf3ce44SJohn Forte  *
2944fcf3ce44SJohn Forte  * req	- contains delete request info.
2945fcf3ce44SJohn Forte  * doc	- response doc to fill up
2946fcf3ce44SJohn Forte  *
2947fcf3ce44SJohn Forte  * ****************************************************************************
2948fcf3ce44SJohn Forte  */
2949fcf3ce44SJohn Forte int
2950fcf3ce44SJohn Forte createModify_dd_ddset_op(
2951fcf3ce44SJohn Forte 	request_t *req,
2952fcf3ce44SJohn Forte 	xmlDocPtr doc
2953fcf3ce44SJohn Forte 	/* any additional arguments go here */
2954fcf3ce44SJohn Forte )
2955fcf3ce44SJohn Forte {
2956fcf3ce44SJohn Forte 	result_code_t ret = 0;
2957fcf3ce44SJohn Forte 
2958fcf3ce44SJohn Forte 	if (req->req_data.attrlist[0]->id != NULL) {
2959fcf3ce44SJohn Forte 	    ret = rename_dd_ddset_op(req, doc, req->op_info.obj);
2960fcf3ce44SJohn Forte 	} else if (req->req_data.attrlist[0]->enabled != NULL) {
2961fcf3ce44SJohn Forte 	    ret = update_dd_ddset_op(req, doc, req->op_info.obj);
2962fcf3ce44SJohn Forte 	} else {
2963fcf3ce44SJohn Forte 	    ret = create_dd_ddset_op(req, doc, req->op_info.obj);
2964fcf3ce44SJohn Forte 	}
2965fcf3ce44SJohn Forte 
2966fcf3ce44SJohn Forte 	return (ret);
2967fcf3ce44SJohn Forte }
2968