2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
10 #include <afsconfig.h>
11 #include <afs/param.h>
22 #include <sys/types.h>
25 #include <netinet/in.h>
26 #endif /* AFS_NT40_ENV */
29 #include <sys/statfs.h>
36 #include <rx/rx_globals.h>
38 #include <afs/vlserver.h>
39 #include <afs/cellconfig.h>
42 #include <afs/afsint.h>
49 struct ubik_client *cstruct;
50 static rxkad_level vsu_rxkad_level = rxkad_clear;
53 ovlentry_to_nvlentry(oentryp, nentryp)
54 struct vldbentry *oentryp;
55 struct nvldbentry *nentryp;
59 memset(nentryp, 0, sizeof(struct nvldbentry));
60 strncpy(nentryp->name, oentryp->name, sizeof(nentryp->name));
61 for (i = 0; i < oentryp->nServers; i++) {
62 nentryp->serverNumber[i] = oentryp->serverNumber[i];
63 nentryp->serverPartition[i] = oentryp->serverPartition[i];
64 nentryp->serverFlags[i] = oentryp->serverFlags[i];
66 nentryp->nServers = oentryp->nServers;
67 for (i = 0; i < MAXTYPES; i++)
68 nentryp->volumeId[i] = oentryp->volumeId[i];
69 nentryp->cloneId = oentryp->cloneId;
70 nentryp->flags = oentryp->flags;
74 nvlentry_to_ovlentry(nentryp, oentryp)
75 struct nvldbentry *nentryp;
76 struct vldbentry *oentryp;
80 memset(oentryp, 0, sizeof(struct vldbentry));
81 strncpy(oentryp->name, nentryp->name, sizeof(oentryp->name));
82 if (nentryp->nServers > OMAXNSERVERS) {
84 * The alternative is to store OMAXSERVERS but it's always better
85 * to know what's going on...
89 for (i = 0; i < nentryp->nServers; i++) {
90 oentryp->serverNumber[i] = nentryp->serverNumber[i];
91 oentryp->serverPartition[i] = nentryp->serverPartition[i];
92 oentryp->serverFlags[i] = nentryp->serverFlags[i];
94 oentryp->nServers = i;
95 for (i = 0; i < MAXTYPES; i++)
96 oentryp->volumeId[i] = nentryp->volumeId[i];
97 oentryp->cloneId = nentryp->cloneId;
98 oentryp->flags = nentryp->flags;
102 static int newvlserver = 0;
104 VLDB_CreateEntry(entryp)
105 struct nvldbentry *entryp;
107 struct vldbentry oentry;
110 if (newvlserver == 1) {
112 code = nvlentry_to_ovlentry(entryp, &oentry);
115 code = ubik_VL_CreateEntry(cstruct, 0, &oentry);
118 code = ubik_VL_CreateEntryN(cstruct, 0, entryp);
120 if (code == RXGEN_OPCODE) {
121 newvlserver = 1; /* Doesn't support new interface */
130 VLDB_GetEntryByID(volid, voltype, entryp)
131 afs_int32 volid, voltype;
132 struct nvldbentry *entryp;
134 struct vldbentry oentry;
137 if (newvlserver == 1) {
140 ubik_VL_GetEntryByID(cstruct, 0, volid, voltype, &oentry);
142 ovlentry_to_nvlentry(&oentry, entryp);
145 code = ubik_VL_GetEntryByIDN(cstruct, 0, volid, voltype, entryp);
147 if (code == RXGEN_OPCODE) {
148 newvlserver = 1; /* Doesn't support new interface */
157 VLDB_GetEntryByName(namep, entryp)
159 struct nvldbentry *entryp;
161 struct vldbentry oentry;
164 if (newvlserver == 1) {
166 code = ubik_VL_GetEntryByNameO(cstruct, 0, namep, &oentry);
168 ovlentry_to_nvlentry(&oentry, entryp);
171 code = ubik_VL_GetEntryByNameN(cstruct, 0, namep, entryp);
173 if (code == RXGEN_OPCODE) {
174 newvlserver = 1; /* Doesn't support new interface */
183 VLDB_ReplaceEntry(volid, voltype, entryp, releasetype)
184 afs_int32 volid, voltype, releasetype;
185 struct nvldbentry *entryp;
187 struct vldbentry oentry;
190 if (newvlserver == 1) {
192 code = nvlentry_to_ovlentry(entryp, &oentry);
196 ubik_VL_ReplaceEntry(cstruct, 0, volid, voltype, &oentry,
201 ubik_VL_ReplaceEntryN(cstruct, 0, volid, voltype, entryp,
204 if (code == RXGEN_OPCODE) {
205 newvlserver = 1; /* Doesn't support new interface */
216 VLDB_ListAttributes(attrp, entriesp, blkentriesp)
217 VldbListByAttributes *attrp;
219 nbulkentries *blkentriesp;
221 bulkentries arrayEntries;
222 register int code, i;
224 if (newvlserver == 1) {
226 memset(&arrayEntries, 0, sizeof(arrayEntries)); /*initialize to hint the stub to alloc space */
228 ubik_VL_ListAttributes(cstruct, 0, attrp, entriesp,
231 blkentriesp->nbulkentries_val =
232 (nvldbentry *) malloc(*entriesp * sizeof(struct nvldbentry));
233 for (i = 0; i < *entriesp; i++) { /* process each entry */
234 ovlentry_to_nvlentry(&arrayEntries.bulkentries_val[i],
235 &blkentriesp->nbulkentries_val[i]);
238 if (arrayEntries.bulkentries_val)
239 free(arrayEntries.bulkentries_val);
243 ubik_VL_ListAttributesN(cstruct, 0, attrp, entriesp,
246 if (code == RXGEN_OPCODE) {
247 newvlserver = 1; /* Doesn't support new interface */
256 VLDB_ListAttributesN2(attrp, name, thisindex, nentriesp, blkentriesp,
258 VldbListByAttributes *attrp;
261 afs_int32 *nentriesp;
262 nbulkentries *blkentriesp;
263 afs_int32 *nextindexp;
268 ubik_VL_ListAttributesN2(cstruct, 0, attrp, (name ? name : ""),
269 thisindex, nentriesp, blkentriesp, nextindexp);
274 static int vlserverv4 = -1;
278 afs_uint32 addrs[16];
281 * Increase cache size. This avoids high CPU usage by the vlserver
282 * in environments where there are more than 16 fileservers in the
285 #define GETADDRUCACHESIZE 64
286 struct cacheips cacheips[GETADDRUCACHESIZE];
287 int cacheip_index = 0;
289 VLDB_IsSameAddrs(serv1, serv2, errorp)
290 afs_int32 serv1, serv2, *errorp;
293 ListAddrByAttributes attrs;
295 afs_uint32 *addrp, nentries, unique, i, j, f1, f2;
297 static int initcache = 0;
303 if (vlserverv4 == 1) {
307 for (i = 0; i < GETADDRUCACHESIZE; i++) {
308 cacheips[i].server = cacheips[i].count = 0;
313 /* See if it's cached */
314 for (i = 0; i < GETADDRUCACHESIZE; i++) {
316 for (j = 0; j < cacheips[i].count; j++) {
317 if (serv1 == cacheips[i].addrs[j])
319 else if (serv2 == cacheips[i].addrs[j])
327 if (cacheips[i].server == serv1)
331 memset(&attrs, 0, sizeof(attrs));
332 attrs.Mask = VLADDR_IPADDR;
333 attrs.ipaddr = serv1;
334 memset(&addrs, 0, sizeof(addrs));
335 memset(&uuid, 0, sizeof(uuid));
337 ubik_VL_GetAddrsU(cstruct, 0, &attrs, &uuid, &unique, &nentries,
339 if (vlserverv4 == -1) {
340 if (code == RXGEN_OPCODE) {
341 vlserverv4 = 1; /* Doesn't support new interface */
347 if (code == VL_NOENT)
355 if (nentries > GETADDRUCACHESIZE)
356 nentries = GETADDRUCACHESIZE; /* safety check; should not happen */
357 if (++cacheip_index >= GETADDRUCACHESIZE)
359 cacheips[cacheip_index].server = serv1;
360 cacheips[cacheip_index].count = nentries;
361 addrp = addrs.bulkaddrs_val;
362 for (i = 0; i < nentries; i++, addrp++) {
363 cacheips[cacheip_index].addrs[i] = *addrp;
364 if (serv2 == *addrp) {
373 Set encryption. If 'cryptflag' is nonzero, encrpytion is turned on
374 for authenticated connections; if zero, encryption is turned off.
375 Calling this function always results in a level of at least rxkad_auth;
376 to get a rxkad_clear connection, simply don't call this.
379 vsu_SetCrypt(cryptflag)
383 vsu_rxkad_level = rxkad_crypt;
385 vsu_rxkad_level = rxkad_auth;
391 Get the appropriate type of ubik client structure out from the system.
394 vsu_ClientInit(noAuthFlag, confDir, cellName, sauth, uclientp, secproc)
398 struct ubik_client **uclientp;
402 return ugen_ClientInit(noAuthFlag, confDir, cellName, sauth, uclientp,
403 secproc, "vsu_ClientInit", vsu_rxkad_level,
404 VLDB_MAXSERVERS, AFSCONF_VLDBSERVICE, 90,
405 0, 0, USER_SERVICE_ID);
409 /*extract the name of volume <name> without readonly or backup suffixes
410 * and return the result as <rname>.
413 vsu_ExtractName(rname, name)
414 char rname[], name[];
416 char sname[VOLSER_OLDMAXVOLNAME + 1];
419 strncpy(sname, name, sizeof(sname));
420 sname[sizeof(sname) - 1] = '\0';
421 total = strlen(sname);
422 if (!strcmp(&sname[total - 9], ".readonly")) {
423 /*discard the last 8 chars */
424 sname[total - 9] = '\0';
425 strcpy(rname, sname);
427 } else if (!strcmp(&sname[total - 7], ".backup")) {
428 /*discard last 6 chars */
429 sname[total - 7] = '\0';
430 strcpy(rname, sname);
433 strncpy(rname, name, VOLSER_OLDMAXVOLNAME);
434 rname[VOLSER_OLDMAXVOLNAME] = '\0';
440 /* returns 0 if failed */
442 vsu_GetVolumeID(astring, acstruct, errp)
443 struct ubik_client *acstruct;
448 char volname[VOLSER_OLDMAXVOLNAME + 1];
449 struct nvldbentry entry;
455 if (isdigit(astring[0])) {
458 result = strtoul(astring, &end, 10);
459 if (result != ULONG_MAX && *end == '\0')
463 /* It was not a volume number but something else */
464 total = strlen(astring);
465 vsu_ExtractName(volname, astring);
466 vcode = VLDB_GetEntryByName(volname, &entry);
468 if (!strcmp(&astring[total - 9], ".readonly"))
469 return entry.volumeId[ROVOL];
470 else if ((!strcmp(&astring[total - 7], ".backup")))
471 return entry.volumeId[BACKVOL];
473 return (entry.volumeId[RWVOL]);
476 return 0; /* can't find volume */