83
83
#include <afs/param.h>
86
("$Header: /cvs/openafs/src/viced/callback.c,v 1.55.2.14 2006/02/02 21:48:39 jaltman Exp $");
86
("$Header: /cvs/openafs/src/viced/callback.c,v 1.55.2.27 2008/03/11 17:40:55 shadow Exp $");
89
89
#include <stdlib.h> /* for malloc() */
90
90
#include <time.h> /* ANSI standard location for time stuff */
91
92
#ifdef AFS_NT40_ENV
310
304
#define FreeCB(cb) iFreeCB((struct CallBack *)cb, &cbstuff.nCBs)
311
305
#define FreeFE(fe) iFreeFE((struct FileEntry *)fe, &cbstuff.nFEs)
313
/* Other protos - move out sometime */
314
extern void ShutDown();
316
307
#define VHASH 512 /* Power of 2 */
317
308
static afs_uint32 HashTable[VHASH]; /* File entry hash table */
318
309
#define VHash(volume, unique) (((volume)+(unique))&(VHASH-1))
750
CompareCBA(const void *e1, const void *e2)
752
const struct cbstruct *cba1 = (const struct cbstruct *)e1;
753
const struct cbstruct *cba2 = (const struct cbstruct *)e2;
754
return ((cba1->hp)->index - (cba2->hp)->index);
756
757
/* Take an array full of hosts, all held. Break callbacks to them, and
757
758
* release the holds once you're done, except don't release xhost. xhost
758
759
* may be NULL. Currently only works for a single Fid in afidp array.
783
784
assert(ncbas <= MAX_CB_HOSTS);
786
/* sort cba list to avoid makecall issues */
787
qsort(cba, ncbas, sizeof(struct cbstruct), CompareCBA);
785
789
/* set up conns for multi-call */
786
790
for (i = 0, j = 0; i < ncbas; i++) {
787
791
struct host *thishost = cba[i].hp;
1182
1187
cbstuff.nbreakers--;
1183
1188
/* If we succeeded it's always ok to unset HFE_LATER */
1184
if (!host->hostFlags & VENUSDOWN)
1189
if (!(host->hostFlags & VENUSDOWN))
1185
1190
host->hostFlags &= ~HFE_LATER;
1186
1191
return (host->hostFlags & VENUSDOWN);
1798
1804
DumpCallBackState(void)
1801
1807
afs_uint32 magic = MAGIC, now = FT_ApproxTime(), freelisthead;
1803
fd = open(AFSDIR_SERVER_CBKDUMP_FILEPATH, O_WRONLY | O_CREAT | O_TRUNC,
1809
oflag = O_WRONLY | O_CREAT | O_TRUNC;
1813
fd = open(AFSDIR_SERVER_CBKDUMP_FILEPATH, oflag, 0666);
1807
1816
("Couldn't create callback dump file %s\n",
1836
1845
ReadDump(char *file)
1839
1848
afs_uint32 magic, freelisthead;
1842
fd = open(file, O_RDONLY);
1855
fd = open(file, oflag);
1844
1857
fprintf(stderr, "Couldn't read dump file %s\n", file);
1860
1873
read(fd, &tfirst, sizeof(tfirst));
1861
1874
read(fd, &freelisthead, sizeof(freelisthead));
1862
1875
CB = ((struct CallBack
1863
*)(calloc(cbstuff.nblks, sizeof(struct FileEntry)))) - 1;
1876
*)(calloc(cbstuff.nblks, sizeof(struct CallBack)))) - 1;
1864
1877
FE = ((struct FileEntry
1865
1878
*)(calloc(cbstuff.nblks, sizeof(struct FileEntry)))) - 1;
1866
1879
CBfree = (struct CallBack *)itocb(freelisthead);
2004
2018
printf("vol=%u vn=%u cbs=%d hi=%d st=%d fest=%d, exp in %d secs at %s",
2005
2019
fe->volid, fe->vnode, fe->ncbs, cb->hhead, cb->status, fe->status,
2006
2020
expires - now, ctime(&expires));
2039
2054
if (!host->interface)
2040
2055
return 1; /* failure */
2042
assert(host->interface->numberOfInterfaces > 0);
2044
2057
/* the only address is the primary interface */
2045
if (host->interface->numberOfInterfaces == 1)
2058
if (host->interface->numberOfInterfaces <= 1)
2046
2059
return 1; /* failure */
2048
2061
/* initialise a security object only once */
2087
2100
if (host->callback_rxcon)
2088
2101
rx_DestroyConnection(host->callback_rxcon);
2089
2102
host->callback_rxcon = conns[multi_i];
2103
hashDelete_r(host->host, host->port, host);
2090
2104
host->host = interfaces[multi_i].addr;
2091
2105
host->port = interfaces[multi_i].port;
2106
hashInsert_r(host->host, host->port, host);
2092
2107
connSuccess = conns[multi_i];
2093
2108
rx_SetConnDeadTime(host->callback_rxcon, 50);
2094
2109
rx_SetConnHardDeadTime(host->callback_rxcon, AFS_HARDDEADTIME);
2134
2149
if (!host->interface)
2135
2150
return 1; /* failure */
2137
assert(host->interface->numberOfInterfaces > 0);
2139
2152
/* the only address is the primary interface */
2140
if (host->interface->numberOfInterfaces == 1)
2141
return 1; /* failure */
2153
if (host->interface->numberOfInterfaces <= 1)
2154
return 1; /* failure */
2143
2156
/* initialise a security object only once */
2162
2175
interfaces[j] = host->interface->interface[i];
2164
rx_NewConnection(interfaces[i].addr,
2165
interfaces[i].port, 1, sc, 0);
2177
rx_NewConnection(interfaces[j].addr,
2178
interfaces[j].port, 1, sc, 0);
2166
2179
rx_SetConnDeadTime(conns[j], 2);
2167
2180
rx_SetConnHardDeadTime(conns[j], AFS_HARDDEADTIME);
2181
2194
if (host->callback_rxcon)
2182
2195
rx_DestroyConnection(host->callback_rxcon);
2196
hashDelete_r(host->host, host->port, host);
2183
2197
host->callback_rxcon = conns[multi_i];
2184
2198
host->host = interfaces[multi_i].addr;
2185
2199
host->port = interfaces[multi_i].port;
2200
hashInsert_r(host->host, host->port, host);
2186
2201
connSuccess = conns[multi_i];
2187
2202
rx_SetConnDeadTime(host->callback_rxcon, 50);
2188
2203
rx_SetConnHardDeadTime(host->callback_rxcon, AFS_HARDDEADTIME);
2190
("multiprobe success with addr %s\n",
2191
afs_inet_ntoa_r(interfaces[multi_i].addr, hoststr)));
2205
("multiprobe success for host %x; new primary addr %s:%d\n",
2206
host, afs_inet_ntoa_r(host->host, hoststr),
2207
ntohs(host->port)));
2196
("multiprobe failure with addr %s\n",
2197
afs_inet_ntoa_r(interfaces[multi_i].addr, hoststr)));
2212
("multiprobe failure with addr %s:%d\n",
2213
afs_inet_ntoa_r(interfaces[multi_i].addr, hoststr),
2214
ntohs(interfaces[multi_i].port)));
2199
2216
/* This is less than desirable but its the best we can do.
2200
2217
* The AFS Cache Manager will return either 0 for a Uuid
2204
2221
* Uuid and fix the host tables.
2206
2223
if (multi_error == 1) {
2207
struct host * newhost;
2209
2224
/* remove the current alternate address from this host */
2211
for (i = 0, j = 0; i < host->interface->numberOfInterfaces; i++) {
2212
if (interfaces[multi_i].addr != host->interface->interface[i].addr &&
2213
interfaces[multi_i].port != host->interface->interface[i].port) {
2214
host->interface->interface[j] = host->interface->interface[i];
2218
host->interface->numberOfInterfaces--;
2226
removeInterfaceAddr_r(host, interfaces[multi_i].addr, interfaces[multi_i].port);