-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathibp_types.c
423 lines (316 loc) · 12.1 KB
/
ibp_types.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
/*
Advanced Computing Center for Research and Education Proprietary License
Version 1.0 (April 2006)
Copyright (c) 2006, Advanced Computing Center for Research and Education,
Vanderbilt University, All rights reserved.
This Work is the sole and exclusive property of the Advanced Computing Center
for Research and Education department at Vanderbilt University. No right to
disclose or otherwise disseminate any of the information contained herein is
granted by virtue of your possession of this software except in accordance with
the terms and conditions of a separate License Agreement entered into with
Vanderbilt University.
THE AUTHOR OR COPYRIGHT HOLDERS PROVIDES THE "WORK" ON AN "AS IS" BASIS,
WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT
LIMITED TO THE WARRANTIES OF MERCHANTABILITY, TITLE, FITNESS FOR A PARTICULAR
PURPOSE, AND NON-INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Vanderbilt University
Advanced Computing Center for Research and Education
230 Appleton Place
Nashville, TN 37203
http://www.accre.vanderbilt.edu
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <assert.h>
#include "ibp.h"
#include "log.h"
//*****************************************************************
// new_ibp_depot -Creates a new ibp_depot_t structure
//*****************************************************************
ibp_depot_t *new_ibp_depot()
{
return((ibp_depot_t *)malloc(sizeof(ibp_depot_t)));
}
//*****************************************************************
// destroy_ibp_depot - Destrots the ibp_depot_t structure
//*****************************************************************
void destroy_ibp_depot(ibp_depot_t *d)
{
free(d);
}
//*****************************************************************
// set_ibp_depot - Initializes an ibp_depot_struct
//*****************************************************************
void set_ibp_depot(ibp_depot_t *d, char *host, int port, rid_t rid)
{
strncpy(d->host, host, sizeof(d->host));
d->host[sizeof(d->host)-1]='\0';
d->port = port;
d->rid = rid;
}
//===================================================================
//*****************************************************************
// new_ibp_attributes -Creates a new ibp_attributes_t structure
//*****************************************************************
ibp_attributes_t *new_ibp_attributes()
{
return((ibp_attributes_t *)malloc(sizeof(ibp_attributes_t)));
}
//*****************************************************************
// destroy_ibp_attributes - Destrots the ibp_attributes_t structure
//*****************************************************************
void destroy_ibp_attributes(ibp_attributes_t *attr)
{
free(attr);
}
//*****************************************************************
// set_ibp_attributes - Initializes the data structure
//*****************************************************************
void set_ibp_attributes(ibp_attributes_t *attr, time_t duration, int reliability, int type)
{
attr->duration = duration;
attr->reliability = reliability;
attr->type = type;
}
//*****************************************************************
// get_ibp_attributes - Returns the ibp attributes
//*****************************************************************
void get_ibp_attributes(ibp_attributes_t *attr, time_t *duration, int *reliability, int *type)
{
*duration = attr->duration;
*reliability = attr->reliability;
*type = attr->type;
}
//===================================================================
//*****************************************************************
// new_ibp_timer -Creates a new ibp_timer_t structure
//*****************************************************************
ibp_timer_t *new_ibp_timer()
{
ibp_timer_t *t = (ibp_timer_t *)malloc(sizeof(ibp_timer_t));
if (t == NULL) return(NULL);
t->ClientTimeout = 0;
t->ServerSync = 0;
return(t);
}
//*****************************************************************
// destroy_ibp_attributes - Destrots the ibp_attributes_t structure
//*****************************************************************
void destroy_ibp_timer(ibp_timer_t *t)
{
free(t);
}
//*****************************************************************
// set_ibp_timer - Initializes the data structure
//*****************************************************************
void set_ibp_timer(ibp_timer_t *t, int client_timeout, int server_timeout)
{
t->ClientTimeout = client_timeout;
t->ServerSync = server_timeout;
}
//*****************************************************************
// set_ibp_timer - Retreives the timer information
//*****************************************************************
void get_ibp_timer(ibp_timer_t *t, int *client_timeout, int *server_timeout)
{
*client_timeout = t->ClientTimeout;
*server_timeout = t->ServerSync;
}
//===================================================================
//*****************************************************************
// destroy_ibp_cap
//*****************************************************************
void destroy_ibp_cap(ibp_cap_t *cap)
{
free(cap);
}
//*****************************************************************
// dup_ibp_cap - Duplicates an IBP capability
//*****************************************************************
ibp_cap_t *dup_ibp_cap(ibp_cap_t *src)
{
return(strdup(src));
}
//===================================================================
//*****************************************************************
// new_ibp_capset -Creates a new ibp_capset_t structure
//*****************************************************************
ibp_capset_t *new_ibp_capset()
{
ibp_capset_t *c = (ibp_capset_t *)malloc(sizeof(ibp_capset_t));
if (c == NULL) return(NULL);
c->readCap = NULL;
c->writeCap = NULL;;
c->manageCap = NULL;
return(c);
}
//*****************************************************************
// destroy_ibp_capset - Destroys the ibp_capset_t structure
//*****************************************************************
void destroy_ibp_capset(ibp_capset_t *caps)
{
destroy_ibp_cap(caps->readCap);
destroy_ibp_cap(caps->writeCap);
destroy_ibp_cap(caps->manageCap);
free(caps);
}
//*****************************************************************
// copy_ibp_cap - Copies a set of IBP capabilities
//*****************************************************************
void copy_ibp_capset(ibp_capset_t *src, ibp_capset_t *dest)
{
dest->readCap = dup_ibp_cap(src->readCap);
dest->writeCap = dup_ibp_cap(src->writeCap);
dest->manageCap = dup_ibp_cap(src->manageCap);
}
//*****************************************************************
// get_ibp_cap - Returns the requested capability
//*****************************************************************
ibp_cap_t *get_ibp_cap(ibp_capset_t *caps, int ctype)
{
ibp_cap_t *c;
if (ctype == IBP_READCAP) {
c = caps->readCap;
} else if (ctype == IBP_WRITECAP) {
c = caps->writeCap;
} else if (ctype == IBP_MANAGECAP) {
c = caps->manageCap;
} else {
c = NULL;
}
return(c);
}
//===================================================================
//*****************************************************************
// new_ibp_alias_capstatus -Creates a new ibp_alias_capstatus_t structure
//*****************************************************************
ibp_alias_capstatus_t *new_ibp_alias_capstatus()
{
ibp_alias_capstatus_t *cs = (ibp_alias_capstatus_t *)malloc(sizeof(ibp_alias_capstatus_t));
if (cs == NULL) return(NULL);
cs->read_refcount = -1;
cs->write_refcount = -1;
cs->offset = 0;
cs->size = 0;
cs->duration = 0;
return(cs);
}
//*****************************************************************
// destroy_ibp_alias_capstatus - Destroys the ibp_alias_capstatus_t structure
//*****************************************************************
void destroy_ibp_alias_capstatus(ibp_alias_capstatus_t *cs)
{
free(cs);
}
//*****************************************************************
// copy_ibp_alias_capstatus - Copies a the alias_capstatus info
//*****************************************************************
void copy_ibp_alias_capstatus(ibp_alias_capstatus_t *src, ibp_alias_capstatus_t *dest)
{
memcpy(dest, src, sizeof(ibp_alias_capstatus_t));
}
//*****************************************************************
// get_ibp_alias_capstatus - Returns the requested alias caps status info
//*****************************************************************
void get_ibp_alias_capstatus(ibp_alias_capstatus_t *cs, int *readcount, int *writecount,
int *offset, int *size, int *duration)
{
*readcount = cs->read_refcount;
*writecount = cs->write_refcount;
*offset = cs->offset;
*size = cs->size;
*duration = cs->duration;
}
//===================================================================
//*****************************************************************
// new_ibp_capstatus -Creates a new ibp_capstatus_t structure
//*****************************************************************
ibp_capstatus_t *new_ibp_capstatus()
{
ibp_capstatus_t *cs = (ibp_capstatus_t *)malloc(sizeof(ibp_capstatus_t));
if (cs == NULL) return(NULL);
cs->readRefCount = -1;
cs->writeRefCount = -1;
cs->currentSize = -1;
cs->maxSize = 0;
set_ibp_attributes(&(cs->attrib), 0, -1, -1);
return(cs);
}
//*****************************************************************
// destroy_ibp_capstatus - Destroys the ibp_capstatus_t structure
//*****************************************************************
void destroy_ibp_capstatus(ibp_capstatus_t *cs)
{
free(cs);
}
//*****************************************************************
// copy_ibp_capstatus - Copies a the capstatus info
//*****************************************************************
void copy_ibp_capstatus(ibp_capstatus_t *src, ibp_capstatus_t *dest)
{
memcpy(dest, src, sizeof(ibp_capstatus_t));
}
//*****************************************************************
// get_ibp_capstatus - Returns the requested caps status info
// The attrib pointer is redirected to the CapStatus's attrib
// field. As a result it should NOT point to "new"ed attribute
// structure.
//*****************************************************************
void get_ibp_capstatus(ibp_capstatus_t *cs, int *readcount, int *writecount,
int *current_size, int *max_size, ibp_attributes_t *attrib)
{
*readcount = cs->readRefCount;
*writecount = cs->writeRefCount;
*current_size = cs->currentSize;
*max_size = cs->maxSize;
*attrib = cs->attrib;
}
//===================================================================
// ibp_ridlist_t manipulation routines
//===================================================================
//*****************************************************************
void ridlist_init(ibp_ridlist_t *rlist, int size)
{
rlist->rl = (rid_t *)malloc(sizeof(rid_t)*size);
assert(rlist->rl != NULL);
rlist->n = size;
}
//*****************************************************************
void ridlist_destroy(ibp_ridlist_t *rlist)
{
free(rlist->rl);
}
//*****************************************************************
int ridlist_get_size(ibp_ridlist_t *rlist)
{
return(rlist->n);
}
//*****************************************************************
rid_t ridlist_get_element(ibp_ridlist_t *rlist, int index)
{
if (index >= rlist->n) {
log_printf(0, "ridlist_get_element: Invalid index! size=%d index=%d\n", rlist->n, index);
return(-1);
}
return(rlist->rl[index]);
}
//*****************************************************************
char *ibp_rid2str(rid_t rid, char *buffer)
{
sprintf(buffer, "%d", rid);
return(buffer);
}
//*****************************************************************
rid_t ibp_str2rid(char *rid_str)
{
return(atol(rid_str));
}
//*****************************************************************
void ibp_empty_rid(rid_t *rid)
{
*rid = 0;
}