2 Copyright (C) 2003 - 2010 Chaskiel Grundman
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions
9 1. Redistributions of source code must retain the above copyright
10 notice, this list of conditions and the following disclaimer.
12 2. Redistributions in binary form must reproduce the above copyright
13 notice, this list of conditions and the following disclaimer in the
14 documentation and/or other materials provided with the distribution.
16 THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 #include <afs/param.h>
28 #include <afs/afsint.h> /*Callback interface defs*/
29 #include <afs/afsutil.h>
33 #include "afscp_internal.h"
35 int afs_cb_inited = 0;
36 struct interfaceAddr afs_cb_interface;
37 static int afs_maxcallbacks=0, afs_cballoced=0;
38 struct afs_callback *allcallbacks=NULL;
40 static int init_afs_cb() {
43 afs_uuid_create(&afs_cb_interface.uuid);
44 count = rx_getAllAddr(&afs_cb_interface.addr_in, AFS_MAX_INTERFACE_ADDR);
46 afs_cb_interface.numberOfInterfaces = 0;
48 afs_cb_interface.numberOfInterfaces = count;
53 int AddCallBack(const struct afs_server *server, const struct AFSFid *fid,
54 const struct AFSFetchStatus *fst, const struct AFSCallBack *cb)
57 struct afs_callback *use=NULL, *newlist;
58 struct afs_venusfid f;
63 for (i=0;i<afs_maxcallbacks;i++) {
64 if (allcallbacks[i].cb.ExpirationTime < now) {
65 if (allcallbacks[i].valid) {
66 f.cell=afs_cellbyid(allcallbacks[i].server->cell);
67 memcpy(&f.fid, &allcallbacks[i].fid, sizeof(struct afs_venusfid));
70 allcallbacks[i].valid=0;
74 if (allcallbacks[i].valid == 0)
76 if (allcallbacks[i].server==server &&
77 fid->Volume == allcallbacks[i].fid.Volume &&
78 fid->Vnode == allcallbacks[i].fid.Vnode &&
79 fid->Unique == allcallbacks[i].fid.Unique) {
85 if (afs_maxcallbacks >= afs_cballoced) {
87 afs_cballoced = afs_cballoced *2;
90 newlist=realloc(allcallbacks, afs_cballoced *
91 sizeof(struct afs_callback));
96 use=&allcallbacks[afs_maxcallbacks++];
100 memmove(&use->fid, fid, sizeof(struct AFSFid));
101 memmove(&use->cb, cb, sizeof(struct AFSCallBack));
102 f.cell=afs_cellbyid(server->cell);
103 memcpy(&f.fid, fid, sizeof(struct AFSFid));
107 int RemoveCallBack(const struct afs_server *server, const struct afs_venusfid *f)
109 struct afs_callback *cb;
115 for (i=0;i<afs_maxcallbacks;i++) {
117 if (cb->server == server &&
118 f->fid.Volume == cb->fid.Volume &&
119 f->fid.Vnode == cb->fid.Vnode &&
120 f->fid.Unique == cb->fid.Unique) {
128 int ReturnCallBacks(const struct afs_server *server)
130 struct AFSCBFids theFids;
131 struct AFSCBs theCBs;
132 struct afs_callback *cb;
133 struct afs_venusfid f;
141 for (i=0;i<afs_maxcallbacks;i++) {
143 /* printf("%d %x %x %ld %d", i, cb, cb->server, cb->cb.ExpirationTime,
145 if (cb->server != server)
147 if (cb->cb.ExpirationTime < now) {
149 f.cell=afs_cellbyid(cb->server->cell);
150 memcpy(&f.fid, &cb->fid, sizeof(struct afs_venusfid));
158 theFids.AFSCBFids_val=malloc(sizeof(struct AFSCallBack) * AFSCBMAX);
159 if (!theFids.AFSCBFids_val)
161 theCBs.AFSCBs_val=malloc(sizeof(struct AFSFid) * AFSCBMAX);
162 if (!theCBs.AFSCBs_val) {
163 free(theFids.AFSCBFids_val);
168 if (ncallbacks == AFSCBMAX) {
169 theFids.AFSCBFids_len=ncallbacks;
170 theCBs.AFSCBs_len=ncallbacks;
171 for (j=0;j<server->naddrs;j++) {
172 if (!RXAFS_GiveUpCallBacks(server->conns[j], &theFids,
178 memmove(&theFids.AFSCBFids_val[ncallbacks], &cb->fid,
179 sizeof(struct AFSFid));
180 memmove(&theCBs.AFSCBs_val[ncallbacks], &cb->cb,
181 sizeof(struct AFSCallBack));
183 theCBs.AFSCBs_val[ncallbacks].CallBackType = CB_DROPPED;
186 f.cell=afs_cellbyid(cb->server->cell);
187 memcpy(&f.fid, &cb->fid, sizeof(struct afs_callback));
194 theFids.AFSCBFids_len=ncallbacks;
195 theCBs.AFSCBs_len=ncallbacks;
196 for (j=0;j<server->naddrs;j++) {
197 if (!RXAFS_GiveUpCallBacks(server->conns[j], &theFids,
201 free(theFids.AFSCBFids_val);
202 free(theCBs.AFSCBs_val);
207 int ReturnAllCallBacks(void)
209 struct afs_server *s;
212 for (i=0;(s=afs_serverbyindex(i));i++)
219 afs_int32 SRXAFSCB_CallBack(rxcall, Fids_Array, CallBack_Array)
220 struct rx_call *rxcall;
221 AFSCBFids *Fids_Array;
222 AFSCBs *CallBack_Array;
224 { /*SRXAFSCB_CallBack*/
225 struct rx_connection *rxconn=rx_ConnectionOf(rxcall);
226 struct rx_peer *rxpeer=rx_PeerOf(rxconn);
227 struct afs_server *server=afs_anyserverbyaddr(rxpeer->host);
228 struct afs_callback *cb;
229 struct afs_venusfid f;
235 for (i=0;i<afs_maxcallbacks;i++) {
237 if (cb->server != server)
239 for (j=0;j<Fids_Array->AFSCBFids_len;j++) {
240 fid=&Fids_Array->AFSCBFids_val[j];
241 if (fid->Volume == cb->fid.Volume &&
242 fid->Vnode == cb->fid.Vnode &&
243 fid->Unique == cb->fid.Unique)
245 f.cell=afs_cellbyid(cb->server->cell);
246 memcpy(&f.fid, &cb->fid, sizeof(struct afs_venusfid));
253 } /*SRXAFSCB_CallBack*/
256 afs_int32 SRXAFSCB_InitCallBackState(rxcall)
257 struct rx_call *rxcall;
259 { /*SRXAFSCB_InitCallBackState*/
260 struct rx_connection *rxconn=rx_ConnectionOf(rxcall);
261 struct rx_peer *rxpeer=rx_PeerOf(rxconn);
262 struct afs_server *server=afs_anyserverbyaddr(rxpeer->host);
263 struct afs_callback *cb;
264 struct afs_venusfid f;
269 for (i=0;i<afs_maxcallbacks;i++) {
271 if (cb->server != server)
274 f.cell=afs_cellbyid(cb->server->cell);
275 memcpy(&f.fid, &cb->fid, sizeof(struct afs_callback));
282 } /*SRXAFSCB_InitCallBackState*/
284 afs_int32 SRXAFSCB_Probe(rxcall)
285 struct rx_call *rxcall;
293 afs_int32 SRXAFSCB_GetCE(rxcall)
294 struct rx_call *rxcall;
300 afs_int32 SRXAFSCB_GetCE64(rxcall)
301 struct rx_call *rxcall;
308 afs_int32 SRXAFSCB_GetLock(rxcall)
309 struct rx_call *rxcall;
311 { /*SRXAFSCB_GetLock*/
314 } /*SRXAFSCB_GetLock*/
315 afs_int32 SRXAFSCB_XStatsVersion(rxcall)
316 struct rx_call *rxcall;
318 { /*SRXAFSCB_XStatsVersion*/
321 } /*SRXAFSCB_XStatsVersion*/
323 afs_int32 SRXAFSCB_GetXStats(rxcall)
324 struct rx_call *rxcall;
326 { /*SRXAFSCB_GetXStats*/
328 } /*SRXAFSCB_GetXStats*/
330 int SRXAFSCB_InitCallBackState2(rxcall, addr)
331 struct rx_call *rxcall;
332 struct interfaceAddr * addr;
337 int SRXAFSCB_WhoAreYou(rxcall, addr)
338 struct rx_call *rxcall;
339 struct interfaceAddr *addr;
342 if ( rxcall && addr )
344 if (!afs_cb_inited) init_afs_cb();
345 *addr = afs_cb_interface;
348 xdrrx_create(&x, rxcall, XDR_ENCODE);
349 xdr_interfaceAddr(&x, addr);
350 rx_Write(rxcall,"",0);
351 rxi_FlushWrite(rxcall);
352 rx_EndCall(rxcall, 0);
359 int SRXAFSCB_InitCallBackState3(rxcall, uuidp)
360 struct rx_call *rxcall;
363 struct rx_connection *rxconn=rx_ConnectionOf(rxcall);
364 struct rx_peer *rxpeer=rx_PeerOf(rxconn);
365 struct afs_server *server=afs_anyserverbyaddr(rxpeer->host);
366 struct afs_callback *cb;
367 struct afs_venusfid f;
372 for (i=0;i<afs_maxcallbacks;i++) {
374 if (cb->server != server)
377 f.cell=afs_cellbyid(cb->server->cell);
378 memcpy(&f.fid, &cb->fid, sizeof(struct afs_callback));
385 int SRXAFSCB_ProbeUuid(rxcall, uuidp)
386 struct rx_call *rxcall;
390 if (!afs_cb_inited) init_afs_cb();
391 if (!afs_uuid_equal(uuidp, &afs_cb_interface.uuid))
392 code = 1; /* failure */
394 rx_EndCall(rxcall,code);
399 int SRXAFSCB_GetServerPrefs(
400 struct rx_call *a_call,
402 afs_int32 *a_srvr_addr,
403 afs_int32 *a_srvr_rank)
405 *a_srvr_addr = 0xffffffff;
406 *a_srvr_rank = 0xffffffff;
410 int SRXAFSCB_GetCellServDB(
411 struct rx_call *a_call,
419 int SRXAFSCB_GetLocalCell(
420 struct rx_call *a_call,
426 int SRXAFSCB_GetCacheConfig(
427 struct rx_call *a_call,
428 afs_uint32 callerVersion,
429 afs_uint32 *serverVersion,
430 afs_uint32 *configCount,
435 int SRXAFSCB_GetCellByNum(
436 struct rx_call *a_call,
443 #ifdef AFS_64BIT_CLIENT
445 SRXAFSCB_TellMeAboutYourself(struct rx_call * rxcall,
446 struct interfaceAddr * addr,
447 Capabilities * capabilities)
449 if ( rxcall && addr )
451 if (!afs_cb_inited) init_afs_cb();
452 *addr = afs_cb_interface;