1*7836SJohn.Forte@Sun.COM /*
2*7836SJohn.Forte@Sun.COM * CDDL HEADER START
3*7836SJohn.Forte@Sun.COM *
4*7836SJohn.Forte@Sun.COM * The contents of this file are subject to the terms of the
5*7836SJohn.Forte@Sun.COM * Common Development and Distribution License (the "License").
6*7836SJohn.Forte@Sun.COM * You may not use this file except in compliance with the License.
7*7836SJohn.Forte@Sun.COM *
8*7836SJohn.Forte@Sun.COM * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9*7836SJohn.Forte@Sun.COM * or http://www.opensolaris.org/os/licensing.
10*7836SJohn.Forte@Sun.COM * See the License for the specific language governing permissions
11*7836SJohn.Forte@Sun.COM * and limitations under the License.
12*7836SJohn.Forte@Sun.COM *
13*7836SJohn.Forte@Sun.COM * When distributing Covered Code, include this CDDL HEADER in each
14*7836SJohn.Forte@Sun.COM * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15*7836SJohn.Forte@Sun.COM * If applicable, add the following below this CDDL HEADER, with the
16*7836SJohn.Forte@Sun.COM * fields enclosed by brackets "[]" replaced with your own identifying
17*7836SJohn.Forte@Sun.COM * information: Portions Copyright [yyyy] [name of copyright owner]
18*7836SJohn.Forte@Sun.COM *
19*7836SJohn.Forte@Sun.COM * CDDL HEADER END
20*7836SJohn.Forte@Sun.COM */
21*7836SJohn.Forte@Sun.COM
22*7836SJohn.Forte@Sun.COM /*
23*7836SJohn.Forte@Sun.COM * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
24*7836SJohn.Forte@Sun.COM * Use is subject to license terms.
25*7836SJohn.Forte@Sun.COM */
26*7836SJohn.Forte@Sun.COM
27*7836SJohn.Forte@Sun.COM #include <stdio.h>
28*7836SJohn.Forte@Sun.COM #include <stdlib.h>
29*7836SJohn.Forte@Sun.COM
30*7836SJohn.Forte@Sun.COM #include "isns_server.h"
31*7836SJohn.Forte@Sun.COM #include "isns_cache.h"
32*7836SJohn.Forte@Sun.COM #include "isns_obj.h"
33*7836SJohn.Forte@Sun.COM #include "isns_dsapi.h"
34*7836SJohn.Forte@Sun.COM #include "isns_dseng.h"
35*7836SJohn.Forte@Sun.COM #include "isns_msgq.h"
36*7836SJohn.Forte@Sun.COM #include "isns_log.h"
37*7836SJohn.Forte@Sun.COM #include "isns_scn.h"
38*7836SJohn.Forte@Sun.COM #include "isns_esi.h"
39*7836SJohn.Forte@Sun.COM
40*7836SJohn.Forte@Sun.COM /*
41*7836SJohn.Forte@Sun.COM * extern variables
42*7836SJohn.Forte@Sun.COM */
43*7836SJohn.Forte@Sun.COM extern const int NUM_OF_CHILD[MAX_OBJ_TYPE];
44*7836SJohn.Forte@Sun.COM extern const int TYPE_OF_PARENT[MAX_OBJ_TYPE_FOR_SIZE];
45*7836SJohn.Forte@Sun.COM
46*7836SJohn.Forte@Sun.COM int
init_data()47*7836SJohn.Forte@Sun.COM init_data(
48*7836SJohn.Forte@Sun.COM )
49*7836SJohn.Forte@Sun.COM {
50*7836SJohn.Forte@Sun.COM return (target_init_data());
51*7836SJohn.Forte@Sun.COM }
52*7836SJohn.Forte@Sun.COM
53*7836SJohn.Forte@Sun.COM int
load_data()54*7836SJohn.Forte@Sun.COM load_data(
55*7836SJohn.Forte@Sun.COM )
56*7836SJohn.Forte@Sun.COM {
57*7836SJohn.Forte@Sun.COM int ec = 0;
58*7836SJohn.Forte@Sun.COM void *prev = NULL;
59*7836SJohn.Forte@Sun.COM isns_obj_t *obj;
60*7836SJohn.Forte@Sun.COM uint32_t uid = 0, type = 0;
61*7836SJohn.Forte@Sun.COM uint32_t puid = 0;
62*7836SJohn.Forte@Sun.COM isns_type_t ptype = 0;
63*7836SJohn.Forte@Sun.COM void const **child[MAX_CHILD_TYPE] = { NULL };
64*7836SJohn.Forte@Sun.COM uchar_t phase;
65*7836SJohn.Forte@Sun.COM
66*7836SJohn.Forte@Sun.COM isns_attr_t *scn_bitmap;
67*7836SJohn.Forte@Sun.COM isns_attr_t *scn_name;
68*7836SJohn.Forte@Sun.COM
69*7836SJohn.Forte@Sun.COM isns_attr_t *eid_attr;
70*7836SJohn.Forte@Sun.COM
71*7836SJohn.Forte@Sun.COM /* lock the cache */
72*7836SJohn.Forte@Sun.COM (void) cache_lock_write();
73*7836SJohn.Forte@Sun.COM
74*7836SJohn.Forte@Sun.COM ec = target_load_obj(&prev, &obj, &phase);
75*7836SJohn.Forte@Sun.COM while (ec == 0 && obj != NULL) {
76*7836SJohn.Forte@Sun.COM scn_bitmap = NULL;
77*7836SJohn.Forte@Sun.COM switch (obj->type) {
78*7836SJohn.Forte@Sun.COM case OBJ_DD:
79*7836SJohn.Forte@Sun.COM case OBJ_DDS:
80*7836SJohn.Forte@Sun.COM ptype = obj->type;
81*7836SJohn.Forte@Sun.COM ec = register_object(obj, &puid, NULL);
82*7836SJohn.Forte@Sun.COM break;
83*7836SJohn.Forte@Sun.COM case OBJ_ENTITY:
84*7836SJohn.Forte@Sun.COM ptype = OBJ_ENTITY;
85*7836SJohn.Forte@Sun.COM ec = register_object(obj, &puid, NULL);
86*7836SJohn.Forte@Sun.COM if (ec == 0) {
87*7836SJohn.Forte@Sun.COM eid_attr = &obj->attrs[
88*7836SJohn.Forte@Sun.COM ATTR_INDEX_ENTITY(ISNS_EID_ATTR_ID)];
89*7836SJohn.Forte@Sun.COM ec = esi_load(puid,
90*7836SJohn.Forte@Sun.COM eid_attr->value.ptr,
91*7836SJohn.Forte@Sun.COM eid_attr->len);
92*7836SJohn.Forte@Sun.COM }
93*7836SJohn.Forte@Sun.COM break;
94*7836SJohn.Forte@Sun.COM case OBJ_ISCSI:
95*7836SJohn.Forte@Sun.COM scn_bitmap = &obj->attrs[ATTR_INDEX_ISCSI(
96*7836SJohn.Forte@Sun.COM ISNS_ISCSI_SCN_BITMAP_ATTR_ID)];
97*7836SJohn.Forte@Sun.COM scn_name = &obj->attrs[ATTR_INDEX_ISCSI(
98*7836SJohn.Forte@Sun.COM ISNS_ISCSI_NAME_ATTR_ID)];
99*7836SJohn.Forte@Sun.COM case OBJ_PORTAL:
100*7836SJohn.Forte@Sun.COM if (puid != 0 &&
101*7836SJohn.Forte@Sun.COM TYPE_OF_PARENT[obj->type] == ptype) {
102*7836SJohn.Forte@Sun.COM (void) set_parent_obj(obj, puid);
103*7836SJohn.Forte@Sun.COM type = obj->type;
104*7836SJohn.Forte@Sun.COM ec = register_object(obj, &uid, NULL);
105*7836SJohn.Forte@Sun.COM } else {
106*7836SJohn.Forte@Sun.COM ec = ISNS_RSP_INTERNAL_ERROR;
107*7836SJohn.Forte@Sun.COM }
108*7836SJohn.Forte@Sun.COM if (ec == 0) {
109*7836SJohn.Forte@Sun.COM ec = buff_child_obj(ptype, type,
110*7836SJohn.Forte@Sun.COM (void *)uid, child);
111*7836SJohn.Forte@Sun.COM }
112*7836SJohn.Forte@Sun.COM if (ec == 0 && scn_bitmap != NULL) {
113*7836SJohn.Forte@Sun.COM /* register scn */
114*7836SJohn.Forte@Sun.COM ec = scn_list_load(
115*7836SJohn.Forte@Sun.COM uid,
116*7836SJohn.Forte@Sun.COM scn_name->value.ptr,
117*7836SJohn.Forte@Sun.COM scn_name->len,
118*7836SJohn.Forte@Sun.COM scn_bitmap->value.ui);
119*7836SJohn.Forte@Sun.COM }
120*7836SJohn.Forte@Sun.COM break;
121*7836SJohn.Forte@Sun.COM case OBJ_PG:
122*7836SJohn.Forte@Sun.COM if (puid != 0 &&
123*7836SJohn.Forte@Sun.COM TYPE_OF_PARENT[OBJ_PG] == ptype) {
124*7836SJohn.Forte@Sun.COM (void) set_parent_obj(obj, puid);
125*7836SJohn.Forte@Sun.COM ec = register_object(obj, NULL, NULL);
126*7836SJohn.Forte@Sun.COM } else {
127*7836SJohn.Forte@Sun.COM ec = ISNS_RSP_INTERNAL_ERROR;
128*7836SJohn.Forte@Sun.COM }
129*7836SJohn.Forte@Sun.COM break;
130*7836SJohn.Forte@Sun.COM case OBJ_ASSOC_ISCSI:
131*7836SJohn.Forte@Sun.COM if (puid != 0 &&
132*7836SJohn.Forte@Sun.COM TYPE_OF_PARENT[OBJ_ASSOC_ISCSI] == ptype) {
133*7836SJohn.Forte@Sun.COM /* ignore adding member to default dd */
134*7836SJohn.Forte@Sun.COM /* during loading objects from data store */
135*7836SJohn.Forte@Sun.COM if (puid != ISNS_DEFAULT_DD_ID) {
136*7836SJohn.Forte@Sun.COM (void) set_parent_obj(obj, puid);
137*7836SJohn.Forte@Sun.COM ec = add_dd_member(obj);
138*7836SJohn.Forte@Sun.COM }
139*7836SJohn.Forte@Sun.COM } else {
140*7836SJohn.Forte@Sun.COM ec = ISNS_RSP_INTERNAL_ERROR;
141*7836SJohn.Forte@Sun.COM }
142*7836SJohn.Forte@Sun.COM free_object(obj);
143*7836SJohn.Forte@Sun.COM break;
144*7836SJohn.Forte@Sun.COM case OBJ_ASSOC_DD:
145*7836SJohn.Forte@Sun.COM if (puid != 0 &&
146*7836SJohn.Forte@Sun.COM TYPE_OF_PARENT[OBJ_ASSOC_DD] == ptype) {
147*7836SJohn.Forte@Sun.COM /* ignore adding member to default dd-set */
148*7836SJohn.Forte@Sun.COM /* and adding default dd to any dd-set */
149*7836SJohn.Forte@Sun.COM /* during loading objects from data store */
150*7836SJohn.Forte@Sun.COM if (puid != ISNS_DEFAULT_DD_SET_ID &&
151*7836SJohn.Forte@Sun.COM get_obj_uid(obj) != ISNS_DEFAULT_DD_ID) {
152*7836SJohn.Forte@Sun.COM (void) set_parent_obj(obj, puid);
153*7836SJohn.Forte@Sun.COM ec = add_dds_member(obj);
154*7836SJohn.Forte@Sun.COM }
155*7836SJohn.Forte@Sun.COM } else {
156*7836SJohn.Forte@Sun.COM ec = ISNS_RSP_INTERNAL_ERROR;
157*7836SJohn.Forte@Sun.COM }
158*7836SJohn.Forte@Sun.COM free_object(obj);
159*7836SJohn.Forte@Sun.COM break;
160*7836SJohn.Forte@Sun.COM default:
161*7836SJohn.Forte@Sun.COM ASSERT(0);
162*7836SJohn.Forte@Sun.COM ec = ISNS_RSP_INTERNAL_ERROR;
163*7836SJohn.Forte@Sun.COM break;
164*7836SJohn.Forte@Sun.COM }
165*7836SJohn.Forte@Sun.COM if (ec == 0) {
166*7836SJohn.Forte@Sun.COM ec = target_load_obj(&prev, &obj, &phase);
167*7836SJohn.Forte@Sun.COM }
168*7836SJohn.Forte@Sun.COM if (ec == 0 &&
169*7836SJohn.Forte@Sun.COM puid != 0 &&
170*7836SJohn.Forte@Sun.COM NUM_OF_CHILD[ptype] > 0 &&
171*7836SJohn.Forte@Sun.COM (obj == NULL ||
172*7836SJohn.Forte@Sun.COM TYPE_OF_PARENT[obj->type] != ptype)) {
173*7836SJohn.Forte@Sun.COM ec = update_child_obj(ptype, puid, child, 0);
174*7836SJohn.Forte@Sun.COM }
175*7836SJohn.Forte@Sun.COM }
176*7836SJohn.Forte@Sun.COM
177*7836SJohn.Forte@Sun.COM /* unlock the cache */
178*7836SJohn.Forte@Sun.COM (void) cache_unlock_sync(0);
179*7836SJohn.Forte@Sun.COM
180*7836SJohn.Forte@Sun.COM /* free the child buffer */
181*7836SJohn.Forte@Sun.COM uid = 0;
182*7836SJohn.Forte@Sun.COM while (uid < MAX_CHILD_TYPE) {
183*7836SJohn.Forte@Sun.COM if (child[uid] != NULL) {
184*7836SJohn.Forte@Sun.COM free(child[uid]);
185*7836SJohn.Forte@Sun.COM }
186*7836SJohn.Forte@Sun.COM uid ++;
187*7836SJohn.Forte@Sun.COM }
188*7836SJohn.Forte@Sun.COM
189*7836SJohn.Forte@Sun.COM return (ec);
190*7836SJohn.Forte@Sun.COM }
191*7836SJohn.Forte@Sun.COM
192*7836SJohn.Forte@Sun.COM int
write_data(int op,const isns_obj_t * obj)193*7836SJohn.Forte@Sun.COM write_data(
194*7836SJohn.Forte@Sun.COM int op,
195*7836SJohn.Forte@Sun.COM const isns_obj_t *obj
196*7836SJohn.Forte@Sun.COM )
197*7836SJohn.Forte@Sun.COM {
198*7836SJohn.Forte@Sun.COM int ec = 0;
199*7836SJohn.Forte@Sun.COM
200*7836SJohn.Forte@Sun.COM switch (op) {
201*7836SJohn.Forte@Sun.COM case DATA_ADD:
202*7836SJohn.Forte@Sun.COM ec = target_add_obj(obj);
203*7836SJohn.Forte@Sun.COM break;
204*7836SJohn.Forte@Sun.COM case DATA_UPDATE:
205*7836SJohn.Forte@Sun.COM ec = target_modify_obj(obj);
206*7836SJohn.Forte@Sun.COM break;
207*7836SJohn.Forte@Sun.COM case DATA_DELETE:
208*7836SJohn.Forte@Sun.COM ec = target_delete_obj(obj);
209*7836SJohn.Forte@Sun.COM break;
210*7836SJohn.Forte@Sun.COM case DATA_DELETE_ASSOC:
211*7836SJohn.Forte@Sun.COM ec = target_delete_assoc(obj);
212*7836SJohn.Forte@Sun.COM break;
213*7836SJohn.Forte@Sun.COM case DATA_COMMIT:
214*7836SJohn.Forte@Sun.COM ec = target_update_commit();
215*7836SJohn.Forte@Sun.COM break;
216*7836SJohn.Forte@Sun.COM case DATA_RETREAT:
217*7836SJohn.Forte@Sun.COM ec = target_update_retreat();
218*7836SJohn.Forte@Sun.COM break;
219*7836SJohn.Forte@Sun.COM default:
220*7836SJohn.Forte@Sun.COM break;
221*7836SJohn.Forte@Sun.COM }
222*7836SJohn.Forte@Sun.COM
223*7836SJohn.Forte@Sun.COM return (ec);
224*7836SJohn.Forte@Sun.COM }
225