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 <afs/afsutil.h>
22 #include <afs/cellconfig.h>
25 #include "vlserver_internal.h"
26 #include "afs/audit.h"
28 #ifdef HAVE_POSIX_REGEX /* use POSIX regexp library */
33 extern int extent_mod;
34 extern struct afsconf_dir *vldb_confdir;
35 extern struct ubik_dbase *VL_dbase;
37 #define ABORT(c) do { \
47 #define VLDBALLOCLIMIT 10000
48 #define VLDBALLOCINCR 2048
50 static int put_attributeentry(struct vl_ctx *ctx,
51 struct vldbentry **, struct vldbentry **,
52 struct vldbentry **, bulkentries *,
53 struct nvlentry *, afs_int32 *, afs_int32 *);
54 static int put_nattributeentry(struct vl_ctx *ctx,
55 struct nvldbentry **, struct nvldbentry **,
56 struct nvldbentry **, nbulkentries *,
57 struct nvlentry *, afs_int32, afs_int32,
58 afs_int32 *, afs_int32 *);
59 static int RemoveEntry(struct vl_ctx *ctx, afs_int32 entryptr,
60 struct nvlentry *tentry);
61 static void ReleaseEntry(struct nvlentry *tentry, afs_int32 releasetype);
62 static int check_vldbentry(struct vldbentry *aentry);
63 static int check_nvldbentry(struct nvldbentry *aentry);
64 static int vldbentry_to_vlentry(struct vl_ctx *ctx,
65 struct vldbentry *VldbEntry,
66 struct nvlentry *VlEntry);
67 static int nvldbentry_to_vlentry(struct vl_ctx *ctx,
68 struct nvldbentry *VldbEntry,
69 struct nvlentry *VlEntry);
70 static int get_vldbupdateentry(struct vl_ctx *ctx, afs_int32 blockindex,
71 struct VldbUpdateEntry *updateentry,
72 struct nvlentry *VlEntry);
73 static int repsite_exists(struct nvlentry *VlEntry, int server, int partition);
74 static void repsite_compress(struct nvlentry *VlEntry, int offset);
75 static int vlentry_to_vldbentry(struct vl_ctx *ctx,
76 struct nvlentry *VlEntry,
77 struct vldbentry *VldbEntry);
78 static int vlentry_to_nvldbentry(struct vl_ctx *ctx,
79 struct nvlentry *VlEntry,
80 struct nvldbentry *VldbEntry);
81 static int vlentry_to_uvldbentry(struct vl_ctx *ctx,
82 struct nvlentry *VlEntry,
83 struct uvldbentry *VldbEntry);
84 static int InvalidVolname(char *volname);
85 static int InvalidVoltype(afs_int32 voltype);
86 static int InvalidOperation(afs_int32 voloper);
87 static int InvalidReleasetype(afs_int32 releasetype);
88 static int IpAddrToRelAddr(struct vl_ctx *ctx, afs_uint32 ipaddr, int create);
89 static int ChangeIPAddr(struct vl_ctx *ctx, afs_uint32 ipaddr1,
93 countRequest(int opcode)
96 dynamic_statistics.requests[opcode - VL_LOWEST_OPCODE]++;
101 countAbort(int opcode)
104 dynamic_statistics.aborts[opcode - VL_LOWEST_OPCODE]++;
110 multiHomedExtentBase(struct vl_ctx *ctx, int srvidx, struct extentaddr **exp,
119 if ((ctx->hostaddress[srvidx] & 0xff000000) == 0xff000000) {
120 base = (ctx->hostaddress[srvidx] >> 16) & 0xff;
121 index = ctx->hostaddress[srvidx] & 0x0000ffff;
122 if (base >= VL_MAX_ADDREXTBLKS) {
123 VLog(0, ("Internal error: Multihome extent base is too large. "
124 "Base %d index %d\n", base, index));
127 if (index >= VL_MHSRV_PERBLK) {
128 VLog(0, ("Internal error: Multihome extent index is too large. "
129 "Base %d index %d\n", base, index));
132 if (!ctx->ex_addr[base]) {
133 VLog(0, ("Internal error: Multihome extent does not exist. "
139 *exp = &ctx->ex_addr[base][index];
146 multiHomedExtent(struct vl_ctx *ctx, int srvidx, struct extentaddr **exp)
150 return multiHomedExtentBase(ctx, srvidx, exp, &base);
154 #define AFS_RXINFO_LEN 128
156 rxinfo(char * str, struct rx_call *rxcall)
159 struct rx_connection *tconn;
164 struct in_addr hostAddr;
166 tconn = rx_ConnectionOf(rxcall);
167 hostAddr.s_addr = rx_HostOf(rx_PeerOf(tconn));
169 rxkad_GetServerInfo(rxcall->conn, NULL, &exp, tname, tinst, tcell,
172 sprintf(str, "%s %s%s%s%s%s", inet_ntoa(hostAddr), tname,
173 (tinst[0] == '\0') ? "" : ".",
174 (tinst[0] == '\0') ? "" : tinst,
175 (tcell[0] == '\0') ? "" : "@",
176 (tcell[0] == '\0') ? "" : tcell);
178 sprintf(str, "%s noauth", inet_ntoa(hostAddr));
182 /* This is called to initialize the database, set the appropriate locks and make sure that the vldb header is valid */
184 Init_VLdbase(struct vl_ctx *ctx,
185 int locktype, /* indicate read or write transaction */
188 int code = 0, pass, wl;
190 for (pass = 1; pass <= 3; pass++) {
191 if (pass == 2) { /* take write lock to rebuild the db */
192 code = ubik_BeginTrans(VL_dbase, UBIK_WRITETRANS, &ctx->trans);
194 } else if (locktype == LOCKREAD) {
196 ubik_BeginTransReadAnyWrite(VL_dbase, UBIK_READTRANS, &ctx->trans);
199 code = ubik_BeginTrans(VL_dbase, UBIK_WRITETRANS, &ctx->trans);
205 code = ubik_SetLock(ctx->trans, 1, 1, locktype);
208 ubik_AbortTrans(ctx->trans);
212 /* check that dbase is initialized and setup cheader */
213 /* 2nd pass we try to rebuild the header */
214 code = CheckInit(ctx->trans, ((pass == 2) ? 1 : 0));
215 if (!code && wl && extent_mod)
216 code = readExtents(ctx->trans); /* Fix the mh extent blocks */
219 ubik_AbortTrans(ctx->trans);
220 /* Only rebuld if the database is empty */
221 /* Exit if can't rebuild */
222 if ((pass == 1) && (code != VL_EMPTY))
226 } else { /* No code */
228 ubik_EndTrans(ctx->trans); /* Rebuilt db. End trans, then retake original lock */
230 break; /* didn't rebuild and successful - exit */
235 code = vlsetcache(ctx, locktype);
241 /* Create a new vldb entry; both new volume id and name must be unique
242 * (non-existant in vldb).
246 SVL_CreateEntry(struct rx_call *rxcall, struct vldbentry *newentry)
248 int this_op = VLCREATEENTRY;
250 afs_int32 code, blockindex;
251 struct nvlentry tentry;
252 char rxstr[AFS_RXINFO_LEN];
254 countRequest(this_op);
255 if (!afsconf_SuperUser(vldb_confdir, rxcall, NULL)) {
260 /* Do some validity tests on new entry */
261 if ((code = check_vldbentry(newentry))
262 || (code = Init_VLdbase(&ctx, LOCKWRITE, this_op)))
266 ("OCreate Volume %d %s\n", newentry->volumeId[RWVOL],
267 rxinfo(rxstr, rxcall)));
268 if (EntryIDExists(&ctx, newentry->volumeId, MAXTYPES, &code)) {
269 /* at least one of the specified IDs already exists; we fail */
276 /* Is this following check (by volume name) necessary?? */
277 /* If entry already exists, we fail */
278 if (FindByName(&ctx, newentry->name, &tentry, &code)) {
285 blockindex = AllocBlock(&ctx, &tentry);
286 if (blockindex == 0) {
287 code = VL_CREATEFAIL;
291 memset(&tentry, 0, sizeof(struct nvlentry));
292 /* Convert to its internal representation; both in host byte order */
293 if ((code = vldbentry_to_vlentry(&ctx, newentry, &tentry))) {
294 FreeBlock(&ctx, blockindex);
298 /* Actually insert the entry in vldb */
299 code = ThreadVLentry(&ctx, blockindex, &tentry);
301 FreeBlock(&ctx, blockindex);
304 code = ubik_EndTrans(ctx.trans);
310 ubik_AbortTrans(ctx.trans);
313 osi_auditU(rxcall, VLCreateEntryEvent, code, AUD_STR,
314 (newentry ? newentry->name : NULL), AUD_END);
320 SVL_CreateEntryN(struct rx_call *rxcall, struct nvldbentry *newentry)
322 int this_op = VLCREATEENTRYN;
324 afs_int32 code, blockindex;
325 struct nvlentry tentry;
326 char rxstr[AFS_RXINFO_LEN];
328 countRequest(this_op);
329 if (!afsconf_SuperUser(vldb_confdir, rxcall, NULL)) {
334 /* Do some validity tests on new entry */
335 if ((code = check_nvldbentry(newentry))
336 || (code = Init_VLdbase(&ctx, LOCKWRITE, this_op)))
340 ("Create Volume %d %s\n", newentry->volumeId[RWVOL],
341 rxinfo(rxstr, rxcall)));
342 if (EntryIDExists(&ctx, newentry->volumeId, MAXTYPES, &code)) {
343 /* at least one of the specified IDs already exists; we fail */
350 /* Is this following check (by volume name) necessary?? */
351 /* If entry already exists, we fail */
352 if (FindByName(&ctx, newentry->name, &tentry, &code)) {
359 blockindex = AllocBlock(&ctx, &tentry);
360 if (blockindex == 0) {
361 code = VL_CREATEFAIL;
365 memset(&tentry, 0, sizeof(struct nvlentry));
366 /* Convert to its internal representation; both in host byte order */
367 if ((code = nvldbentry_to_vlentry(&ctx, newentry, &tentry))) {
368 FreeBlock(&ctx, blockindex);
372 /* Actually insert the entry in vldb */
373 code = ThreadVLentry(&ctx, blockindex, &tentry);
375 FreeBlock(&ctx, blockindex);
378 code = ubik_EndTrans(ctx.trans);
384 ubik_AbortTrans(ctx.trans);
387 osi_auditU(rxcall, VLCreateEntryEvent, code, AUD_STR,
388 (newentry ? newentry->name : NULL), AUD_END);
394 SVL_ChangeAddr(struct rx_call *rxcall, afs_uint32 ip1, afs_uint32 ip2)
396 int this_op = VLCHANGEADDR;
399 char rxstr[AFS_RXINFO_LEN];
401 countRequest(this_op);
402 if (!afsconf_SuperUser(vldb_confdir, rxcall, NULL)) {
407 if ((code = Init_VLdbase(&ctx, LOCKWRITE, this_op)))
410 VLog(1, ("Change Addr %u -> %u %s\n", ip1, ip2, rxinfo(rxstr, rxcall)));
411 if ((code = ChangeIPAddr(&ctx, ip1, ip2)))
414 code = ubik_EndTrans(ctx.trans);
420 ubik_AbortTrans(ctx.trans);
423 osi_auditU(rxcall, VLChangeAddrEvent, code, AUD_LONG, ip1, AUD_LONG,
428 /* Delete a vldb entry given the volume id. */
430 SVL_DeleteEntry(struct rx_call *rxcall, afs_uint32 volid, afs_int32 voltype)
432 int this_op = VLDELETEENTRY;
434 afs_int32 blockindex, code;
435 struct nvlentry tentry;
436 char rxstr[AFS_RXINFO_LEN];
438 countRequest(this_op);
439 if (!afsconf_SuperUser(vldb_confdir, rxcall, NULL))
442 if ((voltype != -1) && (InvalidVoltype(voltype)))
445 if ((code = Init_VLdbase(&ctx, LOCKWRITE, this_op)))
448 VLog(1, ("Delete Volume %u %s\n", volid, rxinfo(rxstr, rxcall)));
449 blockindex = FindByID(&ctx, volid, voltype, &tentry, &code);
450 if (blockindex == 0) { /* volid not found */
456 if (tentry.flags & VLDELETED) { /* Already deleted; return */
457 ABORT(VL_ENTDELETED);
459 if ((code = RemoveEntry(&ctx, blockindex, &tentry))) {
462 code = (ubik_EndTrans(ctx.trans));
467 ubik_AbortTrans(ctx.trans);
470 osi_auditU(rxcall, VLDeleteEntryEvent, code, AUD_LONG, volid,
476 /* Get a vldb entry given its volume id; make sure it's not a deleted entry. */
478 GetEntryByID(struct rx_call *rxcall,
481 char *aentry, /* entry data copied here */
486 afs_int32 blockindex, code;
487 struct nvlentry tentry;
488 char rxstr[AFS_RXINFO_LEN];
490 countRequest(this_op);
492 if ((voltype != -1) && (InvalidVoltype(voltype)))
493 return VL_BADVOLTYPE;
494 if ((code = Init_VLdbase(&ctx, LOCKREAD, this_op)))
497 VLog(5, ("GetVolumeByID %u (%d) %s\n", volid, new,
498 rxinfo(rxstr, rxcall)));
499 blockindex = FindByID(&ctx, volid, voltype, &tentry, &code);
500 if (blockindex == 0) { /* entry not found */
505 if (tentry.flags & VLDELETED) { /* Entry is deleted! */
506 code = VL_ENTDELETED;
509 /* Convert from the internal to external form */
511 code = vlentry_to_nvldbentry(&ctx, &tentry, (struct nvldbentry *)aentry);
513 code = vlentry_to_uvldbentry(&ctx, &tentry, (struct uvldbentry *)aentry);
515 code = vlentry_to_vldbentry(&ctx, &tentry, (struct vldbentry *)aentry);
520 return (ubik_EndTrans(ctx.trans));
524 ubik_AbortTrans(ctx.trans);
529 SVL_GetEntryByID(struct rx_call *rxcall,
532 vldbentry *aentry) /* entry data copied here */
534 return (GetEntryByID(rxcall, volid, voltype, (char *)aentry, 0,
539 SVL_GetEntryByIDN(struct rx_call *rxcall,
542 nvldbentry *aentry) /* entry data copied here */
544 return (GetEntryByID(rxcall, volid, voltype, (char *)aentry, 1,
549 SVL_GetEntryByIDU(struct rx_call *rxcall,
552 uvldbentry *aentry) /* entry data copied here */
554 return (GetEntryByID(rxcall, volid, voltype, (char *)aentry, 2,
558 /* returns true if the id is a decimal integer, in which case we interpret
559 * it as an id. make the cache manager much simpler */
561 NameIsId(char *aname)
564 while ((tc = *aname++)) {
565 if (tc > '9' || tc < '0')
571 /* Get a vldb entry given the volume's name; of course, very similar to
572 * VLGetEntryByID() above. */
574 GetEntryByName(struct rx_call *rxcall,
576 char *aentry, /* entry data copied here */
581 afs_int32 blockindex, code;
582 struct nvlentry tentry;
583 char rxstr[AFS_RXINFO_LEN];
585 if (NameIsId(volname)) {
586 return GetEntryByID(rxcall, atoi(volname), -1, aentry, new, this_op);
588 if (InvalidVolname(volname))
590 if ((code = Init_VLdbase(&ctx, LOCKREAD, this_op)))
592 VLog(5, ("GetVolumeByName %s (%d) %s\n", volname, new, rxinfo(rxstr, rxcall)));
593 blockindex = FindByName(&ctx, volname, &tentry, &code);
594 if (blockindex == 0) { /* entry not found */
599 if (tentry.flags & VLDELETED) { /* Entry is deleted */
600 code = VL_ENTDELETED;
603 /* Convert to external entry representation */
605 code = vlentry_to_nvldbentry(&ctx, &tentry, (struct nvldbentry *)aentry);
607 code = vlentry_to_uvldbentry(&ctx, &tentry, (struct uvldbentry *)aentry);
609 code = vlentry_to_vldbentry(&ctx, &tentry, (struct vldbentry *)aentry);
614 return (ubik_EndTrans(ctx.trans));
618 ubik_AbortTrans(ctx.trans);
624 SVL_GetEntryByNameO(struct rx_call *rxcall,
626 struct vldbentry *aentry) /* entry data copied here */
628 return (GetEntryByName(rxcall, volname, (char *)aentry, 0,
634 SVL_GetEntryByNameN(struct rx_call *rxcall,
636 struct nvldbentry *aentry) /* entry data copied here */
638 return (GetEntryByName(rxcall, volname, (char *)aentry, 1,
643 SVL_GetEntryByNameU(struct rx_call *rxcall,
645 struct uvldbentry *aentry) /* entry data copied here */
647 return (GetEntryByName(rxcall, volname, (char *)aentry, 2,
653 /* Get the current value of the maximum volume id and bump the volume id counter by Maxvolidbump. */
655 SVL_GetNewVolumeId(struct rx_call *rxcall, afs_uint32 Maxvolidbump,
656 afs_uint32 *newvolumeid)
658 int this_op = VLGETNEWVOLUMEID;
660 afs_uint32 maxvolumeid;
662 char rxstr[AFS_RXINFO_LEN];
664 countRequest(this_op);
665 if (!afsconf_SuperUser(vldb_confdir, rxcall, NULL))
668 if (Maxvolidbump < 0 || Maxvolidbump > MAXBUMPCOUNT)
669 END(VL_BADVOLIDBUMP);
671 if ((code = Init_VLdbase(&ctx, LOCKWRITE, this_op)))
674 *newvolumeid = maxvolumeid = NextUnusedID(&ctx,
675 ntohl(ctx.cheader->vital_header.MaxVolumeId), Maxvolidbump, &code);
680 maxvolumeid += Maxvolidbump;
681 VLog(1, ("GetNewVolid newmax=%u %s\n", maxvolumeid, rxinfo(rxstr, rxcall)));
682 ctx.cheader->vital_header.MaxVolumeId = htonl(maxvolumeid);
683 if (write_vital_vlheader(&ctx)) {
686 code = (ubik_EndTrans(ctx.trans));
691 ubik_AbortTrans(ctx.trans);
694 osi_auditU(rxcall, VLGetNewVolumeIdEvent, code, AUD_END);
699 /* Simple replace the contents of the vldb entry, volid, with
700 * newentry. No individual checking/updating per field (alike
701 * VLUpdateEntry) is done. */
704 SVL_ReplaceEntry(struct rx_call *rxcall, afs_uint32 volid, afs_int32 voltype,
705 struct vldbentry *newentry, afs_int32 releasetype)
707 int this_op = VLREPLACEENTRY;
709 afs_int32 blockindex, code, typeindex;
711 int hashVol[MAXTYPES];
712 struct nvlentry tentry;
713 afs_uint32 checkids[MAXTYPES];
714 char rxstr[AFS_RXINFO_LEN];
716 countRequest(this_op);
717 for (typeindex = 0; typeindex < MAXTYPES; typeindex++)
718 hashVol[typeindex] = 0;
720 if (!afsconf_SuperUser(vldb_confdir, rxcall, NULL))
723 if ((code = check_vldbentry(newentry)))
726 if (voltype != -1 && InvalidVoltype(voltype))
729 if (releasetype && InvalidReleasetype(releasetype))
730 END(VL_BADRELLOCKTYPE);
731 if ((code = Init_VLdbase(&ctx, LOCKWRITE, this_op)))
734 VLog(1, ("OReplace Volume %u %s\n", volid, rxinfo(rxstr, rxcall)));
735 /* find vlentry we're changing */
736 blockindex = FindByID(&ctx, volid, voltype, &tentry, &code);
737 if (blockindex == 0) { /* entry not found */
743 /* check that we're not trying to change the RW vol ID */
744 if (newentry->volumeId[RWVOL] != tentry.volumeId[RWVOL]) {
748 /* make sure none of the IDs we are changing to are already in use */
749 memset(&checkids, 0, sizeof(checkids));
750 for (typeindex = ROVOL; typeindex < MAXTYPES; typeindex++) {
751 if (tentry.volumeId[typeindex] != newentry->volumeId[typeindex]) {
752 checkids[typeindex] = newentry->volumeId[typeindex];
755 if (EntryIDExists(&ctx, checkids, MAXTYPES, &code)) {
761 /* make sure the name we're changing to doesn't already exist */
762 if (strcmp(newentry->name, tentry.name)) {
763 struct nvlentry tmp_entry;
764 if (FindByName(&ctx, newentry->name, &tmp_entry, &code)) {
771 /* unhash volid entries if they're disappearing or changing.
772 * Remember if we need to hash in the new value (we don't have to
773 * rehash if volid stays same */
774 for (typeindex = ROVOL; typeindex <= BACKVOL; typeindex++) {
775 if (tentry.volumeId[typeindex] != newentry->volumeId[typeindex]) {
776 if (tentry.volumeId[typeindex])
778 UnhashVolid(&ctx, typeindex, blockindex, &tentry))) {
781 /* we must rehash new id if the id is different and the ID is nonzero */
782 hashVol[typeindex] = 1; /* must rehash this guy if he exists */
786 /* Rehash volname if it changes */
787 if (strcmp(newentry->name, tentry.name)) { /* Name changes; redo hashing */
788 if ((code = UnhashVolname(&ctx, blockindex, &tentry))) {
794 /* after this, tentry is new entry, not old one. vldbentry_to_vlentry
795 * doesn't touch hash chains */
796 if ((code = vldbentry_to_vlentry(&ctx, newentry, &tentry))) {
800 for (typeindex = ROVOL; typeindex <= BACKVOL; typeindex++) {
801 if (hashVol[typeindex] && tentry.volumeId[typeindex]) {
802 if ((code = HashVolid(&ctx, typeindex, blockindex, &tentry))) {
809 HashVolname(&ctx, blockindex, &tentry);
812 ReleaseEntry(&tentry, releasetype); /* Unlock entry if necessary */
813 if (vlentrywrite(ctx.trans, blockindex, &tentry, sizeof(tentry))) {
817 END(ubik_EndTrans(ctx.trans));
821 ubik_AbortTrans(ctx.trans);
824 osi_auditU(rxcall, VLReplaceVLEntryEvent, code, AUD_LONG, volid,
830 SVL_ReplaceEntryN(struct rx_call *rxcall, afs_uint32 volid, afs_int32 voltype,
831 struct nvldbentry *newentry, afs_int32 releasetype)
833 int this_op = VLREPLACEENTRYN;
835 afs_int32 blockindex, code, typeindex;
837 int hashVol[MAXTYPES];
838 struct nvlentry tentry;
839 char rxstr[AFS_RXINFO_LEN];
841 countRequest(this_op);
842 for (typeindex = 0; typeindex < MAXTYPES; typeindex++)
843 hashVol[typeindex] = 0;
845 if (!afsconf_SuperUser(vldb_confdir, rxcall, NULL))
848 if ((code = check_nvldbentry(newentry)))
851 if (voltype != -1 && InvalidVoltype(voltype))
854 if (releasetype && InvalidReleasetype(releasetype))
855 END(VL_BADRELLOCKTYPE);
856 if ((code = Init_VLdbase(&ctx, LOCKWRITE, this_op)))
859 VLog(1, ("Replace Volume %u %s\n", volid, rxinfo(rxstr, rxcall)));
860 /* find vlentry we're changing */
861 blockindex = FindByID(&ctx, volid, voltype, &tentry, &code);
862 if (blockindex == 0) { /* entry not found */
868 /* check that we're not trying to change the RW vol ID */
869 if (newentry->volumeId[RWVOL] != tentry.volumeId[RWVOL]) {
873 /* unhash volid entries if they're disappearing or changing.
874 * Remember if we need to hash in the new value (we don't have to
875 * rehash if volid stays same */
876 for (typeindex = ROVOL; typeindex <= BACKVOL; typeindex++) {
877 if (tentry.volumeId[typeindex] != newentry->volumeId[typeindex]) {
878 if (tentry.volumeId[typeindex])
880 UnhashVolid(&ctx, typeindex, blockindex, &tentry))) {
883 /* we must rehash new id if the id is different and the ID is nonzero */
884 hashVol[typeindex] = 1; /* must rehash this guy if he exists */
888 /* Rehash volname if it changes */
889 if (strcmp(newentry->name, tentry.name)) { /* Name changes; redo hashing */
890 if ((code = UnhashVolname(&ctx, blockindex, &tentry))) {
896 /* after this, tentry is new entry, not old one. vldbentry_to_vlentry
897 * doesn't touch hash chains */
898 if ((code = nvldbentry_to_vlentry(&ctx, newentry, &tentry))) {
902 for (typeindex = ROVOL; typeindex <= BACKVOL; typeindex++) {
903 if (hashVol[typeindex] && tentry.volumeId[typeindex]) {
904 if ((code = HashVolid(&ctx, typeindex, blockindex, &tentry))) {
911 HashVolname(&ctx, blockindex, &tentry);
914 ReleaseEntry(&tentry, releasetype); /* Unlock entry if necessary */
915 if (vlentrywrite(ctx.trans, blockindex, &tentry, sizeof(tentry))) {
919 END(ubik_EndTrans(ctx.trans));
923 ubik_AbortTrans(ctx.trans);
926 osi_auditU(rxcall, VLReplaceVLEntryEvent, code, AUD_LONG, volid,
932 /* Update a vldb entry (accessed thru its volume id). Almost all of the
933 * entry's fields can be modified in a single call by setting the
934 * appropriate bits in the Mask field in VldbUpdateentry. */
935 /* this routine may never have been tested; use replace entry instead
936 * unless you're brave */
938 SVL_UpdateEntry(struct rx_call *rxcall,
941 struct VldbUpdateEntry *updateentry, /* Update entry copied here */
942 afs_int32 releasetype)
944 int this_op = VLUPDATEENTRY;
946 afs_int32 blockindex, code;
947 struct nvlentry tentry;
948 char rxstr[AFS_RXINFO_LEN];
950 countRequest(this_op);
951 if (!afsconf_SuperUser(vldb_confdir, rxcall, NULL))
953 if ((voltype != -1) && (InvalidVoltype(voltype)))
955 if (releasetype && InvalidReleasetype(releasetype))
956 END(VL_BADRELLOCKTYPE);
957 if ((code = Init_VLdbase(&ctx, LOCKWRITE, this_op)))
960 VLog(1, ("Update Volume %u %s\n", volid, rxinfo(rxstr, rxcall)));
961 blockindex = FindByID(&ctx, volid, voltype, &tentry, &code);
962 if (blockindex == 0) { /* entry not found */
968 /* Do the actual updating of the entry, tentry. */
970 get_vldbupdateentry(&ctx, blockindex, updateentry, &tentry))) {
974 ReleaseEntry(&tentry, releasetype); /* Unlock entry if necessary */
975 if (vlentrywrite(ctx.trans, blockindex, &tentry, sizeof(tentry))) {
978 END(ubik_EndTrans(ctx.trans));
982 ubik_AbortTrans(ctx.trans);
985 osi_auditU(rxcall, VLUpdateEntryEvent, code, AUD_LONG, volid,
992 SVL_UpdateEntryByName(struct rx_call *rxcall,
994 struct VldbUpdateEntry *updateentry, /* Update entry copied here */
995 afs_int32 releasetype)
997 int this_op = VLUPDATEENTRYBYNAME;
999 afs_int32 blockindex, code;
1000 struct nvlentry tentry;
1002 countRequest(this_op);
1003 if (!afsconf_SuperUser(vldb_confdir, rxcall, NULL))
1005 if (releasetype && InvalidReleasetype(releasetype))
1006 END(VL_BADRELLOCKTYPE);
1007 if ((code = Init_VLdbase(&ctx, LOCKWRITE, this_op)))
1010 blockindex = FindByName(&ctx, volname, &tentry, &code);
1011 if (blockindex == 0) { /* entry not found */
1017 /* Do the actual updating of the entry, tentry. */
1019 get_vldbupdateentry(&ctx, blockindex, updateentry, &tentry))) {
1023 ReleaseEntry(&tentry, releasetype); /* Unlock entry if necessary */
1024 if (vlentrywrite(ctx.trans, blockindex, &tentry, sizeof(tentry))) {
1027 END(ubik_EndTrans(ctx.trans));
1030 countAbort(this_op);
1031 ubik_AbortTrans(ctx.trans);
1034 osi_auditU(rxcall, VLUpdateEntryEvent, code, AUD_LONG, -1, AUD_END);
1039 /* Set a lock to the vldb entry for volid (of type voltype if not -1). */
1041 SVL_SetLock(struct rx_call *rxcall, afs_uint32 volid, afs_int32 voltype,
1044 int this_op = VLSETLOCK;
1045 afs_int32 timestamp, blockindex, code;
1047 struct nvlentry tentry;
1048 char rxstr[AFS_RXINFO_LEN];
1050 countRequest(this_op);
1051 if (!afsconf_SuperUser(vldb_confdir, rxcall, NULL))
1053 if ((voltype != -1) && (InvalidVoltype(voltype)))
1055 if (InvalidOperation(voloper))
1057 if ((code = Init_VLdbase(&ctx, LOCKWRITE, this_op)))
1060 VLog(1, ("SetLock Volume %u %s\n", volid, rxinfo(rxstr, rxcall)));
1061 blockindex = FindByID(&ctx, volid, voltype, &tentry, &code);
1062 if (blockindex == NULLO) {
1067 if (tentry.flags & VLDELETED) {
1068 ABORT(VL_ENTDELETED);
1070 timestamp = FT_ApproxTime();
1072 /* Check if entry is already locked; note that we unlock any entry
1073 * locked more than MAXLOCKTIME seconds */
1074 if ((tentry.LockTimestamp)
1075 && ((timestamp - tentry.LockTimestamp) < MAXLOCKTIME)) {
1076 ABORT(VL_ENTRYLOCKED);
1079 /* Consider it an unlocked entry: set current timestamp, caller
1080 * and active vol operation */
1081 tentry.LockTimestamp = timestamp;
1082 tentry.LockAfsId = 0; /* Not implemented yet */
1083 if (tentry.flags & VLOP_RELEASE) {
1084 ABORT(VL_RERELEASE);
1086 tentry.flags &= ~VLOP_ALLOPERS; /* Clear any possible older operation bit */
1087 tentry.flags |= voloper;
1089 if (vlentrywrite(ctx.trans, blockindex, &tentry, sizeof(tentry))) {
1092 END(ubik_EndTrans(ctx.trans));
1095 countAbort(this_op);
1096 ubik_AbortTrans(ctx.trans);
1099 osi_auditU(rxcall, VLSetLockEvent, code, AUD_LONG, volid, AUD_END);
1104 /* Release an already locked vldb entry. Releasetype determines what
1105 * fields (afsid and/or volume operation) will be cleared along with
1106 * the lock time stamp. */
1109 SVL_ReleaseLock(struct rx_call *rxcall, afs_uint32 volid, afs_int32 voltype,
1110 afs_int32 releasetype)
1112 int this_op = VLRELEASELOCK;
1113 afs_int32 blockindex, code;
1115 struct nvlentry tentry;
1116 char rxstr[AFS_RXINFO_LEN];
1118 countRequest(this_op);
1119 if (!afsconf_SuperUser(vldb_confdir, rxcall, NULL))
1121 if ((voltype != -1) && (InvalidVoltype(voltype)))
1123 if (releasetype && InvalidReleasetype(releasetype))
1124 END(VL_BADRELLOCKTYPE);
1125 if ((code = Init_VLdbase(&ctx, LOCKWRITE, this_op)))
1128 VLog(1, ("ReleaseLock Volume %u %s\n", volid, rxinfo(rxstr, rxcall)));
1129 blockindex = FindByID(&ctx, volid, voltype, &tentry, &code);
1130 if (blockindex == NULLO) {
1135 if (tentry.flags & VLDELETED) {
1136 ABORT(VL_ENTDELETED);
1139 ReleaseEntry(&tentry, releasetype); /* Unlock the appropriate fields */
1140 if (vlentrywrite(ctx.trans, blockindex, &tentry, sizeof(tentry))) {
1143 END(ubik_EndTrans(ctx.trans));
1146 countAbort(this_op);
1147 ubik_AbortTrans(ctx.trans);
1150 osi_auditU(rxcall, VLReleaseLockEvent, code, AUD_LONG, volid,
1156 /* ListEntry returns a single vldb entry, aentry, with offset previous_index;
1157 * the remaining parameters (i.e. next_index) are used so that sequential
1158 * calls to this routine will get the next (all) vldb entries.
1161 SVL_ListEntry(struct rx_call *rxcall, afs_int32 previous_index,
1162 afs_int32 *count, afs_int32 *next_index,
1163 struct vldbentry *aentry)
1165 int this_op = VLLISTENTRY;
1168 struct nvlentry tentry;
1169 char rxstr[AFS_RXINFO_LEN];
1171 countRequest(this_op);
1172 if ((code = Init_VLdbase(&ctx, LOCKREAD, this_op)))
1174 VLog(25, ("OListEntry index=%d %s\n", previous_index,
1175 rxinfo(rxstr, rxcall)));
1176 *next_index = NextEntry(&ctx, previous_index, &tentry, count);
1178 code = vlentry_to_vldbentry(&ctx, &tentry, aentry);
1180 countAbort(this_op);
1181 ubik_AbortTrans(ctx.trans);
1185 return (ubik_EndTrans(ctx.trans));
1188 /* ListEntry returns a single vldb entry, aentry, with offset previous_index;
1189 * the remaining parameters (i.e. next_index) are used so that sequential
1190 * calls to this routine will get the next (all) vldb entries.
1193 SVL_ListEntryN(struct rx_call *rxcall, afs_int32 previous_index,
1194 afs_int32 *count, afs_int32 *next_index,
1195 struct nvldbentry *aentry)
1197 int this_op = VLLISTENTRYN;
1200 struct nvlentry tentry;
1201 char rxstr[AFS_RXINFO_LEN];
1203 countRequest(this_op);
1204 if ((code = Init_VLdbase(&ctx, LOCKREAD, this_op)))
1206 VLog(25, ("ListEntry index=%d %s\n", previous_index, rxinfo(rxstr, rxcall)));
1207 *next_index = NextEntry(&ctx, previous_index, &tentry, count);
1209 code = vlentry_to_nvldbentry(&ctx, &tentry, aentry);
1211 countAbort(this_op);
1212 ubik_AbortTrans(ctx.trans);
1217 return (ubik_EndTrans(ctx.trans));
1221 /* Retrieves in vldbentries all vldb entries that match the specified
1222 * attributes (by server number, partition, volume type, and flag); if volume
1223 * id is specified then the associated list for that entry is returned.
1224 * CAUTION: This could be a very expensive call since in most cases
1225 * sequential search of all vldb entries is performed.
1228 SVL_ListAttributes(struct rx_call *rxcall,
1229 struct VldbListByAttributes *attributes,
1230 afs_int32 *nentries,
1231 bulkentries *vldbentries)
1233 int this_op = VLLISTATTRIBUTES;
1234 int code, allocCount = 0;
1236 struct nvlentry tentry;
1237 struct vldbentry *Vldbentry = 0, *VldbentryFirst = 0, *VldbentryLast = 0;
1239 char rxstr[AFS_RXINFO_LEN];
1241 countRequest(this_op);
1242 vldbentries->bulkentries_val = 0;
1243 vldbentries->bulkentries_len = *nentries = 0;
1244 if ((code = Init_VLdbase(&ctx, LOCKREAD, this_op)))
1246 allocCount = VLDBALLOCCOUNT;
1247 Vldbentry = VldbentryFirst = vldbentries->bulkentries_val =
1248 (vldbentry *) malloc(allocCount * sizeof(vldbentry));
1249 if (Vldbentry == NULL) {
1253 VldbentryLast = VldbentryFirst + allocCount;
1254 /* Handle the attribute by volume id totally separate of the rest
1255 * (thus additional Mask values are ignored if VLLIST_VOLUMEID is set!) */
1256 if (attributes->Mask & VLLIST_VOLUMEID) {
1257 afs_int32 blockindex;
1260 FindByID(&ctx, attributes->volumeid, -1, &tentry, &code);
1261 if (blockindex == 0) {
1267 code = put_attributeentry(&ctx, &Vldbentry, &VldbentryFirst,
1268 &VldbentryLast, vldbentries, &tentry,
1269 nentries, &allocCount);
1273 afs_int32 nextblockindex = 0, count = 0, k = 0, match = 0;
1274 while ((nextblockindex =
1275 NextEntry(&ctx, nextblockindex, &tentry, &count))) {
1276 if (++pollcount > 50) {
1277 #ifndef AFS_PTHREAD_ENV
1283 if (attributes->Mask & VLLIST_SERVER) {
1286 IpAddrToRelAddr(&ctx, attributes->server, 0)) == -1)
1288 for (k = 0; k < OMAXNSERVERS; k++) {
1289 if (tentry.serverNumber[k] == BADSERVERID)
1291 if (tentry.serverNumber[k] == serverindex) {
1299 if (attributes->Mask & VLLIST_PARTITION) {
1301 if (tentry.serverPartition[k] != attributes->partition)
1304 for (k = 0; k < OMAXNSERVERS; k++) {
1305 if (tentry.serverNumber[k] == BADSERVERID)
1307 if (tentry.serverPartition[k] ==
1308 attributes->partition) {
1318 if (attributes->Mask & VLLIST_FLAG) {
1319 if (!(tentry.flags & attributes->flag))
1322 code = put_attributeentry(&ctx, &Vldbentry, &VldbentryFirst,
1323 &VldbentryLast, vldbentries, &tentry,
1324 nentries, &allocCount);
1329 if (vldbentries->bulkentries_len
1330 && (allocCount > vldbentries->bulkentries_len)) {
1332 vldbentries->bulkentries_val =
1333 (vldbentry *) realloc(vldbentries->bulkentries_val,
1334 vldbentries->bulkentries_len *
1336 if (vldbentries->bulkentries_val == NULL) {
1342 ("ListAttrs nentries=%d %s\n", vldbentries->bulkentries_len,
1343 rxinfo(rxstr, rxcall)));
1344 return (ubik_EndTrans(ctx.trans));
1347 if (vldbentries->bulkentries_val)
1348 free(vldbentries->bulkentries_val);
1349 vldbentries->bulkentries_val = 0;
1350 vldbentries->bulkentries_len = 0;
1352 countAbort(this_op);
1353 ubik_AbortTrans(ctx.trans);
1359 SVL_ListAttributesN(struct rx_call *rxcall,
1360 struct VldbListByAttributes *attributes,
1361 afs_int32 *nentries,
1362 nbulkentries *vldbentries)
1364 int this_op = VLLISTATTRIBUTESN;
1365 int code, allocCount = 0;
1367 struct nvlentry tentry;
1368 struct nvldbentry *Vldbentry = 0, *VldbentryFirst = 0, *VldbentryLast = 0;
1370 char rxstr[AFS_RXINFO_LEN];
1372 countRequest(this_op);
1373 vldbentries->nbulkentries_val = 0;
1374 vldbentries->nbulkentries_len = *nentries = 0;
1375 if ((code = Init_VLdbase(&ctx, LOCKREAD, this_op)))
1377 allocCount = VLDBALLOCCOUNT;
1378 Vldbentry = VldbentryFirst = vldbentries->nbulkentries_val =
1379 (nvldbentry *) malloc(allocCount * sizeof(nvldbentry));
1380 if (Vldbentry == NULL) {
1384 VldbentryLast = VldbentryFirst + allocCount;
1385 /* Handle the attribute by volume id totally separate of the rest
1386 * (thus additional Mask values are ignored if VLLIST_VOLUMEID is set!) */
1387 if (attributes->Mask & VLLIST_VOLUMEID) {
1388 afs_int32 blockindex;
1391 FindByID(&ctx, attributes->volumeid, -1, &tentry, &code);
1392 if (blockindex == 0) {
1398 code = put_nattributeentry(&ctx, &Vldbentry, &VldbentryFirst,
1399 &VldbentryLast, vldbentries, &tentry,
1400 0, 0, nentries, &allocCount);
1404 afs_int32 nextblockindex = 0, count = 0, k = 0, match = 0;
1405 while ((nextblockindex =
1406 NextEntry(&ctx, nextblockindex, &tentry, &count))) {
1407 if (++pollcount > 50) {
1408 #ifndef AFS_PTHREAD_ENV
1415 if (attributes->Mask & VLLIST_SERVER) {
1418 IpAddrToRelAddr(&ctx, attributes->server, 0)) == -1)
1420 for (k = 0; k < NMAXNSERVERS; k++) {
1421 if (tentry.serverNumber[k] == BADSERVERID)
1423 if (tentry.serverNumber[k] == serverindex) {
1431 if (attributes->Mask & VLLIST_PARTITION) {
1433 if (tentry.serverPartition[k] != attributes->partition)
1436 for (k = 0; k < NMAXNSERVERS; k++) {
1437 if (tentry.serverNumber[k] == BADSERVERID)
1439 if (tentry.serverPartition[k] ==
1440 attributes->partition) {
1450 if (attributes->Mask & VLLIST_FLAG) {
1451 if (!(tentry.flags & attributes->flag))
1454 code = put_nattributeentry(&ctx, &Vldbentry, &VldbentryFirst,
1455 &VldbentryLast, vldbentries,
1456 &tentry, 0, 0, nentries, &allocCount);
1461 if (vldbentries->nbulkentries_len
1462 && (allocCount > vldbentries->nbulkentries_len)) {
1464 vldbentries->nbulkentries_val =
1465 (nvldbentry *) realloc(vldbentries->nbulkentries_val,
1466 vldbentries->nbulkentries_len *
1467 sizeof(nvldbentry));
1468 if (vldbentries->nbulkentries_val == NULL) {
1474 ("NListAttrs nentries=%d %s\n", vldbentries->nbulkentries_len,
1475 rxinfo(rxstr, rxcall)));
1476 return (ubik_EndTrans(ctx.trans));
1479 countAbort(this_op);
1480 ubik_AbortTrans(ctx.trans);
1481 if (vldbentries->nbulkentries_val)
1482 free(vldbentries->nbulkentries_val);
1483 vldbentries->nbulkentries_val = 0;
1484 vldbentries->nbulkentries_len = 0;
1490 SVL_ListAttributesN2(struct rx_call *rxcall,
1491 struct VldbListByAttributes *attributes,
1492 char *name, /* Wildcarded volume name */
1493 afs_int32 startindex,
1494 afs_int32 *nentries,
1495 nbulkentries *vldbentries,
1496 afs_int32 *nextstartindex)
1498 int this_op = VLLISTATTRIBUTESN2;
1499 int code = 0, maxCount = VLDBALLOCCOUNT;
1501 struct nvlentry tentry;
1502 struct nvldbentry *Vldbentry = 0, *VldbentryFirst = 0, *VldbentryLast = 0;
1503 afs_int32 blockindex = 0, count = 0, k, match;
1504 afs_int32 matchindex = 0;
1505 int serverindex = -1; /* no server found */
1506 int findserver = 0, findpartition = 0, findflag = 0, findname = 0;
1508 int namematchRWBK, namematchRO, thismatch;
1510 char volumename[VL_MAXNAMELEN+2]; /* regex anchors */
1511 char rxstr[AFS_RXINFO_LEN];
1512 #ifdef HAVE_POSIX_REGEX
1514 int need_regfree = 0;
1519 countRequest(this_op);
1520 vldbentries->nbulkentries_val = 0;
1521 vldbentries->nbulkentries_len = 0;
1523 *nextstartindex = -1;
1525 code = Init_VLdbase(&ctx, LOCKREAD, this_op);
1529 Vldbentry = VldbentryFirst = vldbentries->nbulkentries_val =
1530 (nvldbentry *) malloc(maxCount * sizeof(nvldbentry));
1531 if (Vldbentry == NULL) {
1532 countAbort(this_op);
1533 ubik_AbortTrans(ctx.trans);
1537 VldbentryLast = VldbentryFirst + maxCount;
1539 /* Handle the attribute by volume id totally separate of the rest
1540 * (thus additional Mask values are ignored if VLLIST_VOLUMEID is set!)
1542 if (attributes->Mask & VLLIST_VOLUMEID) {
1544 FindByID(&ctx, attributes->volumeid, -1, &tentry, &code);
1545 if (blockindex == 0) {
1550 put_nattributeentry(&ctx, &Vldbentry, &VldbentryFirst,
1551 &VldbentryLast, vldbentries, &tentry, 0,
1552 0, nentries, &maxCount);
1558 /* Search each entry in the database and return all entries
1559 * that match the request. It checks volumename (with
1560 * wildcarding), entry flags, server, and partition.
1563 /* Get the server index for matching server address */
1564 if (attributes->Mask & VLLIST_SERVER) {
1566 IpAddrToRelAddr(&ctx, attributes->server, 0);
1567 if (serverindex == -1)
1571 findpartition = ((attributes->Mask & VLLIST_PARTITION) ? 1 : 0);
1572 findflag = ((attributes->Mask & VLLIST_FLAG) ? 1 : 0);
1573 if (name && (strcmp(name, ".*") != 0) && (strcmp(name, "") != 0)) {
1574 sprintf(volumename, "^%s$", name);
1575 #ifdef HAVE_POSIX_REGEX
1576 if (regcomp(&re, volumename, REG_NOSUB) != 0) {
1582 t = (char *)re_comp(volumename);
1591 /* Read each entry and see if it is the one we want */
1592 blockindex = startindex;
1593 while ((blockindex = NextEntry(&ctx, blockindex, &tentry, &count))) {
1594 if (++pollcount > 50) {
1595 #ifndef AFS_PTHREAD_ENV
1601 /* Step through each server index searching for a match.
1602 * Match to an existing RW, BK, or RO volume name (preference
1603 * is in this order). Remember which index we matched against.
1605 namematchRWBK = namematchRO = 0; /* 0->notTried; 1->match; 2->noMatch */
1609 && (tentry.serverNumber[k] != BADSERVERID)); k++) {
1610 thismatch = 0; /* does this index match */
1612 /* Match against the RW or BK volume name. Remember
1613 * results in namematchRWBK. Prefer RW over BK.
1615 if (tentry.serverFlags[k] & VLSF_RWVOL) {
1616 /* Does the name match the RW name */
1617 if (tentry.flags & VLF_RWEXISTS) {
1619 sprintf(volumename, "%s", tentry.name);
1620 #ifdef HAVE_POSIX_REGEX
1621 if (regexec(&re, volumename, 0, NULL, 0) == 0) {
1622 thismatch = VLSF_RWVOL;
1625 if (re_exec(volumename)) {
1626 thismatch = VLSF_RWVOL;
1630 thismatch = VLSF_RWVOL;
1634 /* Does the name match the BK name */
1635 if (!thismatch && (tentry.flags & VLF_BACKEXISTS)) {
1637 sprintf(volumename, "%s.backup", tentry.name);
1638 #ifdef HAVE_POSIX_REGEX
1639 if (regexec(&re, volumename, 0, NULL, 0) == 0) {
1640 thismatch = VLSF_BACKVOL;
1643 if (re_exec(volumename)) {
1644 thismatch = VLSF_BACKVOL;
1648 thismatch = VLSF_BACKVOL;
1652 namematchRWBK = (thismatch ? 1 : 2);
1655 /* Match with the RO volume name. Compare once and
1656 * remember results in namematchRO. Note that this will
1657 * pick up entries marked NEWREPSITEs and DONTUSE.
1660 if (tentry.flags & VLF_ROEXISTS) {
1664 ((namematchRO == 1) ? VLSF_ROVOL : 0);
1666 sprintf(volumename, "%s.readonly",
1668 #ifdef HAVE_POSIX_REGEX
1669 if (regexec(&re, volumename, 0, NULL, 0) == 0) {
1670 thismatch = VLSF_ROVOL;
1673 if (re_exec(volumename))
1674 thismatch = VLSF_ROVOL;
1678 thismatch = VLSF_ROVOL;
1681 namematchRO = (thismatch ? 1 : 2);
1684 /* Is there a server match */
1685 if (thismatch && findserver
1686 && (tentry.serverNumber[k] != serverindex))
1689 /* Is there a partition match */
1690 if (thismatch && findpartition
1691 && (tentry.serverPartition[k] != attributes->partition))
1694 /* Is there a flag match */
1695 if (thismatch && findflag
1696 && !(tentry.flags & attributes->flag))
1699 /* We found a match. Remember the index, and type */
1703 matchtype = thismatch;
1706 /* Since we prefer RW and BK volume matches over RO matches,
1707 * if we have already checked the RWBK name, then we already
1708 * found the best match and so end the search.
1710 * If we tried matching against the RW, BK, and RO volume names
1711 * and both failed, then we end the search (none will match).
1713 if ((match && namematchRWBK)
1714 || ((namematchRWBK == 2) && (namematchRO == 2)))
1718 /* Passed all the tests. Take it */
1721 put_nattributeentry(&ctx, &Vldbentry, &VldbentryFirst,
1722 &VldbentryLast, vldbentries, &tentry,
1723 matchtype, matchindex, nentries,
1728 if (*nentries >= maxCount)
1729 break; /* collected the max */
1732 *nextstartindex = (blockindex ? blockindex : -1);
1736 #ifdef HAVE_POSIX_REGEX
1742 countAbort(this_op);
1743 ubik_AbortTrans(ctx.trans);
1744 if (vldbentries->nbulkentries_val)
1745 free((char *)vldbentries->nbulkentries_val);
1746 vldbentries->nbulkentries_val = 0;
1747 vldbentries->nbulkentries_len = 0;
1748 *nextstartindex = -1;
1752 ("N2ListAttrs nentries=%d %s\n", vldbentries->nbulkentries_len,
1753 rxinfo(rxstr, rxcall)));
1754 return (ubik_EndTrans(ctx.trans));
1759 /* Retrieves in vldbentries all vldb entries that match the specified
1760 * attributes (by server number, partition, volume type, and flag); if
1761 * volume id is specified then the associated list for that entry is
1762 * returned. CAUTION: This could be a very expensive call since in most
1763 * cases sequential search of all vldb entries is performed.
1766 SVL_LinkedList(struct rx_call *rxcall,
1767 struct VldbListByAttributes *attributes,
1768 afs_int32 *nentries,
1769 vldb_list *vldbentries)
1771 int this_op = VLLINKEDLIST;
1774 struct nvlentry tentry;
1775 vldblist vllist, *vllistptr;
1776 afs_int32 blockindex, count, match;
1781 countRequest(this_op);
1782 if ((code = Init_VLdbase(&ctx, LOCKREAD, this_op)))
1786 vldbentries->node = NULL;
1787 vllistptr = &vldbentries->node;
1789 /* List by volumeid */
1790 if (attributes->Mask & VLLIST_VOLUMEID) {
1792 FindByID(&ctx, attributes->volumeid, -1, &tentry, &code);
1799 vllist = (single_vldbentry *) malloc(sizeof(single_vldbentry));
1800 if (vllist == NULL) {
1804 code = vlentry_to_vldbentry(&ctx, &tentry, &vllist->VldbEntry);
1808 vllist->next_vldb = NULL;
1810 *vllistptr = vllist; /* Thread onto list */
1811 vllistptr = &vllist->next_vldb;
1815 /* Search by server, partition, and flags */
1817 for (blockindex = NextEntry(&ctx, 0, &tentry, &count); blockindex;
1818 blockindex = NextEntry(&ctx, blockindex, &tentry, &count)) {
1821 if (++pollcount > 50) {
1822 #ifndef AFS_PTHREAD_ENV
1828 /* Does this volume exist on the desired server */
1829 if (attributes->Mask & VLLIST_SERVER) {
1831 IpAddrToRelAddr(&ctx, attributes->server, 0);
1832 if (serverindex == -1)
1834 for (k = 0; k < OMAXNSERVERS; k++) {
1835 if (tentry.serverNumber[k] == BADSERVERID)
1837 if (tentry.serverNumber[k] == serverindex) {
1846 /* Does this volume exist on the desired partition */
1847 if (attributes->Mask & VLLIST_PARTITION) {
1849 if (tentry.serverPartition[k] != attributes->partition)
1852 for (k = 0; k < OMAXNSERVERS; k++) {
1853 if (tentry.serverNumber[k] == BADSERVERID)
1855 if (tentry.serverPartition[k] ==
1856 attributes->partition) {
1866 /* Does this volume have the desired flags */
1867 if (attributes->Mask & VLLIST_FLAG) {
1868 if (!(tentry.flags & attributes->flag))
1872 vllist = (single_vldbentry *) malloc(sizeof(single_vldbentry));
1873 if (vllist == NULL) {
1877 code = vlentry_to_vldbentry(&ctx, &tentry, &vllist->VldbEntry);
1881 vllist->next_vldb = NULL;
1883 *vllistptr = vllist; /* Thread onto list */
1884 vllistptr = &vllist->next_vldb;
1886 if (smallMem && (*nentries >= VLDBALLOCCOUNT)) {
1887 code = VL_SIZEEXCEEDED;
1893 return (ubik_EndTrans(ctx.trans));
1896 countAbort(this_op);
1897 ubik_AbortTrans(ctx.trans);
1902 SVL_LinkedListN(struct rx_call *rxcall,
1903 struct VldbListByAttributes *attributes,
1904 afs_int32 *nentries,
1905 nvldb_list *vldbentries)
1907 int this_op = VLLINKEDLISTN;
1910 struct nvlentry tentry;
1911 nvldblist vllist, *vllistptr;
1912 afs_int32 blockindex, count, match;
1917 countRequest(this_op);
1918 if ((code = Init_VLdbase(&ctx, LOCKREAD, this_op)))
1922 vldbentries->node = NULL;
1923 vllistptr = &vldbentries->node;
1925 /* List by volumeid */
1926 if (attributes->Mask & VLLIST_VOLUMEID) {
1928 FindByID(&ctx, attributes->volumeid, -1, &tentry, &code);
1935 vllist = (single_nvldbentry *) malloc(sizeof(single_nvldbentry));
1936 if (vllist == NULL) {
1940 code = vlentry_to_nvldbentry(&ctx, &tentry, &vllist->VldbEntry);
1944 vllist->next_vldb = NULL;
1946 *vllistptr = vllist; /* Thread onto list */
1947 vllistptr = &vllist->next_vldb;
1951 /* Search by server, partition, and flags */
1953 for (blockindex = NextEntry(&ctx, 0, &tentry, &count); blockindex;
1954 blockindex = NextEntry(&ctx, blockindex, &tentry, &count)) {
1957 if (++pollcount > 50) {
1958 #ifndef AFS_PTHREAD_ENV
1964 /* Does this volume exist on the desired server */
1965 if (attributes->Mask & VLLIST_SERVER) {
1967 IpAddrToRelAddr(&ctx, attributes->server, 0);
1968 if (serverindex == -1)
1970 for (k = 0; k < NMAXNSERVERS; k++) {
1971 if (tentry.serverNumber[k] == BADSERVERID)
1973 if (tentry.serverNumber[k] == serverindex) {
1982 /* Does this volume exist on the desired partition */
1983 if (attributes->Mask & VLLIST_PARTITION) {
1985 if (tentry.serverPartition[k] != attributes->partition)
1988 for (k = 0; k < NMAXNSERVERS; k++) {
1989 if (tentry.serverNumber[k] == BADSERVERID)
1991 if (tentry.serverPartition[k] ==
1992 attributes->partition) {
2002 /* Does this volume have the desired flags */
2003 if (attributes->Mask & VLLIST_FLAG) {
2004 if (!(tentry.flags & attributes->flag))
2008 vllist = (single_nvldbentry *) malloc(sizeof(single_nvldbentry));
2009 if (vllist == NULL) {
2013 code = vlentry_to_nvldbentry(&ctx, &tentry, &vllist->VldbEntry);
2017 vllist->next_vldb = NULL;
2019 *vllistptr = vllist; /* Thread onto list */
2020 vllistptr = &vllist->next_vldb;
2022 if (smallMem && (*nentries >= VLDBALLOCCOUNT)) {
2023 code = VL_SIZEEXCEEDED;
2029 return (ubik_EndTrans(ctx.trans));
2032 countAbort(this_op);
2033 ubik_AbortTrans(ctx.trans);
2037 /* Get back vldb header statistics (allocs, frees, maxvolumeid,
2038 * totalentries, etc) and dynamic statistics (number of requests and/or
2039 * aborts per remote procedure call, etc)
2042 SVL_GetStats(struct rx_call *rxcall,
2044 vital_vlheader *vital_header)
2046 int this_op = VLGETSTATS;
2049 char rxstr[AFS_RXINFO_LEN];
2051 countRequest(this_op);
2053 /* Allow users to get statistics freely */
2054 if (!afsconf_SuperUser(vldb_confdir, rxcall, NULL)) /* Must be in 'UserList' to use */
2057 if ((code = Init_VLdbase(&ctx, LOCKREAD, this_op)))
2059 VLog(5, ("GetStats %s\n", rxinfo(rxstr, rxcall)));
2060 memcpy((char *)vital_header, (char *)&ctx.cheader->vital_header,
2061 sizeof(vital_vlheader));
2062 memcpy((char *)stats, (char *)&dynamic_statistics, sizeof(vldstats));
2063 return (ubik_EndTrans(ctx.trans));
2066 /* Get the list of file server addresses from the VLDB. Currently it's pretty
2067 * easy to do. In the future, it might require a little bit of grunging
2068 * through the VLDB, but that's life.
2071 SVL_GetAddrs(struct rx_call *rxcall,
2074 struct VLCallBack *spare3,
2075 afs_int32 *nentries,
2078 int this_op = VLGETADDRS;
2084 countRequest(this_op);
2085 addrsp->bulkaddrs_len = *nentries = 0;
2086 addrsp->bulkaddrs_val = 0;
2087 memset(spare3, 0, sizeof(struct VLCallBack));
2089 if ((code = Init_VLdbase(&ctx, LOCKREAD, this_op)))
2092 VLog(5, ("GetAddrs\n"));
2093 addrsp->bulkaddrs_val = taddrp =
2094 (afs_uint32 *) malloc(sizeof(afs_int32) * (MAXSERVERID + 1));
2095 nservers = *nentries = addrsp->bulkaddrs_len = 0;
2102 for (i = 0; i <= MAXSERVERID; i++) {
2103 if ((*taddrp = ntohl(ctx.cheader->IpMappedAddr[i]))) {
2109 addrsp->bulkaddrs_len = *nentries = nservers;
2110 return (ubik_EndTrans(ctx.trans));
2113 countAbort(this_op);
2114 ubik_AbortTrans(ctx.trans);
2118 #define PADDR(addr) VLog(0,("%d.%d.%d.%d", (addr>>24)&0xff, (addr>>16)&0xff, (addr>>8) &0xff, addr&0xff));
2121 SVL_RegisterAddrs(struct rx_call *rxcall, afsUUID *uuidp, afs_int32 spare1,
2124 int this_op = VLREGADDR;
2127 int cnt, h, i, j, k, m;
2128 struct extentaddr *exp = 0, *tex;
2130 afs_uint32 addrs[VL_MAXIPADDRS_PERMH];
2132 int count, willChangeEntry, foundUuidEntry, willReplaceCnt;
2133 int WillReplaceEntry, WillChange[MAXSERVERID + 1];
2135 int ReplaceEntry = 0;
2138 countRequest(this_op);
2139 if (!afsconf_SuperUser(vldb_confdir, rxcall, NULL))
2141 if ((code = Init_VLdbase(&ctx, LOCKWRITE, this_op)))
2144 /* Eliminate duplicates from IP address list */
2145 for (k = 0, cnt = 0; k < addrsp->bulkaddrs_len; k++) {
2146 if (addrsp->bulkaddrs_val[k] == 0)
2148 for (m = 0; m < cnt; m++) {
2149 if (addrs[m] == addrsp->bulkaddrs_val[k])
2153 if (m == VL_MAXIPADDRS_PERMH) {
2155 ("Number of addresses exceeds %d. Cannot register IP addr 0x%x in VLDB\n",
2156 VL_MAXIPADDRS_PERMH, addrsp->bulkaddrs_val[k]));
2158 addrs[m] = addrsp->bulkaddrs_val[k];
2164 code = VL_INDEXERANGE;
2171 /* For each server registered within the VLDB */
2172 for (srvidx = 0; srvidx <= MAXSERVERID; srvidx++) {
2173 willChangeEntry = 0;
2174 WillReplaceEntry = 1;
2175 code = multiHomedExtent(&ctx, srvidx, &exp);
2180 /* See if the addresses to register will change this server entry */
2181 tuuid = exp->ex_hostuuid;
2182 afs_ntohuuid(&tuuid);
2183 if (afs_uuid_equal(uuidp, &tuuid)) {
2187 for (mhidx = 0; mhidx < VL_MAXIPADDRS_PERMH; mhidx++) {
2188 if (!exp->ex_addrs[mhidx])
2190 for (k = 0; k < cnt; k++) {
2191 if (ntohl(exp->ex_addrs[mhidx]) == addrs[k]) {
2192 willChangeEntry = 1;
2193 WillChange[count] = srvidx;
2198 WillReplaceEntry = 0;
2202 /* The server is not registered as a multihomed.
2203 * See if the addresses to register will replace this server entry.
2205 for (k = 0; k < cnt; k++) {
2206 if (ctx.hostaddress[srvidx] == addrs[k]) {
2207 willChangeEntry = 1;
2208 WillChange[count] = srvidx;
2209 WillReplaceEntry = 1;
2214 if (willChangeEntry) {
2215 if (WillReplaceEntry) {
2217 ReplaceEntry = srvidx;
2223 /* If we found the uuid in the VLDB and if we are replacing another
2224 * entire entry, then complain and fail. Also, if we did not find
2225 * the uuid in the VLDB and the IP addresses being registered was
2226 * found in more than one other entry, then we don't know which one
2227 * to replace and will complain and fail.
2229 if ((foundUuidEntry && (willReplaceCnt > 0))
2230 || (!foundUuidEntry && (count > 1))) {
2232 ("The following fileserver is being registered in the VLDB:\n"));
2234 for (k = 0; k < cnt; k++) {
2241 if (foundUuidEntry) {
2242 code = multiHomedExtent(&ctx, FoundUuid, &exp);
2244 VLog(0, (" It would have replaced the existing VLDB server "
2246 VLog(0, (" entry %d: [", FoundUuid));
2247 for (mhidx = 0; mhidx < VL_MAXIPADDRS_PERMH; mhidx++) {
2248 if (!exp->ex_addrs[mhidx])
2252 PADDR(ntohl(exp->ex_addrs[mhidx]));
2259 VLog(0, (" Yet another VLDB server entry exists:\n"));
2261 VLog(0, (" Yet other VLDB server entries exist:\n"));
2262 for (j = 0; j < count; j++) {
2263 srvidx = WillChange[j];
2264 VLog(0, (" entry %d: ", srvidx));
2266 code = multiHomedExtent(&ctx, srvidx, &exp);
2272 for (mhidx = 0; mhidx < VL_MAXIPADDRS_PERMH; mhidx++) {
2273 if (!exp->ex_addrs[mhidx])
2277 PADDR(ntohl(exp->ex_addrs[mhidx]));
2281 PADDR(ctx.hostaddress[srvidx]);
2287 VLog(0, (" You must 'vos changeaddr' this other server entry\n"));
2290 (" You must 'vos changeaddr' these other server entries\n"));
2293 (" and/or remove the sysid file from the registering fileserver\n"));
2294 VLog(0, (" before the fileserver can be registered in the VLDB.\n"));
2296 code = VL_MULTIPADDR;
2300 /* Passed the checks. Now find and update the existing mh entry, or create
2303 if (foundUuidEntry) {
2304 /* Found the entry with same uuid. See if we need to change it */
2307 code = multiHomedExtentBase(&ctx, FoundUuid, &exp, &base);
2311 /* Determine if the entry has changed */
2312 for (k = 0; ((k < cnt) && !change); k++) {
2313 if (ntohl(exp->ex_addrs[k]) != addrs[k])
2316 for (; ((k < VL_MAXIPADDRS_PERMH) && !change); k++) {
2317 if (exp->ex_addrs[k] != 0)
2321 return (ubik_EndTrans(ctx.trans));
2325 VLog(0, ("The following fileserver is being registered in the VLDB:\n"));
2327 for (k = 0; k < cnt; k++) {
2334 if (foundUuidEntry) {
2336 (" It will replace the following existing entry in the VLDB (same uuid):\n"));
2337 VLog(0, (" entry %d: [", FoundUuid));
2338 for (k = 0; k < VL_MAXIPADDRS_PERMH; k++) {
2339 if (exp->ex_addrs[k] == 0)
2343 PADDR(ntohl(exp->ex_addrs[k]));
2346 } else if (willReplaceCnt || (count == 1)) {
2347 /* If we are not replacing an entry and there is only one entry to change,
2348 * then we will replace that entry.
2350 if (!willReplaceCnt) {
2351 ReplaceEntry = WillChange[0];
2355 /* Have an entry that needs to be replaced */
2356 code = multiHomedExtentBase(&ctx, ReplaceEntry, &exp, &base);
2362 (" It will replace the following existing entry in the VLDB (new uuid):\n"));
2363 VLog(0, (" entry %d: [", ReplaceEntry));
2364 for (k = 0; k < VL_MAXIPADDRS_PERMH; k++) {
2365 if (exp->ex_addrs[k] == 0)
2369 PADDR(ntohl(exp->ex_addrs[k]));
2373 /* Not a mh entry. So we have to create a new mh entry and
2374 * put it on the ReplaceEntry slot of the ctx.hostaddress array.
2376 VLog(0, (" It will replace existing entry %d, ", ReplaceEntry));
2377 PADDR(ctx.hostaddress[ReplaceEntry]);
2378 VLog(0,(", in the VLDB (new uuid):\n"));
2381 FindExtentBlock(&ctx, uuidp, 1, ReplaceEntry, &exp, &base);
2389 /* There is no entry for this server, must create a new mh entry as
2390 * well as use a new slot of the ctx.hostaddress array.
2392 VLog(0, (" It will create a new entry in the VLDB.\n"));
2393 code = FindExtentBlock(&ctx, uuidp, 1, -1, &exp, &base);
2401 /* Now we have a mh entry to fill in. Update the uuid, bump the
2402 * uniquifier, and fill in its IP addresses.
2405 afs_htonuuid(&tuuid);
2406 exp->ex_hostuuid = tuuid;
2407 exp->ex_uniquifier = htonl(ntohl(exp->ex_uniquifier) + 1);
2408 for (k = 0; k < cnt; k++) {
2409 exp->ex_addrs[k] = htonl(addrs[k]);
2411 for (; k < VL_MAXIPADDRS_PERMH; k++) {
2412 exp->ex_addrs[k] = 0;
2415 /* Write the new mh entry out */
2418 DOFFSET(ntohl(ctx.ex_addr[0]->ex_contaddrs[base]),
2419 (char *)ctx.ex_addr[base], (char *)exp), (char *)exp,
2425 /* Remove any common addresses from other mh entres. We know these entries
2426 * are being changed and not replaced so they are mh entries.
2429 for (i = 0; i < count; i++) {
2432 /* Skip the entry we replaced */
2433 if (willReplaceCnt && (WillChange[i] == ReplaceEntry))
2436 code = multiHomedExtentBase(&ctx, WillChange[i], &tex, &base);
2442 (" The following existing entries in the VLDB will be updated:\n"));
2444 VLog(0, (" entry %d: [", WillChange[i]));
2445 for (h = j = 0; j < VL_MAXIPADDRS_PERMH; j++) {
2446 if (tex->ex_addrs[j]) {
2449 PADDR(ntohl(tex->ex_addrs[j]));
2452 for (k = 0; k < cnt; k++) {
2453 if (ntohl(tex->ex_addrs[j]) == addrs[k])
2457 /* Not found, so we keep it */
2458 tex->ex_addrs[h] = tex->ex_addrs[j];
2462 for (j = h; j < VL_MAXIPADDRS_PERMH; j++) {
2463 tex->ex_addrs[j] = 0; /* zero rest of mh entry */
2467 /* Write out the modified mh entry */
2468 tex->ex_uniquifier = htonl(ntohl(tex->ex_uniquifier) + 1);
2470 DOFFSET(ntohl(ctx.ex_addr[0]->ex_contaddrs[base]),
2471 (char *)ctx.ex_addr[base], (char *)tex);
2472 if (vlwrite(ctx.trans, doff, (char *)tex, sizeof(*tex))) {
2478 return (ubik_EndTrans(ctx.trans));
2481 countAbort(this_op);
2482 ubik_AbortTrans(ctx.trans);
2487 SVL_GetAddrsU(struct rx_call *rxcall,
2488 struct ListAddrByAttributes *attributes,
2490 afs_int32 *uniquifier,
2491 afs_int32 *nentries,
2494 int this_op = VLGETADDRSU;
2495 afs_int32 code, index = -1, offset;
2497 int nservers, i, j, base = 0;
2498 struct extentaddr *exp = 0;
2500 afs_uint32 *taddrp, taddr;
2501 char rxstr[AFS_RXINFO_LEN];
2503 countRequest(this_op);
2504 addrsp->bulkaddrs_len = *nentries = 0;
2505 addrsp->bulkaddrs_val = 0;
2506 VLog(5, ("GetAddrsU %s\n", rxinfo(rxstr, rxcall)));
2507 if ((code = Init_VLdbase(&ctx, LOCKREAD, this_op)))
2510 if (attributes->Mask & VLADDR_IPADDR) {
2511 if (attributes->Mask & (VLADDR_INDEX | VLADDR_UUID)) {
2515 for (base = 0; base < VL_MAX_ADDREXTBLKS; base++) {
2516 if (!ctx.ex_addr[base])
2518 for (i = 1; i < VL_MHSRV_PERBLK; i++) {
2519 exp = &ctx.ex_addr[base][i];
2520 tuuid = exp->ex_hostuuid;
2521 afs_ntohuuid(&tuuid);
2522 if (afs_uuid_is_nil(&tuuid))
2524 for (j = 0; j < VL_MAXIPADDRS_PERMH; j++) {
2525 if (exp->ex_addrs[j]
2526 && (ntohl(exp->ex_addrs[j]) == attributes->ipaddr)) {
2530 if (j < VL_MAXIPADDRS_PERMH)
2533 if (i < VL_MHSRV_PERBLK)
2536 if (base >= VL_MAX_ADDREXTBLKS) {
2540 } else if (attributes->Mask & VLADDR_INDEX) {
2541 if (attributes->Mask & (VLADDR_IPADDR | VLADDR_UUID)) {
2545 index = attributes->index;
2546 if (index < 1 || index >= (VL_MAX_ADDREXTBLKS * VL_MHSRV_PERBLK)) {
2547 code = VL_INDEXERANGE;
2550 base = index / VL_MHSRV_PERBLK;
2551 offset = index % VL_MHSRV_PERBLK;
2556 if (!ctx.ex_addr[base]) {
2557 code = VL_INDEXERANGE;
2560 exp = &ctx.ex_addr[base][offset];
2561 } else if (attributes->Mask & VLADDR_UUID) {
2562 if (attributes->Mask & (VLADDR_IPADDR | VLADDR_INDEX)) {
2566 if (!ctx.ex_addr[0]) { /* mh servers probably aren't setup on this vldb */
2570 code = FindExtentBlock(&ctx, &attributes->uuid, 0, -1, &exp, &base);
2582 addrsp->bulkaddrs_val = taddrp =
2583 (afs_uint32 *) malloc(sizeof(afs_int32) * (MAXSERVERID + 1));
2584 nservers = *nentries = addrsp->bulkaddrs_len = 0;
2589 tuuid = exp->ex_hostuuid;
2590 afs_ntohuuid(&tuuid);
2591 if (afs_uuid_is_nil(&tuuid)) {
2598 *uniquifier = ntohl(exp->ex_uniquifier);
2599 for (i = 0; i < VL_MAXIPADDRS_PERMH; i++) {
2600 if (exp->ex_addrs[i]) {
2601 taddr = ntohl(exp->ex_addrs[i]);
2602 /* Weed out duplicates */
2603 for (j = 0; j < nservers; j++) {
2604 if (taddrp[j] == taddr)
2607 if ((j == nservers) && (j <= MAXSERVERID)) {
2608 taddrp[nservers] = taddr;
2613 addrsp->bulkaddrs_len = *nentries = nservers;
2614 return (ubik_EndTrans(ctx.trans));
2617 countAbort(this_op);
2618 ubik_AbortTrans(ctx.trans);
2622 /* ============> End of Exported vldb RPC functions <============= */
2625 /* Routine that copies the given vldb entry to the output buffer, vldbentries. */
2627 put_attributeentry(struct vl_ctx *ctx,
2628 struct vldbentry **Vldbentry,
2629 struct vldbentry **VldbentryFirst,
2630 struct vldbentry **VldbentryLast,
2631 bulkentries *vldbentries,
2632 struct nvlentry *entry,
2633 afs_int32 *nentries,
2634 afs_int32 *alloccnt)
2640 if (*Vldbentry == *VldbentryLast) {
2642 return VL_SIZEEXCEEDED; /* no growing if smallMem defined */
2644 /* Allocate another set of memory; each time allocate twice as
2645 * many blocks as the last time. When we reach VLDBALLOCLIMIT,
2646 * then grow in increments of VLDBALLOCINCR.
2648 allo = (*alloccnt > VLDBALLOCLIMIT) ? VLDBALLOCINCR : *alloccnt;
2650 (vldbentry *) realloc(*VldbentryFirst,
2651 (*alloccnt + allo) * sizeof(vldbentry));
2655 *VldbentryFirst = vldbentries->bulkentries_val = reall;
2656 *Vldbentry = *VldbentryFirst + *alloccnt;
2657 *VldbentryLast = *Vldbentry + allo;
2661 code = vlentry_to_vldbentry(ctx, entry, *Vldbentry);
2667 vldbentries->bulkentries_len++;
2672 put_nattributeentry(struct vl_ctx *ctx,
2673 struct nvldbentry **Vldbentry,
2674 struct nvldbentry **VldbentryFirst,
2675 struct nvldbentry **VldbentryLast,
2676 nbulkentries *vldbentries,
2677 struct nvlentry *entry,
2678 afs_int32 matchtype,
2679 afs_int32 matchindex,
2680 afs_int32 *nentries,
2681 afs_int32 *alloccnt)
2687 if (*Vldbentry == *VldbentryLast) {
2689 return VL_SIZEEXCEEDED; /* no growing if smallMem defined */
2691 /* Allocate another set of memory; each time allocate twice as
2692 * many blocks as the last time. When we reach VLDBALLOCLIMIT,
2693 * then grow in increments of VLDBALLOCINCR.
2695 allo = (*alloccnt > VLDBALLOCLIMIT) ? VLDBALLOCINCR : *alloccnt;
2697 (nvldbentry *) realloc(*VldbentryFirst,
2698 (*alloccnt + allo) * sizeof(nvldbentry));
2702 *VldbentryFirst = vldbentries->nbulkentries_val = reall;
2703 *Vldbentry = *VldbentryFirst + *alloccnt;
2704 *VldbentryLast = *Vldbentry + allo;
2707 code = vlentry_to_nvldbentry(ctx, entry, *Vldbentry);
2711 (*Vldbentry)->matchindex = (matchtype << 16) + matchindex;
2714 vldbentries->nbulkentries_len++;
2719 /* Common code to actually remove a vldb entry from the database. */
2721 RemoveEntry(struct vl_ctx *ctx, afs_int32 entryptr,
2722 struct nvlentry *tentry)
2726 if ((code = UnthreadVLentry(ctx, entryptr, tentry)))
2728 if ((code = FreeBlock(ctx, entryptr)))
2734 ReleaseEntry(struct nvlentry *tentry, afs_int32 releasetype)
2736 if (releasetype & LOCKREL_TIMESTAMP)
2737 tentry->LockTimestamp = 0;
2738 if (releasetype & LOCKREL_OPCODE)
2739 tentry->flags &= ~VLOP_ALLOPERS;
2740 if (releasetype & LOCKREL_AFSID)
2741 tentry->LockAfsId = 0;
2745 /* Verify that the incoming vldb entry is valid; multi type of error codes
2748 check_vldbentry(struct vldbentry *aentry)
2752 if (InvalidVolname(aentry->name))
2754 if (aentry->nServers <= 0 || aentry->nServers > OMAXNSERVERS)
2755 return VL_BADSERVER;
2756 for (i = 0; i < aentry->nServers; i++) {
2757 /* if (aentry->serverNumber[i] < 0 || aentry->serverNumber[i] > MAXSERVERID)
2758 return VL_BADSERVER; */
2759 if (aentry->serverPartition[i] < 0
2760 || aentry->serverPartition[i] > MAXPARTITIONID)
2761 return VL_BADPARTITION;
2762 if (aentry->serverFlags[i] < 0
2763 || aentry->serverFlags[i] > MAXSERVERFLAG)
2764 return VL_BADSERVERFLAG;
2770 check_nvldbentry(struct nvldbentry *aentry)
2774 if (InvalidVolname(aentry->name))
2776 if (aentry->nServers <= 0 || aentry->nServers > NMAXNSERVERS)
2777 return VL_BADSERVER;
2778 for (i = 0; i < aentry->nServers; i++) {
2779 /* if (aentry->serverNumber[i] < 0 || aentry->serverNumber[i] > MAXSERVERID)
2780 return VL_BADSERVER; */
2781 if (aentry->serverPartition[i] < 0
2782 || aentry->serverPartition[i] > MAXPARTITIONID)
2783 return VL_BADPARTITION;
2784 if (aentry->serverFlags[i] < 0
2785 || aentry->serverFlags[i] > MAXSERVERFLAG)
2786 return VL_BADSERVERFLAG;
2792 /* Convert from the external vldb entry representation to its internal
2793 (more compact) form. This call should not change the hash chains! */
2795 vldbentry_to_vlentry(struct vl_ctx *ctx,
2796 struct vldbentry *VldbEntry,
2797 struct nvlentry *VlEntry)
2801 if (strcmp(VlEntry->name, VldbEntry->name))
2802 strncpy(VlEntry->name, VldbEntry->name, sizeof(VlEntry->name));
2803 for (i = 0; i < VldbEntry->nServers; i++) {
2804 serverindex = IpAddrToRelAddr(ctx, VldbEntry->serverNumber[i], 1);
2805 if (serverindex == -1)
2806 return VL_BADSERVER;
2807 VlEntry->serverNumber[i] = serverindex;
2808 VlEntry->serverPartition[i] = VldbEntry->serverPartition[i];
2809 VlEntry->serverFlags[i] = VldbEntry->serverFlags[i];
2811 for (; i < OMAXNSERVERS; i++)
2812 VlEntry->serverNumber[i] = VlEntry->serverPartition[i] =
2813 VlEntry->serverFlags[i] = BADSERVERID;
2814 for (i = 0; i < MAXTYPES; i++)
2815 VlEntry->volumeId[i] = VldbEntry->volumeId[i];
2816 VlEntry->cloneId = VldbEntry->cloneId;
2817 VlEntry->flags = VldbEntry->flags;
2822 nvldbentry_to_vlentry(struct vl_ctx *ctx,
2823 struct nvldbentry *VldbEntry,
2824 struct nvlentry *VlEntry)
2828 if (strcmp(VlEntry->name, VldbEntry->name))
2829 strncpy(VlEntry->name, VldbEntry->name, sizeof(VlEntry->name));
2830 for (i = 0; i < VldbEntry->nServers; i++) {
2831 serverindex = IpAddrToRelAddr(ctx, VldbEntry->serverNumber[i], 1);
2832 if (serverindex == -1)
2833 return VL_BADSERVER;
2834 VlEntry->serverNumber[i] = serverindex;
2835 VlEntry->serverPartition[i] = VldbEntry->serverPartition[i];
2836 VlEntry->serverFlags[i] = VldbEntry->serverFlags[i];
2838 for (; i < NMAXNSERVERS; i++)
2839 VlEntry->serverNumber[i] = VlEntry->serverPartition[i] =
2840 VlEntry->serverFlags[i] = BADSERVERID;
2841 for (i = 0; i < MAXTYPES; i++)
2842 VlEntry->volumeId[i] = VldbEntry->volumeId[i];
2843 VlEntry->cloneId = VldbEntry->cloneId;
2844 VlEntry->flags = VldbEntry->flags;
2849 /* Update the vldb entry with the new fields as indicated by the value of
2850 * the Mask entry in the updateentry structure. All necessary validation
2851 * checks are performed.
2854 get_vldbupdateentry(struct vl_ctx *ctx,
2855 afs_int32 blockindex,
2856 struct VldbUpdateEntry *updateentry,
2857 struct nvlentry *VlEntry)
2859 int i, j, code, serverindex;
2860 afs_uint32 checkids[MAXTYPES];
2862 /* check if any specified new IDs are already present in the db. Do
2863 * this check before doing anything else, so we don't get a half-
2865 memset(&checkids, 0, sizeof(checkids));
2866 if (updateentry->Mask & VLUPDATE_RWID) {
2867 checkids[RWVOL] = updateentry->spares3; /* rw id */
2869 if (updateentry->Mask & VLUPDATE_READONLYID) {
2870 checkids[ROVOL] = updateentry->ReadOnlyId;
2872 if (updateentry->Mask & VLUPDATE_BACKUPID) {
2873 checkids[BACKVOL] = updateentry->BackupId;
2876 if (EntryIDExists(ctx, checkids, MAXTYPES, &code)) {
2882 if (updateentry->Mask & VLUPDATE_VOLUMENAME) {
2883 struct nvlentry tentry;
2885 if (InvalidVolname(updateentry->name))
2888 if (FindByName(ctx, updateentry->name, &tentry, &code)) {
2889 return VL_NAMEEXIST;
2894 if ((code = UnhashVolname(ctx, blockindex, VlEntry)))
2896 strncpy(VlEntry->name, updateentry->name, sizeof(VlEntry->name));
2897 HashVolname(ctx, blockindex, VlEntry);
2900 if (updateentry->Mask & VLUPDATE_VOLNAMEHASH) {
2901 if ((code = UnhashVolname(ctx, blockindex, VlEntry))) {
2902 if (code != VL_NOENT)
2905 HashVolname(ctx, blockindex, VlEntry);
2908 if (updateentry->Mask & VLUPDATE_FLAGS) {
2909 VlEntry->flags = updateentry->flags;
2911 if (updateentry->Mask & VLUPDATE_CLONEID) {
2912 VlEntry->cloneId = updateentry->cloneId;
2914 if (updateentry->Mask & VLUPDATE_RWID) {
2915 if ((code = UnhashVolid(ctx, RWVOL, blockindex, VlEntry))) {
2916 if (code != VL_NOENT)
2919 VlEntry->volumeId[RWVOL] = updateentry->spares3; /* rw id */
2920 if ((code = HashVolid(ctx, RWVOL, blockindex, VlEntry)))
2923 if (updateentry->Mask & VLUPDATE_READONLYID) {
2924 if ((code = UnhashVolid(ctx, ROVOL, blockindex, VlEntry))) {
2925 if (code != VL_NOENT)
2928 VlEntry->volumeId[ROVOL] = updateentry->ReadOnlyId;
2929 if ((code = HashVolid(ctx, ROVOL, blockindex, VlEntry)))
2932 if (updateentry->Mask & VLUPDATE_BACKUPID) {
2933 if ((code = UnhashVolid(ctx, BACKVOL, blockindex, VlEntry))) {
2934 if (code != VL_NOENT)
2937 VlEntry->volumeId[BACKVOL] = updateentry->BackupId;
2938 if ((code = HashVolid(ctx, BACKVOL, blockindex, VlEntry)))
2941 if (updateentry->Mask & VLUPDATE_REPSITES) {
2942 if (updateentry->nModifiedRepsites <= 0
2943 || updateentry->nModifiedRepsites > OMAXNSERVERS)
2944 return VL_BADSERVER;
2945 for (i = 0; i < updateentry->nModifiedRepsites; i++) {
2946 /* if (updateentry->RepsitesTargetServer[i] < 0 || updateentry->RepsitesTargetServer[i] > MAXSERVERID)
2947 return VL_BADSERVER; */
2948 if (updateentry->RepsitesTargetPart[i] < 0
2949 || updateentry->RepsitesTargetPart[i] > MAXPARTITIONID)
2950 return VL_BADPARTITION;
2951 if (updateentry->RepsitesMask[i] & VLUPDATE_REPS_DELETE) {
2953 repsite_exists(VlEntry,
2954 IpAddrToRelAddr(ctx, updateentry->
2955 RepsitesTargetServer[i],
2957 updateentry->RepsitesTargetPart[i])) !=
2959 repsite_compress(VlEntry, j);
2961 return VL_NOREPSERVER;
2963 if (updateentry->RepsitesMask[i] & VLUPDATE_REPS_ADD) {
2964 /* if (updateentry->RepsitesNewServer[i] < 0 || updateentry->RepsitesNewServer[i] > MAXSERVERID)
2965 return VL_BADSERVER; */
2966 if (updateentry->RepsitesNewPart[i] < 0
2967 || updateentry->RepsitesNewPart[i] > MAXPARTITIONID)
2968 return VL_BADPARTITION;
2971 IpAddrToRelAddr(ctx, updateentry->RepsitesNewServer[i], 1),
2972 updateentry->RepsitesNewPart[i]) != -1)
2973 return VL_DUPREPSERVER;
2975 VlEntry->serverNumber[j] != BADSERVERID
2976 && j < OMAXNSERVERS; j++);
2977 if (j >= OMAXNSERVERS)
2980 IpAddrToRelAddr(ctx, updateentry->RepsitesNewServer[i],
2982 return VL_BADSERVER;
2983 VlEntry->serverNumber[j] = serverindex;
2984 VlEntry->serverPartition[j] = updateentry->RepsitesNewPart[i];
2985 if (updateentry->RepsitesNewFlags[i] < 0
2986 || updateentry->RepsitesNewFlags[i] > MAXSERVERFLAG)
2987 return VL_BADSERVERFLAG;
2988 VlEntry->serverFlags[j] = updateentry->RepsitesNewFlags[i];
2990 if (updateentry->RepsitesMask[i] & VLUPDATE_REPS_MODSERV) {
2991 /*n if (updateentry->RepsitesNewServer[i] < 0 || updateentry->RepsitesNewServer[i] > MAXSERVERID)
2992 return VL_BADSERVER; */
2994 repsite_exists(VlEntry,
2995 IpAddrToRelAddr(ctx, updateentry->
2996 RepsitesTargetServer[i],
2998 updateentry->RepsitesTargetPart[i])) !=
3000 VlEntry->serverNumber[j] =
3001 IpAddrToRelAddr(ctx, updateentry->RepsitesNewServer[i],
3004 return VL_NOREPSERVER;
3006 if (updateentry->RepsitesMask[i] & VLUPDATE_REPS_MODPART) {
3007 if (updateentry->RepsitesNewPart[i] < 0
3008 || updateentry->RepsitesNewPart[i] > MAXPARTITIONID)
3009 return VL_BADPARTITION;
3011 repsite_exists(VlEntry,
3012 IpAddrToRelAddr(ctx, updateentry->
3013 RepsitesTargetServer[i],
3015 updateentry->RepsitesTargetPart[i])) !=
3017 VlEntry->serverPartition[j] =
3018 updateentry->RepsitesNewPart[i];
3020 return VL_NOREPSERVER;
3022 if (updateentry->RepsitesMask[i] & VLUPDATE_REPS_MODFLAG) {
3024 repsite_exists(VlEntry,
3025 IpAddrToRelAddr(ctx, updateentry->
3026 RepsitesTargetServer[i],
3028 updateentry->RepsitesTargetPart[i])) !=
3030 if (updateentry->RepsitesNewFlags[i] < 0
3031 || updateentry->RepsitesNewFlags[i] > MAXSERVERFLAG)
3032 return VL_BADSERVERFLAG;
3033 VlEntry->serverFlags[j] =
3034 updateentry->RepsitesNewFlags[i];
3036 return VL_NOREPSERVER;
3044 /* Check if the specified [server,partition] entry is found in the vldb
3045 * entry's repsite table; it's offset in the table is returned, if it's
3048 repsite_exists(struct nvlentry *VlEntry, int server, int partition)
3052 for (i = 0; VlEntry->serverNumber[i] != BADSERVERID && i < OMAXNSERVERS;
3054 if ((VlEntry->serverNumber[i] == server)
3055 && (VlEntry->serverPartition[i] == partition))
3063 /* Repsite table compression: used when deleting a repsite entry so that
3064 * all active repsite entries are on the top of the table. */
3066 repsite_compress(struct nvlentry *VlEntry, int offset)
3068 int repsite_offset = offset;
3070 VlEntry->serverNumber[repsite_offset] != BADSERVERID
3071 && repsite_offset < OMAXNSERVERS - 1; repsite_offset++) {
3072 VlEntry->serverNumber[repsite_offset] =
3073 VlEntry->serverNumber[repsite_offset + 1];
3074 VlEntry->serverPartition[repsite_offset] =
3075 VlEntry->serverPartition[repsite_offset + 1];
3076 VlEntry->serverFlags[repsite_offset] =
3077 VlEntry->serverFlags[repsite_offset + 1];
3079 VlEntry->serverNumber[repsite_offset] = BADSERVERID;
3083 /* Convert from the internal (compacted) vldb entry to the external
3084 * representation used by the interface. */
3086 vlentry_to_vldbentry(struct vl_ctx *ctx, struct nvlentry *VlEntry,
3087 struct vldbentry *VldbEntry)
3090 struct extentaddr *exp;
3092 memset(VldbEntry, 0, sizeof(struct vldbentry));
3093 strncpy(VldbEntry->name, VlEntry->name, sizeof(VldbEntry->name));
3094 for (i = 0; i < OMAXNSERVERS; i++) {
3095 if (VlEntry->serverNumber[i] == BADSERVERID)
3097 j = VlEntry->serverNumber[i];
3098 code = multiHomedExtent(ctx, VlEntry->serverNumber[i], &exp);
3102 /* For now return the first ip address back */
3103 for (j = 0; j < VL_MAXIPADDRS_PERMH; j++) {
3104 if (exp->ex_addrs[j]) {
3105 VldbEntry->serverNumber[i] = ntohl(exp->ex_addrs[j]);
3110 VldbEntry->serverNumber[i] =
3111 ctx->hostaddress[VlEntry->serverNumber[i]];
3112 VldbEntry->serverPartition[i] = VlEntry->serverPartition[i];
3113 VldbEntry->serverFlags[i] = VlEntry->serverFlags[i];
3115 VldbEntry->nServers = i;
3116 for (i = 0; i < MAXTYPES; i++)
3117 VldbEntry->volumeId[i] = VlEntry->volumeId[i];
3118 VldbEntry->cloneId = VlEntry->cloneId;
3119 VldbEntry->flags = VlEntry->flags;
3125 /* Convert from the internal (compacted) vldb entry to the external
3126 * representation used by the interface. */
3128 vlentry_to_nvldbentry(struct vl_ctx *ctx, struct nvlentry *VlEntry,
3129 struct nvldbentry *VldbEntry)
3132 struct extentaddr *exp;
3134 memset(VldbEntry, 0, sizeof(struct nvldbentry));
3135 strncpy(VldbEntry->name, VlEntry->name, sizeof(VldbEntry->name));
3136 for (i = 0; i < NMAXNSERVERS; i++) {
3137 if (VlEntry->serverNumber[i] == BADSERVERID)
3139 code = multiHomedExtent(ctx, VlEntry->serverNumber[i], &exp);
3144 /* For now return the first ip address back */
3145 for (j = 0; j < VL_MAXIPADDRS_PERMH; j++) {
3146 if (exp->ex_addrs[j]) {
3147 VldbEntry->serverNumber[i] = ntohl(exp->ex_addrs[j]);
3152 VldbEntry->serverNumber[i] =
3153 ctx->hostaddress[VlEntry->serverNumber[i]];
3154 VldbEntry->serverPartition[i] = VlEntry->serverPartition[i];
3155 VldbEntry->serverFlags[i] = VlEntry->serverFlags[i];
3157 VldbEntry->nServers = i;
3158 for (i = 0; i < MAXTYPES; i++)
3159 VldbEntry->volumeId[i] = VlEntry->volumeId[i];
3160 VldbEntry->cloneId = VlEntry->cloneId;
3161 VldbEntry->flags = VlEntry->flags;
3167 vlentry_to_uvldbentry(struct vl_ctx *ctx, struct nvlentry *VlEntry,
3168 struct uvldbentry *VldbEntry)
3171 struct extentaddr *exp;
3173 memset(VldbEntry, 0, sizeof(struct uvldbentry));
3174 strncpy(VldbEntry->name, VlEntry->name, sizeof(VldbEntry->name));
3175 for (i = 0; i < NMAXNSERVERS; i++) {
3176 if (VlEntry->serverNumber[i] == BADSERVERID)
3178 VldbEntry->serverFlags[i] = VlEntry->serverFlags[i];
3179 VldbEntry->serverUnique[i] = 0;
3180 code = multiHomedExtent(ctx, VlEntry->serverNumber[i], &exp);
3187 tuuid = exp->ex_hostuuid;
3188 afs_ntohuuid(&tuuid);
3189 VldbEntry->serverFlags[i] |= VLSERVER_FLAG_UUID;
3190 VldbEntry->serverNumber[i] = tuuid;
3191 VldbEntry->serverUnique[i] = ntohl(exp->ex_uniquifier);
3193 VldbEntry->serverNumber[i].time_low =
3194 ctx->hostaddress[VlEntry->serverNumber[i]];
3196 VldbEntry->serverPartition[i] = VlEntry->serverPartition[i];
3199 VldbEntry->nServers = i;
3200 for (i = 0; i < MAXTYPES; i++)
3201 VldbEntry->volumeId[i] = VlEntry->volumeId[i];
3202 VldbEntry->cloneId = VlEntry->cloneId;
3203 VldbEntry->flags = VlEntry->flags;
3208 #define LEGALCHARS ".ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"
3211 /* Verify that the volname is a valid volume name. */
3213 InvalidVolname(char *volname)
3219 slen = strlen(volname);
3220 if (slen >= VL_MAXNAMELEN)
3222 return (slen != strspn(volname, map));
3226 /* Verify that the given volume type is valid. */
3228 InvalidVoltype(afs_int32 voltype)
3230 if (voltype != RWVOL && voltype != ROVOL && voltype != BACKVOL)
3237 InvalidOperation(afs_int32 voloper)
3239 if (voloper != VLOP_MOVE && voloper != VLOP_RELEASE
3240 && voloper != VLOP_BACKUP && voloper != VLOP_DELETE
3241 && voloper != VLOP_DUMP)
3247 InvalidReleasetype(afs_int32 releasetype)
3249 if ((releasetype & LOCKREL_TIMESTAMP) || (releasetype & LOCKREL_OPCODE)
3250 || (releasetype & LOCKREL_AFSID))
3256 IpAddrToRelAddr(struct vl_ctx *ctx, afs_uint32 ipaddr, int create)
3260 struct extentaddr *exp;
3262 for (i = 0; i <= MAXSERVERID; i++) {
3263 if (ctx->hostaddress[i] == ipaddr)
3265 code = multiHomedExtent(ctx, i, &exp);
3269 for (j = 0; j < VL_MAXIPADDRS_PERMH; j++) {
3270 if (exp->ex_addrs[j] && (ntohl(exp->ex_addrs[j]) == ipaddr)) {
3277 /* allocate the new server a server id pronto */
3279 for (i = 0; i <= MAXSERVERID; i++) {
3280 if (ctx->cheader->IpMappedAddr[i] == 0) {
3281 ctx->cheader->IpMappedAddr[i] = htonl(ipaddr);
3284 DOFFSET(0, ctx->cheader, &ctx->cheader->IpMappedAddr[i]),
3285 (char *)&ctx->cheader->IpMappedAddr[i],
3287 ctx->hostaddress[i] = ipaddr;
3298 ChangeIPAddr(struct vl_ctx *ctx, afs_uint32 ipaddr1, afs_uint32 ipaddr2)
3302 struct extentaddr *exp = NULL;
3306 afs_int32 blockindex, count;
3308 struct nvlentry tentry;
3309 int ipaddr1_id = -1, ipaddr2_id = -1;
3311 /* Don't let addr change to 256.*.*.* : Causes internal error below */
3312 if ((ipaddr2 & 0xff000000) == 0xff000000)
3313 return (VL_BADSERVER);
3315 /* If we are removing an address, ip1 will be -1 and ip2 will be
3316 * the original address. This prevents an older revision vlserver
3317 * from removing the IP address (won't find server 0xfffffff in
3318 * the VLDB). An older revision vlserver does not have the check
3319 * to see if any volumes exist on the server being removed.
3321 if (ipaddr1 == 0xffffffff) {
3326 for (i = 0; i <= MAXSERVERID; i++) {
3327 code = multiHomedExtentBase(ctx, i, &exp, &base);
3332 for (mhidx = 0; mhidx < VL_MAXIPADDRS_PERMH; mhidx++) {
3333 if (!exp->ex_addrs[mhidx])
3335 if (ntohl(exp->ex_addrs[mhidx]) == ipaddr1) {
3338 if (ipaddr2 != 0 && ntohl(exp->ex_addrs[mhidx]) == ipaddr2) {
3343 if (ctx->hostaddress[i] == ipaddr1) {
3347 if (ipaddr2 != 0 && ctx->hostaddress[i] == ipaddr2) {
3352 if (ipaddr1_id >= 0 && (ipaddr2 == 0 || ipaddr2_id >= 0)) {
3353 /* we've either found both IPs already in the VLDB, or we found
3354 * ipaddr1, and we're not going to find ipaddr2 because it's 0 */
3359 if (ipaddr1_id < 0) {
3360 return VL_NOENT; /* not found */
3363 if (ipaddr2_id >= 0 && ipaddr2_id != ipaddr1_id) {
3364 char buf1[16], buf2[16];
3365 VLog(0, ("Cannot change IP address from %s to %s because the latter "
3366 "is in use by server id %d\n",
3367 afs_inet_ntoa_r(htonl(ipaddr1), buf1),
3368 afs_inet_ntoa_r(htonl(ipaddr2), buf2),
3370 return VL_MULTIPADDR;
3373 /* If we are removing a server entry, a volume cannot
3374 * exist on the server. If one does, don't remove the
3375 * server entry: return error "volume entry exists".
3378 for (blockindex = NextEntry(ctx, 0, &tentry, &count); blockindex;
3379 blockindex = NextEntry(ctx, blockindex, &tentry, &count)) {
3380 if (++pollcount > 50) {
3381 #ifndef AFS_PTHREAD_ENV
3386 for (j = 0; j < NMAXNSERVERS; j++) {
3387 if (tentry.serverNumber[j] == BADSERVERID)
3389 if (tentry.serverNumber[j] == ipaddr1_id) {
3396 /* Log a message saying we are changing/removing an IP address */
3398 ("The following IP address is being %s:\n",
3399 (ipaddr2 ? "changed" : "removed")));
3400 VLog(0, (" entry %d: ", i));
3403 for (mhidx = 0; mhidx < VL_MAXIPADDRS_PERMH; mhidx++) {
3404 if (!exp->ex_addrs[mhidx])
3408 PADDR(ntohl(exp->ex_addrs[mhidx]));
3420 /* Change the registered uuuid addresses */
3422 memset(&tuuid, 0, sizeof(afsUUID));
3423 afs_htonuuid(&tuuid);
3424 exp->ex_hostuuid = tuuid;
3427 DOFFSET(ntohl(ctx->ex_addr[0]->ex_contaddrs[base]),
3428 (char *)ctx->ex_addr[base], (char *)exp),
3429 (char *)&tuuid, sizeof(tuuid));
3434 /* Now change the host address entry */
3435 ctx->cheader->IpMappedAddr[ipaddr1_id] = htonl(ipaddr2);
3437 vlwrite(ctx->trans, DOFFSET(0, ctx->cheader, &ctx->cheader->IpMappedAddr[ipaddr1_id]),
3439 &ctx->cheader->IpMappedAddr[ipaddr1_id], sizeof(afs_int32));
3440 ctx->hostaddress[ipaddr1_id] = ipaddr2;
3447 /* see if the vlserver is back yet */
3449 SVL_ProbeServer(struct rx_call *rxcall)