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 2008 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
31 #include "isns_server.h"
32 #include "isns_msgq.h"
33 #include "isns_htab.h"
35 #include "isns_cache.h"
38 #include "isns_dseng.h"
40 #include "isns_utils.h"
43 * extern global variables
45 extern const int UID_ATTR_INDEX
[MAX_OBJ_TYPE_FOR_SIZE
];
47 extern msg_queue_t
*sys_q
;
48 extern msg_queue_t
*scn_q
;
50 extern int cache_flag
;
67 static matrix_t
*new_matrix(uint32_t, uint32_t);
77 isns_obj_t
*obj
= (isns_obj_t
*)p1
;
78 lookup_ctrl_t
*lcp
= (lookup_ctrl_t
*)p2
;
79 uint32_t tag
= lcp
->id
[1];
89 case ISNS_DD_NAME_ATTR_ID
:
90 which
= ATTR_INDEX_DD(ISNS_DD_NAME_ATTR_ID
);
92 case ISNS_DD_FEATURES_ATTR_ID
:
93 which
= ATTR_INDEX_DD(ISNS_DD_FEATURES_ATTR_ID
);
95 case ISNS_DD_SET_NAME_ATTR_ID
:
96 which
= ATTR_INDEX_DDS(ISNS_DD_SET_NAME_ATTR_ID
);
98 case ISNS_DD_SET_STATUS_ATTR_ID
:
99 which
= ATTR_INDEX_DDS(ISNS_DD_SET_STATUS_ATTR_ID
);
106 attr
= &obj
->attrs
[which
];
109 case ISNS_DD_NAME_ATTR_ID
:
110 case ISNS_DD_SET_NAME_ATTR_ID
:
111 len
= lcp
->data
[1].ui
;
112 name
= lcp
->data
[2].ptr
;
116 lc
.op
[0] = OP_STRING
;
117 lc
.data
[0].ptr
= name
;
119 /* check if the name is in use */
120 uid
= is_obj_there(&lc
);
122 if (uid
!= get_obj_uid(obj
)) {
123 ec
= ERR_NAME_IN_USE
;
127 if (len
> attr
->len
) {
128 uchar_t
*tmp
= (uchar_t
*)malloc(len
);
130 free(attr
->value
.ptr
);
131 attr
->value
.ptr
= tmp
;
133 /* memory exhausted */
134 return (ISNS_RSP_INTERNAL_ERROR
);
137 (void) strcpy((char *)attr
->value
.ptr
, (char *)name
);
140 case ISNS_DD_FEATURES_ATTR_ID
:
141 case ISNS_DD_SET_STATUS_ATTR_ID
:
142 if (attr
->tag
!= tag
||
143 attr
->value
.ui
!= lcp
->data
[1].ui
) {
146 attr
->value
.ui
= lcp
->data
[1].ui
;
153 /* cache has been updated, set the flag */
156 /* update data store */
158 ec
= write_data(DATA_UPDATE
, obj
);
170 isns_obj_t
*obj
= NULL
;
174 switch (attr1
->tag
) {
175 case ISNS_DD_ISCSI_NAME_ATTR_ID
:
176 obj
= obj_calloc(OBJ_ISCSI
);
177 attr
= &obj
->attrs
[ATTR_INDEX_ISCSI(ISNS_ISCSI_NAME_ATTR_ID
)];
178 tmp
.tag
= ISNS_ISCSI_NAME_ATTR_ID
;
179 tmp
.len
= attr1
->len
;
180 tmp
.value
.ptr
= attr1
->value
.ptr
;
181 if (assign_attr(attr
, &tmp
) != 0) {
184 } else if (uid
!= 0) {
185 (void) set_obj_uid(obj
, uid
);
201 isns_obj_t
*obj
= NULL
;
202 isns_attr_t name
= { 0 };
204 obj
= obj_calloc(OBJ_DD
);
206 (void) set_obj_uid(obj
, uid
);
207 name
.tag
= ISNS_DD_NAME_ATTR_ID
;
209 &obj
->attrs
[ATTR_INDEX_DD(ISNS_DD_NAME_ATTR_ID
)],
228 lookup_ctrl_t lc
= { 0 };
231 isns_attr_t
*attr1
, *attr2
;
238 attr1
= &assoc
->attrs
[ATTR_INDEX_ASSOC_ISCSI(
239 ISNS_DD_ISCSI_INDEX_ATTR_ID
)];
240 attr2
= &assoc
->attrs
[ATTR_INDEX_ASSOC_ISCSI(
241 ISNS_DD_ISCSI_NAME_ATTR_ID
)];
244 if (attr1
->tag
!= 0 && attr1
->value
.ui
!= 0) {
245 *m_id
= attr1
->value
.ui
;
246 lc
.id
[i
] = UID_ATTR_INDEX
[OBJ_ISCSI
];
247 lc
.op
[i
] = OP_INTEGER
;
248 lc
.data
[i
].ui
= *m_id
;
251 if (attr2
->tag
!= 0) {
252 lc
.id
[i
] = ATTR_INDEX_ISCSI(ISNS_ISCSI_NAME_ATTR_ID
);
253 lc
.op
[i
] = OP_STRING
;
254 lc
.data
[i
].ptr
= attr2
->value
.ptr
;
256 } else if (scn_q
!= NULL
|| sys_q
!= NULL
) {
257 lc
.id
[i
] = ISNS_ISCSI_NAME_ATTR_ID
;
260 /* a member id or member name is required */
264 return (ISNS_RSP_INVALID_REGIS
);
266 /* remove member (isnsp msg request only) */
271 ec
= cache_lookup(&lc
, &tmp_id
, cb_clone_attrs
);
273 if (ec
== 0 && tmp_id
== 0) {
276 if (attr1
->tag
== 0 || sys_q
== NULL
) {
277 /* object does not exist, create one */
278 obj
= make_member_node(*m_id
, attr2
);
280 ec
= ISNS_RSP_INTERNAL_ERROR
;
282 ec
= register_assoc(obj
, &tmp_id
);
288 /* don't create it if uid is specified */
289 ec
= ISNS_RSP_NO_SUCH_ENTRY
;
293 ec
= ERR_NO_SUCH_ASSOCIATION
;
297 if (attr1
->tag
== 0) {
298 attr1
->tag
= ISNS_DD_ISCSI_INDEX_ATTR_ID
;
300 attr1
->value
.ui
= tmp_id
;
301 } else if (attr2
->tag
== 0) {
302 attr2
->tag
= ISNS_DD_ISCSI_NAME_ATTR_ID
;
303 attr2
->len
= strlen((char *)lc
.data
[1].ptr
);
304 attr2
->len
+= 4 - (attr2
->len
% 4);
305 attr2
->value
.ptr
= lc
.data
[1].ptr
;
326 SET_UID_LCP(&lc
, OBJ_DD
, m_id
);
328 return (ISNS_RSP_INVALID_REGIS
);
331 tmp_id
= is_obj_there(&lc
);
334 /* object does not exist, create one */
335 obj
= make_member_dd(m_id
);
337 ec
= register_object(obj
, NULL
, NULL
);
340 ec
= ISNS_RSP_INTERNAL_ERROR
;
358 uint32_t new_x
= 0, new_y
= 0;
359 matrix_t
*tmp_matrix
;
361 uint32_t i
, j
, k
= 0;
363 bmp_t
*bmp
, *tmp_bmp
;
365 uint32_t primary
= GET_PRIMARY(m_id
);
366 uint32_t second
= GET_SECOND(m_id
);
368 if (primary
>= matrix
->x
) {
370 ec
= ERR_NO_SUCH_ASSOCIATION
;
371 goto update_matrix_done
;
373 /* enlarge the matrix on x axis */
374 if (primary
>= matrix
->x
* 2) {
377 new_x
= matrix
->x
* 2;
382 while (i
< matrix
->y
) {
383 bmp
= MATRIX_X_UNIT(matrix
, i
);
384 x_info
= MATRIX_X_INFO(bmp
);
385 if (x_info
== puid
) {
387 } else if (x_info
== 0 && k
== 0) {
388 /* the first available slot */
393 if (i
== matrix
->y
) {
395 ec
= ERR_NO_SUCH_ASSOCIATION
;
396 goto update_matrix_done
;
398 new_y
= matrix
->y
* 2;
405 * enlarge the matrix.
407 if (new_x
!= 0 || new_y
!= 0) {
414 tmp_matrix
= new_matrix(new_x
, new_y
);
415 if (tmp_matrix
!= NULL
) {
417 while (j
< matrix
->y
) {
418 bmp
= MATRIX_X_UNIT(matrix
, j
);
419 x_info
= MATRIX_X_INFO(bmp
);
421 tmp_bmp
= MATRIX_X_UNIT(tmp_matrix
, j
);
422 (void) memcpy((void *)tmp_bmp
,
423 (void *)bmp
, SIZEOF_X_UNIT(matrix
));
428 matrix
->x
= tmp_matrix
->x
;
429 matrix
->y
= tmp_matrix
->y
;
430 matrix
->m
= tmp_matrix
->m
;
433 ec
= ISNS_RSP_INTERNAL_ERROR
;
434 goto update_matrix_done
;
438 bmp
= MATRIX_X_UNIT(matrix
, i
);
440 MATRIX_X_INFO(bmp
) = puid
;
442 if (TEST_MEMBERSHIP(bmp
, primary
, second
) == 0) {
443 SET_MEMBERSHIP(bmp
, primary
, second
);
446 bmp
= MATRIX_X_UNIT(matrix
, 0);
447 ASSERT(MATRIX_X_INFO(bmp
) ==
449 CLEAR_MEMBERSHIP(bmp
, primary
, second
);
452 ec
= ERR_ALREADY_ASSOCIATED
;
454 } else if (op
== '-') {
455 if (TEST_MEMBERSHIP(bmp
, primary
, second
) != 0) {
456 CLEAR_MEMBERSHIP(bmp
, primary
, second
);
460 while (i
< matrix
->y
) {
461 bmp
= MATRIX_X_UNIT(matrix
, i
);
462 x_info
= MATRIX_X_INFO(bmp
);
465 primary
, second
) != 0) {
470 if (i
== matrix
->y
) {
471 bmp
= MATRIX_X_UNIT(matrix
, 0);
472 ASSERT(MATRIX_X_INFO(bmp
) ==
474 SET_MEMBERSHIP(bmp
, primary
, second
);
478 ec
= ERR_NO_SUCH_ASSOCIATION
;
490 const uint32_t dd_id
,
491 const uint32_t m_type
,
497 ASSERT(m_type
== OBJ_ISCSI
);
499 matrix
= cache_get_matrix(OBJ_DD
);
501 return (update_matrix(matrix
, op
, dd_id
, m_id
, 1));
507 const uint32_t dds_id
,
511 matrix_t
*dds_matrix
= cache_get_matrix(OBJ_DDS
);
513 return (update_matrix(dds_matrix
, op
, dds_id
, m_id
, 0));
539 while (i
< matrix
->y
) {
540 bmp
= MATRIX_X_UNIT(matrix
, i
);
541 x_info
= MATRIX_X_INFO(bmp
);
544 /* dup it for caller */
546 *p
= (bmp_t
*)malloc(*n
* sizeof (bmp_t
));
548 (void) memcpy(*p
, &bmp
[MATRIX_X_HEADER
],
549 *n
* sizeof (bmp_t
));
551 ec
= ISNS_RSP_INTERNAL_ERROR
;
555 (void) memset(bmp
, 0, SIZEOF_X_UNIT(matrix
));
561 if (ddd_flag
!= 0 && p
!= NULL
) {
562 bmp
= MATRIX_X_UNIT(matrix
, 0);
563 ASSERT(MATRIX_X_INFO(bmp
) == ISNS_DEFAULT_DD_ID
);
564 /* Test the membership for each node which is a */
565 /* member in the dd that is being deleted. */
566 FOR_EACH_MEMBER(*p
, *n
, i
, {
569 /* put it to the default dd */
570 primary
= GET_PRIMARY(i
);
571 second
= GET_SECOND(i
);
572 SET_MEMBERSHIP(bmp
, primary
, second
);
597 while (i
< matrix
->y
) {
598 bmp
= MATRIX_X_UNIT(matrix
, i
);
599 x_info
= MATRIX_X_INFO(bmp
);
601 /* dup it for caller */
603 *p
= (bmp_t
*)malloc(*n
* sizeof (bmp_t
));
605 (void) memcpy(*p
, &bmp
[MATRIX_X_HEADER
],
606 *n
* sizeof (bmp_t
));
609 ec
= ISNS_RSP_INTERNAL_ERROR
;
621 const uint32_t dd_id
,
626 matrix_t
*matrix
= cache_get_matrix(OBJ_DD
);
628 return (clear_matrix(matrix
, dd_id
, p
, n
, 1));
633 const uint32_t dds_id
636 matrix_t
*matrix
= cache_get_matrix(OBJ_DDS
);
638 return (clear_matrix(matrix
, dds_id
, NULL
, NULL
, 0));
643 const uint32_t dd_id
,
648 matrix_t
*matrix
= cache_get_matrix(OBJ_DD
);
650 return (get_matrix(matrix
, dd_id
, p
, n
));
655 const uint32_t dds_id
,
660 matrix_t
*matrix
= cache_get_matrix(OBJ_DDS
);
662 return (get_matrix(matrix
, dds_id
, p
, n
));
672 isns_obj_t
*obj
= (isns_obj_t
*)p1
;
674 isns_attr_t
*attr
= &obj
->attrs
[
675 ATTR_INDEX_DDS(ISNS_DD_SET_STATUS_ATTR_ID
)];
677 return (DDS_ENABLED(attr
->value
.ui
) ? 1 : 0);
691 SET_UID_LCP(&lc
, OBJ_DDS
, dds_id
);
693 return (cache_lookup(&lc
, NULL
, cb_get_dds_status
));
703 matrix_t
*dds_matrix
;
714 dds_matrix
= cache_get_matrix(OBJ_DDS
);
715 primary
= GET_PRIMARY(dd_id
);
716 second
= GET_SECOND(dd_id
);
718 if (primary
< dds_matrix
->x
) {
720 while (i
< dds_matrix
->y
) {
721 bmp
= MATRIX_X_UNIT(dds_matrix
, i
);
722 x_info
= MATRIX_X_INFO(bmp
);
724 TEST_MEMBERSHIP(bmp
, primary
, second
) != 0) {
725 if (get_dds_status(x_info
) != 0) {
766 /* get the source object uid */
769 lc
.id
[0] = ATTR_INDEX_ISCSI(ISNS_ISCSI_NAME_ATTR_ID
);
770 lc
.op
[0] = OP_STRING
;
771 lc
.data
[0].ptr
= node_name
;
774 uid
= is_obj_there(&lc
);
781 dd_matrix
= cache_get_matrix(OBJ_DD
);
782 primary
= GET_PRIMARY(uid
);
783 second
= GET_SECOND(uid
);
785 if (primary
< dd_matrix
->x
) {
787 while (i
< dd_matrix
->y
) {
788 bmp
= MATRIX_X_UNIT(dd_matrix
, i
);
789 x_info
= MATRIX_X_INFO(bmp
);
790 if (ec
== 0 && x_info
!= 0 &&
791 TEST_MEMBERSHIP(bmp
, primary
, second
) != 0) {
792 if (is_dd_active(x_info
) != 0 &&
793 (ec
= get_dd_matrix(x_info
,
794 &tmp_p
, &tmp_n
)) == 0) {
809 while (j
< short_n
) {
810 (*p
)[j
] |= short_p
[j
];
822 if (ec
== 0 && *p
== NULL
) {
823 *p
= (bmp_t
*)calloc(primary
, sizeof (bmp_t
));
828 ec
= ISNS_RSP_INTERNAL_ERROR
;
833 (*p
)[primary
- 1] |= (1 << second
);
847 isns_obj_t
*obj
= (isns_obj_t
*)p1
;
848 lookup_ctrl_t
*lcp
= (lookup_ctrl_t
*)p2
;
854 while (i
< MAX_LOOKUP_CTRL
&&
860 i
< MAX_LOOKUP_CTRL
&&
862 switch (lcp
->id
[i
]) {
863 case ISNS_ISCSI_NAME_ATTR_ID
:
864 attr
= &obj
->attrs
[ATTR_INDEX_ISCSI(
865 ISNS_ISCSI_NAME_ATTR_ID
)];
866 lcp
->data
[i
].ptr
= (uchar_t
*)malloc(attr
->len
);
867 if (lcp
->data
[i
].ptr
!= NULL
) {
868 (void) strcpy((char *)lcp
->data
[i
].ptr
,
869 (char *)attr
->value
.ptr
);
871 /* memory exhausted */
872 ec
= ISNS_RSP_INTERNAL_ERROR
;
875 case ISNS_ISCSI_NODE_TYPE_ATTR_ID
:
876 attr
= &obj
->attrs
[ATTR_INDEX_ISCSI(
877 ISNS_ISCSI_NODE_TYPE_ATTR_ID
)];
878 lcp
->data
[i
].ui
= attr
->value
.ui
;
880 case ISNS_PG_ISCSI_NAME_ATTR_ID
:
881 attr
= &obj
->attrs
[ATTR_INDEX_PG(
882 ISNS_PG_ISCSI_NAME_ATTR_ID
)];
883 lcp
->data
[i
].ptr
= (uchar_t
*)malloc(attr
->len
);
884 if (lcp
->data
[i
].ptr
!= NULL
) {
885 (void) strcpy((char *)lcp
->data
[i
].ptr
,
886 (char *)attr
->value
.ptr
);
888 /* memory exhausted */
889 ec
= ISNS_RSP_INTERNAL_ERROR
;
892 case ISNS_PG_PORTAL_IP_ADDR_ATTR_ID
:
893 attr
= &obj
->attrs
[ATTR_INDEX_PG(
894 ISNS_PG_PORTAL_IP_ADDR_ATTR_ID
)];
895 lcp
->data
[i
].ip
= (in6_addr_t
*)malloc(attr
->len
);
896 if (lcp
->data
[i
].ip
!= NULL
) {
897 (void) memcpy(lcp
->data
[i
].ip
,
898 attr
->value
.ip
, attr
->len
);
900 /* memory exhausted */
901 ec
= ISNS_RSP_INTERNAL_ERROR
;
904 case ISNS_PG_PORTAL_PORT_ATTR_ID
:
905 attr
= &obj
->attrs
[ATTR_INDEX_PG(
906 ISNS_PG_PORTAL_PORT_ATTR_ID
)];
907 lcp
->data
[i
].ui
= attr
->value
.ui
;
909 case ISNS_PORTAL_IP_ADDR_ATTR_ID
:
910 attr
= &obj
->attrs
[ATTR_INDEX_PORTAL(
911 ISNS_PORTAL_IP_ADDR_ATTR_ID
)];
912 lcp
->data
[i
].ip
= (in6_addr_t
*)malloc(attr
->len
);
913 if (lcp
->data
[i
].ip
!= NULL
) {
914 (void) memcpy(lcp
->data
[i
].ip
,
915 attr
->value
.ip
, attr
->len
);
917 /* memory exhausted */
918 ec
= ISNS_RSP_INTERNAL_ERROR
;
921 case ISNS_PORTAL_PORT_ATTR_ID
:
922 case ISNS_ESI_PORT_ATTR_ID
:
923 attr
= &obj
->attrs
[ATTR_INDEX_PORTAL(lcp
->id
[i
])];
924 if (attr
->tag
!= 0 && attr
->value
.ui
!= 0) {
925 lcp
->data
[i
].ui
= attr
->value
.ui
;
949 matrix
= (matrix_t
*)malloc(sizeof (matrix_t
));
950 if (matrix
!= NULL
) {
953 matrix
->m
= (bmp_t
*)calloc(y
, SIZEOF_X_UNIT(matrix
));
954 if (matrix
->m
== NULL
) {
974 * allocate an array of pointer for dd and dd-set matrix.
976 c
->x
= (matrix_t
**)calloc(2, sizeof (matrix_t
*));
984 x
= new_matrix(8, 64);
993 * Mark the first array on the y axis for Default DD.
995 bmp
= MATRIX_X_UNIT(x
, 0);
996 MATRIX_X_INFO(bmp
) = ISNS_DEFAULT_DD_ID
;
999 * create dd set matrix.
1001 x
= new_matrix(2, 16);
1010 * Mark the first array on the y axis for Default DD-set.
1012 bmp
= MATRIX_X_UNIT(x
, 0);
1013 MATRIX_X_INFO(bmp
) = ISNS_DEFAULT_DD_SET_ID
;
1016 * Add Default DD as a member of Default DD-set.
1018 primary
= GET_PRIMARY(ISNS_DEFAULT_DD_ID
);
1019 second
= GET_SECOND(ISNS_DEFAULT_DD_ID
);
1020 SET_MEMBERSHIP(bmp
, primary
, second
);
1033 uint32_t primary
= GET_PRIMARY(m_id
);
1034 uint32_t second
= GET_SECOND(m_id
);
1039 if (matrix
->x
> primary
) {
1040 while (i
< matrix
->y
) {
1041 bmp
= MATRIX_X_UNIT(matrix
, i
);
1042 uid
= MATRIX_X_INFO(bmp
);
1043 if (uid
> curr_id
&&
1044 TEST_MEMBERSHIP(bmp
, primary
, second
) != 0) {
1045 if (dd_id
== 0 || uid
< dd_id
) {
1066 uint32_t primary1
= GET_PRIMARY(m_id1
);
1067 uint32_t second1
= GET_SECOND(m_id1
);
1068 uint32_t primary2
= GET_PRIMARY(m_id2
);
1069 uint32_t second2
= GET_SECOND(m_id2
);
1073 matrix
= cache_get_matrix(OBJ_DD
);
1075 if (matrix
->x
> primary1
&& matrix
->x
> primary2
) {
1076 while (i
< matrix
->y
) {
1077 bmp
= MATRIX_X_UNIT(matrix
, i
);
1078 if (MATRIX_X_INFO(bmp
) > curr_id
&&
1079 TEST_MEMBERSHIP(bmp
, primary1
, second1
) != 0 &&
1080 TEST_MEMBERSHIP(bmp
, primary2
, second2
) != 0) {
1081 dd_id
= MATRIX_X_INFO(bmp
);
1097 matrix_t
*matrix
= cache_get_matrix(OBJ_DD
);
1099 return (get_ds_id(matrix
, m_id
, curr_id
));
1108 matrix_t
*matrix
= cache_get_matrix(OBJ_DDS
);
1110 return (get_ds_id(matrix
, m_id
, curr_id
));
1117 isns_attr_t
*name_attr
,
1118 isns_attr_t
*uid_attr
,
1119 isns_attr_t
*status_attr
1127 if (type
== OBJ_DD
) {
1128 id1
= ATTR_INDEX_DD(ISNS_DD_NAME_ATTR_ID
);
1129 id2
= ATTR_INDEX_DD(ISNS_DD_ID_ATTR_ID
);
1130 id3
= ATTR_INDEX_DD(ISNS_DD_FEATURES_ATTR_ID
);
1132 ASSERT(type
== OBJ_DDS
);
1133 id1
= ATTR_INDEX_DDS(ISNS_DD_SET_NAME_ATTR_ID
);
1134 id2
= ATTR_INDEX_DDS(ISNS_DD_SET_ID_ATTR_ID
);
1135 id3
= ATTR_INDEX_DDS(ISNS_DD_SET_STATUS_ATTR_ID
);
1138 obj
= obj_calloc(type
);
1140 (name_attr
!= NULL
&& name_attr
->tag
!= 0 &&
1141 assign_attr(&obj
->attrs
[id1
], name_attr
) == 0) &&
1142 (uid_attr
== NULL
|| uid_attr
->value
.ui
== 0 ||
1143 assign_attr(&obj
->attrs
[id2
], uid_attr
) == 0) &&
1144 (status_attr
== NULL
|| status_attr
->value
.ui
== 0 ||
1145 assign_attr(&obj
->attrs
[id3
], status_attr
) == 0)) {
1150 ec
= ISNS_RSP_INTERNAL_ERROR
;
1165 isns_attr_t name
= { 0 };
1166 isns_attr_t dd_id
= { 0 }, features
= { 0 };
1168 name
.tag
= ISNS_DD_NAME_ATTR_ID
;
1170 while (op_len
> 8 && ec
== 0) {
1171 value
= &op
->attr_value
[0];
1172 switch (op
->attr_id
) {
1173 case ISNS_DD_ID_ATTR_ID
:
1174 if (op
->attr_len
== 4) {
1175 dd_id
.tag
= ISNS_DD_ID_ATTR_ID
;
1177 dd_id
.value
.ui
= ntohl(*(uint32_t *)value
);
1178 } else if (op
->attr_len
!= 0) {
1179 ec
= ISNS_RSP_MSG_FORMAT_ERROR
;
1182 case ISNS_DD_NAME_ATTR_ID
:
1183 if (op
->attr_len
> 0 &&
1184 op
->attr_len
<= 256) {
1185 name
.len
= op
->attr_len
;
1186 name
.value
.ptr
= (uchar_t
*)value
;
1187 } else if (op
->attr_len
!= 0) {
1188 ec
= ISNS_RSP_MSG_FORMAT_ERROR
;
1191 case ISNS_DD_ISCSI_INDEX_ATTR_ID
:
1192 case ISNS_DD_ISCSI_NAME_ATTR_ID
:
1194 case ISNS_DD_FC_PORT_NAME_ATTR_ID
:
1195 case ISNS_DD_PORTAL_INDEX_ATTR_ID
:
1196 case ISNS_DD_PORTAL_IP_ADDR_ATTR_ID
:
1197 case ISNS_DD_PORTAL_PORT_ATTR_ID
:
1198 ec
= ISNS_RSP_REGIS_NOT_SUPPORTED
;
1200 case ISNS_DD_FEATURES_ATTR_ID
:
1201 if (op
->attr_len
== 4) {
1202 features
.tag
= ISNS_DD_FEATURES_ATTR_ID
;
1203 features
.len
= op
->attr_len
;
1204 features
.value
.ui
= ntohl(*(uint32_t *)value
);
1205 } else if (op
->attr_len
!= 0) {
1206 ec
= ISNS_RSP_MSG_FORMAT_ERROR
;
1210 ec
= ISNS_RSP_INVALID_REGIS
;
1213 NEXT_TLV(op
, op_len
);
1217 ec
= create_ds_object(OBJ_DD
, dd_p
,
1218 &name
, &dd_id
, &features
);
1233 isns_attr_t name
= { 0 };
1234 isns_attr_t dds_id
= { 0 }, code
= { 0 };
1236 name
.tag
= ISNS_DD_SET_NAME_ATTR_ID
;
1238 while (op_len
> 8 && ec
== 0) {
1239 value
= &op
->attr_value
[0];
1240 switch (op
->attr_id
) {
1241 case ISNS_DD_SET_ID_ATTR_ID
:
1242 if (op
->attr_len
== 4) {
1243 dds_id
.tag
= ISNS_DD_ID_ATTR_ID
;
1245 dds_id
.value
.ui
= ntohl(*(uint32_t *)value
);
1246 } else if (op
->attr_len
!= 0) {
1247 ec
= ISNS_RSP_MSG_FORMAT_ERROR
;
1250 case ISNS_DD_SET_NAME_ATTR_ID
:
1251 if (op
->attr_len
> 0 &&
1252 op
->attr_len
<= 256) {
1253 name
.len
= op
->attr_len
;
1254 name
.value
.ptr
= (uchar_t
*)value
;
1255 } else if (op
->attr_len
!= 0) {
1256 ec
= ISNS_RSP_MSG_FORMAT_ERROR
;
1259 case ISNS_DD_SET_STATUS_ATTR_ID
:
1260 if (op
->attr_len
== 4) {
1261 code
.tag
= ISNS_DD_SET_STATUS_ATTR_ID
;
1262 code
.len
= op
->attr_len
;
1263 code
.value
.ui
= ntohl(*(uint32_t *)value
);
1264 } else if (op
->attr_len
!= 0) {
1265 ec
= ISNS_RSP_MSG_FORMAT_ERROR
;
1268 case ISNS_DD_ID_ATTR_ID
:
1271 ec
= ISNS_RSP_INVALID_REGIS
;
1274 NEXT_TLV(op
, op_len
);
1278 ec
= create_ds_object(OBJ_DDS
, dds_p
,
1279 &name
, &dds_id
, &code
);
1294 isns_attr_t name_attr
= { 0 };
1295 isns_attr_t uid_attr
= { 0 };
1296 isns_attr_t features_attr
= { 0 };
1298 name_attr
.tag
= ISNS_DD_NAME_ATTR_ID
;
1300 /* need to include the null terminator */
1301 /* and be on 4 bytes aligned */
1302 len
= strlen((char *)name
) + 1;
1303 len
+= 4 - (len
% 4);
1304 name_attr
.len
= len
;
1305 name_attr
.value
.ptr
= name
;
1308 uid_attr
.tag
= ISNS_DD_ID_ATTR_ID
;
1310 uid_attr
.value
.ui
= uid
;
1312 features_attr
.tag
= ISNS_DD_FEATURES_ATTR_ID
;
1313 features_attr
.len
= 4;
1314 features_attr
.value
.ui
= features
;
1316 return (create_ds_object(OBJ_DD
, dd_p
,
1317 &name_attr
, &uid_attr
, &features_attr
));
1329 isns_attr_t name_attr
= { 0 };
1330 isns_attr_t uid_attr
= { 0 };
1331 isns_attr_t code_attr
= { 0 };
1333 name_attr
.tag
= ISNS_DD_SET_NAME_ATTR_ID
;
1335 /* need to include the null terminator */
1336 /* and be on 4 bytes aligned */
1337 len
= strlen((char *)name
) + 1;
1338 len
+= 4 - (len
% 4);
1339 name_attr
.len
= len
;
1340 name_attr
.value
.ptr
= name
;
1343 uid_attr
.tag
= ISNS_DD_SET_ID_ATTR_ID
;
1345 uid_attr
.value
.ui
= uid
;
1347 code_attr
.tag
= ISNS_DD_SET_STATUS_ATTR_ID
;
1349 code_attr
.value
.ui
= code
;
1351 return (create_ds_object(OBJ_DDS
, dds_p
,
1352 &name_attr
, &uid_attr
, &code_attr
));
1368 SET_UID_LCP(&lc
, type
, uid
);
1371 lc
.data
[1].ui
= len
;
1372 lc
.data
[2].ptr
= name
;
1374 ec
= cache_rekey(&lc
, &uid
, cb_update_ds_attr
);
1376 ec
= ISNS_RSP_INVALID_REGIS
;
1390 * We do now allow changing the default DD and DD-set name.
1392 if (uid
== ISNS_DEFAULT_DD_ID
) {
1393 return (ISNS_RSP_OPTION_NOT_UNDERSTOOD
);
1396 return (update_ds_name(OBJ_DD
, uid
, ISNS_DD_NAME_ATTR_ID
, len
, name
));
1407 * We do now allow changing the default DD and DD-set name.
1409 if (uid
== ISNS_DEFAULT_DD_ID
) {
1410 return (ISNS_RSP_OPTION_NOT_UNDERSTOOD
);
1413 return (update_ds_name(OBJ_DDS
, uid
,
1414 ISNS_DD_SET_NAME_ATTR_ID
, len
, name
));
1429 SET_UID_LCP(&lc
, type
, uid
);
1432 lc
.data
[1].ui
= value
;
1434 ec
= cache_lookup(&lc
, &uid
, cb_update_ds_attr
);
1436 ec
= ISNS_RSP_INVALID_REGIS
;
1448 return (update_ds_uint32(OBJ_DD
, uid
,
1449 ISNS_DD_FEATURES_ATTR_ID
, features
));
1458 return (update_ds_uint32(OBJ_DDS
, uid
,
1459 ISNS_DD_SET_STATUS_ATTR_ID
, enabled
));
1470 uint32_t m_id
, m_type
;
1472 dd_id
= get_parent_uid(assoc
);
1474 * We do now allow placing any node to the default DD explicitly.
1476 if (dd_id
== ISNS_DEFAULT_DD_ID
) {
1477 return (ISNS_RSP_OPTION_NOT_UNDERSTOOD
);
1480 ec
= get_member_info(assoc
, &m_type
, &m_id
, 1);
1482 ec
= update_dd_matrix(
1483 '+', /* add member */
1490 if (sys_q
!= NULL
) {
1491 /* add the membership to data store */
1492 ec
= write_data(DATA_ADD
, assoc
);
1495 /* trigger a management scn */
1496 if (ec
== 0 && scn_q
!= NULL
) {
1497 (void) make_scn(ISNS_MEMBER_ADDED
, assoc
);
1511 uint32_t m_id
= assoc
->attrs
[ATTR_INDEX_ASSOC_DD(
1512 ISNS_DD_ID_ATTR_ID
)].value
.ui
;
1515 dds_id
= get_parent_uid(assoc
);
1517 * We do now allow changing the membership of the default DD
1520 if (dds_id
== ISNS_DEFAULT_DD_SET_ID
||
1521 m_id
== ISNS_DEFAULT_DD_ID
) {
1522 return (ISNS_RSP_OPTION_NOT_UNDERSTOOD
);
1525 ec
= get_dds_member_info(m_id
);
1527 ec
= update_dds_matrix(
1528 '+', /* add member */
1534 if (sys_q
!= NULL
) {
1535 /* add the membership to data store */
1536 ec
= write_data(DATA_ADD
, assoc
);
1539 /* trigger a management scn */
1540 if (ec
== 0 && scn_q
!= NULL
) {
1541 (void) make_scn(ISNS_MEMBER_ADDED
, assoc
);
1561 dd_id
= get_parent_uid(assoc
);
1563 * We do now allow removing the member from default DD explicitly.
1565 if (dd_id
== ISNS_DEFAULT_DD_ID
) {
1566 return (ISNS_RSP_OPTION_NOT_UNDERSTOOD
);
1569 ec
= get_member_info(assoc
, &m_type
, &m_id
, 0);
1571 ec
= update_dd_matrix(
1572 '-', /* remove member */
1577 /* update data store */
1578 if (sys_q
!= NULL
) {
1579 /* remove it from data store */
1581 DATA_DELETE_ASSOC
, assoc
);
1584 /* trigger a management scn */
1585 if (ec
== 0 && scn_q
!= NULL
) {
1586 (void) make_scn(ISNS_MEMBER_REMOVED
, assoc
);
1589 /* remove it from object container if */
1590 /* it is not a registered object */
1592 SET_UID_LCP(&lc
, m_type
, m_id
);
1593 ec
= dereg_assoc(&lc
);
1612 * We do now allow removing the member from default DD-set.
1614 if (dds_id
== ISNS_DEFAULT_DD_SET_ID
) {
1615 return (ISNS_RSP_OPTION_NOT_UNDERSTOOD
);
1619 ec
= update_dds_matrix(
1620 '-', /* remove member */
1624 clone
= obj_calloc(OBJ_ASSOC_DD
);
1625 if (clone
!= NULL
) {
1626 (void) set_obj_uid((void *)clone
, m_id
);
1627 (void) set_parent_obj(clone
, dds_id
);
1629 /* update data store */
1630 if (sys_q
!= NULL
) {
1631 if (clone
!= NULL
) {
1632 /* remove it from data store */
1634 DATA_DELETE_ASSOC
, clone
);
1636 ec
= ISNS_RSP_INTERNAL_ERROR
;
1640 /* trigger a management scn */
1644 (void) make_scn(ISNS_MEMBER_REMOVED
, clone
);
1654 remove_member_wildchar(
1665 uint32_t primary
= GET_PRIMARY(m_id
);
1666 uint32_t second
= GET_SECOND(m_id
);
1670 if (primary
>= matrix
->x
) {
1675 while (ec
== 0 && i
< matrix
->y
) {
1676 bmp
= MATRIX_X_UNIT(matrix
, i
);
1677 x_info
= MATRIX_X_INFO(bmp
);
1679 TEST_MEMBERSHIP(bmp
, primary
, second
) != 0) {
1680 /* clean the membership */
1681 CLEAR_MEMBERSHIP(bmp
, primary
, second
);
1682 /* update data store */
1683 if (sys_q
!= NULL
) {
1684 clone
= obj_calloc(OBJ_ASSOC_DD
);
1685 if (clone
!= NULL
) {
1686 (void) set_obj_uid((void *)clone
, m_id
);
1687 (void) set_parent_obj(clone
, x_info
);
1688 /* remove it from data store */
1690 DATA_DELETE_ASSOC
, clone
);
1693 ec
= ISNS_RSP_INTERNAL_ERROR
;
1708 matrix_t
*dds_matrix
;
1718 * We do now allow removing the default DD.
1720 if (dd_id
== ISNS_DEFAULT_DD_ID
) {
1721 return (ISNS_RSP_OPTION_NOT_UNDERSTOOD
);
1724 SET_UID_LCP(&lc
, OBJ_DD
, dd_id
);
1726 /* de-register the object at first */
1727 ec
= dereg_object(&lc
, 0);
1729 /* clear it from all of dd-set */
1730 dds_matrix
= cache_get_matrix(OBJ_DDS
);
1731 (void) remove_member_wildchar(dds_matrix
, dd_id
);
1733 /* clear its member bitmap */
1734 (void) clear_dd_matrix(dd_id
, &p
, &n
);
1736 /* deregister the member nodes which are not-registered node */
1737 /* and have no longer membership in other DD(s). */
1739 SET_UID_LCP(&lc
, OBJ_ISCSI
, 0);
1740 FOR_EACH_MEMBER(p
, n
, uid
, {
1741 lc
.data
[0].ui
= uid
;
1742 (void) dereg_assoc(&lc
);
1760 * We do now allow removing the default DD-set.
1762 if (dds_id
== ISNS_DEFAULT_DD_SET_ID
) {
1763 return (ISNS_RSP_OPTION_NOT_UNDERSTOOD
);
1766 (void) clear_dds_matrix(dds_id
);
1768 SET_UID_LCP(&lc
, OBJ_DDS
, dds_id
);
1770 ec
= dereg_object(&lc
, 0);
1786 obj
= (isns_obj_t
*)p
;
1787 if (obj
->type
!= OBJ_ISCSI
) {
1791 matrix
= cache_get_matrix(OBJ_DD
);
1792 uid
= get_obj_uid(obj
);
1794 return (update_matrix(matrix
, op
, ISNS_DEFAULT_DD_ID
, uid
, 0));
1811 /* Ensure the Default DD is registered. */
1812 uid
= ISNS_DEFAULT_DD_ID
;
1814 SET_UID_LCP(&lc
, OBJ_DD
, uid
);
1816 (void) cache_lock_write();
1818 if (is_obj_there(&lc
) == 0) {
1819 name
= (uchar_t
*)DEFAULT_DD_NAME
;
1820 features
= DEFAULT_DD_FEATURES
;
1821 ec
= adm_create_dd(&obj
, name
, uid
, features
);
1823 ec
= register_object(obj
, NULL
, NULL
);
1833 /* Ensure the Default DD-set is registered. */
1834 uid
= ISNS_DEFAULT_DD_SET_ID
;
1836 SET_UID_LCP(&lc
, OBJ_DDS
, uid
);
1838 if (is_obj_there(&lc
) == 0) {
1839 name
= (uchar_t
*)DEFAULT_DD_SET_NAME
;
1840 code
= DEFAULT_DD_SET_STATUS
;
1841 ec
= adm_create_dds(&obj
, name
, uid
, code
);
1843 ec
= register_object(obj
, NULL
, NULL
);
1852 ec
= cache_unlock_sync(ec
);