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 void 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 void repsite_compress();
66 static void vlentry_to_vldbentry();
67 static void vlentry_to_nvldbentry();
68 static void 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) {
1138 #ifndef AFS_PTHREAD_ENV
1144 if (attributes->Mask & VLLIST_SERVER) {
1147 IpAddrToRelAddr(attributes->server,
1148 (struct ubik_trans *)0)) == -1)
1150 for (k = 0; k < OMAXNSERVERS; k++) {
1151 if (tentry.serverNumber[k] == BADSERVERID)
1153 if (tentry.serverNumber[k] == serverindex) {
1161 if (attributes->Mask & VLLIST_PARTITION) {
1163 if (tentry.serverPartition[k] != attributes->partition)
1166 for (k = 0; k < OMAXNSERVERS; k++) {
1167 if (tentry.serverNumber[k] == BADSERVERID)
1169 if (tentry.serverPartition[k] ==
1170 attributes->partition) {
1180 if (attributes->Mask & VLLIST_FLAG) {
1181 if (!(tentry.flags & attributes->flag))
1185 put_attributeentry(&Vldbentry, &VldbentryFirst,
1186 &VldbentryLast, vldbentries, &tentry,
1187 nentries, &allocCount)) {
1189 ubik_AbortTrans(trans);
1190 if (vldbentries->bulkentries_val)
1191 free((char *)vldbentries->bulkentries_val);
1192 vldbentries->bulkentries_val = 0;
1193 vldbentries->bulkentries_len = 0;
1198 if (vldbentries->bulkentries_len
1199 && (allocCount > vldbentries->bulkentries_len)) {
1201 vldbentries->bulkentries_val =
1202 (vldbentry *) realloc(vldbentries->bulkentries_val,
1203 vldbentries->bulkentries_len *
1205 if (vldbentries->bulkentries_val == NULL) {
1207 ubik_AbortTrans(trans);
1212 ("ListAttrs nentries=%d %s\n", vldbentries->bulkentries_len,
1214 return (ubik_EndTrans(trans));
1218 SVL_ListAttributesN(rxcall, attributes, nentries, vldbentries)
1219 struct rx_call *rxcall;
1220 struct VldbListByAttributes *attributes;
1221 afs_int32 *nentries;
1222 nbulkentries *vldbentries;
1224 int errorcode, allocCount = 0;
1225 struct ubik_trans *trans;
1226 struct nvlentry tentry;
1227 struct nvldbentry *Vldbentry = 0, *VldbentryFirst = 0, *VldbentryLast = 0;
1230 COUNT_REQ(VLLISTATTRIBUTESN);
1231 vldbentries->nbulkentries_val = 0;
1232 vldbentries->nbulkentries_len = *nentries = 0;
1233 if (errorcode = Init_VLdbase(&trans, LOCKREAD, this_op))
1235 allocCount = VLDBALLOCCOUNT;
1236 Vldbentry = VldbentryFirst = vldbentries->nbulkentries_val =
1237 (nvldbentry *) malloc(allocCount * sizeof(nvldbentry));
1238 if (Vldbentry == NULL) {
1240 ubik_AbortTrans(trans);
1243 VldbentryLast = VldbentryFirst + allocCount;
1244 /* Handle the attribute by volume id totally separate of the rest (thus additional Mask values are ignored if VLLIST_VOLUMEID is set!) */
1245 if (attributes->Mask & VLLIST_VOLUMEID) {
1246 afs_int32 blockindex;
1249 FindByID(trans, attributes->volumeid, -1, &tentry, &errorcode);
1250 if (blockindex == 0) {
1252 errorcode = VL_NOENT;
1254 ubik_AbortTrans(trans);
1255 if (vldbentries->nbulkentries_val)
1256 free((char *)vldbentries->nbulkentries_val);
1257 vldbentries->nbulkentries_val = 0;
1258 vldbentries->nbulkentries_len = 0;
1262 put_nattributeentry(&Vldbentry, &VldbentryFirst, &VldbentryLast,
1263 vldbentries, &tentry, 0, 0, nentries,
1266 ubik_AbortTrans(trans);
1267 if (vldbentries->nbulkentries_val)
1268 free((char *)vldbentries->nbulkentries_val);
1269 vldbentries->nbulkentries_val = 0;
1270 vldbentries->nbulkentries_len = 0;
1271 return VL_SIZEEXCEEDED;
1274 afs_int32 nextblockindex = 0, count = 0, k, match = 0;
1275 while (nextblockindex =
1276 NextEntry(trans, nextblockindex, &tentry, &count)) {
1277 if (++pollcount > 50) {
1278 #ifndef AFS_PTHREAD_ENV
1285 if (attributes->Mask & VLLIST_SERVER) {
1288 IpAddrToRelAddr(attributes->server,
1289 (struct ubik_trans *)0)) == -1)
1291 for (k = 0; k < NMAXNSERVERS; k++) {
1292 if (tentry.serverNumber[k] == BADSERVERID)
1294 if (tentry.serverNumber[k] == serverindex) {
1302 if (attributes->Mask & VLLIST_PARTITION) {
1304 if (tentry.serverPartition[k] != attributes->partition)
1307 for (k = 0; k < NMAXNSERVERS; k++) {
1308 if (tentry.serverNumber[k] == BADSERVERID)
1310 if (tentry.serverPartition[k] ==
1311 attributes->partition) {
1321 if (attributes->Mask & VLLIST_FLAG) {
1322 if (!(tentry.flags & attributes->flag))
1326 put_nattributeentry(&Vldbentry, &VldbentryFirst,
1327 &VldbentryLast, vldbentries, &tentry, 0,
1328 0, nentries, &allocCount)) {
1330 ubik_AbortTrans(trans);
1331 if (vldbentries->nbulkentries_val)
1332 free((char *)vldbentries->nbulkentries_val);
1333 vldbentries->nbulkentries_val = 0;
1334 vldbentries->nbulkentries_len = 0;
1339 if (vldbentries->nbulkentries_len
1340 && (allocCount > vldbentries->nbulkentries_len)) {
1342 vldbentries->nbulkentries_val =
1343 (nvldbentry *) realloc(vldbentries->nbulkentries_val,
1344 vldbentries->nbulkentries_len *
1345 sizeof(nvldbentry));
1346 if (vldbentries->nbulkentries_val == NULL) {
1348 ubik_AbortTrans(trans);
1353 ("NListAttrs nentries=%d %s\n", vldbentries->nbulkentries_len,
1355 return (ubik_EndTrans(trans));
1360 SVL_ListAttributesN2(rxcall, attributes, name, startindex, nentries,
1361 vldbentries, nextstartindex)
1362 struct rx_call *rxcall;
1363 struct VldbListByAttributes *attributes;
1364 char *name; /* Wildcarded volume name */
1365 afs_int32 startindex;
1366 afs_int32 *nentries;
1367 nbulkentries *vldbentries;
1368 afs_int32 *nextstartindex;
1370 int errorcode = 0, maxCount = VLDBALLOCCOUNT;
1371 struct ubik_trans *trans;
1372 struct nvlentry tentry;
1373 struct nvldbentry *Vldbentry = 0, *VldbentryFirst = 0, *VldbentryLast = 0;
1374 afs_int32 blockindex = 0, count = 0, k, match, matchindex;
1375 int serverindex = -1; /* no server found */
1376 int findserver = 0, findpartition = 0, findflag = 0, findname = 0;
1379 int namematchRWBK, namematchRO, thismatch, matchtype;
1380 char volumename[VL_MAXNAMELEN];
1381 #ifdef HAVE_POSIX_REGEX
1383 int need_regfree = 0;
1386 COUNT_REQ(VLLISTATTRIBUTESN2);
1387 vldbentries->nbulkentries_val = 0;
1388 vldbentries->nbulkentries_len = 0;
1390 *nextstartindex = -1;
1392 errorcode = Init_VLdbase(&trans, LOCKREAD, this_op);
1396 Vldbentry = VldbentryFirst = vldbentries->nbulkentries_val =
1397 (nvldbentry *) malloc(maxCount * sizeof(nvldbentry));
1398 if (Vldbentry == NULL) {
1400 ubik_AbortTrans(trans);
1404 VldbentryLast = VldbentryFirst + maxCount;
1406 /* Handle the attribute by volume id totally separate of the rest
1407 * (thus additional Mask values are ignored if VLLIST_VOLUMEID is set!)
1409 if (attributes->Mask & VLLIST_VOLUMEID) {
1411 FindByID(trans, attributes->volumeid, -1, &tentry, &errorcode);
1412 if (blockindex == 0) {
1414 errorcode = VL_NOENT;
1417 put_nattributeentry(&Vldbentry, &VldbentryFirst,
1418 &VldbentryLast, vldbentries, &tentry, 0,
1419 0, nentries, &maxCount);
1425 /* Search each entry in the database and return all entries
1426 * that match the request. It checks volumename (with
1427 * wildcarding), entry flags, server, and partition.
1430 /* Get the server index for matching server address */
1431 if (attributes->Mask & VLLIST_SERVER) {
1433 IpAddrToRelAddr(attributes->server, (struct ubik_trans *)0);
1434 if (serverindex == -1)
1438 findpartition = ((attributes->Mask & VLLIST_PARTITION) ? 1 : 0);
1439 findflag = ((attributes->Mask & VLLIST_FLAG) ? 1 : 0);
1440 if (name && (strcmp(name, ".*") != 0) && (strcmp(name, "") != 0)) {
1441 sprintf(volumename, "^%s$", name);
1442 #ifdef HAVE_POSIX_REGEX
1443 if (regcomp(&re, volumename, REG_NOSUB) != 0) {
1444 errorcode = VL_BADNAME;
1449 t = (char *)re_comp(volumename);
1451 errorcode = VL_BADNAME;
1458 /* Read each entry and see if it is the one we want */
1459 blockindex = startindex;
1460 while (blockindex = NextEntry(trans, blockindex, &tentry, &count)) {
1461 if (++pollcount > 50) {
1462 #ifndef AFS_PTHREAD_ENV
1468 /* Step through each server index searching for a match.
1469 * Match to an existing RW, BK, or RO volume name (preference
1470 * is in this order). Remember which index we matched against.
1472 namematchRWBK = namematchRO = 0; /* 0->notTried; 1->match; 2->noMatch */
1476 && (tentry.serverNumber[k] != BADSERVERID)); k++) {
1477 thismatch = 0; /* does this index match */
1479 /* Match against the RW or BK volume name. Remember
1480 * results in namematchRWBK. Prefer RW over BK.
1482 if (tentry.serverFlags[k] & VLSF_RWVOL) {
1483 /* Does the name match the RW name */
1484 if (tentry.flags & VLF_RWEXISTS) {
1486 sprintf(volumename, "%s", tentry.name);
1487 #ifdef HAVE_POSIX_REGEX
1488 if (regexec(&re, volumename, 0, NULL, 0) == 0) {
1489 thismatch = VLSF_RWVOL;
1492 if (re_exec(volumename)) {
1493 thismatch = VLSF_RWVOL;
1497 thismatch = VLSF_RWVOL;
1501 /* Does the name match the BK name */
1502 if (!thismatch && (tentry.flags & VLF_BACKEXISTS)) {
1504 sprintf(volumename, "%s.backup", tentry.name);
1505 #ifdef HAVE_POSIX_REGEX
1506 if (regexec(&re, volumename, 0, NULL, 0) == 0) {
1507 thismatch = VLSF_BACKVOL;
1510 if (re_exec(volumename)) {
1511 thismatch = VLSF_BACKVOL;
1515 thismatch = VLSF_BACKVOL;
1519 namematchRWBK = (thismatch ? 1 : 2);
1522 /* Match with the RO volume name. Compare once and
1523 * remember results in namematchRO. Note that this will
1524 * pick up entries marked NEWREPSITEs and DONTUSE.
1527 if (tentry.flags & VLF_ROEXISTS) {
1531 ((namematchRO == 1) ? VLSF_ROVOL : 0);
1533 sprintf(volumename, "%s.readonly",
1535 #ifdef HAVE_POSIX_REGEX
1536 if (regexec(&re, volumename, 0, NULL, 0) == 0) {
1537 thismatch = VLSF_ROVOL;
1540 if (re_exec(volumename))
1541 thismatch = VLSF_ROVOL;
1545 thismatch = VLSF_ROVOL;
1548 namematchRO = (thismatch ? 1 : 2);
1551 /* Is there a server match */
1552 if (thismatch && findserver
1553 && (tentry.serverNumber[k] != serverindex))
1556 /* Is there a partition match */
1557 if (thismatch && findpartition
1558 && (tentry.serverPartition[k] != attributes->partition))
1561 /* Is there a flag match */
1562 if (thismatch && findflag
1563 && !(tentry.flags & attributes->flag))
1566 /* We found a match. Remember the index, and type */
1570 matchtype = thismatch;
1573 /* Since we prefer RW and BK volume matches over RO matches,
1574 * if we have already checked the RWBK name, then we already
1575 * found the best match and so end the search.
1577 * If we tried matching against the RW, BK, and RO volume names
1578 * and both failed, then we end the search (none will match).
1580 if ((match && namematchRWBK)
1581 || ((namematchRWBK == 2) && (namematchRO == 2)))
1585 /* Passed all the tests. Take it */
1588 put_nattributeentry(&Vldbentry, &VldbentryFirst,
1589 &VldbentryLast, vldbentries, &tentry,
1590 matchtype, matchindex, nentries,
1595 if (*nentries >= maxCount)
1596 break; /* collected the max */
1599 *nextstartindex = (blockindex ? blockindex : -1);
1603 #ifdef HAVE_POSIX_REGEX
1610 ubik_AbortTrans(trans);
1611 if (vldbentries->nbulkentries_val)
1612 free((char *)vldbentries->nbulkentries_val);
1613 vldbentries->nbulkentries_val = 0;
1614 vldbentries->nbulkentries_len = 0;
1615 *nextstartindex = -1;
1619 ("N2ListAttrs nentries=%d %s\n", vldbentries->nbulkentries_len,
1621 return (ubik_EndTrans(trans));
1626 /* Retrieves in vldbentries all vldb entries that match the specified
1627 * attributes (by server number, partition, volume type, and flag); if
1628 * volume id is specified then the associated list for that entry is
1629 * returned. CAUTION: This could be a very expensive call since in most
1630 * cases sequential search of all vldb entries is performed.
1633 SVL_LinkedList(rxcall, attributes, nentries, vldbentries)
1634 struct rx_call *rxcall;
1635 struct VldbListByAttributes *attributes;
1636 afs_int32 *nentries;
1637 vldb_list *vldbentries;
1640 struct ubik_trans *trans;
1641 struct nvlentry tentry;
1642 vldblist vllist, *vllistptr;
1643 afs_int32 blockindex, count, k, match;
1647 COUNT_REQ(VLLINKEDLIST);
1648 if (errorcode = Init_VLdbase(&trans, LOCKREAD, this_op))
1652 vldbentries->node = NULL;
1653 vllistptr = &vldbentries->node;
1655 /* List by volumeid */
1656 if (attributes->Mask & VLLIST_VOLUMEID) {
1658 FindByID(trans, attributes->volumeid, -1, &tentry, &errorcode);
1661 ubik_AbortTrans(trans);
1662 return (errorcode ? errorcode : VL_NOENT);
1665 vllist = (single_vldbentry *) malloc(sizeof(single_vldbentry));
1666 if (vllist == NULL) {
1668 ubik_AbortTrans(trans);
1671 vlentry_to_vldbentry(&tentry, &vllist->VldbEntry);
1672 vllist->next_vldb = NULL;
1674 *vllistptr = vllist; /* Thread onto list */
1675 vllistptr = &vllist->next_vldb;
1679 /* Search by server, partition, and flags */
1681 for (blockindex = NextEntry(trans, 0, &tentry, &count); blockindex;
1682 blockindex = NextEntry(trans, blockindex, &tentry, &count)) {
1685 if (++pollcount > 50) {
1686 #ifndef AFS_PTHREAD_ENV
1692 /* Does this volume exist on the desired server */
1693 if (attributes->Mask & VLLIST_SERVER) {
1695 IpAddrToRelAddr(attributes->server,
1696 (struct ubik_trans *)0);
1697 if (serverindex == -1)
1699 for (k = 0; k < OMAXNSERVERS; k++) {
1700 if (tentry.serverNumber[k] == BADSERVERID)
1702 if (tentry.serverNumber[k] == serverindex) {
1711 /* Does this volume exist on the desired partition */
1712 if (attributes->Mask & VLLIST_PARTITION) {
1714 if (tentry.serverPartition[k] != attributes->partition)
1717 for (k = 0; k < OMAXNSERVERS; k++) {
1718 if (tentry.serverNumber[k] == BADSERVERID)
1720 if (tentry.serverPartition[k] ==
1721 attributes->partition) {
1731 /* Does this volume have the desired flags */
1732 if (attributes->Mask & VLLIST_FLAG) {
1733 if (!(tentry.flags & attributes->flag))
1737 vllist = (single_vldbentry *) malloc(sizeof(single_vldbentry));
1738 if (vllist == NULL) {
1740 ubik_AbortTrans(trans);
1743 vlentry_to_vldbentry(&tentry, &vllist->VldbEntry);
1744 vllist->next_vldb = NULL;
1746 *vllistptr = vllist; /* Thread onto list */
1747 vllistptr = &vllist->next_vldb;
1749 if (smallMem && (*nentries >= VLDBALLOCCOUNT)) {
1751 ubik_AbortTrans(trans);
1752 return VL_SIZEEXCEEDED;
1757 return (ubik_EndTrans(trans));
1761 SVL_LinkedListN(rxcall, attributes, nentries, vldbentries)
1762 struct rx_call *rxcall;
1763 struct VldbListByAttributes *attributes;
1764 afs_int32 *nentries;
1765 nvldb_list *vldbentries;
1768 struct ubik_trans *trans;
1769 struct nvlentry tentry;
1770 nvldblist vllist, *vllistptr;
1771 afs_int32 blockindex, count, k, match;
1775 COUNT_REQ(VLLINKEDLISTN);
1776 if (errorcode = Init_VLdbase(&trans, LOCKREAD, this_op))
1780 vldbentries->node = NULL;
1781 vllistptr = &vldbentries->node;
1783 /* List by volumeid */
1784 if (attributes->Mask & VLLIST_VOLUMEID) {
1786 FindByID(trans, attributes->volumeid, -1, &tentry, &errorcode);
1789 ubik_AbortTrans(trans);
1790 return (errorcode ? errorcode : VL_NOENT);
1793 vllist = (single_nvldbentry *) malloc(sizeof(single_nvldbentry));
1794 if (vllist == NULL) {
1796 ubik_AbortTrans(trans);
1799 vlentry_to_nvldbentry(&tentry, &vllist->VldbEntry);
1800 vllist->next_vldb = NULL;
1802 *vllistptr = vllist; /* Thread onto list */
1803 vllistptr = &vllist->next_vldb;
1807 /* Search by server, partition, and flags */
1809 for (blockindex = NextEntry(trans, 0, &tentry, &count); blockindex;
1810 blockindex = NextEntry(trans, blockindex, &tentry, &count)) {
1813 if (++pollcount > 50) {
1814 #ifndef AFS_PTHREAD_ENV
1820 /* Does this volume exist on the desired server */
1821 if (attributes->Mask & VLLIST_SERVER) {
1823 IpAddrToRelAddr(attributes->server,
1824 (struct ubik_trans *)0);
1825 if (serverindex == -1)
1827 for (k = 0; k < NMAXNSERVERS; k++) {
1828 if (tentry.serverNumber[k] == BADSERVERID)
1830 if (tentry.serverNumber[k] == serverindex) {
1839 /* Does this volume exist on the desired partition */
1840 if (attributes->Mask & VLLIST_PARTITION) {
1842 if (tentry.serverPartition[k] != attributes->partition)
1845 for (k = 0; k < NMAXNSERVERS; k++) {
1846 if (tentry.serverNumber[k] == BADSERVERID)
1848 if (tentry.serverPartition[k] ==
1849 attributes->partition) {
1859 /* Does this volume have the desired flags */
1860 if (attributes->Mask & VLLIST_FLAG) {
1861 if (!(tentry.flags & attributes->flag))
1865 vllist = (single_nvldbentry *) malloc(sizeof(single_nvldbentry));
1866 if (vllist == NULL) {
1868 ubik_AbortTrans(trans);
1871 vlentry_to_nvldbentry(&tentry, &vllist->VldbEntry);
1872 vllist->next_vldb = NULL;
1874 *vllistptr = vllist; /* Thread onto list */
1875 vllistptr = &vllist->next_vldb;
1877 if (smallMem && (*nentries >= VLDBALLOCCOUNT)) {
1879 ubik_AbortTrans(trans);
1880 return VL_SIZEEXCEEDED;
1885 return (ubik_EndTrans(trans));
1888 /* Get back vldb header statistics (allocs, frees, maxvolumeid, totalentries, etc) and dynamic statistics (number of requests and/or aborts per remote procedure call, etc) */
1890 SVL_GetStats(rxcall, stats, vital_header)
1891 struct rx_call *rxcall;
1893 vital_vlheader *vital_header;
1895 register afs_int32 errorcode;
1896 struct ubik_trans *trans;
1898 COUNT_REQ(VLGETSTATS);
1900 /* Allow users to get statistics freely */
1901 if (!afsconf_SuperUser(vldb_confdir, rxcall, NULL)) /* Must be in 'UserList' to use */
1904 if (errorcode = Init_VLdbase(&trans, LOCKREAD, this_op))
1906 VLog(5, ("GetStats %s\n", rxinfo(rxcall)));
1907 memcpy((char *)vital_header, (char *)&cheader.vital_header,
1908 sizeof(vital_vlheader));
1909 memcpy((char *)stats, (char *)&dynamic_statistics, sizeof(vldstats));
1910 return (ubik_EndTrans(trans));
1913 /* Get the list of file server addresses from the VLDB. Currently it's pretty
1914 * easy to do. In the future, it might require a little bit of grunging
1915 * through the VLDB, but that's life.
1918 SVL_GetAddrs(rxcall, Handle, spare2, spare3, nentries, addrsp)
1919 struct rx_call *rxcall;
1920 afs_int32 Handle, spare2;
1921 struct VLCallBack *spare3;
1922 afs_int32 *nentries;
1925 register afs_int32 errorcode;
1926 struct ubik_trans *trans;
1930 COUNT_REQ(VLGETADDRS);
1931 addrsp->bulkaddrs_len = *nentries = 0;
1932 addrsp->bulkaddrs_val = 0;
1933 memset(spare3, 0, sizeof(struct VLCallBack));
1935 if (errorcode = Init_VLdbase(&trans, LOCKREAD, this_op))
1938 VLog(5, ("GetAddrs\n"));
1939 addrsp->bulkaddrs_val = taddrp =
1940 (afs_uint32 *) malloc(sizeof(afs_int32) * (MAXSERVERID + 1));
1941 nservers = *nentries = addrsp->bulkaddrs_len = 0;
1945 ubik_AbortTrans(trans);
1949 for (i = 0; i <= MAXSERVERID; i++) {
1950 if (*taddrp = ntohl(cheader.IpMappedAddr[i])) {
1956 addrsp->bulkaddrs_len = *nentries = nservers;
1957 return (ubik_EndTrans(trans));
1960 #define PADDR(addr) VLog(0,("%d.%d.%d.%d", (addr>>24)&0xff, (addr>>16)&0xff, (addr>>8) &0xff, addr&0xff));
1963 SVL_RegisterAddrs(rxcall, uuidp, spare1, addrsp)
1964 struct rx_call *rxcall;
1970 struct ubik_trans *trans;
1971 int cnt, h, i, j, k, m, base, index;
1972 struct extentaddr *exp = 0, *tex;
1974 afs_uint32 addrs[VL_MAXIPADDRS_PERMH];
1976 int count, willChangeEntry, foundUuidEntry, willReplaceCnt;
1977 int WillReplaceEntry, WillChange[MAXSERVERID + 1], FoundUuid,
1981 COUNT_REQ(VLREGADDR);
1982 if (!afsconf_SuperUser(vldb_confdir, rxcall, NULL))
1984 if (code = Init_VLdbase(&trans, LOCKWRITE, this_op))
1987 /* Eliminate duplicates from IP address list */
1988 for (k = 0, cnt = 0; k < addrsp->bulkaddrs_len; k++) {
1989 if (addrsp->bulkaddrs_val[k] == 0)
1991 for (m = 0; m < cnt; m++) {
1992 if (addrs[m] == addrsp->bulkaddrs_val[k])
1996 if (m == VL_MAXIPADDRS_PERMH) {
1998 ("Number of addresses exceeds %d. Cannot register IP addr 0x%x in VLDB\n",
1999 VL_MAXIPADDRS_PERMH, addrsp->bulkaddrs_val[k]));
2001 addrs[m] = addrsp->bulkaddrs_val[k];
2007 ubik_AbortTrans(trans);
2008 return VL_INDEXERANGE;
2014 /* For each server registered within the VLDB */
2015 for (srvidx = 0; srvidx <= MAXSERVERID; srvidx++) {
2016 willChangeEntry = 0;
2017 WillReplaceEntry = 1;
2018 if ((HostAddress[srvidx] & 0xff000000) == 0xff000000) {
2019 /* The server is registered as a multihomed */
2020 base = (HostAddress[srvidx] >> 16) & 0xff;
2021 index = HostAddress[srvidx] & 0x0000ffff;
2022 if (base >= VL_MAX_ADDREXTBLKS) {
2024 ("Internal error: Multihome extent base is too large. Base %d index %d\n",
2028 if (index >= VL_MHSRV_PERBLK) {
2030 ("Internal error: Multihome extent index is too large. Base %d index %d\n",
2034 if (!ex_addr[base]) {
2036 ("Internal error: Multihome extent does not exist. Base %d\n",
2041 /* See if the addresses to register will change this server entry */
2042 exp = &ex_addr[base][index];
2043 tuuid = exp->ex_hostuuid;
2044 afs_ntohuuid(&tuuid);
2045 if (afs_uuid_equal(uuidp, &tuuid)) {
2049 for (mhidx = 0; mhidx < VL_MAXIPADDRS_PERMH; mhidx++) {
2050 if (!exp->ex_addrs[mhidx])
2052 for (k = 0; k < cnt; k++) {
2053 if (ntohl(exp->ex_addrs[mhidx]) == addrs[k]) {
2054 willChangeEntry = 1;
2055 WillChange[count] = srvidx;
2060 WillReplaceEntry = 0;
2064 /* The server is not registered as a multihomed.
2065 * See if the addresses to register will replace this server entry.
2067 for (k = 0; k < cnt; k++) {
2068 if (HostAddress[srvidx] == addrs[k]) {
2069 willChangeEntry = 1;
2070 WillChange[count] = srvidx;
2071 WillReplaceEntry = 1;
2076 if (willChangeEntry) {
2077 if (WillReplaceEntry) {
2079 ReplaceEntry = srvidx;
2085 /* If we found the uuid in the VLDB and if we are replacing another
2086 * entire entry, then complain and fail. Also, if we did not find
2087 * the uuid in the VLDB and the IP addresses being registered was
2088 * found in more than one other entry, then we don't know which one
2089 * to replace and will complain and fail.
2091 if ((foundUuidEntry && (willReplaceCnt > 0))
2092 || (!foundUuidEntry && (count > 1))) {
2094 ("The following fileserver is being registered in the VLDB:\n"));
2096 for (k = 0; k < cnt; k++) {
2103 if (foundUuidEntry) {
2105 (" It would have replaced the existing VLDB server entry:\n"));
2106 VLog(0, (" entry %d: [", FoundUuid));
2107 base = (HostAddress[FoundUuid] >> 16) & 0xff;
2108 index = HostAddress[FoundUuid] & 0x0000ffff;
2109 exp = &ex_addr[base][index];
2110 for (mhidx = 0; mhidx < VL_MAXIPADDRS_PERMH; mhidx++) {
2111 if (!exp->ex_addrs[mhidx])
2115 PADDR(ntohl(exp->ex_addrs[mhidx]));
2121 VLog(0, (" Yet another VLDB server entry exists:\n"));
2123 VLog(0, (" Yet other VLDB server entries exist:\n"));
2124 for (j = 0; j < count; j++) {
2125 srvidx = WillChange[j];
2126 VLog(0, (" entry %d: ", srvidx));
2127 if ((HostAddress[srvidx] & 0xff000000) == 0xff000000) {
2129 base = (HostAddress[srvidx] >> 16) & 0xff;
2130 index = HostAddress[srvidx] & 0x0000ffff;
2131 exp = &ex_addr[base][index];
2132 for (mhidx = 0; mhidx < VL_MAXIPADDRS_PERMH; mhidx++) {
2133 if (!exp->ex_addrs[mhidx])
2137 PADDR(ntohl(exp->ex_addrs[mhidx]));
2141 PADDR(HostAddress[srvidx]);
2147 VLog(0, (" You must 'vos changeaddr' this other server entry\n"));
2150 (" You must 'vos changeaddr' these other server entries\n"));
2153 (" and/or remove the sysid file from the registering fileserver\n"));
2154 VLog(0, (" before the fileserver can be registered in the VLDB.\n"));
2156 ubik_AbortTrans(trans);
2157 return VL_MULTIPADDR;
2160 /* Passed the checks. Now find and update the existing mh entry, or create
2163 if (foundUuidEntry) {
2164 /* Found the entry with same uuid. See if we need to change it */
2167 fbase = (HostAddress[FoundUuid] >> 16) & 0xff;
2168 index = HostAddress[FoundUuid] & 0x0000ffff;
2169 exp = &ex_addr[fbase][index];
2171 /* Determine if the entry has changed */
2172 for (k = 0; ((k < cnt) && !change); k++) {
2173 if (ntohl(exp->ex_addrs[k]) != addrs[k])
2176 for (; ((k < VL_MAXIPADDRS_PERMH) && !change); k++) {
2177 if (exp->ex_addrs[k] != 0)
2181 return (ubik_EndTrans(trans));
2185 VLog(0, ("The following fileserver is being registered in the VLDB:\n"));
2187 for (k = 0; k < cnt; k++) {
2194 if (foundUuidEntry) {
2196 (" It will replace the following existing entry in the VLDB (same uuid):\n"));
2197 VLog(0, (" entry %d: [", FoundUuid));
2198 for (k = 0; k < VL_MAXIPADDRS_PERMH; k++) {
2199 if (exp->ex_addrs[k] == 0)
2203 PADDR(ntohl(exp->ex_addrs[k]));
2206 } else if (willReplaceCnt || (count == 1)) {
2207 /* If we are not replacing an entry and there is only one entry to change,
2208 * then we will replace that entry.
2210 if (!willReplaceCnt) {
2211 ReplaceEntry = WillChange[0];
2215 /* Have an entry that needs to be replaced */
2216 if ((HostAddress[ReplaceEntry] & 0xff000000) == 0xff000000) {
2217 fbase = (HostAddress[ReplaceEntry] >> 16) & 0xff;
2218 index = HostAddress[ReplaceEntry] & 0x0000ffff;
2219 exp = &ex_addr[fbase][index];
2222 (" It will replace the following existing entry in the VLDB (new uuid):\n"));
2223 VLog(0, (" entry %d: [", ReplaceEntry));
2224 for (k = 0; k < VL_MAXIPADDRS_PERMH; k++) {
2225 if (exp->ex_addrs[k] == 0)
2229 PADDR(ntohl(exp->ex_addrs[k]));
2233 /* Not a mh entry. So we have to create a new mh entry and
2234 * put it on the ReplaceEntry slot of the HostAddress array.
2236 VLog(0, (" It will replace existing entry %d, ", ReplaceEntry));
2237 PADDR(HostAddress[ReplaceEntry]);
2238 VLog(0,(", in the VLDB (new uuid):\n"));
2241 FindExtentBlock(trans, uuidp, 1, ReplaceEntry, &exp, &fbase);
2243 ubik_AbortTrans(trans);
2244 return (code ? code : VL_IO);
2248 /* There is no entry for this server, must create a new mh entry as
2249 * well as use a new slot of the HostAddress array.
2251 VLog(0, (" It will create a new entry in the VLDB.\n"));
2252 code = FindExtentBlock(trans, uuidp, 1, -1, &exp, &fbase);
2254 ubik_AbortTrans(trans);
2255 return (code ? code : VL_IO);
2259 /* Now we have a mh entry to fill in. Update the uuid, bump the
2260 * uniquifier, and fill in its IP addresses.
2263 afs_htonuuid(&tuuid);
2264 exp->ex_hostuuid = tuuid;
2265 exp->ex_uniquifier = htonl(ntohl(exp->ex_uniquifier) + 1);
2266 for (k = 0; k < cnt; k++) {
2267 exp->ex_addrs[k] = htonl(addrs[k]);
2269 for (; k < VL_MAXIPADDRS_PERMH; k++) {
2270 exp->ex_addrs[k] = 0;
2273 /* Write the new mh entry out */
2276 DOFFSET(ntohl(ex_addr[0]->ex_contaddrs[fbase]),
2277 (char *)ex_addr[fbase], (char *)exp), (char *)exp,
2279 ubik_AbortTrans(trans);
2283 /* Remove any common addresses from other mh entres. We know these entries
2284 * are being changed and not replaced so they are mh entries.
2287 for (i = 0; i < count; i++) {
2290 /* Skip the entry we replaced */
2291 if (willReplaceCnt && (WillChange[i] == ReplaceEntry))
2294 base = (HostAddress[WillChange[i]] >> 16) & 0xff;
2295 index = HostAddress[WillChange[i]] & 0x0000ffff;
2296 tex = &ex_addr[fbase][index];
2300 (" The following existing entries in the VLDB will be updated:\n"));
2302 VLog(0, (" entry %d: [", WillChange[i]));
2303 for (h = j = 0; j < VL_MAXIPADDRS_PERMH; j++) {
2304 if (tex->ex_addrs[j]) {
2307 PADDR(ntohl(tex->ex_addrs[j]));
2310 for (k = 0; k < cnt; k++) {
2311 if (ntohl(tex->ex_addrs[j]) == addrs[k])
2315 /* Not found, so we keep it */
2316 tex->ex_addrs[h] = tex->ex_addrs[j];
2320 for (j = h; j < VL_MAXIPADDRS_PERMH; j++) {
2321 tex->ex_addrs[j] = 0; /* zero rest of mh entry */
2325 /* Write out the modified mh entry */
2326 tex->ex_uniquifier = htonl(ntohl(tex->ex_uniquifier) + 1);
2328 DOFFSET(ntohl(ex_addr[0]->ex_contaddrs[base]),
2329 (char *)ex_addr[base], (char *)tex);
2330 if (vlwrite(trans, doff, (char *)tex, sizeof(*tex))) {
2331 ubik_AbortTrans(trans);
2336 return (ubik_EndTrans(trans));
2340 SVL_GetAddrsU(rxcall, attributes, uuidpo, uniquifier, nentries, addrsp)
2341 struct rx_call *rxcall;
2342 struct ListAddrByAttributes *attributes;
2344 afs_int32 *uniquifier, *nentries;
2347 register afs_int32 errorcode, index = -1, offset;
2348 struct ubik_trans *trans;
2349 int nservers, i, j, base = 0;
2350 struct extentaddr *exp = 0;
2352 afs_uint32 *taddrp, taddr;
2354 COUNT_REQ(VLGETADDRSU);
2355 addrsp->bulkaddrs_len = *nentries = 0;
2356 addrsp->bulkaddrs_val = 0;
2357 VLog(5, ("GetAddrsU %s\n", rxinfo(rxcall)));
2358 if (errorcode = Init_VLdbase(&trans, LOCKREAD, this_op))
2361 if (attributes->Mask & VLADDR_IPADDR) {
2362 if (attributes->Mask & (VLADDR_INDEX | VLADDR_UUID)) {
2363 ubik_AbortTrans(trans);
2366 for (base = 0; base < VL_MAX_ADDREXTBLKS; base++) {
2369 for (i = 1; i < VL_MHSRV_PERBLK; i++) {
2370 exp = &ex_addr[base][i];
2371 tuuid = exp->ex_hostuuid;
2372 afs_ntohuuid(&tuuid);
2373 if (afs_uuid_is_nil(&tuuid))
2375 for (j = 0; j < VL_MAXIPADDRS_PERMH; j++) {
2376 if (exp->ex_addrs[j]
2377 && (ntohl(exp->ex_addrs[j]) == attributes->ipaddr)) {
2381 if (j < VL_MAXIPADDRS_PERMH)
2384 if (i < VL_MHSRV_PERBLK)
2387 if (base >= VL_MAX_ADDREXTBLKS) {
2388 ubik_AbortTrans(trans);
2391 } else if (attributes->Mask & VLADDR_INDEX) {
2392 if (attributes->Mask & (VLADDR_IPADDR | VLADDR_UUID)) {
2393 ubik_AbortTrans(trans);
2396 index = attributes->index;
2397 if (index < 1 || index >= (VL_MAX_ADDREXTBLKS * VL_MHSRV_PERBLK)) {
2398 ubik_AbortTrans(trans);
2399 return VL_INDEXERANGE;
2401 base = index / VL_MHSRV_PERBLK;
2402 offset = index % VL_MHSRV_PERBLK;
2404 ubik_AbortTrans(trans);
2407 if (!ex_addr[base]) {
2408 ubik_AbortTrans(trans);
2409 return VL_INDEXERANGE;
2411 exp = &ex_addr[base][offset];
2412 } else if (attributes->Mask & VLADDR_UUID) {
2413 if (attributes->Mask & (VLADDR_IPADDR | VLADDR_INDEX)) {
2414 ubik_AbortTrans(trans);
2417 if (!ex_addr[0]) { /* mh servers probably aren't setup on this vldb */
2418 ubik_AbortTrans(trans);
2422 FindExtentBlock(trans, &attributes->uuid, 0, -1, &exp, &base)) {
2423 ubik_AbortTrans(trans);
2427 ubik_AbortTrans(trans);
2432 ubik_AbortTrans(trans);
2435 addrsp->bulkaddrs_val = taddrp =
2436 (afs_uint32 *) malloc(sizeof(afs_int32) * (MAXSERVERID + 1));
2437 nservers = *nentries = addrsp->bulkaddrs_len = 0;
2440 ubik_AbortTrans(trans);
2443 tuuid = exp->ex_hostuuid;
2444 afs_ntohuuid(&tuuid);
2445 if (afs_uuid_is_nil(&tuuid)) {
2446 ubik_AbortTrans(trans);
2452 *uniquifier = ntohl(exp->ex_uniquifier);
2453 for (i = 0; i < VL_MAXIPADDRS_PERMH; i++) {
2454 if (exp->ex_addrs[i]) {
2455 taddr = ntohl(exp->ex_addrs[i]);
2456 /* Weed out duplicates */
2457 for (j = 0; j < nservers; j++) {
2458 if (taddrp[j] == taddr)
2461 if ((j == nservers) && (j <= MAXSERVERID)) {
2462 taddrp[nservers] = taddr;
2467 addrsp->bulkaddrs_len = *nentries = nservers;
2468 return (ubik_EndTrans(trans));
2471 /* ============> End of Exported vldb RPC functions <============= */
2474 /* Routine that copies the given vldb entry to the output buffer, vldbentries. */
2476 put_attributeentry(Vldbentry, VldbentryFirst, VldbentryLast, vldbentries,
2477 entry, nentries, alloccnt)
2478 struct vldbentry **Vldbentry, **VldbentryFirst, **VldbentryLast;
2479 bulkentries *vldbentries;
2480 struct nvlentry *entry;
2481 afs_int32 *nentries, *alloccnt;
2486 if (*Vldbentry == *VldbentryLast) {
2488 return VL_SIZEEXCEEDED; /* no growing if smallMem defined */
2490 /* Allocate another set of memory; each time allocate twice as
2491 * many blocks as the last time. When we reach VLDBALLOCLIMIT,
2492 * then grow in increments of VLDBALLOCINCR.
2494 allo = (*alloccnt > VLDBALLOCLIMIT) ? VLDBALLOCINCR : *alloccnt;
2496 (vldbentry *) realloc(*VldbentryFirst,
2497 (*alloccnt + allo) * sizeof(vldbentry));
2501 *VldbentryFirst = vldbentries->bulkentries_val = reall;
2502 *Vldbentry = *VldbentryFirst + *alloccnt;
2503 *VldbentryLast = *Vldbentry + allo;
2506 vlentry_to_vldbentry(entry, *Vldbentry);
2509 vldbentries->bulkentries_len++;
2514 put_nattributeentry(Vldbentry, VldbentryFirst, VldbentryLast, vldbentries,
2515 entry, matchtype, matchindex, nentries, alloccnt)
2516 struct nvldbentry **Vldbentry, **VldbentryFirst, **VldbentryLast;
2517 nbulkentries *vldbentries;
2518 struct nvlentry *entry;
2519 afs_int32 matchtype, matchindex, *nentries, *alloccnt;
2524 if (*Vldbentry == *VldbentryLast) {
2526 return VL_SIZEEXCEEDED; /* no growing if smallMem defined */
2528 /* Allocate another set of memory; each time allocate twice as
2529 * many blocks as the last time. When we reach VLDBALLOCLIMIT,
2530 * then grow in increments of VLDBALLOCINCR.
2532 allo = (*alloccnt > VLDBALLOCLIMIT) ? VLDBALLOCINCR : *alloccnt;
2534 (nvldbentry *) realloc(*VldbentryFirst,
2535 (*alloccnt + allo) * sizeof(nvldbentry));
2539 *VldbentryFirst = vldbentries->nbulkentries_val = reall;
2540 *Vldbentry = *VldbentryFirst + *alloccnt;
2541 *VldbentryLast = *Vldbentry + allo;
2544 vlentry_to_nvldbentry(entry, *Vldbentry);
2545 (*Vldbentry)->matchindex = (matchtype << 16) + matchindex;
2548 vldbentries->nbulkentries_len++;
2553 /* Common code to actually remove a vldb entry from the database. */
2555 RemoveEntry(trans, entryptr, tentry)
2556 struct ubik_trans *trans;
2558 struct nvlentry *tentry;
2560 register int errorcode;
2562 if (errorcode = UnthreadVLentry(trans, entryptr, tentry))
2564 if (errorcode = FreeBlock(trans, entryptr))
2570 ReleaseEntry(tentry, releasetype)
2571 struct nvlentry *tentry;
2572 afs_int32 releasetype;
2574 if (releasetype & LOCKREL_TIMESTAMP)
2575 tentry->LockTimestamp = 0;
2576 if (releasetype & LOCKREL_OPCODE)
2577 tentry->flags &= ~VLOP_ALLOPERS;
2578 if (releasetype & LOCKREL_AFSID)
2579 tentry->LockAfsId = 0;
2583 /* Verify that the incoming vldb entry is valid; multi type of error codes are returned. */
2585 check_vldbentry(aentry)
2586 struct vldbentry *aentry;
2590 if (InvalidVolname(aentry->name))
2592 if (aentry->nServers <= 0 || aentry->nServers > OMAXNSERVERS)
2593 return VL_BADSERVER;
2594 for (i = 0; i < aentry->nServers; i++) {
2595 /* if (aentry->serverNumber[i] < 0 || aentry->serverNumber[i] > MAXSERVERID)
2596 return VL_BADSERVER; */
2597 if (aentry->serverPartition[i] < 0
2598 || aentry->serverPartition[i] > MAXPARTITIONID)
2599 return VL_BADPARTITION;
2600 if (aentry->serverFlags[i] < 0
2601 || aentry->serverFlags[i] > MAXSERVERFLAG)
2602 return VL_BADSERVERFLAG;
2608 check_nvldbentry(aentry)
2609 struct nvldbentry *aentry;
2613 if (InvalidVolname(aentry->name))
2615 if (aentry->nServers <= 0 || aentry->nServers > NMAXNSERVERS)
2616 return VL_BADSERVER;
2617 for (i = 0; i < aentry->nServers; i++) {
2618 /* if (aentry->serverNumber[i] < 0 || aentry->serverNumber[i] > MAXSERVERID)
2619 return VL_BADSERVER; */
2620 if (aentry->serverPartition[i] < 0
2621 || aentry->serverPartition[i] > MAXPARTITIONID)
2622 return VL_BADPARTITION;
2623 if (aentry->serverFlags[i] < 0
2624 || aentry->serverFlags[i] > MAXSERVERFLAG)
2625 return VL_BADSERVERFLAG;
2631 /* Convert from the external vldb entry representation to its internal
2632 (more compact) form. This call should not change the hash chains! */
2634 vldbentry_to_vlentry(atrans, VldbEntry, VlEntry)
2635 struct ubik_trans *atrans;
2636 struct vldbentry *VldbEntry;
2637 struct nvlentry *VlEntry;
2641 if (strcmp(VlEntry->name, VldbEntry->name))
2642 strncpy(VlEntry->name, VldbEntry->name, sizeof(VlEntry->name));
2643 for (i = 0; i < VldbEntry->nServers; i++) {
2644 serverindex = IpAddrToRelAddr(VldbEntry->serverNumber[i], atrans);
2645 if (serverindex == -1)
2646 return VL_BADSERVER;
2647 VlEntry->serverNumber[i] = serverindex;
2648 VlEntry->serverPartition[i] = VldbEntry->serverPartition[i];
2649 VlEntry->serverFlags[i] = VldbEntry->serverFlags[i];
2651 for (; i < OMAXNSERVERS; i++)
2652 VlEntry->serverNumber[i] = VlEntry->serverPartition[i] =
2653 VlEntry->serverFlags[i] = BADSERVERID;
2654 for (i = 0; i < MAXTYPES; i++)
2655 VlEntry->volumeId[i] = VldbEntry->volumeId[i];
2656 VlEntry->cloneId = VldbEntry->cloneId;
2657 VlEntry->flags = VldbEntry->flags;
2662 nvldbentry_to_vlentry(atrans, VldbEntry, VlEntry)
2663 struct ubik_trans *atrans;
2664 struct nvldbentry *VldbEntry;
2665 struct nvlentry *VlEntry;
2669 if (strcmp(VlEntry->name, VldbEntry->name))
2670 strncpy(VlEntry->name, VldbEntry->name, sizeof(VlEntry->name));
2671 for (i = 0; i < VldbEntry->nServers; i++) {
2672 serverindex = IpAddrToRelAddr(VldbEntry->serverNumber[i], atrans);
2673 if (serverindex == -1)
2674 return VL_BADSERVER;
2675 VlEntry->serverNumber[i] = serverindex;
2676 VlEntry->serverPartition[i] = VldbEntry->serverPartition[i];
2677 VlEntry->serverFlags[i] = VldbEntry->serverFlags[i];
2679 for (; i < NMAXNSERVERS; i++)
2680 VlEntry->serverNumber[i] = VlEntry->serverPartition[i] =
2681 VlEntry->serverFlags[i] = BADSERVERID;
2682 for (i = 0; i < MAXTYPES; i++)
2683 VlEntry->volumeId[i] = VldbEntry->volumeId[i];
2684 VlEntry->cloneId = VldbEntry->cloneId;
2685 VlEntry->flags = VldbEntry->flags;
2690 /* 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. */
2692 get_vldbupdateentry(trans, blockindex, updateentry, VlEntry)
2693 struct ubik_trans *trans;
2694 afs_int32 blockindex;
2695 struct VldbUpdateEntry *updateentry;
2696 struct nvlentry *VlEntry;
2698 int i, j, errorcode, serverindex;
2700 if (updateentry->Mask & VLUPDATE_VOLUMENAME) {
2701 if (InvalidVolname(updateentry->name))
2703 if (errorcode = UnhashVolname(trans, blockindex, VlEntry))
2705 strncpy(VlEntry->name, updateentry->name, sizeof(VlEntry->name));
2706 HashVolname(trans, blockindex, VlEntry);
2709 if (updateentry->Mask & VLUPDATE_VOLNAMEHASH) {
2710 if (errorcode = UnhashVolname(trans, blockindex, VlEntry)) {
2711 if (errorcode != VL_NOENT)
2714 HashVolname(trans, blockindex, VlEntry);
2717 if (updateentry->Mask & VLUPDATE_FLAGS) {
2718 VlEntry->flags = updateentry->flags;
2720 if (updateentry->Mask & VLUPDATE_CLONEID) {
2721 VlEntry->cloneId = updateentry->cloneId;
2723 if (updateentry->Mask & VLUPDATE_RWID) {
2724 if (errorcode = UnhashVolid(trans, RWVOL, blockindex, VlEntry)) {
2725 if (errorcode != VL_NOENT)
2728 VlEntry->volumeId[RWVOL] = updateentry->spares3; /* rw id */
2729 if (errorcode = HashVolid(trans, RWVOL, blockindex, VlEntry))
2732 if (updateentry->Mask & VLUPDATE_READONLYID) {
2733 if (errorcode = UnhashVolid(trans, ROVOL, blockindex, VlEntry)) {
2734 if (errorcode != VL_NOENT)
2737 VlEntry->volumeId[ROVOL] = updateentry->ReadOnlyId;
2738 if (errorcode = HashVolid(trans, ROVOL, blockindex, VlEntry))
2741 if (updateentry->Mask & VLUPDATE_BACKUPID) {
2742 if (errorcode = UnhashVolid(trans, BACKVOL, blockindex, VlEntry)) {
2743 if (errorcode != VL_NOENT)
2746 VlEntry->volumeId[BACKVOL] = updateentry->BackupId;
2747 if (errorcode = HashVolid(trans, BACKVOL, blockindex, VlEntry))
2750 if (updateentry->Mask & VLUPDATE_REPSITES) {
2751 if (updateentry->nModifiedRepsites <= 0
2752 || updateentry->nModifiedRepsites > OMAXNSERVERS)
2753 return VL_BADSERVER;
2754 for (i = 0; i < updateentry->nModifiedRepsites; i++) {
2755 /* if (updateentry->RepsitesTargetServer[i] < 0 || updateentry->RepsitesTargetServer[i] > MAXSERVERID)
2756 return VL_BADSERVER; */
2757 if (updateentry->RepsitesTargetPart[i] < 0
2758 || updateentry->RepsitesTargetPart[i] > MAXPARTITIONID)
2759 return VL_BADPARTITION;
2760 if (updateentry->RepsitesMask[i] & VLUPDATE_REPS_DELETE) {
2762 repsite_exists(VlEntry,
2763 IpAddrToRelAddr(updateentry->
2764 RepsitesTargetServer[i],
2766 updateentry->RepsitesTargetPart[i])) !=
2768 repsite_compress(VlEntry, j);
2770 return VL_NOREPSERVER;
2772 if (updateentry->RepsitesMask[i] & VLUPDATE_REPS_ADD) {
2773 /* if (updateentry->RepsitesNewServer[i] < 0 || updateentry->RepsitesNewServer[i] > MAXSERVERID)
2774 return VL_BADSERVER; */
2775 if (updateentry->RepsitesNewPart[i] < 0
2776 || updateentry->RepsitesNewPart[i] > MAXPARTITIONID)
2777 return VL_BADPARTITION;
2780 IpAddrToRelAddr(updateentry->RepsitesNewServer[i],
2782 updateentry->RepsitesNewPart[i]) != -1)
2783 return VL_DUPREPSERVER;
2785 VlEntry->serverNumber[j] != BADSERVERID
2786 && j < OMAXNSERVERS; j++);
2787 if (j >= OMAXNSERVERS)
2790 IpAddrToRelAddr(updateentry->RepsitesNewServer[i],
2792 return VL_BADSERVER;
2793 VlEntry->serverNumber[j] = serverindex;
2794 VlEntry->serverPartition[j] = updateentry->RepsitesNewPart[i];
2795 if (updateentry->RepsitesNewFlags[i] < 0
2796 || updateentry->RepsitesNewFlags[i] > MAXSERVERFLAG)
2797 return VL_BADSERVERFLAG;
2798 VlEntry->serverFlags[j] = updateentry->RepsitesNewFlags[i];
2800 if (updateentry->RepsitesMask[i] & VLUPDATE_REPS_MODSERV) {
2801 /*n if (updateentry->RepsitesNewServer[i] < 0 || updateentry->RepsitesNewServer[i] > MAXSERVERID)
2802 return VL_BADSERVER; */
2804 repsite_exists(VlEntry,
2805 IpAddrToRelAddr(updateentry->
2806 RepsitesTargetServer[i],
2808 updateentry->RepsitesTargetPart[i])) !=
2810 VlEntry->serverNumber[j] =
2811 IpAddrToRelAddr(updateentry->RepsitesNewServer[i],
2814 return VL_NOREPSERVER;
2816 if (updateentry->RepsitesMask[i] & VLUPDATE_REPS_MODPART) {
2817 if (updateentry->RepsitesNewPart[i] < 0
2818 || updateentry->RepsitesNewPart[i] > MAXPARTITIONID)
2819 return VL_BADPARTITION;
2821 repsite_exists(VlEntry,
2822 IpAddrToRelAddr(updateentry->
2823 RepsitesTargetServer[i],
2825 updateentry->RepsitesTargetPart[i])) !=
2827 VlEntry->serverPartition[j] =
2828 updateentry->RepsitesNewPart[i];
2830 return VL_NOREPSERVER;
2832 if (updateentry->RepsitesMask[i] & VLUPDATE_REPS_MODFLAG) {
2834 repsite_exists(VlEntry,
2835 IpAddrToRelAddr(updateentry->
2836 RepsitesTargetServer[i],
2838 updateentry->RepsitesTargetPart[i])) !=
2840 if (updateentry->RepsitesNewFlags[i] < 0
2841 || updateentry->RepsitesNewFlags[i] > MAXSERVERFLAG)
2842 return VL_BADSERVERFLAG;
2843 VlEntry->serverFlags[j] =
2844 updateentry->RepsitesNewFlags[i];
2846 return VL_NOREPSERVER;
2854 /* 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. */
2856 repsite_exists(VlEntry, server, partition)
2857 struct nvlentry *VlEntry;
2858 int server, partition;
2862 for (i = 0; VlEntry->serverNumber[i] != BADSERVERID && i < OMAXNSERVERS;
2864 if ((VlEntry->serverNumber[i] == server)
2865 && (VlEntry->serverPartition[i] == partition))
2873 /* Repsite table compression: used when deleting a repsite entry so that all active repsite entries are on the top of the table. */
2875 repsite_compress(VlEntry, offset)
2876 struct nvlentry *VlEntry;
2879 int repsite_offset = offset;
2881 VlEntry->serverNumber[repsite_offset] != BADSERVERID
2882 && repsite_offset < OMAXNSERVERS - 1; repsite_offset++) {
2883 VlEntry->serverNumber[repsite_offset] =
2884 VlEntry->serverNumber[repsite_offset + 1];
2885 VlEntry->serverPartition[repsite_offset] =
2886 VlEntry->serverPartition[repsite_offset + 1];
2887 VlEntry->serverFlags[repsite_offset] =
2888 VlEntry->serverFlags[repsite_offset + 1];
2890 VlEntry->serverNumber[repsite_offset] = BADSERVERID;
2894 /* Convert from the internal (compacted) vldb entry to the external representation used by the interface. */
2896 vlentry_to_vldbentry(VlEntry, VldbEntry)
2897 struct nvlentry *VlEntry;
2898 struct vldbentry *VldbEntry;
2902 memset(VldbEntry, 0, sizeof(struct vldbentry));
2903 strncpy(VldbEntry->name, VlEntry->name, sizeof(VldbEntry->name));
2904 for (i = 0; i < OMAXNSERVERS; i++) {
2905 if (VlEntry->serverNumber[i] == BADSERVERID)
2907 if ((HostAddress[j = VlEntry->serverNumber[i]] & 0xff000000) ==
2909 struct extentaddr *exp;
2912 base = (HostAddress[j] >> 16) & 0xff;
2913 index = HostAddress[j] & 0x0000ffff;
2914 exp = &ex_addr[base][index];
2915 /* For now return the first ip address back */
2916 for (j = 0; j < VL_MAXIPADDRS_PERMH; j++) {
2917 if (exp->ex_addrs[j]) {
2918 VldbEntry->serverNumber[i] = ntohl(exp->ex_addrs[j]);
2923 VldbEntry->serverNumber[i] =
2924 HostAddress[VlEntry->serverNumber[i]];
2925 VldbEntry->serverPartition[i] = VlEntry->serverPartition[i];
2926 VldbEntry->serverFlags[i] = VlEntry->serverFlags[i];
2928 VldbEntry->nServers = i;
2929 for (i = 0; i < MAXTYPES; i++)
2930 VldbEntry->volumeId[i] = VlEntry->volumeId[i];
2931 VldbEntry->cloneId = VlEntry->cloneId;
2932 VldbEntry->flags = VlEntry->flags;
2936 /* Convert from the internal (compacted) vldb entry to the external representation used by the interface. */
2938 vlentry_to_nvldbentry(VlEntry, VldbEntry)
2939 struct nvlentry *VlEntry;
2940 struct nvldbentry *VldbEntry;
2944 memset(VldbEntry, 0, sizeof(struct vldbentry));
2945 strncpy(VldbEntry->name, VlEntry->name, sizeof(VldbEntry->name));
2946 for (i = 0; i < NMAXNSERVERS; i++) {
2947 if (VlEntry->serverNumber[i] == BADSERVERID)
2949 if ((HostAddress[j = VlEntry->serverNumber[i]] & 0xff000000) ==
2951 struct extentaddr *exp;
2954 base = (HostAddress[j] >> 16) & 0xff;
2955 index = HostAddress[j] & 0x0000ffff;
2956 exp = &ex_addr[base][index];
2957 /* For now return the first ip address back */
2958 for (j = 0; j < VL_MAXIPADDRS_PERMH; j++) {
2959 if (exp->ex_addrs[j]) {
2960 VldbEntry->serverNumber[i] = ntohl(exp->ex_addrs[j]);
2965 VldbEntry->serverNumber[i] =
2966 HostAddress[VlEntry->serverNumber[i]];
2967 VldbEntry->serverPartition[i] = VlEntry->serverPartition[i];
2968 VldbEntry->serverFlags[i] = VlEntry->serverFlags[i];
2970 VldbEntry->nServers = i;
2971 for (i = 0; i < MAXTYPES; i++)
2972 VldbEntry->volumeId[i] = VlEntry->volumeId[i];
2973 VldbEntry->cloneId = VlEntry->cloneId;
2974 VldbEntry->flags = VlEntry->flags;
2978 vlentry_to_uvldbentry(VlEntry, VldbEntry)
2979 struct nvlentry *VlEntry;
2980 struct uvldbentry *VldbEntry;
2984 memset(VldbEntry, 0, sizeof(struct vldbentry));
2985 strncpy(VldbEntry->name, VlEntry->name, sizeof(VldbEntry->name));
2986 for (i = 0; i < NMAXNSERVERS; i++) {
2987 if (VlEntry->serverNumber[i] == BADSERVERID)
2989 VldbEntry->serverFlags[i] = VlEntry->serverFlags[i];
2990 VldbEntry->serverUnique[i] = 0;
2991 if ((HostAddress[j = VlEntry->serverNumber[i]] & 0xff000000) ==
2993 struct extentaddr *exp;
2997 base = (HostAddress[j] >> 16) & 0xff;
2998 index = HostAddress[j] & 0x0000ffff;
2999 exp = &ex_addr[base][index];
3000 tuuid = exp->ex_hostuuid;
3001 afs_ntohuuid(&tuuid);
3002 VldbEntry->serverFlags[i] |= VLSERVER_FLAG_UUID;
3003 VldbEntry->serverNumber[i] = tuuid;
3004 VldbEntry->serverUnique[i] = ntohl(exp->ex_uniquifier);
3006 VldbEntry->serverNumber[i].time_low =
3007 HostAddress[VlEntry->serverNumber[i]];
3009 VldbEntry->serverPartition[i] = VlEntry->serverPartition[i];
3012 VldbEntry->nServers = i;
3013 for (i = 0; i < MAXTYPES; i++)
3014 VldbEntry->volumeId[i] = VlEntry->volumeId[i];
3015 VldbEntry->cloneId = VlEntry->cloneId;
3016 VldbEntry->flags = VlEntry->flags;
3019 #define LEGALCHARS ".ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"
3022 /* Verify that the volname is a valid volume name. */
3024 InvalidVolname(volname)
3031 slen = strlen(volname);
3032 if (slen >= VL_MAXNAMELEN)
3034 return (slen != strspn(volname, map));
3038 /* Verify that the given volume type is valid. */
3040 InvalidVoltype(voltype)
3043 if (voltype != RWVOL && voltype != ROVOL && voltype != BACKVOL)
3050 InvalidOperation(voloper)
3053 if (voloper != VLOP_MOVE && voloper != VLOP_RELEASE
3054 && voloper != VLOP_BACKUP && voloper != VLOP_DELETE
3055 && voloper != VLOP_DUMP)
3061 InvalidReleasetype(releasetype)
3062 afs_int32 releasetype;
3064 if ((releasetype & LOCKREL_TIMESTAMP) || (releasetype & LOCKREL_OPCODE)
3065 || (releasetype & LOCKREL_AFSID))
3071 IpAddrToRelAddr(ipaddr, atrans)
3072 struct ubik_trans *atrans;
3073 register afs_uint32 ipaddr;
3076 register afs_int32 code, base, index;
3077 struct extentaddr *exp;
3079 for (i = 0; i <= MAXSERVERID; i++) {
3080 if (HostAddress[i] == ipaddr)
3082 if ((HostAddress[i] & 0xff000000) == 0xff000000) {
3083 base = (HostAddress[i] >> 16) & 0xff;
3084 index = HostAddress[i] & 0x0000ffff;
3085 if (base >= VL_MAX_ADDREXTBLKS) {
3087 ("Internal error: Multihome extent base is too large. Base %d index %d\n",
3089 return -1; /* EINVAL */
3091 if (index >= VL_MHSRV_PERBLK) {
3093 ("Internal error: Multihome extent index is too large. Base %d index %d\n",
3095 return -1; /* EINVAL */
3097 if (!ex_addr[base]) {
3099 ("Internal error: Multihome extent does not exist. Base %d\n",
3101 return -1; /* EINVAL */
3103 exp = &ex_addr[base][index];
3104 for (j = 0; j < VL_MAXIPADDRS_PERMH; j++) {
3105 if (exp->ex_addrs[j] && (ntohl(exp->ex_addrs[j]) == ipaddr)) {
3112 /* allocate the new server a server id pronto */
3114 for (i = 0; i <= MAXSERVERID; i++) {
3115 if (cheader.IpMappedAddr[i] == 0) {
3116 cheader.IpMappedAddr[i] = htonl(ipaddr);
3119 DOFFSET(0, &cheader, &cheader.IpMappedAddr[i]),
3120 (char *)&cheader.IpMappedAddr[i],
3122 HostAddress[i] = ipaddr;
3133 ChangeIPAddr(ipaddr1, ipaddr2, atrans)
3134 struct ubik_trans *atrans;
3135 register afs_uint32 ipaddr1, ipaddr2;
3139 struct extentaddr *exp;
3140 int base, index, mhidx;
3142 afs_int32 blockindex, count;
3144 struct nvlentry tentry;
3147 return VL_CREATEFAIL;
3149 /* Don't let addr change to 256.*.*.* : Causes internal error below */
3150 if ((ipaddr2 & 0xff000000) == 0xff000000)
3151 return (VL_BADSERVER);
3153 /* If we are removing an address, ip1 will be -1 and ip2 will be
3154 * the original address. This prevents an older revision vlserver
3155 * from removing the IP address (won't find server 0xfffffff in
3156 * the VLDB). An older revision vlserver does not have the check
3157 * to see if any volumes exist on the server being removed.
3159 if (ipaddr1 == 0xffffffff) {
3164 for (i = 0; i <= MAXSERVERID; i++) {
3165 if ((HostAddress[i] & 0xff000000) == 0xff000000) {
3166 base = (HostAddress[i] >> 16) & 0xff;
3167 index = HostAddress[i] & 0x0000ffff;
3168 if ((base >= VL_MAX_ADDREXTBLKS) || (index >= VL_MHSRV_PERBLK)) {
3170 ("Internal error: Multihome extent addr is too large. Base %d index %d\n",
3172 return -1; /* EINVAL */
3175 exp = &ex_addr[base][index];
3176 for (mhidx = 0; mhidx < VL_MAXIPADDRS_PERMH; mhidx++) {
3177 if (!exp->ex_addrs[mhidx])
3179 if (ntohl(exp->ex_addrs[mhidx]) == ipaddr1)
3182 if (mhidx < VL_MAXIPADDRS_PERMH) {
3185 } else if (HostAddress[i] == ipaddr1) {
3191 if (i >= MAXSERVERID) {
3192 return VL_NOENT; /* not found */
3195 /* If we are removing a server entry, a volume cannot
3196 * exist on the server. If one does, don't remove the
3197 * server entry: return error "volume entry exists".
3200 for (blockindex = NextEntry(atrans, 0, &tentry, &count); blockindex;
3201 blockindex = NextEntry(atrans, blockindex, &tentry, &count)) {
3202 if (++pollcount > 50) {
3203 #ifndef AFS_PTHREAD_ENV
3208 for (j = 0; j < NMAXNSERVERS; j++) {
3209 if (tentry.serverNumber[j] == BADSERVERID)
3211 if (tentry.serverNumber[j] == i) {
3218 /* Log a message saying we are changing/removing an IP address */
3220 ("The following IP address is being %s:\n",
3221 (ipaddr2 ? "changed" : "removed")));
3222 VLog(0, (" entry %d: ", i));
3225 for (mhidx = 0; mhidx < VL_MAXIPADDRS_PERMH; mhidx++) {
3226 if (!exp->ex_addrs[mhidx])
3230 PADDR(ntohl(exp->ex_addrs[mhidx]));
3242 /* Change the registered uuuid addresses */
3244 memset(&tuuid, 0, sizeof(afsUUID));
3245 afs_htonuuid(&tuuid);
3246 exp->ex_hostuuid = tuuid;
3249 DOFFSET(ntohl(ex_addr[0]->ex_contaddrs[base]),
3250 (char *)ex_addr[base], (char *)exp),
3251 (char *)&tuuid, sizeof(tuuid));
3256 /* Now change the host address entry */
3257 cheader.IpMappedAddr[i] = htonl(ipaddr2);
3259 vlwrite(atrans, DOFFSET(0, &cheader, &cheader.IpMappedAddr[i]),
3261 &cheader.IpMappedAddr[i], sizeof(afs_int32));
3262 HostAddress[i] = ipaddr2;
3269 /* see if the vlserver is back yet */
3271 SVL_ProbeServer(rxcall)
3272 struct rx_call *rxcall;