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;
218 register int code, i;
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_int32 serv1, afs_int32 serv2, afs_int32 *errorp)
288 ListAddrByAttributes attrs;
290 afs_uint32 *addrp, nentries, unique, i, j, f1, f2;
292 static int initcache = 0;
298 if (vlserverv4 == 1) {
302 for (i = 0; i < GETADDRUCACHESIZE; i++) {
303 cacheips[i].server = cacheips[i].count = 0;
308 /* See if it's cached */
309 for (i = 0; i < GETADDRUCACHESIZE; i++) {
311 for (j = 0; j < cacheips[i].count; j++) {
312 if (serv1 == cacheips[i].addrs[j])
314 else if (serv2 == cacheips[i].addrs[j])
322 if (cacheips[i].server == serv1)
326 memset(&attrs, 0, sizeof(attrs));
327 attrs.Mask = VLADDR_IPADDR;
328 attrs.ipaddr = serv1;
329 memset(&addrs, 0, sizeof(addrs));
330 memset(&uuid, 0, sizeof(uuid));
332 ubik_VL_GetAddrsU(cstruct, 0, &attrs, &uuid, &unique, &nentries,
334 if (vlserverv4 == -1) {
335 if (code == RXGEN_OPCODE) {
336 vlserverv4 = 1; /* Doesn't support new interface */
342 if (code == VL_NOENT)
350 if (nentries > GETADDRUCACHESIZE)
351 nentries = GETADDRUCACHESIZE; /* safety check; should not happen */
352 if (++cacheip_index >= GETADDRUCACHESIZE)
354 cacheips[cacheip_index].server = serv1;
355 cacheips[cacheip_index].count = nentries;
356 addrp = addrs.bulkaddrs_val;
357 for (i = 0; i < nentries; i++, addrp++) {
358 cacheips[cacheip_index].addrs[i] = *addrp;
359 if (serv2 == *addrp) {
368 Set encryption. If 'cryptflag' is nonzero, encrpytion is turned on
369 for authenticated connections; if zero, encryption is turned off.
370 Calling this function always results in a level of at least rxkad_auth;
371 to get a rxkad_clear connection, simply don't call this.
374 vsu_SetCrypt(int cryptflag)
377 vsu_rxkad_level = rxkad_crypt;
379 vsu_rxkad_level = rxkad_auth;
385 Get the appropriate type of ubik client structure out from the system.
388 vsu_ClientInit(int noAuthFlag, char *confDir, char *cellName, afs_int32 sauth,
389 struct ubik_client **uclientp, int (*secproc)())
391 return ugen_ClientInit(noAuthFlag, confDir, cellName, sauth, uclientp,
392 secproc, "vsu_ClientInit", vsu_rxkad_level,
393 VLDB_MAXSERVERS, AFSCONF_VLDBSERVICE, 90,
394 0, 0, USER_SERVICE_ID);
398 /*extract the name of volume <name> without readonly or backup suffixes
399 * and return the result as <rname>.
402 vsu_ExtractName(char rname[], char name[])
404 char sname[VOLSER_OLDMAXVOLNAME + 1];
407 strncpy(sname, name, sizeof(sname));
408 sname[sizeof(sname) - 1] = '\0';
409 total = strlen(sname);
410 if (!strcmp(&sname[total - 9], ".readonly")) {
411 /*discard the last 8 chars */
412 sname[total - 9] = '\0';
413 strcpy(rname, sname);
415 } else if (!strcmp(&sname[total - 7], ".backup")) {
416 /*discard last 6 chars */
417 sname[total - 7] = '\0';
418 strcpy(rname, sname);
421 strncpy(rname, name, VOLSER_OLDMAXVOLNAME);
422 rname[VOLSER_OLDMAXVOLNAME] = '\0';
428 /* returns 0 if failed */
430 vsu_GetVolumeID(char *astring, struct ubik_client *acstruct, afs_int32 *errp)
432 char volname[VOLSER_OLDMAXVOLNAME + 1];
433 struct nvldbentry entry;
439 if (isdigit(astring[0])) {
442 result = strtoul(astring, &end, 10);
443 if (result != ULONG_MAX && *end == '\0')
447 /* It was not a volume number but something else */
448 total = strlen(astring);
449 vsu_ExtractName(volname, astring);
450 vcode = VLDB_GetEntryByName(volname, &entry);
452 if (!strcmp(&astring[total - 9], ".readonly"))
453 return entry.volumeId[ROVOL];
454 else if ((!strcmp(&astring[total - 7], ".backup")))
455 return entry.volumeId[BACKVOL];
457 return (entry.volumeId[RWVOL]);
460 return 0; /* can't find volume */