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