4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
31 #include <sys/types.h>
32 #include <sys/socket.h>
33 #include <netinet/in.h>
34 #include <arpa/inet.h>
36 #include "isns_server.h"
37 #include "isns_msgq.h"
38 #include "isns_htab.h"
39 #include "isns_cache.h"
43 #include "isns_func.h"
44 #include "isns_dseng.h"
47 #include "isns_utils.h"
54 extern int verbose_mc
;
55 extern void print_object(char *, isns_obj_t
*);
58 extern msg_queue_t
*sys_q
;
59 extern msg_queue_t
*scn_q
;
61 extern pthread_mutex_t el_mtx
;
63 extern int cache_flag
;
72 /* type of parent object */
73 const int TYPE_OF_PARENT
[MAX_OBJ_TYPE_FOR_SIZE
] = {
86 ASSOC_ISCSI_PARENT_TYPE
,
90 /* number of children object type */
91 const int NUM_OF_CHILD
[MAX_OBJ_TYPE
] = {
101 /* type of a child object */
102 const int TYPE_OF_CHILD
[MAX_OBJ_TYPE
][MAX_CHILD_TYPE
] = {
104 { OBJ_ISCSI
, OBJ_PORTAL
},
112 /* number of attributes of certain type of object */
113 const int NUM_OF_ATTRS
[MAX_OBJ_TYPE_FOR_SIZE
] = {
121 0, /* MAX_OBJ_TYPE */
126 NUM_OF_ASSOC_ISCSI_ATTRS
,
127 NUM_OF_ASSOC_DD_ATTRS
130 /* the tag of UID of each type of object */
131 static const int UID_TAG
[MAX_OBJ_TYPE_FOR_SIZE
] = {
133 ISNS_ENTITY_INDEX_ATTR_ID
,
134 ISNS_ISCSI_NODE_INDEX_ATTR_ID
,
135 ISNS_PORTAL_INDEX_ATTR_ID
,
136 ISNS_PG_INDEX_ATTR_ID
,
138 ISNS_DD_SET_ID_ATTR_ID
,
139 0, /* MAX_OBJ_TYPE */
144 ISNS_DD_ISCSI_INDEX_ATTR_ID
,
148 /* the index of UID of each type of object */
149 const int UID_ATTR_INDEX
[MAX_OBJ_TYPE_FOR_SIZE
] = {
151 ATTR_INDEX_ENTITY(ISNS_ENTITY_INDEX_ATTR_ID
),
152 ATTR_INDEX_ISCSI(ISNS_ISCSI_NODE_INDEX_ATTR_ID
),
153 ATTR_INDEX_PORTAL(ISNS_PORTAL_INDEX_ATTR_ID
),
154 ATTR_INDEX_PG(ISNS_PG_INDEX_ATTR_ID
),
155 ATTR_INDEX_DD(ISNS_DD_ID_ATTR_ID
),
156 ATTR_INDEX_DDS(ISNS_DD_SET_ID_ATTR_ID
),
157 0, /* MAX_OBJ_TYPE */
162 ATTR_INDEX_ASSOC_ISCSI(ISNS_DD_ISCSI_INDEX_ATTR_ID
),
163 ATTR_INDEX_ASSOC_DD(ISNS_DD_ID_ATTR_ID
)
166 /* the index of the key attributes of each type of object */
167 static const int KEY_ATTR_INDEX
[MAX_OBJ_TYPE
][MAX_KEY_ATTRS
] = {
169 { ATTR_INDEX_ENTITY(ISNS_EID_ATTR_ID
), 0 },
170 { ATTR_INDEX_ISCSI(ISNS_ISCSI_NAME_ATTR_ID
),
172 { ATTR_INDEX_PORTAL(ISNS_PORTAL_IP_ADDR_ATTR_ID
),
173 ATTR_INDEX_PORTAL(ISNS_PORTAL_PORT_ATTR_ID
),
175 { ATTR_INDEX_PG(ISNS_PG_ISCSI_NAME_ATTR_ID
),
176 ATTR_INDEX_PG(ISNS_PG_PORTAL_IP_ADDR_ATTR_ID
),
177 ATTR_INDEX_PG(ISNS_PG_PORTAL_PORT_ATTR_ID
) },
178 { ATTR_INDEX_DD(ISNS_DD_NAME_ATTR_ID
), 0 },
179 { ATTR_INDEX_DDS(ISNS_DD_SET_NAME_ATTR_ID
), 0 }
182 /* the operating methods for key attributes of each type of object */
183 static const int KEY_ATTR_OP
[MAX_OBJ_TYPE
][MAX_KEY_ATTRS
] = {
187 { OP_MEMORY_IP6
, OP_INTEGER
, 0 },
188 { OP_STRING
, OP_MEMORY_IP6
, OP_INTEGER
},
193 /* the size of each type of object */
194 static const int SIZEOF_OBJ
[MAX_OBJ_TYPE_FOR_SIZE
] = {
196 sizeof (isns_entity_t
),
197 sizeof (isns_iscsi_t
),
198 sizeof (isns_portal_t
),
207 sizeof (isns_assoc_iscsi_t
),
208 sizeof (isns_assoc_dd_t
)
212 const int NUM_OF_REF
[MAX_OBJ_TYPE_FOR_SIZE
] = {
214 static const int NUM_OF_REF
[MAX_OBJ_TYPE_FOR_SIZE
] = {
232 /* the type of the reference object */
233 static const int TYPE_OF_REF
[MAX_OBJ_TYPE
][MAX_REF_COUNT
+ 1] = {
236 { OBJ_PG
, OBJ_PORTAL
, 0 },
237 { OBJ_PG
, OBJ_ISCSI
, 0 },
238 { 0, OBJ_ISCSI
, OBJ_PORTAL
},
243 /* the operating method for match operation of the reference object */
244 #define MAX_REF_MATCH (2)
245 static const int REF_MATCH_OPS
[MAX_OBJ_TYPE
][MAX_REF_MATCH
] = {
249 { OP_MEMORY_IP6
, OP_INTEGER
},
255 /* the index of the attribute of being matched object */
256 static const int REF_MATCH_ID1
[MAX_OBJ_TYPE
][MAX_REF_MATCH
] = {
259 { ATTR_INDEX_ISCSI(ISNS_ISCSI_NAME_ATTR_ID
), 0 },
260 { ATTR_INDEX_PORTAL(ISNS_PORTAL_IP_ADDR_ATTR_ID
),
261 ATTR_INDEX_PORTAL(ISNS_PORTAL_PORT_ATTR_ID
) },
267 /* the index of the attribute of matching object */
268 static const int REF_MATCH_ID2
[MAX_OBJ_TYPE
][MAX_REF_MATCH
] = {
271 { ATTR_INDEX_PG(ISNS_PG_ISCSI_NAME_ATTR_ID
), 0 },
272 { ATTR_INDEX_PG(ISNS_PG_PORTAL_IP_ADDR_ATTR_ID
),
273 ATTR_INDEX_PG(ISNS_PG_PORTAL_PORT_ATTR_ID
) },
282 static uint32_t get_reg_period();
283 static char *make_unique_name(int *, uint32_t);
284 static lookup_ctrl_t
*set_lookup_ctrl(lookup_ctrl_t
*, isns_obj_t
*);
285 static int setup_ref_lcp(lookup_ctrl_t
*,
286 const isns_obj_t
*, const isns_obj_t
*);
287 static int setup_deref_lcp(lookup_ctrl_t
*,
288 const isns_obj_t
*, isns_type_t
);
289 static int cb_get_parent(void *, void *);
290 static int cb_node_child(void *, void *);
291 static int cb_set_ref(void *, void *);
292 static int cb_clear_ref(void *, void *);
293 static int cb_add_child(void *, void *);
294 static int cb_remove_child(void *, void *);
295 static int cb_verify_ref(void *, void *);
296 static int cb_ref_new2old(void *, void *);
297 static int cb_new_ref(void *, void *);
298 static int ref_new2old(
299 lookup_ctrl_t
*, isns_type_t
, uint32_t, const isns_obj_t
*);
300 static int ref_new2new(
301 lookup_ctrl_t
*, const isns_obj_t
*, const isns_obj_t
*);
302 static int new_ref(const isns_obj_t
*, const isns_obj_t
*);
303 static uint32_t setup_parent_lcp(lookup_ctrl_t
*, isns_obj_t
*);
304 static int set_obj_offline(isns_obj_t
*);
305 static int copy_attrs(isns_obj_t
*, const isns_obj_t
*);
307 static isns_obj_t
*make_default_pg(const isns_obj_t
*, const isns_obj_t
*);
308 static isns_obj_t
*(*const make_ref
[MAX_OBJ_TYPE
])
309 (const isns_obj_t
*, const isns_obj_t
*) = {
319 static uint32_t entity_hval(void *, uint16_t, uint32_t *);
320 static uint32_t iscsi_hval(void *, uint16_t, uint32_t *);
321 static uint32_t portal_hval(void *, uint16_t, uint32_t *);
322 static uint32_t pg_hval(void *, uint16_t, uint32_t *);
323 static uint32_t dd_hval(void *, uint16_t, uint32_t *);
324 static uint32_t dds_hval(void *, uint16_t, uint32_t *);
325 static uint32_t (*const hval_func
[MAX_OBJ_TYPE
])
326 (void *, uint16_t, uint32_t *) = {
337 * ****************************************************************************
340 * caculate the hash value of a network entity object.
342 * p - the pointer pointers to network entity object or
343 * the lookup control data, both have the key attribute
344 * of a network entity object.
345 * chunk- which chunk of the hash table.
346 * flags- pointer to flags.
347 * return - the hash value.
349 * ****************************************************************************
354 /* LINTED E_FUNC_ARG_UNUSED */
363 if ((*flags
& FLAGS_CTRL_MASK
) == 0) {
364 /* p pointers to a network entity object */
365 obj
= (isns_obj_t
*)p
;
366 key
= obj
->attrs
[ATTR_INDEX_ENTITY(ISNS_EID_ATTR_ID
)].
369 /* p is lookup control data */
370 lcp
= (lookup_ctrl_t
*)p
;
371 key
= lcp
->data
[0].ptr
;
374 return (htab_compute_hval(key
));
378 * ****************************************************************************
381 * caculate the hash value of an iscsi storage node object.
383 * p - the pointer pointers to iscsi storage node object or
384 * the lookup control data, both have the key attribute
385 * of an iscsi storage node object.
386 * chunk- which chunk of the hash table.
387 * flags- pointer to flags.
388 * return - the hash value.
390 * ****************************************************************************
395 /* LINTED E_FUNC_ARG_UNUSED */
404 if ((*flags
& FLAGS_CTRL_MASK
) == 0) {
405 /* p pointers to an iscsi storage node object */
406 obj
= (isns_obj_t
*)p
;
407 key
= obj
->attrs
[ATTR_INDEX_ISCSI(ISNS_ISCSI_NAME_ATTR_ID
)].
410 /* p is lookup control data */
411 lcp
= (lookup_ctrl_t
*)p
;
412 key
= lcp
->data
[0].ptr
;
415 return (htab_compute_hval(key
));
419 * ****************************************************************************
422 * caculate the hash value of a portal object.
424 * p - the pointer pointers to a portal object or the lookup control
425 * data, both have the key attributes of a portal object.
426 * chunk- which chunk of the hash table.
427 * flags- pointer to flags.
428 * return - the hash value.
430 * ****************************************************************************
435 /* LINTED E_FUNC_ARG_UNUSED */
440 char buff
[INET6_ADDRSTRLEN
+ 8] = { 0 };
441 char buff2
[8] = { 0 };
449 if ((*flags
& FLAGS_CTRL_MASK
) == 0) {
450 /* p pointers to a portal object */
451 obj
= (isns_obj_t
*)p
;
452 ip
= obj
->attrs
[ATTR_INDEX_PORTAL
453 (ISNS_PORTAL_IP_ADDR_ATTR_ID
)].value
.ip
;
454 port
= obj
->attrs
[ATTR_INDEX_PORTAL
455 (ISNS_PORTAL_PORT_ATTR_ID
)].value
.ui
;
457 /* p is lookup control data */
458 lcp
= (lookup_ctrl_t
*)p
;
459 ip
= lcp
->data
[0].ip
;
460 port
= lcp
->data
[1].ui
;
463 key
= (uchar_t
*)inet_ntop(AF_INET6
, (void *)ip
,
464 buff
, sizeof (buff
));
465 (void) snprintf(buff2
, sizeof (buff2
), "%d", port
);
466 (void) strcat((char *)key
, buff2
);
468 return (htab_compute_hval(key
));
472 * ****************************************************************************
475 * caculate the hash value of a portal group object.
477 * p - the pointer pointers to a portal group object or the lookup
478 * control data, both have the key attributes of a portal object.
479 * chunk- which chunk of the hash table.
480 * flags- pointer to flags.
481 * return - the hash value.
483 * ****************************************************************************
492 char buff
[INET6_ADDRSTRLEN
+ 8] = { 0 };
493 char buff2
[8] = { 0 };
498 in6_addr_t
*ip
= NULL
;
501 if ((*flags
& FLAGS_CTRL_MASK
) == 0) {
502 /* p is a portal group object */
503 obj
= (isns_obj_t
*)p
;
505 /* the first chunk */
506 key
= obj
->attrs
[ATTR_INDEX_PG
507 (ISNS_PG_ISCSI_NAME_ATTR_ID
)].value
.ptr
;
510 ip
= obj
->attrs
[ATTR_INDEX_PG
511 (ISNS_PG_PORTAL_IP_ADDR_ATTR_ID
)].value
.ip
;
512 port
= obj
->attrs
[ATTR_INDEX_PG
513 (ISNS_PG_PORTAL_PORT_ATTR_ID
)].value
.ui
;
516 /* p is a lookup control data */
517 lcp
= (lookup_ctrl_t
*)p
;
518 /* clear the chunk flags */
519 *flags
&= ~FLAGS_CHUNK_MASK
;
520 if (lcp
->op
[0] == OP_STRING
) {
521 /* the first chunk */
522 key
= lcp
->data
[0].ptr
;
525 ip
= lcp
->data
[0].ip
;
526 port
= lcp
->data
[1].ui
;
532 key
= (uchar_t
*)inet_ntop(AF_INET6
, (void *)ip
,
533 buff
, sizeof (buff
));
534 (void) snprintf(buff2
, sizeof (buff2
), "%d", port
);
535 (void) strcat((char *)key
, buff2
);
538 return (htab_compute_hval(key
));
542 * ****************************************************************************
545 * caculate the hash value of a DD object.
547 * p - the pointer pointers to a DD object or the lookup control data,
548 * both have the key attributes of a DD object.
549 * chunk- which chunk of the hash table.
550 * flags- pointer to flags.
551 * return - the hash value.
553 * ****************************************************************************
558 /* LINTED E_FUNC_ARG_UNUSED */
567 if ((*flags
& FLAGS_CTRL_MASK
) == 0) {
568 /* p is a DD object */
569 obj
= (isns_obj_t
*)p
;
570 key
= obj
->attrs
[ATTR_INDEX_DD(ISNS_DD_NAME_ATTR_ID
)].
573 /* p is a lookup control data */
574 lcp
= (lookup_ctrl_t
*)p
;
575 key
= lcp
->data
[0].ptr
;
578 return (htab_compute_hval(key
));
582 * ****************************************************************************
585 * caculate the hash value of a DD-set object.
587 * p - the pointer pointers to a DD-set object or the lookup control data,
588 * both have the key attributes of a DD-set object.
589 * chunk- which chunk of the hash table.
590 * flags- pointer to flags.
591 * return - the hash value.
593 * ****************************************************************************
598 /* LINTED E_FUNC_ARG_UNUSED */
607 if ((*flags
& FLAGS_CTRL_MASK
) == 0) {
608 /* p is a DD-set object */
609 obj
= (isns_obj_t
*)p
;
610 key
= obj
->attrs
[ATTR_INDEX_DDS(ISNS_DD_SET_NAME_ATTR_ID
)].
613 /* p is lookup control data */
614 lcp
= (lookup_ctrl_t
*)p
;
615 key
= lcp
->data
[0].ptr
;
618 return (htab_compute_hval(key
));
622 * ****************************************************************************
625 * caculate the hash value of an object.
627 * p - the pointer pointers to an object or lookup control data,
628 * both has the object type and the key attributes of an object.
629 * chunk- which chunk of the hash table.
630 * flags- pointer to flags.
631 * return - the hash value.
633 * ****************************************************************************
642 isns_type_t type
= ((isns_obj_t
*)p
)->type
;
644 return (hval_func
[type
](p
, chunk
, flags
));
648 * ****************************************************************************
651 * get the UID of an object.
653 * p - the pointer pointers to an object.
656 * ****************************************************************************
663 isns_obj_t
*obj
= (isns_obj_t
*)p
;
664 isns_attr_t
*attr
= &obj
->attrs
[UID_ATTR_INDEX
[obj
->type
]];
665 uint32_t uid
= attr
->value
.ui
;
670 * ****************************************************************************
673 * set the UID of an object.
675 * p - the pointer pointers to an object.
679 * ****************************************************************************
687 isns_obj_t
*obj
= (isns_obj_t
*)p
;
688 isns_attr_t
*attr
= &obj
->attrs
[UID_ATTR_INDEX
[obj
->type
]];
690 /* set the tag, len and value */
691 attr
->tag
= UID_TAG
[obj
->type
];
693 attr
->value
.ui
= uid
;
699 * ****************************************************************************
702 * compare between two objects or an object with a lookup control data.
704 * p1 - the pointer points to an object.
705 * p2 - the pointer points to an object or a lookup control data.
706 * flags- 0: p2 is an object; otherwise p2 is a lookup control data.
707 * return - the comparsion result.
709 * ****************************************************************************
718 isns_obj_t
*obj
= (isns_obj_t
*)p1
;
719 lookup_ctrl_t buff
= { 0 };
724 lcp
= set_lookup_ctrl(&buff
, (isns_obj_t
*)p2
);
726 lcp
= (lookup_ctrl_t
*)p2
;
727 uid
= get_obj_uid(obj
);
728 /* the object are linked with decending order by */
729 /* the object UID, if the object UID is greater than */
730 /* or equal to the current UID, it needs to compare */
731 /* for the next one. */
732 if (lcp
->curr_uid
!= 0 && uid
>= lcp
->curr_uid
) {
737 return (key_cmp(lcp
, obj
));
741 * ****************************************************************************
744 * replace an existing object with the new one.
746 * p1 - the pointer points to an object being replaced.
747 * p2 - the pointer points to a new object.
748 * uid_p- points to uid for returning.
749 * flag - 0: do not free the source object, otherwise free it.
750 * return - error code.
752 * ****************************************************************************
764 #ifndef SKIP_SRC_AUTH
765 uint32_t *pp_dst
, *pp_src
, swap
;
769 isns_obj_t
*dst
= (isns_obj_t
*)p1
;
770 isns_obj_t
*src
= (isns_obj_t
*)p2
;
772 if (src
->type
== OBJ_DD
|| src
->type
== OBJ_DDS
) {
773 /* replace not allowed */
774 return (ERR_NAME_IN_USE
);
777 online
= is_obj_online(dst
);
779 /* set cache update flag */
782 /* update parent uid */
783 #ifndef SKIP_SRC_AUTH
784 pp_dst
= get_parent_p(dst
);
785 if (pp_dst
!= NULL
) {
786 pp_src
= get_parent_p(src
);
795 /* update all of attributes */
796 if (copy_attrs(dst
, src
) != 0) {
797 return (ISNS_RSP_INTERNAL_ERROR
);
800 /* free up the src object */
802 (void) free_object(src
);
803 } else if (online
== 0) {
804 (void) set_obj_uid(src
, get_obj_uid(dst
));
805 (void) set_obj_offline(src
);
808 /* update data store */
810 ec
= write_data(DATA_UPDATE
, dst
);
812 /* we should never have duplicated entry in data store */
813 ec
= ISNS_RSP_INTERNAL_ERROR
;
819 (void) make_scn((online
== 0) ?
825 *uid_p
= get_obj_uid(dst
);
833 * ****************************************************************************
836 * post function after adding a new object.
838 * p - object which has been added.
839 * return - error code.
841 * ****************************************************************************
850 isns_obj_t
*obj
= (isns_obj_t
*)p
;
852 /* add the new object to data store */
854 ec
= write_data(DATA_ADD
, obj
);
858 if (ec
== 0 && scn_q
!= NULL
) {
859 (void) make_scn(ISNS_OBJECT_ADDED
, obj
);
866 * ****************************************************************************
869 * initialize the object hash tables.
871 * c - points to the cache.
872 * return - error code.
874 * ****************************************************************************
886 * allocate an array of pointer for the object hash tables.
888 c
->t
= (struct htab
**)calloc(sizeof (struct htab
*), MAX_OBJ_TYPE
);
894 * hash table for network entity objects.
896 t
= htab_create(UID_FLAGS_SEQ
, 8, 1);
899 c
->t
[OBJ_ENTITY
] = t
;
905 * hash table for iscsi storage node objects.
907 t
= htab_create(UID_FLAGS_SEQ
, 8, 1);
916 * hash table for portal objects.
918 t
= htab_create(UID_FLAGS_SEQ
, 8, 1);
921 c
->t
[OBJ_PORTAL
] = t
;
927 * hash table for portal group objects.
929 t
= htab_create(UID_FLAGS_SEQ
, 8, 2);
938 * hash table for discovery domain objects.
940 t
= htab_create(0, 6, 1);
949 * hash table for discovery domain set objects.
951 t
= htab_create(0, 4, 1);
963 * ****************************************************************************
966 * get the ref pointer of the portal group object.
968 * obj - portal group object.
969 * return - ref pointer.
971 * ****************************************************************************
980 obj
->type
== OBJ_PG
? &((isns_pg_t
*)obj
)->ref
[n
] : NULL
;
995 return (*get_ref_np(obj
, n
));
1004 isns_type_t t
= obj
->type
;
1007 while (i
< NUM_OF_REF
[t
]) {
1008 if (rt
== TYPE_OF_REF
[t
][i
+ 1]) {
1009 return (get_ref_np(obj
, i
));
1023 uint32_t *refp
= get_ref_p(obj
, type
);
1027 /* LINTED E_NOP_ELSE_STMT */
1036 * ****************************************************************************
1039 * get the pointer of the parent object.
1042 * return - parent object pointer.
1044 * ****************************************************************************
1048 const isns_obj_t
*obj
1052 switch (obj
->type
) {
1054 pp
= &((isns_iscsi_t
*)obj
)->puid
;
1057 pp
= &((isns_portal_t
*)obj
)->puid
;
1060 pp
= &((isns_pg_t
*)obj
)->puid
;
1062 case OBJ_ASSOC_ISCSI
:
1063 pp
= &((isns_assoc_iscsi_t
*)obj
)->puid
;
1066 pp
= &((isns_assoc_dd_t
*)obj
)->puid
;
1078 const isns_obj_t
*obj
1081 uint32_t *pp
= get_parent_p(obj
);
1090 * ****************************************************************************
1093 * get the pointer of the UID array of the n'th child of an object.
1096 * n - the child index.
1097 * return - the pointer of the UID array.
1099 * ****************************************************************************
1108 obj
->type
== OBJ_ENTITY
? &((isns_entity_t
*)obj
)->cuid
[n
] : NULL
;
1114 * ****************************************************************************
1117 * get the UID array of the n'th child of an object.
1120 * n - the child index.
1121 * return - the UID array.
1123 * ****************************************************************************
1135 uint32_t **pp
= get_child_np(obj
, n
);
1146 * ****************************************************************************
1149 * get the pointer of the UID array of the child matching the type.
1152 * child_type - the child object type.
1153 * return - the pointer of the UID array.
1155 * ****************************************************************************
1163 uint32_t **pp
= NULL
;
1165 while (i
< NUM_OF_CHILD
[base
->type
]) {
1166 if (child_type
== TYPE_OF_CHILD
[base
->type
][i
]) {
1167 pp
= get_child_np(base
, i
);
1177 * ****************************************************************************
1180 * get the UID array of the child object matching the type.
1183 * child_type - the child object type.
1184 * return - the UID array.
1186 * ****************************************************************************
1194 uint32_t **pp
= get_child_p(base
, child_type
);
1204 * ****************************************************************************
1207 * compare the object against the lookup control data.
1209 * lcp - the lookup control data.
1211 * return - comparison result.
1213 * ****************************************************************************
1223 while (i
< MAX_LOOKUP_CTRL
&& lcp
->op
[i
] > 0 && match
) {
1224 isns_attr_t
*attr
= &obj
->attrs
[lcp
->id
[i
]];
1225 switch (lcp
->op
[i
]) {
1227 match
= (strcmp((const char *)lcp
->data
[i
].ptr
,
1228 (const char *)attr
->value
.ptr
) == 0);
1231 match
= (lcp
->data
[i
].ui
== attr
->value
.ui
);
1234 match
= !memcmp((void *)lcp
->data
[i
].ip
,
1235 (void *)attr
->value
.ip
,
1236 sizeof (in6_addr_t
));
1254 * ****************************************************************************
1257 * fill in the lookup control data for an object.
1259 * lcp - the lookup control data.
1261 * return - the lookup control data.
1263 * ****************************************************************************
1265 static lookup_ctrl_t
*
1271 isns_type_t type
= obj
->type
;
1276 while (i
< MAX_KEY_ATTRS
) {
1277 op
= KEY_ATTR_OP
[type
][i
];
1279 id
= KEY_ATTR_INDEX
[type
][i
];
1282 lcp
->data
[i
].ui
= obj
->attrs
[id
].value
.ui
;
1293 * ****************************************************************************
1296 * assign an attribute.
1298 * attr - the attribute being assigned.
1299 * tmp - the attribute.
1300 * return - error code.
1302 * ****************************************************************************
1307 const isns_attr_t
*tmp
1313 case ISNS_EID_ATTR_ID
:
1314 case ISNS_DD_SET_NAME_ATTR_ID
:
1315 case ISNS_DD_NAME_ATTR_ID
:
1316 if (tmp
->len
== 0 && attr
->len
== 0) {
1318 char *name
= make_unique_name(&len
, tmp
->tag
);
1320 attr
->value
.ptr
= (uchar_t
*)name
;
1321 attr
->tag
= tmp
->tag
;
1324 /* memory exhausted */
1328 case ISNS_PORTAL_NAME_ATTR_ID
:
1329 case ISNS_ISCSI_NAME_ATTR_ID
:
1330 case ISNS_ISCSI_ALIAS_ATTR_ID
:
1331 case ISNS_ISCSI_AUTH_METHOD_ATTR_ID
:
1332 case ISNS_PG_ISCSI_NAME_ATTR_ID
:
1333 case ISNS_DD_ISCSI_NAME_ATTR_ID
:
1334 if (tmp
->len
== 0) {
1336 } else if (tmp
->len
>= attr
->len
) {
1337 attr
->value
.ptr
= realloc(
1338 attr
->value
.ptr
, tmp
->len
+ 1);
1340 if (attr
->value
.ptr
!= NULL
) {
1341 (void) strncpy((char *)attr
->value
.ptr
,
1342 (char *)tmp
->value
.ptr
, tmp
->len
);
1343 attr
->value
.ptr
[tmp
->len
] = 0;
1344 attr
->tag
= tmp
->tag
;
1345 attr
->len
= tmp
->len
;
1347 /* memory exhausted */
1351 case ISNS_MGMT_IP_ADDR_ATTR_ID
:
1352 case ISNS_PORTAL_IP_ADDR_ATTR_ID
:
1353 case ISNS_PG_PORTAL_IP_ADDR_ATTR_ID
:
1354 if (attr
->value
.ip
== NULL
) {
1355 attr
->value
.ip
= (in6_addr_t
*)calloc(1, tmp
->len
);
1357 if (attr
->value
.ip
!= NULL
) {
1358 (void) memcpy((void *)attr
->value
.ip
,
1359 (void *)tmp
->value
.ip
, tmp
->len
);
1360 attr
->tag
= tmp
->tag
;
1361 attr
->len
= tmp
->len
;
1363 /* memory exhausted */
1367 case ISNS_ENTITY_INDEX_ATTR_ID
:
1368 case ISNS_PORTAL_INDEX_ATTR_ID
:
1369 case ISNS_ISCSI_NODE_INDEX_ATTR_ID
:
1370 case ISNS_PG_INDEX_ATTR_ID
:
1371 case ISNS_DD_SET_ID_ATTR_ID
:
1372 case ISNS_DD_ID_ATTR_ID
:
1373 if (attr
->value
.ui
!= 0) {
1376 case ISNS_ENTITY_PROTOCOL_ATTR_ID
:
1377 case ISNS_VERSION_RANGE_ATTR_ID
:
1379 case ISNS_PORTAL_PORT_ATTR_ID
:
1380 case ISNS_ESI_PORT_ATTR_ID
:
1381 case ISNS_SCN_PORT_ATTR_ID
:
1383 case ISNS_ISCSI_NODE_TYPE_ATTR_ID
:
1384 case ISNS_ISCSI_SCN_BITMAP_ATTR_ID
:
1386 case ISNS_PG_PORTAL_PORT_ATTR_ID
:
1387 case ISNS_PG_TAG_ATTR_ID
:
1389 case ISNS_DD_SET_STATUS_ATTR_ID
:
1390 case ISNS_DD_ISCSI_INDEX_ATTR_ID
:
1391 attr
->tag
= tmp
->tag
;
1392 attr
->len
= tmp
->len
;
1393 attr
->value
.ui
= tmp
->value
.ui
;
1395 case ISNS_ENTITY_REG_PERIOD_ATTR_ID
:
1396 attr
->tag
= tmp
->tag
;
1397 attr
->len
= tmp
->len
;
1398 attr
->value
.ui
= tmp
->value
.ui
;
1399 t
= get_reg_period();
1400 if (attr
->value
.ui
> t
) {
1402 } else if (attr
->value
.ui
< ONE_DAY
) {
1403 attr
->value
.ui
= ONE_DAY
;
1406 case ISNS_ESI_INTERVAL_ATTR_ID
:
1407 attr
->tag
= tmp
->tag
;
1408 attr
->len
= tmp
->len
;
1409 attr
->value
.ui
= tmp
->value
.ui
;
1410 if (attr
->value
.ui
> ONE_DAY
) {
1411 attr
->value
.ui
= ONE_DAY
;
1412 } else if (attr
->value
.ui
< MIN_ESI_INTVAL
) {
1413 attr
->value
.ui
= MIN_ESI_INTVAL
; /* 20 seconds */
1418 /* don't assign the attribute */
1425 * ****************************************************************************
1428 * copy all of attributes from one object to another.
1430 * dst - the destination object.
1431 * tmp - the source object.
1432 * return - error code.
1434 * ****************************************************************************
1439 const isns_obj_t
*src
1443 int n
= NUM_OF_ATTRS
[dst
->type
];
1445 isns_attr_t
*dst_attr
;
1446 const isns_attr_t
*src_attr
;
1449 src_attr
= &(src
->attrs
[i
]);
1450 if (src_attr
->tag
!= 0) {
1451 dst_attr
= &(dst
->attrs
[i
]);
1452 if (assign_attr(dst_attr
, src_attr
) != 0) {
1463 * ****************************************************************************
1466 * extract an attribute from a TLV format data.
1468 * attr - the attribute.
1469 * tlv - the TLV format data.
1470 * return - error code.
1472 * ****************************************************************************
1477 const isns_tlv_t
*tlv
,
1483 uint32_t min_len
= 4, max_len
= 224;
1485 switch (tlv
->attr_id
) {
1486 case ISNS_EID_ATTR_ID
:
1488 case ISNS_PORTAL_NAME_ATTR_ID
:
1489 case ISNS_ISCSI_ALIAS_ATTR_ID
:
1490 case ISNS_DD_SET_NAME_ATTR_ID
:
1491 case ISNS_DD_NAME_ATTR_ID
:
1493 case ISNS_ISCSI_NAME_ATTR_ID
:
1494 case ISNS_PG_ISCSI_NAME_ATTR_ID
:
1495 if (tlv
->attr_len
< min_len
|| tlv
->attr_len
> max_len
) {
1496 ec
= ISNS_RSP_MSG_FORMAT_ERROR
;
1498 attr
->tag
= tlv
->attr_id
;
1499 attr
->len
= tlv
->attr_len
;
1500 attr
->value
.ptr
= (uchar_t
*)&(tlv
->attr_value
[0]);
1503 case ISNS_ISCSI_AUTH_METHOD_ATTR_ID
:
1504 attr
->tag
= tlv
->attr_id
;
1505 attr
->len
= tlv
->attr_len
;
1506 attr
->value
.ptr
= (uchar_t
*)&(tlv
->attr_value
[0]);
1508 case ISNS_MGMT_IP_ADDR_ATTR_ID
:
1509 case ISNS_PORTAL_IP_ADDR_ATTR_ID
:
1510 case ISNS_PG_PORTAL_IP_ADDR_ATTR_ID
:
1511 if (tlv
->attr_len
!= 16) {
1512 ec
= ISNS_RSP_MSG_FORMAT_ERROR
;
1514 attr
->tag
= tlv
->attr_id
;
1515 attr
->len
= tlv
->attr_len
;
1516 attr
->value
.ip
= (void *)&(tlv
->attr_value
[0]);
1519 case ISNS_ENTITY_PROTOCOL_ATTR_ID
:
1520 case ISNS_VERSION_RANGE_ATTR_ID
:
1521 case ISNS_ENTITY_REG_PERIOD_ATTR_ID
:
1523 case ISNS_PORTAL_PORT_ATTR_ID
:
1524 case ISNS_ESI_INTERVAL_ATTR_ID
:
1525 case ISNS_ESI_PORT_ATTR_ID
:
1526 case ISNS_SCN_PORT_ATTR_ID
:
1528 case ISNS_ISCSI_NODE_TYPE_ATTR_ID
:
1530 case ISNS_PG_PORTAL_PORT_ATTR_ID
:
1532 case ISNS_DD_SET_ID_ATTR_ID
:
1533 case ISNS_DD_SET_STATUS_ATTR_ID
:
1535 case ISNS_DD_ID_ATTR_ID
:
1536 if (tlv
->attr_len
!= 4) {
1537 ec
= ISNS_RSP_MSG_FORMAT_ERROR
;
1540 case ISNS_PG_TAG_ATTR_ID
:
1541 attr
->tag
= tlv
->attr_id
;
1542 attr
->len
= tlv
->attr_len
;
1543 if (tlv
->attr_len
== 4) {
1544 attr
->value
.ui
= ntohl(*(uint32_t *)
1545 &(tlv
->attr_value
[0]));
1550 case ISNS_ISCSI_SCN_BITMAP_ATTR_ID
:
1551 /* ignore scn bitmap attribute during object registration, */
1552 /* it is registered by scn_reg message. */
1553 case ISNS_ENTITY_ISAKMP_P1_ATTR_ID
:
1554 case ISNS_ENTITY_CERT_ATTR_ID
:
1555 case ISNS_PORTAL_SEC_BMP_ATTR_ID
:
1556 case ISNS_PORTAL_ISAKMP_P1_ATTR_ID
:
1557 case ISNS_PORTAL_ISAKMP_P2_ATTR_ID
:
1558 case ISNS_PORTAL_CERT_ATTR_ID
:
1560 case ISNS_PORTAL_INDEX_ATTR_ID
:
1561 case ISNS_ISCSI_NODE_INDEX_ATTR_ID
:
1562 case ISNS_PG_INDEX_ATTR_ID
:
1564 if (tlv
->attr_len
!= 4) {
1565 ec
= ISNS_RSP_MSG_FORMAT_ERROR
;
1567 attr
->tag
= tlv
->attr_id
;
1568 attr
->len
= tlv
->attr_len
;
1569 attr
->value
.ui
= ntohl(*(uint32_t *)
1570 &(tlv
->attr_value
[0]));
1574 case ISNS_ENTITY_INDEX_ATTR_ID
:
1575 case ISNS_TIMESTAMP_ATTR_ID
:
1578 ec
= ISNS_RSP_INVALID_QRY
;
1580 ec
= ISNS_RSP_INVALID_REGIS
;
1589 * ****************************************************************************
1592 * copy an attribute from a TLV format data.
1594 * attr - the attribute.
1595 * tlv - the TLV format data.
1596 * return - error code.
1598 * ****************************************************************************
1603 const isns_tlv_t
*tlv
1608 isns_attr_t tmp
= { 0 };
1610 /* extract the attribute first */
1611 ec
= extract_attr(&tmp
, tlv
, 1);
1613 /* assign the attribute */
1614 if (ec
== 0 && tmp
.tag
!= 0) {
1615 if (assign_attr(attr
, &tmp
) != 0) {
1616 ec
= ISNS_RSP_INTERNAL_ERROR
;
1624 * ****************************************************************************
1627 * get current timestamp.
1629 * return - current timestamp.
1631 * ****************************************************************************
1640 /* block the scheduler */
1641 (void) pthread_mutex_lock(&el_mtx
);
1643 /* get most current time */
1644 if (sys_q
!= NULL
) {
1645 /* need to wakeup idle */
1650 t
= get_stopwatch(flag
);
1653 (void) pthread_mutex_unlock(&el_mtx
);
1659 * ****************************************************************************
1662 * get the longest registration period.
1664 * return - the longest registration period.
1666 * ****************************************************************************
1675 /* get most current time */
1676 t
= get_timestamp();
1678 /* just one second before the end of the world */
1679 period
= INFINITY
- t
- 1;
1685 * ****************************************************************************
1688 * allocate memory space for an object.
1690 * type - the object type.
1691 * return - pointer of the object being allocated.
1693 * ****************************************************************************
1700 isns_obj_t
*obj
= NULL
;
1702 obj
= (isns_obj_t
*)calloc(1, SIZEOF_OBJ
[type
]);
1707 printf("object(%d) allocated\n", type
);
1716 * ****************************************************************************
1718 * make_default_entity:
1719 * generate a default network entity object.
1721 * return - pointer of the default network entity object.
1723 * ****************************************************************************
1726 make_default_entity(
1731 isns_obj_t
*obj
= obj_calloc(OBJ_ENTITY
);
1735 char *eid
= make_unique_name(&len
, ISNS_EID_ATTR_ID
);
1740 attr
= &obj
->attrs
[ATTR_INDEX_ENTITY(ISNS_EID_ATTR_ID
)];
1742 /* set default entity name */
1743 attr
->tag
= ISNS_EID_ATTR_ID
;
1745 attr
->value
.ptr
= (uchar_t
*)eid
;
1747 /* set default registration period */
1749 ATTR_INDEX_ENTITY(ISNS_ENTITY_REG_PERIOD_ATTR_ID
)];
1750 if (attr
->tag
== 0) {
1751 attr
->tag
= ISNS_ENTITY_REG_PERIOD_ATTR_ID
;
1753 t
= get_reg_period();
1762 * ****************************************************************************
1765 * generate a default portal group object.
1767 * iscsi - the iscsi storage node object.
1768 * portal - the portal object.
1769 * return - pointer of the default portal group object.
1771 * ****************************************************************************
1775 const isns_obj_t
*p1
,
1776 const isns_obj_t
*p2
1779 const isns_obj_t
*iscsi
, *portal
;
1780 const isns_attr_t
*name
, *addr
, *port
;
1784 in6_addr_t
*pg_addr
;
1790 if (p1
->type
== OBJ_ISCSI
) {
1797 name
= &iscsi
->attrs
[ATTR_INDEX_ISCSI(ISNS_ISCSI_NAME_ATTR_ID
)];
1798 addr
= &portal
->attrs
[ATTR_INDEX_PORTAL(ISNS_PORTAL_IP_ADDR_ATTR_ID
)];
1799 port
= &portal
->attrs
[ATTR_INDEX_PORTAL(ISNS_PORTAL_PORT_ATTR_ID
)];
1801 pg
= obj_calloc(OBJ_PG
);
1802 pg_name
= (uchar_t
*)malloc(name
->len
);
1803 pg_addr
= (in6_addr_t
*)malloc(addr
->len
);
1804 if (pg
!= NULL
&& pg_name
!= NULL
&& pg_addr
!= NULL
) {
1805 (void) strcpy((char *)pg_name
, (char *)name
->value
.ptr
);
1806 attr
= &pg
->attrs
[ATTR_INDEX_PG(ISNS_PG_ISCSI_NAME_ATTR_ID
)];
1807 attr
->tag
= ISNS_PG_ISCSI_NAME_ATTR_ID
;
1808 attr
->len
= name
->len
;
1809 attr
->value
.ptr
= pg_name
;
1811 (void) memcpy((void *)pg_addr
,
1812 (void *)addr
->value
.ip
, addr
->len
);
1813 attr
= &pg
->attrs
[ATTR_INDEX_PG(
1814 ISNS_PG_PORTAL_IP_ADDR_ATTR_ID
)];
1815 attr
->tag
= ISNS_PG_PORTAL_IP_ADDR_ATTR_ID
;
1816 attr
->len
= addr
->len
;
1817 attr
->value
.ip
= pg_addr
;
1819 attr
= &pg
->attrs
[ATTR_INDEX_PG(
1820 ISNS_PG_PORTAL_PORT_ATTR_ID
)];
1821 attr
->tag
= ISNS_PG_PORTAL_PORT_ATTR_ID
;
1822 attr
->len
= port
->len
;
1823 attr
->value
.ui
= port
->value
.ui
;
1825 attr
= &pg
->attrs
[ATTR_INDEX_PG(
1826 ISNS_PG_TAG_ATTR_ID
)];
1827 attr
->tag
= ISNS_PG_TAG_ATTR_ID
;
1829 attr
->value
.ui
= ISNS_DEFAULT_PGT
;
1831 refp
= get_ref_p(pg
, OBJ_ISCSI
);
1832 *refp
= get_obj_uid(iscsi
);
1834 refp
= get_ref_p(pg
, OBJ_PORTAL
);
1835 *refp
= get_obj_uid(portal
);
1837 (void) set_parent_obj(pg
, get_parent_uid(iscsi
));
1849 * ****************************************************************************
1852 * parse the Operating Attributes of the DevAttrReg message and
1853 * create the Network Entity object if it has one.
1855 * p - the pointer of the object for returning.
1856 * op - the operating attributes.
1857 * op_len - the length of the operating attributes.
1858 * return - error code.
1860 * ****************************************************************************
1875 isns_obj_t
*entity
= NULL
;
1880 /* parse the entity object */
1881 if (tmp_len
>= 8 && IS_ENTITY_KEY(tmp
->attr_id
)) {
1882 entity
= obj_calloc(OBJ_ENTITY
);
1883 if (entity
!= NULL
) {
1885 attr
= &entity
->attrs
[
1886 ATTR_INDEX_ENTITY(tmp
->attr_id
)];
1887 ec
= copy_attr(attr
, tmp
);
1888 NEXT_TLV(tmp
, tmp_len
);
1891 IS_ENTITY_ATTR(tmp
->attr_id
));
1893 ec
= ISNS_RSP_INTERNAL_ERROR
;
1897 /* set default registration period */
1898 attr
= &entity
->attrs
[
1899 ATTR_INDEX_ENTITY(ISNS_ENTITY_REG_PERIOD_ATTR_ID
)];
1900 if (attr
->tag
== 0) {
1901 attr
->tag
= ISNS_ENTITY_REG_PERIOD_ATTR_ID
;
1903 attr
->value
.ui
= get_reg_period();
1905 } else if (entity
!= NULL
) {
1919 * ****************************************************************************
1922 * parse the Operating Attributes of the DevAttrReg message and
1923 * create an iSCSI Storage Node object.
1925 * p - the pointer of the object for returning.
1926 * pg_key1 - the pointer of iscsi storage node name for returning.
1927 * op - the operating attributes.
1928 * op_len - the length of the operating attributes.
1929 * return - error code.
1931 * ****************************************************************************
1936 isns_attr_t
*pg_key1
,
1947 isns_obj_t
*obj
= NULL
;
1952 /* keep the iscsi storage node name for */
1953 /* parsing a pg object which is immediately */
1954 /* followed with a PGT by the iscsi storage node */
1955 pg_key1
->tag
= PG_KEY1
;
1956 pg_key1
->len
= tmp
->attr_len
;
1957 pg_key1
->value
.ptr
= (uchar_t
*)&tmp
->attr_value
[0];
1959 /* parse one iscsi storage node object */
1960 obj
= obj_calloc(OBJ_ISCSI
);
1962 /* parse key & non-key attributes */
1965 ATTR_INDEX_ISCSI(tmp
->attr_id
)];
1966 ec
= copy_attr(attr
, tmp
);
1967 NEXT_TLV(tmp
, tmp_len
);
1970 IS_ISCSI_ATTR(tmp
->attr_id
));
1973 ec
= ISNS_RSP_INTERNAL_ERROR
;
1984 * ****************************************************************************
1987 * parse the Operating Attributes of the DevAttrReg message and
1988 * create a Portal object.
1990 * p - the pointer of the object for returning.
1991 * pg_key1 - the pointer of portal ip addr for returning.
1992 * pg_key2 - the pointer of portal port for returning.
1993 * op - the operating attributes.
1994 * op_len - the length of the operating attributes.
1995 * return - error code.
1997 * ****************************************************************************
2002 isns_attr_t
*pg_key1
,
2003 isns_attr_t
*pg_key2
,
2014 isns_obj_t
*obj
= NULL
;
2021 /* keep the portal ip addr */
2022 pg_key1
->tag
= PG_KEY2
;
2023 pg_key1
->len
= tmp
->attr_len
;
2024 pg_key1
->value
.ip
= (void *)&tmp
->attr_value
[0];
2027 NEXT_TLV(tmp
, tmp_len
);
2029 tmp
->attr_id
== PORTAL_KEY2
&&
2030 tmp
->attr_len
== 4) {
2031 /* keep the portal port */
2032 pg_key2
->tag
= PG_KEY3
;
2033 pg_key2
->len
= tmp
->attr_len
;
2034 pg_key2
->value
.ui
= ntohl(*(uint32_t *)&tmp
->attr_value
[0]);
2036 /* parse one portal object */
2037 obj
= obj_calloc(OBJ_PORTAL
);
2039 /* copy ip addr attribute */
2041 ATTR_INDEX_PORTAL(ip
->attr_id
)];
2042 ec
= copy_attr(attr
, ip
);
2043 /* copy port attribute */
2046 ATTR_INDEX_PORTAL(tmp
->attr_id
)];
2047 ec
= copy_attr(attr
, tmp
);
2049 /* parse non-key attributes */
2050 NEXT_TLV(tmp
, tmp_len
);
2053 IS_PORTAL_ATTR(tmp
->attr_id
)) {
2057 ec
= copy_attr(attr
, tmp
);
2058 NEXT_TLV(tmp
, tmp_len
);
2062 ec
= ISNS_RSP_INTERNAL_ERROR
;
2065 /* ip address is not followed by port */
2066 ec
= ISNS_RSP_MSG_FORMAT_ERROR
;
2077 * ****************************************************************************
2080 * parse the Operating Attributes of the DevAttrReg message and
2081 * create a Portal Group object.
2083 * p - the pointer of the object for returning.
2084 * op - the operating attributes.
2085 * op_len - the length of the operating attributes.
2086 * return - error code.
2088 * ****************************************************************************
2103 isns_obj_t
*obj
= NULL
;
2108 /* parse a complete pg object */
2109 obj
= obj_calloc(OBJ_PG
);
2111 /* parse attributes */
2114 ATTR_INDEX_PG(tmp
->attr_id
)];
2115 ec
= copy_attr(attr
, tmp
);
2116 NEXT_TLV(tmp
, tmp_len
);
2119 IS_PG_ATTR(tmp
->attr_id
));
2121 ec
= ISNS_RSP_INTERNAL_ERROR
;
2132 * ****************************************************************************
2135 * parse the Operating Attributes of the DevAttrReg message and
2136 * create a Portal Group object which is followed to a Portal object.
2138 * p - the pointer of the object for returning.
2139 * pgt - the size-3 array of pointers which have the pg portal ip addr, port
2140 * and the pg tag attributes.
2141 * op - the operating attributes.
2142 * op_len - the length of the operating attributes.
2143 * return - error code.
2145 * ****************************************************************************
2150 isns_attr_t
const *pgt
,
2161 isns_obj_t
*obj
= NULL
;
2167 if (pgt
[0].tag
== PG_KEY2
&&
2168 pgt
[1].tag
== PG_KEY3
) {
2169 /* the pg iscsi storage node name is */
2170 /* followed to a portal group tag */
2171 obj
= obj_calloc(OBJ_PG
);
2173 /* copy pg iscsi storage node name */
2175 ATTR_INDEX_PG(tmp
->attr_id
)];
2176 ec
= copy_attr(attr
, tmp
);
2177 /* copy pg ip addr, pg port & pgt */
2178 while (ec
== 0 && i
< 3) {
2180 ATTR_INDEX_PG(pgt
[i
].tag
)];
2181 ec
= assign_attr(attr
, &pgt
[i
]);
2184 NEXT_TLV(tmp
, tmp_len
);
2187 ec
= ISNS_RSP_INTERNAL_ERROR
;
2190 ec
= ISNS_RSP_MSG_FORMAT_ERROR
;
2201 * ****************************************************************************
2204 * parse the Operating Attributes of the DevAttrReg message and
2205 * create a Portal Group object which is followed to a iSCSI
2206 * Storage Node object.
2208 * p - the pointer of the object for returning.
2209 * pgt - the size-3 array of pointers which have the pg iscsi storage
2210 * node name and the pg tag attributes.
2211 * op - the operating attributes.
2212 * op_len - the length of the operating attributes.
2213 * return - error code.
2215 * ****************************************************************************
2220 isns_attr_t
const *pgt
,
2231 isns_obj_t
*obj
= NULL
;
2239 /* keep ip address */
2241 NEXT_TLV(tmp
, tmp_len
);
2244 /* expect pg portal port */
2245 tmp
->attr_id
== PG_KEY3
&&
2246 tmp
->attr_len
== 4 &&
2248 pgt
[2].tag
== PG_PGT
&&
2249 /* expect pg iscsi storage node name only */
2251 pgt
[0].tag
== PG_KEY1
) {
2252 /* the pg portal ip addr & port is followed */
2253 /* to a pg tag and we have the iscsi storage */
2254 /* node parsed previously */
2255 obj
= obj_calloc(OBJ_PG
);
2257 /* copy the pg ip addr */
2259 ATTR_INDEX_PG(ip
->attr_id
)];
2260 ec
= copy_attr(attr
, ip
);
2261 /* copy the pg port */
2264 ATTR_INDEX_PG(tmp
->attr_id
)];
2265 ec
= copy_attr(attr
, tmp
);
2267 /* copy pg iscsi storage node name & pgt */
2268 while (ec
== 0 && i
< 3) {
2270 ATTR_INDEX_PG(pgt
[i
].tag
)];
2271 ec
= assign_attr(attr
, &pgt
[i
]);
2274 NEXT_TLV(tmp
, tmp_len
);
2276 ec
= ISNS_RSP_INTERNAL_ERROR
;
2279 ec
= ISNS_RSP_MSG_FORMAT_ERROR
;
2290 * ****************************************************************************
2293 * parse and create one object from the rest of Operating Attributes
2294 * of the DevAttrReg message, the object can be iSCSI Storage Node,
2295 * Portal or Portal Group.
2297 * p - the pointer of the object for returning.
2298 * pgt - an attribute array with size 3, the elements are:
2299 * 0: the first pg key attribute, it is either the name of an
2300 * iscsi storage node object or the ip addr of a portal object.
2301 * 1: the second pg key attribute, i.e. the portal port.
2302 * 2: the portal group tag attribute.
2303 * op - the operating attributes.
2304 * op_len - the length of the operating attributes.
2305 * return - error code.
2307 * ****************************************************************************
2328 switch ((*op
)->attr_id
) {
2330 ec
= reg_get_iscsi(p
, &pgt
[0], op
, op_len
);
2335 ec
= reg_get_portal(p
, &pgt
[0], &pgt
[1], op
, op_len
);
2339 if (pgt
[2].tag
== PG_PGT
) {
2340 /* pg iscsi storage node name is */
2341 /* followed to a pgt */
2342 ec
= reg_get_pg1(p
, pgt
, op
, op_len
);
2344 /* a complete pg object */
2345 ec
= reg_get_pg(p
, op
, op_len
);
2352 /* pg portal ip addr is followed to a pgt */
2353 ec
= reg_get_pg2(p
, pgt
, op
, op_len
);
2356 switch (pgt
[0].tag
) {
2358 /* portal group tag does not follow */
2359 /* iscsi storage node or portal object */
2361 ec
= ISNS_RSP_MSG_FORMAT_ERROR
;
2365 pgt
[2].tag
= PG_PGT
;
2366 pgt
[2].len
= (*op
)->attr_len
;
2368 switch ((*op
)->attr_len
) {
2370 pg_tag
= ntohl(*(uint32_t *)
2371 &(*op
)->attr_value
[0]);
2373 pgt
[2].value
.ui
= pg_tag
;
2377 ec
= ISNS_RSP_MSG_FORMAT_ERROR
;
2382 NEXT_TLV(*op
, *op_len
);
2383 ec
= reg_get_obj(p
, pgt
, op
, op_len
);
2387 /* should never happen */
2390 ec
= ISNS_RSP_INTERNAL_ERROR
;
2396 ec
= ISNS_RSP_MSG_FORMAT_ERROR
;
2400 if (ec
== 0 && derefd
== 0) {
2401 ec
= update_deref_obj(*p
);
2404 if (ec
!= 0 && *p
!= NULL
) {
2405 free_one_object(*p
);
2413 * ****************************************************************************
2416 * Authorize the source attribute the DevAttrReg message.
2417 * The update can only performed by the node who has the owenership.
2419 * p - the pointer of the object for returning.
2420 * pgt - an attribute array with size 3, the elements are:
2421 * 0: the first pg key attribute, it is either the name of an
2422 * iscsi storage node object or the ip addr of a portal object.
2423 * 1: the second pg key attribute, i.e. the portal port.
2424 * 2: the portal group tag attribute.
2425 * op - the operating attributes.
2426 * op_len - the length of the operating attributes.
2427 * return - error code.
2429 * ****************************************************************************
2441 puid
= is_parent_there(src
);
2443 if (TYPE_OF_PARENT
[type
] != 0) {
2444 SET_UID_LCP(&lc
, type
, uid
);
2445 uid
= cache_lookup(&lc
, NULL
, cb_get_parent
);
2446 type
= TYPE_OF_PARENT
[type
];
2449 if (uid
!= 0 && puid
== 0) {
2450 SET_UID_LCP(&lc
, type
, uid
);
2451 uid
= cache_lookup(&lc
, NULL
, cb_node_child
);
2462 * ****************************************************************************
2465 * determine if the object is currently registered with the server.
2467 * obj - the object being checked.
2468 * return - 0: not registered, otherwise registered.
2470 * ****************************************************************************
2474 const isns_obj_t
*obj
2479 switch (obj
->type
) {
2481 online
= obj
->attrs
[ATTR_INDEX_ISCSI(
2482 ISNS_ISCSI_NODE_TYPE_ATTR_ID
)].value
.ui
== 0 ? 0 : 1;
2496 switch (obj
->type
) {
2498 obj
->attrs
[ATTR_INDEX_ISCSI(
2499 ISNS_ISCSI_NODE_TYPE_ATTR_ID
)].value
.ui
= 0;
2509 * ****************************************************************************
2512 * clone the association object.
2514 * p - the object being cloned.
2515 * clone_flag - 0: the object is being removed;
2516 * 1: only the association is being removed.
2517 * return - the clone object.
2519 * ****************************************************************************
2529 const isns_attr_t
*src_attr
;
2530 isns_attr_t
*dst_attr
;
2534 const isns_obj_t
*obj
;
2540 obj
= (isns_obj_t
*)p
;
2542 if (obj
->type
!= OBJ_ISCSI
) {
2546 dd_flag
= (get_dd_id(get_obj_uid(obj
), ISNS_DEFAULT_DD_ID
) == 0) ?
2548 online
= is_obj_online(obj
);
2550 state
= (clone_flag
<< 2) | (dd_flag
<< 1) | online
;
2552 /* clone_flag dd_flag online action */
2553 /* 0 0 0 ASSERT(0) */
2556 /* 0 1 1 clone it */
2579 clone
= obj_calloc(type
);
2581 if (clone
!= NULL
) {
2582 id
= UID_ATTR_INDEX
[type
];
2583 src_attr
= &(obj
->attrs
[id
]);
2584 dst_attr
= &(clone
->attrs
[id
]);
2585 if (assign_attr(dst_attr
, src_attr
) != 0) {
2586 free_one_object(clone
);
2590 while (i
< MAX_KEY_ATTRS
) {
2591 op
= KEY_ATTR_OP
[type
][i
];
2593 id
= KEY_ATTR_INDEX
[type
][i
];
2594 src_attr
= &(obj
->attrs
[id
]);
2595 dst_attr
= &(clone
->attrs
[id
]);
2596 if (assign_attr(dst_attr
, src_attr
) != 0) {
2597 free_one_object(clone
);
2607 return ((void *)clone
);
2611 * ****************************************************************************
2614 * free up one object.
2616 * obj - the object being freed.
2618 * ****************************************************************************
2630 for (i
= 0; i
< NUM_OF_ATTRS
[obj
->type
]; i
++) {
2631 isns_attr_t
*attr
= &obj
->attrs
[i
];
2632 switch (attr
->tag
) {
2633 case ISNS_EID_ATTR_ID
:
2634 case ISNS_ISCSI_NAME_ATTR_ID
:
2635 case ISNS_ISCSI_ALIAS_ATTR_ID
:
2636 case ISNS_ISCSI_AUTH_METHOD_ATTR_ID
:
2637 case ISNS_PG_ISCSI_NAME_ATTR_ID
:
2638 case ISNS_PORTAL_IP_ADDR_ATTR_ID
:
2639 case ISNS_PORTAL_NAME_ATTR_ID
:
2640 case ISNS_PG_PORTAL_IP_ADDR_ATTR_ID
:
2641 case ISNS_DD_SET_NAME_ATTR_ID
:
2642 case ISNS_DD_NAME_ATTR_ID
:
2643 case ISNS_DD_ISCSI_NAME_ATTR_ID
:
2644 case ISNS_DD_FC_PORT_NAME_ATTR_ID
:
2645 case ISNS_DD_PORTAL_IP_ADDR_ATTR_ID
:
2648 printf("memory(%d) deallocated\n",
2652 free(attr
->value
.ptr
);
2653 attr
->value
.ptr
= NULL
;
2660 /* free child uids */
2662 while (i
< NUM_OF_CHILD
[obj
->type
]) {
2663 cuid
= get_child_n(obj
, i
);
2668 /* at last, free the object itself */
2671 printf("object(%d) deallocated\n", obj
->type
);
2678 * ****************************************************************************
2681 * free up one object.
2683 * obj - the object being freed.
2685 * ****************************************************************************
2692 free_one_object(obj
);
2696 * ****************************************************************************
2699 * set the parent object UID.
2701 * obj - the child object.
2702 * puid- the parent object UID.
2703 * return - error code.
2705 * ****************************************************************************
2713 uint32_t *const p
= get_parent_p(obj
);
2722 * ****************************************************************************
2725 * add a child object UID to the child object array.
2727 * obj - the parent object.
2728 * child_type - the type of the child object.
2729 * number - the number of the child object.
2730 * return - the length of the child object UID array.
2732 * ****************************************************************************
2736 const isns_type_t ptype
,
2737 const isns_type_t ctype
,
2745 void const ***pp
, **p
;
2746 uint32_t num
, new_num
;
2749 /* get the pointer of the array which the child belongs to */
2750 while (i
< NUM_OF_CHILD
[ptype
]) {
2751 if (TYPE_OF_CHILD
[ptype
][i
] == ctype
) {
2758 /* the child type is not applicable */
2764 /* get an empty slot from the uid array for this child */
2769 if (p
[++i
] == NULL
) {
2782 /* the array is full, enlarge the child uid array */
2783 p
= reallocarray(p
, new_num
+ 1, sizeof (void *));
2786 *p
= (void *)new_num
;
2789 ec
= ISNS_RSP_INTERNAL_ERROR
;
2796 * ****************************************************************************
2798 * update_child_object:
2799 * update the child object of a network entity object.
2801 * puid - the UID of the parent object, i.e. the network entity object.
2802 * child_type - the type of the child object.
2803 * child_uid - the uid of the child object.
2804 * return - error code.
2806 * ****************************************************************************
2810 const isns_type_t ptype
,
2811 const uint32_t puid
,
2812 void const ***child
,
2820 SET_UID_LCP(&lc
, ptype
, puid
);
2822 lc
.data
[1].ptr
= (uchar_t
*)child
;
2823 lc
.data
[2].ui
= child_flag
;
2825 ec
= cache_lookup(&lc
, NULL
, cb_add_child
);
2832 const isns_obj_t
*obj
2841 if (TYPE_OF_REF
[t
][0] != 0) {
2842 (void) setup_ref_lcp(&lc
, obj
, NULL
);
2845 lc
.data
[2].ui
= get_obj_uid(obj
);
2850 (void) cache_lookup(&lc
, &uid
, cb_set_ref
);
2858 * ****************************************************************************
2861 * update the reference bit of a portal group object.
2863 * obj - the object being ref'ed.
2864 * return - error code.
2866 * ****************************************************************************
2870 const isns_type_t ptype
,
2871 const uint32_t puid
,
2879 SET_UID_LCP(&lc
, ptype
, puid
);
2881 lc
.data
[1].ptr
= (uchar_t
*)child
;
2883 ec
= cache_lookup(&lc
, NULL
, cb_verify_ref
);
2899 uint32_t uid
, *refp
;
2903 while (i
< NUM_OF_REF
[t
]) {
2904 rt
= TYPE_OF_REF
[t
][i
+ 1];
2905 (void) setup_deref_lcp(&lc
, obj
, rt
);
2906 uid
= is_obj_there(&lc
);
2908 refp
= get_ref_p(obj
, lc
.type
);
2915 if (i
> 0 && ref_count
== 0) {
2916 ec
= ISNS_RSP_INVALID_REGIS
;
2923 * ****************************************************************************
2926 * add one object to the object container.
2928 * obj - the object being added.
2929 * uid_p- the pointer for returning object UID.
2930 * update_p- the pointer for returning flag which indicates if the object
2931 * is newly registered or updated with an existing one.
2932 * return - error code.
2934 * ****************************************************************************
2943 return (cache_add(obj
, 0, uid_p
, update_p
));
2947 * ****************************************************************************
2950 * add one association object to the object container, the association
2951 * object has only the information for discovery domain membership, i.e.
2952 * a name and UID only.
2954 * obj - the association object being added.
2955 * uid_p- the pointer for returning object UID.
2956 * return - error code.
2958 * ****************************************************************************
2966 return (cache_add(obj
, 1, uid_p
, NULL
));
2970 * ****************************************************************************
2973 * check if the object is registered or not.
2975 * lcp - the lookup control data.
2976 * return - the object UID.
2978 * ****************************************************************************
2987 (void) cache_lookup(lcp
, &uid
, NULL
);
3000 lc
.type
= OBJ_ISCSI
;
3001 lc
.id
[0] = ATTR_INDEX_ISCSI(ISNS_ISCSI_NAME_ATTR_ID
);
3002 lc
.op
[0] = OP_STRING
;
3003 lc
.data
[0].ptr
= src
;
3006 return (cache_lookup(&lc
, NULL
, cb_get_parent
));
3010 * ****************************************************************************
3013 * prepare the lookup control data for looking up a portal group
3014 * object which references to a iscsi stroage node and/or a portal
3017 * lcp - the lookup control data.
3018 * iscsi- the ref'ed iscsi storage node object.
3019 * portal- the ref'ed portal object.
3020 * return - error code.
3022 * ****************************************************************************
3027 const isns_obj_t
*iscsi
,
3028 const isns_obj_t
*portal
3034 lcp
->type
= TYPE_OF_REF
[iscsi
->type
][0];
3036 /* extrace the matching attributes from iscsi storage node object */
3037 while (iscsi
!= NULL
&&
3038 i
< MAX_REF_MATCH
&&
3039 REF_MATCH_OPS
[iscsi
->type
][i
] > 0) {
3040 lcp
->id
[i
] = REF_MATCH_ID2
[iscsi
->type
][i
];
3041 lcp
->op
[i
] = REF_MATCH_OPS
[iscsi
->type
][i
];
3042 lcp
->data
[i
].ptr
= iscsi
->attrs
[
3043 REF_MATCH_ID1
[iscsi
->type
][i
]].value
.ptr
;
3047 /* extrace the matching attributes from portal object */
3048 while (portal
!= NULL
&&
3049 i
< MAX_LOOKUP_CTRL
&&
3050 j
< MAX_REF_MATCH
&&
3051 REF_MATCH_OPS
[portal
->type
][j
] > 0) {
3052 lcp
->id
[i
] = REF_MATCH_ID2
[portal
->type
][j
];
3053 lcp
->op
[i
] = REF_MATCH_OPS
[portal
->type
][j
];
3054 lcp
->data
[i
].ptr
= portal
->attrs
[
3055 REF_MATCH_ID1
[portal
->type
][j
]].value
.ptr
;
3060 if (i
< MAX_LOOKUP_CTRL
) {
3070 const isns_obj_t
*pg
,
3079 /* extrace the matching attributes from iscsi storage node object */
3080 while (i
< MAX_REF_MATCH
&&
3081 REF_MATCH_OPS
[t
][i
] > 0) {
3082 lcp
->id
[i
] = REF_MATCH_ID1
[t
][i
];
3083 lcp
->op
[i
] = REF_MATCH_OPS
[t
][i
];
3084 lcp
->data
[i
].ptr
= pg
->attrs
[
3085 REF_MATCH_ID2
[t
][i
]].value
.ptr
;
3089 if (i
< MAX_LOOKUP_CTRL
) {
3097 * ****************************************************************************
3100 * prepare the lookup control data for looking up parent object
3101 * with a child object.
3103 * lcp - the lookup control data.
3104 * obj - the child object.
3105 * return - parent object UID.
3107 * ****************************************************************************
3118 puid
= get_parent_uid(obj
);
3120 ptype
= TYPE_OF_PARENT
[obj
->type
];
3121 SET_UID_LCP(lcp
, ptype
, puid
);
3122 lcp
->data
[1].ui
= obj
->type
;
3123 lcp
->data
[2].ui
= get_obj_uid(obj
);
3132 /* LINTED E_FUNC_ARG_UNUSED */
3136 return (get_parent_uid(p1
));
3142 /* LINTED E_FUNC_ARG_UNUSED */
3146 isns_obj_t
*obj
= (isns_obj_t
*)p1
;
3150 uint32_t *cuid
= get_child_t(obj
, OBJ_ISCSI
);
3170 * ****************************************************************************
3173 * callback function which sets the reference bit to 1 according to
3174 * the type of object.
3178 * return - error code.
3180 * ****************************************************************************
3188 isns_obj_t
*obj
= (isns_obj_t
*)p1
;
3189 lookup_ctrl_t
*lcp
= (lookup_ctrl_t
*)p2
;
3197 u
= lcp
->data
[2].ui
;
3198 refp
= get_ref_p(obj
, t
);
3206 * ****************************************************************************
3209 * callback function which clears the reference bit according to
3210 * the type of object.
3214 * return - 1: the object is no longer ref'ed, 0: otherwise.
3216 * ****************************************************************************
3224 isns_obj_t
*obj
= (isns_obj_t
*)p1
;
3225 lookup_ctrl_t
*lcp
= (lookup_ctrl_t
*)p2
;
3233 t
= lcp
->data
[2].ui
;
3234 refp
= get_ref_p(obj
, t
);
3237 while (i
< NUM_OF_REF
[obj
->type
]) {
3238 ref
= get_ref_n(obj
, i
);
3254 isns_obj_t
*obj
= (isns_obj_t
*)p1
;
3255 lookup_ctrl_t
*lcp
= (lookup_ctrl_t
*)p2
;
3257 const void ***child
;
3262 uint32_t **upp
, *up
;
3269 child
= (const void ***)lcp
->data
[1].ptr
;
3270 child_flag
= lcp
->data
[2].ui
;
3272 while (i
< NUM_OF_CHILD
[obj
->type
]) {
3275 (vnum
= (uint32_t)*vpp
) > 0 &&
3276 *(vpp
+ 1) != NULL
) {
3277 upp
= get_child_np(obj
, i
);
3279 if (child_flag
== 0 &&
3280 sizeof (typeof (**upp
)) ==
3281 sizeof (typeof (**child
))) {
3282 *upp
= (uint32_t *)vpp
;
3292 up
= reallocarray(*upp
, num
+ 1,
3295 return (ISNS_RSP_INTERNAL_ERROR
);
3304 } else if (child_flag
== 0) {
3305 *up
= (uint32_t)*vpp
;
3308 o
= (isns_obj_t
*)*vpp
;
3309 *up
= get_obj_uid(o
);
3310 if (is_obj_online(o
) == 0) {
3328 * ****************************************************************************
3331 * callback function which removes a child object UID from the
3332 * children objet UID array of the parent object.
3336 * return - 1: no more such type of child object, 0: otherwise.
3338 * ****************************************************************************
3346 isns_obj_t
*obj
= (isns_obj_t
*)p1
;
3347 lookup_ctrl_t
*lcp
= (lookup_ctrl_t
*)p2
;
3348 uint32_t child_type
= lcp
->data
[1].ui
;
3349 uint32_t child_uid
= lcp
->data
[2].ui
;
3350 uint32_t *cuidp
, cuid
, num_of_child
= 0;
3353 /* get the children object UID array */
3354 cuidp
= get_child_t(obj
, child_type
);
3355 if (cuidp
!= NULL
) {
3356 num_of_child
= *cuidp
;
3360 while (num_of_child
> 0) {
3362 if (cuid
== child_uid
) {
3369 /* check if all of child object UIDs are removed */
3371 while (i
< NUM_OF_CHILD
[obj
->type
]) {
3372 cuidp
= get_child_n(obj
, i
);
3373 if (cuidp
!= NULL
) {
3374 num_of_child
= *cuidp
;
3375 while (num_of_child
> 0) {
3397 isns_obj_t
*parent
= (isns_obj_t
*)p1
;
3398 lookup_ctrl_t
*lcp
= (lookup_ctrl_t
*)p2
;
3400 const void ***child
;
3410 isns_type_t pt
; /* parent object type */
3411 isns_type_t ct
; /* child object type */
3412 isns_type_t rt
; /* ref object type */
3413 isns_type_t et
; /* peer object type */
3420 uint8_t flag
[MAX_OBJ_TYPE
+ 1] = { 0 };
3426 child
= (const void ***)lcp
->data
[1].ptr
;
3428 for (i
= 0; i
< NUM_OF_CHILD
[pt
]; i
++) {
3429 ct
= TYPE_OF_CHILD
[pt
][i
];
3430 rt
= TYPE_OF_REF
[ct
][0];
3435 et
= TYPE_OF_REF
[ct
][1];
3438 vnum
= (uint32_t)*vpp
;
3439 up
= get_child_t(parent
, et
);
3453 (void) setup_ref_lcp(&lc
, vp
, NULL
);
3465 } /* End of while each unum */
3468 } /* End of while each vnum */
3470 if (flag
[ct
] != 0) {
3476 while (j
< NUM_OF_CHILD
[pt
]) {
3477 if (TYPE_OF_CHILD
[pt
][j
] == et
) {
3480 evnum
= (uint32_t)*evpp
;
3493 if (vp
!= NULL
&& evp
!= NULL
) {
3494 (void) setup_ref_lcp(&lc
, vp
, evp
);
3495 ec
= ref_new2new(&lc
, vp
, evp
);
3503 } /* End of while each vnum */
3506 } /* End of for each type of child */
3517 isns_obj_t
*obj
= (isns_obj_t
*)p1
;
3518 lookup_ctrl_t
*lcp
= (lookup_ctrl_t
*)p2
;
3528 uu
= lcp
->data
[2].ui
;
3530 ref
= get_ref_t(obj
, et
);
3549 lookup_ctrl_t
*lcp
= (lookup_ctrl_t
*)p2
;
3550 isns_obj_t
*a
= (isns_obj_t
*)p1
;
3551 isns_obj_t
*b
= (isns_obj_t
*)lcp
->data
[2].ptr
;
3563 const isns_obj_t
*vp
3574 lcp
->data
[2].ui
= uu
;
3578 lcp
->curr_uid
= uid
;
3579 match
= cache_lookup(lcp
, &uid
, cb_ref_new2old
);
3580 } while (match
== 0 && uid
!= 0);
3583 /* no such ref, create a default one */
3584 SET_UID_LCP(&lc
, et
, uu
);
3586 lc
.data
[2].ptr
= (uchar_t
*)vp
;
3588 ec
= cache_lookup(&lc
, NULL
, cb_new_ref
);
3597 const isns_obj_t
*p1
,
3598 const isns_obj_t
*p2
3603 if (is_obj_there(lcp
) != 0) {
3607 ec
= new_ref(p1
, p2
);
3614 const isns_obj_t
*p1
,
3615 const isns_obj_t
*p2
3622 obj
= make_ref
[p1
->type
](p1
, p2
);
3624 ec
= register_object(obj
, NULL
, NULL
);
3626 ec
= ISNS_RSP_INTERNAL_ERROR
;
3633 * ****************************************************************************
3636 * Physically remove an object along with the children objects,
3637 * the reference object and the parent object recursively.
3638 * Apporiate SCN is triggered.
3640 * lcp - the lookup control for the object being removed.
3641 * parent_flag - 1: the object being removed is the parent object;
3643 * child_flag - 1: the object being removed is a child object;
3645 * pending - 1: do not remove the ESI entry immediately;
3646 * 0: remove the ESI entry without any delay.
3647 * return - error code.
3649 * ****************************************************************************
3662 uint32_t *cuidp
, num
;
3667 /* remove the object from object container */
3668 obj
= cache_remove(lcp
, 0);
3675 if (scn_q
!= NULL
) {
3676 (void) make_scn(ISNS_OBJECT_REMOVED
, obj
);
3679 /* dereg children */
3681 while (ec
== 0 && !parent_flag
&&
3682 i
< NUM_OF_CHILD
[obj
->type
]) {
3683 type
= TYPE_OF_CHILD
[obj
->type
][i
];
3684 cuidp
= get_child_n(obj
, i
);
3685 if (cuidp
!= NULL
) {
3690 while (ec
== 0 && num
> 0) {
3693 SET_UID_LCP(lcp
, type
, uid
);
3704 /* clear the ref bit on the ref'd object */
3705 if (ec
== 0 && TYPE_OF_REF
[obj
->type
][0] > 0) {
3708 (void) setup_ref_lcp(lcp
, obj
, NULL
);
3709 lcp
->curr_uid
= uid
;
3710 lcp
->data
[2].ui
= obj
->type
;
3711 if (cache_lookup(lcp
, &uid
, cb_clear_ref
) != 0) {
3712 UPDATE_LCP_UID(lcp
, uid
);
3721 /* remove it from the parent */
3722 if (ec
== 0 && !child_flag
&&
3723 TYPE_OF_PARENT
[obj
->type
] > 0 &&
3724 (uid
= setup_parent_lcp(lcp
, obj
)) != 0) {
3725 if (cache_lookup(lcp
, NULL
, cb_remove_child
) != 0) {
3726 UPDATE_LCP_UID(lcp
, uid
);
3734 if (ec
== 0 && !child_flag
) {
3735 /* remove it from persistent data store */
3737 ec
= write_data(DATA_DELETE
, obj
);
3739 /* remove esi event entry */
3741 (void) esi_remove_obj(obj
, pending
);
3744 /* save the parent uid for caller */
3745 if (TYPE_OF_PARENT
[obj
->type
] != 0) {
3746 lcp
->curr_uid
= get_parent_uid(obj
);
3748 /* it's the parent itself */
3749 lcp
->curr_uid
= get_obj_uid(obj
);
3753 /* remove this portal from scn registry */
3755 obj
->type
== OBJ_PORTAL
) {
3756 (void) remove_scn_portal(get_obj_uid(obj
));
3759 /* free the object */
3760 (void) free_object(obj
);
3766 * ****************************************************************************
3769 * Remove one association object from object container.
3771 * lcp - the lookup control for the object being removed.
3772 * return - error code.
3774 * ****************************************************************************
3783 obj
= cache_remove(lcp
, 1);
3785 /* free the object */
3794 * ****************************************************************************
3797 * Remove one object from object container.
3799 * lcp - the lookup control for the object being removed.
3800 * return - error code.
3802 * ****************************************************************************
3810 return (do_dereg(lcp
, 0, 0, pending
));
3814 * ****************************************************************************
3817 * Synchronize the cache with persistent data store.
3818 * Flush the cache data to data store if the input ec is zero,
3819 * retreat the changes in cache and ignore data store update
3820 * if there is an error.
3823 * return - error code.
3825 * ****************************************************************************
3832 /* cache is updated successfully, commit the data to data store */
3833 if (IS_CACHE_UPDATED()) {
3835 ec
= write_data(DATA_COMMIT
, NULL
);
3838 /* successful, trigger the SCN */
3839 (void) queue_msg_set(scn_q
, SCN_TRIGGER
, NULL
);
3844 /* ignore all SCNs which have been generated */
3845 (void) queue_msg_set(scn_q
, SCN_IGNORE
, NULL
);
3847 (void) write_data(DATA_RETREAT
, NULL
);
3853 static pthread_mutex_t name_mtx
[3] = {
3854 PTHREAD_MUTEX_INITIALIZER
,
3855 PTHREAD_MUTEX_INITIALIZER
,
3856 PTHREAD_MUTEX_INITIALIZER
3858 static const char *name_pattern
[3] = {
3863 static uint32_t name_count
[3] = {
3870 * ****************************************************************************
3873 * make a default unique name for a newly registered network entity,
3874 * discovery domain or discovery domain set object.
3876 * len - pointer of the length of the new name for returning.
3877 * tag - which attribute of the new name is for.
3878 * return - the name being made.
3880 * ****************************************************************************
3890 char name
[32] = { 0 };
3899 case ISNS_EID_ATTR_ID
:
3901 lc
.type
= OBJ_ENTITY
;
3902 lc
.id
[0] = ATTR_INDEX_ENTITY(ISNS_EID_ATTR_ID
);
3904 case ISNS_DD_NAME_ATTR_ID
:
3907 lc
.id
[0] = ATTR_INDEX_DD(ISNS_DD_NAME_ATTR_ID
);
3909 case ISNS_DD_SET_NAME_ATTR_ID
:
3912 lc
.id
[0] = ATTR_INDEX_DDS(ISNS_DD_SET_NAME_ATTR_ID
);
3919 lc
.op
[0] = OP_STRING
;
3922 (void) pthread_mutex_lock(&name_mtx
[i
]);
3923 count
= ++ name_count
[i
];
3924 (void) pthread_mutex_unlock(&name_mtx
[i
]);
3925 /* no more space, failure */
3929 (void) sprintf(name
, name_pattern
[i
], count
);
3930 lc
.data
[0].ptr
= (uchar_t
*)name
;
3931 } while (is_obj_there(&lc
) != 0);
3933 /* 4-bytes aligned length */
3934 *len
= strlen(name
);
3935 *len
= *len
+ (4 - *len
% 4);
3936 p
= (char *)malloc(*len
);
3938 (void) strcpy(p
, name
);
3949 print_object(NULL
, (isns_obj_t
*)p
);