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>
16 #include <sys/types.h>
20 #include <afs/afsutil.h>
27 #include <netinet/in.h>
31 #include "afs/audit.h"
35 #ifdef HAVE_POSIX_REGEX /* use POSIX regexp library */
41 extern struct afsconf_dir *vldb_confdir;
42 extern struct ubik_dbase *VL_dbase;
43 struct vlheader cheader; /* kept in network byte order */
44 extern afs_uint32 HostAddress[]; /* host addresses kept in host byte order */
46 struct extentaddr *ex_addr[VL_MAX_ADDREXTBLKS] = { 0, 0, 0, 0 };
47 static char rxinfo_str[128]; /* Need rxinfo string to be non-local */
48 #define ABORT(c) { errorcode = (c); goto abort; }
50 #define END(c) { errorcode = (c); goto end; }
52 #define VLDBALLOCLIMIT 10000
53 #define VLDBALLOCINCR 2048
55 static int put_attributeentry();
56 static int put_nattributeentry();
57 static int RemoveEntry();
58 static ReleaseEntry();
59 static int check_vldbentry();
60 static int check_nvldbentry();
61 static int vldbentry_to_vlentry();
62 static int nvldbentry_to_vlentry();
63 static get_vldbupdateentry();
64 static int repsite_exists();
65 static repsite_compress();
66 static vlentry_to_vldbentry();
67 static vlentry_to_nvldbentry();
68 static vlentry_to_uvldbentry();
69 static int InvalidVolname();
70 static int InvalidVoltype();
71 static int InvalidOperation();
72 static int InvalidReleasetype();
73 static int IpAddrToRelAddr();
74 static int ChangeIPAddr();
78 struct rx_call *rxcall;
81 register struct rx_connection *tconn;
86 struct in_addr hostAddr;
88 tconn = rx_ConnectionOf(rxcall);
89 hostAddr.s_addr = rx_HostOf(rx_PeerOf(tconn));
91 rxkad_GetServerInfo(rxcall->conn, NULL, &exp, tname, tinst, tcell,
94 sprintf(rxinfo_str, "%s %s%s%s%s%s", inet_ntoa(hostAddr), tname,
95 tinst?".":"", tinst?tinst:"", tcell?"@":"", tcell?tcell:"");
97 sprintf(rxinfo_str, "%s noauth", inet_ntoa(hostAddr));
101 /* This is called to initialize the database, set the appropriate locks and make sure that the vldb header is valid */
103 Init_VLdbase(trans, locktype, this_op)
104 struct ubik_trans **trans;
105 int locktype; /* indicate read or write transaction */
108 int errorcode = 0, pass, wl;
110 for (pass = 1; pass <= 3; pass++) {
111 if (pass == 2) { /* take write lock to rebuild the db */
112 errorcode = ubik_BeginTrans(VL_dbase, UBIK_WRITETRANS, trans);
114 } else if (locktype == LOCKREAD) {
116 ubik_BeginTransReadAny(VL_dbase, UBIK_READTRANS, trans);
119 errorcode = ubik_BeginTrans(VL_dbase, UBIK_WRITETRANS, trans);
125 errorcode = ubik_SetLock(*trans, 1, 1, locktype);
128 ubik_AbortTrans(*trans);
132 /* check that dbase is initialized and setup cheader */
133 /* 2nd pass we try to rebuild the header */
134 errorcode = CheckInit(*trans, ((pass == 2) ? 1 : 0));
135 if (!errorcode && wl && extent_mod)
136 errorcode = readExtents(*trans); /* Fix the mh extent blocks */
139 ubik_AbortTrans(*trans);
140 /* Only rebuld if the database is empty */
141 /* Exit if can't rebuild */
142 if ((pass == 1) && (errorcode != VL_EMPTY))
146 } else { /* No errorcode */
148 ubik_EndTrans(*trans); /* Rebuilt db. End trans, then retake original lock */
150 break; /* didn't rebuild and successful - exit */
158 /* Create a new vldb entry; both new volume id and name must be unique (non-existant in vldb). */
161 SVL_CreateEntry(rxcall, newentry)
162 struct rx_call *rxcall;
163 struct vldbentry *newentry;
165 struct ubik_trans *trans;
166 afs_int32 errorcode, blockindex;
167 struct nvlentry tentry;
169 COUNT_REQ(VLCREATEENTRY);
170 if (!afsconf_SuperUser(vldb_confdir, rxcall, NULL)) {
175 /* Do some validity tests on new entry */
176 if ((errorcode = check_vldbentry(newentry))
177 || (errorcode = Init_VLdbase(&trans, LOCKWRITE, this_op)))
181 ("OCreate Volume %d %s\n", newentry->volumeId[RWVOL],
183 /* XXX shouldn't we check to see if the r/o volume is duplicated? */
184 if (newentry->volumeId[RWVOL]
185 && FindByID(trans, newentry->volumeId[RWVOL], RWVOL, &tentry, &errorcode)) { /* entry already exists, we fail */
186 errorcode = VL_IDEXIST;
188 } else if (errorcode) {
192 /* Is this following check (by volume name) necessary?? */
193 /* If entry already exists, we fail */
194 if (FindByName(trans, newentry->name, &tentry, &errorcode)) {
195 errorcode = VL_NAMEEXIST;
197 } else if (errorcode) {
201 blockindex = AllocBlock(trans, &tentry);
202 if (blockindex == 0) {
203 errorcode = VL_CREATEFAIL;
207 memset(&tentry, 0, sizeof(struct nvlentry));
208 /* Convert to its internal representation; both in host byte order */
209 if (errorcode = vldbentry_to_vlentry(trans, newentry, &tentry)) {
210 FreeBlock(trans, blockindex);
214 /* Actually insert the entry in vldb */
215 errorcode = ThreadVLentry(trans, blockindex, &tentry);
217 FreeBlock(trans, blockindex);
220 errorcode = ubik_EndTrans(trans);
226 ubik_AbortTrans(trans);
229 osi_auditU(rxcall, VLCreateEntryEvent, errorcode, AUD_STR,
230 (newentry ? newentry->name : NULL), AUD_END);
236 SVL_CreateEntryN(rxcall, newentry)
237 struct rx_call *rxcall;
238 struct nvldbentry *newentry;
240 struct ubik_trans *trans;
241 afs_int32 errorcode, blockindex;
242 struct nvlentry tentry;
244 COUNT_REQ(VLCREATEENTRYN);
245 if (!afsconf_SuperUser(vldb_confdir, rxcall, NULL)) {
250 /* Do some validity tests on new entry */
251 if ((errorcode = check_nvldbentry(newentry))
252 || (errorcode = Init_VLdbase(&trans, LOCKWRITE, this_op)))
256 ("Create Volume %d %s\n", newentry->volumeId[RWVOL],
258 /* XXX shouldn't we check to see if the r/o volume is duplicated? */
259 if (newentry->volumeId[RWVOL]
260 && FindByID(trans, newentry->volumeId[RWVOL], RWVOL, &tentry, &errorcode)) { /* entry already exists, we fail */
261 errorcode = VL_IDEXIST;
263 } else if (errorcode) {
267 /* Is this following check (by volume name) necessary?? */
268 /* If entry already exists, we fail */
269 if (FindByName(trans, newentry->name, &tentry, &errorcode)) {
270 errorcode = VL_NAMEEXIST;
272 } else if (errorcode) {
276 blockindex = AllocBlock(trans, &tentry);
277 if (blockindex == 0) {
278 errorcode = VL_CREATEFAIL;
282 memset(&tentry, 0, sizeof(struct nvlentry));
283 /* Convert to its internal representation; both in host byte order */
284 if (errorcode = nvldbentry_to_vlentry(trans, newentry, &tentry)) {
285 FreeBlock(trans, blockindex);
289 /* Actually insert the entry in vldb */
290 errorcode = ThreadVLentry(trans, blockindex, &tentry);
292 FreeBlock(trans, blockindex);
295 errorcode = ubik_EndTrans(trans);
301 ubik_AbortTrans(trans);
304 osi_auditU(rxcall, VLCreateEntryEvent, errorcode, AUD_STR,
305 (newentry ? newentry->name : NULL), AUD_END);
311 SVL_ChangeAddr(rxcall, ip1, ip2)
312 struct rx_call *rxcall;
315 struct ubik_trans *trans;
318 COUNT_REQ(VLCHANGEADDR);
319 if (!afsconf_SuperUser(vldb_confdir, rxcall, NULL)) {
324 if (errorcode = Init_VLdbase(&trans, LOCKWRITE, this_op))
327 VLog(1, ("Change Addr %d -> %d %s\n", ip1, ip2, rxinfo(rxcall)));
328 if (errorcode = ChangeIPAddr(ip1, ip2, trans))
331 errorcode = ubik_EndTrans(trans);
337 ubik_AbortTrans(trans);
340 osi_auditU(rxcall, VLChangeAddrEvent, errorcode, AUD_LONG, ip1, AUD_LONG,
345 /* Delete a vldb entry given the volume id. */
347 SVL_DeleteEntry(rxcall, volid, voltype)
348 struct rx_call *rxcall;
352 struct ubik_trans *trans;
353 afs_int32 blockindex, errorcode;
354 struct nvlentry tentry;
356 COUNT_REQ(VLDELETEENTRY);
357 if (!afsconf_SuperUser(vldb_confdir, rxcall, NULL))
360 if ((voltype != -1) && (InvalidVoltype(voltype)))
363 if (errorcode = Init_VLdbase(&trans, LOCKWRITE, this_op))
366 VLog(1, ("Delete Volume %d %s\n", volid, rxinfo(rxcall)));
367 blockindex = FindByID(trans, volid, voltype, &tentry, &errorcode);
368 if (blockindex == 0) { /* volid not found */
370 errorcode = VL_NOENT;
374 if (tentry.flags & VLDELETED) { /* Already deleted; return */
375 ABORT(VL_ENTDELETED);
377 if (errorcode = RemoveEntry(trans, blockindex, &tentry)) {
380 errorcode = (ubik_EndTrans(trans));
385 ubik_AbortTrans(trans);
388 osi_auditU(rxcall, VLDeleteEntryEvent, errorcode, AUD_LONG, volid,
394 /* Get a vldb entry given its volume id; make sure it's not a deleted entry. */
395 GetEntryByID(rxcall, volid, voltype, aentry, new, this_op)
396 struct rx_call *rxcall;
398 afs_int32 voltype, new, this_op;
399 char *aentry; /* entry data copied here */
401 struct ubik_trans *trans;
402 afs_int32 blockindex, errorcode;
403 struct nvlentry tentry;
405 if ((voltype != -1) && (InvalidVoltype(voltype)))
406 return VL_BADVOLTYPE;
407 if (errorcode = Init_VLdbase(&trans, LOCKREAD, this_op))
410 VLog(5, ("GetVolumeByID %d (%d) %s\n", volid, new, rxinfo(rxcall)));
411 blockindex = FindByID(trans, volid, voltype, &tentry, &errorcode);
412 if (blockindex == 0) { /* entry not found */
414 errorcode = VL_NOENT;
416 ubik_AbortTrans(trans);
419 if (tentry.flags & VLDELETED) { /* Entry is deleted! */
421 ubik_AbortTrans(trans);
422 return VL_ENTDELETED;
424 /* Convert from the internal to external form */
426 vlentry_to_nvldbentry(&tentry, (struct nvldbentry *)aentry);
428 vlentry_to_uvldbentry(&tentry, (struct uvldbentry *)aentry);
430 vlentry_to_vldbentry(&tentry, (struct vldbentry *)aentry);
431 return (ubik_EndTrans(trans));
435 SVL_GetEntryByID(rxcall, volid, voltype, aentry)
436 struct rx_call *rxcall;
437 afs_int32 volid, voltype;
438 vldbentry *aentry; /* entry data copied here */
440 COUNT_REQ(VLGETENTRYBYID);
441 return (GetEntryByID(rxcall, volid, voltype, (char *)aentry, 0, this_op));
445 SVL_GetEntryByIDN(rxcall, volid, voltype, aentry)
446 struct rx_call *rxcall;
447 afs_int32 volid, voltype;
448 nvldbentry *aentry; /* entry data copied here */
450 COUNT_REQ(VLGETENTRYBYIDN);
451 return (GetEntryByID(rxcall, volid, voltype, (char *)aentry, 1, this_op));
455 SVL_GetEntryByIDU(rxcall, volid, voltype, aentry)
456 struct rx_call *rxcall;
457 afs_int32 volid, voltype;
458 uvldbentry *aentry; /* entry data copied here */
460 COUNT_REQ(VLGETENTRYBYIDU);
461 return (GetEntryByID(rxcall, volid, voltype, (char *)aentry, 2, this_op));
466 /* returns true if the id is a decimal integer, in which case we interpret it
467 as an id. make the cache manager much simpler */
470 register char *aname;
473 while (tc = *aname++) {
474 if (tc > '9' || tc < '0')
480 /* Get a vldb entry given the volume's name; of course, very similar to VLGetEntryByID() above. */
481 GetEntryByName(rxcall, volname, aentry, new, this_op)
482 struct rx_call *rxcall;
484 char *aentry; /* entry data copied here */
487 struct ubik_trans *trans;
488 afs_int32 blockindex, errorcode;
489 struct nvlentry tentry;
491 if (NameIsId(volname)) {
492 return GetEntryByID(rxcall, atoi(volname), -1, aentry, new, this_op);
494 if (InvalidVolname(volname))
496 if (errorcode = Init_VLdbase(&trans, LOCKREAD, this_op))
498 VLog(5, ("GetVolumeByName %s (%d) %s\n", volname, new, rxinfo(rxcall)));
499 blockindex = FindByName(trans, volname, &tentry, &errorcode);
500 if (blockindex == 0) { /* entry not found */
502 errorcode = VL_NOENT;
504 ubik_AbortTrans(trans);
507 if (tentry.flags & VLDELETED) { /* Entry is deleted */
509 ubik_AbortTrans(trans);
510 return VL_ENTDELETED;
512 /* Convert to external entry representation */
514 vlentry_to_nvldbentry(&tentry, (struct nvldbentry *)aentry);
516 vlentry_to_uvldbentry(&tentry, (struct uvldbentry *)aentry);
518 vlentry_to_vldbentry(&tentry, (struct vldbentry *)aentry);
519 return (ubik_EndTrans(trans));
523 SVL_GetEntryByNameO(rxcall, volname, aentry)
524 struct rx_call *rxcall;
526 struct vldbentry *aentry; /* entry data copied here */
528 COUNT_REQ(VLGETENTRYBYNAME);
529 return (GetEntryByName(rxcall, volname, (char *)aentry, 0, this_op));
534 SVL_GetEntryByNameN(rxcall, volname, aentry)
535 struct rx_call *rxcall;
537 struct nvldbentry *aentry; /* entry data copied here */
539 COUNT_REQ(VLGETENTRYBYNAMEN);
540 return (GetEntryByName(rxcall, volname, (char *)aentry, 1, this_op));
544 SVL_GetEntryByNameU(rxcall, volname, aentry)
545 struct rx_call *rxcall;
547 struct uvldbentry *aentry; /* entry data copied here */
549 COUNT_REQ(VLGETENTRYBYNAMEU);
550 return (GetEntryByName(rxcall, volname, (char *)aentry, 2, this_op));
555 /* Get the current value of the maximum volume id and bump the volume id counter by Maxvolidbump. */
557 SVL_GetNewVolumeId(rxcall, Maxvolidbump, newvolumeid)
558 struct rx_call *rxcall;
559 afs_int32 Maxvolidbump;
560 afs_int32 *newvolumeid;
562 register afs_int32 errorcode, maxvolumeid;
563 struct ubik_trans *trans;
565 COUNT_REQ(VLGETNEWVOLUMEID);
566 if (!afsconf_SuperUser(vldb_confdir, rxcall, NULL))
569 if (Maxvolidbump < 0 || Maxvolidbump > MAXBUMPCOUNT)
570 END(VL_BADVOLIDBUMP);
572 if (errorcode = Init_VLdbase(&trans, LOCKWRITE, this_op))
575 *newvolumeid = maxvolumeid = ntohl(cheader.vital_header.MaxVolumeId);
576 maxvolumeid += Maxvolidbump;
577 VLog(1, ("GetNewVolid newmax=%d %s\n", maxvolumeid, rxinfo(rxcall)));
578 cheader.vital_header.MaxVolumeId = htonl(maxvolumeid);
579 if (write_vital_vlheader(trans)) {
582 errorcode = (ubik_EndTrans(trans));
587 ubik_AbortTrans(trans);
590 osi_auditU(rxcall, VLGetNewVolumeIdEvent, errorcode, AUD_END);
595 /* Simple replace the contents of the vldb entry, volid, with
596 * newentry. No individual checking/updating per field (alike
597 * VLUpdateEntry) is done. */
600 SVL_ReplaceEntry(rxcall, volid, voltype, newentry, releasetype)
601 struct rx_call *rxcall;
604 struct vldbentry *newentry;
605 afs_int32 releasetype;
607 struct ubik_trans *trans;
608 afs_int32 blockindex, errorcode, typeindex;
610 int hashVol[MAXTYPES];
611 struct nvlentry tentry;
613 COUNT_REQ(VLREPLACEENTRY);
614 for (typeindex = 0; typeindex < MAXTYPES; typeindex++)
615 hashVol[typeindex] = 0;
617 if (!afsconf_SuperUser(vldb_confdir, rxcall, NULL))
620 if (errorcode = check_vldbentry(newentry))
623 if (voltype != -1 && InvalidVoltype(voltype))
626 if (releasetype && InvalidReleasetype(releasetype))
627 END(VL_BADRELLOCKTYPE);
628 if (errorcode = Init_VLdbase(&trans, LOCKWRITE, this_op))
631 VLog(1, ("OReplace Volume %d %s\n", volid, rxinfo(rxcall)));
632 /* find vlentry we're changing */
633 blockindex = FindByID(trans, volid, voltype, &tentry, &errorcode);
634 if (blockindex == 0) { /* entry not found */
636 errorcode = VL_NOENT;
640 /* check that we're not trying to change the RW vol ID */
641 if (newentry->volumeId[RWVOL] != tentry.volumeId[RWVOL]) {
645 /* unhash volid entries if they're disappearing or changing.
646 * Remember if we need to hash in the new value (we don't have to
647 * rehash if volid stays same */
648 for (typeindex = ROVOL; typeindex <= BACKVOL; typeindex++) {
649 if (tentry.volumeId[typeindex] != newentry->volumeId[typeindex]) {
650 if (tentry.volumeId[typeindex])
652 UnhashVolid(trans, typeindex, blockindex, &tentry)) {
655 /* we must rehash new id if the id is different and the ID is nonzero */
656 hashVol[typeindex] = 1; /* must rehash this guy if he exists */
660 /* Rehash volname if it changes */
661 if (strcmp(newentry->name, tentry.name)) { /* Name changes; redo hashing */
662 if (errorcode = UnhashVolname(trans, blockindex, &tentry)) {
668 /* after this, tentry is new entry, not old one. vldbentry_to_vlentry
669 * doesn't touch hash chains */
670 if (errorcode = vldbentry_to_vlentry(trans, newentry, &tentry)) {
674 for (typeindex = ROVOL; typeindex <= BACKVOL; typeindex++) {
675 if (hashVol[typeindex] && tentry.volumeId[typeindex]) {
676 if (errorcode = HashVolid(trans, typeindex, blockindex, &tentry)) {
683 HashVolname(trans, blockindex, &tentry);
686 ReleaseEntry(&tentry, releasetype); /* Unlock entry if necessary */
687 if (vlentrywrite(trans, blockindex, &tentry, sizeof(tentry))) {
691 END(ubik_EndTrans(trans));
695 ubik_AbortTrans(trans);
698 osi_auditU(rxcall, VLReplaceVLEntryEvent, errorcode, AUD_LONG, volid,
704 SVL_ReplaceEntryN(rxcall, volid, voltype, newentry, releasetype)
705 struct rx_call *rxcall;
708 struct nvldbentry *newentry;
709 afs_int32 releasetype;
711 struct ubik_trans *trans;
712 afs_int32 blockindex, errorcode, typeindex;
714 int hashVol[MAXTYPES];
715 struct nvlentry tentry;
717 COUNT_REQ(VLREPLACEENTRYN);
718 for (typeindex = 0; typeindex < MAXTYPES; typeindex++)
719 hashVol[typeindex] = 0;
721 if (!afsconf_SuperUser(vldb_confdir, rxcall, NULL))
724 if (errorcode = check_nvldbentry(newentry))
727 if (voltype != -1 && InvalidVoltype(voltype))
730 if (releasetype && InvalidReleasetype(releasetype))
731 END(VL_BADRELLOCKTYPE);
732 if (errorcode = Init_VLdbase(&trans, LOCKWRITE, this_op))
735 VLog(1, ("Replace Volume %d %s\n", volid, rxinfo(rxcall)));
736 /* find vlentry we're changing */
737 blockindex = FindByID(trans, volid, voltype, &tentry, &errorcode);
738 if (blockindex == 0) { /* entry not found */
740 errorcode = VL_NOENT;
744 /* check that we're not trying to change the RW vol ID */
745 if (newentry->volumeId[RWVOL] != tentry.volumeId[RWVOL]) {
749 /* unhash volid entries if they're disappearing or changing.
750 * Remember if we need to hash in the new value (we don't have to
751 * rehash if volid stays same */
752 for (typeindex = ROVOL; typeindex <= BACKVOL; typeindex++) {
753 if (tentry.volumeId[typeindex] != newentry->volumeId[typeindex]) {
754 if (tentry.volumeId[typeindex])
756 UnhashVolid(trans, typeindex, blockindex, &tentry)) {
759 /* we must rehash new id if the id is different and the ID is nonzero */
760 hashVol[typeindex] = 1; /* must rehash this guy if he exists */
764 /* Rehash volname if it changes */
765 if (strcmp(newentry->name, tentry.name)) { /* Name changes; redo hashing */
766 if (errorcode = UnhashVolname(trans, blockindex, &tentry)) {
772 /* after this, tentry is new entry, not old one. vldbentry_to_vlentry
773 * doesn't touch hash chains */
774 if (errorcode = nvldbentry_to_vlentry(trans, newentry, &tentry)) {
778 for (typeindex = ROVOL; typeindex <= BACKVOL; typeindex++) {
779 if (hashVol[typeindex] && tentry.volumeId[typeindex]) {
780 if (errorcode = HashVolid(trans, typeindex, blockindex, &tentry)) {
787 HashVolname(trans, blockindex, &tentry);
790 ReleaseEntry(&tentry, releasetype); /* Unlock entry if necessary */
791 if (vlentrywrite(trans, blockindex, &tentry, sizeof(tentry))) {
795 END(ubik_EndTrans(trans));
799 ubik_AbortTrans(trans);
802 osi_auditU(rxcall, VLReplaceVLEntryEvent, errorcode, AUD_LONG, volid,
808 /* Update a vldb entry (accessed thru its volume id). Almost all of the entry's fields can be modified in a single call by setting the appropriate bits in the Mask field in VldbUpdateentry. */
809 /* this routine may never have been tested; use replace entry instead unless you're brave */
811 SVL_UpdateEntry(rxcall, volid, voltype, updateentry, releasetype)
812 struct rx_call *rxcall;
815 afs_int32 releasetype;
816 struct VldbUpdateEntry *updateentry; /* Update entry copied here */
818 struct ubik_trans *trans;
819 afs_int32 blockindex, errorcode;
820 struct nvlentry tentry;
822 COUNT_REQ(VLUPDATEENTRY);
823 if (!afsconf_SuperUser(vldb_confdir, rxcall, NULL))
825 if ((voltype != -1) && (InvalidVoltype(voltype)))
827 if (releasetype && InvalidReleasetype(releasetype))
828 END(VL_BADRELLOCKTYPE);
829 if (errorcode = Init_VLdbase(&trans, LOCKWRITE, this_op))
832 VLog(1, ("Update Volume %d %s\n", volid, rxinfo(rxcall)));
833 blockindex = FindByID(trans, volid, voltype, &tentry, &errorcode);
834 if (blockindex == 0) { /* entry not found */
836 errorcode = VL_NOENT;
840 /* Do the actual updating of the entry, tentry. */
842 get_vldbupdateentry(trans, blockindex, updateentry, &tentry)) {
846 ReleaseEntry(&tentry, releasetype); /* Unlock entry if necessary */
847 if (vlentrywrite(trans, blockindex, &tentry, sizeof(tentry))) {
850 END(ubik_EndTrans(trans));
854 ubik_AbortTrans(trans);
857 osi_auditU(rxcall, VLUpdateEntryEvent, errorcode, AUD_LONG, volid,
864 SVL_UpdateEntryByName(rxcall, volname, updateentry, releasetype)
865 struct rx_call *rxcall;
867 afs_int32 releasetype;
868 struct VldbUpdateEntry *updateentry; /* Update entry copied here */
870 struct ubik_trans *trans;
871 afs_int32 blockindex, errorcode;
872 struct nvlentry tentry;
874 COUNT_REQ(VLUPDATEENTRYBYNAME);
875 if (!afsconf_SuperUser(vldb_confdir, rxcall, NULL))
877 if (releasetype && InvalidReleasetype(releasetype))
878 END(VL_BADRELLOCKTYPE);
879 if (errorcode = Init_VLdbase(&trans, LOCKWRITE, this_op))
882 blockindex = FindByName(trans, volname, &tentry, &errorcode);
883 if (blockindex == 0) { /* entry not found */
885 errorcode = VL_NOENT;
889 /* Do the actual updating of the entry, tentry. */
891 get_vldbupdateentry(trans, blockindex, updateentry, &tentry)) {
895 ReleaseEntry(&tentry, releasetype); /* Unlock entry if necessary */
896 if (vlentrywrite(trans, blockindex, &tentry, sizeof(tentry))) {
899 END(ubik_EndTrans(trans));
903 ubik_AbortTrans(trans);
906 osi_auditU(rxcall, VLUpdateEntryEvent, errorcode, AUD_LONG, -1, AUD_END);
911 /* Set a lock to the vldb entry for volid (of type voltype if not -1). */
913 SVL_SetLock(rxcall, volid, voltype, voloper)
914 struct rx_call *rxcall;
919 afs_int32 timestamp, blockindex, errorcode;
920 struct ubik_trans *trans;
921 struct nvlentry tentry;
923 COUNT_REQ(VLSETLOCK);
924 if (!afsconf_SuperUser(vldb_confdir, rxcall, NULL))
926 if ((voltype != -1) && (InvalidVoltype(voltype)))
928 if (InvalidOperation(voloper))
930 if (errorcode = Init_VLdbase(&trans, LOCKWRITE, this_op))
933 VLog(1, ("SetLock Volume %d %s\n", volid, rxinfo(rxcall)));
934 blockindex = FindByID(trans, volid, voltype, &tentry, &errorcode);
935 if (blockindex == NULLO) {
937 errorcode = VL_NOENT;
940 if (tentry.flags & VLDELETED) {
941 ABORT(VL_ENTDELETED);
943 timestamp = FT_ApproxTime();
945 /* Check if entry is already locked; note that we unlock any entry
946 * locked more than MAXLOCKTIME seconds */
947 if ((tentry.LockTimestamp)
948 && ((timestamp - tentry.LockTimestamp) < MAXLOCKTIME)) {
949 ABORT(VL_ENTRYLOCKED);
952 /* Consider it an unlocked entry: set current timestamp, caller
953 * and active vol operation */
954 tentry.LockTimestamp = timestamp;
955 tentry.LockAfsId = 0; /* Not implemented yet */
956 if (tentry.flags & VLOP_RELEASE) {
959 tentry.flags &= ~VLOP_ALLOPERS; /* Clear any possible older operation bit */
960 tentry.flags |= voloper;
962 if (vlentrywrite(trans, blockindex, &tentry, sizeof(tentry))) {
965 END(ubik_EndTrans(trans));
969 ubik_AbortTrans(trans);
972 osi_auditU(rxcall, VLSetLockEvent, errorcode, AUD_LONG, volid, AUD_END);
977 /* Release an already locked vldb entry. Releasetype determines what
978 * fields (afsid and/or volume operation) will be cleared along with
979 * the lock time stamp. */
982 SVL_ReleaseLock(rxcall, volid, voltype, releasetype)
983 struct rx_call *rxcall;
986 afs_int32 releasetype;
988 afs_int32 blockindex, errorcode;
989 struct ubik_trans *trans;
990 struct nvlentry tentry;
992 COUNT_REQ(VLRELEASELOCK);
993 if (!afsconf_SuperUser(vldb_confdir, rxcall, NULL))
995 if ((voltype != -1) && (InvalidVoltype(voltype)))
997 if (releasetype && InvalidReleasetype(releasetype))
998 END(VL_BADRELLOCKTYPE);
999 if (errorcode = Init_VLdbase(&trans, LOCKWRITE, this_op))
1002 VLog(1, ("ReleaseLock Volume %d %s\n", volid, rxinfo(rxcall)));
1003 blockindex = FindByID(trans, volid, voltype, &tentry, &errorcode);
1004 if (blockindex == NULLO) {
1006 errorcode = VL_NOENT;
1009 if (tentry.flags & VLDELETED) {
1010 ABORT(VL_ENTDELETED);
1013 ReleaseEntry(&tentry, releasetype); /* Unlock the appropriate fields */
1014 if (vlentrywrite(trans, blockindex, &tentry, sizeof(tentry))) {
1017 END(ubik_EndTrans(trans));
1021 ubik_AbortTrans(trans);
1024 osi_auditU(rxcall, VLReleaseLockEvent, errorcode, AUD_LONG, volid,
1030 /* ListEntry returns a single vldb entry, aentry, with offset previous_index; the remaining parameters (i.e. next_index) are used so that sequential calls to this routine will get the next (all) vldb entries. */
1032 SVL_ListEntry(rxcall, previous_index, count, next_index, aentry)
1033 struct rx_call *rxcall;
1034 afs_int32 previous_index;
1036 afs_int32 *next_index;
1037 struct vldbentry *aentry;
1040 struct ubik_trans *trans;
1041 struct nvlentry tentry;
1043 COUNT_REQ(VLLISTENTRY);
1044 if (errorcode = Init_VLdbase(&trans, LOCKREAD, this_op))
1046 VLog(25, ("OListEntry index=%d %s\n", previous_index, rxinfo(rxcall)));
1047 *next_index = NextEntry(trans, previous_index, &tentry, count);
1049 vlentry_to_vldbentry(&tentry, aentry);
1050 return (ubik_EndTrans(trans));
1053 /* ListEntry returns a single vldb entry, aentry, with offset previous_index; the remaining parameters (i.e. next_index) are used so that sequential calls to this routine will get the next (all) vldb entries. */
1055 SVL_ListEntryN(rxcall, previous_index, count, next_index, aentry)
1056 struct rx_call *rxcall;
1057 afs_int32 previous_index;
1059 afs_int32 *next_index;
1060 struct nvldbentry *aentry;
1063 struct ubik_trans *trans;
1064 struct nvlentry tentry;
1066 COUNT_REQ(VLLISTENTRYN);
1067 if (errorcode = Init_VLdbase(&trans, LOCKREAD, this_op))
1069 VLog(25, ("ListEntry index=%d %s\n", previous_index, rxinfo(rxcall)));
1070 *next_index = NextEntry(trans, previous_index, &tentry, count);
1072 vlentry_to_nvldbentry(&tentry, aentry);
1073 return (ubik_EndTrans(trans));
1077 /* Retrieves in vldbentries all vldb entries that match the specified attributes (by server number, partition, volume type, and flag); if volume id is specified then the associated list for that entry is returned. CAUTION: This could be a very expensive call since in most cases sequential search of all vldb entries is performed. */
1079 SVL_ListAttributes(rxcall, attributes, nentries, vldbentries)
1080 struct rx_call *rxcall;
1081 struct VldbListByAttributes *attributes;
1082 afs_int32 *nentries;
1083 bulkentries *vldbentries;
1085 int errorcode, allocCount = 0;
1086 struct ubik_trans *trans;
1087 struct nvlentry tentry;
1088 struct vldbentry *Vldbentry = 0, *VldbentryFirst = 0, *VldbentryLast = 0;
1091 COUNT_REQ(VLLISTATTRIBUTES);
1092 vldbentries->bulkentries_val = 0;
1093 vldbentries->bulkentries_len = *nentries = 0;
1094 if (errorcode = Init_VLdbase(&trans, LOCKREAD, this_op))
1096 allocCount = VLDBALLOCCOUNT;
1097 Vldbentry = VldbentryFirst = vldbentries->bulkentries_val =
1098 (vldbentry *) malloc(allocCount * sizeof(vldbentry));
1099 if (Vldbentry == NULL) {
1101 ubik_AbortTrans(trans);
1104 VldbentryLast = VldbentryFirst + allocCount;
1105 /* Handle the attribute by volume id totally separate of the rest (thus additional Mask values are ignored if VLLIST_VOLUMEID is set!) */
1106 if (attributes->Mask & VLLIST_VOLUMEID) {
1107 afs_int32 blockindex;
1110 FindByID(trans, attributes->volumeid, -1, &tentry, &errorcode);
1111 if (blockindex == 0) {
1113 errorcode = VL_NOENT;
1115 ubik_AbortTrans(trans);
1116 if (vldbentries->bulkentries_val)
1117 free((char *)vldbentries->bulkentries_val);
1118 vldbentries->bulkentries_val = 0;
1119 vldbentries->bulkentries_len = 0;
1123 put_attributeentry(&Vldbentry, &VldbentryFirst, &VldbentryLast,
1124 vldbentries, &tentry, nentries, &allocCount)) {
1126 ubik_AbortTrans(trans);
1127 if (vldbentries->bulkentries_val)
1128 free((char *)vldbentries->bulkentries_val);
1129 vldbentries->bulkentries_val = 0;
1130 vldbentries->bulkentries_len = 0;
1131 return VL_SIZEEXCEEDED;
1134 afs_int32 nextblockindex = 0, count = 0, k, match = 0;
1135 while (nextblockindex =
1136 NextEntry(trans, nextblockindex, &tentry, &count)) {
1137 if (++pollcount > 50) {
1142 if (attributes->Mask & VLLIST_SERVER) {
1145 IpAddrToRelAddr(attributes->server,
1146 (struct ubik_trans *)0)) == -1)
1148 for (k = 0; k < OMAXNSERVERS; k++) {
1149 if (tentry.serverNumber[k] == BADSERVERID)
1151 if (tentry.serverNumber[k] == serverindex) {
1159 if (attributes->Mask & VLLIST_PARTITION) {
1161 if (tentry.serverPartition[k] != attributes->partition)
1164 for (k = 0; k < OMAXNSERVERS; k++) {
1165 if (tentry.serverNumber[k] == BADSERVERID)
1167 if (tentry.serverPartition[k] ==
1168 attributes->partition) {
1178 if (attributes->Mask & VLLIST_FLAG) {
1179 if (!(tentry.flags & attributes->flag))
1183 put_attributeentry(&Vldbentry, &VldbentryFirst,
1184 &VldbentryLast, vldbentries, &tentry,
1185 nentries, &allocCount)) {
1187 ubik_AbortTrans(trans);
1188 if (vldbentries->bulkentries_val)
1189 free((char *)vldbentries->bulkentries_val);
1190 vldbentries->bulkentries_val = 0;
1191 vldbentries->bulkentries_len = 0;
1196 if (vldbentries->bulkentries_len
1197 && (allocCount > vldbentries->bulkentries_len)) {
1199 vldbentries->bulkentries_val =
1200 (vldbentry *) realloc(vldbentries->bulkentries_val,
1201 vldbentries->bulkentries_len *
1203 if (vldbentries->bulkentries_val == NULL) {
1205 ubik_AbortTrans(trans);
1210 ("ListAttrs nentries=%d %s\n", vldbentries->bulkentries_len,
1212 return (ubik_EndTrans(trans));
1216 SVL_ListAttributesN(rxcall, attributes, nentries, vldbentries)
1217 struct rx_call *rxcall;
1218 struct VldbListByAttributes *attributes;
1219 afs_int32 *nentries;
1220 nbulkentries *vldbentries;
1222 int errorcode, allocCount = 0;
1223 struct ubik_trans *trans;
1224 struct nvlentry tentry;
1225 struct nvldbentry *Vldbentry = 0, *VldbentryFirst = 0, *VldbentryLast = 0;
1228 COUNT_REQ(VLLISTATTRIBUTESN);
1229 vldbentries->nbulkentries_val = 0;
1230 vldbentries->nbulkentries_len = *nentries = 0;
1231 if (errorcode = Init_VLdbase(&trans, LOCKREAD, this_op))
1233 allocCount = VLDBALLOCCOUNT;
1234 Vldbentry = VldbentryFirst = vldbentries->nbulkentries_val =
1235 (nvldbentry *) malloc(allocCount * sizeof(nvldbentry));
1236 if (Vldbentry == NULL) {
1238 ubik_AbortTrans(trans);
1241 VldbentryLast = VldbentryFirst + allocCount;
1242 /* Handle the attribute by volume id totally separate of the rest (thus additional Mask values are ignored if VLLIST_VOLUMEID is set!) */
1243 if (attributes->Mask & VLLIST_VOLUMEID) {
1244 afs_int32 blockindex;
1247 FindByID(trans, attributes->volumeid, -1, &tentry, &errorcode);
1248 if (blockindex == 0) {
1250 errorcode = VL_NOENT;
1252 ubik_AbortTrans(trans);
1253 if (vldbentries->nbulkentries_val)
1254 free((char *)vldbentries->nbulkentries_val);
1255 vldbentries->nbulkentries_val = 0;
1256 vldbentries->nbulkentries_len = 0;
1260 put_nattributeentry(&Vldbentry, &VldbentryFirst, &VldbentryLast,
1261 vldbentries, &tentry, 0, 0, nentries,
1264 ubik_AbortTrans(trans);
1265 if (vldbentries->nbulkentries_val)
1266 free((char *)vldbentries->nbulkentries_val);
1267 vldbentries->nbulkentries_val = 0;
1268 vldbentries->nbulkentries_len = 0;
1269 return VL_SIZEEXCEEDED;
1272 afs_int32 nextblockindex = 0, count = 0, k, match = 0;
1273 while (nextblockindex =
1274 NextEntry(trans, nextblockindex, &tentry, &count)) {
1275 if (++pollcount > 50) {
1281 if (attributes->Mask & VLLIST_SERVER) {
1284 IpAddrToRelAddr(attributes->server,
1285 (struct ubik_trans *)0)) == -1)
1287 for (k = 0; k < NMAXNSERVERS; k++) {
1288 if (tentry.serverNumber[k] == BADSERVERID)
1290 if (tentry.serverNumber[k] == serverindex) {
1298 if (attributes->Mask & VLLIST_PARTITION) {
1300 if (tentry.serverPartition[k] != attributes->partition)
1303 for (k = 0; k < NMAXNSERVERS; k++) {
1304 if (tentry.serverNumber[k] == BADSERVERID)
1306 if (tentry.serverPartition[k] ==
1307 attributes->partition) {
1317 if (attributes->Mask & VLLIST_FLAG) {
1318 if (!(tentry.flags & attributes->flag))
1322 put_nattributeentry(&Vldbentry, &VldbentryFirst,
1323 &VldbentryLast, vldbentries, &tentry, 0,
1324 0, nentries, &allocCount)) {
1326 ubik_AbortTrans(trans);
1327 if (vldbentries->nbulkentries_val)
1328 free((char *)vldbentries->nbulkentries_val);
1329 vldbentries->nbulkentries_val = 0;
1330 vldbentries->nbulkentries_len = 0;
1335 if (vldbentries->nbulkentries_len
1336 && (allocCount > vldbentries->nbulkentries_len)) {
1338 vldbentries->nbulkentries_val =
1339 (nvldbentry *) realloc(vldbentries->nbulkentries_val,
1340 vldbentries->nbulkentries_len *
1341 sizeof(nvldbentry));
1342 if (vldbentries->nbulkentries_val == NULL) {
1344 ubik_AbortTrans(trans);
1349 ("NListAttrs nentries=%d %s\n", vldbentries->nbulkentries_len,
1351 return (ubik_EndTrans(trans));
1356 SVL_ListAttributesN2(rxcall, attributes, name, startindex, nentries,
1357 vldbentries, nextstartindex)
1358 struct rx_call *rxcall;
1359 struct VldbListByAttributes *attributes;
1360 char *name; /* Wildcarded volume name */
1361 afs_int32 startindex;
1362 afs_int32 *nentries;
1363 nbulkentries *vldbentries;
1364 afs_int32 *nextstartindex;
1366 int errorcode = 0, maxCount = VLDBALLOCCOUNT;
1367 struct ubik_trans *trans;
1368 struct nvlentry tentry;
1369 struct nvldbentry *Vldbentry = 0, *VldbentryFirst = 0, *VldbentryLast = 0;
1370 afs_int32 blockindex = 0, count = 0, k, match, matchindex;
1371 int serverindex = -1; /* no server found */
1372 int findserver = 0, findpartition = 0, findflag = 0, findname = 0;
1375 int namematchRWBK, namematchRO, thismatch, matchtype;
1376 char volumename[VL_MAXNAMELEN];
1377 #ifdef HAVE_POSIX_REGEX
1379 int need_regfree = 0;
1382 COUNT_REQ(VLLISTATTRIBUTESN2);
1383 vldbentries->nbulkentries_val = 0;
1384 vldbentries->nbulkentries_len = 0;
1386 *nextstartindex = -1;
1388 errorcode = Init_VLdbase(&trans, LOCKREAD, this_op);
1392 Vldbentry = VldbentryFirst = vldbentries->nbulkentries_val =
1393 (nvldbentry *) malloc(maxCount * sizeof(nvldbentry));
1394 if (Vldbentry == NULL) {
1396 ubik_AbortTrans(trans);
1400 VldbentryLast = VldbentryFirst + maxCount;
1402 /* Handle the attribute by volume id totally separate of the rest
1403 * (thus additional Mask values are ignored if VLLIST_VOLUMEID is set!)
1405 if (attributes->Mask & VLLIST_VOLUMEID) {
1407 FindByID(trans, attributes->volumeid, -1, &tentry, &errorcode);
1408 if (blockindex == 0) {
1410 errorcode = VL_NOENT;
1413 put_nattributeentry(&Vldbentry, &VldbentryFirst,
1414 &VldbentryLast, vldbentries, &tentry, 0,
1415 0, nentries, &maxCount);
1421 /* Search each entry in the database and return all entries
1422 * that match the request. It checks volumename (with
1423 * wildcarding), entry flags, server, and partition.
1426 /* Get the server index for matching server address */
1427 if (attributes->Mask & VLLIST_SERVER) {
1429 IpAddrToRelAddr(attributes->server, (struct ubik_trans *)0);
1430 if (serverindex == -1)
1434 findpartition = ((attributes->Mask & VLLIST_PARTITION) ? 1 : 0);
1435 findflag = ((attributes->Mask & VLLIST_FLAG) ? 1 : 0);
1436 if (name && (strcmp(name, ".*") != 0) && (strcmp(name, "") != 0)) {
1437 sprintf(volumename, "^%s$", name);
1438 #ifdef HAVE_POSIX_REGEX
1439 if (regcomp(&re, volumename, REG_NOSUB) != 0) {
1440 errorcode = VL_BADNAME;
1445 t = (char *)re_comp(volumename);
1447 errorcode = VL_BADNAME;
1454 /* Read each entry and see if it is the one we want */
1455 blockindex = startindex;
1456 while (blockindex = NextEntry(trans, blockindex, &tentry, &count)) {
1457 if (++pollcount > 50) {
1462 /* Step through each server index searching for a match.
1463 * Match to an existing RW, BK, or RO volume name (preference
1464 * is in this order). Remember which index we matched against.
1466 namematchRWBK = namematchRO = 0; /* 0->notTried; 1->match; 2->noMatch */
1470 && (tentry.serverNumber[k] != BADSERVERID)); k++) {
1471 thismatch = 0; /* does this index match */
1473 /* Match against the RW or BK volume name. Remember
1474 * results in namematchRWBK. Prefer RW over BK.
1476 if (tentry.serverFlags[k] & VLSF_RWVOL) {
1477 /* Does the name match the RW name */
1478 if (tentry.flags & VLF_RWEXISTS) {
1480 sprintf(volumename, "%s", tentry.name);
1481 #ifdef HAVE_POSIX_REGEX
1482 if (regexec(&re, volumename, 0, NULL, 0) == 0) {
1483 thismatch = VLSF_RWVOL;
1486 if (re_exec(volumename)) {
1487 thismatch = VLSF_RWVOL;
1491 thismatch = VLSF_RWVOL;
1495 /* Does the name match the BK name */
1496 if (!thismatch && (tentry.flags & VLF_BACKEXISTS)) {
1498 sprintf(volumename, "%s.backup", tentry.name);
1499 #ifdef HAVE_POSIX_REGEX
1500 if (regexec(&re, volumename, 0, NULL, 0) == 0) {
1501 thismatch = VLSF_BACKVOL;
1504 if (re_exec(volumename)) {
1505 thismatch = VLSF_BACKVOL;
1509 thismatch = VLSF_BACKVOL;
1513 namematchRWBK = (thismatch ? 1 : 2);
1516 /* Match with the RO volume name. Compare once and
1517 * remember results in namematchRO. Note that this will
1518 * pick up entries marked NEWREPSITEs and DONTUSE.
1521 if (tentry.flags & VLF_ROEXISTS) {
1525 ((namematchRO == 1) ? VLSF_ROVOL : 0);
1527 sprintf(volumename, "%s.readonly",
1529 #ifdef HAVE_POSIX_REGEX
1530 if (regexec(&re, volumename, 0, NULL, 0) == 0) {
1531 thismatch = VLSF_ROVOL;
1534 if (re_exec(volumename))
1535 thismatch = VLSF_ROVOL;
1539 thismatch = VLSF_ROVOL;
1542 namematchRO = (thismatch ? 1 : 2);
1545 /* Is there a server match */
1546 if (thismatch && findserver
1547 && (tentry.serverNumber[k] != serverindex))
1550 /* Is there a partition match */
1551 if (thismatch && findpartition
1552 && (tentry.serverPartition[k] != attributes->partition))
1555 /* Is there a flag match */
1556 if (thismatch && findflag
1557 && !(tentry.flags & attributes->flag))
1560 /* We found a match. Remember the index, and type */
1564 matchtype = thismatch;
1567 /* Since we prefer RW and BK volume matches over RO matches,
1568 * if we have already checked the RWBK name, then we already
1569 * found the best match and so end the search.
1571 * If we tried matching against the RW, BK, and RO volume names
1572 * and both failed, then we end the search (none will match).
1574 if ((match && namematchRWBK)
1575 || ((namematchRWBK == 2) && (namematchRO == 2)))
1579 /* Passed all the tests. Take it */
1582 put_nattributeentry(&Vldbentry, &VldbentryFirst,
1583 &VldbentryLast, vldbentries, &tentry,
1584 matchtype, matchindex, nentries,
1589 if (*nentries >= maxCount)
1590 break; /* collected the max */
1593 *nextstartindex = (blockindex ? blockindex : -1);
1597 #ifdef HAVE_POSIX_REGEX
1604 ubik_AbortTrans(trans);
1605 if (vldbentries->nbulkentries_val)
1606 free((char *)vldbentries->nbulkentries_val);
1607 vldbentries->nbulkentries_val = 0;
1608 vldbentries->nbulkentries_len = 0;
1609 *nextstartindex = -1;
1613 ("N2ListAttrs nentries=%d %s\n", vldbentries->nbulkentries_len,
1615 return (ubik_EndTrans(trans));
1620 /* Retrieves in vldbentries all vldb entries that match the specified
1621 * attributes (by server number, partition, volume type, and flag); if
1622 * volume id is specified then the associated list for that entry is
1623 * returned. CAUTION: This could be a very expensive call since in most
1624 * cases sequential search of all vldb entries is performed.
1627 SVL_LinkedList(rxcall, attributes, nentries, vldbentries)
1628 struct rx_call *rxcall;
1629 struct VldbListByAttributes *attributes;
1630 afs_int32 *nentries;
1631 vldb_list *vldbentries;
1634 struct ubik_trans *trans;
1635 struct nvlentry tentry;
1636 vldblist vllist, *vllistptr;
1637 afs_int32 blockindex, count, k, match;
1641 COUNT_REQ(VLLINKEDLIST);
1642 if (errorcode = Init_VLdbase(&trans, LOCKREAD, this_op))
1646 vldbentries->node = NULL;
1647 vllistptr = &vldbentries->node;
1649 /* List by volumeid */
1650 if (attributes->Mask & VLLIST_VOLUMEID) {
1652 FindByID(trans, attributes->volumeid, -1, &tentry, &errorcode);
1655 ubik_AbortTrans(trans);
1656 return (errorcode ? errorcode : VL_NOENT);
1659 vllist = (single_vldbentry *) malloc(sizeof(single_vldbentry));
1660 if (vllist == NULL) {
1662 ubik_AbortTrans(trans);
1665 vlentry_to_vldbentry(&tentry, &vllist->VldbEntry);
1666 vllist->next_vldb = NULL;
1668 *vllistptr = vllist; /* Thread onto list */
1669 vllistptr = &vllist->next_vldb;
1673 /* Search by server, partition, and flags */
1675 for (blockindex = NextEntry(trans, 0, &tentry, &count); blockindex;
1676 blockindex = NextEntry(trans, blockindex, &tentry, &count)) {
1679 if (++pollcount > 50) {
1684 /* Does this volume exist on the desired server */
1685 if (attributes->Mask & VLLIST_SERVER) {
1687 IpAddrToRelAddr(attributes->server,
1688 (struct ubik_trans *)0);
1689 if (serverindex == -1)
1691 for (k = 0; k < OMAXNSERVERS; k++) {
1692 if (tentry.serverNumber[k] == BADSERVERID)
1694 if (tentry.serverNumber[k] == serverindex) {
1703 /* Does this volume exist on the desired partition */
1704 if (attributes->Mask & VLLIST_PARTITION) {
1706 if (tentry.serverPartition[k] != attributes->partition)
1709 for (k = 0; k < OMAXNSERVERS; k++) {
1710 if (tentry.serverNumber[k] == BADSERVERID)
1712 if (tentry.serverPartition[k] ==
1713 attributes->partition) {
1723 /* Does this volume have the desired flags */
1724 if (attributes->Mask & VLLIST_FLAG) {
1725 if (!(tentry.flags & attributes->flag))
1729 vllist = (single_vldbentry *) malloc(sizeof(single_vldbentry));
1730 if (vllist == NULL) {
1732 ubik_AbortTrans(trans);
1735 vlentry_to_vldbentry(&tentry, &vllist->VldbEntry);
1736 vllist->next_vldb = NULL;
1738 *vllistptr = vllist; /* Thread onto list */
1739 vllistptr = &vllist->next_vldb;
1741 if (smallMem && (*nentries >= VLDBALLOCCOUNT)) {
1743 ubik_AbortTrans(trans);
1744 return VL_SIZEEXCEEDED;
1749 return (ubik_EndTrans(trans));
1753 SVL_LinkedListN(rxcall, attributes, nentries, vldbentries)
1754 struct rx_call *rxcall;
1755 struct VldbListByAttributes *attributes;
1756 afs_int32 *nentries;
1757 nvldb_list *vldbentries;
1760 struct ubik_trans *trans;
1761 struct nvlentry tentry;
1762 nvldblist vllist, *vllistptr;
1763 afs_int32 blockindex, count, k, match;
1767 COUNT_REQ(VLLINKEDLISTN);
1768 if (errorcode = Init_VLdbase(&trans, LOCKREAD, this_op))
1772 vldbentries->node = NULL;
1773 vllistptr = &vldbentries->node;
1775 /* List by volumeid */
1776 if (attributes->Mask & VLLIST_VOLUMEID) {
1778 FindByID(trans, attributes->volumeid, -1, &tentry, &errorcode);
1781 ubik_AbortTrans(trans);
1782 return (errorcode ? errorcode : VL_NOENT);
1785 vllist = (single_nvldbentry *) malloc(sizeof(single_nvldbentry));
1786 if (vllist == NULL) {
1788 ubik_AbortTrans(trans);
1791 vlentry_to_nvldbentry(&tentry, &vllist->VldbEntry);
1792 vllist->next_vldb = NULL;
1794 *vllistptr = vllist; /* Thread onto list */
1795 vllistptr = &vllist->next_vldb;
1799 /* Search by server, partition, and flags */
1801 for (blockindex = NextEntry(trans, 0, &tentry, &count); blockindex;
1802 blockindex = NextEntry(trans, blockindex, &tentry, &count)) {
1805 if (++pollcount > 50) {
1810 /* Does this volume exist on the desired server */
1811 if (attributes->Mask & VLLIST_SERVER) {
1813 IpAddrToRelAddr(attributes->server,
1814 (struct ubik_trans *)0);
1815 if (serverindex == -1)
1817 for (k = 0; k < NMAXNSERVERS; k++) {
1818 if (tentry.serverNumber[k] == BADSERVERID)
1820 if (tentry.serverNumber[k] == serverindex) {
1829 /* Does this volume exist on the desired partition */
1830 if (attributes->Mask & VLLIST_PARTITION) {
1832 if (tentry.serverPartition[k] != attributes->partition)
1835 for (k = 0; k < NMAXNSERVERS; k++) {
1836 if (tentry.serverNumber[k] == BADSERVERID)
1838 if (tentry.serverPartition[k] ==
1839 attributes->partition) {
1849 /* Does this volume have the desired flags */
1850 if (attributes->Mask & VLLIST_FLAG) {
1851 if (!(tentry.flags & attributes->flag))
1855 vllist = (single_nvldbentry *) malloc(sizeof(single_nvldbentry));
1856 if (vllist == NULL) {
1858 ubik_AbortTrans(trans);
1861 vlentry_to_nvldbentry(&tentry, &vllist->VldbEntry);
1862 vllist->next_vldb = NULL;
1864 *vllistptr = vllist; /* Thread onto list */
1865 vllistptr = &vllist->next_vldb;
1867 if (smallMem && (*nentries >= VLDBALLOCCOUNT)) {
1869 ubik_AbortTrans(trans);
1870 return VL_SIZEEXCEEDED;
1875 return (ubik_EndTrans(trans));
1878 /* Get back vldb header statistics (allocs, frees, maxvolumeid, totalentries, etc) and dynamic statistics (number of requests and/or aborts per remote procedure call, etc) */
1880 SVL_GetStats(rxcall, stats, vital_header)
1881 struct rx_call *rxcall;
1883 vital_vlheader *vital_header;
1885 register afs_int32 errorcode;
1886 struct ubik_trans *trans;
1888 COUNT_REQ(VLGETSTATS);
1890 /* Allow users to get statistics freely */
1891 if (!afsconf_SuperUser(vldb_confdir, rxcall, NULL)) /* Must be in 'UserList' to use */
1894 if (errorcode = Init_VLdbase(&trans, LOCKREAD, this_op))
1896 VLog(5, ("GetStats %s\n", rxinfo(rxcall)));
1897 memcpy((char *)vital_header, (char *)&cheader.vital_header,
1898 sizeof(vital_vlheader));
1899 memcpy((char *)stats, (char *)&dynamic_statistics, sizeof(vldstats));
1900 return (ubik_EndTrans(trans));
1903 /* Get the list of file server addresses from the VLDB. Currently it's pretty
1904 * easy to do. In the future, it might require a little bit of grunging
1905 * through the VLDB, but that's life.
1908 SVL_GetAddrs(rxcall, Handle, spare2, spare3, nentries, addrsp)
1909 struct rx_call *rxcall;
1910 afs_int32 Handle, spare2;
1911 struct VLCallBack *spare3;
1912 afs_int32 *nentries;
1915 register afs_int32 errorcode;
1916 struct ubik_trans *trans;
1920 COUNT_REQ(VLGETADDRS);
1921 addrsp->bulkaddrs_len = *nentries = 0;
1922 addrsp->bulkaddrs_val = 0;
1923 memset(spare3, 0, sizeof(struct VLCallBack));
1925 if (errorcode = Init_VLdbase(&trans, LOCKREAD, this_op))
1928 VLog(5, ("GetAddrs\n"));
1929 addrsp->bulkaddrs_val = taddrp =
1930 (afs_uint32 *) malloc(sizeof(afs_int32) * (MAXSERVERID + 1));
1931 nservers = *nentries = addrsp->bulkaddrs_len = 0;
1935 ubik_AbortTrans(trans);
1939 for (i = 0; i <= MAXSERVERID; i++) {
1940 if (*taddrp = ntohl(cheader.IpMappedAddr[i])) {
1946 addrsp->bulkaddrs_len = *nentries = nservers;
1947 return (ubik_EndTrans(trans));
1950 #define PADDR(addr) VLog(0,("%d.%d.%d.%d", (addr>>24)&0xff, (addr>>16)&0xff, (addr>>8) &0xff, addr&0xff));
1953 SVL_RegisterAddrs(rxcall, uuidp, spare1, addrsp)
1954 struct rx_call *rxcall;
1960 struct ubik_trans *trans;
1961 int cnt, h, i, j, k, m, base, index;
1962 struct extentaddr *exp = 0, *tex;
1964 afs_uint32 addrs[VL_MAXIPADDRS_PERMH];
1966 int count, willChangeEntry, foundUuidEntry, willReplaceCnt;
1967 int WillReplaceEntry, WillChange[MAXSERVERID + 1], FoundUuid,
1971 COUNT_REQ(VLREGADDR);
1972 if (!afsconf_SuperUser(vldb_confdir, rxcall, NULL))
1974 if (code = Init_VLdbase(&trans, LOCKWRITE, this_op))
1977 /* Eliminate duplicates from IP address list */
1978 for (k = 0, cnt = 0; k < addrsp->bulkaddrs_len; k++) {
1979 if (addrsp->bulkaddrs_val[k] == 0)
1981 for (m = 0; m < cnt; m++) {
1982 if (addrs[m] == addrsp->bulkaddrs_val[k])
1986 if (m == VL_MAXIPADDRS_PERMH) {
1988 ("Number of addresses exceeds %d. Cannot register IP addr 0x%x in VLDB\n",
1989 VL_MAXIPADDRS_PERMH, addrsp->bulkaddrs_val[k]));
1991 addrs[m] = addrsp->bulkaddrs_val[k];
1997 ubik_AbortTrans(trans);
1998 return VL_INDEXERANGE;
2004 /* For each server registered within the VLDB */
2005 for (srvidx = 0; srvidx <= MAXSERVERID; srvidx++) {
2006 willChangeEntry = 0;
2007 WillReplaceEntry = 1;
2008 if ((HostAddress[srvidx] & 0xff000000) == 0xff000000) {
2009 /* The server is registered as a multihomed */
2010 base = (HostAddress[srvidx] >> 16) & 0xff;
2011 index = HostAddress[srvidx] & 0x0000ffff;
2012 if (base >= VL_MAX_ADDREXTBLKS) {
2014 ("Internal error: Multihome extent base is too large. Base %d index %d\n",
2018 if (index >= VL_MHSRV_PERBLK) {
2020 ("Internal error: Multihome extent index is too large. Base %d index %d\n",
2024 if (!ex_addr[base]) {
2026 ("Internal error: Multihome extent does not exist. Base %d\n",
2031 /* See if the addresses to register will change this server entry */
2032 exp = &ex_addr[base][index];
2033 tuuid = exp->ex_hostuuid;
2034 afs_ntohuuid(&tuuid);
2035 if (afs_uuid_equal(uuidp, &tuuid)) {
2039 for (mhidx = 0; mhidx < VL_MAXIPADDRS_PERMH; mhidx++) {
2040 if (!exp->ex_addrs[mhidx])
2042 for (k = 0; k < cnt; k++) {
2043 if (ntohl(exp->ex_addrs[mhidx]) == addrs[k]) {
2044 willChangeEntry = 1;
2045 WillChange[count] = srvidx;
2050 WillReplaceEntry = 0;
2054 /* The server is not registered as a multihomed.
2055 * See if the addresses to register will replace this server entry.
2057 for (k = 0; k < cnt; k++) {
2058 if (HostAddress[srvidx] == addrs[k]) {
2059 willChangeEntry = 1;
2060 WillChange[count] = srvidx;
2061 WillReplaceEntry = 1;
2066 if (willChangeEntry) {
2067 if (WillReplaceEntry) {
2069 ReplaceEntry = srvidx;
2075 /* If we found the uuid in the VLDB and if we are replacing another
2076 * entire entry, then complain and fail. Also, if we did not find
2077 * the uuid in the VLDB and the IP addresses being registered was
2078 * found in more than one other entry, then we don't know which one
2079 * to replace and will complain and fail.
2081 if ((foundUuidEntry && (willReplaceCnt > 0))
2082 || (!foundUuidEntry && (count > 1))) {
2084 ("The following fileserver is being registered in the VLDB:\n"));
2086 for (k = 0; k < cnt; k++) {
2093 if (foundUuidEntry) {
2095 (" It would have replaced the existing VLDB server entry:\n"));
2096 VLog(0, (" entry %d: [", FoundUuid));
2097 base = (HostAddress[FoundUuid] >> 16) & 0xff;
2098 index = HostAddress[FoundUuid] & 0x0000ffff;
2099 exp = &ex_addr[base][index];
2100 for (mhidx = 0; mhidx < VL_MAXIPADDRS_PERMH; mhidx++) {
2101 if (!exp->ex_addrs[mhidx])
2105 PADDR(ntohl(exp->ex_addrs[mhidx]));
2111 VLog(0, (" Yet another VLDB server entry exists:\n"));
2113 VLog(0, (" Yet other VLDB server entries exist:\n"));
2114 for (j = 0; j < count; j++) {
2115 srvidx = WillChange[j];
2116 VLog(0, (" entry %d: ", srvidx));
2117 if ((HostAddress[srvidx] & 0xff000000) == 0xff000000) {
2119 base = (HostAddress[srvidx] >> 16) & 0xff;
2120 index = HostAddress[srvidx] & 0x0000ffff;
2121 exp = &ex_addr[base][index];
2122 for (mhidx = 0; mhidx < VL_MAXIPADDRS_PERMH; mhidx++) {
2123 if (!exp->ex_addrs[mhidx])
2127 PADDR(ntohl(exp->ex_addrs[mhidx]));
2131 PADDR(HostAddress[srvidx]);
2137 VLog(0, (" You must 'vos changeaddr' this other server entry\n"));
2140 (" You must 'vos changeaddr' these other server entries\n"));
2143 (" and/or remove the sysid file from the registering fileserver\n"));
2144 VLog(0, (" before the fileserver can be registered in the VLDB.\n"));
2146 ubik_AbortTrans(trans);
2147 return VL_MULTIPADDR;
2150 /* Passed the checks. Now find and update the existing mh entry, or create
2153 if (foundUuidEntry) {
2154 /* Found the entry with same uuid. See if we need to change it */
2157 fbase = (HostAddress[FoundUuid] >> 16) & 0xff;
2158 index = HostAddress[FoundUuid] & 0x0000ffff;
2159 exp = &ex_addr[fbase][index];
2161 /* Determine if the entry has changed */
2162 for (k = 0; ((k < cnt) && !change); k++) {
2163 if (ntohl(exp->ex_addrs[k]) != addrs[k])
2166 for (; ((k < VL_MAXIPADDRS_PERMH) && !change); k++) {
2167 if (exp->ex_addrs[k] != 0)
2171 return (ubik_EndTrans(trans));
2175 VLog(0, ("The following fileserver is being registered in the VLDB:\n"));
2177 for (k = 0; k < cnt; k++) {
2184 if (foundUuidEntry) {
2186 (" It will replace the following existing entry in the VLDB (same uuid):\n"));
2187 VLog(0, (" entry %d: [", FoundUuid));
2188 for (k = 0; k < VL_MAXIPADDRS_PERMH; k++) {
2189 if (exp->ex_addrs[k] == 0)
2193 PADDR(ntohl(exp->ex_addrs[k]));
2196 } else if (willReplaceCnt || (count == 1)) {
2197 /* If we are not replacing an entry and there is only one entry to change,
2198 * then we will replace that entry.
2200 if (!willReplaceCnt) {
2201 ReplaceEntry = WillChange[0];
2205 /* Have an entry that needs to be replaced */
2206 if ((HostAddress[ReplaceEntry] & 0xff000000) == 0xff000000) {
2207 fbase = (HostAddress[ReplaceEntry] >> 16) & 0xff;
2208 index = HostAddress[ReplaceEntry] & 0x0000ffff;
2209 exp = &ex_addr[fbase][index];
2212 (" It will replace the following existing entry in the VLDB (new uuid):\n"));
2213 VLog(0, (" entry %d: [", ReplaceEntry));
2214 for (k = 0; k < VL_MAXIPADDRS_PERMH; k++) {
2215 if (exp->ex_addrs[k] == 0)
2219 PADDR(ntohl(exp->ex_addrs[k]));
2223 /* Not a mh entry. So we have to create a new mh entry and
2224 * put it on the ReplaceEntry slot of the HostAddress array.
2226 VLog(0, (" It will replace existing entry %d, ", ReplaceEntry));
2227 PADDR(HostAddress[ReplaceEntry]);
2228 VLog(0,(", in the VLDB (new uuid):\n"));
2231 FindExtentBlock(trans, uuidp, 1, ReplaceEntry, &exp, &fbase);
2233 ubik_AbortTrans(trans);
2234 return (code ? code : VL_IO);
2238 /* There is no entry for this server, must create a new mh entry as
2239 * well as use a new slot of the HostAddress array.
2241 VLog(0, (" It will create a new entry in the VLDB.\n"));
2242 code = FindExtentBlock(trans, uuidp, 1, -1, &exp, &fbase);
2244 ubik_AbortTrans(trans);
2245 return (code ? code : VL_IO);
2249 /* Now we have a mh entry to fill in. Update the uuid, bump the
2250 * uniquifier, and fill in its IP addresses.
2253 afs_htonuuid(&tuuid);
2254 exp->ex_hostuuid = tuuid;
2255 exp->ex_uniquifier = htonl(ntohl(exp->ex_uniquifier) + 1);
2256 for (k = 0; k < cnt; k++) {
2257 exp->ex_addrs[k] = htonl(addrs[k]);
2259 for (; k < VL_MAXIPADDRS_PERMH; k++) {
2260 exp->ex_addrs[k] = 0;
2263 /* Write the new mh entry out */
2266 DOFFSET(ntohl(ex_addr[0]->ex_contaddrs[fbase]),
2267 (char *)ex_addr[fbase], (char *)exp), (char *)exp,
2269 ubik_AbortTrans(trans);
2273 /* Remove any common addresses from other mh entres. We know these entries
2274 * are being changed and not replaced so they are mh entries.
2277 for (i = 0; i < count; i++) {
2280 /* Skip the entry we replaced */
2281 if (willReplaceCnt && (WillChange[i] == ReplaceEntry))
2284 base = (HostAddress[WillChange[i]] >> 16) & 0xff;
2285 index = HostAddress[WillChange[i]] & 0x0000ffff;
2286 tex = &ex_addr[fbase][index];
2290 (" The following existing entries in the VLDB will be updated:\n"));
2292 VLog(0, (" entry %d: [", WillChange[i]));
2293 for (h = j = 0; j < VL_MAXIPADDRS_PERMH; j++) {
2294 if (tex->ex_addrs[j]) {
2297 PADDR(ntohl(tex->ex_addrs[j]));
2300 for (k = 0; k < cnt; k++) {
2301 if (ntohl(tex->ex_addrs[j]) == addrs[k])
2305 /* Not found, so we keep it */
2306 tex->ex_addrs[h] = tex->ex_addrs[j];
2310 for (j = h; j < VL_MAXIPADDRS_PERMH; j++) {
2311 tex->ex_addrs[j] = 0; /* zero rest of mh entry */
2315 /* Write out the modified mh entry */
2316 tex->ex_uniquifier = htonl(ntohl(tex->ex_uniquifier) + 1);
2318 DOFFSET(ntohl(ex_addr[0]->ex_contaddrs[base]),
2319 (char *)ex_addr[base], (char *)tex);
2320 if (vlwrite(trans, doff, (char *)tex, sizeof(*tex))) {
2321 ubik_AbortTrans(trans);
2326 return (ubik_EndTrans(trans));
2330 SVL_GetAddrsU(rxcall, attributes, uuidpo, uniquifier, nentries, addrsp)
2331 struct rx_call *rxcall;
2332 struct ListAddrByAttributes *attributes;
2334 afs_int32 *uniquifier, *nentries;
2337 register afs_int32 errorcode, index = -1, offset;
2338 struct ubik_trans *trans;
2339 int nservers, i, j, base = 0;
2340 struct extentaddr *exp = 0;
2342 afs_uint32 *taddrp, taddr;
2344 COUNT_REQ(VLGETADDRSU);
2345 addrsp->bulkaddrs_len = *nentries = 0;
2346 addrsp->bulkaddrs_val = 0;
2347 VLog(5, ("GetAddrsU %s\n", rxinfo(rxcall)));
2348 if (errorcode = Init_VLdbase(&trans, LOCKREAD, this_op))
2351 if (attributes->Mask & VLADDR_IPADDR) {
2352 if (attributes->Mask & (VLADDR_INDEX | VLADDR_UUID)) {
2353 ubik_AbortTrans(trans);
2356 for (base = 0; base < VL_MAX_ADDREXTBLKS; base++) {
2359 for (i = 1; i < VL_MHSRV_PERBLK; i++) {
2360 exp = &ex_addr[base][i];
2361 tuuid = exp->ex_hostuuid;
2362 afs_ntohuuid(&tuuid);
2363 if (afs_uuid_is_nil(&tuuid))
2365 for (j = 0; j < VL_MAXIPADDRS_PERMH; j++) {
2366 if (exp->ex_addrs[j]
2367 && (ntohl(exp->ex_addrs[j]) == attributes->ipaddr)) {
2371 if (j < VL_MAXIPADDRS_PERMH)
2374 if (i < VL_MHSRV_PERBLK)
2377 if (base >= VL_MAX_ADDREXTBLKS) {
2378 ubik_AbortTrans(trans);
2381 } else if (attributes->Mask & VLADDR_INDEX) {
2382 if (attributes->Mask & (VLADDR_IPADDR | VLADDR_UUID)) {
2383 ubik_AbortTrans(trans);
2386 index = attributes->index;
2387 if (index < 1 || index >= (VL_MAX_ADDREXTBLKS * VL_MHSRV_PERBLK)) {
2388 ubik_AbortTrans(trans);
2389 return VL_INDEXERANGE;
2391 base = index / VL_MHSRV_PERBLK;
2392 offset = index % VL_MHSRV_PERBLK;
2394 ubik_AbortTrans(trans);
2397 if (!ex_addr[base]) {
2398 ubik_AbortTrans(trans);
2399 return VL_INDEXERANGE;
2401 exp = &ex_addr[base][offset];
2402 } else if (attributes->Mask & VLADDR_UUID) {
2403 if (attributes->Mask & (VLADDR_IPADDR | VLADDR_INDEX)) {
2404 ubik_AbortTrans(trans);
2407 if (!ex_addr[0]) { /* mh servers probably aren't setup on this vldb */
2408 ubik_AbortTrans(trans);
2412 FindExtentBlock(trans, &attributes->uuid, 0, -1, &exp, &base)) {
2413 ubik_AbortTrans(trans);
2417 ubik_AbortTrans(trans);
2422 ubik_AbortTrans(trans);
2425 addrsp->bulkaddrs_val = taddrp =
2426 (afs_uint32 *) malloc(sizeof(afs_int32) * (MAXSERVERID + 1));
2427 nservers = *nentries = addrsp->bulkaddrs_len = 0;
2430 ubik_AbortTrans(trans);
2433 tuuid = exp->ex_hostuuid;
2434 afs_ntohuuid(&tuuid);
2435 if (afs_uuid_is_nil(&tuuid)) {
2436 ubik_AbortTrans(trans);
2442 *uniquifier = ntohl(exp->ex_uniquifier);
2443 for (i = 0; i < VL_MAXIPADDRS_PERMH; i++) {
2444 if (exp->ex_addrs[i]) {
2445 taddr = ntohl(exp->ex_addrs[i]);
2446 /* Weed out duplicates */
2447 for (j = 0; j < nservers; j++) {
2448 if (taddrp[j] == taddr)
2451 if ((j == nservers) && (j <= MAXSERVERID)) {
2452 taddrp[nservers] = taddr;
2457 addrsp->bulkaddrs_len = *nentries = nservers;
2458 return (ubik_EndTrans(trans));
2461 /* ============> End of Exported vldb RPC functions <============= */
2464 /* Routine that copies the given vldb entry to the output buffer, vldbentries. */
2466 put_attributeentry(Vldbentry, VldbentryFirst, VldbentryLast, vldbentries,
2467 entry, nentries, alloccnt)
2468 struct vldbentry **Vldbentry, **VldbentryFirst, **VldbentryLast;
2469 bulkentries *vldbentries;
2470 struct nvlentry *entry;
2471 afs_int32 *nentries, *alloccnt;
2476 if (*Vldbentry == *VldbentryLast) {
2478 return VL_SIZEEXCEEDED; /* no growing if smallMem defined */
2480 /* Allocate another set of memory; each time allocate twice as
2481 * many blocks as the last time. When we reach VLDBALLOCLIMIT,
2482 * then grow in increments of VLDBALLOCINCR.
2484 allo = (*alloccnt > VLDBALLOCLIMIT) ? VLDBALLOCINCR : *alloccnt;
2486 (vldbentry *) realloc(*VldbentryFirst,
2487 (*alloccnt + allo) * sizeof(vldbentry));
2491 *VldbentryFirst = vldbentries->bulkentries_val = reall;
2492 *Vldbentry = *VldbentryFirst + *alloccnt;
2493 *VldbentryLast = *Vldbentry + allo;
2496 vlentry_to_vldbentry(entry, *Vldbentry);
2499 vldbentries->bulkentries_len++;
2504 put_nattributeentry(Vldbentry, VldbentryFirst, VldbentryLast, vldbentries,
2505 entry, matchtype, matchindex, nentries, alloccnt)
2506 struct nvldbentry **Vldbentry, **VldbentryFirst, **VldbentryLast;
2507 nbulkentries *vldbentries;
2508 struct nvlentry *entry;
2509 afs_int32 matchtype, matchindex, *nentries, *alloccnt;
2514 if (*Vldbentry == *VldbentryLast) {
2516 return VL_SIZEEXCEEDED; /* no growing if smallMem defined */
2518 /* Allocate another set of memory; each time allocate twice as
2519 * many blocks as the last time. When we reach VLDBALLOCLIMIT,
2520 * then grow in increments of VLDBALLOCINCR.
2522 allo = (*alloccnt > VLDBALLOCLIMIT) ? VLDBALLOCINCR : *alloccnt;
2524 (nvldbentry *) realloc(*VldbentryFirst,
2525 (*alloccnt + allo) * sizeof(nvldbentry));
2529 *VldbentryFirst = vldbentries->nbulkentries_val = reall;
2530 *Vldbentry = *VldbentryFirst + *alloccnt;
2531 *VldbentryLast = *Vldbentry + allo;
2534 vlentry_to_nvldbentry(entry, *Vldbentry);
2535 (*Vldbentry)->matchindex = (matchtype << 16) + matchindex;
2538 vldbentries->nbulkentries_len++;
2543 /* Common code to actually remove a vldb entry from the database. */
2545 RemoveEntry(trans, entryptr, tentry)
2546 struct ubik_trans *trans;
2548 struct nvlentry *tentry;
2550 register int errorcode;
2552 if (errorcode = UnthreadVLentry(trans, entryptr, tentry))
2554 if (errorcode = FreeBlock(trans, entryptr))
2560 ReleaseEntry(tentry, releasetype)
2561 struct nvlentry *tentry;
2562 afs_int32 releasetype;
2564 if (releasetype & LOCKREL_TIMESTAMP)
2565 tentry->LockTimestamp = 0;
2566 if (releasetype & LOCKREL_OPCODE)
2567 tentry->flags &= ~VLOP_ALLOPERS;
2568 if (releasetype & LOCKREL_AFSID)
2569 tentry->LockAfsId = 0;
2573 /* Verify that the incoming vldb entry is valid; multi type of error codes are returned. */
2575 check_vldbentry(aentry)
2576 struct vldbentry *aentry;
2580 if (InvalidVolname(aentry->name))
2582 if (aentry->nServers <= 0 || aentry->nServers > OMAXNSERVERS)
2583 return VL_BADSERVER;
2584 for (i = 0; i < aentry->nServers; i++) {
2585 /* if (aentry->serverNumber[i] < 0 || aentry->serverNumber[i] > MAXSERVERID)
2586 return VL_BADSERVER; */
2587 if (aentry->serverPartition[i] < 0
2588 || aentry->serverPartition[i] > MAXPARTITIONID)
2589 return VL_BADPARTITION;
2590 if (aentry->serverFlags[i] < 0
2591 || aentry->serverFlags[i] > MAXSERVERFLAG)
2592 return VL_BADSERVERFLAG;
2598 check_nvldbentry(aentry)
2599 struct nvldbentry *aentry;
2603 if (InvalidVolname(aentry->name))
2605 if (aentry->nServers <= 0 || aentry->nServers > NMAXNSERVERS)
2606 return VL_BADSERVER;
2607 for (i = 0; i < aentry->nServers; i++) {
2608 /* if (aentry->serverNumber[i] < 0 || aentry->serverNumber[i] > MAXSERVERID)
2609 return VL_BADSERVER; */
2610 if (aentry->serverPartition[i] < 0
2611 || aentry->serverPartition[i] > MAXPARTITIONID)
2612 return VL_BADPARTITION;
2613 if (aentry->serverFlags[i] < 0
2614 || aentry->serverFlags[i] > MAXSERVERFLAG)
2615 return VL_BADSERVERFLAG;
2621 /* Convert from the external vldb entry representation to its internal
2622 (more compact) form. This call should not change the hash chains! */
2624 vldbentry_to_vlentry(atrans, VldbEntry, VlEntry)
2625 struct ubik_trans *atrans;
2626 struct vldbentry *VldbEntry;
2627 struct nvlentry *VlEntry;
2631 if (strcmp(VlEntry->name, VldbEntry->name))
2632 strncpy(VlEntry->name, VldbEntry->name, sizeof(VlEntry->name));
2633 for (i = 0; i < VldbEntry->nServers; i++) {
2634 serverindex = IpAddrToRelAddr(VldbEntry->serverNumber[i], atrans);
2635 if (serverindex == -1)
2636 return VL_BADSERVER;
2637 VlEntry->serverNumber[i] = serverindex;
2638 VlEntry->serverPartition[i] = VldbEntry->serverPartition[i];
2639 VlEntry->serverFlags[i] = VldbEntry->serverFlags[i];
2641 for (; i < OMAXNSERVERS; i++)
2642 VlEntry->serverNumber[i] = VlEntry->serverPartition[i] =
2643 VlEntry->serverFlags[i] = BADSERVERID;
2644 for (i = 0; i < MAXTYPES; i++)
2645 VlEntry->volumeId[i] = VldbEntry->volumeId[i];
2646 VlEntry->cloneId = VldbEntry->cloneId;
2647 VlEntry->flags = VldbEntry->flags;
2652 nvldbentry_to_vlentry(atrans, VldbEntry, VlEntry)
2653 struct ubik_trans *atrans;
2654 struct nvldbentry *VldbEntry;
2655 struct nvlentry *VlEntry;
2659 if (strcmp(VlEntry->name, VldbEntry->name))
2660 strncpy(VlEntry->name, VldbEntry->name, sizeof(VlEntry->name));
2661 for (i = 0; i < VldbEntry->nServers; i++) {
2662 serverindex = IpAddrToRelAddr(VldbEntry->serverNumber[i], atrans);
2663 if (serverindex == -1)
2664 return VL_BADSERVER;
2665 VlEntry->serverNumber[i] = serverindex;
2666 VlEntry->serverPartition[i] = VldbEntry->serverPartition[i];
2667 VlEntry->serverFlags[i] = VldbEntry->serverFlags[i];
2669 for (; i < NMAXNSERVERS; i++)
2670 VlEntry->serverNumber[i] = VlEntry->serverPartition[i] =
2671 VlEntry->serverFlags[i] = BADSERVERID;
2672 for (i = 0; i < MAXTYPES; i++)
2673 VlEntry->volumeId[i] = VldbEntry->volumeId[i];
2674 VlEntry->cloneId = VldbEntry->cloneId;
2675 VlEntry->flags = VldbEntry->flags;
2680 /* Update the vldb entry with the new fields as indicated by the value of the Mask entry in the updateentry structure. All necessary validation checks are performed. */
2682 get_vldbupdateentry(trans, blockindex, updateentry, VlEntry)
2683 struct ubik_trans *trans;
2684 afs_int32 blockindex;
2685 struct VldbUpdateEntry *updateentry;
2686 struct nvlentry *VlEntry;
2688 int i, j, errorcode, serverindex;
2690 if (updateentry->Mask & VLUPDATE_VOLUMENAME) {
2691 if (InvalidVolname(updateentry->name))
2693 if (errorcode = UnhashVolname(trans, blockindex, VlEntry))
2695 strncpy(VlEntry->name, updateentry->name, sizeof(VlEntry->name));
2696 HashVolname(trans, blockindex, VlEntry);
2699 if (updateentry->Mask & VLUPDATE_VOLNAMEHASH) {
2700 if (errorcode = UnhashVolname(trans, blockindex, VlEntry)) {
2701 if (errorcode != VL_NOENT)
2704 HashVolname(trans, blockindex, VlEntry);
2707 if (updateentry->Mask & VLUPDATE_FLAGS) {
2708 VlEntry->flags = updateentry->flags;
2710 if (updateentry->Mask & VLUPDATE_CLONEID) {
2711 VlEntry->cloneId = updateentry->cloneId;
2713 if (updateentry->Mask & VLUPDATE_RWID) {
2714 if (errorcode = UnhashVolid(trans, RWVOL, blockindex, VlEntry)) {
2715 if (errorcode != VL_NOENT)
2718 VlEntry->volumeId[RWVOL] = updateentry->spares3; /* rw id */
2719 if (errorcode = HashVolid(trans, RWVOL, blockindex, VlEntry))
2722 if (updateentry->Mask & VLUPDATE_READONLYID) {
2723 if (errorcode = UnhashVolid(trans, ROVOL, blockindex, VlEntry)) {
2724 if (errorcode != VL_NOENT)
2727 VlEntry->volumeId[ROVOL] = updateentry->ReadOnlyId;
2728 if (errorcode = HashVolid(trans, ROVOL, blockindex, VlEntry))
2731 if (updateentry->Mask & VLUPDATE_BACKUPID) {
2732 if (errorcode = UnhashVolid(trans, BACKVOL, blockindex, VlEntry)) {
2733 if (errorcode != VL_NOENT)
2736 VlEntry->volumeId[BACKVOL] = updateentry->BackupId;
2737 if (errorcode = HashVolid(trans, BACKVOL, blockindex, VlEntry))
2740 if (updateentry->Mask & VLUPDATE_REPSITES) {
2741 if (updateentry->nModifiedRepsites <= 0
2742 || updateentry->nModifiedRepsites > OMAXNSERVERS)
2743 return VL_BADSERVER;
2744 for (i = 0; i < updateentry->nModifiedRepsites; i++) {
2745 /* if (updateentry->RepsitesTargetServer[i] < 0 || updateentry->RepsitesTargetServer[i] > MAXSERVERID)
2746 return VL_BADSERVER; */
2747 if (updateentry->RepsitesTargetPart[i] < 0
2748 || updateentry->RepsitesTargetPart[i] > MAXPARTITIONID)
2749 return VL_BADPARTITION;
2750 if (updateentry->RepsitesMask[i] & VLUPDATE_REPS_DELETE) {
2752 repsite_exists(VlEntry,
2753 IpAddrToRelAddr(updateentry->
2754 RepsitesTargetServer[i],
2756 updateentry->RepsitesTargetPart[i])) !=
2758 repsite_compress(VlEntry, j);
2760 return VL_NOREPSERVER;
2762 if (updateentry->RepsitesMask[i] & VLUPDATE_REPS_ADD) {
2763 /* if (updateentry->RepsitesNewServer[i] < 0 || updateentry->RepsitesNewServer[i] > MAXSERVERID)
2764 return VL_BADSERVER; */
2765 if (updateentry->RepsitesNewPart[i] < 0
2766 || updateentry->RepsitesNewPart[i] > MAXPARTITIONID)
2767 return VL_BADPARTITION;
2770 IpAddrToRelAddr(updateentry->RepsitesNewServer[i],
2772 updateentry->RepsitesNewPart[i]) != -1)
2773 return VL_DUPREPSERVER;
2775 VlEntry->serverNumber[j] != BADSERVERID
2776 && j < OMAXNSERVERS; j++);
2777 if (j >= OMAXNSERVERS)
2780 IpAddrToRelAddr(updateentry->RepsitesNewServer[i],
2782 return VL_BADSERVER;
2783 VlEntry->serverNumber[j] = serverindex;
2784 VlEntry->serverPartition[j] = updateentry->RepsitesNewPart[i];
2785 if (updateentry->RepsitesNewFlags[i] < 0
2786 || updateentry->RepsitesNewFlags[i] > MAXSERVERFLAG)
2787 return VL_BADSERVERFLAG;
2788 VlEntry->serverFlags[j] = updateentry->RepsitesNewFlags[i];
2790 if (updateentry->RepsitesMask[i] & VLUPDATE_REPS_MODSERV) {
2791 /*n if (updateentry->RepsitesNewServer[i] < 0 || updateentry->RepsitesNewServer[i] > MAXSERVERID)
2792 return VL_BADSERVER; */
2794 repsite_exists(VlEntry,
2795 IpAddrToRelAddr(updateentry->
2796 RepsitesTargetServer[i],
2798 updateentry->RepsitesTargetPart[i])) !=
2800 VlEntry->serverNumber[j] =
2801 IpAddrToRelAddr(updateentry->RepsitesNewServer[i],
2804 return VL_NOREPSERVER;
2806 if (updateentry->RepsitesMask[i] & VLUPDATE_REPS_MODPART) {
2807 if (updateentry->RepsitesNewPart[i] < 0
2808 || updateentry->RepsitesNewPart[i] > MAXPARTITIONID)
2809 return VL_BADPARTITION;
2811 repsite_exists(VlEntry,
2812 IpAddrToRelAddr(updateentry->
2813 RepsitesTargetServer[i],
2815 updateentry->RepsitesTargetPart[i])) !=
2817 VlEntry->serverPartition[j] =
2818 updateentry->RepsitesNewPart[i];
2820 return VL_NOREPSERVER;
2822 if (updateentry->RepsitesMask[i] & VLUPDATE_REPS_MODFLAG) {
2824 repsite_exists(VlEntry,
2825 IpAddrToRelAddr(updateentry->
2826 RepsitesTargetServer[i],
2828 updateentry->RepsitesTargetPart[i])) !=
2830 if (updateentry->RepsitesNewFlags[i] < 0
2831 || updateentry->RepsitesNewFlags[i] > MAXSERVERFLAG)
2832 return VL_BADSERVERFLAG;
2833 VlEntry->serverFlags[j] =
2834 updateentry->RepsitesNewFlags[i];
2836 return VL_NOREPSERVER;
2844 /* Check if the specified [server,partition] entry is found in the vldb entry's repsite table; it's offset in the table is returned, if it's present there. */
2846 repsite_exists(VlEntry, server, partition)
2847 struct nvlentry *VlEntry;
2848 int server, partition;
2852 for (i = 0; VlEntry->serverNumber[i] != BADSERVERID && i < OMAXNSERVERS;
2854 if ((VlEntry->serverNumber[i] == server)
2855 && (VlEntry->serverPartition[i] == partition))
2863 /* Repsite table compression: used when deleting a repsite entry so that all active repsite entries are on the top of the table. */
2865 repsite_compress(VlEntry, offset)
2866 struct nvlentry *VlEntry;
2869 int repsite_offset = offset;
2871 VlEntry->serverNumber[repsite_offset] != BADSERVERID
2872 && repsite_offset < OMAXNSERVERS - 1; repsite_offset++) {
2873 VlEntry->serverNumber[repsite_offset] =
2874 VlEntry->serverNumber[repsite_offset + 1];
2875 VlEntry->serverPartition[repsite_offset] =
2876 VlEntry->serverPartition[repsite_offset + 1];
2877 VlEntry->serverFlags[repsite_offset] =
2878 VlEntry->serverFlags[repsite_offset + 1];
2880 VlEntry->serverNumber[repsite_offset] = BADSERVERID;
2884 /* Convert from the internal (compacted) vldb entry to the external representation used by the interface. */
2886 vlentry_to_vldbentry(VlEntry, VldbEntry)
2887 struct nvlentry *VlEntry;
2888 struct vldbentry *VldbEntry;
2892 memset(VldbEntry, 0, sizeof(struct vldbentry));
2893 strncpy(VldbEntry->name, VlEntry->name, sizeof(VldbEntry->name));
2894 for (i = 0; i < OMAXNSERVERS; i++) {
2895 if (VlEntry->serverNumber[i] == BADSERVERID)
2897 if ((HostAddress[j = VlEntry->serverNumber[i]] & 0xff000000) ==
2899 struct extentaddr *exp;
2902 base = (HostAddress[j] >> 16) & 0xff;
2903 index = HostAddress[j] & 0x0000ffff;
2904 exp = &ex_addr[base][index];
2905 /* For now return the first ip address back */
2906 for (j = 0; j < VL_MAXIPADDRS_PERMH; j++) {
2907 if (exp->ex_addrs[j]) {
2908 VldbEntry->serverNumber[i] = ntohl(exp->ex_addrs[j]);
2913 VldbEntry->serverNumber[i] =
2914 HostAddress[VlEntry->serverNumber[i]];
2915 VldbEntry->serverPartition[i] = VlEntry->serverPartition[i];
2916 VldbEntry->serverFlags[i] = VlEntry->serverFlags[i];
2918 VldbEntry->nServers = i;
2919 for (i = 0; i < MAXTYPES; i++)
2920 VldbEntry->volumeId[i] = VlEntry->volumeId[i];
2921 VldbEntry->cloneId = VlEntry->cloneId;
2922 VldbEntry->flags = VlEntry->flags;
2926 /* Convert from the internal (compacted) vldb entry to the external representation used by the interface. */
2928 vlentry_to_nvldbentry(VlEntry, VldbEntry)
2929 struct nvlentry *VlEntry;
2930 struct nvldbentry *VldbEntry;
2934 memset(VldbEntry, 0, sizeof(struct vldbentry));
2935 strncpy(VldbEntry->name, VlEntry->name, sizeof(VldbEntry->name));
2936 for (i = 0; i < NMAXNSERVERS; i++) {
2937 if (VlEntry->serverNumber[i] == BADSERVERID)
2939 if ((HostAddress[j = VlEntry->serverNumber[i]] & 0xff000000) ==
2941 struct extentaddr *exp;
2944 base = (HostAddress[j] >> 16) & 0xff;
2945 index = HostAddress[j] & 0x0000ffff;
2946 exp = &ex_addr[base][index];
2947 /* For now return the first ip address back */
2948 for (j = 0; j < VL_MAXIPADDRS_PERMH; j++) {
2949 if (exp->ex_addrs[j]) {
2950 VldbEntry->serverNumber[i] = ntohl(exp->ex_addrs[j]);
2955 VldbEntry->serverNumber[i] =
2956 HostAddress[VlEntry->serverNumber[i]];
2957 VldbEntry->serverPartition[i] = VlEntry->serverPartition[i];
2958 VldbEntry->serverFlags[i] = VlEntry->serverFlags[i];
2960 VldbEntry->nServers = i;
2961 for (i = 0; i < MAXTYPES; i++)
2962 VldbEntry->volumeId[i] = VlEntry->volumeId[i];
2963 VldbEntry->cloneId = VlEntry->cloneId;
2964 VldbEntry->flags = VlEntry->flags;
2968 vlentry_to_uvldbentry(VlEntry, VldbEntry)
2969 struct nvlentry *VlEntry;
2970 struct uvldbentry *VldbEntry;
2974 memset(VldbEntry, 0, sizeof(struct vldbentry));
2975 strncpy(VldbEntry->name, VlEntry->name, sizeof(VldbEntry->name));
2976 for (i = 0; i < NMAXNSERVERS; i++) {
2977 if (VlEntry->serverNumber[i] == BADSERVERID)
2979 VldbEntry->serverFlags[i] = VlEntry->serverFlags[i];
2980 VldbEntry->serverUnique[i] = 0;
2981 if ((HostAddress[j = VlEntry->serverNumber[i]] & 0xff000000) ==
2983 struct extentaddr *exp;
2987 base = (HostAddress[j] >> 16) & 0xff;
2988 index = HostAddress[j] & 0x0000ffff;
2989 exp = &ex_addr[base][index];
2990 tuuid = exp->ex_hostuuid;
2991 afs_ntohuuid(&tuuid);
2992 VldbEntry->serverFlags[i] |= VLSERVER_FLAG_UUID;
2993 VldbEntry->serverNumber[i] = tuuid;
2994 VldbEntry->serverUnique[i] = ntohl(exp->ex_uniquifier);
2996 VldbEntry->serverNumber[i].time_low =
2997 HostAddress[VlEntry->serverNumber[i]];
2999 VldbEntry->serverPartition[i] = VlEntry->serverPartition[i];
3002 VldbEntry->nServers = i;
3003 for (i = 0; i < MAXTYPES; i++)
3004 VldbEntry->volumeId[i] = VlEntry->volumeId[i];
3005 VldbEntry->cloneId = VlEntry->cloneId;
3006 VldbEntry->flags = VlEntry->flags;
3009 #define LEGALCHARS ".ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"
3012 /* Verify that the volname is a valid volume name. */
3014 InvalidVolname(volname)
3021 slen = strlen(volname);
3022 if (slen >= VL_MAXNAMELEN)
3024 return (slen != strspn(volname, map));
3028 /* Verify that the given volume type is valid. */
3030 InvalidVoltype(voltype)
3033 if (voltype != RWVOL && voltype != ROVOL && voltype != BACKVOL)
3040 InvalidOperation(voloper)
3043 if (voloper != VLOP_MOVE && voloper != VLOP_RELEASE
3044 && voloper != VLOP_BACKUP && voloper != VLOP_DELETE
3045 && voloper != VLOP_DUMP)
3051 InvalidReleasetype(releasetype)
3052 afs_int32 releasetype;
3054 if ((releasetype & LOCKREL_TIMESTAMP) || (releasetype & LOCKREL_OPCODE)
3055 || (releasetype & LOCKREL_AFSID))
3061 IpAddrToRelAddr(ipaddr, atrans)
3062 struct ubik_trans *atrans;
3063 register afs_uint32 ipaddr;
3066 register afs_int32 code, base, index;
3067 struct extentaddr *exp;
3069 for (i = 0; i <= MAXSERVERID; i++) {
3070 if (HostAddress[i] == ipaddr)
3072 if ((HostAddress[i] & 0xff000000) == 0xff000000) {
3073 base = (HostAddress[i] >> 16) & 0xff;
3074 index = HostAddress[i] & 0x0000ffff;
3075 if (base >= VL_MAX_ADDREXTBLKS) {
3077 ("Internal error: Multihome extent base is too large. Base %d index %d\n",
3079 return -1; /* EINVAL */
3081 if (index >= VL_MHSRV_PERBLK) {
3083 ("Internal error: Multihome extent index is too large. Base %d index %d\n",
3085 return -1; /* EINVAL */
3087 if (!ex_addr[base]) {
3089 ("Internal error: Multihome extent does not exist. Base %d\n",
3091 return -1; /* EINVAL */
3093 exp = &ex_addr[base][index];
3094 for (j = 0; j < VL_MAXIPADDRS_PERMH; j++) {
3095 if (exp->ex_addrs[j] && (ntohl(exp->ex_addrs[j]) == ipaddr)) {
3102 /* allocate the new server a server id pronto */
3104 for (i = 0; i <= MAXSERVERID; i++) {
3105 if (cheader.IpMappedAddr[i] == 0) {
3106 cheader.IpMappedAddr[i] = htonl(ipaddr);
3109 DOFFSET(0, &cheader, &cheader.IpMappedAddr[i]),
3110 (char *)&cheader.IpMappedAddr[i],
3112 HostAddress[i] = ipaddr;
3123 ChangeIPAddr(ipaddr1, ipaddr2, atrans)
3124 struct ubik_trans *atrans;
3125 register afs_uint32 ipaddr1, ipaddr2;
3129 struct extentaddr *exp;
3130 int base, index, mhidx;
3132 afs_int32 blockindex, count;
3134 struct nvlentry tentry;
3137 return VL_CREATEFAIL;
3139 /* Don't let addr change to 256.*.*.* : Causes internal error below */
3140 if ((ipaddr2 & 0xff000000) == 0xff000000)
3141 return (VL_BADSERVER);
3143 /* If we are removing an address, ip1 will be -1 and ip2 will be
3144 * the original address. This prevents an older revision vlserver
3145 * from removing the IP address (won't find server 0xfffffff in
3146 * the VLDB). An older revision vlserver does not have the check
3147 * to see if any volumes exist on the server being removed.
3149 if (ipaddr1 == 0xffffffff) {
3154 for (i = 0; i <= MAXSERVERID; i++) {
3155 if ((HostAddress[i] & 0xff000000) == 0xff000000) {
3156 base = (HostAddress[i] >> 16) & 0xff;
3157 index = HostAddress[i] & 0x0000ffff;
3158 if ((base >= VL_MAX_ADDREXTBLKS) || (index >= VL_MHSRV_PERBLK)) {
3160 ("Internal error: Multihome extent addr is too large. Base %d index %d\n",
3162 return -1; /* EINVAL */
3165 exp = &ex_addr[base][index];
3166 for (mhidx = 0; mhidx < VL_MAXIPADDRS_PERMH; mhidx++) {
3167 if (!exp->ex_addrs[mhidx])
3169 if (ntohl(exp->ex_addrs[mhidx]) == ipaddr1)
3172 if (mhidx < VL_MAXIPADDRS_PERMH) {
3175 } else if (HostAddress[i] == ipaddr1) {
3181 if (i >= MAXSERVERID) {
3182 return VL_NOENT; /* not found */
3185 /* If we are removing a server entry, a volume cannot
3186 * exist on the server. If one does, don't remove the
3187 * server entry: return error "volume entry exists".
3190 for (blockindex = NextEntry(atrans, 0, &tentry, &count); blockindex;
3191 blockindex = NextEntry(atrans, blockindex, &tentry, &count)) {
3192 if (++pollcount > 50) {
3196 for (j = 0; j < NMAXNSERVERS; j++) {
3197 if (tentry.serverNumber[j] == BADSERVERID)
3199 if (tentry.serverNumber[j] == i) {
3206 /* Log a message saying we are changing/removing an IP address */
3208 ("The following IP address is being %s:\n",
3209 (ipaddr2 ? "changed" : "removed")));
3210 VLog(0, (" entry %d: ", i));
3213 for (mhidx = 0; mhidx < VL_MAXIPADDRS_PERMH; mhidx++) {
3214 if (!exp->ex_addrs[mhidx])
3218 PADDR(ntohl(exp->ex_addrs[mhidx]));
3230 /* Change the registered uuuid addresses */
3232 memset(&tuuid, 0, sizeof(afsUUID));
3233 afs_htonuuid(&tuuid);
3234 exp->ex_hostuuid = tuuid;
3237 DOFFSET(ntohl(ex_addr[0]->ex_contaddrs[base]),
3238 (char *)ex_addr[base], (char *)exp),
3239 (char *)&tuuid, sizeof(tuuid));
3244 /* Now change the host address entry */
3245 cheader.IpMappedAddr[i] = htonl(ipaddr2);
3247 vlwrite(atrans, DOFFSET(0, &cheader, &cheader.IpMappedAddr[i]),
3249 &cheader.IpMappedAddr[i], sizeof(afs_int32));
3250 HostAddress[i] = ipaddr2;
3257 /* see if the vlserver is back yet */
3259 SVL_ProbeServer(rxcall)
3260 struct rx_call *rxcall;