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 #include "vsutils_prototypes.h"
51 struct ubik_client *cstruct;
52 static rxkad_level vsu_rxkad_level = rxkad_clear;
55 ovlentry_to_nvlentry(struct vldbentry *oentryp,
56 struct nvldbentry *nentryp)
60 memset(nentryp, 0, sizeof(struct nvldbentry));
61 strncpy(nentryp->name, oentryp->name, sizeof(nentryp->name));
62 for (i = 0; i < oentryp->nServers; i++) {
63 nentryp->serverNumber[i] = oentryp->serverNumber[i];
64 nentryp->serverPartition[i] = oentryp->serverPartition[i];
65 nentryp->serverFlags[i] = oentryp->serverFlags[i];
67 nentryp->nServers = oentryp->nServers;
68 for (i = 0; i < MAXTYPES; i++)
69 nentryp->volumeId[i] = oentryp->volumeId[i];
70 nentryp->cloneId = oentryp->cloneId;
71 nentryp->flags = oentryp->flags;
75 nvlentry_to_ovlentry(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;
105 VLDB_CreateEntry(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 */
131 VLDB_GetEntryByID(afs_uint32 volid, afs_int32 voltype, struct nvldbentry *entryp)
133 struct vldbentry oentry;
136 if (newvlserver == 1) {
139 ubik_VL_GetEntryByID(cstruct, 0, volid, voltype, &oentry);
141 ovlentry_to_nvlentry(&oentry, entryp);
144 code = ubik_VL_GetEntryByIDN(cstruct, 0, volid, voltype, entryp);
146 if (code == RXGEN_OPCODE) {
147 newvlserver = 1; /* Doesn't support new interface */
157 VLDB_GetEntryByName(char *namep, struct nvldbentry *entryp)
159 struct vldbentry oentry;
162 if (newvlserver == 1) {
164 code = ubik_VL_GetEntryByNameO(cstruct, 0, namep, &oentry);
166 ovlentry_to_nvlentry(&oentry, entryp);
169 code = ubik_VL_GetEntryByNameN(cstruct, 0, namep, entryp);
171 if (code == RXGEN_OPCODE) {
172 newvlserver = 1; /* Doesn't support new interface */
182 VLDB_ReplaceEntry(afs_uint32 volid, afs_int32 voltype, struct nvldbentry *entryp, afs_int32 releasetype)
184 struct vldbentry oentry;
187 if (newvlserver == 1) {
189 code = nvlentry_to_ovlentry(entryp, &oentry);
193 ubik_VL_ReplaceEntry(cstruct, 0, volid, voltype, &oentry,
198 ubik_VL_ReplaceEntryN(cstruct, 0, volid, voltype, entryp,
201 if (code == RXGEN_OPCODE) {
202 newvlserver = 1; /* Doesn't support new interface */
213 VLDB_ListAttributes(VldbListByAttributes *attrp,
215 nbulkentries *blkentriesp)
217 bulkentries arrayEntries;
220 if (newvlserver == 1) {
222 memset(&arrayEntries, 0, sizeof(arrayEntries)); /*initialize to hint the stub to alloc space */
224 ubik_VL_ListAttributes(cstruct, 0, attrp, entriesp,
227 blkentriesp->nbulkentries_val =
228 (nvldbentry *) malloc(*entriesp * sizeof(struct nvldbentry));
229 for (i = 0; i < *entriesp; i++) { /* process each entry */
230 ovlentry_to_nvlentry(&arrayEntries.bulkentries_val[i],
231 &blkentriesp->nbulkentries_val[i]);
234 if (arrayEntries.bulkentries_val)
235 free(arrayEntries.bulkentries_val);
239 ubik_VL_ListAttributesN(cstruct, 0, attrp, entriesp,
242 if (code == RXGEN_OPCODE) {
243 newvlserver = 1; /* Doesn't support new interface */
253 VLDB_ListAttributesN2(VldbListByAttributes *attrp,
256 afs_int32 *nentriesp,
257 nbulkentries *blkentriesp,
258 afs_int32 *nextindexp)
263 ubik_VL_ListAttributesN2(cstruct, 0, attrp, (name ? name : ""),
264 thisindex, nentriesp, blkentriesp, nextindexp);
269 static int vlserverv4 = -1;
273 afs_uint32 addrs[16];
276 * Increase cache size. This avoids high CPU usage by the vlserver
277 * in environments where there are more than 16 fileservers in the
280 #define GETADDRUCACHESIZE 64
281 struct cacheips cacheips[GETADDRUCACHESIZE];
282 int cacheip_index = 0;
285 VLDB_IsSameAddrs(afs_uint32 serv1, afs_uint32 serv2, afs_int32 *errorp)
288 ListAddrByAttributes attrs;
290 afs_uint32 *addrp, i, j, f1, f2;
291 afs_int32 unique, nentries;
293 static int initcache = 0;
299 if (vlserverv4 == 1) {
303 for (i = 0; i < GETADDRUCACHESIZE; i++) {
304 cacheips[i].server = cacheips[i].count = 0;
309 /* See if it's cached */
310 for (i = 0; i < GETADDRUCACHESIZE; i++) {
312 for (j = 0; j < cacheips[i].count; j++) {
313 if (serv1 == cacheips[i].addrs[j])
315 else if (serv2 == cacheips[i].addrs[j])
323 if (cacheips[i].server == serv1)
327 memset(&attrs, 0, sizeof(attrs));
328 attrs.Mask = VLADDR_IPADDR;
329 attrs.ipaddr = serv1;
330 memset(&addrs, 0, sizeof(addrs));
331 memset(&uuid, 0, sizeof(uuid));
333 ubik_VL_GetAddrsU(cstruct, 0, &attrs, &uuid, &unique, &nentries,
335 if (vlserverv4 == -1) {
336 if (code == RXGEN_OPCODE) {
337 vlserverv4 = 1; /* Doesn't support new interface */
343 if (code == VL_NOENT)
351 if (nentries > GETADDRUCACHESIZE)
352 nentries = GETADDRUCACHESIZE; /* safety check; should not happen */
353 if (++cacheip_index >= GETADDRUCACHESIZE)
355 cacheips[cacheip_index].server = serv1;
356 cacheips[cacheip_index].count = nentries;
357 addrp = addrs.bulkaddrs_val;
358 for (i = 0; i < nentries; i++, addrp++) {
359 cacheips[cacheip_index].addrs[i] = *addrp;
360 if (serv2 == *addrp) {
369 Set encryption. If 'cryptflag' is nonzero, encrpytion is turned on
370 for authenticated connections; if zero, encryption is turned off.
371 Calling this function always results in a level of at least rxkad_auth;
372 to get a rxkad_clear connection, simply don't call this.
375 vsu_SetCrypt(int cryptflag)
378 vsu_rxkad_level = rxkad_crypt;
380 vsu_rxkad_level = rxkad_auth;
386 Get the appropriate type of ubik client structure out from the system.
389 vsu_ClientInit(int noAuthFlag, const char *confDir, char *cellName, afs_int32 sauth,
390 struct ubik_client **uclientp,
391 int (*secproc)(struct rx_securityClass *, afs_int32))
393 return ugen_ClientInit(noAuthFlag, confDir, cellName, sauth, uclientp,
394 secproc, "vsu_ClientInit", vsu_rxkad_level,
395 VLDB_MAXSERVERS, AFSCONF_VLDBSERVICE, 90,
396 0, 0, USER_SERVICE_ID);
400 /*extract the name of volume <name> without readonly or backup suffixes
401 * and return the result as <rname>.
404 vsu_ExtractName(char rname[], char name[])
406 char sname[VOLSER_OLDMAXVOLNAME + 1];
409 strncpy(sname, name, sizeof(sname));
410 sname[sizeof(sname) - 1] = '\0';
411 total = strlen(sname);
412 if (!strcmp(&sname[total - 9], ".readonly")) {
413 /*discard the last 8 chars */
414 sname[total - 9] = '\0';
415 strcpy(rname, sname);
417 } else if (!strcmp(&sname[total - 7], ".backup")) {
418 /*discard last 6 chars */
419 sname[total - 7] = '\0';
420 strcpy(rname, sname);
423 strncpy(rname, name, VOLSER_OLDMAXVOLNAME);
424 rname[VOLSER_OLDMAXVOLNAME] = '\0';
429 /* returns 0 if failed */
431 vsu_GetVolumeID(char *astring, struct ubik_client *acstruct, afs_int32 *errp)
433 char volname[VOLSER_OLDMAXVOLNAME + 1];
434 struct nvldbentry entry;
440 if (isdigit(astring[0])) {
443 result = strtoul(astring, &end, 10);
444 if (result != UINT_MAX && *end == '\0')
448 /* It was not a volume number but something else */
449 total = strlen(astring);
450 vsu_ExtractName(volname, astring);
451 vcode = VLDB_GetEntryByName(volname, &entry);
453 if ((total >= 9) && (!strcmp(&astring[total - 9], ".readonly")))
454 return entry.volumeId[ROVOL];
455 else if ((total >= 7) && (!strcmp(&astring[total - 7], ".backup")))
456 return entry.volumeId[BACKVOL];
458 return (entry.volumeId[RWVOL]);
461 return 0; /* can't find volume */