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>
21 #include <sys/types.h>
24 #include <netinet/in.h>
25 #endif /* AFS_NT40_ENV */
28 #include <sys/statfs.h>
43 #include <rx/rx_globals.h>
45 #include <afs/vlserver.h>
46 #include <afs/cellconfig.h>
49 #include <afs/afsint.h>
56 struct ubik_client *cstruct;
57 static rxkad_level vsu_rxkad_level = rxkad_clear;
60 ovlentry_to_nvlentry(oentryp, nentryp)
61 struct vldbentry *oentryp;
62 struct nvldbentry *nentryp;
66 memset(nentryp, 0, sizeof(struct nvldbentry));
67 strncpy(nentryp->name, oentryp->name, sizeof(nentryp->name));
68 for (i = 0; i < oentryp->nServers; i++) {
69 nentryp->serverNumber[i] = oentryp->serverNumber[i];
70 nentryp->serverPartition[i] = oentryp->serverPartition[i];
71 nentryp->serverFlags[i] = oentryp->serverFlags[i];
73 nentryp->nServers = oentryp->nServers;
74 for (i = 0; i < MAXTYPES; i++)
75 nentryp->volumeId[i] = oentryp->volumeId[i];
76 nentryp->cloneId = oentryp->cloneId;
77 nentryp->flags = oentryp->flags;
81 nvlentry_to_ovlentry(nentryp, oentryp)
82 struct nvldbentry *nentryp;
83 struct vldbentry *oentryp;
87 memset(oentryp, 0, sizeof(struct vldbentry));
88 strncpy(oentryp->name, nentryp->name, sizeof(oentryp->name));
89 if (nentryp->nServers > OMAXNSERVERS) {
91 * The alternative is to store OMAXSERVERS but it's always better
92 * to know what's going on...
96 for (i = 0; i < nentryp->nServers; i++) {
97 oentryp->serverNumber[i] = nentryp->serverNumber[i];
98 oentryp->serverPartition[i] = nentryp->serverPartition[i];
99 oentryp->serverFlags[i] = nentryp->serverFlags[i];
101 oentryp->nServers = i;
102 for (i = 0; i < MAXTYPES; i++)
103 oentryp->volumeId[i] = nentryp->volumeId[i];
104 oentryp->cloneId = nentryp->cloneId;
105 oentryp->flags = nentryp->flags;
109 static int newvlserver = 0;
111 VLDB_CreateEntry(entryp)
112 struct nvldbentry *entryp;
114 struct vldbentry oentry;
117 if (newvlserver == 1) {
119 code = nvlentry_to_ovlentry(entryp, &oentry);
122 code = ubik_VL_CreateEntry(cstruct, 0, &oentry);
125 code = ubik_VL_CreateEntryN(cstruct, 0, entryp);
127 if (code == RXGEN_OPCODE) {
128 newvlserver = 1; /* Doesn't support new interface */
137 VLDB_GetEntryByID(volid, voltype, entryp)
138 afs_int32 volid, voltype;
139 struct nvldbentry *entryp;
141 struct vldbentry oentry;
144 if (newvlserver == 1) {
147 ubik_VL_GetEntryByID(cstruct, 0, volid, voltype, &oentry);
149 ovlentry_to_nvlentry(&oentry, entryp);
152 code = ubik_VL_GetEntryByIDN(cstruct, 0, volid, voltype, entryp);
154 if (code == RXGEN_OPCODE) {
155 newvlserver = 1; /* Doesn't support new interface */
164 VLDB_GetEntryByName(namep, entryp)
166 struct nvldbentry *entryp;
168 struct vldbentry oentry;
171 if (newvlserver == 1) {
173 code = ubik_VL_GetEntryByNameO(cstruct, 0, namep, &oentry);
175 ovlentry_to_nvlentry(&oentry, entryp);
178 code = ubik_VL_GetEntryByNameN(cstruct, 0, namep, entryp);
180 if (code == RXGEN_OPCODE) {
181 newvlserver = 1; /* Doesn't support new interface */
190 VLDB_ReplaceEntry(volid, voltype, entryp, releasetype)
191 afs_int32 volid, voltype, releasetype;
192 struct nvldbentry *entryp;
194 struct vldbentry oentry;
197 if (newvlserver == 1) {
199 code = nvlentry_to_ovlentry(entryp, &oentry);
203 ubik_VL_ReplaceEntry(cstruct, 0, volid, voltype, &oentry,
208 ubik_VL_ReplaceEntryN(cstruct, 0, volid, voltype, entryp,
211 if (code == RXGEN_OPCODE) {
212 newvlserver = 1; /* Doesn't support new interface */
223 VLDB_ListAttributes(attrp, entriesp, blkentriesp)
224 VldbListByAttributes *attrp;
226 nbulkentries *blkentriesp;
228 bulkentries arrayEntries;
229 register int code, i;
231 if (newvlserver == 1) {
233 memset(&arrayEntries, 0, sizeof(arrayEntries)); /*initialize to hint the stub to alloc space */
235 ubik_VL_ListAttributes(cstruct, 0, attrp, entriesp,
238 blkentriesp->nbulkentries_val =
239 (nvldbentry *) malloc(*entriesp * sizeof(struct nvldbentry));
240 for (i = 0; i < *entriesp; i++) { /* process each entry */
241 ovlentry_to_nvlentry(&arrayEntries.bulkentries_val[i],
242 &blkentriesp->nbulkentries_val[i]);
245 if (arrayEntries.bulkentries_val)
246 free(arrayEntries.bulkentries_val);
250 ubik_VL_ListAttributesN(cstruct, 0, attrp, entriesp,
253 if (code == RXGEN_OPCODE) {
254 newvlserver = 1; /* Doesn't support new interface */
263 VLDB_ListAttributesN2(attrp, name, thisindex, nentriesp, blkentriesp,
265 VldbListByAttributes *attrp;
268 afs_int32 *nentriesp;
269 nbulkentries *blkentriesp;
270 afs_int32 *nextindexp;
275 ubik_VL_ListAttributesN2(cstruct, 0, attrp, (name ? name : ""),
276 thisindex, nentriesp, blkentriesp, nextindexp);
281 static int vlserverv4 = -1;
285 afs_uint32 addrs[16];
288 * Increase cache size. This avoids high CPU usage by the vlserver
289 * in environments where there are more than 16 fileservers in the
292 #define GETADDRUCACHESIZE 64
293 struct cacheips cacheips[GETADDRUCACHESIZE];
294 int cacheip_index = 0;
296 VLDB_IsSameAddrs(serv1, serv2, errorp)
297 afs_int32 serv1, serv2, *errorp;
300 ListAddrByAttributes attrs;
302 afs_uint32 *addrp, nentries, unique, i, j, f1, f2;
304 static int initcache = 0;
310 if (vlserverv4 == 1) {
314 for (i = 0; i < GETADDRUCACHESIZE; i++) {
315 cacheips[i].server = cacheips[i].count = 0;
320 /* See if it's cached */
321 for (i = 0; i < GETADDRUCACHESIZE; i++) {
323 for (j = 0; j < cacheips[i].count; j++) {
324 if (serv1 == cacheips[i].addrs[j])
326 else if (serv2 == cacheips[i].addrs[j])
334 if (cacheips[i].server == serv1)
338 memset(&attrs, 0, sizeof(attrs));
339 attrs.Mask = VLADDR_IPADDR;
340 attrs.ipaddr = serv1;
341 memset(&addrs, 0, sizeof(addrs));
342 memset(&uuid, 0, sizeof(uuid));
344 ubik_VL_GetAddrsU(cstruct, 0, &attrs, &uuid, &unique, &nentries,
346 if (vlserverv4 == -1) {
347 if (code == RXGEN_OPCODE) {
348 vlserverv4 = 1; /* Doesn't support new interface */
354 if (code == VL_NOENT)
362 if (nentries > GETADDRUCACHESIZE)
363 nentries = GETADDRUCACHESIZE; /* safety check; should not happen */
364 if (++cacheip_index >= GETADDRUCACHESIZE)
366 cacheips[cacheip_index].server = serv1;
367 cacheips[cacheip_index].count = nentries;
368 addrp = addrs.bulkaddrs_val;
369 for (i = 0; i < nentries; i++, addrp++) {
370 cacheips[cacheip_index].addrs[i] = *addrp;
371 if (serv2 == *addrp) {
380 Set encryption. If 'cryptflag' is nonzero, encrpytion is turned on
381 for authenticated connections; if zero, encryption is turned off.
382 Calling this function always results in a level of at least rxkad_auth;
383 to get a rxkad_clear connection, simply don't call this.
386 vsu_SetCrypt(cryptflag)
390 vsu_rxkad_level = rxkad_crypt;
392 vsu_rxkad_level = rxkad_auth;
398 Get the appropriate type of ubik client structure out from the system.
401 vsu_ClientInit(noAuthFlag, confDir, cellName, sauth, uclientp, secproc)
405 struct ubik_client **uclientp;
409 return ugen_ClientInit(noAuthFlag, confDir, cellName, sauth, uclientp,
410 secproc, "vsu_ClientInit", vsu_rxkad_level,
411 VLDB_MAXSERVERS, AFSCONF_VLDBSERVICE, 90,
412 0, 0, USER_SERVICE_ID);
416 /*extract the name of volume <name> without readonly or backup suffixes
417 * and return the result as <rname>.
420 vsu_ExtractName(rname, name)
421 char rname[], name[];
423 char sname[VOLSER_OLDMAXVOLNAME + 1];
426 strncpy(sname, name, sizeof(sname));
427 sname[sizeof(sname) - 1] = '\0';
428 total = strlen(sname);
429 if (!strcmp(&sname[total - 9], ".readonly")) {
430 /*discard the last 8 chars */
431 sname[total - 9] = '\0';
432 strcpy(rname, sname);
434 } else if (!strcmp(&sname[total - 7], ".backup")) {
435 /*discard last 6 chars */
436 sname[total - 7] = '\0';
437 strcpy(rname, sname);
440 strncpy(rname, name, VOLSER_OLDMAXVOLNAME);
441 rname[VOLSER_OLDMAXVOLNAME] = '\0';
447 /* returns 0 if failed */
449 vsu_GetVolumeID(astring, acstruct, errp)
450 struct ubik_client *acstruct;
455 char volname[VOLSER_OLDMAXVOLNAME + 1];
456 struct nvldbentry entry;
462 if (isdigit(astring[0])) {
465 result = strtoul(astring, &end, 10);
466 if (result != ULONG_MAX && *end == '\0')
470 /* It was not a volume number but something else */
471 total = strlen(astring);
472 vsu_ExtractName(volname, astring);
473 vcode = VLDB_GetEntryByName(volname, &entry);
475 if (!strcmp(&astring[total - 9], ".readonly"))
476 return entry.volumeId[ROVOL];
477 else if ((!strcmp(&astring[total - 7], ".backup")))
478 return entry.volumeId[BACKVOL];
480 return (entry.volumeId[RWVOL]);
483 return 0; /* can't find volume */