xref: /titanic_41/usr/src/cmd/isns/isnsd/dsapi.c (revision b3697b90e692e3e5d859fb77d285d4c056d99eda)
1 /*
2  * CDDL HEADER START
3  *
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.
7  *
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.
12  *
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]
18  *
19  * CDDL HEADER END
20  */
21 
22 /*
23  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #include <stdio.h>
28 #include <stdlib.h>
29 #ifdef DEBUG
30 #include <time.h>
31 #endif
32 
33 #include "isns_server.h"
34 #include "isns_cache.h"
35 #include "isns_obj.h"
36 #include "isns_log.h"
37 
38 #ifndef	TARGET_DATA_STORE
39 #define	TARGET_DATA_STORE	xml
40 #endif
41 
42 #define	TARGET_src(TARGET)	XTARGET_src(TARGET)
43 #define	XTARGET_src(TARGET)	XXTARGET_src(TARGET/data.c)
44 #define	XXTARGET_src(TARGET)	#TARGET
45 
46 #include TARGET_src(TARGET_DATA_STORE)
47 
48 #define	TARGET_func(func)	XTARGET_func(TARGET_DATA_STORE, func)
49 #define	XTARGET_func(TARGET, func)	XXTARGET_func(TARGET, func)
50 #define	XXTARGET_func(TARGET, func)	TARGET ## func
51 
52 #ifdef DEBUG
53 static time_t total_time = 0;
54 static clock_t total_clock = 0;
55 extern int verbose_tc;
56 #endif
57 
58 int
59 target_init_data(
60 )
61 {
62 	return (TARGET_func(_init_data)());
63 }
64 
65 int
66 target_load_obj(
67 	void **p,
68 	isns_obj_t **objp,
69 	uchar_t *phase
70 )
71 {
72 	return (TARGET_func(_load_obj)(p, objp, phase));
73 }
74 
75 int
76 target_add_obj(
77 	const isns_obj_t *obj
78 )
79 {
80 	int status;
81 #ifdef DEBUG
82 	time_t t;
83 	clock_t c;
84 	if (verbose_tc != 0) {
85 		t = time(NULL);
86 		c = clock();
87 	}
88 #endif
89 	status = TARGET_func(_add_obj)(obj);
90 #ifdef DEBUG
91 	if (verbose_tc != 0) {
92 		t = time(NULL) - t;
93 		c = clock() - c;
94 		total_time += t;
95 		total_clock += c;
96 		printf("time %d clock %.4lf -adding one object\n",
97 		    t, c / (double)CLOCKS_PER_SEC);
98 	}
99 #endif
100 	return (status);
101 }
102 
103 int
104 target_modify_obj(
105 	const isns_obj_t *obj
106 )
107 {
108 	int status;
109 #ifdef DEBUG
110 	time_t t;
111 	clock_t c;
112 	if (verbose_tc != 0) {
113 		t = time(NULL);
114 		c = clock();
115 	}
116 #endif
117 	status = TARGET_func(_modify_obj)(obj);
118 #ifdef DEBUG
119 	if (verbose_tc != 0) {
120 		t = time(NULL) - t;
121 		c = clock() - c;
122 		total_time += t;
123 		total_clock += c;
124 		printf("time %d clock %.4lf -updating one object\n",
125 		    t, c / (double)CLOCKS_PER_SEC);
126 	}
127 #endif
128 	return (status);
129 }
130 
131 int
132 target_delete_obj(
133 	const isns_obj_t *obj
134 )
135 {
136 	int status;
137 #ifdef DEBUG
138 	time_t t;
139 	clock_t c;
140 	if (verbose_tc != 0) {
141 		t = time(NULL);
142 		c = clock();
143 	}
144 #endif
145 	status = TARGET_func(_delete_obj)(obj);
146 #ifdef DEBUG
147 	if (verbose_tc != 0) {
148 		t = time(NULL) - t;
149 		c = clock() - c;
150 		total_time += t;
151 		total_clock += c;
152 		printf("time %d clock %.4lf -deleting one object\n",
153 		    t, c / (double)CLOCKS_PER_SEC);
154 	}
155 #endif
156 	return (status);
157 }
158 
159 int
160 target_delete_assoc(
161 	const isns_obj_t *obj
162 )
163 {
164 	int status;
165 #ifdef DEBUG
166 	time_t t;
167 	clock_t c;
168 	if (verbose_tc != 0) {
169 		t = time(NULL);
170 		c = clock();
171 	}
172 #endif
173 	status = TARGET_func(_delete_assoc)(obj);
174 #ifdef DEBUG
175 	if (verbose_tc != 0) {
176 		t = time(NULL) - t;
177 		c = clock() - c;
178 		total_time += t;
179 		total_clock += c;
180 		printf("time %d clock %.4lf -deleting one membership\n",
181 		    t, c / (double)CLOCKS_PER_SEC);
182 	}
183 #endif
184 	return (status);
185 }
186 
187 int
188 target_update_commit(
189 )
190 {
191 	int status;
192 #ifdef DEBUG
193 	time_t t;
194 	clock_t c;
195 	if (verbose_tc != 0) {
196 		t = time(NULL);
197 		c = clock();
198 	}
199 #endif
200 	status = TARGET_func(_update_commit)();
201 #ifdef DEBUG
202 	if (verbose_tc != 0) {
203 		t = time(NULL) - t;
204 		c = clock() - c;
205 		total_time += t;
206 		total_clock += c;
207 		printf("time %d clock %.4lf -flushing the data\n",
208 		    t, c / (double)CLOCKS_PER_SEC);
209 		printf("time %d clock %.4lf -total update\n",
210 		    total_time, total_clock / (double)CLOCKS_PER_SEC);
211 		total_time = 0;
212 		total_clock = 0;
213 	}
214 #endif
215 	return (status);
216 }
217 
218 int
219 target_update_retreat(
220 )
221 {
222 	int status;
223 #ifdef DEBUG
224 	time_t t;
225 	clock_t c;
226 	if (verbose_tc != 0) {
227 		t = time(NULL);
228 		c = clock();
229 	}
230 #endif
231 	status = TARGET_func(_update_retreat)();
232 #ifdef DEBUG
233 	if (verbose_tc != 0) {
234 		t = time(NULL) - t;
235 		c = clock() - c;
236 		total_time += t;
237 		total_clock += c;
238 		printf("time %d clock %.4lf -flushing the data\n",
239 		    t, c / (double)CLOCKS_PER_SEC);
240 		printf("time %d clock %.4lf -total update\n",
241 		    total_time, total_clock / (double)CLOCKS_PER_SEC);
242 		total_time = 0;
243 		total_clock = 0;
244 	}
245 #endif
246 	return (status);
247 }
248