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 restrictedQueryLevel;
34 extern int extent_mod;
35 extern struct afsconf_dir *vldb_confdir;
36 extern struct ubik_dbase *VL_dbase;
38 #define ABORT(c) do { \
48 #define VLDBALLOCLIMIT 10000
49 #define VLDBALLOCINCR 2048
51 static int put_attributeentry(struct vl_ctx *ctx,
52 struct vldbentry **, struct vldbentry **,
53 struct vldbentry **, bulkentries *,
54 struct nvlentry *, afs_int32 *, afs_int32 *);
55 static int put_nattributeentry(struct vl_ctx *ctx,
56 struct nvldbentry **, struct nvldbentry **,
57 struct nvldbentry **, nbulkentries *,
58 struct nvlentry *, afs_int32, afs_int32,
59 afs_int32 *, afs_int32 *);
60 static int RemoveEntry(struct vl_ctx *ctx, afs_int32 entryptr,
61 struct nvlentry *tentry);
62 static void ReleaseEntry(struct nvlentry *tentry, afs_int32 releasetype);
63 static int check_vldbentry(struct vldbentry *aentry);
64 static int check_nvldbentry(struct nvldbentry *aentry);
65 static int vldbentry_to_vlentry(struct vl_ctx *ctx,
66 struct vldbentry *VldbEntry,
67 struct nvlentry *VlEntry);
68 static int nvldbentry_to_vlentry(struct vl_ctx *ctx,
69 struct nvldbentry *VldbEntry,
70 struct nvlentry *VlEntry);
71 static int get_vldbupdateentry(struct vl_ctx *ctx, afs_int32 blockindex,
72 struct VldbUpdateEntry *updateentry,
73 struct nvlentry *VlEntry);
74 static int repsite_exists(struct nvlentry *VlEntry, int server, int partition);
75 static void repsite_compress(struct nvlentry *VlEntry, int offset);
76 static int vlentry_to_vldbentry(struct vl_ctx *ctx,
77 struct nvlentry *VlEntry,
78 struct vldbentry *VldbEntry);
79 static int vlentry_to_nvldbentry(struct vl_ctx *ctx,
80 struct nvlentry *VlEntry,
81 struct nvldbentry *VldbEntry);
82 static int vlentry_to_uvldbentry(struct vl_ctx *ctx,
83 struct nvlentry *VlEntry,
84 struct uvldbentry *VldbEntry);
85 static int InvalidVolname(char *volname);
86 static int InvalidVoltype(afs_int32 voltype);
87 static int InvalidOperation(afs_int32 voloper);
88 static int InvalidReleasetype(afs_int32 releasetype);
89 static int IpAddrToRelAddr(struct vl_ctx *ctx, afs_uint32 ipaddr, int create);
90 static int ChangeIPAddr(struct vl_ctx *ctx, afs_uint32 ipaddr1,
94 countRequest(int opcode)
97 dynamic_statistics.requests[opcode - VL_LOWEST_OPCODE]++;
102 countAbort(int opcode)
105 dynamic_statistics.aborts[opcode - VL_LOWEST_OPCODE]++;
111 multiHomedExtentBase(struct vl_ctx *ctx, int srvidx, struct extentaddr **exp,
120 if ((ctx->hostaddress[srvidx] & 0xff000000) == 0xff000000) {
121 base = (ctx->hostaddress[srvidx] >> 16) & 0xff;
122 index = ctx->hostaddress[srvidx] & 0x0000ffff;
123 if (base >= VL_MAX_ADDREXTBLKS) {
124 VLog(0, ("Internal error: Multihome extent base is too large. "
125 "Base %d index %d\n", base, index));
128 if (index >= VL_MHSRV_PERBLK) {
129 VLog(0, ("Internal error: Multihome extent index is too large. "
130 "Base %d index %d\n", base, index));
133 if (!ctx->ex_addr[base]) {
134 VLog(0, ("Internal error: Multihome extent does not exist. "
140 *exp = &ctx->ex_addr[base][index];
147 multiHomedExtent(struct vl_ctx *ctx, int srvidx, struct extentaddr **exp)
151 return multiHomedExtentBase(ctx, srvidx, exp, &base);
154 #define AFS_RXINFO_LEN 128
156 rxkadInfo(char *str, struct rx_connection *conn, struct in_addr hostAddr)
164 code = rxkad_GetServerInfo(conn, NULL, &exp, tname, tinst, tcell,
167 snprintf(str, AFS_RXINFO_LEN,
168 "%s rxkad:%s%s%s%s%s", inet_ntoa(hostAddr), tname,
169 (tinst[0] == '\0') ? "" : ".",
170 (tinst[0] == '\0') ? "" : tinst,
171 (tcell[0] == '\0') ? "" : "@",
172 (tcell[0] == '\0') ? "" : tcell);
174 snprintf(str, AFS_RXINFO_LEN, "%s noauth", inet_ntoa(hostAddr));
179 rxinfo(char *str, struct rx_call *rxcall)
181 struct rx_connection *conn;
182 struct in_addr hostAddr;
183 rx_securityIndex authClass;
185 conn = rx_ConnectionOf(rxcall);
186 authClass = rx_SecurityClassOf(conn);
187 hostAddr.s_addr = rx_HostOf(rx_PeerOf(conn));
191 return rxkadInfo(str, conn, hostAddr);
196 snprintf(str, AFS_RXINFO_LEN, "%s noauth", inet_ntoa(hostAddr));
201 /* This is called to initialize the database, set the appropriate locks and make sure that the vldb header is valid */
203 Init_VLdbase(struct vl_ctx *ctx,
204 int locktype, /* indicate read or write transaction */
207 int code = 0, pass, wl;
209 for (pass = 1; pass <= 3; pass++) {
210 if (pass == 2) { /* take write lock to rebuild the db */
211 code = ubik_BeginTrans(VL_dbase, UBIK_WRITETRANS, &ctx->trans);
213 } else if (locktype == LOCKREAD) {
215 ubik_BeginTransReadAnyWrite(VL_dbase, UBIK_READTRANS, &ctx->trans);
218 code = ubik_BeginTrans(VL_dbase, UBIK_WRITETRANS, &ctx->trans);
224 code = ubik_SetLock(ctx->trans, 1, 1, locktype);
227 ubik_AbortTrans(ctx->trans);
231 /* check that dbase is initialized and setup cheader */
232 /* 2nd pass we try to rebuild the header */
233 code = CheckInit(ctx->trans, ((pass == 2) ? 1 : 0));
234 if (!code && wl && extent_mod)
235 code = readExtents(ctx->trans); /* Fix the mh extent blocks */
238 ubik_AbortTrans(ctx->trans);
239 /* Only rebuld if the database is empty */
240 /* Exit if can't rebuild */
241 if ((pass == 1) && (code != VL_EMPTY))
245 } else { /* No code */
247 /* The database header was rebuilt; end the write transaction.
248 * This will call vlsynccache() to copy the write header buffers
249 * to the read header buffers, before calling vlsetache().
250 * Do a third pass to re-acquire the original lock, which
251 * may be a read lock. */
252 ubik_EndTrans(ctx->trans);
254 break; /* didn't rebuild and successful - exit */
259 code = vlsetcache(ctx, locktype);
265 /* Create a new vldb entry; both new volume id and name must be unique
266 * (non-existant in vldb).
270 SVL_CreateEntry(struct rx_call *rxcall, struct vldbentry *newentry)
272 int this_op = VLCREATEENTRY;
274 afs_int32 code, blockindex;
275 struct nvlentry tentry;
276 char rxstr[AFS_RXINFO_LEN];
278 countRequest(this_op);
279 if (!afsconf_SuperUser(vldb_confdir, rxcall, NULL)) {
284 /* Do some validity tests on new entry */
285 if ((code = check_vldbentry(newentry))
286 || (code = Init_VLdbase(&ctx, LOCKWRITE, this_op)))
290 ("OCreate Volume %d %s\n", newentry->volumeId[RWVOL],
291 rxinfo(rxstr, rxcall)));
292 if (EntryIDExists(&ctx, newentry->volumeId, MAXTYPES, &code)) {
293 /* at least one of the specified IDs already exists; we fail */
300 /* Is this following check (by volume name) necessary?? */
301 /* If entry already exists, we fail */
302 if (FindByName(&ctx, newentry->name, &tentry, &code)) {
309 blockindex = AllocBlock(&ctx, &tentry);
310 if (blockindex == 0) {
311 code = VL_CREATEFAIL;
315 memset(&tentry, 0, sizeof(struct nvlentry));
316 /* Convert to its internal representation; both in host byte order */
317 if ((code = vldbentry_to_vlentry(&ctx, newentry, &tentry))) {
318 FreeBlock(&ctx, blockindex);
322 /* Actually insert the entry in vldb */
323 code = ThreadVLentry(&ctx, blockindex, &tentry);
325 FreeBlock(&ctx, blockindex);
328 code = ubik_EndTrans(ctx.trans);
334 ubik_AbortTrans(ctx.trans);
337 osi_auditU(rxcall, VLCreateEntryEvent, code, AUD_STR,
338 (newentry ? newentry->name : NULL), AUD_END);
344 SVL_CreateEntryN(struct rx_call *rxcall, struct nvldbentry *newentry)
346 int this_op = VLCREATEENTRYN;
348 afs_int32 code, blockindex;
349 struct nvlentry tentry;
350 char rxstr[AFS_RXINFO_LEN];
352 countRequest(this_op);
353 if (!afsconf_SuperUser(vldb_confdir, rxcall, NULL)) {
358 /* Do some validity tests on new entry */
359 if ((code = check_nvldbentry(newentry))
360 || (code = Init_VLdbase(&ctx, LOCKWRITE, this_op)))
364 ("Create Volume %d %s\n", newentry->volumeId[RWVOL],
365 rxinfo(rxstr, rxcall)));
366 if (EntryIDExists(&ctx, newentry->volumeId, MAXTYPES, &code)) {
367 /* at least one of the specified IDs already exists; we fail */
374 /* Is this following check (by volume name) necessary?? */
375 /* If entry already exists, we fail */
376 if (FindByName(&ctx, newentry->name, &tentry, &code)) {
383 blockindex = AllocBlock(&ctx, &tentry);
384 if (blockindex == 0) {
385 code = VL_CREATEFAIL;
389 memset(&tentry, 0, sizeof(struct nvlentry));
390 /* Convert to its internal representation; both in host byte order */
391 if ((code = nvldbentry_to_vlentry(&ctx, newentry, &tentry))) {
392 FreeBlock(&ctx, blockindex);
396 /* Actually insert the entry in vldb */
397 code = ThreadVLentry(&ctx, blockindex, &tentry);
399 FreeBlock(&ctx, blockindex);
402 code = ubik_EndTrans(ctx.trans);
408 ubik_AbortTrans(ctx.trans);
411 osi_auditU(rxcall, VLCreateEntryEvent, code, AUD_STR,
412 (newentry ? newentry->name : NULL), AUD_END);
418 SVL_ChangeAddr(struct rx_call *rxcall, afs_uint32 ip1, afs_uint32 ip2)
420 int this_op = VLCHANGEADDR;
423 char rxstr[AFS_RXINFO_LEN];
425 countRequest(this_op);
426 if (!afsconf_SuperUser(vldb_confdir, rxcall, NULL)) {
431 if ((code = Init_VLdbase(&ctx, LOCKWRITE, this_op)))
434 VLog(1, ("Change Addr %u -> %u %s\n", ip1, ip2, rxinfo(rxstr, rxcall)));
435 if ((code = ChangeIPAddr(&ctx, ip1, ip2)))
438 code = ubik_EndTrans(ctx.trans);
444 ubik_AbortTrans(ctx.trans);
447 osi_auditU(rxcall, VLChangeAddrEvent, code, AUD_LONG, ip1, AUD_LONG,
452 /* Delete a vldb entry given the volume id. */
454 SVL_DeleteEntry(struct rx_call *rxcall, afs_uint32 volid, afs_int32 voltype)
456 int this_op = VLDELETEENTRY;
458 afs_int32 blockindex, code;
459 struct nvlentry tentry;
460 char rxstr[AFS_RXINFO_LEN];
462 countRequest(this_op);
463 if (!afsconf_SuperUser(vldb_confdir, rxcall, NULL))
466 if ((voltype != -1) && (InvalidVoltype(voltype)))
469 if ((code = Init_VLdbase(&ctx, LOCKWRITE, this_op)))
472 VLog(1, ("Delete Volume %u %s\n", volid, rxinfo(rxstr, rxcall)));
473 blockindex = FindByID(&ctx, volid, voltype, &tentry, &code);
474 if (blockindex == 0) { /* volid not found */
480 if (tentry.flags & VLDELETED) { /* Already deleted; return */
481 ABORT(VL_ENTDELETED);
483 if ((code = RemoveEntry(&ctx, blockindex, &tentry))) {
486 code = (ubik_EndTrans(ctx.trans));
491 ubik_AbortTrans(ctx.trans);
494 osi_auditU(rxcall, VLDeleteEntryEvent, code, AUD_LONG, volid,
500 /* Get a vldb entry given its volume id; make sure it's not a deleted entry. */
502 GetEntryByID(struct rx_call *rxcall,
505 char *aentry, /* entry data copied here */
510 afs_int32 blockindex, code;
511 struct nvlentry tentry;
512 char rxstr[AFS_RXINFO_LEN];
514 countRequest(this_op);
516 if ((voltype != -1) && (InvalidVoltype(voltype)))
517 return VL_BADVOLTYPE;
518 if ((code = Init_VLdbase(&ctx, LOCKREAD, this_op)))
521 VLog(5, ("GetVolumeByID %u (%d) %s\n", volid, new,
522 rxinfo(rxstr, rxcall)));
523 blockindex = FindByID(&ctx, volid, voltype, &tentry, &code);
524 if (blockindex == 0) { /* entry not found */
529 if (tentry.flags & VLDELETED) { /* Entry is deleted! */
530 code = VL_ENTDELETED;
533 /* Convert from the internal to external form */
535 code = vlentry_to_nvldbentry(&ctx, &tentry, (struct nvldbentry *)aentry);
537 code = vlentry_to_uvldbentry(&ctx, &tentry, (struct uvldbentry *)aentry);
539 code = vlentry_to_vldbentry(&ctx, &tentry, (struct vldbentry *)aentry);
544 return (ubik_EndTrans(ctx.trans));
548 ubik_AbortTrans(ctx.trans);
553 SVL_GetEntryByID(struct rx_call *rxcall,
556 vldbentry *aentry) /* entry data copied here */
558 return (GetEntryByID(rxcall, volid, voltype, (char *)aentry, 0,
563 SVL_GetEntryByIDN(struct rx_call *rxcall,
566 nvldbentry *aentry) /* entry data copied here */
568 return (GetEntryByID(rxcall, volid, voltype, (char *)aentry, 1,
573 SVL_GetEntryByIDU(struct rx_call *rxcall,
576 uvldbentry *aentry) /* entry data copied here */
578 return (GetEntryByID(rxcall, volid, voltype, (char *)aentry, 2,
582 /* returns true if the id is a decimal integer, in which case we interpret
583 * it as an id. make the cache manager much simpler */
585 NameIsId(char *aname)
588 while ((tc = *aname++)) {
589 if (tc > '9' || tc < '0')
595 /* Get a vldb entry given the volume's name; of course, very similar to
596 * VLGetEntryByID() above. */
598 GetEntryByName(struct rx_call *rxcall,
600 char *aentry, /* entry data copied here */
605 afs_int32 blockindex, code;
606 struct nvlentry tentry;
607 char rxstr[AFS_RXINFO_LEN];
609 if (NameIsId(volname)) {
610 return GetEntryByID(rxcall, strtoul(volname, NULL, 10), -1, aentry, new, this_op);
612 if (InvalidVolname(volname))
614 if ((code = Init_VLdbase(&ctx, LOCKREAD, this_op)))
616 VLog(5, ("GetVolumeByName %s (%d) %s\n", volname, new, rxinfo(rxstr, rxcall)));
617 blockindex = FindByName(&ctx, volname, &tentry, &code);
618 if (blockindex == 0) { /* entry not found */
623 if (tentry.flags & VLDELETED) { /* Entry is deleted */
624 code = VL_ENTDELETED;
627 /* Convert to external entry representation */
629 code = vlentry_to_nvldbentry(&ctx, &tentry, (struct nvldbentry *)aentry);
631 code = vlentry_to_uvldbentry(&ctx, &tentry, (struct uvldbentry *)aentry);
633 code = vlentry_to_vldbentry(&ctx, &tentry, (struct vldbentry *)aentry);
638 return (ubik_EndTrans(ctx.trans));
642 ubik_AbortTrans(ctx.trans);
648 SVL_GetEntryByNameO(struct rx_call *rxcall,
650 struct vldbentry *aentry) /* entry data copied here */
652 return (GetEntryByName(rxcall, volname, (char *)aentry, 0,
658 SVL_GetEntryByNameN(struct rx_call *rxcall,
660 struct nvldbentry *aentry) /* entry data copied here */
662 return (GetEntryByName(rxcall, volname, (char *)aentry, 1,
667 SVL_GetEntryByNameU(struct rx_call *rxcall,
669 struct uvldbentry *aentry) /* entry data copied here */
671 return (GetEntryByName(rxcall, volname, (char *)aentry, 2,
677 /* Get the current value of the maximum volume id and bump the volume id counter by Maxvolidbump. */
679 SVL_GetNewVolumeId(struct rx_call *rxcall, afs_uint32 Maxvolidbump,
680 afs_uint32 *newvolumeid)
682 int this_op = VLGETNEWVOLUMEID;
684 afs_uint32 maxvolumeid;
686 char rxstr[AFS_RXINFO_LEN];
688 countRequest(this_op);
689 if (!afsconf_SuperUser(vldb_confdir, rxcall, NULL))
692 if (Maxvolidbump > MAXBUMPCOUNT)
693 END(VL_BADVOLIDBUMP);
695 if ((code = Init_VLdbase(&ctx, LOCKWRITE, this_op)))
698 *newvolumeid = maxvolumeid = NextUnusedID(&ctx,
699 ntohl(ctx.cheader->vital_header.MaxVolumeId), Maxvolidbump, &code);
704 maxvolumeid += Maxvolidbump;
705 VLog(1, ("GetNewVolid newmax=%u %s\n", maxvolumeid, rxinfo(rxstr, rxcall)));
706 ctx.cheader->vital_header.MaxVolumeId = htonl(maxvolumeid);
707 if (write_vital_vlheader(&ctx)) {
710 code = (ubik_EndTrans(ctx.trans));
715 ubik_AbortTrans(ctx.trans);
718 osi_auditU(rxcall, VLGetNewVolumeIdEvent, code, AUD_END);
723 /* Simple replace the contents of the vldb entry, volid, with
724 * newentry. No individual checking/updating per field (alike
725 * VLUpdateEntry) is done. */
728 SVL_ReplaceEntry(struct rx_call *rxcall, afs_uint32 volid, afs_int32 voltype,
729 struct vldbentry *newentry, afs_int32 releasetype)
731 int this_op = VLREPLACEENTRY;
733 afs_int32 blockindex, code, typeindex;
735 int hashVol[MAXTYPES];
736 struct nvlentry tentry;
737 afs_uint32 checkids[MAXTYPES];
738 char rxstr[AFS_RXINFO_LEN];
740 countRequest(this_op);
741 for (typeindex = 0; typeindex < MAXTYPES; typeindex++)
742 hashVol[typeindex] = 0;
744 if (!afsconf_SuperUser(vldb_confdir, rxcall, NULL))
747 if ((code = check_vldbentry(newentry)))
750 if (voltype != -1 && InvalidVoltype(voltype))
753 if (releasetype && InvalidReleasetype(releasetype))
754 END(VL_BADRELLOCKTYPE);
755 if ((code = Init_VLdbase(&ctx, LOCKWRITE, this_op)))
758 VLog(1, ("OReplace Volume %u %s\n", volid, rxinfo(rxstr, rxcall)));
759 /* find vlentry we're changing */
760 blockindex = FindByID(&ctx, volid, voltype, &tentry, &code);
761 if (blockindex == 0) { /* entry not found */
767 /* check that we're not trying to change the RW vol ID */
768 if (newentry->volumeId[RWVOL] != tentry.volumeId[RWVOL]) {
772 /* make sure none of the IDs we are changing to are already in use */
773 memset(&checkids, 0, sizeof(checkids));
774 for (typeindex = ROVOL; typeindex < MAXTYPES; typeindex++) {
775 if (tentry.volumeId[typeindex] != newentry->volumeId[typeindex]) {
776 checkids[typeindex] = newentry->volumeId[typeindex];
779 if (EntryIDExists(&ctx, checkids, MAXTYPES, &code)) {
785 /* make sure the name we're changing to doesn't already exist */
786 if (strcmp(newentry->name, tentry.name)) {
787 struct nvlentry tmp_entry;
788 if (FindByName(&ctx, newentry->name, &tmp_entry, &code)) {
795 /* unhash volid entries if they're disappearing or changing.
796 * Remember if we need to hash in the new value (we don't have to
797 * rehash if volid stays same */
798 for (typeindex = ROVOL; typeindex <= BACKVOL; typeindex++) {
799 if (tentry.volumeId[typeindex] != newentry->volumeId[typeindex]) {
800 if (tentry.volumeId[typeindex])
802 UnhashVolid(&ctx, typeindex, blockindex, &tentry))) {
805 /* we must rehash new id if the id is different and the ID is nonzero */
806 hashVol[typeindex] = 1; /* must rehash this guy if he exists */
810 /* Rehash volname if it changes */
811 if (strcmp(newentry->name, tentry.name)) { /* Name changes; redo hashing */
812 if ((code = UnhashVolname(&ctx, blockindex, &tentry))) {
818 /* after this, tentry is new entry, not old one. vldbentry_to_vlentry
819 * doesn't touch hash chains */
820 if ((code = vldbentry_to_vlentry(&ctx, newentry, &tentry))) {
824 for (typeindex = ROVOL; typeindex <= BACKVOL; typeindex++) {
825 if (hashVol[typeindex] && tentry.volumeId[typeindex]) {
826 if ((code = HashVolid(&ctx, typeindex, blockindex, &tentry))) {
833 HashVolname(&ctx, blockindex, &tentry);
836 ReleaseEntry(&tentry, releasetype); /* Unlock entry if necessary */
837 if (vlentrywrite(ctx.trans, blockindex, &tentry, sizeof(tentry))) {
841 END(ubik_EndTrans(ctx.trans));
845 ubik_AbortTrans(ctx.trans);
848 osi_auditU(rxcall, VLReplaceVLEntryEvent, code, AUD_LONG, volid,
854 SVL_ReplaceEntryN(struct rx_call *rxcall, afs_uint32 volid, afs_int32 voltype,
855 struct nvldbentry *newentry, afs_int32 releasetype)
857 int this_op = VLREPLACEENTRYN;
859 afs_int32 blockindex, code, typeindex;
861 int hashVol[MAXTYPES];
862 struct nvlentry tentry;
863 char rxstr[AFS_RXINFO_LEN];
865 countRequest(this_op);
866 for (typeindex = 0; typeindex < MAXTYPES; typeindex++)
867 hashVol[typeindex] = 0;
869 if (!afsconf_SuperUser(vldb_confdir, rxcall, NULL))
872 if ((code = check_nvldbentry(newentry)))
875 if (voltype != -1 && InvalidVoltype(voltype))
878 if (releasetype && InvalidReleasetype(releasetype))
879 END(VL_BADRELLOCKTYPE);
880 if ((code = Init_VLdbase(&ctx, LOCKWRITE, this_op)))
883 VLog(1, ("Replace Volume %u %s\n", volid, rxinfo(rxstr, rxcall)));
884 /* find vlentry we're changing */
885 blockindex = FindByID(&ctx, volid, voltype, &tentry, &code);
886 if (blockindex == 0) { /* entry not found */
892 /* check that we're not trying to change the RW vol ID */
893 if (newentry->volumeId[RWVOL] != tentry.volumeId[RWVOL]) {
897 /* unhash volid entries if they're disappearing or changing.
898 * Remember if we need to hash in the new value (we don't have to
899 * rehash if volid stays same */
900 for (typeindex = ROVOL; typeindex <= BACKVOL; typeindex++) {
901 if (tentry.volumeId[typeindex] != newentry->volumeId[typeindex]) {
902 if (tentry.volumeId[typeindex])
904 UnhashVolid(&ctx, typeindex, blockindex, &tentry))) {
907 /* we must rehash new id if the id is different and the ID is nonzero */
908 hashVol[typeindex] = 1; /* must rehash this guy if he exists */
912 /* Rehash volname if it changes */
913 if (strcmp(newentry->name, tentry.name)) { /* Name changes; redo hashing */
914 if ((code = UnhashVolname(&ctx, blockindex, &tentry))) {
920 /* after this, tentry is new entry, not old one. vldbentry_to_vlentry
921 * doesn't touch hash chains */
922 if ((code = nvldbentry_to_vlentry(&ctx, newentry, &tentry))) {
926 for (typeindex = ROVOL; typeindex <= BACKVOL; typeindex++) {
927 if (hashVol[typeindex] && tentry.volumeId[typeindex]) {
928 if ((code = HashVolid(&ctx, typeindex, blockindex, &tentry))) {
935 HashVolname(&ctx, blockindex, &tentry);
938 ReleaseEntry(&tentry, releasetype); /* Unlock entry if necessary */
939 if (vlentrywrite(ctx.trans, blockindex, &tentry, sizeof(tentry))) {
943 END(ubik_EndTrans(ctx.trans));
947 ubik_AbortTrans(ctx.trans);
950 osi_auditU(rxcall, VLReplaceVLEntryEvent, code, AUD_LONG, volid,
956 /* Update a vldb entry (accessed thru its volume id). Almost all of the
957 * entry's fields can be modified in a single call by setting the
958 * appropriate bits in the Mask field in VldbUpdateentry. */
959 /* this routine may never have been tested; use replace entry instead
960 * unless you're brave */
962 SVL_UpdateEntry(struct rx_call *rxcall,
965 struct VldbUpdateEntry *updateentry, /* Update entry copied here */
966 afs_int32 releasetype)
968 int this_op = VLUPDATEENTRY;
970 afs_int32 blockindex, code;
971 struct nvlentry tentry;
972 char rxstr[AFS_RXINFO_LEN];
974 countRequest(this_op);
975 if (!afsconf_SuperUser(vldb_confdir, rxcall, NULL))
977 if ((voltype != -1) && (InvalidVoltype(voltype)))
979 if (releasetype && InvalidReleasetype(releasetype))
980 END(VL_BADRELLOCKTYPE);
981 if ((code = Init_VLdbase(&ctx, LOCKWRITE, this_op)))
984 VLog(1, ("Update Volume %u %s\n", volid, rxinfo(rxstr, rxcall)));
985 blockindex = FindByID(&ctx, volid, voltype, &tentry, &code);
986 if (blockindex == 0) { /* entry not found */
992 /* Do the actual updating of the entry, tentry. */
994 get_vldbupdateentry(&ctx, blockindex, updateentry, &tentry))) {
998 ReleaseEntry(&tentry, releasetype); /* Unlock entry if necessary */
999 if (vlentrywrite(ctx.trans, blockindex, &tentry, sizeof(tentry))) {
1002 END(ubik_EndTrans(ctx.trans));
1005 countAbort(this_op);
1006 ubik_AbortTrans(ctx.trans);
1009 osi_auditU(rxcall, VLUpdateEntryEvent, code, AUD_LONG, volid,
1016 SVL_UpdateEntryByName(struct rx_call *rxcall,
1018 struct VldbUpdateEntry *updateentry, /* Update entry copied here */
1019 afs_int32 releasetype)
1021 int this_op = VLUPDATEENTRYBYNAME;
1023 afs_int32 blockindex, code;
1024 struct nvlentry tentry;
1026 countRequest(this_op);
1027 if (!afsconf_SuperUser(vldb_confdir, rxcall, NULL))
1029 if (releasetype && InvalidReleasetype(releasetype))
1030 END(VL_BADRELLOCKTYPE);
1031 if ((code = Init_VLdbase(&ctx, LOCKWRITE, this_op)))
1034 blockindex = FindByName(&ctx, volname, &tentry, &code);
1035 if (blockindex == 0) { /* entry not found */
1041 /* Do the actual updating of the entry, tentry. */
1043 get_vldbupdateentry(&ctx, blockindex, updateentry, &tentry))) {
1047 ReleaseEntry(&tentry, releasetype); /* Unlock entry if necessary */
1048 if (vlentrywrite(ctx.trans, blockindex, &tentry, sizeof(tentry))) {
1051 END(ubik_EndTrans(ctx.trans));
1054 countAbort(this_op);
1055 ubik_AbortTrans(ctx.trans);
1058 osi_auditU(rxcall, VLUpdateEntryEvent, code, AUD_LONG, -1, AUD_END);
1063 /* Set a lock to the vldb entry for volid (of type voltype if not -1). */
1065 SVL_SetLock(struct rx_call *rxcall, afs_uint32 volid, afs_int32 voltype,
1068 int this_op = VLSETLOCK;
1069 afs_int32 timestamp, blockindex, code;
1071 struct nvlentry tentry;
1072 char rxstr[AFS_RXINFO_LEN];
1074 countRequest(this_op);
1075 if (!afsconf_SuperUser(vldb_confdir, rxcall, NULL))
1077 if ((voltype != -1) && (InvalidVoltype(voltype)))
1079 if (InvalidOperation(voloper))
1081 if ((code = Init_VLdbase(&ctx, LOCKWRITE, this_op)))
1084 VLog(1, ("SetLock Volume %u %s\n", volid, rxinfo(rxstr, rxcall)));
1085 blockindex = FindByID(&ctx, volid, voltype, &tentry, &code);
1086 if (blockindex == NULLO) {
1091 if (tentry.flags & VLDELETED) {
1092 ABORT(VL_ENTDELETED);
1094 timestamp = FT_ApproxTime();
1096 /* Check if entry is already locked; note that we unlock any entry
1097 * locked more than MAXLOCKTIME seconds */
1098 if ((tentry.LockTimestamp)
1099 && ((timestamp - tentry.LockTimestamp) < MAXLOCKTIME)) {
1100 ABORT(VL_ENTRYLOCKED);
1103 /* Consider it an unlocked entry: set current timestamp, caller
1104 * and active vol operation */
1105 tentry.LockTimestamp = timestamp;
1106 tentry.LockAfsId = 0; /* Not implemented yet */
1107 if (tentry.flags & VLOP_RELEASE) {
1108 ABORT(VL_RERELEASE);
1110 tentry.flags &= ~VLOP_ALLOPERS; /* Clear any possible older operation bit */
1111 tentry.flags |= voloper;
1113 if (vlentrywrite(ctx.trans, blockindex, &tentry, sizeof(tentry))) {
1116 END(ubik_EndTrans(ctx.trans));
1119 countAbort(this_op);
1120 ubik_AbortTrans(ctx.trans);
1123 osi_auditU(rxcall, VLSetLockEvent, code, AUD_LONG, volid, AUD_END);
1128 /* Release an already locked vldb entry. Releasetype determines what
1129 * fields (afsid and/or volume operation) will be cleared along with
1130 * the lock time stamp. */
1133 SVL_ReleaseLock(struct rx_call *rxcall, afs_uint32 volid, afs_int32 voltype,
1134 afs_int32 releasetype)
1136 int this_op = VLRELEASELOCK;
1137 afs_int32 blockindex, code;
1139 struct nvlentry tentry;
1140 char rxstr[AFS_RXINFO_LEN];
1142 countRequest(this_op);
1143 if (!afsconf_SuperUser(vldb_confdir, rxcall, NULL))
1145 if ((voltype != -1) && (InvalidVoltype(voltype)))
1147 if (releasetype && InvalidReleasetype(releasetype))
1148 END(VL_BADRELLOCKTYPE);
1149 if ((code = Init_VLdbase(&ctx, LOCKWRITE, this_op)))
1152 VLog(1, ("ReleaseLock Volume %u %s\n", volid, rxinfo(rxstr, rxcall)));
1153 blockindex = FindByID(&ctx, volid, voltype, &tentry, &code);
1154 if (blockindex == NULLO) {
1159 if (tentry.flags & VLDELETED) {
1160 ABORT(VL_ENTDELETED);
1163 ReleaseEntry(&tentry, releasetype); /* Unlock the appropriate fields */
1164 if (vlentrywrite(ctx.trans, blockindex, &tentry, sizeof(tentry))) {
1167 END(ubik_EndTrans(ctx.trans));
1170 countAbort(this_op);
1171 ubik_AbortTrans(ctx.trans);
1174 osi_auditU(rxcall, VLReleaseLockEvent, code, AUD_LONG, volid,
1180 /* ListEntry returns a single vldb entry, aentry, with offset previous_index;
1181 * the remaining parameters (i.e. next_index) are used so that sequential
1182 * calls to this routine will get the next (all) vldb entries.
1185 SVL_ListEntry(struct rx_call *rxcall, afs_int32 previous_index,
1186 afs_int32 *count, afs_int32 *next_index,
1187 struct vldbentry *aentry)
1189 int this_op = VLLISTENTRY;
1192 struct nvlentry tentry;
1193 char rxstr[AFS_RXINFO_LEN];
1195 countRequest(this_op);
1197 if (!afsconf_CheckRestrictedQuery(vldb_confdir, rxcall,
1198 restrictedQueryLevel))
1201 if ((code = Init_VLdbase(&ctx, LOCKREAD, this_op)))
1203 VLog(25, ("OListEntry index=%d %s\n", previous_index,
1204 rxinfo(rxstr, rxcall)));
1205 *next_index = NextEntry(&ctx, previous_index, &tentry, count);
1207 code = vlentry_to_vldbentry(&ctx, &tentry, aentry);
1209 countAbort(this_op);
1210 ubik_AbortTrans(ctx.trans);
1214 code = ubik_EndTrans(ctx.trans);
1216 osi_auditU(rxcall, VLListEntryEvent, code, AUD_LONG, previous_index, AUD_END);
1220 /* ListEntry returns a single vldb entry, aentry, with offset previous_index;
1221 * the remaining parameters (i.e. next_index) are used so that sequential
1222 * calls to this routine will get the next (all) vldb entries.
1225 SVL_ListEntryN(struct rx_call *rxcall, afs_int32 previous_index,
1226 afs_int32 *count, afs_int32 *next_index,
1227 struct nvldbentry *aentry)
1229 int this_op = VLLISTENTRYN;
1232 struct nvlentry tentry;
1233 char rxstr[AFS_RXINFO_LEN];
1235 countRequest(this_op);
1237 if (!afsconf_CheckRestrictedQuery(vldb_confdir, rxcall,
1238 restrictedQueryLevel))
1241 if ((code = Init_VLdbase(&ctx, LOCKREAD, this_op)))
1243 VLog(25, ("ListEntry index=%d %s\n", previous_index, rxinfo(rxstr, rxcall)));
1244 *next_index = NextEntry(&ctx, previous_index, &tentry, count);
1246 code = vlentry_to_nvldbentry(&ctx, &tentry, aentry);
1248 countAbort(this_op);
1249 ubik_AbortTrans(ctx.trans);
1254 code = ubik_EndTrans(ctx.trans);
1256 osi_auditU(rxcall, VLListEntryEventN, code, AUD_LONG, previous_index, AUD_END);
1261 /* Retrieves in vldbentries all vldb entries that match the specified
1262 * attributes (by server number, partition, volume type, and flag); if volume
1263 * id is specified then the associated list for that entry is returned.
1264 * CAUTION: This could be a very expensive call since in most cases
1265 * sequential search of all vldb entries is performed.
1268 SVL_ListAttributes(struct rx_call *rxcall,
1269 struct VldbListByAttributes *attributes,
1270 afs_int32 *nentries,
1271 bulkentries *vldbentries)
1273 int this_op = VLLISTATTRIBUTES;
1274 int code, allocCount = 0;
1276 struct nvlentry tentry;
1277 struct vldbentry *Vldbentry = 0, *VldbentryFirst = 0, *VldbentryLast = 0;
1279 char rxstr[AFS_RXINFO_LEN];
1281 countRequest(this_op);
1283 if (!afsconf_CheckRestrictedQuery(vldb_confdir, rxcall,
1284 restrictedQueryLevel))
1287 vldbentries->bulkentries_val = 0;
1288 vldbentries->bulkentries_len = *nentries = 0;
1289 if ((code = Init_VLdbase(&ctx, LOCKREAD, this_op)))
1291 allocCount = VLDBALLOCCOUNT;
1292 Vldbentry = VldbentryFirst = vldbentries->bulkentries_val =
1293 malloc(allocCount * sizeof(vldbentry));
1294 if (Vldbentry == NULL) {
1298 VldbentryLast = VldbentryFirst + allocCount;
1299 /* Handle the attribute by volume id totally separate of the rest
1300 * (thus additional Mask values are ignored if VLLIST_VOLUMEID is set!) */
1301 if (attributes->Mask & VLLIST_VOLUMEID) {
1302 afs_int32 blockindex;
1305 FindByID(&ctx, attributes->volumeid, -1, &tentry, &code);
1306 if (blockindex == 0) {
1312 code = put_attributeentry(&ctx, &Vldbentry, &VldbentryFirst,
1313 &VldbentryLast, vldbentries, &tentry,
1314 nentries, &allocCount);
1318 afs_int32 nextblockindex = 0, count = 0, k = 0, match = 0;
1319 while ((nextblockindex =
1320 NextEntry(&ctx, nextblockindex, &tentry, &count))) {
1321 if (++pollcount > 50) {
1322 #ifndef AFS_PTHREAD_ENV
1328 if (attributes->Mask & VLLIST_SERVER) {
1331 IpAddrToRelAddr(&ctx, attributes->server, 0)) == -1)
1333 for (k = 0; k < OMAXNSERVERS; k++) {
1334 if (tentry.serverNumber[k] == BADSERVERID)
1336 if (tentry.serverNumber[k] == serverindex) {
1344 if (attributes->Mask & VLLIST_PARTITION) {
1346 if (tentry.serverPartition[k] != attributes->partition)
1349 for (k = 0; k < OMAXNSERVERS; k++) {
1350 if (tentry.serverNumber[k] == BADSERVERID)
1352 if (tentry.serverPartition[k] ==
1353 attributes->partition) {
1363 if (attributes->Mask & VLLIST_FLAG) {
1364 if (!(tentry.flags & attributes->flag))
1367 code = put_attributeentry(&ctx, &Vldbentry, &VldbentryFirst,
1368 &VldbentryLast, vldbentries, &tentry,
1369 nentries, &allocCount);
1374 if (vldbentries->bulkentries_len
1375 && (allocCount > vldbentries->bulkentries_len)) {
1377 vldbentries->bulkentries_val =
1378 realloc(vldbentries->bulkentries_val,
1379 vldbentries->bulkentries_len * sizeof(vldbentry));
1380 if (vldbentries->bulkentries_val == NULL) {
1386 ("ListAttrs nentries=%d %s\n", vldbentries->bulkentries_len,
1387 rxinfo(rxstr, rxcall)));
1388 code = ubik_EndTrans(ctx.trans);
1390 osi_auditU(rxcall, VLListAttributesEvent, code, AUD_END);
1394 if (vldbentries->bulkentries_val)
1395 free(vldbentries->bulkentries_val);
1396 vldbentries->bulkentries_val = 0;
1397 vldbentries->bulkentries_len = 0;
1399 countAbort(this_op);
1400 ubik_AbortTrans(ctx.trans);
1406 SVL_ListAttributesN(struct rx_call *rxcall,
1407 struct VldbListByAttributes *attributes,
1408 afs_int32 *nentries,
1409 nbulkentries *vldbentries)
1411 int this_op = VLLISTATTRIBUTESN;
1412 int code, allocCount = 0;
1414 struct nvlentry tentry;
1415 struct nvldbentry *Vldbentry = 0, *VldbentryFirst = 0, *VldbentryLast = 0;
1417 char rxstr[AFS_RXINFO_LEN];
1419 countRequest(this_op);
1421 if (!afsconf_CheckRestrictedQuery(vldb_confdir, rxcall,
1422 restrictedQueryLevel))
1425 vldbentries->nbulkentries_val = 0;
1426 vldbentries->nbulkentries_len = *nentries = 0;
1427 if ((code = Init_VLdbase(&ctx, LOCKREAD, this_op)))
1429 allocCount = VLDBALLOCCOUNT;
1430 Vldbentry = VldbentryFirst = vldbentries->nbulkentries_val =
1431 malloc(allocCount * sizeof(nvldbentry));
1432 if (Vldbentry == NULL) {
1436 VldbentryLast = VldbentryFirst + allocCount;
1437 /* Handle the attribute by volume id totally separate of the rest
1438 * (thus additional Mask values are ignored if VLLIST_VOLUMEID is set!) */
1439 if (attributes->Mask & VLLIST_VOLUMEID) {
1440 afs_int32 blockindex;
1443 FindByID(&ctx, attributes->volumeid, -1, &tentry, &code);
1444 if (blockindex == 0) {
1450 code = put_nattributeentry(&ctx, &Vldbentry, &VldbentryFirst,
1451 &VldbentryLast, vldbentries, &tentry,
1452 0, 0, nentries, &allocCount);
1456 afs_int32 nextblockindex = 0, count = 0, k = 0, match = 0;
1457 while ((nextblockindex =
1458 NextEntry(&ctx, nextblockindex, &tentry, &count))) {
1459 if (++pollcount > 50) {
1460 #ifndef AFS_PTHREAD_ENV
1467 if (attributes->Mask & VLLIST_SERVER) {
1470 IpAddrToRelAddr(&ctx, attributes->server, 0)) == -1)
1472 for (k = 0; k < NMAXNSERVERS; k++) {
1473 if (tentry.serverNumber[k] == BADSERVERID)
1475 if (tentry.serverNumber[k] == serverindex) {
1483 if (attributes->Mask & VLLIST_PARTITION) {
1485 if (tentry.serverPartition[k] != attributes->partition)
1488 for (k = 0; k < NMAXNSERVERS; k++) {
1489 if (tentry.serverNumber[k] == BADSERVERID)
1491 if (tentry.serverPartition[k] ==
1492 attributes->partition) {
1502 if (attributes->Mask & VLLIST_FLAG) {
1503 if (!(tentry.flags & attributes->flag))
1506 code = put_nattributeentry(&ctx, &Vldbentry, &VldbentryFirst,
1507 &VldbentryLast, vldbentries,
1508 &tentry, 0, 0, nentries, &allocCount);
1513 if (vldbentries->nbulkentries_len
1514 && (allocCount > vldbentries->nbulkentries_len)) {
1516 vldbentries->nbulkentries_val =
1517 realloc(vldbentries->nbulkentries_val,
1518 vldbentries->nbulkentries_len * sizeof(nvldbentry));
1519 if (vldbentries->nbulkentries_val == NULL) {
1525 ("NListAttrs nentries=%d %s\n", vldbentries->nbulkentries_len,
1526 rxinfo(rxstr, rxcall)));
1527 code = ubik_EndTrans(ctx.trans);
1529 osi_auditU(rxcall, VLListAttributesNEvent, code, AUD_END);
1533 countAbort(this_op);
1534 ubik_AbortTrans(ctx.trans);
1535 if (vldbentries->nbulkentries_val)
1536 free(vldbentries->nbulkentries_val);
1537 vldbentries->nbulkentries_val = 0;
1538 vldbentries->nbulkentries_len = 0;
1544 SVL_ListAttributesN2(struct rx_call *rxcall,
1545 struct VldbListByAttributes *attributes,
1546 char *name, /* Wildcarded volume name */
1547 afs_int32 startindex,
1548 afs_int32 *nentries,
1549 nbulkentries *vldbentries,
1550 afs_int32 *nextstartindex)
1552 int this_op = VLLISTATTRIBUTESN2;
1553 int code = 0, maxCount = VLDBALLOCCOUNT;
1555 struct nvlentry tentry;
1556 struct nvldbentry *Vldbentry = 0, *VldbentryFirst = 0, *VldbentryLast = 0;
1557 afs_int32 blockindex = 0, count = 0, k, match;
1558 afs_int32 matchindex = 0;
1559 int serverindex = -1; /* no server found */
1560 int findserver = 0, findpartition = 0, findflag = 0, findname = 0;
1562 int namematchRWBK, namematchRO, thismatch;
1564 char volumename[VL_MAXNAMELEN+2]; /* regex anchors */
1565 char rxstr[AFS_RXINFO_LEN];
1566 #ifdef HAVE_POSIX_REGEX
1568 int need_regfree = 0;
1573 countRequest(this_op);
1575 if (!afsconf_CheckRestrictedQuery(vldb_confdir, rxcall,
1576 restrictedQueryLevel))
1579 vldbentries->nbulkentries_val = 0;
1580 vldbentries->nbulkentries_len = 0;
1582 *nextstartindex = -1;
1584 code = Init_VLdbase(&ctx, LOCKREAD, this_op);
1588 Vldbentry = VldbentryFirst = vldbentries->nbulkentries_val =
1589 malloc(maxCount * sizeof(nvldbentry));
1590 if (Vldbentry == NULL) {
1591 countAbort(this_op);
1592 ubik_AbortTrans(ctx.trans);
1597 VldbentryLast = VldbentryFirst + maxCount;
1599 /* Handle the attribute by volume id totally separate of the rest
1600 * (thus additional Mask values are ignored if VLLIST_VOLUMEID is set!)
1602 if (attributes->Mask & VLLIST_VOLUMEID) {
1604 FindByID(&ctx, attributes->volumeid, -1, &tentry, &code);
1605 if (blockindex == 0) {
1610 put_nattributeentry(&ctx, &Vldbentry, &VldbentryFirst,
1611 &VldbentryLast, vldbentries, &tentry, 0,
1612 0, nentries, &maxCount);
1618 /* Search each entry in the database and return all entries
1619 * that match the request. It checks volumename (with
1620 * wildcarding), entry flags, server, and partition.
1623 /* Get the server index for matching server address */
1624 if (attributes->Mask & VLLIST_SERVER) {
1626 IpAddrToRelAddr(&ctx, attributes->server, 0);
1627 if (serverindex == -1)
1631 findpartition = ((attributes->Mask & VLLIST_PARTITION) ? 1 : 0);
1632 findflag = ((attributes->Mask & VLLIST_FLAG) ? 1 : 0);
1633 if (name && (strcmp(name, ".*") != 0) && (strcmp(name, "") != 0)) {
1634 sprintf(volumename, "^%s$", name);
1635 #ifdef HAVE_POSIX_REGEX
1636 if (regcomp(&re, volumename, REG_NOSUB) != 0) {
1642 t = (char *)re_comp(volumename);
1651 /* Read each entry and see if it is the one we want */
1652 blockindex = startindex;
1653 while ((blockindex = NextEntry(&ctx, blockindex, &tentry, &count))) {
1654 if (++pollcount > 50) {
1655 #ifndef AFS_PTHREAD_ENV
1661 /* Step through each server index searching for a match.
1662 * Match to an existing RW, BK, or RO volume name (preference
1663 * is in this order). Remember which index we matched against.
1665 namematchRWBK = namematchRO = 0; /* 0->notTried; 1->match; 2->noMatch */
1669 && (tentry.serverNumber[k] != BADSERVERID)); k++) {
1670 thismatch = 0; /* does this index match */
1672 /* Match against the RW or BK volume name. Remember
1673 * results in namematchRWBK. Prefer RW over BK.
1675 if (tentry.serverFlags[k] & VLSF_RWVOL) {
1676 /* Does the name match the RW name */
1677 if (tentry.flags & VLF_RWEXISTS) {
1679 sprintf(volumename, "%s", tentry.name);
1680 #ifdef HAVE_POSIX_REGEX
1681 if (regexec(&re, volumename, 0, NULL, 0) == 0) {
1682 thismatch = VLSF_RWVOL;
1685 if (re_exec(volumename)) {
1686 thismatch = VLSF_RWVOL;
1690 thismatch = VLSF_RWVOL;
1694 /* Does the name match the BK name */
1695 if (!thismatch && (tentry.flags & VLF_BACKEXISTS)) {
1697 sprintf(volumename, "%s.backup", tentry.name);
1698 #ifdef HAVE_POSIX_REGEX
1699 if (regexec(&re, volumename, 0, NULL, 0) == 0) {
1700 thismatch = VLSF_BACKVOL;
1703 if (re_exec(volumename)) {
1704 thismatch = VLSF_BACKVOL;
1708 thismatch = VLSF_BACKVOL;
1712 namematchRWBK = (thismatch ? 1 : 2);
1715 /* Match with the RO volume name. Compare once and
1716 * remember results in namematchRO. Note that this will
1717 * pick up entries marked NEWREPSITEs and DONTUSE.
1720 if (tentry.flags & VLF_ROEXISTS) {
1724 ((namematchRO == 1) ? VLSF_ROVOL : 0);
1726 sprintf(volumename, "%s.readonly",
1728 #ifdef HAVE_POSIX_REGEX
1729 if (regexec(&re, volumename, 0, NULL, 0) == 0) {
1730 thismatch = VLSF_ROVOL;
1733 if (re_exec(volumename))
1734 thismatch = VLSF_ROVOL;
1738 thismatch = VLSF_ROVOL;
1741 namematchRO = (thismatch ? 1 : 2);
1744 /* Is there a server match */
1745 if (thismatch && findserver
1746 && (tentry.serverNumber[k] != serverindex))
1749 /* Is there a partition match */
1750 if (thismatch && findpartition
1751 && (tentry.serverPartition[k] != attributes->partition))
1754 /* Is there a flag match */
1755 if (thismatch && findflag
1756 && !(tentry.flags & attributes->flag))
1759 /* We found a match. Remember the index, and type */
1763 matchtype = thismatch;
1766 /* Since we prefer RW and BK volume matches over RO matches,
1767 * if we have already checked the RWBK name, then we already
1768 * found the best match and so end the search.
1770 * If we tried matching against the RW, BK, and RO volume names
1771 * and both failed, then we end the search (none will match).
1773 if ((match && namematchRWBK)
1774 || ((namematchRWBK == 2) && (namematchRO == 2)))
1778 /* Passed all the tests. Take it */
1781 put_nattributeentry(&ctx, &Vldbentry, &VldbentryFirst,
1782 &VldbentryLast, vldbentries, &tentry,
1783 matchtype, matchindex, nentries,
1788 if (*nentries >= maxCount)
1789 break; /* collected the max */
1792 *nextstartindex = (blockindex ? blockindex : -1);
1796 #ifdef HAVE_POSIX_REGEX
1802 countAbort(this_op);
1803 ubik_AbortTrans(ctx.trans);
1804 if (vldbentries->nbulkentries_val)
1805 free(vldbentries->nbulkentries_val);
1806 vldbentries->nbulkentries_val = 0;
1807 vldbentries->nbulkentries_len = 0;
1808 *nextstartindex = -1;
1811 ("N2ListAttrs nentries=%d %s\n", vldbentries->nbulkentries_len,
1812 rxinfo(rxstr, rxcall)));
1813 code = ubik_EndTrans(ctx.trans);
1817 osi_auditU(rxcall, VLListAttributesN2Event, code, AUD_END);
1822 /* Retrieves in vldbentries all vldb entries that match the specified
1823 * attributes (by server number, partition, volume type, and flag); if
1824 * volume id is specified then the associated list for that entry is
1825 * returned. CAUTION: This could be a very expensive call since in most
1826 * cases sequential search of all vldb entries is performed.
1829 SVL_LinkedList(struct rx_call *rxcall,
1830 struct VldbListByAttributes *attributes,
1831 afs_int32 *nentries,
1832 vldb_list *vldbentries)
1834 int this_op = VLLINKEDLIST;
1837 struct nvlentry tentry;
1838 vldblist vllist, *vllistptr;
1839 afs_int32 blockindex, count, match;
1844 countRequest(this_op);
1846 if (!afsconf_CheckRestrictedQuery(vldb_confdir, rxcall,
1847 restrictedQueryLevel))
1850 if ((code = Init_VLdbase(&ctx, LOCKREAD, this_op)))
1854 vldbentries->node = NULL;
1855 vllistptr = &vldbentries->node;
1857 /* List by volumeid */
1858 if (attributes->Mask & VLLIST_VOLUMEID) {
1860 FindByID(&ctx, attributes->volumeid, -1, &tentry, &code);
1867 vllist = malloc(sizeof(single_vldbentry));
1868 if (vllist == NULL) {
1872 code = vlentry_to_vldbentry(&ctx, &tentry, &vllist->VldbEntry);
1876 vllist->next_vldb = NULL;
1878 *vllistptr = vllist; /* Thread onto list */
1879 vllistptr = &vllist->next_vldb;
1883 /* Search by server, partition, and flags */
1885 for (blockindex = NextEntry(&ctx, 0, &tentry, &count); blockindex;
1886 blockindex = NextEntry(&ctx, blockindex, &tentry, &count)) {
1889 if (++pollcount > 50) {
1890 #ifndef AFS_PTHREAD_ENV
1896 /* Does this volume exist on the desired server */
1897 if (attributes->Mask & VLLIST_SERVER) {
1899 IpAddrToRelAddr(&ctx, attributes->server, 0);
1900 if (serverindex == -1)
1902 for (k = 0; k < OMAXNSERVERS; k++) {
1903 if (tentry.serverNumber[k] == BADSERVERID)
1905 if (tentry.serverNumber[k] == serverindex) {
1914 /* Does this volume exist on the desired partition */
1915 if (attributes->Mask & VLLIST_PARTITION) {
1917 if (tentry.serverPartition[k] != attributes->partition)
1920 for (k = 0; k < OMAXNSERVERS; k++) {
1921 if (tentry.serverNumber[k] == BADSERVERID)
1923 if (tentry.serverPartition[k] ==
1924 attributes->partition) {
1934 /* Does this volume have the desired flags */
1935 if (attributes->Mask & VLLIST_FLAG) {
1936 if (!(tentry.flags & attributes->flag))
1940 vllist = malloc(sizeof(single_vldbentry));
1941 if (vllist == NULL) {
1945 code = vlentry_to_vldbentry(&ctx, &tentry, &vllist->VldbEntry);
1949 vllist->next_vldb = NULL;
1951 *vllistptr = vllist; /* Thread onto list */
1952 vllistptr = &vllist->next_vldb;
1954 if (smallMem && (*nentries >= VLDBALLOCCOUNT)) {
1955 code = VL_SIZEEXCEEDED;
1961 code = ubik_EndTrans(ctx.trans);
1963 osi_auditU(rxcall, VLLinkedListEvent, code, AUD_END);
1967 countAbort(this_op);
1968 ubik_AbortTrans(ctx.trans);
1973 SVL_LinkedListN(struct rx_call *rxcall,
1974 struct VldbListByAttributes *attributes,
1975 afs_int32 *nentries,
1976 nvldb_list *vldbentries)
1978 int this_op = VLLINKEDLISTN;
1981 struct nvlentry tentry;
1982 nvldblist vllist, *vllistptr;
1983 afs_int32 blockindex, count, match;
1988 countRequest(this_op);
1990 if (!afsconf_CheckRestrictedQuery(vldb_confdir, rxcall,
1991 restrictedQueryLevel))
1994 if ((code = Init_VLdbase(&ctx, LOCKREAD, this_op)))
1998 vldbentries->node = NULL;
1999 vllistptr = &vldbentries->node;
2001 /* List by volumeid */
2002 if (attributes->Mask & VLLIST_VOLUMEID) {
2004 FindByID(&ctx, attributes->volumeid, -1, &tentry, &code);
2011 vllist = malloc(sizeof(single_nvldbentry));
2012 if (vllist == NULL) {
2016 code = vlentry_to_nvldbentry(&ctx, &tentry, &vllist->VldbEntry);
2020 vllist->next_vldb = NULL;
2022 *vllistptr = vllist; /* Thread onto list */
2023 vllistptr = &vllist->next_vldb;
2027 /* Search by server, partition, and flags */
2029 for (blockindex = NextEntry(&ctx, 0, &tentry, &count); blockindex;
2030 blockindex = NextEntry(&ctx, blockindex, &tentry, &count)) {
2033 if (++pollcount > 50) {
2034 #ifndef AFS_PTHREAD_ENV
2040 /* Does this volume exist on the desired server */
2041 if (attributes->Mask & VLLIST_SERVER) {
2043 IpAddrToRelAddr(&ctx, attributes->server, 0);
2044 if (serverindex == -1)
2046 for (k = 0; k < NMAXNSERVERS; k++) {
2047 if (tentry.serverNumber[k] == BADSERVERID)
2049 if (tentry.serverNumber[k] == serverindex) {
2058 /* Does this volume exist on the desired partition */
2059 if (attributes->Mask & VLLIST_PARTITION) {
2061 if (tentry.serverPartition[k] != attributes->partition)
2064 for (k = 0; k < NMAXNSERVERS; k++) {
2065 if (tentry.serverNumber[k] == BADSERVERID)
2067 if (tentry.serverPartition[k] ==
2068 attributes->partition) {
2078 /* Does this volume have the desired flags */
2079 if (attributes->Mask & VLLIST_FLAG) {
2080 if (!(tentry.flags & attributes->flag))
2084 vllist = malloc(sizeof(single_nvldbentry));
2085 if (vllist == NULL) {
2089 code = vlentry_to_nvldbentry(&ctx, &tentry, &vllist->VldbEntry);
2093 vllist->next_vldb = NULL;
2095 *vllistptr = vllist; /* Thread onto list */
2096 vllistptr = &vllist->next_vldb;
2098 if (smallMem && (*nentries >= VLDBALLOCCOUNT)) {
2099 code = VL_SIZEEXCEEDED;
2105 code = ubik_EndTrans(ctx.trans);
2107 osi_auditU(rxcall, VLLinkedListNEvent, code, AUD_END);
2111 countAbort(this_op);
2112 ubik_AbortTrans(ctx.trans);
2116 /* Get back vldb header statistics (allocs, frees, maxvolumeid,
2117 * totalentries, etc) and dynamic statistics (number of requests and/or
2118 * aborts per remote procedure call, etc)
2121 SVL_GetStats(struct rx_call *rxcall,
2123 vital_vlheader *vital_header)
2125 int this_op = VLGETSTATS;
2128 char rxstr[AFS_RXINFO_LEN];
2130 countRequest(this_op);
2132 if (!afsconf_CheckRestrictedQuery(vldb_confdir, rxcall,
2133 restrictedQueryLevel))
2136 if ((code = Init_VLdbase(&ctx, LOCKREAD, this_op)))
2138 VLog(5, ("GetStats %s\n", rxinfo(rxstr, rxcall)));
2139 memcpy((char *)vital_header, (char *)&ctx.cheader->vital_header,
2140 sizeof(vital_vlheader));
2141 memcpy((char *)stats, (char *)&dynamic_statistics, sizeof(vldstats));
2142 code = ubik_EndTrans(ctx.trans);
2144 osi_auditU(rxcall, VLGetStatsEvent, code, AUD_END);
2148 /* Get the list of file server addresses from the VLDB. Currently it's pretty
2149 * easy to do. In the future, it might require a little bit of grunging
2150 * through the VLDB, but that's life.
2153 SVL_GetAddrs(struct rx_call *rxcall,
2156 struct VLCallBack *spare3,
2157 afs_int32 *nentries,
2160 int this_op = VLGETADDRS;
2166 countRequest(this_op);
2167 addrsp->bulkaddrs_len = *nentries = 0;
2168 addrsp->bulkaddrs_val = 0;
2169 memset(spare3, 0, sizeof(struct VLCallBack));
2171 if ((code = Init_VLdbase(&ctx, LOCKREAD, this_op)))
2174 VLog(5, ("GetAddrs\n"));
2175 addrsp->bulkaddrs_val = taddrp =
2176 malloc(sizeof(afs_uint32) * (MAXSERVERID + 1));
2177 nservers = *nentries = addrsp->bulkaddrs_len = 0;
2184 for (i = 0; i <= MAXSERVERID; i++) {
2185 if ((*taddrp = ntohl(ctx.cheader->IpMappedAddr[i]))) {
2191 addrsp->bulkaddrs_len = *nentries = nservers;
2192 return (ubik_EndTrans(ctx.trans));
2195 countAbort(this_op);
2196 ubik_AbortTrans(ctx.trans);
2201 append_addr(char *buffer, afs_uint32 addr, size_t buffer_size)
2203 int n = strlen(buffer);
2204 if (buffer_size > n) {
2205 snprintf(buffer + n, buffer_size - n, "%u.%u.%u.%u",
2206 (addr >> 24) & 0xff, (addr >> 16) & 0xff, (addr >> 8) & 0xff,
2212 SVL_RegisterAddrs(struct rx_call *rxcall, afsUUID *uuidp, afs_int32 spare1,
2215 int this_op = VLREGADDR;
2218 int cnt, h, i, j, k, m;
2219 struct extentaddr *exp = 0, *tex;
2222 afs_uint32 addrs[VL_MAXIPADDRS_PERMH];
2224 int count, willChangeEntry, foundUuidEntry, willReplaceCnt;
2225 int WillReplaceEntry, WillChange[MAXSERVERID + 1];
2227 int ReplaceEntry = 0;
2230 countRequest(this_op);
2231 if (!afsconf_SuperUser(vldb_confdir, rxcall, NULL))
2233 if ((code = Init_VLdbase(&ctx, LOCKWRITE, this_op)))
2236 /* Eliminate duplicates from IP address list */
2237 for (k = 0, cnt = 0; k < addrsp->bulkaddrs_len; k++) {
2238 if (addrsp->bulkaddrs_val[k] == 0)
2240 for (m = 0; m < cnt; m++) {
2241 if (addrs[m] == addrsp->bulkaddrs_val[k])
2245 if (m == VL_MAXIPADDRS_PERMH) {
2247 ("Number of addresses exceeds %d. Cannot register IP addr 0x%x in VLDB\n",
2248 VL_MAXIPADDRS_PERMH, addrsp->bulkaddrs_val[k]));
2250 addrs[m] = addrsp->bulkaddrs_val[k];
2256 code = VL_INDEXERANGE;
2263 /* For each server registered within the VLDB */
2264 for (srvidx = 0; srvidx <= MAXSERVERID; srvidx++) {
2265 willChangeEntry = 0;
2266 WillReplaceEntry = 1;
2267 code = multiHomedExtent(&ctx, srvidx, &exp);
2272 /* See if the addresses to register will change this server entry */
2273 tuuid = exp->ex_hostuuid;
2274 afs_ntohuuid(&tuuid);
2275 if (afs_uuid_equal(uuidp, &tuuid)) {
2279 for (mhidx = 0; mhidx < VL_MAXIPADDRS_PERMH; mhidx++) {
2280 if (!exp->ex_addrs[mhidx])
2282 for (k = 0; k < cnt; k++) {
2283 if (ntohl(exp->ex_addrs[mhidx]) == addrs[k]) {
2284 willChangeEntry = 1;
2285 WillChange[count] = srvidx;
2290 WillReplaceEntry = 0;
2294 /* The server is not registered as a multihomed.
2295 * See if the addresses to register will replace this server entry.
2297 for (k = 0; k < cnt; k++) {
2298 if (ctx.hostaddress[srvidx] == addrs[k]) {
2299 willChangeEntry = 1;
2300 WillChange[count] = srvidx;
2301 WillReplaceEntry = 1;
2306 if (willChangeEntry) {
2307 if (WillReplaceEntry) {
2309 ReplaceEntry = srvidx;
2315 /* If we found the uuid in the VLDB and if we are replacing another
2316 * entire entry, then complain and fail. Also, if we did not find
2317 * the uuid in the VLDB and the IP addresses being registered was
2318 * found in more than one other entry, then we don't know which one
2319 * to replace and will complain and fail.
2321 if ((foundUuidEntry && (willReplaceCnt > 0))
2322 || (!foundUuidEntry && (count > 1))) {
2324 ("The following fileserver is being registered in the VLDB:\n"));
2325 for (addrbuf[0] = '\0', k = 0; k < cnt; k++) {
2327 strlcat(addrbuf, " ", sizeof(addrbuf));
2328 append_addr(addrbuf, addrs[k], sizeof(addrbuf));
2330 VLog(0, (" [%s]\n", addrbuf));
2332 if (foundUuidEntry) {
2333 code = multiHomedExtent(&ctx, FoundUuid, &exp);
2335 VLog(0, (" It would have replaced the existing VLDB server "
2337 for (addrbuf[0] = '\0', mhidx = 0; mhidx < VL_MAXIPADDRS_PERMH; mhidx++) {
2338 if (!exp->ex_addrs[mhidx])
2341 strlcat(addrbuf, " ", sizeof(addrbuf));
2342 append_addr(addrbuf, ntohl(exp->ex_addrs[mhidx]), sizeof(addrbuf));
2344 VLog(0, (" entry %d: [%s]\n", FoundUuid, addrbuf));
2349 VLog(0, (" Yet another VLDB server entry exists:\n"));
2351 VLog(0, (" Yet other VLDB server entries exist:\n"));
2352 for (j = 0; j < count; j++) {
2353 srvidx = WillChange[j];
2354 VLog(0, (" entry %d: ", srvidx));
2356 code = multiHomedExtent(&ctx, srvidx, &exp);
2362 for (mhidx = 0; mhidx < VL_MAXIPADDRS_PERMH; mhidx++) {
2363 if (!exp->ex_addrs[mhidx])
2366 strlcat(addrbuf, " ", sizeof(addrbuf));
2367 append_addr(addrbuf, ntohl(exp->ex_addrs[mhidx]), sizeof(addrbuf));
2370 append_addr(addrbuf, ctx.hostaddress[srvidx], sizeof(addrbuf));
2372 VLog(0, (" entry %d: [%s]\n", srvidx, addrbuf));
2376 VLog(0, (" You must 'vos changeaddr' this other server entry\n"));
2379 (" You must 'vos changeaddr' these other server entries\n"));
2382 (" and/or remove the sysid file from the registering fileserver\n"));
2383 VLog(0, (" before the fileserver can be registered in the VLDB.\n"));
2385 code = VL_MULTIPADDR;
2389 /* Passed the checks. Now find and update the existing mh entry, or create
2392 if (foundUuidEntry) {
2393 /* Found the entry with same uuid. See if we need to change it */
2396 code = multiHomedExtentBase(&ctx, FoundUuid, &exp, &base);
2400 /* Determine if the entry has changed */
2401 for (k = 0; ((k < cnt) && !change); k++) {
2402 if (ntohl(exp->ex_addrs[k]) != addrs[k])
2405 for (; ((k < VL_MAXIPADDRS_PERMH) && !change); k++) {
2406 if (exp->ex_addrs[k] != 0)
2410 return (ubik_EndTrans(ctx.trans));
2414 VLog(0, ("The following fileserver is being registered in the VLDB:\n"));
2415 for (addrbuf[0] = '\0', k = 0; k < cnt; k++) {
2417 strlcat(addrbuf, " ", sizeof(addrbuf));
2418 append_addr(addrbuf, addrs[k], sizeof(addrbuf));
2420 VLog(0, (" [%s]\n", addrbuf));
2422 if (foundUuidEntry) {
2424 (" It will replace the following existing entry in the VLDB (same uuid):\n"));
2425 for (addrbuf[0] = '\0', k = 0; k < VL_MAXIPADDRS_PERMH; k++) {
2426 if (exp->ex_addrs[k] == 0)
2429 strlcat(addrbuf, " ", sizeof(addrbuf));
2430 append_addr(addrbuf, ntohl(exp->ex_addrs[k]), sizeof(addrbuf));
2432 VLog(0, (" entry %d: [%s]\n", FoundUuid, addrbuf));
2433 } else if (willReplaceCnt || (count == 1)) {
2434 /* If we are not replacing an entry and there is only one entry to change,
2435 * then we will replace that entry.
2437 if (!willReplaceCnt) {
2438 ReplaceEntry = WillChange[0];
2442 /* Have an entry that needs to be replaced */
2443 code = multiHomedExtentBase(&ctx, ReplaceEntry, &exp, &base);
2449 (" It will replace the following existing entry in the VLDB (new uuid):\n"));
2450 for (addrbuf[0] = '\0', k = 0; k < VL_MAXIPADDRS_PERMH; k++) {
2451 if (exp->ex_addrs[k] == 0)
2454 strlcat(addrbuf, " ", sizeof(addrbuf));
2455 append_addr(addrbuf, ntohl(exp->ex_addrs[k]), sizeof(addrbuf));
2457 VLog(0, (" entry %d: [%s]\n", ReplaceEntry, addrbuf));
2459 /* Not a mh entry. So we have to create a new mh entry and
2460 * put it on the ReplaceEntry slot of the ctx.hostaddress array.
2463 append_addr(addrbuf, ctx.hostaddress[ReplaceEntry], sizeof(addrbuf));
2464 VLog(0, (" It will replace existing entry %d, %s,"
2465 " in the VLDB (new uuid):\n", ReplaceEntry, addrbuf));
2467 FindExtentBlock(&ctx, uuidp, 1, ReplaceEntry, &exp, &base);
2475 /* There is no entry for this server, must create a new mh entry as
2476 * well as use a new slot of the ctx.hostaddress array.
2478 VLog(0, (" It will create a new entry in the VLDB.\n"));
2479 code = FindExtentBlock(&ctx, uuidp, 1, -1, &exp, &base);
2487 /* Now we have a mh entry to fill in. Update the uuid, bump the
2488 * uniquifier, and fill in its IP addresses.
2491 afs_htonuuid(&tuuid);
2492 exp->ex_hostuuid = tuuid;
2493 exp->ex_uniquifier = htonl(ntohl(exp->ex_uniquifier) + 1);
2494 for (k = 0; k < cnt; k++) {
2495 exp->ex_addrs[k] = htonl(addrs[k]);
2497 for (; k < VL_MAXIPADDRS_PERMH; k++) {
2498 exp->ex_addrs[k] = 0;
2501 /* Write the new mh entry out */
2504 DOFFSET(ntohl(ctx.ex_addr[0]->ex_contaddrs[base]),
2505 (char *)ctx.ex_addr[base], (char *)exp), (char *)exp,
2511 /* Remove any common addresses from other mh entres. We know these entries
2512 * are being changed and not replaced so they are mh entries.
2515 for (i = 0; i < count; i++) {
2518 /* Skip the entry we replaced */
2519 if (willReplaceCnt && (WillChange[i] == ReplaceEntry))
2522 code = multiHomedExtentBase(&ctx, WillChange[i], &tex, &base);
2528 (" The following existing entries in the VLDB will be updated:\n"));
2530 for (addrbuf[0] = '\0', h = j = 0; j < VL_MAXIPADDRS_PERMH; j++) {
2531 if (tex->ex_addrs[j]) {
2533 strlcat(addrbuf, " ", sizeof(addrbuf));
2534 append_addr(addrbuf, ntohl(tex->ex_addrs[j]), sizeof(addrbuf));
2537 for (k = 0; k < cnt; k++) {
2538 if (ntohl(tex->ex_addrs[j]) == addrs[k])
2542 /* Not found, so we keep it */
2543 tex->ex_addrs[h] = tex->ex_addrs[j];
2547 for (j = h; j < VL_MAXIPADDRS_PERMH; j++) {
2548 tex->ex_addrs[j] = 0; /* zero rest of mh entry */
2550 VLog(0, (" entry %d: [%s]\n", WillChange[i], addrbuf));
2552 /* Write out the modified mh entry */
2553 tex->ex_uniquifier = htonl(ntohl(tex->ex_uniquifier) + 1);
2555 DOFFSET(ntohl(ctx.ex_addr[0]->ex_contaddrs[base]),
2556 (char *)ctx.ex_addr[base], (char *)tex);
2557 if (vlwrite(ctx.trans, doff, (char *)tex, sizeof(*tex))) {
2563 return (ubik_EndTrans(ctx.trans));
2566 countAbort(this_op);
2567 ubik_AbortTrans(ctx.trans);
2572 SVL_GetAddrsU(struct rx_call *rxcall,
2573 struct ListAddrByAttributes *attributes,
2575 afs_int32 *uniquifier,
2576 afs_int32 *nentries,
2579 int this_op = VLGETADDRSU;
2580 afs_int32 code, index;
2582 int nservers, i, j, base = 0;
2583 struct extentaddr *exp = 0;
2585 afs_uint32 *taddrp, taddr;
2586 char rxstr[AFS_RXINFO_LEN];
2588 countRequest(this_op);
2589 addrsp->bulkaddrs_len = *nentries = 0;
2590 addrsp->bulkaddrs_val = 0;
2591 VLog(5, ("GetAddrsU %s\n", rxinfo(rxstr, rxcall)));
2592 if ((code = Init_VLdbase(&ctx, LOCKREAD, this_op)))
2595 if (attributes->Mask & VLADDR_IPADDR) {
2596 if (attributes->Mask & (VLADDR_INDEX | VLADDR_UUID)) {
2600 /* Search for a server registered with the VLDB with this ip address. */
2601 for (index = 0; index <= MAXSERVERID; index++) {
2602 code = multiHomedExtent(&ctx, index, &exp);
2607 for (j = 0; j < VL_MAXIPADDRS_PERMH; j++) {
2608 if (exp->ex_addrs[j]
2609 && (ntohl(exp->ex_addrs[j]) == attributes->ipaddr)) {
2613 if (j < VL_MAXIPADDRS_PERMH)
2617 if (index > MAXSERVERID) {
2621 } else if (attributes->Mask & VLADDR_INDEX) {
2622 if (attributes->Mask & (VLADDR_IPADDR | VLADDR_UUID)) {
2626 /* VLADDR_INDEX index is one based */
2627 if (attributes->index < 1 || attributes->index > MAXSERVERID) {
2628 code = VL_INDEXERANGE;
2631 index = attributes->index - 1;
2632 code = multiHomedExtent(&ctx, index, &exp);
2637 } else if (attributes->Mask & VLADDR_UUID) {
2638 if (attributes->Mask & (VLADDR_IPADDR | VLADDR_INDEX)) {
2642 if (!ctx.ex_addr[0]) { /* mh servers probably aren't setup on this vldb */
2646 code = FindExtentBlock(&ctx, &attributes->uuid, 0, -1, &exp, &base);
2658 addrsp->bulkaddrs_val = taddrp =
2659 malloc(sizeof(afs_uint32) * (MAXSERVERID + 1));
2660 nservers = *nentries = addrsp->bulkaddrs_len = 0;
2665 tuuid = exp->ex_hostuuid;
2666 afs_ntohuuid(&tuuid);
2667 if (afs_uuid_is_nil(&tuuid)) {
2674 *uniquifier = ntohl(exp->ex_uniquifier);
2675 for (i = 0; i < VL_MAXIPADDRS_PERMH; i++) {
2676 if (exp->ex_addrs[i]) {
2677 taddr = ntohl(exp->ex_addrs[i]);
2678 /* Weed out duplicates */
2679 for (j = 0; j < nservers; j++) {
2680 if (taddrp[j] == taddr)
2683 if ((j == nservers) && (j <= MAXSERVERID)) {
2684 taddrp[nservers] = taddr;
2689 addrsp->bulkaddrs_len = *nentries = nservers;
2690 return (ubik_EndTrans(ctx.trans));
2693 countAbort(this_op);
2694 ubik_AbortTrans(ctx.trans);
2698 /* ============> End of Exported vldb RPC functions <============= */
2701 /* Routine that copies the given vldb entry to the output buffer, vldbentries. */
2703 put_attributeentry(struct vl_ctx *ctx,
2704 struct vldbentry **Vldbentry,
2705 struct vldbentry **VldbentryFirst,
2706 struct vldbentry **VldbentryLast,
2707 bulkentries *vldbentries,
2708 struct nvlentry *entry,
2709 afs_int32 *nentries,
2710 afs_int32 *alloccnt)
2716 if (*Vldbentry == *VldbentryLast) {
2718 return VL_SIZEEXCEEDED; /* no growing if smallMem defined */
2720 /* Allocate another set of memory; each time allocate twice as
2721 * many blocks as the last time. When we reach VLDBALLOCLIMIT,
2722 * then grow in increments of VLDBALLOCINCR.
2724 allo = (*alloccnt > VLDBALLOCLIMIT) ? VLDBALLOCINCR : *alloccnt;
2725 reall = realloc(*VldbentryFirst,
2726 (*alloccnt + allo) * sizeof(vldbentry));
2730 *VldbentryFirst = vldbentries->bulkentries_val = reall;
2731 *Vldbentry = *VldbentryFirst + *alloccnt;
2732 *VldbentryLast = *Vldbentry + allo;
2736 code = vlentry_to_vldbentry(ctx, entry, *Vldbentry);
2742 vldbentries->bulkentries_len++;
2747 put_nattributeentry(struct vl_ctx *ctx,
2748 struct nvldbentry **Vldbentry,
2749 struct nvldbentry **VldbentryFirst,
2750 struct nvldbentry **VldbentryLast,
2751 nbulkentries *vldbentries,
2752 struct nvlentry *entry,
2753 afs_int32 matchtype,
2754 afs_int32 matchindex,
2755 afs_int32 *nentries,
2756 afs_int32 *alloccnt)
2762 if (*Vldbentry == *VldbentryLast) {
2764 return VL_SIZEEXCEEDED; /* no growing if smallMem defined */
2766 /* Allocate another set of memory; each time allocate twice as
2767 * many blocks as the last time. When we reach VLDBALLOCLIMIT,
2768 * then grow in increments of VLDBALLOCINCR.
2770 allo = (*alloccnt > VLDBALLOCLIMIT) ? VLDBALLOCINCR : *alloccnt;
2771 reall = realloc(*VldbentryFirst,
2772 (*alloccnt + allo) * sizeof(nvldbentry));
2776 *VldbentryFirst = vldbentries->nbulkentries_val = reall;
2777 *Vldbentry = *VldbentryFirst + *alloccnt;
2778 *VldbentryLast = *Vldbentry + allo;
2781 code = vlentry_to_nvldbentry(ctx, entry, *Vldbentry);
2785 (*Vldbentry)->matchindex = (matchtype << 16) + matchindex;
2788 vldbentries->nbulkentries_len++;
2793 /* Common code to actually remove a vldb entry from the database. */
2795 RemoveEntry(struct vl_ctx *ctx, afs_int32 entryptr,
2796 struct nvlentry *tentry)
2800 if ((code = UnthreadVLentry(ctx, entryptr, tentry)))
2802 if ((code = FreeBlock(ctx, entryptr)))
2808 ReleaseEntry(struct nvlentry *tentry, afs_int32 releasetype)
2810 if (releasetype & LOCKREL_TIMESTAMP)
2811 tentry->LockTimestamp = 0;
2812 if (releasetype & LOCKREL_OPCODE)
2813 tentry->flags &= ~VLOP_ALLOPERS;
2814 if (releasetype & LOCKREL_AFSID)
2815 tentry->LockAfsId = 0;
2819 /* Verify that the incoming vldb entry is valid; multi type of error codes
2822 check_vldbentry(struct vldbentry *aentry)
2826 if (InvalidVolname(aentry->name))
2828 if (aentry->nServers <= 0 || aentry->nServers > OMAXNSERVERS)
2829 return VL_BADSERVER;
2830 for (i = 0; i < aentry->nServers; i++) {
2831 /* if (aentry->serverNumber[i] < 0 || aentry->serverNumber[i] > MAXSERVERID)
2832 return VL_BADSERVER; */
2833 if (aentry->serverPartition[i] < 0
2834 || aentry->serverPartition[i] > MAXPARTITIONID)
2835 return VL_BADPARTITION;
2836 if (aentry->serverFlags[i] < 0
2837 || aentry->serverFlags[i] > MAXSERVERFLAG)
2838 return VL_BADSERVERFLAG;
2844 check_nvldbentry(struct nvldbentry *aentry)
2848 if (InvalidVolname(aentry->name))
2850 if (aentry->nServers <= 0 || aentry->nServers > NMAXNSERVERS)
2851 return VL_BADSERVER;
2852 for (i = 0; i < aentry->nServers; i++) {
2853 /* if (aentry->serverNumber[i] < 0 || aentry->serverNumber[i] > MAXSERVERID)
2854 return VL_BADSERVER; */
2855 if (aentry->serverPartition[i] < 0
2856 || aentry->serverPartition[i] > MAXPARTITIONID)
2857 return VL_BADPARTITION;
2858 if (aentry->serverFlags[i] < 0
2859 || aentry->serverFlags[i] > MAXSERVERFLAG)
2860 return VL_BADSERVERFLAG;
2866 /* Convert from the external vldb entry representation to its internal
2867 (more compact) form. This call should not change the hash chains! */
2869 vldbentry_to_vlentry(struct vl_ctx *ctx,
2870 struct vldbentry *VldbEntry,
2871 struct nvlentry *VlEntry)
2875 if (strcmp(VlEntry->name, VldbEntry->name))
2876 strncpy(VlEntry->name, VldbEntry->name, sizeof(VlEntry->name));
2877 for (i = 0; i < VldbEntry->nServers; i++) {
2878 serverindex = IpAddrToRelAddr(ctx, VldbEntry->serverNumber[i], 1);
2879 if (serverindex == -1)
2880 return VL_BADSERVER;
2881 VlEntry->serverNumber[i] = serverindex;
2882 VlEntry->serverPartition[i] = VldbEntry->serverPartition[i];
2883 VlEntry->serverFlags[i] = VldbEntry->serverFlags[i];
2885 for (; i < OMAXNSERVERS; i++)
2886 VlEntry->serverNumber[i] = VlEntry->serverPartition[i] =
2887 VlEntry->serverFlags[i] = BADSERVERID;
2888 for (i = 0; i < MAXTYPES; i++)
2889 VlEntry->volumeId[i] = VldbEntry->volumeId[i];
2890 VlEntry->cloneId = VldbEntry->cloneId;
2891 VlEntry->flags = VldbEntry->flags;
2896 nvldbentry_to_vlentry(struct vl_ctx *ctx,
2897 struct nvldbentry *VldbEntry,
2898 struct nvlentry *VlEntry)
2902 if (strcmp(VlEntry->name, VldbEntry->name))
2903 strncpy(VlEntry->name, VldbEntry->name, sizeof(VlEntry->name));
2904 for (i = 0; i < VldbEntry->nServers; i++) {
2905 serverindex = IpAddrToRelAddr(ctx, VldbEntry->serverNumber[i], 1);
2906 if (serverindex == -1)
2907 return VL_BADSERVER;
2908 VlEntry->serverNumber[i] = serverindex;
2909 VlEntry->serverPartition[i] = VldbEntry->serverPartition[i];
2910 VlEntry->serverFlags[i] = VldbEntry->serverFlags[i];
2912 for (; i < NMAXNSERVERS; i++)
2913 VlEntry->serverNumber[i] = VlEntry->serverPartition[i] =
2914 VlEntry->serverFlags[i] = BADSERVERID;
2915 for (i = 0; i < MAXTYPES; i++)
2916 VlEntry->volumeId[i] = VldbEntry->volumeId[i];
2917 VlEntry->cloneId = VldbEntry->cloneId;
2918 VlEntry->flags = VldbEntry->flags;
2923 /* Update the vldb entry with the new fields as indicated by the value of
2924 * the Mask entry in the updateentry structure. All necessary validation
2925 * checks are performed.
2928 get_vldbupdateentry(struct vl_ctx *ctx,
2929 afs_int32 blockindex,
2930 struct VldbUpdateEntry *updateentry,
2931 struct nvlentry *VlEntry)
2933 int i, j, code, serverindex;
2934 afs_uint32 checkids[MAXTYPES];
2936 /* check if any specified new IDs are already present in the db. Do
2937 * this check before doing anything else, so we don't get a half-
2939 memset(&checkids, 0, sizeof(checkids));
2940 if (updateentry->Mask & VLUPDATE_RWID) {
2941 checkids[RWVOL] = updateentry->spares3; /* rw id */
2943 if (updateentry->Mask & VLUPDATE_READONLYID) {
2944 checkids[ROVOL] = updateentry->ReadOnlyId;
2946 if (updateentry->Mask & VLUPDATE_BACKUPID) {
2947 checkids[BACKVOL] = updateentry->BackupId;
2950 if (EntryIDExists(ctx, checkids, MAXTYPES, &code)) {
2956 if (updateentry->Mask & VLUPDATE_VOLUMENAME) {
2957 struct nvlentry tentry;
2959 if (InvalidVolname(updateentry->name))
2962 if (FindByName(ctx, updateentry->name, &tentry, &code)) {
2963 return VL_NAMEEXIST;
2968 if ((code = UnhashVolname(ctx, blockindex, VlEntry)))
2970 strncpy(VlEntry->name, updateentry->name, sizeof(VlEntry->name));
2971 HashVolname(ctx, blockindex, VlEntry);
2974 if (updateentry->Mask & VLUPDATE_VOLNAMEHASH) {
2975 if ((code = UnhashVolname(ctx, blockindex, VlEntry))) {
2976 if (code != VL_NOENT)
2979 HashVolname(ctx, blockindex, VlEntry);
2982 if (updateentry->Mask & VLUPDATE_FLAGS) {
2983 VlEntry->flags = updateentry->flags;
2985 if (updateentry->Mask & VLUPDATE_CLONEID) {
2986 VlEntry->cloneId = updateentry->cloneId;
2988 if (updateentry->Mask & VLUPDATE_RWID) {
2989 if ((code = UnhashVolid(ctx, RWVOL, blockindex, VlEntry))) {
2990 if (code != VL_NOENT)
2993 VlEntry->volumeId[RWVOL] = updateentry->spares3; /* rw id */
2994 if ((code = HashVolid(ctx, RWVOL, blockindex, VlEntry)))
2997 if (updateentry->Mask & VLUPDATE_READONLYID) {
2998 if ((code = UnhashVolid(ctx, ROVOL, blockindex, VlEntry))) {
2999 if (code != VL_NOENT)
3002 VlEntry->volumeId[ROVOL] = updateentry->ReadOnlyId;
3003 if ((code = HashVolid(ctx, ROVOL, blockindex, VlEntry)))
3006 if (updateentry->Mask & VLUPDATE_BACKUPID) {
3007 if ((code = UnhashVolid(ctx, BACKVOL, blockindex, VlEntry))) {
3008 if (code != VL_NOENT)
3011 VlEntry->volumeId[BACKVOL] = updateentry->BackupId;
3012 if ((code = HashVolid(ctx, BACKVOL, blockindex, VlEntry)))
3015 if (updateentry->Mask & VLUPDATE_REPSITES) {
3016 if (updateentry->nModifiedRepsites <= 0
3017 || updateentry->nModifiedRepsites > OMAXNSERVERS)
3018 return VL_BADSERVER;
3019 for (i = 0; i < updateentry->nModifiedRepsites; i++) {
3020 /* if (updateentry->RepsitesTargetServer[i] < 0 || updateentry->RepsitesTargetServer[i] > MAXSERVERID)
3021 return VL_BADSERVER; */
3022 if (updateentry->RepsitesTargetPart[i] < 0
3023 || updateentry->RepsitesTargetPart[i] > MAXPARTITIONID)
3024 return VL_BADPARTITION;
3025 if (updateentry->RepsitesMask[i] & VLUPDATE_REPS_DELETE) {
3027 repsite_exists(VlEntry,
3028 IpAddrToRelAddr(ctx, updateentry->
3029 RepsitesTargetServer[i],
3031 updateentry->RepsitesTargetPart[i])) !=
3033 repsite_compress(VlEntry, j);
3035 return VL_NOREPSERVER;
3037 if (updateentry->RepsitesMask[i] & VLUPDATE_REPS_ADD) {
3038 /* if (updateentry->RepsitesNewServer[i] < 0 || updateentry->RepsitesNewServer[i] > MAXSERVERID)
3039 return VL_BADSERVER; */
3040 if (updateentry->RepsitesNewPart[i] < 0
3041 || updateentry->RepsitesNewPart[i] > MAXPARTITIONID)
3042 return VL_BADPARTITION;
3045 IpAddrToRelAddr(ctx, updateentry->RepsitesNewServer[i], 1),
3046 updateentry->RepsitesNewPart[i]) != -1)
3047 return VL_DUPREPSERVER;
3049 VlEntry->serverNumber[j] != BADSERVERID
3050 && j < OMAXNSERVERS; j++);
3051 if (j >= OMAXNSERVERS)
3054 IpAddrToRelAddr(ctx, updateentry->RepsitesNewServer[i],
3056 return VL_BADSERVER;
3057 VlEntry->serverNumber[j] = serverindex;
3058 VlEntry->serverPartition[j] = updateentry->RepsitesNewPart[i];
3059 if (updateentry->RepsitesNewFlags[i] < 0
3060 || updateentry->RepsitesNewFlags[i] > MAXSERVERFLAG)
3061 return VL_BADSERVERFLAG;
3062 VlEntry->serverFlags[j] = updateentry->RepsitesNewFlags[i];
3064 if (updateentry->RepsitesMask[i] & VLUPDATE_REPS_MODSERV) {
3065 /*n if (updateentry->RepsitesNewServer[i] < 0 || updateentry->RepsitesNewServer[i] > MAXSERVERID)
3066 return VL_BADSERVER; */
3068 repsite_exists(VlEntry,
3069 IpAddrToRelAddr(ctx, updateentry->
3070 RepsitesTargetServer[i],
3072 updateentry->RepsitesTargetPart[i])) !=
3074 VlEntry->serverNumber[j] =
3075 IpAddrToRelAddr(ctx, updateentry->RepsitesNewServer[i],
3078 return VL_NOREPSERVER;
3080 if (updateentry->RepsitesMask[i] & VLUPDATE_REPS_MODPART) {
3081 if (updateentry->RepsitesNewPart[i] < 0
3082 || updateentry->RepsitesNewPart[i] > MAXPARTITIONID)
3083 return VL_BADPARTITION;
3085 repsite_exists(VlEntry,
3086 IpAddrToRelAddr(ctx, updateentry->
3087 RepsitesTargetServer[i],
3089 updateentry->RepsitesTargetPart[i])) !=
3091 VlEntry->serverPartition[j] =
3092 updateentry->RepsitesNewPart[i];
3094 return VL_NOREPSERVER;
3096 if (updateentry->RepsitesMask[i] & VLUPDATE_REPS_MODFLAG) {
3098 repsite_exists(VlEntry,
3099 IpAddrToRelAddr(ctx, updateentry->
3100 RepsitesTargetServer[i],
3102 updateentry->RepsitesTargetPart[i])) !=
3104 if (updateentry->RepsitesNewFlags[i] < 0
3105 || updateentry->RepsitesNewFlags[i] > MAXSERVERFLAG)
3106 return VL_BADSERVERFLAG;
3107 VlEntry->serverFlags[j] =
3108 updateentry->RepsitesNewFlags[i];
3110 return VL_NOREPSERVER;
3118 /* Check if the specified [server,partition] entry is found in the vldb
3119 * entry's repsite table; it's offset in the table is returned, if it's
3122 repsite_exists(struct nvlentry *VlEntry, int server, int partition)
3126 for (i = 0; VlEntry->serverNumber[i] != BADSERVERID && i < OMAXNSERVERS;
3128 if ((VlEntry->serverNumber[i] == server)
3129 && (VlEntry->serverPartition[i] == partition))
3137 /* Repsite table compression: used when deleting a repsite entry so that
3138 * all active repsite entries are on the top of the table. */
3140 repsite_compress(struct nvlentry *VlEntry, int offset)
3142 int repsite_offset = offset;
3144 VlEntry->serverNumber[repsite_offset] != BADSERVERID
3145 && repsite_offset < OMAXNSERVERS - 1; repsite_offset++) {
3146 VlEntry->serverNumber[repsite_offset] =
3147 VlEntry->serverNumber[repsite_offset + 1];
3148 VlEntry->serverPartition[repsite_offset] =
3149 VlEntry->serverPartition[repsite_offset + 1];
3150 VlEntry->serverFlags[repsite_offset] =
3151 VlEntry->serverFlags[repsite_offset + 1];
3153 VlEntry->serverNumber[repsite_offset] = BADSERVERID;
3157 /* Convert from the internal (compacted) vldb entry to the external
3158 * representation used by the interface. */
3160 vlentry_to_vldbentry(struct vl_ctx *ctx, struct nvlentry *VlEntry,
3161 struct vldbentry *VldbEntry)
3164 struct extentaddr *exp;
3166 memset(VldbEntry, 0, sizeof(struct vldbentry));
3167 strncpy(VldbEntry->name, VlEntry->name, sizeof(VldbEntry->name));
3168 for (i = 0; i < OMAXNSERVERS; i++) {
3169 if (VlEntry->serverNumber[i] == BADSERVERID)
3171 code = multiHomedExtent(ctx, VlEntry->serverNumber[i], &exp);
3175 /* For now return the first ip address back */
3176 for (j = 0; j < VL_MAXIPADDRS_PERMH; j++) {
3177 if (exp->ex_addrs[j]) {
3178 VldbEntry->serverNumber[i] = ntohl(exp->ex_addrs[j]);
3183 VldbEntry->serverNumber[i] =
3184 ctx->hostaddress[VlEntry->serverNumber[i]];
3185 VldbEntry->serverPartition[i] = VlEntry->serverPartition[i];
3186 VldbEntry->serverFlags[i] = VlEntry->serverFlags[i];
3188 VldbEntry->nServers = i;
3189 for (i = 0; i < MAXTYPES; i++)
3190 VldbEntry->volumeId[i] = VlEntry->volumeId[i];
3191 VldbEntry->cloneId = VlEntry->cloneId;
3192 VldbEntry->flags = VlEntry->flags;
3198 /* Convert from the internal (compacted) vldb entry to the external
3199 * representation used by the interface. */
3201 vlentry_to_nvldbentry(struct vl_ctx *ctx, struct nvlentry *VlEntry,
3202 struct nvldbentry *VldbEntry)
3205 struct extentaddr *exp;
3207 memset(VldbEntry, 0, sizeof(struct nvldbentry));
3208 strncpy(VldbEntry->name, VlEntry->name, sizeof(VldbEntry->name));
3209 for (i = 0; i < NMAXNSERVERS; i++) {
3210 if (VlEntry->serverNumber[i] == BADSERVERID)
3212 code = multiHomedExtent(ctx, VlEntry->serverNumber[i], &exp);
3217 /* For now return the first ip address back */
3218 for (j = 0; j < VL_MAXIPADDRS_PERMH; j++) {
3219 if (exp->ex_addrs[j]) {
3220 VldbEntry->serverNumber[i] = ntohl(exp->ex_addrs[j]);
3225 VldbEntry->serverNumber[i] =
3226 ctx->hostaddress[VlEntry->serverNumber[i]];
3227 VldbEntry->serverPartition[i] = VlEntry->serverPartition[i];
3228 VldbEntry->serverFlags[i] = VlEntry->serverFlags[i];
3230 VldbEntry->nServers = i;
3231 for (i = 0; i < MAXTYPES; i++)
3232 VldbEntry->volumeId[i] = VlEntry->volumeId[i];
3233 VldbEntry->cloneId = VlEntry->cloneId;
3234 VldbEntry->flags = VlEntry->flags;
3240 vlentry_to_uvldbentry(struct vl_ctx *ctx, struct nvlentry *VlEntry,
3241 struct uvldbentry *VldbEntry)
3244 struct extentaddr *exp;
3246 memset(VldbEntry, 0, sizeof(struct uvldbentry));
3247 strncpy(VldbEntry->name, VlEntry->name, sizeof(VldbEntry->name));
3248 for (i = 0; i < NMAXNSERVERS; i++) {
3249 if (VlEntry->serverNumber[i] == BADSERVERID)
3251 VldbEntry->serverFlags[i] = VlEntry->serverFlags[i];
3252 VldbEntry->serverUnique[i] = 0;
3253 code = multiHomedExtent(ctx, VlEntry->serverNumber[i], &exp);
3260 tuuid = exp->ex_hostuuid;
3261 afs_ntohuuid(&tuuid);
3262 VldbEntry->serverFlags[i] |= VLSF_UUID;
3263 VldbEntry->serverNumber[i] = tuuid;
3264 VldbEntry->serverUnique[i] = ntohl(exp->ex_uniquifier);
3266 VldbEntry->serverNumber[i].time_low =
3267 ctx->hostaddress[VlEntry->serverNumber[i]];
3269 VldbEntry->serverPartition[i] = VlEntry->serverPartition[i];
3272 VldbEntry->nServers = i;
3273 for (i = 0; i < MAXTYPES; i++)
3274 VldbEntry->volumeId[i] = VlEntry->volumeId[i];
3275 VldbEntry->cloneId = VlEntry->cloneId;
3276 VldbEntry->flags = VlEntry->flags;
3281 #define LEGALCHARS ".ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"
3284 /* Verify that the volname is a valid volume name. */
3286 InvalidVolname(char *volname)
3292 slen = strlen(volname);
3293 if (slen >= VL_MAXNAMELEN)
3295 return (slen != strspn(volname, map));
3299 /* Verify that the given volume type is valid. */
3301 InvalidVoltype(afs_int32 voltype)
3303 if (voltype != RWVOL && voltype != ROVOL && voltype != BACKVOL)
3310 InvalidOperation(afs_int32 voloper)
3312 if (voloper != VLOP_MOVE && voloper != VLOP_RELEASE
3313 && voloper != VLOP_BACKUP && voloper != VLOP_DELETE
3314 && voloper != VLOP_DUMP)
3320 InvalidReleasetype(afs_int32 releasetype)
3322 if ((releasetype & LOCKREL_TIMESTAMP) || (releasetype & LOCKREL_OPCODE)
3323 || (releasetype & LOCKREL_AFSID))
3329 IpAddrToRelAddr(struct vl_ctx *ctx, afs_uint32 ipaddr, int create)
3333 struct extentaddr *exp;
3335 for (i = 0; i <= MAXSERVERID; i++) {
3336 if (ctx->hostaddress[i] == ipaddr)
3338 code = multiHomedExtent(ctx, i, &exp);
3342 for (j = 0; j < VL_MAXIPADDRS_PERMH; j++) {
3343 if (exp->ex_addrs[j] && (ntohl(exp->ex_addrs[j]) == ipaddr)) {
3350 /* allocate the new server a server id pronto */
3352 for (i = 0; i <= MAXSERVERID; i++) {
3353 if (ctx->cheader->IpMappedAddr[i] == 0) {
3354 ctx->cheader->IpMappedAddr[i] = htonl(ipaddr);
3357 DOFFSET(0, ctx->cheader, &ctx->cheader->IpMappedAddr[i]),
3358 (char *)&ctx->cheader->IpMappedAddr[i],
3360 ctx->hostaddress[i] = ipaddr;
3371 ChangeIPAddr(struct vl_ctx *ctx, afs_uint32 ipaddr1, afs_uint32 ipaddr2)
3375 struct extentaddr *exp = NULL;
3379 afs_int32 blockindex, count;
3381 struct nvlentry tentry;
3382 int ipaddr1_id = -1, ipaddr2_id = -1;
3386 /* Don't let addr change to 256.*.*.* : Causes internal error below */
3387 if ((ipaddr2 & 0xff000000) == 0xff000000)
3388 return (VL_BADSERVER);
3390 /* If we are removing an address, ip1 will be -1 and ip2 will be
3391 * the original address. This prevents an older revision vlserver
3392 * from removing the IP address (won't find server 0xfffffff in
3393 * the VLDB). An older revision vlserver does not have the check
3394 * to see if any volumes exist on the server being removed.
3396 if (ipaddr1 == 0xffffffff) {
3401 for (i = 0; i <= MAXSERVERID; i++) {
3402 code = multiHomedExtentBase(ctx, i, &exp, &base);
3407 for (mhidx = 0; mhidx < VL_MAXIPADDRS_PERMH; mhidx++) {
3408 if (!exp->ex_addrs[mhidx])
3410 if (ntohl(exp->ex_addrs[mhidx]) == ipaddr1) {
3413 if (ipaddr2 != 0 && ntohl(exp->ex_addrs[mhidx]) == ipaddr2) {
3418 if (ctx->hostaddress[i] == ipaddr1) {
3422 if (ipaddr2 != 0 && ctx->hostaddress[i] == ipaddr2) {
3427 if (ipaddr1_id >= 0 && (ipaddr2 == 0 || ipaddr2_id >= 0)) {
3428 /* we've either found both IPs already in the VLDB, or we found
3429 * ipaddr1, and we're not going to find ipaddr2 because it's 0 */
3434 if (ipaddr1_id < 0) {
3435 return VL_NOENT; /* not found */
3438 if (ipaddr2_id >= 0 && ipaddr2_id != ipaddr1_id) {
3439 char buf1[16], buf2[16];
3440 VLog(0, ("Cannot change IP address from %s to %s because the latter "
3441 "is in use by server id %d\n",
3442 afs_inet_ntoa_r(htonl(ipaddr1), buf1),
3443 afs_inet_ntoa_r(htonl(ipaddr2), buf2),
3445 return VL_MULTIPADDR;
3448 /* If we are removing a server entry, a volume cannot
3449 * exist on the server. If one does, don't remove the
3450 * server entry: return error "volume entry exists".
3453 for (blockindex = NextEntry(ctx, 0, &tentry, &count); blockindex;
3454 blockindex = NextEntry(ctx, blockindex, &tentry, &count)) {
3455 if (++pollcount > 50) {
3456 #ifndef AFS_PTHREAD_ENV
3461 for (j = 0; j < NMAXNSERVERS; j++) {
3462 if (tentry.serverNumber[j] == BADSERVERID)
3464 if (tentry.serverNumber[j] == ipaddr1_id) {
3471 /* Log a message saying we are changing/removing an IP address */
3473 ("The following IP address is being %s:\n",
3474 (ipaddr2 ? "changed" : "removed")));
3475 addrbuf1[0] = addrbuf2[0] = '\0';
3477 for (mhidx = 0; mhidx < VL_MAXIPADDRS_PERMH; mhidx++) {
3478 if (!exp->ex_addrs[mhidx])
3481 strlcat(addrbuf1, " ", sizeof(addrbuf1));
3482 append_addr(addrbuf1, ntohl(exp->ex_addrs[mhidx]), sizeof(addrbuf1));
3485 append_addr(addrbuf1, ipaddr1, sizeof(addrbuf1));
3488 append_addr(addrbuf2, ipaddr2, sizeof(addrbuf2));
3490 VLog(0, (" entry %d: [%s] -> [%s]\n", i, addrbuf1, addrbuf2));
3492 /* Change the registered uuuid addresses */
3494 memset(&tuuid, 0, sizeof(afsUUID));
3495 afs_htonuuid(&tuuid);
3496 exp->ex_hostuuid = tuuid;
3499 DOFFSET(ntohl(ctx->ex_addr[0]->ex_contaddrs[base]),
3500 (char *)ctx->ex_addr[base], (char *)exp),
3501 (char *)&tuuid, sizeof(tuuid));
3506 /* Now change the host address entry */
3507 ctx->cheader->IpMappedAddr[ipaddr1_id] = htonl(ipaddr2);
3509 vlwrite(ctx->trans, DOFFSET(0, ctx->cheader, &ctx->cheader->IpMappedAddr[ipaddr1_id]),
3511 &ctx->cheader->IpMappedAddr[ipaddr1_id], sizeof(afs_int32));
3512 ctx->hostaddress[ipaddr1_id] = ipaddr2;
3519 /* see if the vlserver is back yet */
3521 SVL_ProbeServer(struct rx_call *rxcall)