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);
153 #define AFS_RXINFO_LEN 128
155 rxkadInfo(char *str, struct rx_connection *conn, struct in_addr hostAddr)
163 code = rxkad_GetServerInfo(conn, NULL, &exp, tname, tinst, tcell,
166 snprintf(str, AFS_RXINFO_LEN,
167 "%s rxkad:%s%s%s%s%s", inet_ntoa(hostAddr), tname,
168 (tinst[0] == '\0') ? "" : ".",
169 (tinst[0] == '\0') ? "" : tinst,
170 (tcell[0] == '\0') ? "" : "@",
171 (tcell[0] == '\0') ? "" : tcell);
173 snprintf(str, AFS_RXINFO_LEN, "%s noauth", inet_ntoa(hostAddr));
178 rxinfo(char *str, struct rx_call *rxcall)
180 struct rx_connection *conn;
181 struct in_addr hostAddr;
182 rx_securityIndex authClass;
184 conn = rx_ConnectionOf(rxcall);
185 authClass = rx_SecurityClassOf(conn);
186 hostAddr.s_addr = rx_HostOf(rx_PeerOf(conn));
190 return rxkadInfo(str, conn, hostAddr);
195 snprintf(str, AFS_RXINFO_LEN, "%s noauth", inet_ntoa(hostAddr));
200 /* This is called to initialize the database, set the appropriate locks and make sure that the vldb header is valid */
202 Init_VLdbase(struct vl_ctx *ctx,
203 int locktype, /* indicate read or write transaction */
206 int code = 0, pass, wl;
208 for (pass = 1; pass <= 3; pass++) {
209 if (pass == 2) { /* take write lock to rebuild the db */
210 code = ubik_BeginTrans(VL_dbase, UBIK_WRITETRANS, &ctx->trans);
212 } else if (locktype == LOCKREAD) {
214 ubik_BeginTransReadAnyWrite(VL_dbase, UBIK_READTRANS, &ctx->trans);
217 code = ubik_BeginTrans(VL_dbase, UBIK_WRITETRANS, &ctx->trans);
223 code = ubik_SetLock(ctx->trans, 1, 1, locktype);
226 ubik_AbortTrans(ctx->trans);
230 /* check that dbase is initialized and setup cheader */
231 /* 2nd pass we try to rebuild the header */
232 code = CheckInit(ctx->trans, ((pass == 2) ? 1 : 0));
233 if (!code && wl && extent_mod)
234 code = readExtents(ctx->trans); /* Fix the mh extent blocks */
237 ubik_AbortTrans(ctx->trans);
238 /* Only rebuld if the database is empty */
239 /* Exit if can't rebuild */
240 if ((pass == 1) && (code != VL_EMPTY))
244 } else { /* No code */
246 ubik_EndTrans(ctx->trans); /* Rebuilt db. End trans, then retake original lock */
248 break; /* didn't rebuild and successful - exit */
253 code = vlsetcache(ctx, locktype);
259 /* Create a new vldb entry; both new volume id and name must be unique
260 * (non-existant in vldb).
264 SVL_CreateEntry(struct rx_call *rxcall, struct vldbentry *newentry)
266 int this_op = VLCREATEENTRY;
268 afs_int32 code, blockindex;
269 struct nvlentry tentry;
270 char rxstr[AFS_RXINFO_LEN];
272 countRequest(this_op);
273 if (!afsconf_SuperUser(vldb_confdir, rxcall, NULL)) {
278 /* Do some validity tests on new entry */
279 if ((code = check_vldbentry(newentry))
280 || (code = Init_VLdbase(&ctx, LOCKWRITE, this_op)))
284 ("OCreate Volume %d %s\n", newentry->volumeId[RWVOL],
285 rxinfo(rxstr, rxcall)));
286 if (EntryIDExists(&ctx, newentry->volumeId, MAXTYPES, &code)) {
287 /* at least one of the specified IDs already exists; we fail */
294 /* Is this following check (by volume name) necessary?? */
295 /* If entry already exists, we fail */
296 if (FindByName(&ctx, newentry->name, &tentry, &code)) {
303 blockindex = AllocBlock(&ctx, &tentry);
304 if (blockindex == 0) {
305 code = VL_CREATEFAIL;
309 memset(&tentry, 0, sizeof(struct nvlentry));
310 /* Convert to its internal representation; both in host byte order */
311 if ((code = vldbentry_to_vlentry(&ctx, newentry, &tentry))) {
312 FreeBlock(&ctx, blockindex);
316 /* Actually insert the entry in vldb */
317 code = ThreadVLentry(&ctx, blockindex, &tentry);
319 FreeBlock(&ctx, blockindex);
322 code = ubik_EndTrans(ctx.trans);
328 ubik_AbortTrans(ctx.trans);
331 osi_auditU(rxcall, VLCreateEntryEvent, code, AUD_STR,
332 (newentry ? newentry->name : NULL), AUD_END);
338 SVL_CreateEntryN(struct rx_call *rxcall, struct nvldbentry *newentry)
340 int this_op = VLCREATEENTRYN;
342 afs_int32 code, blockindex;
343 struct nvlentry tentry;
344 char rxstr[AFS_RXINFO_LEN];
346 countRequest(this_op);
347 if (!afsconf_SuperUser(vldb_confdir, rxcall, NULL)) {
352 /* Do some validity tests on new entry */
353 if ((code = check_nvldbentry(newentry))
354 || (code = Init_VLdbase(&ctx, LOCKWRITE, this_op)))
358 ("Create Volume %d %s\n", newentry->volumeId[RWVOL],
359 rxinfo(rxstr, rxcall)));
360 if (EntryIDExists(&ctx, newentry->volumeId, MAXTYPES, &code)) {
361 /* at least one of the specified IDs already exists; we fail */
368 /* Is this following check (by volume name) necessary?? */
369 /* If entry already exists, we fail */
370 if (FindByName(&ctx, newentry->name, &tentry, &code)) {
377 blockindex = AllocBlock(&ctx, &tentry);
378 if (blockindex == 0) {
379 code = VL_CREATEFAIL;
383 memset(&tentry, 0, sizeof(struct nvlentry));
384 /* Convert to its internal representation; both in host byte order */
385 if ((code = nvldbentry_to_vlentry(&ctx, newentry, &tentry))) {
386 FreeBlock(&ctx, blockindex);
390 /* Actually insert the entry in vldb */
391 code = ThreadVLentry(&ctx, blockindex, &tentry);
393 FreeBlock(&ctx, blockindex);
396 code = ubik_EndTrans(ctx.trans);
402 ubik_AbortTrans(ctx.trans);
405 osi_auditU(rxcall, VLCreateEntryEvent, code, AUD_STR,
406 (newentry ? newentry->name : NULL), AUD_END);
412 SVL_ChangeAddr(struct rx_call *rxcall, afs_uint32 ip1, afs_uint32 ip2)
414 int this_op = VLCHANGEADDR;
417 char rxstr[AFS_RXINFO_LEN];
419 countRequest(this_op);
420 if (!afsconf_SuperUser(vldb_confdir, rxcall, NULL)) {
425 if ((code = Init_VLdbase(&ctx, LOCKWRITE, this_op)))
428 VLog(1, ("Change Addr %u -> %u %s\n", ip1, ip2, rxinfo(rxstr, rxcall)));
429 if ((code = ChangeIPAddr(&ctx, ip1, ip2)))
432 code = ubik_EndTrans(ctx.trans);
438 ubik_AbortTrans(ctx.trans);
441 osi_auditU(rxcall, VLChangeAddrEvent, code, AUD_LONG, ip1, AUD_LONG,
446 /* Delete a vldb entry given the volume id. */
448 SVL_DeleteEntry(struct rx_call *rxcall, afs_uint32 volid, afs_int32 voltype)
450 int this_op = VLDELETEENTRY;
452 afs_int32 blockindex, code;
453 struct nvlentry tentry;
454 char rxstr[AFS_RXINFO_LEN];
456 countRequest(this_op);
457 if (!afsconf_SuperUser(vldb_confdir, rxcall, NULL))
460 if ((voltype != -1) && (InvalidVoltype(voltype)))
463 if ((code = Init_VLdbase(&ctx, LOCKWRITE, this_op)))
466 VLog(1, ("Delete Volume %u %s\n", volid, rxinfo(rxstr, rxcall)));
467 blockindex = FindByID(&ctx, volid, voltype, &tentry, &code);
468 if (blockindex == 0) { /* volid not found */
474 if (tentry.flags & VLDELETED) { /* Already deleted; return */
475 ABORT(VL_ENTDELETED);
477 if ((code = RemoveEntry(&ctx, blockindex, &tentry))) {
480 code = (ubik_EndTrans(ctx.trans));
485 ubik_AbortTrans(ctx.trans);
488 osi_auditU(rxcall, VLDeleteEntryEvent, code, AUD_LONG, volid,
494 /* Get a vldb entry given its volume id; make sure it's not a deleted entry. */
496 GetEntryByID(struct rx_call *rxcall,
499 char *aentry, /* entry data copied here */
504 afs_int32 blockindex, code;
505 struct nvlentry tentry;
506 char rxstr[AFS_RXINFO_LEN];
508 countRequest(this_op);
510 if ((voltype != -1) && (InvalidVoltype(voltype)))
511 return VL_BADVOLTYPE;
512 if ((code = Init_VLdbase(&ctx, LOCKREAD, this_op)))
515 VLog(5, ("GetVolumeByID %u (%d) %s\n", volid, new,
516 rxinfo(rxstr, rxcall)));
517 blockindex = FindByID(&ctx, volid, voltype, &tentry, &code);
518 if (blockindex == 0) { /* entry not found */
523 if (tentry.flags & VLDELETED) { /* Entry is deleted! */
524 code = VL_ENTDELETED;
527 /* Convert from the internal to external form */
529 code = vlentry_to_nvldbentry(&ctx, &tentry, (struct nvldbentry *)aentry);
531 code = vlentry_to_uvldbentry(&ctx, &tentry, (struct uvldbentry *)aentry);
533 code = vlentry_to_vldbentry(&ctx, &tentry, (struct vldbentry *)aentry);
538 return (ubik_EndTrans(ctx.trans));
542 ubik_AbortTrans(ctx.trans);
547 SVL_GetEntryByID(struct rx_call *rxcall,
550 vldbentry *aentry) /* entry data copied here */
552 return (GetEntryByID(rxcall, volid, voltype, (char *)aentry, 0,
557 SVL_GetEntryByIDN(struct rx_call *rxcall,
560 nvldbentry *aentry) /* entry data copied here */
562 return (GetEntryByID(rxcall, volid, voltype, (char *)aentry, 1,
567 SVL_GetEntryByIDU(struct rx_call *rxcall,
570 uvldbentry *aentry) /* entry data copied here */
572 return (GetEntryByID(rxcall, volid, voltype, (char *)aentry, 2,
576 /* returns true if the id is a decimal integer, in which case we interpret
577 * it as an id. make the cache manager much simpler */
579 NameIsId(char *aname)
582 while ((tc = *aname++)) {
583 if (tc > '9' || tc < '0')
589 /* Get a vldb entry given the volume's name; of course, very similar to
590 * VLGetEntryByID() above. */
592 GetEntryByName(struct rx_call *rxcall,
594 char *aentry, /* entry data copied here */
599 afs_int32 blockindex, code;
600 struct nvlentry tentry;
601 char rxstr[AFS_RXINFO_LEN];
603 if (NameIsId(volname)) {
604 return GetEntryByID(rxcall, strtoul(volname, NULL, 10), -1, aentry, new, this_op);
606 if (InvalidVolname(volname))
608 if ((code = Init_VLdbase(&ctx, LOCKREAD, this_op)))
610 VLog(5, ("GetVolumeByName %s (%d) %s\n", volname, new, rxinfo(rxstr, rxcall)));
611 blockindex = FindByName(&ctx, volname, &tentry, &code);
612 if (blockindex == 0) { /* entry not found */
617 if (tentry.flags & VLDELETED) { /* Entry is deleted */
618 code = VL_ENTDELETED;
621 /* Convert to external entry representation */
623 code = vlentry_to_nvldbentry(&ctx, &tentry, (struct nvldbentry *)aentry);
625 code = vlentry_to_uvldbentry(&ctx, &tentry, (struct uvldbentry *)aentry);
627 code = vlentry_to_vldbentry(&ctx, &tentry, (struct vldbentry *)aentry);
632 return (ubik_EndTrans(ctx.trans));
636 ubik_AbortTrans(ctx.trans);
642 SVL_GetEntryByNameO(struct rx_call *rxcall,
644 struct vldbentry *aentry) /* entry data copied here */
646 return (GetEntryByName(rxcall, volname, (char *)aentry, 0,
652 SVL_GetEntryByNameN(struct rx_call *rxcall,
654 struct nvldbentry *aentry) /* entry data copied here */
656 return (GetEntryByName(rxcall, volname, (char *)aentry, 1,
661 SVL_GetEntryByNameU(struct rx_call *rxcall,
663 struct uvldbentry *aentry) /* entry data copied here */
665 return (GetEntryByName(rxcall, volname, (char *)aentry, 2,
671 /* Get the current value of the maximum volume id and bump the volume id counter by Maxvolidbump. */
673 SVL_GetNewVolumeId(struct rx_call *rxcall, afs_uint32 Maxvolidbump,
674 afs_uint32 *newvolumeid)
676 int this_op = VLGETNEWVOLUMEID;
678 afs_uint32 maxvolumeid;
680 char rxstr[AFS_RXINFO_LEN];
682 countRequest(this_op);
683 if (!afsconf_SuperUser(vldb_confdir, rxcall, NULL))
686 if (Maxvolidbump > MAXBUMPCOUNT)
687 END(VL_BADVOLIDBUMP);
689 if ((code = Init_VLdbase(&ctx, LOCKWRITE, this_op)))
692 *newvolumeid = maxvolumeid = NextUnusedID(&ctx,
693 ntohl(ctx.cheader->vital_header.MaxVolumeId), Maxvolidbump, &code);
698 maxvolumeid += Maxvolidbump;
699 VLog(1, ("GetNewVolid newmax=%u %s\n", maxvolumeid, rxinfo(rxstr, rxcall)));
700 ctx.cheader->vital_header.MaxVolumeId = htonl(maxvolumeid);
701 if (write_vital_vlheader(&ctx)) {
704 code = (ubik_EndTrans(ctx.trans));
709 ubik_AbortTrans(ctx.trans);
712 osi_auditU(rxcall, VLGetNewVolumeIdEvent, code, AUD_END);
717 /* Simple replace the contents of the vldb entry, volid, with
718 * newentry. No individual checking/updating per field (alike
719 * VLUpdateEntry) is done. */
722 SVL_ReplaceEntry(struct rx_call *rxcall, afs_uint32 volid, afs_int32 voltype,
723 struct vldbentry *newentry, afs_int32 releasetype)
725 int this_op = VLREPLACEENTRY;
727 afs_int32 blockindex, code, typeindex;
729 int hashVol[MAXTYPES];
730 struct nvlentry tentry;
731 afs_uint32 checkids[MAXTYPES];
732 char rxstr[AFS_RXINFO_LEN];
734 countRequest(this_op);
735 for (typeindex = 0; typeindex < MAXTYPES; typeindex++)
736 hashVol[typeindex] = 0;
738 if (!afsconf_SuperUser(vldb_confdir, rxcall, NULL))
741 if ((code = check_vldbentry(newentry)))
744 if (voltype != -1 && InvalidVoltype(voltype))
747 if (releasetype && InvalidReleasetype(releasetype))
748 END(VL_BADRELLOCKTYPE);
749 if ((code = Init_VLdbase(&ctx, LOCKWRITE, this_op)))
752 VLog(1, ("OReplace Volume %u %s\n", volid, rxinfo(rxstr, rxcall)));
753 /* find vlentry we're changing */
754 blockindex = FindByID(&ctx, volid, voltype, &tentry, &code);
755 if (blockindex == 0) { /* entry not found */
761 /* check that we're not trying to change the RW vol ID */
762 if (newentry->volumeId[RWVOL] != tentry.volumeId[RWVOL]) {
766 /* make sure none of the IDs we are changing to are already in use */
767 memset(&checkids, 0, sizeof(checkids));
768 for (typeindex = ROVOL; typeindex < MAXTYPES; typeindex++) {
769 if (tentry.volumeId[typeindex] != newentry->volumeId[typeindex]) {
770 checkids[typeindex] = newentry->volumeId[typeindex];
773 if (EntryIDExists(&ctx, checkids, MAXTYPES, &code)) {
779 /* make sure the name we're changing to doesn't already exist */
780 if (strcmp(newentry->name, tentry.name)) {
781 struct nvlentry tmp_entry;
782 if (FindByName(&ctx, newentry->name, &tmp_entry, &code)) {
789 /* unhash volid entries if they're disappearing or changing.
790 * Remember if we need to hash in the new value (we don't have to
791 * rehash if volid stays same */
792 for (typeindex = ROVOL; typeindex <= BACKVOL; typeindex++) {
793 if (tentry.volumeId[typeindex] != newentry->volumeId[typeindex]) {
794 if (tentry.volumeId[typeindex])
796 UnhashVolid(&ctx, typeindex, blockindex, &tentry))) {
799 /* we must rehash new id if the id is different and the ID is nonzero */
800 hashVol[typeindex] = 1; /* must rehash this guy if he exists */
804 /* Rehash volname if it changes */
805 if (strcmp(newentry->name, tentry.name)) { /* Name changes; redo hashing */
806 if ((code = UnhashVolname(&ctx, blockindex, &tentry))) {
812 /* after this, tentry is new entry, not old one. vldbentry_to_vlentry
813 * doesn't touch hash chains */
814 if ((code = vldbentry_to_vlentry(&ctx, newentry, &tentry))) {
818 for (typeindex = ROVOL; typeindex <= BACKVOL; typeindex++) {
819 if (hashVol[typeindex] && tentry.volumeId[typeindex]) {
820 if ((code = HashVolid(&ctx, typeindex, blockindex, &tentry))) {
827 HashVolname(&ctx, blockindex, &tentry);
830 ReleaseEntry(&tentry, releasetype); /* Unlock entry if necessary */
831 if (vlentrywrite(ctx.trans, blockindex, &tentry, sizeof(tentry))) {
835 END(ubik_EndTrans(ctx.trans));
839 ubik_AbortTrans(ctx.trans);
842 osi_auditU(rxcall, VLReplaceVLEntryEvent, code, AUD_LONG, volid,
848 SVL_ReplaceEntryN(struct rx_call *rxcall, afs_uint32 volid, afs_int32 voltype,
849 struct nvldbentry *newentry, afs_int32 releasetype)
851 int this_op = VLREPLACEENTRYN;
853 afs_int32 blockindex, code, typeindex;
855 int hashVol[MAXTYPES];
856 struct nvlentry tentry;
857 char rxstr[AFS_RXINFO_LEN];
859 countRequest(this_op);
860 for (typeindex = 0; typeindex < MAXTYPES; typeindex++)
861 hashVol[typeindex] = 0;
863 if (!afsconf_SuperUser(vldb_confdir, rxcall, NULL))
866 if ((code = check_nvldbentry(newentry)))
869 if (voltype != -1 && InvalidVoltype(voltype))
872 if (releasetype && InvalidReleasetype(releasetype))
873 END(VL_BADRELLOCKTYPE);
874 if ((code = Init_VLdbase(&ctx, LOCKWRITE, this_op)))
877 VLog(1, ("Replace Volume %u %s\n", volid, rxinfo(rxstr, rxcall)));
878 /* find vlentry we're changing */
879 blockindex = FindByID(&ctx, volid, voltype, &tentry, &code);
880 if (blockindex == 0) { /* entry not found */
886 /* check that we're not trying to change the RW vol ID */
887 if (newentry->volumeId[RWVOL] != tentry.volumeId[RWVOL]) {
891 /* unhash volid entries if they're disappearing or changing.
892 * Remember if we need to hash in the new value (we don't have to
893 * rehash if volid stays same */
894 for (typeindex = ROVOL; typeindex <= BACKVOL; typeindex++) {
895 if (tentry.volumeId[typeindex] != newentry->volumeId[typeindex]) {
896 if (tentry.volumeId[typeindex])
898 UnhashVolid(&ctx, typeindex, blockindex, &tentry))) {
901 /* we must rehash new id if the id is different and the ID is nonzero */
902 hashVol[typeindex] = 1; /* must rehash this guy if he exists */
906 /* Rehash volname if it changes */
907 if (strcmp(newentry->name, tentry.name)) { /* Name changes; redo hashing */
908 if ((code = UnhashVolname(&ctx, blockindex, &tentry))) {
914 /* after this, tentry is new entry, not old one. vldbentry_to_vlentry
915 * doesn't touch hash chains */
916 if ((code = nvldbentry_to_vlentry(&ctx, newentry, &tentry))) {
920 for (typeindex = ROVOL; typeindex <= BACKVOL; typeindex++) {
921 if (hashVol[typeindex] && tentry.volumeId[typeindex]) {
922 if ((code = HashVolid(&ctx, typeindex, blockindex, &tentry))) {
929 HashVolname(&ctx, blockindex, &tentry);
932 ReleaseEntry(&tentry, releasetype); /* Unlock entry if necessary */
933 if (vlentrywrite(ctx.trans, blockindex, &tentry, sizeof(tentry))) {
937 END(ubik_EndTrans(ctx.trans));
941 ubik_AbortTrans(ctx.trans);
944 osi_auditU(rxcall, VLReplaceVLEntryEvent, code, AUD_LONG, volid,
950 /* Update a vldb entry (accessed thru its volume id). Almost all of the
951 * entry's fields can be modified in a single call by setting the
952 * appropriate bits in the Mask field in VldbUpdateentry. */
953 /* this routine may never have been tested; use replace entry instead
954 * unless you're brave */
956 SVL_UpdateEntry(struct rx_call *rxcall,
959 struct VldbUpdateEntry *updateentry, /* Update entry copied here */
960 afs_int32 releasetype)
962 int this_op = VLUPDATEENTRY;
964 afs_int32 blockindex, code;
965 struct nvlentry tentry;
966 char rxstr[AFS_RXINFO_LEN];
968 countRequest(this_op);
969 if (!afsconf_SuperUser(vldb_confdir, rxcall, NULL))
971 if ((voltype != -1) && (InvalidVoltype(voltype)))
973 if (releasetype && InvalidReleasetype(releasetype))
974 END(VL_BADRELLOCKTYPE);
975 if ((code = Init_VLdbase(&ctx, LOCKWRITE, this_op)))
978 VLog(1, ("Update Volume %u %s\n", volid, rxinfo(rxstr, rxcall)));
979 blockindex = FindByID(&ctx, volid, voltype, &tentry, &code);
980 if (blockindex == 0) { /* entry not found */
986 /* Do the actual updating of the entry, tentry. */
988 get_vldbupdateentry(&ctx, blockindex, updateentry, &tentry))) {
992 ReleaseEntry(&tentry, releasetype); /* Unlock entry if necessary */
993 if (vlentrywrite(ctx.trans, blockindex, &tentry, sizeof(tentry))) {
996 END(ubik_EndTrans(ctx.trans));
1000 ubik_AbortTrans(ctx.trans);
1003 osi_auditU(rxcall, VLUpdateEntryEvent, code, AUD_LONG, volid,
1010 SVL_UpdateEntryByName(struct rx_call *rxcall,
1012 struct VldbUpdateEntry *updateentry, /* Update entry copied here */
1013 afs_int32 releasetype)
1015 int this_op = VLUPDATEENTRYBYNAME;
1017 afs_int32 blockindex, code;
1018 struct nvlentry tentry;
1020 countRequest(this_op);
1021 if (!afsconf_SuperUser(vldb_confdir, rxcall, NULL))
1023 if (releasetype && InvalidReleasetype(releasetype))
1024 END(VL_BADRELLOCKTYPE);
1025 if ((code = Init_VLdbase(&ctx, LOCKWRITE, this_op)))
1028 blockindex = FindByName(&ctx, volname, &tentry, &code);
1029 if (blockindex == 0) { /* entry not found */
1035 /* Do the actual updating of the entry, tentry. */
1037 get_vldbupdateentry(&ctx, blockindex, updateentry, &tentry))) {
1041 ReleaseEntry(&tentry, releasetype); /* Unlock entry if necessary */
1042 if (vlentrywrite(ctx.trans, blockindex, &tentry, sizeof(tentry))) {
1045 END(ubik_EndTrans(ctx.trans));
1048 countAbort(this_op);
1049 ubik_AbortTrans(ctx.trans);
1052 osi_auditU(rxcall, VLUpdateEntryEvent, code, AUD_LONG, -1, AUD_END);
1057 /* Set a lock to the vldb entry for volid (of type voltype if not -1). */
1059 SVL_SetLock(struct rx_call *rxcall, afs_uint32 volid, afs_int32 voltype,
1062 int this_op = VLSETLOCK;
1063 afs_int32 timestamp, blockindex, code;
1065 struct nvlentry tentry;
1066 char rxstr[AFS_RXINFO_LEN];
1068 countRequest(this_op);
1069 if (!afsconf_SuperUser(vldb_confdir, rxcall, NULL))
1071 if ((voltype != -1) && (InvalidVoltype(voltype)))
1073 if (InvalidOperation(voloper))
1075 if ((code = Init_VLdbase(&ctx, LOCKWRITE, this_op)))
1078 VLog(1, ("SetLock Volume %u %s\n", volid, rxinfo(rxstr, rxcall)));
1079 blockindex = FindByID(&ctx, volid, voltype, &tentry, &code);
1080 if (blockindex == NULLO) {
1085 if (tentry.flags & VLDELETED) {
1086 ABORT(VL_ENTDELETED);
1088 timestamp = FT_ApproxTime();
1090 /* Check if entry is already locked; note that we unlock any entry
1091 * locked more than MAXLOCKTIME seconds */
1092 if ((tentry.LockTimestamp)
1093 && ((timestamp - tentry.LockTimestamp) < MAXLOCKTIME)) {
1094 ABORT(VL_ENTRYLOCKED);
1097 /* Consider it an unlocked entry: set current timestamp, caller
1098 * and active vol operation */
1099 tentry.LockTimestamp = timestamp;
1100 tentry.LockAfsId = 0; /* Not implemented yet */
1101 if (tentry.flags & VLOP_RELEASE) {
1102 ABORT(VL_RERELEASE);
1104 tentry.flags &= ~VLOP_ALLOPERS; /* Clear any possible older operation bit */
1105 tentry.flags |= voloper;
1107 if (vlentrywrite(ctx.trans, blockindex, &tentry, sizeof(tentry))) {
1110 END(ubik_EndTrans(ctx.trans));
1113 countAbort(this_op);
1114 ubik_AbortTrans(ctx.trans);
1117 osi_auditU(rxcall, VLSetLockEvent, code, AUD_LONG, volid, AUD_END);
1122 /* Release an already locked vldb entry. Releasetype determines what
1123 * fields (afsid and/or volume operation) will be cleared along with
1124 * the lock time stamp. */
1127 SVL_ReleaseLock(struct rx_call *rxcall, afs_uint32 volid, afs_int32 voltype,
1128 afs_int32 releasetype)
1130 int this_op = VLRELEASELOCK;
1131 afs_int32 blockindex, code;
1133 struct nvlentry tentry;
1134 char rxstr[AFS_RXINFO_LEN];
1136 countRequest(this_op);
1137 if (!afsconf_SuperUser(vldb_confdir, rxcall, NULL))
1139 if ((voltype != -1) && (InvalidVoltype(voltype)))
1141 if (releasetype && InvalidReleasetype(releasetype))
1142 END(VL_BADRELLOCKTYPE);
1143 if ((code = Init_VLdbase(&ctx, LOCKWRITE, this_op)))
1146 VLog(1, ("ReleaseLock Volume %u %s\n", volid, rxinfo(rxstr, rxcall)));
1147 blockindex = FindByID(&ctx, volid, voltype, &tentry, &code);
1148 if (blockindex == NULLO) {
1153 if (tentry.flags & VLDELETED) {
1154 ABORT(VL_ENTDELETED);
1157 ReleaseEntry(&tentry, releasetype); /* Unlock the appropriate fields */
1158 if (vlentrywrite(ctx.trans, blockindex, &tentry, sizeof(tentry))) {
1161 END(ubik_EndTrans(ctx.trans));
1164 countAbort(this_op);
1165 ubik_AbortTrans(ctx.trans);
1168 osi_auditU(rxcall, VLReleaseLockEvent, code, AUD_LONG, volid,
1174 /* ListEntry returns a single vldb entry, aentry, with offset previous_index;
1175 * the remaining parameters (i.e. next_index) are used so that sequential
1176 * calls to this routine will get the next (all) vldb entries.
1179 SVL_ListEntry(struct rx_call *rxcall, afs_int32 previous_index,
1180 afs_int32 *count, afs_int32 *next_index,
1181 struct vldbentry *aentry)
1183 int this_op = VLLISTENTRY;
1186 struct nvlentry tentry;
1187 char rxstr[AFS_RXINFO_LEN];
1189 countRequest(this_op);
1190 if ((code = Init_VLdbase(&ctx, LOCKREAD, this_op)))
1192 VLog(25, ("OListEntry index=%d %s\n", previous_index,
1193 rxinfo(rxstr, rxcall)));
1194 *next_index = NextEntry(&ctx, previous_index, &tentry, count);
1196 code = vlentry_to_vldbentry(&ctx, &tentry, aentry);
1198 countAbort(this_op);
1199 ubik_AbortTrans(ctx.trans);
1203 return (ubik_EndTrans(ctx.trans));
1206 /* ListEntry returns a single vldb entry, aentry, with offset previous_index;
1207 * the remaining parameters (i.e. next_index) are used so that sequential
1208 * calls to this routine will get the next (all) vldb entries.
1211 SVL_ListEntryN(struct rx_call *rxcall, afs_int32 previous_index,
1212 afs_int32 *count, afs_int32 *next_index,
1213 struct nvldbentry *aentry)
1215 int this_op = VLLISTENTRYN;
1218 struct nvlentry tentry;
1219 char rxstr[AFS_RXINFO_LEN];
1221 countRequest(this_op);
1222 if ((code = Init_VLdbase(&ctx, LOCKREAD, this_op)))
1224 VLog(25, ("ListEntry index=%d %s\n", previous_index, rxinfo(rxstr, rxcall)));
1225 *next_index = NextEntry(&ctx, previous_index, &tentry, count);
1227 code = vlentry_to_nvldbentry(&ctx, &tentry, aentry);
1229 countAbort(this_op);
1230 ubik_AbortTrans(ctx.trans);
1235 return (ubik_EndTrans(ctx.trans));
1239 /* Retrieves in vldbentries all vldb entries that match the specified
1240 * attributes (by server number, partition, volume type, and flag); if volume
1241 * id is specified then the associated list for that entry is returned.
1242 * CAUTION: This could be a very expensive call since in most cases
1243 * sequential search of all vldb entries is performed.
1246 SVL_ListAttributes(struct rx_call *rxcall,
1247 struct VldbListByAttributes *attributes,
1248 afs_int32 *nentries,
1249 bulkentries *vldbentries)
1251 int this_op = VLLISTATTRIBUTES;
1252 int code, allocCount = 0;
1254 struct nvlentry tentry;
1255 struct vldbentry *Vldbentry = 0, *VldbentryFirst = 0, *VldbentryLast = 0;
1257 char rxstr[AFS_RXINFO_LEN];
1259 countRequest(this_op);
1260 vldbentries->bulkentries_val = 0;
1261 vldbentries->bulkentries_len = *nentries = 0;
1262 if ((code = Init_VLdbase(&ctx, LOCKREAD, this_op)))
1264 allocCount = VLDBALLOCCOUNT;
1265 Vldbentry = VldbentryFirst = vldbentries->bulkentries_val =
1266 (vldbentry *) malloc(allocCount * sizeof(vldbentry));
1267 if (Vldbentry == NULL) {
1271 VldbentryLast = VldbentryFirst + allocCount;
1272 /* Handle the attribute by volume id totally separate of the rest
1273 * (thus additional Mask values are ignored if VLLIST_VOLUMEID is set!) */
1274 if (attributes->Mask & VLLIST_VOLUMEID) {
1275 afs_int32 blockindex;
1278 FindByID(&ctx, attributes->volumeid, -1, &tentry, &code);
1279 if (blockindex == 0) {
1285 code = put_attributeentry(&ctx, &Vldbentry, &VldbentryFirst,
1286 &VldbentryLast, vldbentries, &tentry,
1287 nentries, &allocCount);
1291 afs_int32 nextblockindex = 0, count = 0, k = 0, match = 0;
1292 while ((nextblockindex =
1293 NextEntry(&ctx, nextblockindex, &tentry, &count))) {
1294 if (++pollcount > 50) {
1295 #ifndef AFS_PTHREAD_ENV
1301 if (attributes->Mask & VLLIST_SERVER) {
1304 IpAddrToRelAddr(&ctx, attributes->server, 0)) == -1)
1306 for (k = 0; k < OMAXNSERVERS; k++) {
1307 if (tentry.serverNumber[k] == BADSERVERID)
1309 if (tentry.serverNumber[k] == serverindex) {
1317 if (attributes->Mask & VLLIST_PARTITION) {
1319 if (tentry.serverPartition[k] != attributes->partition)
1322 for (k = 0; k < OMAXNSERVERS; k++) {
1323 if (tentry.serverNumber[k] == BADSERVERID)
1325 if (tentry.serverPartition[k] ==
1326 attributes->partition) {
1336 if (attributes->Mask & VLLIST_FLAG) {
1337 if (!(tentry.flags & attributes->flag))
1340 code = put_attributeentry(&ctx, &Vldbentry, &VldbentryFirst,
1341 &VldbentryLast, vldbentries, &tentry,
1342 nentries, &allocCount);
1347 if (vldbentries->bulkentries_len
1348 && (allocCount > vldbentries->bulkentries_len)) {
1350 vldbentries->bulkentries_val =
1351 (vldbentry *) realloc(vldbentries->bulkentries_val,
1352 vldbentries->bulkentries_len *
1354 if (vldbentries->bulkentries_val == NULL) {
1360 ("ListAttrs nentries=%d %s\n", vldbentries->bulkentries_len,
1361 rxinfo(rxstr, rxcall)));
1362 return (ubik_EndTrans(ctx.trans));
1365 if (vldbentries->bulkentries_val)
1366 free(vldbentries->bulkentries_val);
1367 vldbentries->bulkentries_val = 0;
1368 vldbentries->bulkentries_len = 0;
1370 countAbort(this_op);
1371 ubik_AbortTrans(ctx.trans);
1377 SVL_ListAttributesN(struct rx_call *rxcall,
1378 struct VldbListByAttributes *attributes,
1379 afs_int32 *nentries,
1380 nbulkentries *vldbentries)
1382 int this_op = VLLISTATTRIBUTESN;
1383 int code, allocCount = 0;
1385 struct nvlentry tentry;
1386 struct nvldbentry *Vldbentry = 0, *VldbentryFirst = 0, *VldbentryLast = 0;
1388 char rxstr[AFS_RXINFO_LEN];
1390 countRequest(this_op);
1391 vldbentries->nbulkentries_val = 0;
1392 vldbentries->nbulkentries_len = *nentries = 0;
1393 if ((code = Init_VLdbase(&ctx, LOCKREAD, this_op)))
1395 allocCount = VLDBALLOCCOUNT;
1396 Vldbentry = VldbentryFirst = vldbentries->nbulkentries_val =
1397 (nvldbentry *) malloc(allocCount * sizeof(nvldbentry));
1398 if (Vldbentry == NULL) {
1402 VldbentryLast = VldbentryFirst + allocCount;
1403 /* Handle the attribute by volume id totally separate of the rest
1404 * (thus additional Mask values are ignored if VLLIST_VOLUMEID is set!) */
1405 if (attributes->Mask & VLLIST_VOLUMEID) {
1406 afs_int32 blockindex;
1409 FindByID(&ctx, attributes->volumeid, -1, &tentry, &code);
1410 if (blockindex == 0) {
1416 code = put_nattributeentry(&ctx, &Vldbentry, &VldbentryFirst,
1417 &VldbentryLast, vldbentries, &tentry,
1418 0, 0, nentries, &allocCount);
1422 afs_int32 nextblockindex = 0, count = 0, k = 0, match = 0;
1423 while ((nextblockindex =
1424 NextEntry(&ctx, nextblockindex, &tentry, &count))) {
1425 if (++pollcount > 50) {
1426 #ifndef AFS_PTHREAD_ENV
1433 if (attributes->Mask & VLLIST_SERVER) {
1436 IpAddrToRelAddr(&ctx, attributes->server, 0)) == -1)
1438 for (k = 0; k < NMAXNSERVERS; k++) {
1439 if (tentry.serverNumber[k] == BADSERVERID)
1441 if (tentry.serverNumber[k] == serverindex) {
1449 if (attributes->Mask & VLLIST_PARTITION) {
1451 if (tentry.serverPartition[k] != attributes->partition)
1454 for (k = 0; k < NMAXNSERVERS; k++) {
1455 if (tentry.serverNumber[k] == BADSERVERID)
1457 if (tentry.serverPartition[k] ==
1458 attributes->partition) {
1468 if (attributes->Mask & VLLIST_FLAG) {
1469 if (!(tentry.flags & attributes->flag))
1472 code = put_nattributeentry(&ctx, &Vldbentry, &VldbentryFirst,
1473 &VldbentryLast, vldbentries,
1474 &tentry, 0, 0, nentries, &allocCount);
1479 if (vldbentries->nbulkentries_len
1480 && (allocCount > vldbentries->nbulkentries_len)) {
1482 vldbentries->nbulkentries_val =
1483 (nvldbentry *) realloc(vldbentries->nbulkentries_val,
1484 vldbentries->nbulkentries_len *
1485 sizeof(nvldbentry));
1486 if (vldbentries->nbulkentries_val == NULL) {
1492 ("NListAttrs nentries=%d %s\n", vldbentries->nbulkentries_len,
1493 rxinfo(rxstr, rxcall)));
1494 return (ubik_EndTrans(ctx.trans));
1497 countAbort(this_op);
1498 ubik_AbortTrans(ctx.trans);
1499 if (vldbentries->nbulkentries_val)
1500 free(vldbentries->nbulkentries_val);
1501 vldbentries->nbulkentries_val = 0;
1502 vldbentries->nbulkentries_len = 0;
1508 SVL_ListAttributesN2(struct rx_call *rxcall,
1509 struct VldbListByAttributes *attributes,
1510 char *name, /* Wildcarded volume name */
1511 afs_int32 startindex,
1512 afs_int32 *nentries,
1513 nbulkentries *vldbentries,
1514 afs_int32 *nextstartindex)
1516 int this_op = VLLISTATTRIBUTESN2;
1517 int code = 0, maxCount = VLDBALLOCCOUNT;
1519 struct nvlentry tentry;
1520 struct nvldbentry *Vldbentry = 0, *VldbentryFirst = 0, *VldbentryLast = 0;
1521 afs_int32 blockindex = 0, count = 0, k, match;
1522 afs_int32 matchindex = 0;
1523 int serverindex = -1; /* no server found */
1524 int findserver = 0, findpartition = 0, findflag = 0, findname = 0;
1526 int namematchRWBK, namematchRO, thismatch;
1528 char volumename[VL_MAXNAMELEN+2]; /* regex anchors */
1529 char rxstr[AFS_RXINFO_LEN];
1530 #ifdef HAVE_POSIX_REGEX
1532 int need_regfree = 0;
1537 countRequest(this_op);
1538 vldbentries->nbulkentries_val = 0;
1539 vldbentries->nbulkentries_len = 0;
1541 *nextstartindex = -1;
1543 code = Init_VLdbase(&ctx, LOCKREAD, this_op);
1547 Vldbentry = VldbentryFirst = vldbentries->nbulkentries_val =
1548 (nvldbentry *) malloc(maxCount * sizeof(nvldbentry));
1549 if (Vldbentry == NULL) {
1550 countAbort(this_op);
1551 ubik_AbortTrans(ctx.trans);
1555 VldbentryLast = VldbentryFirst + maxCount;
1557 /* Handle the attribute by volume id totally separate of the rest
1558 * (thus additional Mask values are ignored if VLLIST_VOLUMEID is set!)
1560 if (attributes->Mask & VLLIST_VOLUMEID) {
1562 FindByID(&ctx, attributes->volumeid, -1, &tentry, &code);
1563 if (blockindex == 0) {
1568 put_nattributeentry(&ctx, &Vldbentry, &VldbentryFirst,
1569 &VldbentryLast, vldbentries, &tentry, 0,
1570 0, nentries, &maxCount);
1576 /* Search each entry in the database and return all entries
1577 * that match the request. It checks volumename (with
1578 * wildcarding), entry flags, server, and partition.
1581 /* Get the server index for matching server address */
1582 if (attributes->Mask & VLLIST_SERVER) {
1584 IpAddrToRelAddr(&ctx, attributes->server, 0);
1585 if (serverindex == -1)
1589 findpartition = ((attributes->Mask & VLLIST_PARTITION) ? 1 : 0);
1590 findflag = ((attributes->Mask & VLLIST_FLAG) ? 1 : 0);
1591 if (name && (strcmp(name, ".*") != 0) && (strcmp(name, "") != 0)) {
1592 sprintf(volumename, "^%s$", name);
1593 #ifdef HAVE_POSIX_REGEX
1594 if (regcomp(&re, volumename, REG_NOSUB) != 0) {
1600 t = (char *)re_comp(volumename);
1609 /* Read each entry and see if it is the one we want */
1610 blockindex = startindex;
1611 while ((blockindex = NextEntry(&ctx, blockindex, &tentry, &count))) {
1612 if (++pollcount > 50) {
1613 #ifndef AFS_PTHREAD_ENV
1619 /* Step through each server index searching for a match.
1620 * Match to an existing RW, BK, or RO volume name (preference
1621 * is in this order). Remember which index we matched against.
1623 namematchRWBK = namematchRO = 0; /* 0->notTried; 1->match; 2->noMatch */
1627 && (tentry.serverNumber[k] != BADSERVERID)); k++) {
1628 thismatch = 0; /* does this index match */
1630 /* Match against the RW or BK volume name. Remember
1631 * results in namematchRWBK. Prefer RW over BK.
1633 if (tentry.serverFlags[k] & VLSF_RWVOL) {
1634 /* Does the name match the RW name */
1635 if (tentry.flags & VLF_RWEXISTS) {
1637 sprintf(volumename, "%s", tentry.name);
1638 #ifdef HAVE_POSIX_REGEX
1639 if (regexec(&re, volumename, 0, NULL, 0) == 0) {
1640 thismatch = VLSF_RWVOL;
1643 if (re_exec(volumename)) {
1644 thismatch = VLSF_RWVOL;
1648 thismatch = VLSF_RWVOL;
1652 /* Does the name match the BK name */
1653 if (!thismatch && (tentry.flags & VLF_BACKEXISTS)) {
1655 sprintf(volumename, "%s.backup", tentry.name);
1656 #ifdef HAVE_POSIX_REGEX
1657 if (regexec(&re, volumename, 0, NULL, 0) == 0) {
1658 thismatch = VLSF_BACKVOL;
1661 if (re_exec(volumename)) {
1662 thismatch = VLSF_BACKVOL;
1666 thismatch = VLSF_BACKVOL;
1670 namematchRWBK = (thismatch ? 1 : 2);
1673 /* Match with the RO volume name. Compare once and
1674 * remember results in namematchRO. Note that this will
1675 * pick up entries marked NEWREPSITEs and DONTUSE.
1678 if (tentry.flags & VLF_ROEXISTS) {
1682 ((namematchRO == 1) ? VLSF_ROVOL : 0);
1684 sprintf(volumename, "%s.readonly",
1686 #ifdef HAVE_POSIX_REGEX
1687 if (regexec(&re, volumename, 0, NULL, 0) == 0) {
1688 thismatch = VLSF_ROVOL;
1691 if (re_exec(volumename))
1692 thismatch = VLSF_ROVOL;
1696 thismatch = VLSF_ROVOL;
1699 namematchRO = (thismatch ? 1 : 2);
1702 /* Is there a server match */
1703 if (thismatch && findserver
1704 && (tentry.serverNumber[k] != serverindex))
1707 /* Is there a partition match */
1708 if (thismatch && findpartition
1709 && (tentry.serverPartition[k] != attributes->partition))
1712 /* Is there a flag match */
1713 if (thismatch && findflag
1714 && !(tentry.flags & attributes->flag))
1717 /* We found a match. Remember the index, and type */
1721 matchtype = thismatch;
1724 /* Since we prefer RW and BK volume matches over RO matches,
1725 * if we have already checked the RWBK name, then we already
1726 * found the best match and so end the search.
1728 * If we tried matching against the RW, BK, and RO volume names
1729 * and both failed, then we end the search (none will match).
1731 if ((match && namematchRWBK)
1732 || ((namematchRWBK == 2) && (namematchRO == 2)))
1736 /* Passed all the tests. Take it */
1739 put_nattributeentry(&ctx, &Vldbentry, &VldbentryFirst,
1740 &VldbentryLast, vldbentries, &tentry,
1741 matchtype, matchindex, nentries,
1746 if (*nentries >= maxCount)
1747 break; /* collected the max */
1750 *nextstartindex = (blockindex ? blockindex : -1);
1754 #ifdef HAVE_POSIX_REGEX
1760 countAbort(this_op);
1761 ubik_AbortTrans(ctx.trans);
1762 if (vldbentries->nbulkentries_val)
1763 free(vldbentries->nbulkentries_val);
1764 vldbentries->nbulkentries_val = 0;
1765 vldbentries->nbulkentries_len = 0;
1766 *nextstartindex = -1;
1770 ("N2ListAttrs nentries=%d %s\n", vldbentries->nbulkentries_len,
1771 rxinfo(rxstr, rxcall)));
1772 return (ubik_EndTrans(ctx.trans));
1777 /* Retrieves in vldbentries all vldb entries that match the specified
1778 * attributes (by server number, partition, volume type, and flag); if
1779 * volume id is specified then the associated list for that entry is
1780 * returned. CAUTION: This could be a very expensive call since in most
1781 * cases sequential search of all vldb entries is performed.
1784 SVL_LinkedList(struct rx_call *rxcall,
1785 struct VldbListByAttributes *attributes,
1786 afs_int32 *nentries,
1787 vldb_list *vldbentries)
1789 int this_op = VLLINKEDLIST;
1792 struct nvlentry tentry;
1793 vldblist vllist, *vllistptr;
1794 afs_int32 blockindex, count, match;
1799 countRequest(this_op);
1800 if ((code = Init_VLdbase(&ctx, LOCKREAD, this_op)))
1804 vldbentries->node = NULL;
1805 vllistptr = &vldbentries->node;
1807 /* List by volumeid */
1808 if (attributes->Mask & VLLIST_VOLUMEID) {
1810 FindByID(&ctx, attributes->volumeid, -1, &tentry, &code);
1817 vllist = (single_vldbentry *) malloc(sizeof(single_vldbentry));
1818 if (vllist == NULL) {
1822 code = vlentry_to_vldbentry(&ctx, &tentry, &vllist->VldbEntry);
1826 vllist->next_vldb = NULL;
1828 *vllistptr = vllist; /* Thread onto list */
1829 vllistptr = &vllist->next_vldb;
1833 /* Search by server, partition, and flags */
1835 for (blockindex = NextEntry(&ctx, 0, &tentry, &count); blockindex;
1836 blockindex = NextEntry(&ctx, blockindex, &tentry, &count)) {
1839 if (++pollcount > 50) {
1840 #ifndef AFS_PTHREAD_ENV
1846 /* Does this volume exist on the desired server */
1847 if (attributes->Mask & VLLIST_SERVER) {
1849 IpAddrToRelAddr(&ctx, attributes->server, 0);
1850 if (serverindex == -1)
1852 for (k = 0; k < OMAXNSERVERS; k++) {
1853 if (tentry.serverNumber[k] == BADSERVERID)
1855 if (tentry.serverNumber[k] == serverindex) {
1864 /* Does this volume exist on the desired partition */
1865 if (attributes->Mask & VLLIST_PARTITION) {
1867 if (tentry.serverPartition[k] != attributes->partition)
1870 for (k = 0; k < OMAXNSERVERS; k++) {
1871 if (tentry.serverNumber[k] == BADSERVERID)
1873 if (tentry.serverPartition[k] ==
1874 attributes->partition) {
1884 /* Does this volume have the desired flags */
1885 if (attributes->Mask & VLLIST_FLAG) {
1886 if (!(tentry.flags & attributes->flag))
1890 vllist = (single_vldbentry *) malloc(sizeof(single_vldbentry));
1891 if (vllist == NULL) {
1895 code = vlentry_to_vldbentry(&ctx, &tentry, &vllist->VldbEntry);
1899 vllist->next_vldb = NULL;
1901 *vllistptr = vllist; /* Thread onto list */
1902 vllistptr = &vllist->next_vldb;
1904 if (smallMem && (*nentries >= VLDBALLOCCOUNT)) {
1905 code = VL_SIZEEXCEEDED;
1911 return (ubik_EndTrans(ctx.trans));
1914 countAbort(this_op);
1915 ubik_AbortTrans(ctx.trans);
1920 SVL_LinkedListN(struct rx_call *rxcall,
1921 struct VldbListByAttributes *attributes,
1922 afs_int32 *nentries,
1923 nvldb_list *vldbentries)
1925 int this_op = VLLINKEDLISTN;
1928 struct nvlentry tentry;
1929 nvldblist vllist, *vllistptr;
1930 afs_int32 blockindex, count, match;
1935 countRequest(this_op);
1936 if ((code = Init_VLdbase(&ctx, LOCKREAD, this_op)))
1940 vldbentries->node = NULL;
1941 vllistptr = &vldbentries->node;
1943 /* List by volumeid */
1944 if (attributes->Mask & VLLIST_VOLUMEID) {
1946 FindByID(&ctx, attributes->volumeid, -1, &tentry, &code);
1953 vllist = (single_nvldbentry *) malloc(sizeof(single_nvldbentry));
1954 if (vllist == NULL) {
1958 code = vlentry_to_nvldbentry(&ctx, &tentry, &vllist->VldbEntry);
1962 vllist->next_vldb = NULL;
1964 *vllistptr = vllist; /* Thread onto list */
1965 vllistptr = &vllist->next_vldb;
1969 /* Search by server, partition, and flags */
1971 for (blockindex = NextEntry(&ctx, 0, &tentry, &count); blockindex;
1972 blockindex = NextEntry(&ctx, blockindex, &tentry, &count)) {
1975 if (++pollcount > 50) {
1976 #ifndef AFS_PTHREAD_ENV
1982 /* Does this volume exist on the desired server */
1983 if (attributes->Mask & VLLIST_SERVER) {
1985 IpAddrToRelAddr(&ctx, attributes->server, 0);
1986 if (serverindex == -1)
1988 for (k = 0; k < NMAXNSERVERS; k++) {
1989 if (tentry.serverNumber[k] == BADSERVERID)
1991 if (tentry.serverNumber[k] == serverindex) {
2000 /* Does this volume exist on the desired partition */
2001 if (attributes->Mask & VLLIST_PARTITION) {
2003 if (tentry.serverPartition[k] != attributes->partition)
2006 for (k = 0; k < NMAXNSERVERS; k++) {
2007 if (tentry.serverNumber[k] == BADSERVERID)
2009 if (tentry.serverPartition[k] ==
2010 attributes->partition) {
2020 /* Does this volume have the desired flags */
2021 if (attributes->Mask & VLLIST_FLAG) {
2022 if (!(tentry.flags & attributes->flag))
2026 vllist = (single_nvldbentry *) malloc(sizeof(single_nvldbentry));
2027 if (vllist == NULL) {
2031 code = vlentry_to_nvldbentry(&ctx, &tentry, &vllist->VldbEntry);
2035 vllist->next_vldb = NULL;
2037 *vllistptr = vllist; /* Thread onto list */
2038 vllistptr = &vllist->next_vldb;
2040 if (smallMem && (*nentries >= VLDBALLOCCOUNT)) {
2041 code = VL_SIZEEXCEEDED;
2047 return (ubik_EndTrans(ctx.trans));
2050 countAbort(this_op);
2051 ubik_AbortTrans(ctx.trans);
2055 /* Get back vldb header statistics (allocs, frees, maxvolumeid,
2056 * totalentries, etc) and dynamic statistics (number of requests and/or
2057 * aborts per remote procedure call, etc)
2060 SVL_GetStats(struct rx_call *rxcall,
2062 vital_vlheader *vital_header)
2064 int this_op = VLGETSTATS;
2067 char rxstr[AFS_RXINFO_LEN];
2069 countRequest(this_op);
2071 /* Allow users to get statistics freely */
2072 if (!afsconf_SuperUser(vldb_confdir, rxcall, NULL)) /* Must be in 'UserList' to use */
2075 if ((code = Init_VLdbase(&ctx, LOCKREAD, this_op)))
2077 VLog(5, ("GetStats %s\n", rxinfo(rxstr, rxcall)));
2078 memcpy((char *)vital_header, (char *)&ctx.cheader->vital_header,
2079 sizeof(vital_vlheader));
2080 memcpy((char *)stats, (char *)&dynamic_statistics, sizeof(vldstats));
2081 return (ubik_EndTrans(ctx.trans));
2084 /* Get the list of file server addresses from the VLDB. Currently it's pretty
2085 * easy to do. In the future, it might require a little bit of grunging
2086 * through the VLDB, but that's life.
2089 SVL_GetAddrs(struct rx_call *rxcall,
2092 struct VLCallBack *spare3,
2093 afs_int32 *nentries,
2096 int this_op = VLGETADDRS;
2102 countRequest(this_op);
2103 addrsp->bulkaddrs_len = *nentries = 0;
2104 addrsp->bulkaddrs_val = 0;
2105 memset(spare3, 0, sizeof(struct VLCallBack));
2107 if ((code = Init_VLdbase(&ctx, LOCKREAD, this_op)))
2110 VLog(5, ("GetAddrs\n"));
2111 addrsp->bulkaddrs_val = taddrp =
2112 (afs_uint32 *) malloc(sizeof(afs_int32) * (MAXSERVERID + 1));
2113 nservers = *nentries = addrsp->bulkaddrs_len = 0;
2120 for (i = 0; i <= MAXSERVERID; i++) {
2121 if ((*taddrp = ntohl(ctx.cheader->IpMappedAddr[i]))) {
2127 addrsp->bulkaddrs_len = *nentries = nservers;
2128 return (ubik_EndTrans(ctx.trans));
2131 countAbort(this_op);
2132 ubik_AbortTrans(ctx.trans);
2136 #define PADDR(addr) VLog(0,("%d.%d.%d.%d", (addr>>24)&0xff, (addr>>16)&0xff, (addr>>8) &0xff, addr&0xff));
2139 SVL_RegisterAddrs(struct rx_call *rxcall, afsUUID *uuidp, afs_int32 spare1,
2142 int this_op = VLREGADDR;
2145 int cnt, h, i, j, k, m;
2146 struct extentaddr *exp = 0, *tex;
2148 afs_uint32 addrs[VL_MAXIPADDRS_PERMH];
2150 int count, willChangeEntry, foundUuidEntry, willReplaceCnt;
2151 int WillReplaceEntry, WillChange[MAXSERVERID + 1];
2153 int ReplaceEntry = 0;
2156 countRequest(this_op);
2157 if (!afsconf_SuperUser(vldb_confdir, rxcall, NULL))
2159 if ((code = Init_VLdbase(&ctx, LOCKWRITE, this_op)))
2162 /* Eliminate duplicates from IP address list */
2163 for (k = 0, cnt = 0; k < addrsp->bulkaddrs_len; k++) {
2164 if (addrsp->bulkaddrs_val[k] == 0)
2166 for (m = 0; m < cnt; m++) {
2167 if (addrs[m] == addrsp->bulkaddrs_val[k])
2171 if (m == VL_MAXIPADDRS_PERMH) {
2173 ("Number of addresses exceeds %d. Cannot register IP addr 0x%x in VLDB\n",
2174 VL_MAXIPADDRS_PERMH, addrsp->bulkaddrs_val[k]));
2176 addrs[m] = addrsp->bulkaddrs_val[k];
2182 code = VL_INDEXERANGE;
2189 /* For each server registered within the VLDB */
2190 for (srvidx = 0; srvidx <= MAXSERVERID; srvidx++) {
2191 willChangeEntry = 0;
2192 WillReplaceEntry = 1;
2193 code = multiHomedExtent(&ctx, srvidx, &exp);
2198 /* See if the addresses to register will change this server entry */
2199 tuuid = exp->ex_hostuuid;
2200 afs_ntohuuid(&tuuid);
2201 if (afs_uuid_equal(uuidp, &tuuid)) {
2205 for (mhidx = 0; mhidx < VL_MAXIPADDRS_PERMH; mhidx++) {
2206 if (!exp->ex_addrs[mhidx])
2208 for (k = 0; k < cnt; k++) {
2209 if (ntohl(exp->ex_addrs[mhidx]) == addrs[k]) {
2210 willChangeEntry = 1;
2211 WillChange[count] = srvidx;
2216 WillReplaceEntry = 0;
2220 /* The server is not registered as a multihomed.
2221 * See if the addresses to register will replace this server entry.
2223 for (k = 0; k < cnt; k++) {
2224 if (ctx.hostaddress[srvidx] == addrs[k]) {
2225 willChangeEntry = 1;
2226 WillChange[count] = srvidx;
2227 WillReplaceEntry = 1;
2232 if (willChangeEntry) {
2233 if (WillReplaceEntry) {
2235 ReplaceEntry = srvidx;
2241 /* If we found the uuid in the VLDB and if we are replacing another
2242 * entire entry, then complain and fail. Also, if we did not find
2243 * the uuid in the VLDB and the IP addresses being registered was
2244 * found in more than one other entry, then we don't know which one
2245 * to replace and will complain and fail.
2247 if ((foundUuidEntry && (willReplaceCnt > 0))
2248 || (!foundUuidEntry && (count > 1))) {
2250 ("The following fileserver is being registered in the VLDB:\n"));
2252 for (k = 0; k < cnt; k++) {
2259 if (foundUuidEntry) {
2260 code = multiHomedExtent(&ctx, FoundUuid, &exp);
2262 VLog(0, (" It would have replaced the existing VLDB server "
2264 VLog(0, (" entry %d: [", FoundUuid));
2265 for (mhidx = 0; mhidx < VL_MAXIPADDRS_PERMH; mhidx++) {
2266 if (!exp->ex_addrs[mhidx])
2270 PADDR(ntohl(exp->ex_addrs[mhidx]));
2277 VLog(0, (" Yet another VLDB server entry exists:\n"));
2279 VLog(0, (" Yet other VLDB server entries exist:\n"));
2280 for (j = 0; j < count; j++) {
2281 srvidx = WillChange[j];
2282 VLog(0, (" entry %d: ", srvidx));
2284 code = multiHomedExtent(&ctx, srvidx, &exp);
2290 for (mhidx = 0; mhidx < VL_MAXIPADDRS_PERMH; mhidx++) {
2291 if (!exp->ex_addrs[mhidx])
2295 PADDR(ntohl(exp->ex_addrs[mhidx]));
2299 PADDR(ctx.hostaddress[srvidx]);
2305 VLog(0, (" You must 'vos changeaddr' this other server entry\n"));
2308 (" You must 'vos changeaddr' these other server entries\n"));
2311 (" and/or remove the sysid file from the registering fileserver\n"));
2312 VLog(0, (" before the fileserver can be registered in the VLDB.\n"));
2314 code = VL_MULTIPADDR;
2318 /* Passed the checks. Now find and update the existing mh entry, or create
2321 if (foundUuidEntry) {
2322 /* Found the entry with same uuid. See if we need to change it */
2325 code = multiHomedExtentBase(&ctx, FoundUuid, &exp, &base);
2329 /* Determine if the entry has changed */
2330 for (k = 0; ((k < cnt) && !change); k++) {
2331 if (ntohl(exp->ex_addrs[k]) != addrs[k])
2334 for (; ((k < VL_MAXIPADDRS_PERMH) && !change); k++) {
2335 if (exp->ex_addrs[k] != 0)
2339 return (ubik_EndTrans(ctx.trans));
2343 VLog(0, ("The following fileserver is being registered in the VLDB:\n"));
2345 for (k = 0; k < cnt; k++) {
2352 if (foundUuidEntry) {
2354 (" It will replace the following existing entry in the VLDB (same uuid):\n"));
2355 VLog(0, (" entry %d: [", FoundUuid));
2356 for (k = 0; k < VL_MAXIPADDRS_PERMH; k++) {
2357 if (exp->ex_addrs[k] == 0)
2361 PADDR(ntohl(exp->ex_addrs[k]));
2364 } else if (willReplaceCnt || (count == 1)) {
2365 /* If we are not replacing an entry and there is only one entry to change,
2366 * then we will replace that entry.
2368 if (!willReplaceCnt) {
2369 ReplaceEntry = WillChange[0];
2373 /* Have an entry that needs to be replaced */
2374 code = multiHomedExtentBase(&ctx, ReplaceEntry, &exp, &base);
2380 (" It will replace the following existing entry in the VLDB (new uuid):\n"));
2381 VLog(0, (" entry %d: [", ReplaceEntry));
2382 for (k = 0; k < VL_MAXIPADDRS_PERMH; k++) {
2383 if (exp->ex_addrs[k] == 0)
2387 PADDR(ntohl(exp->ex_addrs[k]));
2391 /* Not a mh entry. So we have to create a new mh entry and
2392 * put it on the ReplaceEntry slot of the ctx.hostaddress array.
2394 VLog(0, (" It will replace existing entry %d, ", ReplaceEntry));
2395 PADDR(ctx.hostaddress[ReplaceEntry]);
2396 VLog(0,(", in the VLDB (new uuid):\n"));
2399 FindExtentBlock(&ctx, uuidp, 1, ReplaceEntry, &exp, &base);
2407 /* There is no entry for this server, must create a new mh entry as
2408 * well as use a new slot of the ctx.hostaddress array.
2410 VLog(0, (" It will create a new entry in the VLDB.\n"));
2411 code = FindExtentBlock(&ctx, uuidp, 1, -1, &exp, &base);
2419 /* Now we have a mh entry to fill in. Update the uuid, bump the
2420 * uniquifier, and fill in its IP addresses.
2423 afs_htonuuid(&tuuid);
2424 exp->ex_hostuuid = tuuid;
2425 exp->ex_uniquifier = htonl(ntohl(exp->ex_uniquifier) + 1);
2426 for (k = 0; k < cnt; k++) {
2427 exp->ex_addrs[k] = htonl(addrs[k]);
2429 for (; k < VL_MAXIPADDRS_PERMH; k++) {
2430 exp->ex_addrs[k] = 0;
2433 /* Write the new mh entry out */
2436 DOFFSET(ntohl(ctx.ex_addr[0]->ex_contaddrs[base]),
2437 (char *)ctx.ex_addr[base], (char *)exp), (char *)exp,
2443 /* Remove any common addresses from other mh entres. We know these entries
2444 * are being changed and not replaced so they are mh entries.
2447 for (i = 0; i < count; i++) {
2450 /* Skip the entry we replaced */
2451 if (willReplaceCnt && (WillChange[i] == ReplaceEntry))
2454 code = multiHomedExtentBase(&ctx, WillChange[i], &tex, &base);
2460 (" The following existing entries in the VLDB will be updated:\n"));
2462 VLog(0, (" entry %d: [", WillChange[i]));
2463 for (h = j = 0; j < VL_MAXIPADDRS_PERMH; j++) {
2464 if (tex->ex_addrs[j]) {
2467 PADDR(ntohl(tex->ex_addrs[j]));
2470 for (k = 0; k < cnt; k++) {
2471 if (ntohl(tex->ex_addrs[j]) == addrs[k])
2475 /* Not found, so we keep it */
2476 tex->ex_addrs[h] = tex->ex_addrs[j];
2480 for (j = h; j < VL_MAXIPADDRS_PERMH; j++) {
2481 tex->ex_addrs[j] = 0; /* zero rest of mh entry */
2485 /* Write out the modified mh entry */
2486 tex->ex_uniquifier = htonl(ntohl(tex->ex_uniquifier) + 1);
2488 DOFFSET(ntohl(ctx.ex_addr[0]->ex_contaddrs[base]),
2489 (char *)ctx.ex_addr[base], (char *)tex);
2490 if (vlwrite(ctx.trans, doff, (char *)tex, sizeof(*tex))) {
2496 return (ubik_EndTrans(ctx.trans));
2499 countAbort(this_op);
2500 ubik_AbortTrans(ctx.trans);
2505 SVL_GetAddrsU(struct rx_call *rxcall,
2506 struct ListAddrByAttributes *attributes,
2508 afs_int32 *uniquifier,
2509 afs_int32 *nentries,
2512 int this_op = VLGETADDRSU;
2513 afs_int32 code, index = -1, offset;
2515 int nservers, i, j, base = 0;
2516 struct extentaddr *exp = 0;
2518 afs_uint32 *taddrp, taddr;
2519 char rxstr[AFS_RXINFO_LEN];
2521 countRequest(this_op);
2522 addrsp->bulkaddrs_len = *nentries = 0;
2523 addrsp->bulkaddrs_val = 0;
2524 VLog(5, ("GetAddrsU %s\n", rxinfo(rxstr, rxcall)));
2525 if ((code = Init_VLdbase(&ctx, LOCKREAD, this_op)))
2528 if (attributes->Mask & VLADDR_IPADDR) {
2529 if (attributes->Mask & (VLADDR_INDEX | VLADDR_UUID)) {
2533 for (base = 0; base < VL_MAX_ADDREXTBLKS; base++) {
2534 if (!ctx.ex_addr[base])
2536 for (i = 1; i < VL_MHSRV_PERBLK; i++) {
2537 exp = &ctx.ex_addr[base][i];
2538 tuuid = exp->ex_hostuuid;
2539 afs_ntohuuid(&tuuid);
2540 if (afs_uuid_is_nil(&tuuid))
2542 for (j = 0; j < VL_MAXIPADDRS_PERMH; j++) {
2543 if (exp->ex_addrs[j]
2544 && (ntohl(exp->ex_addrs[j]) == attributes->ipaddr)) {
2548 if (j < VL_MAXIPADDRS_PERMH)
2551 if (i < VL_MHSRV_PERBLK)
2554 if (base >= VL_MAX_ADDREXTBLKS) {
2558 } else if (attributes->Mask & VLADDR_INDEX) {
2559 if (attributes->Mask & (VLADDR_IPADDR | VLADDR_UUID)) {
2563 index = attributes->index;
2564 if (index < 1 || index >= (VL_MAX_ADDREXTBLKS * VL_MHSRV_PERBLK)) {
2565 code = VL_INDEXERANGE;
2568 base = index / VL_MHSRV_PERBLK;
2569 offset = index % VL_MHSRV_PERBLK;
2574 if (!ctx.ex_addr[base]) {
2575 code = VL_INDEXERANGE;
2578 exp = &ctx.ex_addr[base][offset];
2579 } else if (attributes->Mask & VLADDR_UUID) {
2580 if (attributes->Mask & (VLADDR_IPADDR | VLADDR_INDEX)) {
2584 if (!ctx.ex_addr[0]) { /* mh servers probably aren't setup on this vldb */
2588 code = FindExtentBlock(&ctx, &attributes->uuid, 0, -1, &exp, &base);
2600 addrsp->bulkaddrs_val = taddrp =
2601 (afs_uint32 *) malloc(sizeof(afs_int32) * (MAXSERVERID + 1));
2602 nservers = *nentries = addrsp->bulkaddrs_len = 0;
2607 tuuid = exp->ex_hostuuid;
2608 afs_ntohuuid(&tuuid);
2609 if (afs_uuid_is_nil(&tuuid)) {
2616 *uniquifier = ntohl(exp->ex_uniquifier);
2617 for (i = 0; i < VL_MAXIPADDRS_PERMH; i++) {
2618 if (exp->ex_addrs[i]) {
2619 taddr = ntohl(exp->ex_addrs[i]);
2620 /* Weed out duplicates */
2621 for (j = 0; j < nservers; j++) {
2622 if (taddrp[j] == taddr)
2625 if ((j == nservers) && (j <= MAXSERVERID)) {
2626 taddrp[nservers] = taddr;
2631 addrsp->bulkaddrs_len = *nentries = nservers;
2632 return (ubik_EndTrans(ctx.trans));
2635 countAbort(this_op);
2636 ubik_AbortTrans(ctx.trans);
2640 /* ============> End of Exported vldb RPC functions <============= */
2643 /* Routine that copies the given vldb entry to the output buffer, vldbentries. */
2645 put_attributeentry(struct vl_ctx *ctx,
2646 struct vldbentry **Vldbentry,
2647 struct vldbentry **VldbentryFirst,
2648 struct vldbentry **VldbentryLast,
2649 bulkentries *vldbentries,
2650 struct nvlentry *entry,
2651 afs_int32 *nentries,
2652 afs_int32 *alloccnt)
2658 if (*Vldbentry == *VldbentryLast) {
2660 return VL_SIZEEXCEEDED; /* no growing if smallMem defined */
2662 /* Allocate another set of memory; each time allocate twice as
2663 * many blocks as the last time. When we reach VLDBALLOCLIMIT,
2664 * then grow in increments of VLDBALLOCINCR.
2666 allo = (*alloccnt > VLDBALLOCLIMIT) ? VLDBALLOCINCR : *alloccnt;
2668 (vldbentry *) realloc(*VldbentryFirst,
2669 (*alloccnt + allo) * sizeof(vldbentry));
2673 *VldbentryFirst = vldbentries->bulkentries_val = reall;
2674 *Vldbentry = *VldbentryFirst + *alloccnt;
2675 *VldbentryLast = *Vldbentry + allo;
2679 code = vlentry_to_vldbentry(ctx, entry, *Vldbentry);
2685 vldbentries->bulkentries_len++;
2690 put_nattributeentry(struct vl_ctx *ctx,
2691 struct nvldbentry **Vldbentry,
2692 struct nvldbentry **VldbentryFirst,
2693 struct nvldbentry **VldbentryLast,
2694 nbulkentries *vldbentries,
2695 struct nvlentry *entry,
2696 afs_int32 matchtype,
2697 afs_int32 matchindex,
2698 afs_int32 *nentries,
2699 afs_int32 *alloccnt)
2705 if (*Vldbentry == *VldbentryLast) {
2707 return VL_SIZEEXCEEDED; /* no growing if smallMem defined */
2709 /* Allocate another set of memory; each time allocate twice as
2710 * many blocks as the last time. When we reach VLDBALLOCLIMIT,
2711 * then grow in increments of VLDBALLOCINCR.
2713 allo = (*alloccnt > VLDBALLOCLIMIT) ? VLDBALLOCINCR : *alloccnt;
2715 (nvldbentry *) realloc(*VldbentryFirst,
2716 (*alloccnt + allo) * sizeof(nvldbentry));
2720 *VldbentryFirst = vldbentries->nbulkentries_val = reall;
2721 *Vldbentry = *VldbentryFirst + *alloccnt;
2722 *VldbentryLast = *Vldbentry + allo;
2725 code = vlentry_to_nvldbentry(ctx, entry, *Vldbentry);
2729 (*Vldbentry)->matchindex = (matchtype << 16) + matchindex;
2732 vldbentries->nbulkentries_len++;
2737 /* Common code to actually remove a vldb entry from the database. */
2739 RemoveEntry(struct vl_ctx *ctx, afs_int32 entryptr,
2740 struct nvlentry *tentry)
2744 if ((code = UnthreadVLentry(ctx, entryptr, tentry)))
2746 if ((code = FreeBlock(ctx, entryptr)))
2752 ReleaseEntry(struct nvlentry *tentry, afs_int32 releasetype)
2754 if (releasetype & LOCKREL_TIMESTAMP)
2755 tentry->LockTimestamp = 0;
2756 if (releasetype & LOCKREL_OPCODE)
2757 tentry->flags &= ~VLOP_ALLOPERS;
2758 if (releasetype & LOCKREL_AFSID)
2759 tentry->LockAfsId = 0;
2763 /* Verify that the incoming vldb entry is valid; multi type of error codes
2766 check_vldbentry(struct vldbentry *aentry)
2770 if (InvalidVolname(aentry->name))
2772 if (aentry->nServers <= 0 || aentry->nServers > OMAXNSERVERS)
2773 return VL_BADSERVER;
2774 for (i = 0; i < aentry->nServers; i++) {
2775 /* if (aentry->serverNumber[i] < 0 || aentry->serverNumber[i] > MAXSERVERID)
2776 return VL_BADSERVER; */
2777 if (aentry->serverPartition[i] < 0
2778 || aentry->serverPartition[i] > MAXPARTITIONID)
2779 return VL_BADPARTITION;
2780 if (aentry->serverFlags[i] < 0
2781 || aentry->serverFlags[i] > MAXSERVERFLAG)
2782 return VL_BADSERVERFLAG;
2788 check_nvldbentry(struct nvldbentry *aentry)
2792 if (InvalidVolname(aentry->name))
2794 if (aentry->nServers <= 0 || aentry->nServers > NMAXNSERVERS)
2795 return VL_BADSERVER;
2796 for (i = 0; i < aentry->nServers; i++) {
2797 /* if (aentry->serverNumber[i] < 0 || aentry->serverNumber[i] > MAXSERVERID)
2798 return VL_BADSERVER; */
2799 if (aentry->serverPartition[i] < 0
2800 || aentry->serverPartition[i] > MAXPARTITIONID)
2801 return VL_BADPARTITION;
2802 if (aentry->serverFlags[i] < 0
2803 || aentry->serverFlags[i] > MAXSERVERFLAG)
2804 return VL_BADSERVERFLAG;
2810 /* Convert from the external vldb entry representation to its internal
2811 (more compact) form. This call should not change the hash chains! */
2813 vldbentry_to_vlentry(struct vl_ctx *ctx,
2814 struct vldbentry *VldbEntry,
2815 struct nvlentry *VlEntry)
2819 if (strcmp(VlEntry->name, VldbEntry->name))
2820 strncpy(VlEntry->name, VldbEntry->name, sizeof(VlEntry->name));
2821 for (i = 0; i < VldbEntry->nServers; i++) {
2822 serverindex = IpAddrToRelAddr(ctx, VldbEntry->serverNumber[i], 1);
2823 if (serverindex == -1)
2824 return VL_BADSERVER;
2825 VlEntry->serverNumber[i] = serverindex;
2826 VlEntry->serverPartition[i] = VldbEntry->serverPartition[i];
2827 VlEntry->serverFlags[i] = VldbEntry->serverFlags[i];
2829 for (; i < OMAXNSERVERS; i++)
2830 VlEntry->serverNumber[i] = VlEntry->serverPartition[i] =
2831 VlEntry->serverFlags[i] = BADSERVERID;
2832 for (i = 0; i < MAXTYPES; i++)
2833 VlEntry->volumeId[i] = VldbEntry->volumeId[i];
2834 VlEntry->cloneId = VldbEntry->cloneId;
2835 VlEntry->flags = VldbEntry->flags;
2840 nvldbentry_to_vlentry(struct vl_ctx *ctx,
2841 struct nvldbentry *VldbEntry,
2842 struct nvlentry *VlEntry)
2846 if (strcmp(VlEntry->name, VldbEntry->name))
2847 strncpy(VlEntry->name, VldbEntry->name, sizeof(VlEntry->name));
2848 for (i = 0; i < VldbEntry->nServers; i++) {
2849 serverindex = IpAddrToRelAddr(ctx, VldbEntry->serverNumber[i], 1);
2850 if (serverindex == -1)
2851 return VL_BADSERVER;
2852 VlEntry->serverNumber[i] = serverindex;
2853 VlEntry->serverPartition[i] = VldbEntry->serverPartition[i];
2854 VlEntry->serverFlags[i] = VldbEntry->serverFlags[i];
2856 for (; i < NMAXNSERVERS; i++)
2857 VlEntry->serverNumber[i] = VlEntry->serverPartition[i] =
2858 VlEntry->serverFlags[i] = BADSERVERID;
2859 for (i = 0; i < MAXTYPES; i++)
2860 VlEntry->volumeId[i] = VldbEntry->volumeId[i];
2861 VlEntry->cloneId = VldbEntry->cloneId;
2862 VlEntry->flags = VldbEntry->flags;
2867 /* Update the vldb entry with the new fields as indicated by the value of
2868 * the Mask entry in the updateentry structure. All necessary validation
2869 * checks are performed.
2872 get_vldbupdateentry(struct vl_ctx *ctx,
2873 afs_int32 blockindex,
2874 struct VldbUpdateEntry *updateentry,
2875 struct nvlentry *VlEntry)
2877 int i, j, code, serverindex;
2878 afs_uint32 checkids[MAXTYPES];
2880 /* check if any specified new IDs are already present in the db. Do
2881 * this check before doing anything else, so we don't get a half-
2883 memset(&checkids, 0, sizeof(checkids));
2884 if (updateentry->Mask & VLUPDATE_RWID) {
2885 checkids[RWVOL] = updateentry->spares3; /* rw id */
2887 if (updateentry->Mask & VLUPDATE_READONLYID) {
2888 checkids[ROVOL] = updateentry->ReadOnlyId;
2890 if (updateentry->Mask & VLUPDATE_BACKUPID) {
2891 checkids[BACKVOL] = updateentry->BackupId;
2894 if (EntryIDExists(ctx, checkids, MAXTYPES, &code)) {
2900 if (updateentry->Mask & VLUPDATE_VOLUMENAME) {
2901 struct nvlentry tentry;
2903 if (InvalidVolname(updateentry->name))
2906 if (FindByName(ctx, updateentry->name, &tentry, &code)) {
2907 return VL_NAMEEXIST;
2912 if ((code = UnhashVolname(ctx, blockindex, VlEntry)))
2914 strncpy(VlEntry->name, updateentry->name, sizeof(VlEntry->name));
2915 HashVolname(ctx, blockindex, VlEntry);
2918 if (updateentry->Mask & VLUPDATE_VOLNAMEHASH) {
2919 if ((code = UnhashVolname(ctx, blockindex, VlEntry))) {
2920 if (code != VL_NOENT)
2923 HashVolname(ctx, blockindex, VlEntry);
2926 if (updateentry->Mask & VLUPDATE_FLAGS) {
2927 VlEntry->flags = updateentry->flags;
2929 if (updateentry->Mask & VLUPDATE_CLONEID) {
2930 VlEntry->cloneId = updateentry->cloneId;
2932 if (updateentry->Mask & VLUPDATE_RWID) {
2933 if ((code = UnhashVolid(ctx, RWVOL, blockindex, VlEntry))) {
2934 if (code != VL_NOENT)
2937 VlEntry->volumeId[RWVOL] = updateentry->spares3; /* rw id */
2938 if ((code = HashVolid(ctx, RWVOL, blockindex, VlEntry)))
2941 if (updateentry->Mask & VLUPDATE_READONLYID) {
2942 if ((code = UnhashVolid(ctx, ROVOL, blockindex, VlEntry))) {
2943 if (code != VL_NOENT)
2946 VlEntry->volumeId[ROVOL] = updateentry->ReadOnlyId;
2947 if ((code = HashVolid(ctx, ROVOL, blockindex, VlEntry)))
2950 if (updateentry->Mask & VLUPDATE_BACKUPID) {
2951 if ((code = UnhashVolid(ctx, BACKVOL, blockindex, VlEntry))) {
2952 if (code != VL_NOENT)
2955 VlEntry->volumeId[BACKVOL] = updateentry->BackupId;
2956 if ((code = HashVolid(ctx, BACKVOL, blockindex, VlEntry)))
2959 if (updateentry->Mask & VLUPDATE_REPSITES) {
2960 if (updateentry->nModifiedRepsites <= 0
2961 || updateentry->nModifiedRepsites > OMAXNSERVERS)
2962 return VL_BADSERVER;
2963 for (i = 0; i < updateentry->nModifiedRepsites; i++) {
2964 /* if (updateentry->RepsitesTargetServer[i] < 0 || updateentry->RepsitesTargetServer[i] > MAXSERVERID)
2965 return VL_BADSERVER; */
2966 if (updateentry->RepsitesTargetPart[i] < 0
2967 || updateentry->RepsitesTargetPart[i] > MAXPARTITIONID)
2968 return VL_BADPARTITION;
2969 if (updateentry->RepsitesMask[i] & VLUPDATE_REPS_DELETE) {
2971 repsite_exists(VlEntry,
2972 IpAddrToRelAddr(ctx, updateentry->
2973 RepsitesTargetServer[i],
2975 updateentry->RepsitesTargetPart[i])) !=
2977 repsite_compress(VlEntry, j);
2979 return VL_NOREPSERVER;
2981 if (updateentry->RepsitesMask[i] & VLUPDATE_REPS_ADD) {
2982 /* if (updateentry->RepsitesNewServer[i] < 0 || updateentry->RepsitesNewServer[i] > MAXSERVERID)
2983 return VL_BADSERVER; */
2984 if (updateentry->RepsitesNewPart[i] < 0
2985 || updateentry->RepsitesNewPart[i] > MAXPARTITIONID)
2986 return VL_BADPARTITION;
2989 IpAddrToRelAddr(ctx, updateentry->RepsitesNewServer[i], 1),
2990 updateentry->RepsitesNewPart[i]) != -1)
2991 return VL_DUPREPSERVER;
2993 VlEntry->serverNumber[j] != BADSERVERID
2994 && j < OMAXNSERVERS; j++);
2995 if (j >= OMAXNSERVERS)
2998 IpAddrToRelAddr(ctx, updateentry->RepsitesNewServer[i],
3000 return VL_BADSERVER;
3001 VlEntry->serverNumber[j] = serverindex;
3002 VlEntry->serverPartition[j] = updateentry->RepsitesNewPart[i];
3003 if (updateentry->RepsitesNewFlags[i] < 0
3004 || updateentry->RepsitesNewFlags[i] > MAXSERVERFLAG)
3005 return VL_BADSERVERFLAG;
3006 VlEntry->serverFlags[j] = updateentry->RepsitesNewFlags[i];
3008 if (updateentry->RepsitesMask[i] & VLUPDATE_REPS_MODSERV) {
3009 /*n if (updateentry->RepsitesNewServer[i] < 0 || updateentry->RepsitesNewServer[i] > MAXSERVERID)
3010 return VL_BADSERVER; */
3012 repsite_exists(VlEntry,
3013 IpAddrToRelAddr(ctx, updateentry->
3014 RepsitesTargetServer[i],
3016 updateentry->RepsitesTargetPart[i])) !=
3018 VlEntry->serverNumber[j] =
3019 IpAddrToRelAddr(ctx, updateentry->RepsitesNewServer[i],
3022 return VL_NOREPSERVER;
3024 if (updateentry->RepsitesMask[i] & VLUPDATE_REPS_MODPART) {
3025 if (updateentry->RepsitesNewPart[i] < 0
3026 || updateentry->RepsitesNewPart[i] > MAXPARTITIONID)
3027 return VL_BADPARTITION;
3029 repsite_exists(VlEntry,
3030 IpAddrToRelAddr(ctx, updateentry->
3031 RepsitesTargetServer[i],
3033 updateentry->RepsitesTargetPart[i])) !=
3035 VlEntry->serverPartition[j] =
3036 updateentry->RepsitesNewPart[i];
3038 return VL_NOREPSERVER;
3040 if (updateentry->RepsitesMask[i] & VLUPDATE_REPS_MODFLAG) {
3042 repsite_exists(VlEntry,
3043 IpAddrToRelAddr(ctx, updateentry->
3044 RepsitesTargetServer[i],
3046 updateentry->RepsitesTargetPart[i])) !=
3048 if (updateentry->RepsitesNewFlags[i] < 0
3049 || updateentry->RepsitesNewFlags[i] > MAXSERVERFLAG)
3050 return VL_BADSERVERFLAG;
3051 VlEntry->serverFlags[j] =
3052 updateentry->RepsitesNewFlags[i];
3054 return VL_NOREPSERVER;
3062 /* Check if the specified [server,partition] entry is found in the vldb
3063 * entry's repsite table; it's offset in the table is returned, if it's
3066 repsite_exists(struct nvlentry *VlEntry, int server, int partition)
3070 for (i = 0; VlEntry->serverNumber[i] != BADSERVERID && i < OMAXNSERVERS;
3072 if ((VlEntry->serverNumber[i] == server)
3073 && (VlEntry->serverPartition[i] == partition))
3081 /* Repsite table compression: used when deleting a repsite entry so that
3082 * all active repsite entries are on the top of the table. */
3084 repsite_compress(struct nvlentry *VlEntry, int offset)
3086 int repsite_offset = offset;
3088 VlEntry->serverNumber[repsite_offset] != BADSERVERID
3089 && repsite_offset < OMAXNSERVERS - 1; repsite_offset++) {
3090 VlEntry->serverNumber[repsite_offset] =
3091 VlEntry->serverNumber[repsite_offset + 1];
3092 VlEntry->serverPartition[repsite_offset] =
3093 VlEntry->serverPartition[repsite_offset + 1];
3094 VlEntry->serverFlags[repsite_offset] =
3095 VlEntry->serverFlags[repsite_offset + 1];
3097 VlEntry->serverNumber[repsite_offset] = BADSERVERID;
3101 /* Convert from the internal (compacted) vldb entry to the external
3102 * representation used by the interface. */
3104 vlentry_to_vldbentry(struct vl_ctx *ctx, struct nvlentry *VlEntry,
3105 struct vldbentry *VldbEntry)
3108 struct extentaddr *exp;
3110 memset(VldbEntry, 0, sizeof(struct vldbentry));
3111 strncpy(VldbEntry->name, VlEntry->name, sizeof(VldbEntry->name));
3112 for (i = 0; i < OMAXNSERVERS; i++) {
3113 if (VlEntry->serverNumber[i] == BADSERVERID)
3115 j = VlEntry->serverNumber[i];
3116 code = multiHomedExtent(ctx, VlEntry->serverNumber[i], &exp);
3120 /* For now return the first ip address back */
3121 for (j = 0; j < VL_MAXIPADDRS_PERMH; j++) {
3122 if (exp->ex_addrs[j]) {
3123 VldbEntry->serverNumber[i] = ntohl(exp->ex_addrs[j]);
3128 VldbEntry->serverNumber[i] =
3129 ctx->hostaddress[VlEntry->serverNumber[i]];
3130 VldbEntry->serverPartition[i] = VlEntry->serverPartition[i];
3131 VldbEntry->serverFlags[i] = VlEntry->serverFlags[i];
3133 VldbEntry->nServers = i;
3134 for (i = 0; i < MAXTYPES; i++)
3135 VldbEntry->volumeId[i] = VlEntry->volumeId[i];
3136 VldbEntry->cloneId = VlEntry->cloneId;
3137 VldbEntry->flags = VlEntry->flags;
3143 /* Convert from the internal (compacted) vldb entry to the external
3144 * representation used by the interface. */
3146 vlentry_to_nvldbentry(struct vl_ctx *ctx, struct nvlentry *VlEntry,
3147 struct nvldbentry *VldbEntry)
3150 struct extentaddr *exp;
3152 memset(VldbEntry, 0, sizeof(struct nvldbentry));
3153 strncpy(VldbEntry->name, VlEntry->name, sizeof(VldbEntry->name));
3154 for (i = 0; i < NMAXNSERVERS; i++) {
3155 if (VlEntry->serverNumber[i] == BADSERVERID)
3157 code = multiHomedExtent(ctx, VlEntry->serverNumber[i], &exp);
3162 /* For now return the first ip address back */
3163 for (j = 0; j < VL_MAXIPADDRS_PERMH; j++) {
3164 if (exp->ex_addrs[j]) {
3165 VldbEntry->serverNumber[i] = ntohl(exp->ex_addrs[j]);
3170 VldbEntry->serverNumber[i] =
3171 ctx->hostaddress[VlEntry->serverNumber[i]];
3172 VldbEntry->serverPartition[i] = VlEntry->serverPartition[i];
3173 VldbEntry->serverFlags[i] = VlEntry->serverFlags[i];
3175 VldbEntry->nServers = i;
3176 for (i = 0; i < MAXTYPES; i++)
3177 VldbEntry->volumeId[i] = VlEntry->volumeId[i];
3178 VldbEntry->cloneId = VlEntry->cloneId;
3179 VldbEntry->flags = VlEntry->flags;
3185 vlentry_to_uvldbentry(struct vl_ctx *ctx, struct nvlentry *VlEntry,
3186 struct uvldbentry *VldbEntry)
3189 struct extentaddr *exp;
3191 memset(VldbEntry, 0, sizeof(struct uvldbentry));
3192 strncpy(VldbEntry->name, VlEntry->name, sizeof(VldbEntry->name));
3193 for (i = 0; i < NMAXNSERVERS; i++) {
3194 if (VlEntry->serverNumber[i] == BADSERVERID)
3196 VldbEntry->serverFlags[i] = VlEntry->serverFlags[i];
3197 VldbEntry->serverUnique[i] = 0;
3198 code = multiHomedExtent(ctx, VlEntry->serverNumber[i], &exp);
3205 tuuid = exp->ex_hostuuid;
3206 afs_ntohuuid(&tuuid);
3207 VldbEntry->serverFlags[i] |= VLSF_UUID;
3208 VldbEntry->serverNumber[i] = tuuid;
3209 VldbEntry->serverUnique[i] = ntohl(exp->ex_uniquifier);
3211 VldbEntry->serverNumber[i].time_low =
3212 ctx->hostaddress[VlEntry->serverNumber[i]];
3214 VldbEntry->serverPartition[i] = VlEntry->serverPartition[i];
3217 VldbEntry->nServers = i;
3218 for (i = 0; i < MAXTYPES; i++)
3219 VldbEntry->volumeId[i] = VlEntry->volumeId[i];
3220 VldbEntry->cloneId = VlEntry->cloneId;
3221 VldbEntry->flags = VlEntry->flags;
3226 #define LEGALCHARS ".ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"
3229 /* Verify that the volname is a valid volume name. */
3231 InvalidVolname(char *volname)
3237 slen = strlen(volname);
3238 if (slen >= VL_MAXNAMELEN)
3240 return (slen != strspn(volname, map));
3244 /* Verify that the given volume type is valid. */
3246 InvalidVoltype(afs_int32 voltype)
3248 if (voltype != RWVOL && voltype != ROVOL && voltype != BACKVOL)
3255 InvalidOperation(afs_int32 voloper)
3257 if (voloper != VLOP_MOVE && voloper != VLOP_RELEASE
3258 && voloper != VLOP_BACKUP && voloper != VLOP_DELETE
3259 && voloper != VLOP_DUMP)
3265 InvalidReleasetype(afs_int32 releasetype)
3267 if ((releasetype & LOCKREL_TIMESTAMP) || (releasetype & LOCKREL_OPCODE)
3268 || (releasetype & LOCKREL_AFSID))
3274 IpAddrToRelAddr(struct vl_ctx *ctx, afs_uint32 ipaddr, int create)
3278 struct extentaddr *exp;
3280 for (i = 0; i <= MAXSERVERID; i++) {
3281 if (ctx->hostaddress[i] == ipaddr)
3283 code = multiHomedExtent(ctx, i, &exp);
3287 for (j = 0; j < VL_MAXIPADDRS_PERMH; j++) {
3288 if (exp->ex_addrs[j] && (ntohl(exp->ex_addrs[j]) == ipaddr)) {
3295 /* allocate the new server a server id pronto */
3297 for (i = 0; i <= MAXSERVERID; i++) {
3298 if (ctx->cheader->IpMappedAddr[i] == 0) {
3299 ctx->cheader->IpMappedAddr[i] = htonl(ipaddr);
3302 DOFFSET(0, ctx->cheader, &ctx->cheader->IpMappedAddr[i]),
3303 (char *)&ctx->cheader->IpMappedAddr[i],
3305 ctx->hostaddress[i] = ipaddr;
3316 ChangeIPAddr(struct vl_ctx *ctx, afs_uint32 ipaddr1, afs_uint32 ipaddr2)
3320 struct extentaddr *exp = NULL;
3324 afs_int32 blockindex, count;
3326 struct nvlentry tentry;
3327 int ipaddr1_id = -1, ipaddr2_id = -1;
3329 /* Don't let addr change to 256.*.*.* : Causes internal error below */
3330 if ((ipaddr2 & 0xff000000) == 0xff000000)
3331 return (VL_BADSERVER);
3333 /* If we are removing an address, ip1 will be -1 and ip2 will be
3334 * the original address. This prevents an older revision vlserver
3335 * from removing the IP address (won't find server 0xfffffff in
3336 * the VLDB). An older revision vlserver does not have the check
3337 * to see if any volumes exist on the server being removed.
3339 if (ipaddr1 == 0xffffffff) {
3344 for (i = 0; i <= MAXSERVERID; i++) {
3345 code = multiHomedExtentBase(ctx, i, &exp, &base);
3350 for (mhidx = 0; mhidx < VL_MAXIPADDRS_PERMH; mhidx++) {
3351 if (!exp->ex_addrs[mhidx])
3353 if (ntohl(exp->ex_addrs[mhidx]) == ipaddr1) {
3356 if (ipaddr2 != 0 && ntohl(exp->ex_addrs[mhidx]) == ipaddr2) {
3361 if (ctx->hostaddress[i] == ipaddr1) {
3365 if (ipaddr2 != 0 && ctx->hostaddress[i] == ipaddr2) {
3370 if (ipaddr1_id >= 0 && (ipaddr2 == 0 || ipaddr2_id >= 0)) {
3371 /* we've either found both IPs already in the VLDB, or we found
3372 * ipaddr1, and we're not going to find ipaddr2 because it's 0 */
3377 if (ipaddr1_id < 0) {
3378 return VL_NOENT; /* not found */
3381 if (ipaddr2_id >= 0 && ipaddr2_id != ipaddr1_id) {
3382 char buf1[16], buf2[16];
3383 VLog(0, ("Cannot change IP address from %s to %s because the latter "
3384 "is in use by server id %d\n",
3385 afs_inet_ntoa_r(htonl(ipaddr1), buf1),
3386 afs_inet_ntoa_r(htonl(ipaddr2), buf2),
3388 return VL_MULTIPADDR;
3391 /* If we are removing a server entry, a volume cannot
3392 * exist on the server. If one does, don't remove the
3393 * server entry: return error "volume entry exists".
3396 for (blockindex = NextEntry(ctx, 0, &tentry, &count); blockindex;
3397 blockindex = NextEntry(ctx, blockindex, &tentry, &count)) {
3398 if (++pollcount > 50) {
3399 #ifndef AFS_PTHREAD_ENV
3404 for (j = 0; j < NMAXNSERVERS; j++) {
3405 if (tentry.serverNumber[j] == BADSERVERID)
3407 if (tentry.serverNumber[j] == ipaddr1_id) {
3414 /* Log a message saying we are changing/removing an IP address */
3416 ("The following IP address is being %s:\n",
3417 (ipaddr2 ? "changed" : "removed")));
3418 VLog(0, (" entry %d: ", i));
3421 for (mhidx = 0; mhidx < VL_MAXIPADDRS_PERMH; mhidx++) {
3422 if (!exp->ex_addrs[mhidx])
3426 PADDR(ntohl(exp->ex_addrs[mhidx]));
3438 /* Change the registered uuuid addresses */
3440 memset(&tuuid, 0, sizeof(afsUUID));
3441 afs_htonuuid(&tuuid);
3442 exp->ex_hostuuid = tuuid;
3445 DOFFSET(ntohl(ctx->ex_addr[0]->ex_contaddrs[base]),
3446 (char *)ctx->ex_addr[base], (char *)exp),
3447 (char *)&tuuid, sizeof(tuuid));
3452 /* Now change the host address entry */
3453 ctx->cheader->IpMappedAddr[ipaddr1_id] = htonl(ipaddr2);
3455 vlwrite(ctx->trans, DOFFSET(0, ctx->cheader, &ctx->cheader->IpMappedAddr[ipaddr1_id]),
3457 &ctx->cheader->IpMappedAddr[ipaddr1_id], sizeof(afs_int32));
3458 ctx->hostaddress[ipaddr1_id] = ipaddr2;
3465 /* see if the vlserver is back yet */
3467 SVL_ProbeServer(struct rx_call *rxcall)