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 { \
43 #define VLDBALLOCLIMIT 10000
44 #define VLDBALLOCINCR 2048
46 static int put_attributeentry(struct vl_ctx *ctx,
47 struct vldbentry **, struct vldbentry **,
48 struct vldbentry **, bulkentries *,
49 struct nvlentry *, afs_int32 *, afs_int32 *);
50 static int put_nattributeentry(struct vl_ctx *ctx,
51 struct nvldbentry **, struct nvldbentry **,
52 struct nvldbentry **, nbulkentries *,
53 struct nvlentry *, afs_int32, afs_int32,
54 afs_int32 *, afs_int32 *);
55 static int RemoveEntry(struct vl_ctx *ctx, afs_int32 entryptr,
56 struct nvlentry *tentry);
57 static void ReleaseEntry(struct nvlentry *tentry, afs_int32 releasetype);
58 static int check_vldbentry(struct vldbentry *aentry);
59 static int check_nvldbentry(struct nvldbentry *aentry);
60 static int vldbentry_to_vlentry(struct vl_ctx *ctx,
61 struct vldbentry *VldbEntry,
62 struct nvlentry *VlEntry);
63 static int nvldbentry_to_vlentry(struct vl_ctx *ctx,
64 struct nvldbentry *VldbEntry,
65 struct nvlentry *VlEntry);
66 static int get_vldbupdateentry(struct vl_ctx *ctx, afs_int32 blockindex,
67 struct VldbUpdateEntry *updateentry,
68 struct nvlentry *VlEntry);
69 static int repsite_exists(struct nvlentry *VlEntry, int server, int partition);
70 static void repsite_compress(struct nvlentry *VlEntry, int offset);
71 static int vlentry_to_vldbentry(struct vl_ctx *ctx,
72 struct nvlentry *VlEntry,
73 struct vldbentry *VldbEntry);
74 static int vlentry_to_nvldbentry(struct vl_ctx *ctx,
75 struct nvlentry *VlEntry,
76 struct nvldbentry *VldbEntry);
77 static int vlentry_to_uvldbentry(struct vl_ctx *ctx,
78 struct nvlentry *VlEntry,
79 struct uvldbentry *VldbEntry);
80 static int InvalidVolname(char *volname);
81 static int InvalidVoltype(afs_int32 voltype);
82 static int InvalidOperation(afs_int32 voloper);
83 static int InvalidReleasetype(afs_int32 releasetype);
84 static int IpAddrToRelAddr(struct vl_ctx *ctx, afs_uint32 ipaddr, int create);
85 static int ChangeIPAddr(struct vl_ctx *ctx, afs_uint32 ipaddr1,
89 countRequest(int opcode)
92 dynamic_statistics.requests[opcode - VL_LOWEST_OPCODE]++;
97 countAbort(int opcode)
100 dynamic_statistics.aborts[opcode - VL_LOWEST_OPCODE]++;
106 multiHomedExtentBase(struct vl_ctx *ctx, int srvidx, struct extentaddr **exp,
115 if ((ctx->hostaddress[srvidx] & 0xff000000) == 0xff000000) {
116 base = (ctx->hostaddress[srvidx] >> 16) & 0xff;
117 index = ctx->hostaddress[srvidx] & 0x0000ffff;
118 if (base >= VL_MAX_ADDREXTBLKS) {
119 VLog(0, ("Internal error: Multihome extent base is too large. "
120 "Base %d index %d\n", base, index));
123 if (index >= VL_MHSRV_PERBLK) {
124 VLog(0, ("Internal error: Multihome extent index is too large. "
125 "Base %d index %d\n", base, index));
128 if (!ctx->ex_addr[base]) {
129 VLog(0, ("Internal error: Multihome extent does not exist. "
135 *exp = &ctx->ex_addr[base][index];
142 multiHomedExtent(struct vl_ctx *ctx, int srvidx, struct extentaddr **exp)
146 return multiHomedExtentBase(ctx, srvidx, exp, &base);
149 #define AFS_RXINFO_LEN 128
151 rxkadInfo(char *str, struct rx_connection *conn, struct in_addr hostAddr)
159 code = rxkad_GetServerInfo(conn, NULL, &exp, tname, tinst, tcell,
162 snprintf(str, AFS_RXINFO_LEN,
163 "%s rxkad:%s%s%s%s%s", inet_ntoa(hostAddr), tname,
164 (tinst[0] == '\0') ? "" : ".",
165 (tinst[0] == '\0') ? "" : tinst,
166 (tcell[0] == '\0') ? "" : "@",
167 (tcell[0] == '\0') ? "" : tcell);
169 snprintf(str, AFS_RXINFO_LEN, "%s noauth", inet_ntoa(hostAddr));
174 rxinfo(char *str, struct rx_call *rxcall)
176 struct rx_connection *conn;
177 struct in_addr hostAddr;
178 rx_securityIndex authClass;
180 conn = rx_ConnectionOf(rxcall);
181 authClass = rx_SecurityClassOf(conn);
182 hostAddr.s_addr = rx_HostOf(rx_PeerOf(conn));
186 return rxkadInfo(str, conn, hostAddr);
191 snprintf(str, AFS_RXINFO_LEN, "%s noauth", inet_ntoa(hostAddr));
196 /* This is called to initialize the database, set the appropriate locks and make sure that the vldb header is valid */
198 Init_VLdbase(struct vl_ctx *ctx,
199 int locktype, /* indicate read or write transaction */
202 int code = 0, pass, wl;
204 for (pass = 1; pass <= 3; pass++) {
205 if (pass == 2) { /* take write lock to rebuild the db */
206 code = ubik_BeginTrans(VL_dbase, UBIK_WRITETRANS, &ctx->trans);
208 } else if (locktype == LOCKREAD) {
210 ubik_BeginTransReadAnyWrite(VL_dbase, UBIK_READTRANS, &ctx->trans);
213 code = ubik_BeginTrans(VL_dbase, UBIK_WRITETRANS, &ctx->trans);
219 code = ubik_SetLock(ctx->trans, 1, 1, locktype);
222 ubik_AbortTrans(ctx->trans);
226 /* check that dbase is initialized and setup cheader */
227 /* 2nd pass we try to rebuild the header */
228 code = CheckInit(ctx->trans, ((pass == 2) ? 1 : 0));
229 if (!code && wl && extent_mod)
230 code = readExtents(ctx->trans); /* Fix the mh extent blocks */
233 ubik_AbortTrans(ctx->trans);
234 /* Only rebuld if the database is empty */
235 /* Exit if can't rebuild */
236 if ((pass == 1) && (code != VL_EMPTY))
240 } else { /* No code */
242 /* The database header was rebuilt; end the write transaction.
243 * This will call vlsynccache() to copy the write header buffers
244 * to the read header buffers, before calling vlsetache().
245 * Do a third pass to re-acquire the original lock, which
246 * may be a read lock. */
247 ubik_EndTrans(ctx->trans);
249 break; /* didn't rebuild and successful - exit */
254 code = vlsetcache(ctx, locktype);
260 /* Create a new vldb entry; both new volume id and name must be unique
261 * (non-existant in vldb).
265 CreateEntry(struct rx_call *rxcall, struct vldbentry *newentry)
267 int this_op = VLCREATEENTRY;
269 afs_int32 code, blockindex;
270 struct nvlentry tentry;
271 char rxstr[AFS_RXINFO_LEN];
273 countRequest(this_op);
274 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 return ubik_EndTrans(ctx.trans);
327 ubik_AbortTrans(ctx.trans);
332 SVL_CreateEntry(struct rx_call *rxcall, struct vldbentry *newentry)
336 code = CreateEntry(rxcall, newentry);
337 osi_auditU(rxcall, VLCreateEntryEvent, code, AUD_STR,
338 (newentry ? newentry->name : NULL), AUD_END);
343 CreateEntryN(struct rx_call *rxcall, struct nvldbentry *newentry)
345 int this_op = VLCREATEENTRYN;
347 afs_int32 code, blockindex;
348 struct nvlentry tentry;
349 char rxstr[AFS_RXINFO_LEN];
351 countRequest(this_op);
352 if (!afsconf_SuperUser(vldb_confdir, rxcall, NULL)) {
356 /* Do some validity tests on new entry */
357 if ((code = check_nvldbentry(newentry))
358 || (code = Init_VLdbase(&ctx, LOCKWRITE, this_op)))
362 ("Create Volume %d %s\n", newentry->volumeId[RWVOL],
363 rxinfo(rxstr, rxcall)));
364 if (EntryIDExists(&ctx, newentry->volumeId, MAXTYPES, &code)) {
365 /* at least one of the specified IDs already exists; we fail */
372 /* Is this following check (by volume name) necessary?? */
373 /* If entry already exists, we fail */
374 if (FindByName(&ctx, newentry->name, &tentry, &code)) {
381 blockindex = AllocBlock(&ctx, &tentry);
382 if (blockindex == 0) {
383 code = VL_CREATEFAIL;
387 memset(&tentry, 0, sizeof(struct nvlentry));
388 /* Convert to its internal representation; both in host byte order */
389 if ((code = nvldbentry_to_vlentry(&ctx, newentry, &tentry))) {
390 FreeBlock(&ctx, blockindex);
394 /* Actually insert the entry in vldb */
395 code = ThreadVLentry(&ctx, blockindex, &tentry);
397 FreeBlock(&ctx, blockindex);
400 return ubik_EndTrans(ctx.trans);
405 ubik_AbortTrans(ctx.trans);
410 SVL_CreateEntryN(struct rx_call *rxcall, struct nvldbentry *newentry)
414 code = CreateEntryN(rxcall, newentry);
415 osi_auditU(rxcall, VLCreateEntryEvent, code, AUD_STR,
416 (newentry ? newentry->name : NULL), AUD_END);
421 ChangeAddr(struct rx_call *rxcall, afs_uint32 ip1, afs_uint32 ip2)
423 int this_op = VLCHANGEADDR;
426 char rxstr[AFS_RXINFO_LEN];
428 countRequest(this_op);
429 if (!afsconf_SuperUser(vldb_confdir, rxcall, NULL)) {
433 if ((code = Init_VLdbase(&ctx, LOCKWRITE, this_op)))
436 VLog(1, ("Change Addr %u -> %u %s\n", ip1, ip2, rxinfo(rxstr, rxcall)));
437 if ((code = ChangeIPAddr(&ctx, ip1, ip2)))
440 code = ubik_EndTrans(ctx.trans);
446 ubik_AbortTrans(ctx.trans);
451 SVL_ChangeAddr(struct rx_call *rxcall, afs_uint32 ip1, afs_uint32 ip2)
455 code = ChangeAddr(rxcall, ip1, ip2);
456 osi_auditU(rxcall, VLChangeAddrEvent, code, AUD_LONG, ip1, AUD_LONG,
461 /* Delete a vldb entry given the volume id. */
463 DeleteEntry(struct rx_call *rxcall, afs_uint32 volid, afs_int32 voltype)
465 int this_op = VLDELETEENTRY;
467 afs_int32 blockindex, code;
468 struct nvlentry tentry;
469 char rxstr[AFS_RXINFO_LEN];
471 countRequest(this_op);
472 if (!afsconf_SuperUser(vldb_confdir, rxcall, NULL))
475 if ((voltype != -1) && (InvalidVoltype(voltype)))
476 return VL_BADVOLTYPE;
478 if ((code = Init_VLdbase(&ctx, LOCKWRITE, this_op)))
481 VLog(1, ("Delete Volume %u %s\n", volid, rxinfo(rxstr, rxcall)));
482 blockindex = FindByID(&ctx, volid, voltype, &tentry, &code);
483 if (blockindex == 0) { /* volid not found */
489 if (tentry.flags & VLDELETED) { /* Already deleted; return */
490 ABORT(VL_ENTDELETED);
492 if ((code = RemoveEntry(&ctx, blockindex, &tentry))) {
495 return ubik_EndTrans(ctx.trans);
499 ubik_AbortTrans(ctx.trans);
504 SVL_DeleteEntry(struct rx_call *rxcall, afs_uint32 volid, afs_int32 voltype)
508 code = DeleteEntry(rxcall, volid, voltype);
509 osi_auditU(rxcall, VLDeleteEntryEvent, code, AUD_LONG, volid,
515 /* Get a vldb entry given its volume id; make sure it's not a deleted entry. */
517 GetEntryByID(struct rx_call *rxcall,
520 char *aentry, /* entry data copied here */
525 afs_int32 blockindex, code;
526 struct nvlentry tentry;
527 char rxstr[AFS_RXINFO_LEN];
529 countRequest(this_op);
531 if ((voltype != -1) && (InvalidVoltype(voltype)))
532 return VL_BADVOLTYPE;
533 if ((code = Init_VLdbase(&ctx, LOCKREAD, this_op)))
536 VLog(5, ("GetVolumeByID %u (%d) %s\n", volid, new,
537 rxinfo(rxstr, rxcall)));
538 blockindex = FindByID(&ctx, volid, voltype, &tentry, &code);
539 if (blockindex == 0) { /* entry not found */
544 if (tentry.flags & VLDELETED) { /* Entry is deleted! */
545 code = VL_ENTDELETED;
548 /* Convert from the internal to external form */
550 code = vlentry_to_nvldbentry(&ctx, &tentry, (struct nvldbentry *)aentry);
552 code = vlentry_to_uvldbentry(&ctx, &tentry, (struct uvldbentry *)aentry);
554 code = vlentry_to_vldbentry(&ctx, &tentry, (struct vldbentry *)aentry);
559 return (ubik_EndTrans(ctx.trans));
563 ubik_AbortTrans(ctx.trans);
568 SVL_GetEntryByID(struct rx_call *rxcall,
571 vldbentry *aentry) /* entry data copied here */
573 return (GetEntryByID(rxcall, volid, voltype, (char *)aentry, 0,
578 SVL_GetEntryByIDN(struct rx_call *rxcall,
581 nvldbentry *aentry) /* entry data copied here */
583 return (GetEntryByID(rxcall, volid, voltype, (char *)aentry, 1,
588 SVL_GetEntryByIDU(struct rx_call *rxcall,
591 uvldbentry *aentry) /* entry data copied here */
593 return (GetEntryByID(rxcall, volid, voltype, (char *)aentry, 2,
597 /* returns true if the id is a decimal integer, in which case we interpret
598 * it as an id. make the cache manager much simpler */
600 NameIsId(char *aname)
603 while ((tc = *aname++)) {
604 if (tc > '9' || tc < '0')
610 /* Get a vldb entry given the volume's name; of course, very similar to
611 * VLGetEntryByID() above. */
613 GetEntryByName(struct rx_call *rxcall,
615 char *aentry, /* entry data copied here */
620 afs_int32 blockindex, code;
621 struct nvlentry tentry;
622 char rxstr[AFS_RXINFO_LEN];
624 if (NameIsId(volname)) {
625 return GetEntryByID(rxcall, strtoul(volname, NULL, 10), -1, aentry, new, this_op);
627 if (InvalidVolname(volname))
629 if ((code = Init_VLdbase(&ctx, LOCKREAD, this_op)))
631 VLog(5, ("GetVolumeByName %s (%d) %s\n", volname, new, rxinfo(rxstr, rxcall)));
632 blockindex = FindByName(&ctx, volname, &tentry, &code);
633 if (blockindex == 0) { /* entry not found */
638 if (tentry.flags & VLDELETED) { /* Entry is deleted */
639 code = VL_ENTDELETED;
642 /* Convert to external entry representation */
644 code = vlentry_to_nvldbentry(&ctx, &tentry, (struct nvldbentry *)aentry);
646 code = vlentry_to_uvldbentry(&ctx, &tentry, (struct uvldbentry *)aentry);
648 code = vlentry_to_vldbentry(&ctx, &tentry, (struct vldbentry *)aentry);
653 return (ubik_EndTrans(ctx.trans));
657 ubik_AbortTrans(ctx.trans);
663 SVL_GetEntryByNameO(struct rx_call *rxcall,
665 struct vldbentry *aentry) /* entry data copied here */
667 return (GetEntryByName(rxcall, volname, (char *)aentry, 0,
672 SVL_GetEntryByNameN(struct rx_call *rxcall,
674 struct nvldbentry *aentry) /* entry data copied here */
676 return (GetEntryByName(rxcall, volname, (char *)aentry, 1,
681 SVL_GetEntryByNameU(struct rx_call *rxcall,
683 struct uvldbentry *aentry) /* entry data copied here */
685 return (GetEntryByName(rxcall, volname, (char *)aentry, 2,
689 /* Get the current value of the maximum volume id and bump the volume id counter by Maxvolidbump. */
691 getNewVolumeId(struct rx_call *rxcall, afs_uint32 Maxvolidbump,
692 afs_uint32 *newvolumeid)
694 int this_op = VLGETNEWVOLUMEID;
696 afs_uint32 maxvolumeid;
698 char rxstr[AFS_RXINFO_LEN];
700 countRequest(this_op);
701 if (!afsconf_SuperUser(vldb_confdir, rxcall, NULL))
704 if (Maxvolidbump > MAXBUMPCOUNT)
705 return VL_BADVOLIDBUMP;
707 if ((code = Init_VLdbase(&ctx, LOCKWRITE, this_op)))
710 *newvolumeid = maxvolumeid = NextUnusedID(&ctx,
711 ntohl(ctx.cheader->vital_header.MaxVolumeId), Maxvolidbump, &code);
716 maxvolumeid += Maxvolidbump;
717 VLog(1, ("GetNewVolid newmax=%u %s\n", maxvolumeid, rxinfo(rxstr, rxcall)));
718 ctx.cheader->vital_header.MaxVolumeId = htonl(maxvolumeid);
719 if (write_vital_vlheader(&ctx)) {
722 return ubik_EndTrans(ctx.trans);
726 ubik_AbortTrans(ctx.trans);
731 SVL_GetNewVolumeId(struct rx_call *rxcall, afs_uint32 Maxvolidbump,
732 afs_uint32 *newvolumeid)
736 code = getNewVolumeId(rxcall, Maxvolidbump, newvolumeid);
737 osi_auditU(rxcall, VLGetNewVolumeIdEvent, code, AUD_END);
742 /* Simple replace the contents of the vldb entry, volid, with
743 * newentry. No individual checking/updating per field (alike
744 * VLUpdateEntry) is done. */
747 ReplaceEntry(struct rx_call *rxcall, afs_uint32 volid, afs_int32 voltype,
748 struct vldbentry *newentry, afs_int32 releasetype)
750 int this_op = VLREPLACEENTRY;
752 afs_int32 blockindex, code, typeindex;
754 int hashVol[MAXTYPES];
755 struct nvlentry tentry;
756 afs_uint32 checkids[MAXTYPES];
757 char rxstr[AFS_RXINFO_LEN];
759 countRequest(this_op);
760 for (typeindex = 0; typeindex < MAXTYPES; typeindex++)
761 hashVol[typeindex] = 0;
763 if (!afsconf_SuperUser(vldb_confdir, rxcall, NULL))
766 if ((code = check_vldbentry(newentry)))
769 if (voltype != -1 && InvalidVoltype(voltype))
770 return VL_BADVOLTYPE;
772 if (releasetype && InvalidReleasetype(releasetype))
773 return VL_BADRELLOCKTYPE;
774 if ((code = Init_VLdbase(&ctx, LOCKWRITE, this_op)))
777 VLog(1, ("OReplace Volume %u %s\n", volid, rxinfo(rxstr, rxcall)));
778 /* find vlentry we're changing */
779 blockindex = FindByID(&ctx, volid, voltype, &tentry, &code);
780 if (blockindex == 0) { /* entry not found */
786 /* check that we're not trying to change the RW vol ID */
787 if (newentry->volumeId[RWVOL] != tentry.volumeId[RWVOL]) {
791 /* make sure none of the IDs we are changing to are already in use */
792 memset(&checkids, 0, sizeof(checkids));
793 for (typeindex = ROVOL; typeindex < MAXTYPES; typeindex++) {
794 if (tentry.volumeId[typeindex] != newentry->volumeId[typeindex]) {
795 checkids[typeindex] = newentry->volumeId[typeindex];
798 if (EntryIDExists(&ctx, checkids, MAXTYPES, &code)) {
804 /* make sure the name we're changing to doesn't already exist */
805 if (strcmp(newentry->name, tentry.name)) {
806 struct nvlentry tmp_entry;
807 if (FindByName(&ctx, newentry->name, &tmp_entry, &code)) {
814 /* unhash volid entries if they're disappearing or changing.
815 * Remember if we need to hash in the new value (we don't have to
816 * rehash if volid stays same */
817 for (typeindex = ROVOL; typeindex <= BACKVOL; typeindex++) {
818 if (tentry.volumeId[typeindex] != newentry->volumeId[typeindex]) {
819 if (tentry.volumeId[typeindex])
821 UnhashVolid(&ctx, typeindex, blockindex, &tentry))) {
824 /* we must rehash new id if the id is different and the ID is nonzero */
825 hashVol[typeindex] = 1; /* must rehash this guy if he exists */
829 /* Rehash volname if it changes */
830 if (strcmp(newentry->name, tentry.name)) { /* Name changes; redo hashing */
831 if ((code = UnhashVolname(&ctx, blockindex, &tentry))) {
837 /* after this, tentry is new entry, not old one. vldbentry_to_vlentry
838 * doesn't touch hash chains */
839 if ((code = vldbentry_to_vlentry(&ctx, newentry, &tentry))) {
843 for (typeindex = ROVOL; typeindex <= BACKVOL; typeindex++) {
844 if (hashVol[typeindex] && tentry.volumeId[typeindex]) {
845 if ((code = HashVolid(&ctx, typeindex, blockindex, &tentry))) {
852 HashVolname(&ctx, blockindex, &tentry);
855 ReleaseEntry(&tentry, releasetype); /* Unlock entry if necessary */
856 if (vlentrywrite(ctx.trans, blockindex, &tentry, sizeof(tentry))) {
860 return ubik_EndTrans(ctx.trans);
864 ubik_AbortTrans(ctx.trans);
869 SVL_ReplaceEntry(struct rx_call *rxcall, afs_uint32 volid, afs_int32 voltype,
870 struct vldbentry *newentry, afs_int32 releasetype)
874 code = ReplaceEntry(rxcall, volid, voltype, newentry, releasetype);
875 osi_auditU(rxcall, VLReplaceVLEntryEvent, code, AUD_LONG, volid, AUD_END);
880 ReplaceEntryN(struct rx_call *rxcall, afs_uint32 volid, afs_int32 voltype,
881 struct nvldbentry *newentry, afs_int32 releasetype)
883 int this_op = VLREPLACEENTRYN;
885 afs_int32 blockindex, code, typeindex;
887 int hashVol[MAXTYPES];
888 struct nvlentry tentry;
889 char rxstr[AFS_RXINFO_LEN];
891 countRequest(this_op);
892 for (typeindex = 0; typeindex < MAXTYPES; typeindex++)
893 hashVol[typeindex] = 0;
895 if (!afsconf_SuperUser(vldb_confdir, rxcall, NULL))
898 if ((code = check_nvldbentry(newentry)))
901 if (voltype != -1 && InvalidVoltype(voltype))
902 return VL_BADVOLTYPE;
904 if (releasetype && InvalidReleasetype(releasetype))
905 return VL_BADRELLOCKTYPE;
906 if ((code = Init_VLdbase(&ctx, LOCKWRITE, this_op)))
909 VLog(1, ("Replace Volume %u %s\n", volid, rxinfo(rxstr, rxcall)));
910 /* find vlentry we're changing */
911 blockindex = FindByID(&ctx, volid, voltype, &tentry, &code);
912 if (blockindex == 0) { /* entry not found */
918 /* check that we're not trying to change the RW vol ID */
919 if (newentry->volumeId[RWVOL] != tentry.volumeId[RWVOL]) {
923 /* unhash volid entries if they're disappearing or changing.
924 * Remember if we need to hash in the new value (we don't have to
925 * rehash if volid stays same */
926 for (typeindex = ROVOL; typeindex <= BACKVOL; typeindex++) {
927 if (tentry.volumeId[typeindex] != newentry->volumeId[typeindex]) {
928 if (tentry.volumeId[typeindex])
930 UnhashVolid(&ctx, typeindex, blockindex, &tentry))) {
933 /* we must rehash new id if the id is different and the ID is nonzero */
934 hashVol[typeindex] = 1; /* must rehash this guy if he exists */
938 /* Rehash volname if it changes */
939 if (strcmp(newentry->name, tentry.name)) { /* Name changes; redo hashing */
940 if ((code = UnhashVolname(&ctx, blockindex, &tentry))) {
946 /* after this, tentry is new entry, not old one. vldbentry_to_vlentry
947 * doesn't touch hash chains */
948 if ((code = nvldbentry_to_vlentry(&ctx, newentry, &tentry))) {
952 for (typeindex = ROVOL; typeindex <= BACKVOL; typeindex++) {
953 if (hashVol[typeindex] && tentry.volumeId[typeindex]) {
954 if ((code = HashVolid(&ctx, typeindex, blockindex, &tentry))) {
961 HashVolname(&ctx, blockindex, &tentry);
964 ReleaseEntry(&tentry, releasetype); /* Unlock entry if necessary */
965 if (vlentrywrite(ctx.trans, blockindex, &tentry, sizeof(tentry))) {
969 return ubik_EndTrans(ctx.trans);
973 ubik_AbortTrans(ctx.trans);
978 SVL_ReplaceEntryN(struct rx_call *rxcall, afs_uint32 volid, afs_int32 voltype,
979 struct nvldbentry *newentry, afs_int32 releasetype)
983 code = ReplaceEntryN(rxcall, volid, voltype, newentry, releasetype);
984 osi_auditU(rxcall, VLReplaceVLEntryEvent, code, AUD_LONG, volid, AUD_END);
989 /* Update a vldb entry (accessed thru its volume id). Almost all of the
990 * entry's fields can be modified in a single call by setting the
991 * appropriate bits in the Mask field in VldbUpdateentry. */
992 /* this routine may never have been tested; use replace entry instead
993 * unless you're brave */
995 UpdateEntry(struct rx_call *rxcall,
998 struct VldbUpdateEntry *updateentry, /* Update entry copied here */
999 afs_int32 releasetype)
1001 int this_op = VLUPDATEENTRY;
1003 afs_int32 blockindex, code;
1004 struct nvlentry tentry;
1005 char rxstr[AFS_RXINFO_LEN];
1007 countRequest(this_op);
1008 if (!afsconf_SuperUser(vldb_confdir, rxcall, NULL))
1010 if ((voltype != -1) && (InvalidVoltype(voltype)))
1011 return VL_BADVOLTYPE;
1012 if (releasetype && InvalidReleasetype(releasetype))
1013 return VL_BADRELLOCKTYPE;
1014 if ((code = Init_VLdbase(&ctx, LOCKWRITE, this_op)))
1017 VLog(1, ("Update Volume %u %s\n", volid, rxinfo(rxstr, rxcall)));
1018 blockindex = FindByID(&ctx, volid, voltype, &tentry, &code);
1019 if (blockindex == 0) { /* entry not found */
1025 /* Do the actual updating of the entry, tentry. */
1027 get_vldbupdateentry(&ctx, blockindex, updateentry, &tentry))) {
1031 ReleaseEntry(&tentry, releasetype); /* Unlock entry if necessary */
1032 if (vlentrywrite(ctx.trans, blockindex, &tentry, sizeof(tentry))) {
1035 return ubik_EndTrans(ctx.trans);
1038 countAbort(this_op);
1039 ubik_AbortTrans(ctx.trans);
1044 SVL_UpdateEntry(struct rx_call *rxcall,
1047 struct VldbUpdateEntry *updateentry,
1048 afs_int32 releasetype)
1052 code = UpdateEntry(rxcall, volid, voltype, updateentry, releasetype);
1053 osi_auditU(rxcall, VLUpdateEntryEvent, code, AUD_LONG, volid, AUD_END);
1058 UpdateEntryByName(struct rx_call *rxcall,
1060 struct VldbUpdateEntry *updateentry, /* Update entry copied here */
1061 afs_int32 releasetype)
1063 int this_op = VLUPDATEENTRYBYNAME;
1065 afs_int32 blockindex, code;
1066 struct nvlentry tentry;
1068 countRequest(this_op);
1069 if (!afsconf_SuperUser(vldb_confdir, rxcall, NULL))
1071 if (releasetype && InvalidReleasetype(releasetype))
1072 return VL_BADRELLOCKTYPE;
1073 if ((code = Init_VLdbase(&ctx, LOCKWRITE, this_op)))
1076 blockindex = FindByName(&ctx, volname, &tentry, &code);
1077 if (blockindex == 0) { /* entry not found */
1083 /* Do the actual updating of the entry, tentry. */
1085 get_vldbupdateentry(&ctx, blockindex, updateentry, &tentry))) {
1089 ReleaseEntry(&tentry, releasetype); /* Unlock entry if necessary */
1090 if (vlentrywrite(ctx.trans, blockindex, &tentry, sizeof(tentry))) {
1093 return ubik_EndTrans(ctx.trans);
1096 countAbort(this_op);
1097 ubik_AbortTrans(ctx.trans);
1102 SVL_UpdateEntryByName(struct rx_call *rxcall,
1104 struct VldbUpdateEntry *updateentry, /* Update entry copied here */
1105 afs_int32 releasetype)
1109 code = UpdateEntryByName(rxcall, volname, updateentry, releasetype);
1110 osi_auditU(rxcall, VLUpdateEntryEvent, code, AUD_LONG, -1, AUD_END);
1114 /* Set a lock to the vldb entry for volid (of type voltype if not -1). */
1116 SetLock(struct rx_call *rxcall, afs_uint32 volid, afs_int32 voltype,
1119 int this_op = VLSETLOCK;
1120 afs_int32 timestamp, blockindex, code;
1122 struct nvlentry tentry;
1123 char rxstr[AFS_RXINFO_LEN];
1125 countRequest(this_op);
1126 if (!afsconf_SuperUser(vldb_confdir, rxcall, NULL))
1128 if ((voltype != -1) && (InvalidVoltype(voltype)))
1129 return VL_BADVOLTYPE;
1130 if (InvalidOperation(voloper))
1131 return VL_BADVOLOPER;
1132 if ((code = Init_VLdbase(&ctx, LOCKWRITE, this_op)))
1135 VLog(1, ("SetLock Volume %u %s\n", volid, rxinfo(rxstr, rxcall)));
1136 blockindex = FindByID(&ctx, volid, voltype, &tentry, &code);
1137 if (blockindex == NULLO) {
1142 if (tentry.flags & VLDELETED) {
1143 ABORT(VL_ENTDELETED);
1145 timestamp = FT_ApproxTime();
1147 /* Check if entry is already locked; note that we unlock any entry
1148 * locked more than MAXLOCKTIME seconds */
1149 if ((tentry.LockTimestamp)
1150 && ((timestamp - tentry.LockTimestamp) < MAXLOCKTIME)) {
1151 ABORT(VL_ENTRYLOCKED);
1154 /* Consider it an unlocked entry: set current timestamp, caller
1155 * and active vol operation */
1156 tentry.LockTimestamp = timestamp;
1157 tentry.LockAfsId = 0; /* Not implemented yet */
1158 if (tentry.flags & VLOP_RELEASE) {
1159 ABORT(VL_RERELEASE);
1161 tentry.flags &= ~VLOP_ALLOPERS; /* Clear any possible older operation bit */
1162 tentry.flags |= voloper;
1164 if (vlentrywrite(ctx.trans, blockindex, &tentry, sizeof(tentry))) {
1167 return ubik_EndTrans(ctx.trans);
1170 countAbort(this_op);
1171 ubik_AbortTrans(ctx.trans);
1176 SVL_SetLock(struct rx_call *rxcall, afs_uint32 volid, afs_int32 voltype,
1181 code = SetLock(rxcall, volid, voltype, voloper);
1182 osi_auditU(rxcall, VLSetLockEvent, code, AUD_LONG, volid, AUD_END);
1186 /* Release an already locked vldb entry. Releasetype determines what
1187 * fields (afsid and/or volume operation) will be cleared along with
1188 * the lock time stamp. */
1191 ReleaseLock(struct rx_call *rxcall, afs_uint32 volid, afs_int32 voltype,
1192 afs_int32 releasetype)
1194 int this_op = VLRELEASELOCK;
1195 afs_int32 blockindex, code;
1197 struct nvlentry tentry;
1198 char rxstr[AFS_RXINFO_LEN];
1200 countRequest(this_op);
1201 if (!afsconf_SuperUser(vldb_confdir, rxcall, NULL))
1203 if ((voltype != -1) && (InvalidVoltype(voltype)))
1204 return VL_BADVOLTYPE;
1205 if (releasetype && InvalidReleasetype(releasetype))
1206 return VL_BADRELLOCKTYPE;
1207 if ((code = Init_VLdbase(&ctx, LOCKWRITE, this_op)))
1210 VLog(1, ("ReleaseLock Volume %u %s\n", volid, rxinfo(rxstr, rxcall)));
1211 blockindex = FindByID(&ctx, volid, voltype, &tentry, &code);
1212 if (blockindex == NULLO) {
1217 if (tentry.flags & VLDELETED) {
1218 ABORT(VL_ENTDELETED);
1221 ReleaseEntry(&tentry, releasetype); /* Unlock the appropriate fields */
1222 if (vlentrywrite(ctx.trans, blockindex, &tentry, sizeof(tentry))) {
1225 return ubik_EndTrans(ctx.trans);
1228 countAbort(this_op);
1229 ubik_AbortTrans(ctx.trans);
1234 SVL_ReleaseLock(struct rx_call *rxcall, afs_uint32 volid, afs_int32 voltype,
1235 afs_int32 releasetype)
1239 code = ReleaseLock(rxcall, volid, voltype, releasetype);
1240 osi_auditU(rxcall, VLReleaseLockEvent, code, AUD_LONG, volid, AUD_END);
1244 /* ListEntry returns a single vldb entry, aentry, with offset previous_index;
1245 * the remaining parameters (i.e. next_index) are used so that sequential
1246 * calls to this routine will get the next (all) vldb entries.
1249 ListEntry(struct rx_call *rxcall, afs_int32 previous_index,
1250 afs_int32 *count, afs_int32 *next_index,
1251 struct vldbentry *aentry)
1253 int this_op = VLLISTENTRY;
1256 struct nvlentry tentry;
1257 char rxstr[AFS_RXINFO_LEN];
1259 countRequest(this_op);
1261 if (!afsconf_CheckRestrictedQuery(vldb_confdir, rxcall,
1262 restrictedQueryLevel))
1265 if ((code = Init_VLdbase(&ctx, LOCKREAD, this_op)))
1267 VLog(25, ("OListEntry index=%d %s\n", previous_index,
1268 rxinfo(rxstr, rxcall)));
1269 *next_index = NextEntry(&ctx, previous_index, &tentry, count);
1271 code = vlentry_to_vldbentry(&ctx, &tentry, aentry);
1273 countAbort(this_op);
1274 ubik_AbortTrans(ctx.trans);
1278 return ubik_EndTrans(ctx.trans);
1282 SVL_ListEntry(struct rx_call *rxcall, afs_int32 previous_index,
1283 afs_int32 *count, afs_int32 *next_index,
1284 struct vldbentry *aentry)
1288 code = ListEntry(rxcall, previous_index, count, next_index, aentry);
1289 osi_auditU(rxcall, VLListEntryEvent, code, AUD_LONG, previous_index, AUD_END);
1293 /* ListEntry returns a single vldb entry, aentry, with offset previous_index;
1294 * the remaining parameters (i.e. next_index) are used so that sequential
1295 * calls to this routine will get the next (all) vldb entries.
1298 ListEntryN(struct rx_call *rxcall, afs_int32 previous_index,
1299 afs_int32 *count, afs_int32 *next_index,
1300 struct nvldbentry *aentry)
1302 int this_op = VLLISTENTRYN;
1305 struct nvlentry tentry;
1306 char rxstr[AFS_RXINFO_LEN];
1308 countRequest(this_op);
1310 if (!afsconf_CheckRestrictedQuery(vldb_confdir, rxcall,
1311 restrictedQueryLevel))
1314 if ((code = Init_VLdbase(&ctx, LOCKREAD, this_op)))
1316 VLog(25, ("ListEntry index=%d %s\n", previous_index, rxinfo(rxstr, rxcall)));
1317 *next_index = NextEntry(&ctx, previous_index, &tentry, count);
1319 code = vlentry_to_nvldbentry(&ctx, &tentry, aentry);
1321 countAbort(this_op);
1322 ubik_AbortTrans(ctx.trans);
1327 return ubik_EndTrans(ctx.trans);
1331 SVL_ListEntryN(struct rx_call *rxcall, afs_int32 previous_index,
1332 afs_int32 *count, afs_int32 *next_index,
1333 struct nvldbentry *aentry)
1337 code = ListEntryN(rxcall, previous_index, count, next_index, aentry);
1338 osi_auditU(rxcall, VLListEntryEventN, code, AUD_LONG, previous_index, AUD_END);
1342 /* Retrieves in vldbentries all vldb entries that match the specified
1343 * attributes (by server number, partition, volume type, and flag); if volume
1344 * id is specified then the associated list for that entry is returned.
1345 * CAUTION: This could be a very expensive call since in most cases
1346 * sequential search of all vldb entries is performed.
1349 ListAttributes(struct rx_call *rxcall,
1350 struct VldbListByAttributes *attributes,
1351 afs_int32 *nentries,
1352 bulkentries *vldbentries)
1354 int this_op = VLLISTATTRIBUTES;
1355 int code, allocCount = 0;
1357 struct nvlentry tentry;
1358 struct vldbentry *Vldbentry = 0, *VldbentryFirst = 0, *VldbentryLast = 0;
1360 char rxstr[AFS_RXINFO_LEN];
1362 countRequest(this_op);
1364 if (!afsconf_CheckRestrictedQuery(vldb_confdir, rxcall,
1365 restrictedQueryLevel))
1368 vldbentries->bulkentries_val = 0;
1369 vldbentries->bulkentries_len = *nentries = 0;
1370 if ((code = Init_VLdbase(&ctx, LOCKREAD, this_op)))
1372 allocCount = VLDBALLOCCOUNT;
1373 Vldbentry = VldbentryFirst = vldbentries->bulkentries_val =
1374 malloc(allocCount * sizeof(vldbentry));
1375 if (Vldbentry == NULL) {
1379 VldbentryLast = VldbentryFirst + allocCount;
1380 /* Handle the attribute by volume id totally separate of the rest
1381 * (thus additional Mask values are ignored if VLLIST_VOLUMEID is set!) */
1382 if (attributes->Mask & VLLIST_VOLUMEID) {
1383 afs_int32 blockindex;
1386 FindByID(&ctx, attributes->volumeid, -1, &tentry, &code);
1387 if (blockindex == 0) {
1393 code = put_attributeentry(&ctx, &Vldbentry, &VldbentryFirst,
1394 &VldbentryLast, vldbentries, &tentry,
1395 nentries, &allocCount);
1399 afs_int32 nextblockindex = 0, count = 0, k = 0, match = 0;
1400 while ((nextblockindex =
1401 NextEntry(&ctx, nextblockindex, &tentry, &count))) {
1402 if (++pollcount > 50) {
1403 #ifndef AFS_PTHREAD_ENV
1409 if (attributes->Mask & VLLIST_SERVER) {
1412 IpAddrToRelAddr(&ctx, attributes->server, 0)) == -1)
1414 for (k = 0; k < OMAXNSERVERS; k++) {
1415 if (tentry.serverNumber[k] == BADSERVERID)
1417 if (tentry.serverNumber[k] == serverindex) {
1425 if (attributes->Mask & VLLIST_PARTITION) {
1427 if (tentry.serverPartition[k] != attributes->partition)
1430 for (k = 0; k < OMAXNSERVERS; k++) {
1431 if (tentry.serverNumber[k] == BADSERVERID)
1433 if (tentry.serverPartition[k] ==
1434 attributes->partition) {
1444 if (attributes->Mask & VLLIST_FLAG) {
1445 if (!(tentry.flags & attributes->flag))
1448 code = put_attributeentry(&ctx, &Vldbentry, &VldbentryFirst,
1449 &VldbentryLast, vldbentries, &tentry,
1450 nentries, &allocCount);
1455 if (vldbentries->bulkentries_len
1456 && (allocCount > vldbentries->bulkentries_len)) {
1458 vldbentries->bulkentries_val =
1459 realloc(vldbentries->bulkentries_val,
1460 vldbentries->bulkentries_len * sizeof(vldbentry));
1461 if (vldbentries->bulkentries_val == NULL) {
1467 ("ListAttrs nentries=%d %s\n", vldbentries->bulkentries_len,
1468 rxinfo(rxstr, rxcall)));
1469 return ubik_EndTrans(ctx.trans);
1472 if (vldbentries->bulkentries_val)
1473 free(vldbentries->bulkentries_val);
1474 vldbentries->bulkentries_val = 0;
1475 vldbentries->bulkentries_len = 0;
1477 countAbort(this_op);
1478 ubik_AbortTrans(ctx.trans);
1483 SVL_ListAttributes(struct rx_call *rxcall,
1484 struct VldbListByAttributes *attributes,
1485 afs_int32 *nentries,
1486 bulkentries *vldbentries)
1490 code = ListAttributes(rxcall, attributes, nentries, vldbentries);
1491 osi_auditU(rxcall, VLListAttributesEvent, code, AUD_END);
1496 ListAttributesN(struct rx_call *rxcall,
1497 struct VldbListByAttributes *attributes,
1498 afs_int32 *nentries,
1499 nbulkentries *vldbentries)
1501 int this_op = VLLISTATTRIBUTESN;
1502 int code, allocCount = 0;
1504 struct nvlentry tentry;
1505 struct nvldbentry *Vldbentry = 0, *VldbentryFirst = 0, *VldbentryLast = 0;
1507 char rxstr[AFS_RXINFO_LEN];
1509 countRequest(this_op);
1511 if (!afsconf_CheckRestrictedQuery(vldb_confdir, rxcall,
1512 restrictedQueryLevel))
1515 vldbentries->nbulkentries_val = 0;
1516 vldbentries->nbulkentries_len = *nentries = 0;
1517 if ((code = Init_VLdbase(&ctx, LOCKREAD, this_op)))
1519 allocCount = VLDBALLOCCOUNT;
1520 Vldbentry = VldbentryFirst = vldbentries->nbulkentries_val =
1521 malloc(allocCount * sizeof(nvldbentry));
1522 if (Vldbentry == NULL) {
1526 VldbentryLast = VldbentryFirst + allocCount;
1527 /* Handle the attribute by volume id totally separate of the rest
1528 * (thus additional Mask values are ignored if VLLIST_VOLUMEID is set!) */
1529 if (attributes->Mask & VLLIST_VOLUMEID) {
1530 afs_int32 blockindex;
1533 FindByID(&ctx, attributes->volumeid, -1, &tentry, &code);
1534 if (blockindex == 0) {
1540 code = put_nattributeentry(&ctx, &Vldbentry, &VldbentryFirst,
1541 &VldbentryLast, vldbentries, &tentry,
1542 0, 0, nentries, &allocCount);
1546 afs_int32 nextblockindex = 0, count = 0, k = 0, match = 0;
1547 while ((nextblockindex =
1548 NextEntry(&ctx, nextblockindex, &tentry, &count))) {
1549 if (++pollcount > 50) {
1550 #ifndef AFS_PTHREAD_ENV
1557 if (attributes->Mask & VLLIST_SERVER) {
1560 IpAddrToRelAddr(&ctx, attributes->server, 0)) == -1)
1562 for (k = 0; k < NMAXNSERVERS; k++) {
1563 if (tentry.serverNumber[k] == BADSERVERID)
1565 if (tentry.serverNumber[k] == serverindex) {
1573 if (attributes->Mask & VLLIST_PARTITION) {
1575 if (tentry.serverPartition[k] != attributes->partition)
1578 for (k = 0; k < NMAXNSERVERS; k++) {
1579 if (tentry.serverNumber[k] == BADSERVERID)
1581 if (tentry.serverPartition[k] ==
1582 attributes->partition) {
1592 if (attributes->Mask & VLLIST_FLAG) {
1593 if (!(tentry.flags & attributes->flag))
1596 code = put_nattributeentry(&ctx, &Vldbentry, &VldbentryFirst,
1597 &VldbentryLast, vldbentries,
1598 &tentry, 0, 0, nentries, &allocCount);
1603 if (vldbentries->nbulkentries_len
1604 && (allocCount > vldbentries->nbulkentries_len)) {
1606 vldbentries->nbulkentries_val =
1607 realloc(vldbentries->nbulkentries_val,
1608 vldbentries->nbulkentries_len * sizeof(nvldbentry));
1609 if (vldbentries->nbulkentries_val == NULL) {
1615 ("NListAttrs nentries=%d %s\n", vldbentries->nbulkentries_len,
1616 rxinfo(rxstr, rxcall)));
1617 return ubik_EndTrans(ctx.trans);
1620 countAbort(this_op);
1621 ubik_AbortTrans(ctx.trans);
1622 if (vldbentries->nbulkentries_val)
1623 free(vldbentries->nbulkentries_val);
1624 vldbentries->nbulkentries_val = 0;
1625 vldbentries->nbulkentries_len = 0;
1630 SVL_ListAttributesN(struct rx_call *rxcall,
1631 struct VldbListByAttributes *attributes,
1632 afs_int32 *nentries,
1633 nbulkentries *vldbentries)
1637 code = ListAttributesN(rxcall, attributes, nentries, vldbentries);
1638 osi_auditU(rxcall, VLListAttributesNEvent, code, AUD_END);
1643 ListAttributesN2(struct rx_call *rxcall,
1644 struct VldbListByAttributes *attributes,
1645 char *name, /* Wildcarded volume name */
1646 afs_int32 startindex,
1647 afs_int32 *nentries,
1648 nbulkentries *vldbentries,
1649 afs_int32 *nextstartindex)
1651 int this_op = VLLISTATTRIBUTESN2;
1652 int code = 0, maxCount = VLDBALLOCCOUNT;
1654 struct nvlentry tentry;
1655 struct nvldbentry *Vldbentry = 0, *VldbentryFirst = 0, *VldbentryLast = 0;
1656 afs_int32 blockindex = 0, count = 0, k, match;
1657 afs_int32 matchindex = 0;
1658 int serverindex = -1; /* no server found */
1659 int findserver = 0, findpartition = 0, findflag = 0;
1661 int namematchRWBK, namematchRO, thismatch;
1663 char rxstr[AFS_RXINFO_LEN];
1664 #ifdef HAVE_POSIX_REGEX
1666 int need_regfree = 0;
1671 countRequest(this_op);
1673 if (!afsconf_CheckRestrictedQuery(vldb_confdir, rxcall,
1674 restrictedQueryLevel))
1677 vldbentries->nbulkentries_val = 0;
1678 vldbentries->nbulkentries_len = 0;
1680 *nextstartindex = -1;
1682 code = Init_VLdbase(&ctx, LOCKREAD, this_op);
1686 Vldbentry = VldbentryFirst = vldbentries->nbulkentries_val =
1687 malloc(maxCount * sizeof(nvldbentry));
1688 if (Vldbentry == NULL) {
1689 countAbort(this_op);
1690 ubik_AbortTrans(ctx.trans);
1694 VldbentryLast = VldbentryFirst + maxCount;
1696 /* Handle the attribute by volume id totally separate of the rest
1697 * (thus additional Mask values are ignored if VLLIST_VOLUMEID is set!)
1699 if (attributes->Mask & VLLIST_VOLUMEID) {
1701 FindByID(&ctx, attributes->volumeid, -1, &tentry, &code);
1702 if (blockindex == 0) {
1707 put_nattributeentry(&ctx, &Vldbentry, &VldbentryFirst,
1708 &VldbentryLast, vldbentries, &tentry, 0,
1709 0, nentries, &maxCount);
1715 /* Search each entry in the database and return all entries
1716 * that match the request. It checks entry flags, server, and partition.
1719 /* Get the server index for matching server address */
1720 if (attributes->Mask & VLLIST_SERVER) {
1722 IpAddrToRelAddr(&ctx, attributes->server, 0);
1723 if (serverindex == -1)
1727 findpartition = ((attributes->Mask & VLLIST_PARTITION) ? 1 : 0);
1728 findflag = ((attributes->Mask & VLLIST_FLAG) ? 1 : 0);
1729 if (name && (strcmp(name, ".*") != 0) && (strcmp(name, "") != 0)) {
1730 /* regex-matching code has been disabled for security reasons. */
1735 /* Read each entry and see if it is the one we want */
1736 blockindex = startindex;
1737 while ((blockindex = NextEntry(&ctx, blockindex, &tentry, &count))) {
1738 if (++pollcount > 50) {
1739 #ifndef AFS_PTHREAD_ENV
1745 /* Step through each server index searching for a match.
1746 * Match to an existing RW, BK, or RO volume name (preference
1747 * is in this order). Remember which index we matched against.
1749 namematchRWBK = namematchRO = 0; /* 0->notTried; 1->match; 2->noMatch */
1753 && (tentry.serverNumber[k] != BADSERVERID)); k++) {
1754 thismatch = 0; /* does this index match */
1756 /* Match against the RW or BK volume name. Remember
1757 * results in namematchRWBK. Prefer RW over BK.
1759 if (tentry.serverFlags[k] & VLSF_RWVOL) {
1760 /* Does the name match the RW name */
1761 if (tentry.flags & VLF_RWEXISTS) {
1762 thismatch = VLSF_RWVOL;
1765 /* Does the name match the BK name */
1766 if (!thismatch && (tentry.flags & VLF_BACKEXISTS)) {
1767 thismatch = VLSF_BACKVOL;
1770 namematchRWBK = (thismatch ? 1 : 2);
1773 /* Match with the RO volume name. Compare once and
1774 * remember results in namematchRO. Note that this will
1775 * pick up entries marked NEWREPSITEs and DONTUSE.
1778 if (tentry.flags & VLF_ROEXISTS) {
1779 thismatch = VLSF_ROVOL;
1781 namematchRO = (thismatch ? 1 : 2);
1784 /* Is there a server match */
1785 if (thismatch && findserver
1786 && (tentry.serverNumber[k] != serverindex))
1789 /* Is there a partition match */
1790 if (thismatch && findpartition
1791 && (tentry.serverPartition[k] != attributes->partition))
1794 /* Is there a flag match */
1795 if (thismatch && findflag
1796 && !(tentry.flags & attributes->flag))
1799 /* We found a match. Remember the index, and type */
1803 matchtype = thismatch;
1806 /* Since we prefer RW and BK volume matches over RO matches,
1807 * if we have already checked the RWBK name, then we already
1808 * found the best match and so end the search.
1810 * If we tried matching against the RW, BK, and RO volume names
1811 * and both failed, then we end the search (none will match).
1813 if ((match && namematchRWBK)
1814 || ((namematchRWBK == 2) && (namematchRO == 2)))
1818 /* Passed all the tests. Take it */
1821 put_nattributeentry(&ctx, &Vldbentry, &VldbentryFirst,
1822 &VldbentryLast, vldbentries, &tentry,
1823 matchtype, matchindex, nentries,
1828 if (*nentries >= maxCount)
1829 break; /* collected the max */
1832 *nextstartindex = (blockindex ? blockindex : -1);
1836 #ifdef HAVE_POSIX_REGEX
1842 countAbort(this_op);
1843 ubik_AbortTrans(ctx.trans);
1844 if (vldbentries->nbulkentries_val)
1845 free(vldbentries->nbulkentries_val);
1846 vldbentries->nbulkentries_val = 0;
1847 vldbentries->nbulkentries_len = 0;
1848 *nextstartindex = -1;
1851 ("N2ListAttrs nentries=%d %s\n", vldbentries->nbulkentries_len,
1852 rxinfo(rxstr, rxcall)));
1853 code = ubik_EndTrans(ctx.trans);
1860 SVL_ListAttributesN2(struct rx_call *rxcall,
1861 struct VldbListByAttributes *attributes,
1862 char *name, /* Wildcarded volume name */
1863 afs_int32 startindex,
1864 afs_int32 *nentries,
1865 nbulkentries *vldbentries,
1866 afs_int32 *nextstartindex)
1870 code = ListAttributesN2(rxcall, attributes, name, startindex,
1871 nentries, vldbentries, nextstartindex);
1872 osi_auditU(rxcall, VLListAttributesN2Event, code, AUD_END);
1876 /* Retrieves in vldbentries all vldb entries that match the specified
1877 * attributes (by server number, partition, volume type, and flag); if
1878 * volume id is specified then the associated list for that entry is
1879 * returned. CAUTION: This could be a very expensive call since in most
1880 * cases sequential search of all vldb entries is performed.
1883 LinkedList(struct rx_call *rxcall,
1884 struct VldbListByAttributes *attributes,
1885 afs_int32 *nentries,
1886 vldb_list *vldbentries)
1888 int this_op = VLLINKEDLIST;
1891 struct nvlentry tentry;
1892 vldblist vllist, *vllistptr;
1893 afs_int32 blockindex, count, match;
1898 countRequest(this_op);
1900 if (!afsconf_CheckRestrictedQuery(vldb_confdir, rxcall,
1901 restrictedQueryLevel))
1904 if ((code = Init_VLdbase(&ctx, LOCKREAD, this_op)))
1908 vldbentries->node = NULL;
1909 vllistptr = &vldbentries->node;
1911 /* List by volumeid */
1912 if (attributes->Mask & VLLIST_VOLUMEID) {
1914 FindByID(&ctx, attributes->volumeid, -1, &tentry, &code);
1921 vllist = malloc(sizeof(single_vldbentry));
1922 if (vllist == NULL) {
1926 code = vlentry_to_vldbentry(&ctx, &tentry, &vllist->VldbEntry);
1930 vllist->next_vldb = NULL;
1932 *vllistptr = vllist; /* Thread onto list */
1933 vllistptr = &vllist->next_vldb;
1937 /* Search by server, partition, and flags */
1939 for (blockindex = NextEntry(&ctx, 0, &tentry, &count); blockindex;
1940 blockindex = NextEntry(&ctx, blockindex, &tentry, &count)) {
1943 if (++pollcount > 50) {
1944 #ifndef AFS_PTHREAD_ENV
1950 /* Does this volume exist on the desired server */
1951 if (attributes->Mask & VLLIST_SERVER) {
1953 IpAddrToRelAddr(&ctx, attributes->server, 0);
1954 if (serverindex == -1)
1956 for (k = 0; k < OMAXNSERVERS; k++) {
1957 if (tentry.serverNumber[k] == BADSERVERID)
1959 if (tentry.serverNumber[k] == serverindex) {
1968 /* Does this volume exist on the desired partition */
1969 if (attributes->Mask & VLLIST_PARTITION) {
1971 if (tentry.serverPartition[k] != attributes->partition)
1974 for (k = 0; k < OMAXNSERVERS; k++) {
1975 if (tentry.serverNumber[k] == BADSERVERID)
1977 if (tentry.serverPartition[k] ==
1978 attributes->partition) {
1988 /* Does this volume have the desired flags */
1989 if (attributes->Mask & VLLIST_FLAG) {
1990 if (!(tentry.flags & attributes->flag))
1994 vllist = malloc(sizeof(single_vldbentry));
1995 if (vllist == NULL) {
1999 code = vlentry_to_vldbentry(&ctx, &tentry, &vllist->VldbEntry);
2003 vllist->next_vldb = NULL;
2005 *vllistptr = vllist; /* Thread onto list */
2006 vllistptr = &vllist->next_vldb;
2008 if (smallMem && (*nentries >= VLDBALLOCCOUNT)) {
2009 code = VL_SIZEEXCEEDED;
2015 return ubik_EndTrans(ctx.trans);
2018 countAbort(this_op);
2019 ubik_AbortTrans(ctx.trans);
2024 SVL_LinkedList(struct rx_call *rxcall,
2025 struct VldbListByAttributes *attributes,
2026 afs_int32 *nentries,
2027 vldb_list *vldbentries)
2031 code = LinkedList(rxcall, attributes, nentries, vldbentries);
2032 osi_auditU(rxcall, VLLinkedListEvent, code, AUD_END);
2037 LinkedListN(struct rx_call *rxcall,
2038 struct VldbListByAttributes *attributes,
2039 afs_int32 *nentries,
2040 nvldb_list *vldbentries)
2042 int this_op = VLLINKEDLISTN;
2045 struct nvlentry tentry;
2046 nvldblist vllist, *vllistptr;
2047 afs_int32 blockindex, count, match;
2052 countRequest(this_op);
2054 if (!afsconf_CheckRestrictedQuery(vldb_confdir, rxcall,
2055 restrictedQueryLevel))
2058 if ((code = Init_VLdbase(&ctx, LOCKREAD, this_op)))
2062 vldbentries->node = NULL;
2063 vllistptr = &vldbentries->node;
2065 /* List by volumeid */
2066 if (attributes->Mask & VLLIST_VOLUMEID) {
2068 FindByID(&ctx, attributes->volumeid, -1, &tentry, &code);
2075 vllist = malloc(sizeof(single_nvldbentry));
2076 if (vllist == NULL) {
2080 code = vlentry_to_nvldbentry(&ctx, &tentry, &vllist->VldbEntry);
2084 vllist->next_vldb = NULL;
2086 *vllistptr = vllist; /* Thread onto list */
2087 vllistptr = &vllist->next_vldb;
2091 /* Search by server, partition, and flags */
2093 for (blockindex = NextEntry(&ctx, 0, &tentry, &count); blockindex;
2094 blockindex = NextEntry(&ctx, blockindex, &tentry, &count)) {
2097 if (++pollcount > 50) {
2098 #ifndef AFS_PTHREAD_ENV
2104 /* Does this volume exist on the desired server */
2105 if (attributes->Mask & VLLIST_SERVER) {
2107 IpAddrToRelAddr(&ctx, attributes->server, 0);
2108 if (serverindex == -1)
2110 for (k = 0; k < NMAXNSERVERS; k++) {
2111 if (tentry.serverNumber[k] == BADSERVERID)
2113 if (tentry.serverNumber[k] == serverindex) {
2122 /* Does this volume exist on the desired partition */
2123 if (attributes->Mask & VLLIST_PARTITION) {
2125 if (tentry.serverPartition[k] != attributes->partition)
2128 for (k = 0; k < NMAXNSERVERS; k++) {
2129 if (tentry.serverNumber[k] == BADSERVERID)
2131 if (tentry.serverPartition[k] ==
2132 attributes->partition) {
2142 /* Does this volume have the desired flags */
2143 if (attributes->Mask & VLLIST_FLAG) {
2144 if (!(tentry.flags & attributes->flag))
2148 vllist = malloc(sizeof(single_nvldbentry));
2149 if (vllist == NULL) {
2153 code = vlentry_to_nvldbentry(&ctx, &tentry, &vllist->VldbEntry);
2157 vllist->next_vldb = NULL;
2159 *vllistptr = vllist; /* Thread onto list */
2160 vllistptr = &vllist->next_vldb;
2162 if (smallMem && (*nentries >= VLDBALLOCCOUNT)) {
2163 code = VL_SIZEEXCEEDED;
2169 return ubik_EndTrans(ctx.trans);
2172 countAbort(this_op);
2173 ubik_AbortTrans(ctx.trans);
2178 SVL_LinkedListN(struct rx_call *rxcall,
2179 struct VldbListByAttributes *attributes,
2180 afs_int32 *nentries,
2181 nvldb_list *vldbentries)
2185 code = LinkedListN(rxcall, attributes, nentries, vldbentries);
2186 osi_auditU(rxcall, VLLinkedListNEvent, code, AUD_END);
2190 /* Get back vldb header statistics (allocs, frees, maxvolumeid,
2191 * totalentries, etc) and dynamic statistics (number of requests and/or
2192 * aborts per remote procedure call, etc)
2195 GetStats(struct rx_call *rxcall,
2197 vital_vlheader *vital_header)
2199 int this_op = VLGETSTATS;
2202 char rxstr[AFS_RXINFO_LEN];
2204 countRequest(this_op);
2206 if (!afsconf_CheckRestrictedQuery(vldb_confdir, rxcall,
2207 restrictedQueryLevel))
2210 if ((code = Init_VLdbase(&ctx, LOCKREAD, this_op)))
2212 VLog(5, ("GetStats %s\n", rxinfo(rxstr, rxcall)));
2213 memcpy((char *)vital_header, (char *)&ctx.cheader->vital_header,
2214 sizeof(vital_vlheader));
2215 memcpy((char *)stats, (char *)&dynamic_statistics, sizeof(vldstats));
2216 return ubik_EndTrans(ctx.trans);
2220 SVL_GetStats(struct rx_call *rxcall,
2222 vital_vlheader *vital_header)
2226 code = GetStats(rxcall, stats, vital_header);
2227 osi_auditU(rxcall, VLGetStatsEvent, code, AUD_END);
2231 /* Get the list of file server addresses from the VLDB. Currently it's pretty
2232 * easy to do. In the future, it might require a little bit of grunging
2233 * through the VLDB, but that's life.
2236 SVL_GetAddrs(struct rx_call *rxcall,
2239 struct VLCallBack *spare3,
2240 afs_int32 *nentries,
2243 int this_op = VLGETADDRS;
2249 countRequest(this_op);
2250 addrsp->bulkaddrs_len = *nentries = 0;
2251 addrsp->bulkaddrs_val = 0;
2252 memset(spare3, 0, sizeof(struct VLCallBack));
2254 if ((code = Init_VLdbase(&ctx, LOCKREAD, this_op)))
2257 VLog(5, ("GetAddrs\n"));
2258 addrsp->bulkaddrs_val = taddrp =
2259 malloc(sizeof(afs_uint32) * (MAXSERVERID + 1));
2260 nservers = *nentries = addrsp->bulkaddrs_len = 0;
2267 for (i = 0; i <= MAXSERVERID; i++) {
2268 if ((*taddrp = ntohl(ctx.cheader->IpMappedAddr[i]))) {
2274 addrsp->bulkaddrs_len = *nentries = nservers;
2275 return (ubik_EndTrans(ctx.trans));
2278 countAbort(this_op);
2279 ubik_AbortTrans(ctx.trans);
2284 append_addr(char *buffer, afs_uint32 addr, size_t buffer_size)
2286 int n = strlen(buffer);
2287 if (buffer_size > n) {
2288 snprintf(buffer + n, buffer_size - n, "%u.%u.%u.%u",
2289 (addr >> 24) & 0xff, (addr >> 16) & 0xff, (addr >> 8) & 0xff,
2295 SVL_RegisterAddrs(struct rx_call *rxcall, afsUUID *uuidp, afs_int32 spare1,
2298 int this_op = VLREGADDR;
2301 int cnt, h, i, j, k, m;
2302 struct extentaddr *exp = 0, *tex;
2305 afs_uint32 addrs[VL_MAXIPADDRS_PERMH];
2307 int count, willChangeEntry, foundUuidEntry, willReplaceCnt;
2308 int WillReplaceEntry, WillChange[MAXSERVERID + 1];
2310 int ReplaceEntry = 0;
2313 countRequest(this_op);
2314 if (!afsconf_SuperUser(vldb_confdir, rxcall, NULL))
2316 if ((code = Init_VLdbase(&ctx, LOCKWRITE, this_op)))
2319 /* Eliminate duplicates from IP address list */
2320 for (k = 0, cnt = 0; k < addrsp->bulkaddrs_len; k++) {
2321 if (addrsp->bulkaddrs_val[k] == 0)
2323 for (m = 0; m < cnt; m++) {
2324 if (addrs[m] == addrsp->bulkaddrs_val[k])
2328 if (m == VL_MAXIPADDRS_PERMH) {
2330 ("Number of addresses exceeds %d. Cannot register IP addr 0x%x in VLDB\n",
2331 VL_MAXIPADDRS_PERMH, addrsp->bulkaddrs_val[k]));
2333 addrs[m] = addrsp->bulkaddrs_val[k];
2339 code = VL_INDEXERANGE;
2346 /* For each server registered within the VLDB */
2347 for (srvidx = 0; srvidx <= MAXSERVERID; srvidx++) {
2348 willChangeEntry = 0;
2349 WillReplaceEntry = 1;
2350 code = multiHomedExtent(&ctx, srvidx, &exp);
2355 /* See if the addresses to register will change this server entry */
2356 tuuid = exp->ex_hostuuid;
2357 afs_ntohuuid(&tuuid);
2358 if (afs_uuid_equal(uuidp, &tuuid)) {
2362 for (mhidx = 0; mhidx < VL_MAXIPADDRS_PERMH; mhidx++) {
2363 if (!exp->ex_addrs[mhidx])
2365 for (k = 0; k < cnt; k++) {
2366 if (ntohl(exp->ex_addrs[mhidx]) == addrs[k]) {
2367 willChangeEntry = 1;
2368 WillChange[count] = srvidx;
2373 WillReplaceEntry = 0;
2377 /* The server is not registered as a multihomed.
2378 * See if the addresses to register will replace this server entry.
2380 for (k = 0; k < cnt; k++) {
2381 if (ctx.hostaddress[srvidx] == addrs[k]) {
2382 willChangeEntry = 1;
2383 WillChange[count] = srvidx;
2384 WillReplaceEntry = 1;
2389 if (willChangeEntry) {
2390 if (WillReplaceEntry) {
2392 ReplaceEntry = srvidx;
2398 /* If we found the uuid in the VLDB and if we are replacing another
2399 * entire entry, then complain and fail. Also, if we did not find
2400 * the uuid in the VLDB and the IP addresses being registered was
2401 * found in more than one other entry, then we don't know which one
2402 * to replace and will complain and fail.
2404 if ((foundUuidEntry && (willReplaceCnt > 0))
2405 || (!foundUuidEntry && (count > 1))) {
2407 ("The following fileserver is being registered in the VLDB:\n"));
2408 for (addrbuf[0] = '\0', k = 0; k < cnt; k++) {
2410 strlcat(addrbuf, " ", sizeof(addrbuf));
2411 append_addr(addrbuf, addrs[k], sizeof(addrbuf));
2413 VLog(0, (" [%s]\n", addrbuf));
2415 if (foundUuidEntry) {
2416 code = multiHomedExtent(&ctx, FoundUuid, &exp);
2418 VLog(0, (" It would have replaced the existing VLDB server "
2420 for (addrbuf[0] = '\0', mhidx = 0; mhidx < VL_MAXIPADDRS_PERMH; mhidx++) {
2421 if (!exp->ex_addrs[mhidx])
2424 strlcat(addrbuf, " ", sizeof(addrbuf));
2425 append_addr(addrbuf, ntohl(exp->ex_addrs[mhidx]), sizeof(addrbuf));
2427 VLog(0, (" entry %d: [%s]\n", FoundUuid, addrbuf));
2432 VLog(0, (" Yet another VLDB server entry exists:\n"));
2434 VLog(0, (" Yet other VLDB server entries exist:\n"));
2435 for (j = 0; j < count; j++) {
2436 srvidx = WillChange[j];
2437 VLog(0, (" entry %d: ", srvidx));
2439 code = multiHomedExtent(&ctx, srvidx, &exp);
2445 for (mhidx = 0; mhidx < VL_MAXIPADDRS_PERMH; mhidx++) {
2446 if (!exp->ex_addrs[mhidx])
2449 strlcat(addrbuf, " ", sizeof(addrbuf));
2450 append_addr(addrbuf, ntohl(exp->ex_addrs[mhidx]), sizeof(addrbuf));
2453 append_addr(addrbuf, ctx.hostaddress[srvidx], sizeof(addrbuf));
2455 VLog(0, (" entry %d: [%s]\n", srvidx, addrbuf));
2459 VLog(0, (" You must 'vos changeaddr' this other server entry\n"));
2462 (" You must 'vos changeaddr' these other server entries\n"));
2465 (" and/or remove the sysid file from the registering fileserver\n"));
2466 VLog(0, (" before the fileserver can be registered in the VLDB.\n"));
2468 code = VL_MULTIPADDR;
2472 /* Passed the checks. Now find and update the existing mh entry, or create
2475 if (foundUuidEntry) {
2476 /* Found the entry with same uuid. See if we need to change it */
2479 code = multiHomedExtentBase(&ctx, FoundUuid, &exp, &base);
2483 /* Determine if the entry has changed */
2484 for (k = 0; ((k < cnt) && !change); k++) {
2485 if (ntohl(exp->ex_addrs[k]) != addrs[k])
2488 for (; ((k < VL_MAXIPADDRS_PERMH) && !change); k++) {
2489 if (exp->ex_addrs[k] != 0)
2493 return (ubik_EndTrans(ctx.trans));
2497 VLog(0, ("The following fileserver is being registered in the VLDB:\n"));
2498 for (addrbuf[0] = '\0', k = 0; k < cnt; k++) {
2500 strlcat(addrbuf, " ", sizeof(addrbuf));
2501 append_addr(addrbuf, addrs[k], sizeof(addrbuf));
2503 VLog(0, (" [%s]\n", addrbuf));
2505 if (foundUuidEntry) {
2507 (" It will replace the following existing entry in the VLDB (same uuid):\n"));
2508 for (addrbuf[0] = '\0', k = 0; k < VL_MAXIPADDRS_PERMH; k++) {
2509 if (exp->ex_addrs[k] == 0)
2512 strlcat(addrbuf, " ", sizeof(addrbuf));
2513 append_addr(addrbuf, ntohl(exp->ex_addrs[k]), sizeof(addrbuf));
2515 VLog(0, (" entry %d: [%s]\n", FoundUuid, addrbuf));
2516 } else if (willReplaceCnt || (count == 1)) {
2517 /* If we are not replacing an entry and there is only one entry to change,
2518 * then we will replace that entry.
2520 if (!willReplaceCnt) {
2521 ReplaceEntry = WillChange[0];
2525 /* Have an entry that needs to be replaced */
2526 code = multiHomedExtentBase(&ctx, ReplaceEntry, &exp, &base);
2532 (" It will replace the following existing entry in the VLDB (new uuid):\n"));
2533 for (addrbuf[0] = '\0', k = 0; k < VL_MAXIPADDRS_PERMH; k++) {
2534 if (exp->ex_addrs[k] == 0)
2537 strlcat(addrbuf, " ", sizeof(addrbuf));
2538 append_addr(addrbuf, ntohl(exp->ex_addrs[k]), sizeof(addrbuf));
2540 VLog(0, (" entry %d: [%s]\n", ReplaceEntry, addrbuf));
2542 /* Not a mh entry. So we have to create a new mh entry and
2543 * put it on the ReplaceEntry slot of the ctx.hostaddress array.
2546 append_addr(addrbuf, ctx.hostaddress[ReplaceEntry], sizeof(addrbuf));
2547 VLog(0, (" It will replace existing entry %d, %s,"
2548 " in the VLDB (new uuid):\n", ReplaceEntry, addrbuf));
2550 FindExtentBlock(&ctx, uuidp, 1, ReplaceEntry, &exp, &base);
2558 /* There is no entry for this server, must create a new mh entry as
2559 * well as use a new slot of the ctx.hostaddress array.
2561 VLog(0, (" It will create a new entry in the VLDB.\n"));
2562 code = FindExtentBlock(&ctx, uuidp, 1, -1, &exp, &base);
2570 /* Now we have a mh entry to fill in. Update the uuid, bump the
2571 * uniquifier, and fill in its IP addresses.
2574 afs_htonuuid(&tuuid);
2575 exp->ex_hostuuid = tuuid;
2576 exp->ex_uniquifier = htonl(ntohl(exp->ex_uniquifier) + 1);
2577 for (k = 0; k < cnt; k++) {
2578 exp->ex_addrs[k] = htonl(addrs[k]);
2580 for (; k < VL_MAXIPADDRS_PERMH; k++) {
2581 exp->ex_addrs[k] = 0;
2584 /* Write the new mh entry out */
2587 DOFFSET(ntohl(ctx.ex_addr[0]->ex_contaddrs[base]),
2588 (char *)ctx.ex_addr[base], (char *)exp), (char *)exp,
2594 /* Remove any common addresses from other mh entres. We know these entries
2595 * are being changed and not replaced so they are mh entries.
2598 for (i = 0; i < count; i++) {
2601 /* Skip the entry we replaced */
2602 if (willReplaceCnt && (WillChange[i] == ReplaceEntry))
2605 code = multiHomedExtentBase(&ctx, WillChange[i], &tex, &base);
2611 (" The following existing entries in the VLDB will be updated:\n"));
2613 for (addrbuf[0] = '\0', h = j = 0; j < VL_MAXIPADDRS_PERMH; j++) {
2614 if (tex->ex_addrs[j]) {
2616 strlcat(addrbuf, " ", sizeof(addrbuf));
2617 append_addr(addrbuf, ntohl(tex->ex_addrs[j]), sizeof(addrbuf));
2620 for (k = 0; k < cnt; k++) {
2621 if (ntohl(tex->ex_addrs[j]) == addrs[k])
2625 /* Not found, so we keep it */
2626 tex->ex_addrs[h] = tex->ex_addrs[j];
2630 for (j = h; j < VL_MAXIPADDRS_PERMH; j++) {
2631 tex->ex_addrs[j] = 0; /* zero rest of mh entry */
2633 VLog(0, (" entry %d: [%s]\n", WillChange[i], addrbuf));
2635 /* Write out the modified mh entry */
2636 tex->ex_uniquifier = htonl(ntohl(tex->ex_uniquifier) + 1);
2638 DOFFSET(ntohl(ctx.ex_addr[0]->ex_contaddrs[base]),
2639 (char *)ctx.ex_addr[base], (char *)tex);
2640 if (vlwrite(ctx.trans, doff, (char *)tex, sizeof(*tex))) {
2646 return (ubik_EndTrans(ctx.trans));
2649 countAbort(this_op);
2650 ubik_AbortTrans(ctx.trans);
2655 SVL_GetAddrsU(struct rx_call *rxcall,
2656 struct ListAddrByAttributes *attributes,
2658 afs_int32 *uniquifier,
2659 afs_int32 *nentries,
2662 int this_op = VLGETADDRSU;
2663 afs_int32 code, index;
2665 int nservers, i, j, base = 0;
2666 struct extentaddr *exp = 0;
2668 afs_uint32 *taddrp, taddr;
2669 char rxstr[AFS_RXINFO_LEN];
2671 countRequest(this_op);
2672 addrsp->bulkaddrs_len = *nentries = 0;
2673 addrsp->bulkaddrs_val = 0;
2674 VLog(5, ("GetAddrsU %s\n", rxinfo(rxstr, rxcall)));
2675 if ((code = Init_VLdbase(&ctx, LOCKREAD, this_op)))
2678 if (attributes->Mask & VLADDR_IPADDR) {
2679 if (attributes->Mask & (VLADDR_INDEX | VLADDR_UUID)) {
2683 /* Search for a server registered with the VLDB with this ip address. */
2684 for (index = 0; index <= MAXSERVERID; index++) {
2685 code = multiHomedExtent(&ctx, index, &exp);
2690 for (j = 0; j < VL_MAXIPADDRS_PERMH; j++) {
2691 if (exp->ex_addrs[j]
2692 && (ntohl(exp->ex_addrs[j]) == attributes->ipaddr)) {
2696 if (j < VL_MAXIPADDRS_PERMH)
2700 if (index > MAXSERVERID) {
2704 } else if (attributes->Mask & VLADDR_INDEX) {
2705 if (attributes->Mask & (VLADDR_IPADDR | VLADDR_UUID)) {
2709 /* VLADDR_INDEX index is one based */
2710 if (attributes->index < 1 || attributes->index > MAXSERVERID) {
2711 code = VL_INDEXERANGE;
2714 index = attributes->index - 1;
2715 code = multiHomedExtent(&ctx, index, &exp);
2720 } else if (attributes->Mask & VLADDR_UUID) {
2721 if (attributes->Mask & (VLADDR_IPADDR | VLADDR_INDEX)) {
2725 if (!ctx.ex_addr[0]) { /* mh servers probably aren't setup on this vldb */
2729 code = FindExtentBlock(&ctx, &attributes->uuid, 0, -1, &exp, &base);
2741 addrsp->bulkaddrs_val = taddrp =
2742 malloc(sizeof(afs_uint32) * (MAXSERVERID + 1));
2743 nservers = *nentries = addrsp->bulkaddrs_len = 0;
2748 tuuid = exp->ex_hostuuid;
2749 afs_ntohuuid(&tuuid);
2750 if (afs_uuid_is_nil(&tuuid)) {
2757 *uniquifier = ntohl(exp->ex_uniquifier);
2758 for (i = 0; i < VL_MAXIPADDRS_PERMH; i++) {
2759 if (exp->ex_addrs[i]) {
2760 taddr = ntohl(exp->ex_addrs[i]);
2761 /* Weed out duplicates */
2762 for (j = 0; j < nservers; j++) {
2763 if (taddrp[j] == taddr)
2766 if ((j == nservers) && (j <= MAXSERVERID)) {
2767 taddrp[nservers] = taddr;
2772 addrsp->bulkaddrs_len = *nentries = nservers;
2773 return (ubik_EndTrans(ctx.trans));
2776 countAbort(this_op);
2777 ubik_AbortTrans(ctx.trans);
2781 /* ============> End of Exported vldb RPC functions <============= */
2784 /* Routine that copies the given vldb entry to the output buffer, vldbentries. */
2786 put_attributeentry(struct vl_ctx *ctx,
2787 struct vldbentry **Vldbentry,
2788 struct vldbentry **VldbentryFirst,
2789 struct vldbentry **VldbentryLast,
2790 bulkentries *vldbentries,
2791 struct nvlentry *entry,
2792 afs_int32 *nentries,
2793 afs_int32 *alloccnt)
2799 if (*Vldbentry == *VldbentryLast) {
2801 return VL_SIZEEXCEEDED; /* no growing if smallMem defined */
2803 /* Allocate another set of memory; each time allocate twice as
2804 * many blocks as the last time. When we reach VLDBALLOCLIMIT,
2805 * then grow in increments of VLDBALLOCINCR.
2807 allo = (*alloccnt > VLDBALLOCLIMIT) ? VLDBALLOCINCR : *alloccnt;
2808 reall = realloc(*VldbentryFirst,
2809 (*alloccnt + allo) * sizeof(vldbentry));
2813 *VldbentryFirst = vldbentries->bulkentries_val = reall;
2814 *Vldbentry = *VldbentryFirst + *alloccnt;
2815 *VldbentryLast = *Vldbentry + allo;
2819 code = vlentry_to_vldbentry(ctx, entry, *Vldbentry);
2825 vldbentries->bulkentries_len++;
2830 put_nattributeentry(struct vl_ctx *ctx,
2831 struct nvldbentry **Vldbentry,
2832 struct nvldbentry **VldbentryFirst,
2833 struct nvldbentry **VldbentryLast,
2834 nbulkentries *vldbentries,
2835 struct nvlentry *entry,
2836 afs_int32 matchtype,
2837 afs_int32 matchindex,
2838 afs_int32 *nentries,
2839 afs_int32 *alloccnt)
2845 if (*Vldbentry == *VldbentryLast) {
2847 return VL_SIZEEXCEEDED; /* no growing if smallMem defined */
2849 /* Allocate another set of memory; each time allocate twice as
2850 * many blocks as the last time. When we reach VLDBALLOCLIMIT,
2851 * then grow in increments of VLDBALLOCINCR.
2853 allo = (*alloccnt > VLDBALLOCLIMIT) ? VLDBALLOCINCR : *alloccnt;
2854 reall = realloc(*VldbentryFirst,
2855 (*alloccnt + allo) * sizeof(nvldbentry));
2859 *VldbentryFirst = vldbentries->nbulkentries_val = reall;
2860 *Vldbentry = *VldbentryFirst + *alloccnt;
2861 *VldbentryLast = *Vldbentry + allo;
2864 code = vlentry_to_nvldbentry(ctx, entry, *Vldbentry);
2868 (*Vldbentry)->matchindex = (matchtype << 16) + matchindex;
2871 vldbentries->nbulkentries_len++;
2876 /* Common code to actually remove a vldb entry from the database. */
2878 RemoveEntry(struct vl_ctx *ctx, afs_int32 entryptr,
2879 struct nvlentry *tentry)
2883 if ((code = UnthreadVLentry(ctx, entryptr, tentry)))
2885 if ((code = FreeBlock(ctx, entryptr)))
2891 ReleaseEntry(struct nvlentry *tentry, afs_int32 releasetype)
2893 if (releasetype & LOCKREL_TIMESTAMP)
2894 tentry->LockTimestamp = 0;
2895 if (releasetype & LOCKREL_OPCODE)
2896 tentry->flags &= ~VLOP_ALLOPERS;
2897 if (releasetype & LOCKREL_AFSID)
2898 tentry->LockAfsId = 0;
2902 /* Verify that the incoming vldb entry is valid; multi type of error codes
2905 check_vldbentry(struct vldbentry *aentry)
2909 if (InvalidVolname(aentry->name))
2911 if (aentry->nServers <= 0 || aentry->nServers > OMAXNSERVERS)
2912 return VL_BADSERVER;
2913 for (i = 0; i < aentry->nServers; i++) {
2914 /* if (aentry->serverNumber[i] < 0 || aentry->serverNumber[i] > MAXSERVERID)
2915 return VL_BADSERVER; */
2916 if (aentry->serverPartition[i] < 0
2917 || aentry->serverPartition[i] > MAXPARTITIONID)
2918 return VL_BADPARTITION;
2919 if (aentry->serverFlags[i] < 0
2920 || aentry->serverFlags[i] > MAXSERVERFLAG)
2921 return VL_BADSERVERFLAG;
2927 check_nvldbentry(struct nvldbentry *aentry)
2931 if (InvalidVolname(aentry->name))
2933 if (aentry->nServers <= 0 || aentry->nServers > NMAXNSERVERS)
2934 return VL_BADSERVER;
2935 for (i = 0; i < aentry->nServers; i++) {
2936 /* if (aentry->serverNumber[i] < 0 || aentry->serverNumber[i] > MAXSERVERID)
2937 return VL_BADSERVER; */
2938 if (aentry->serverPartition[i] < 0
2939 || aentry->serverPartition[i] > MAXPARTITIONID)
2940 return VL_BADPARTITION;
2941 if (aentry->serverFlags[i] < 0
2942 || aentry->serverFlags[i] > MAXSERVERFLAG)
2943 return VL_BADSERVERFLAG;
2949 /* Convert from the external vldb entry representation to its internal
2950 (more compact) form. This call should not change the hash chains! */
2952 vldbentry_to_vlentry(struct vl_ctx *ctx,
2953 struct vldbentry *VldbEntry,
2954 struct nvlentry *VlEntry)
2958 if (strcmp(VlEntry->name, VldbEntry->name))
2959 strncpy(VlEntry->name, VldbEntry->name, sizeof(VlEntry->name));
2960 for (i = 0; i < VldbEntry->nServers; i++) {
2961 serverindex = IpAddrToRelAddr(ctx, VldbEntry->serverNumber[i], 1);
2962 if (serverindex == -1)
2963 return VL_BADSERVER;
2964 VlEntry->serverNumber[i] = serverindex;
2965 VlEntry->serverPartition[i] = VldbEntry->serverPartition[i];
2966 VlEntry->serverFlags[i] = VldbEntry->serverFlags[i];
2968 for (; i < OMAXNSERVERS; i++)
2969 VlEntry->serverNumber[i] = VlEntry->serverPartition[i] =
2970 VlEntry->serverFlags[i] = BADSERVERID;
2971 for (i = 0; i < MAXTYPES; i++)
2972 VlEntry->volumeId[i] = VldbEntry->volumeId[i];
2973 VlEntry->cloneId = VldbEntry->cloneId;
2974 VlEntry->flags = VldbEntry->flags;
2979 nvldbentry_to_vlentry(struct vl_ctx *ctx,
2980 struct nvldbentry *VldbEntry,
2981 struct nvlentry *VlEntry)
2985 if (strcmp(VlEntry->name, VldbEntry->name))
2986 strncpy(VlEntry->name, VldbEntry->name, sizeof(VlEntry->name));
2987 for (i = 0; i < VldbEntry->nServers; i++) {
2988 serverindex = IpAddrToRelAddr(ctx, VldbEntry->serverNumber[i], 1);
2989 if (serverindex == -1)
2990 return VL_BADSERVER;
2991 VlEntry->serverNumber[i] = serverindex;
2992 VlEntry->serverPartition[i] = VldbEntry->serverPartition[i];
2993 VlEntry->serverFlags[i] = VldbEntry->serverFlags[i];
2995 for (; i < NMAXNSERVERS; i++)
2996 VlEntry->serverNumber[i] = VlEntry->serverPartition[i] =
2997 VlEntry->serverFlags[i] = BADSERVERID;
2998 for (i = 0; i < MAXTYPES; i++)
2999 VlEntry->volumeId[i] = VldbEntry->volumeId[i];
3000 VlEntry->cloneId = VldbEntry->cloneId;
3001 VlEntry->flags = VldbEntry->flags;
3006 /* Update the vldb entry with the new fields as indicated by the value of
3007 * the Mask entry in the updateentry structure. All necessary validation
3008 * checks are performed.
3011 get_vldbupdateentry(struct vl_ctx *ctx,
3012 afs_int32 blockindex,
3013 struct VldbUpdateEntry *updateentry,
3014 struct nvlentry *VlEntry)
3016 int i, j, code, serverindex;
3017 afs_uint32 checkids[MAXTYPES];
3019 /* check if any specified new IDs are already present in the db. Do
3020 * this check before doing anything else, so we don't get a half-
3022 memset(&checkids, 0, sizeof(checkids));
3023 if (updateentry->Mask & VLUPDATE_RWID) {
3024 checkids[RWVOL] = updateentry->spares3; /* rw id */
3026 if (updateentry->Mask & VLUPDATE_READONLYID) {
3027 checkids[ROVOL] = updateentry->ReadOnlyId;
3029 if (updateentry->Mask & VLUPDATE_BACKUPID) {
3030 checkids[BACKVOL] = updateentry->BackupId;
3033 if (EntryIDExists(ctx, checkids, MAXTYPES, &code)) {
3039 if (updateentry->Mask & VLUPDATE_VOLUMENAME) {
3040 struct nvlentry tentry;
3042 if (InvalidVolname(updateentry->name))
3045 if (FindByName(ctx, updateentry->name, &tentry, &code)) {
3046 return VL_NAMEEXIST;
3051 if ((code = UnhashVolname(ctx, blockindex, VlEntry)))
3053 strncpy(VlEntry->name, updateentry->name, sizeof(VlEntry->name));
3054 HashVolname(ctx, blockindex, VlEntry);
3057 if (updateentry->Mask & VLUPDATE_VOLNAMEHASH) {
3058 if ((code = UnhashVolname(ctx, blockindex, VlEntry))) {
3059 if (code != VL_NOENT)
3062 HashVolname(ctx, blockindex, VlEntry);
3065 if (updateentry->Mask & VLUPDATE_FLAGS) {
3066 VlEntry->flags = updateentry->flags;
3068 if (updateentry->Mask & VLUPDATE_CLONEID) {
3069 VlEntry->cloneId = updateentry->cloneId;
3071 if (updateentry->Mask & VLUPDATE_RWID) {
3072 if ((code = UnhashVolid(ctx, RWVOL, blockindex, VlEntry))) {
3073 if (code != VL_NOENT)
3076 VlEntry->volumeId[RWVOL] = updateentry->spares3; /* rw id */
3077 if ((code = HashVolid(ctx, RWVOL, blockindex, VlEntry)))
3080 if (updateentry->Mask & VLUPDATE_READONLYID) {
3081 if ((code = UnhashVolid(ctx, ROVOL, blockindex, VlEntry))) {
3082 if (code != VL_NOENT)
3085 VlEntry->volumeId[ROVOL] = updateentry->ReadOnlyId;
3086 if ((code = HashVolid(ctx, ROVOL, blockindex, VlEntry)))
3089 if (updateentry->Mask & VLUPDATE_BACKUPID) {
3090 if ((code = UnhashVolid(ctx, BACKVOL, blockindex, VlEntry))) {
3091 if (code != VL_NOENT)
3094 VlEntry->volumeId[BACKVOL] = updateentry->BackupId;
3095 if ((code = HashVolid(ctx, BACKVOL, blockindex, VlEntry)))
3098 if (updateentry->Mask & VLUPDATE_REPSITES) {
3099 if (updateentry->nModifiedRepsites <= 0
3100 || updateentry->nModifiedRepsites > OMAXNSERVERS)
3101 return VL_BADSERVER;
3102 for (i = 0; i < updateentry->nModifiedRepsites; i++) {
3103 /* if (updateentry->RepsitesTargetServer[i] < 0 || updateentry->RepsitesTargetServer[i] > MAXSERVERID)
3104 return VL_BADSERVER; */
3105 if (updateentry->RepsitesTargetPart[i] < 0
3106 || updateentry->RepsitesTargetPart[i] > MAXPARTITIONID)
3107 return VL_BADPARTITION;
3108 if (updateentry->RepsitesMask[i] & VLUPDATE_REPS_DELETE) {
3110 repsite_exists(VlEntry,
3111 IpAddrToRelAddr(ctx, updateentry->
3112 RepsitesTargetServer[i],
3114 updateentry->RepsitesTargetPart[i])) !=
3116 repsite_compress(VlEntry, j);
3118 return VL_NOREPSERVER;
3120 if (updateentry->RepsitesMask[i] & VLUPDATE_REPS_ADD) {
3121 /* if (updateentry->RepsitesNewServer[i] < 0 || updateentry->RepsitesNewServer[i] > MAXSERVERID)
3122 return VL_BADSERVER; */
3123 if (updateentry->RepsitesNewPart[i] < 0
3124 || updateentry->RepsitesNewPart[i] > MAXPARTITIONID)
3125 return VL_BADPARTITION;
3128 IpAddrToRelAddr(ctx, updateentry->RepsitesNewServer[i], 1),
3129 updateentry->RepsitesNewPart[i]) != -1)
3130 return VL_DUPREPSERVER;
3132 VlEntry->serverNumber[j] != BADSERVERID
3133 && j < OMAXNSERVERS; j++);
3134 if (j >= OMAXNSERVERS)
3137 IpAddrToRelAddr(ctx, updateentry->RepsitesNewServer[i],
3139 return VL_BADSERVER;
3140 VlEntry->serverNumber[j] = serverindex;
3141 VlEntry->serverPartition[j] = updateentry->RepsitesNewPart[i];
3142 if (updateentry->RepsitesNewFlags[i] < 0
3143 || updateentry->RepsitesNewFlags[i] > MAXSERVERFLAG)
3144 return VL_BADSERVERFLAG;
3145 VlEntry->serverFlags[j] = updateentry->RepsitesNewFlags[i];
3147 if (updateentry->RepsitesMask[i] & VLUPDATE_REPS_MODSERV) {
3148 /*n if (updateentry->RepsitesNewServer[i] < 0 || updateentry->RepsitesNewServer[i] > MAXSERVERID)
3149 return VL_BADSERVER; */
3151 repsite_exists(VlEntry,
3152 IpAddrToRelAddr(ctx, updateentry->
3153 RepsitesTargetServer[i],
3155 updateentry->RepsitesTargetPart[i])) !=
3157 VlEntry->serverNumber[j] =
3158 IpAddrToRelAddr(ctx, updateentry->RepsitesNewServer[i],
3161 return VL_NOREPSERVER;
3163 if (updateentry->RepsitesMask[i] & VLUPDATE_REPS_MODPART) {
3164 if (updateentry->RepsitesNewPart[i] < 0
3165 || updateentry->RepsitesNewPart[i] > MAXPARTITIONID)
3166 return VL_BADPARTITION;
3168 repsite_exists(VlEntry,
3169 IpAddrToRelAddr(ctx, updateentry->
3170 RepsitesTargetServer[i],
3172 updateentry->RepsitesTargetPart[i])) !=
3174 VlEntry->serverPartition[j] =
3175 updateentry->RepsitesNewPart[i];
3177 return VL_NOREPSERVER;
3179 if (updateentry->RepsitesMask[i] & VLUPDATE_REPS_MODFLAG) {
3181 repsite_exists(VlEntry,
3182 IpAddrToRelAddr(ctx, updateentry->
3183 RepsitesTargetServer[i],
3185 updateentry->RepsitesTargetPart[i])) !=
3187 if (updateentry->RepsitesNewFlags[i] < 0
3188 || updateentry->RepsitesNewFlags[i] > MAXSERVERFLAG)
3189 return VL_BADSERVERFLAG;
3190 VlEntry->serverFlags[j] =
3191 updateentry->RepsitesNewFlags[i];
3193 return VL_NOREPSERVER;
3201 /* Check if the specified [server,partition] entry is found in the vldb
3202 * entry's repsite table; it's offset in the table is returned, if it's
3205 repsite_exists(struct nvlentry *VlEntry, int server, int partition)
3209 for (i = 0; VlEntry->serverNumber[i] != BADSERVERID && i < OMAXNSERVERS;
3211 if ((VlEntry->serverNumber[i] == server)
3212 && (VlEntry->serverPartition[i] == partition))
3220 /* Repsite table compression: used when deleting a repsite entry so that
3221 * all active repsite entries are on the top of the table. */
3223 repsite_compress(struct nvlentry *VlEntry, int offset)
3225 int repsite_offset = offset;
3227 VlEntry->serverNumber[repsite_offset] != BADSERVERID
3228 && repsite_offset < OMAXNSERVERS - 1; repsite_offset++) {
3229 VlEntry->serverNumber[repsite_offset] =
3230 VlEntry->serverNumber[repsite_offset + 1];
3231 VlEntry->serverPartition[repsite_offset] =
3232 VlEntry->serverPartition[repsite_offset + 1];
3233 VlEntry->serverFlags[repsite_offset] =
3234 VlEntry->serverFlags[repsite_offset + 1];
3236 VlEntry->serverNumber[repsite_offset] = BADSERVERID;
3240 /* Convert from the internal (compacted) vldb entry to the external
3241 * representation used by the interface. */
3243 vlentry_to_vldbentry(struct vl_ctx *ctx, struct nvlentry *VlEntry,
3244 struct vldbentry *VldbEntry)
3247 struct extentaddr *exp;
3249 memset(VldbEntry, 0, sizeof(struct vldbentry));
3250 strncpy(VldbEntry->name, VlEntry->name, sizeof(VldbEntry->name));
3251 for (i = 0; i < OMAXNSERVERS; i++) {
3252 if (VlEntry->serverNumber[i] == BADSERVERID)
3254 code = multiHomedExtent(ctx, VlEntry->serverNumber[i], &exp);
3258 /* For now return the first ip address back */
3259 for (j = 0; j < VL_MAXIPADDRS_PERMH; j++) {
3260 if (exp->ex_addrs[j]) {
3261 VldbEntry->serverNumber[i] = ntohl(exp->ex_addrs[j]);
3266 VldbEntry->serverNumber[i] =
3267 ctx->hostaddress[VlEntry->serverNumber[i]];
3268 VldbEntry->serverPartition[i] = VlEntry->serverPartition[i];
3269 VldbEntry->serverFlags[i] = VlEntry->serverFlags[i];
3271 VldbEntry->nServers = i;
3272 for (i = 0; i < MAXTYPES; i++)
3273 VldbEntry->volumeId[i] = VlEntry->volumeId[i];
3274 VldbEntry->cloneId = VlEntry->cloneId;
3275 VldbEntry->flags = VlEntry->flags;
3281 /* Convert from the internal (compacted) vldb entry to the external
3282 * representation used by the interface. */
3284 vlentry_to_nvldbentry(struct vl_ctx *ctx, struct nvlentry *VlEntry,
3285 struct nvldbentry *VldbEntry)
3288 struct extentaddr *exp;
3290 memset(VldbEntry, 0, sizeof(struct nvldbentry));
3291 strncpy(VldbEntry->name, VlEntry->name, sizeof(VldbEntry->name));
3292 for (i = 0; i < NMAXNSERVERS; i++) {
3293 if (VlEntry->serverNumber[i] == BADSERVERID)
3295 code = multiHomedExtent(ctx, VlEntry->serverNumber[i], &exp);
3300 /* For now return the first ip address back */
3301 for (j = 0; j < VL_MAXIPADDRS_PERMH; j++) {
3302 if (exp->ex_addrs[j]) {
3303 VldbEntry->serverNumber[i] = ntohl(exp->ex_addrs[j]);
3308 VldbEntry->serverNumber[i] =
3309 ctx->hostaddress[VlEntry->serverNumber[i]];
3310 VldbEntry->serverPartition[i] = VlEntry->serverPartition[i];
3311 VldbEntry->serverFlags[i] = VlEntry->serverFlags[i];
3313 VldbEntry->nServers = i;
3314 for (i = 0; i < MAXTYPES; i++)
3315 VldbEntry->volumeId[i] = VlEntry->volumeId[i];
3316 VldbEntry->cloneId = VlEntry->cloneId;
3317 VldbEntry->flags = VlEntry->flags;
3323 vlentry_to_uvldbentry(struct vl_ctx *ctx, struct nvlentry *VlEntry,
3324 struct uvldbentry *VldbEntry)
3327 struct extentaddr *exp;
3329 memset(VldbEntry, 0, sizeof(struct uvldbentry));
3330 strncpy(VldbEntry->name, VlEntry->name, sizeof(VldbEntry->name));
3331 for (i = 0; i < NMAXNSERVERS; i++) {
3332 if (VlEntry->serverNumber[i] == BADSERVERID)
3334 VldbEntry->serverFlags[i] = VlEntry->serverFlags[i];
3335 VldbEntry->serverUnique[i] = 0;
3336 code = multiHomedExtent(ctx, VlEntry->serverNumber[i], &exp);
3343 tuuid = exp->ex_hostuuid;
3344 afs_ntohuuid(&tuuid);
3345 VldbEntry->serverFlags[i] |= VLSF_UUID;
3346 VldbEntry->serverNumber[i] = tuuid;
3347 VldbEntry->serverUnique[i] = ntohl(exp->ex_uniquifier);
3349 VldbEntry->serverNumber[i].time_low =
3350 ctx->hostaddress[VlEntry->serverNumber[i]];
3352 VldbEntry->serverPartition[i] = VlEntry->serverPartition[i];
3355 VldbEntry->nServers = i;
3356 for (i = 0; i < MAXTYPES; i++)
3357 VldbEntry->volumeId[i] = VlEntry->volumeId[i];
3358 VldbEntry->cloneId = VlEntry->cloneId;
3359 VldbEntry->flags = VlEntry->flags;
3364 #define LEGALCHARS ".ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"
3367 /* Verify that the volname is a valid volume name. */
3369 InvalidVolname(char *volname)
3375 slen = strlen(volname);
3376 if (slen >= VL_MAXNAMELEN)
3378 return (slen != strspn(volname, map));
3382 /* Verify that the given volume type is valid. */
3384 InvalidVoltype(afs_int32 voltype)
3386 if (voltype != RWVOL && voltype != ROVOL && voltype != BACKVOL)
3393 InvalidOperation(afs_int32 voloper)
3395 if (voloper != VLOP_MOVE && voloper != VLOP_RELEASE
3396 && voloper != VLOP_BACKUP && voloper != VLOP_DELETE
3397 && voloper != VLOP_DUMP)
3403 InvalidReleasetype(afs_int32 releasetype)
3405 if ((releasetype & LOCKREL_TIMESTAMP) || (releasetype & LOCKREL_OPCODE)
3406 || (releasetype & LOCKREL_AFSID))
3412 IpAddrToRelAddr(struct vl_ctx *ctx, afs_uint32 ipaddr, int create)
3416 struct extentaddr *exp;
3418 for (i = 0; i <= MAXSERVERID; i++) {
3419 if (ctx->hostaddress[i] == ipaddr)
3421 code = multiHomedExtent(ctx, i, &exp);
3425 for (j = 0; j < VL_MAXIPADDRS_PERMH; j++) {
3426 if (exp->ex_addrs[j] && (ntohl(exp->ex_addrs[j]) == ipaddr)) {
3433 /* allocate the new server a server id pronto */
3435 for (i = 0; i <= MAXSERVERID; i++) {
3436 if (ctx->cheader->IpMappedAddr[i] == 0) {
3437 ctx->cheader->IpMappedAddr[i] = htonl(ipaddr);
3440 DOFFSET(0, ctx->cheader, &ctx->cheader->IpMappedAddr[i]),
3441 (char *)&ctx->cheader->IpMappedAddr[i],
3443 ctx->hostaddress[i] = ipaddr;
3454 ChangeIPAddr(struct vl_ctx *ctx, afs_uint32 ipaddr1, afs_uint32 ipaddr2)
3458 struct extentaddr *exp = NULL;
3462 afs_int32 blockindex, count;
3464 struct nvlentry tentry;
3465 int ipaddr1_id = -1, ipaddr2_id = -1;
3469 /* Don't let addr change to 255.*.*.* : Causes internal error below */
3470 if ((ipaddr2 & 0xff000000) == 0xff000000)
3471 return (VL_BADSERVER);
3473 /* If we are removing an address, ip1 will be -1 and ip2 will be
3474 * the original address. This prevents an older revision vlserver
3475 * from removing the IP address (won't find server 0xfffffff in
3476 * the VLDB). An older revision vlserver does not have the check
3477 * to see if any volumes exist on the server being removed.
3479 if (ipaddr1 == 0xffffffff) {
3484 for (i = 0; i <= MAXSERVERID; i++) {
3485 struct extentaddr *texp = NULL;
3488 code = multiHomedExtentBase(ctx, i, &texp, &tbase);
3493 for (mhidx = 0; mhidx < VL_MAXIPADDRS_PERMH; mhidx++) {
3494 if (!texp->ex_addrs[mhidx])
3496 if (ntohl(texp->ex_addrs[mhidx]) == ipaddr1) {
3501 if (ipaddr2 != 0 && ntohl(texp->ex_addrs[mhidx]) == ipaddr2) {
3506 if (ctx->hostaddress[i] == ipaddr1) {
3511 if (ipaddr2 != 0 && ctx->hostaddress[i] == ipaddr2) {
3516 if (ipaddr1_id >= 0 && (ipaddr2 == 0 || ipaddr2_id >= 0)) {
3517 /* we've either found both IPs already in the VLDB, or we found
3518 * ipaddr1, and we're not going to find ipaddr2 because it's 0 */
3523 if (ipaddr1_id < 0) {
3524 return VL_NOENT; /* not found */
3527 if (ipaddr2_id >= 0 && ipaddr2_id != ipaddr1_id) {
3528 char buf1[16], buf2[16];
3529 VLog(0, ("Cannot change IP address from %s to %s because the latter "
3530 "is in use by server id %d\n",
3531 afs_inet_ntoa_r(htonl(ipaddr1), buf1),
3532 afs_inet_ntoa_r(htonl(ipaddr2), buf2),
3534 return VL_MULTIPADDR;
3537 /* If we are removing a server entry, a volume cannot
3538 * exist on the server. If one does, don't remove the
3539 * server entry: return error "volume entry exists".
3542 for (blockindex = NextEntry(ctx, 0, &tentry, &count); blockindex;
3543 blockindex = NextEntry(ctx, blockindex, &tentry, &count)) {
3544 if (++pollcount > 50) {
3545 #ifndef AFS_PTHREAD_ENV
3550 for (j = 0; j < NMAXNSERVERS; j++) {
3551 if (tentry.serverNumber[j] == BADSERVERID)
3553 if (tentry.serverNumber[j] == ipaddr1_id) {
3559 /* Do not allow changing addresses in multi-homed entries.
3560 Older versions of this RPC would silently "downgrade" mh entries
3561 to single-homed entries and orphan the mh enties. */
3563 append_addr(addrbuf1, ipaddr1, sizeof(addrbuf1));
3564 VLog(0, ("Refusing to change address %s in multi-homed entry; "
3565 "use RegisterAddrs instead.\n", addrbuf1));
3566 return VL_NOENT; /* single-homed entry not found */
3569 /* Log a message saying we are changing/removing an IP address */
3571 ("The following IP address is being %s:\n",
3572 (ipaddr2 ? "changed" : "removed")));
3573 addrbuf1[0] = addrbuf2[0] = '\0';
3575 for (mhidx = 0; mhidx < VL_MAXIPADDRS_PERMH; mhidx++) {
3576 if (!exp->ex_addrs[mhidx])
3579 strlcat(addrbuf1, " ", sizeof(addrbuf1));
3580 append_addr(addrbuf1, ntohl(exp->ex_addrs[mhidx]), sizeof(addrbuf1));
3583 append_addr(addrbuf1, ipaddr1, sizeof(addrbuf1));
3586 append_addr(addrbuf2, ipaddr2, sizeof(addrbuf2));
3588 VLog(0, (" entry %d: [%s] -> [%s]\n", ipaddr1_id, addrbuf1, addrbuf2));
3590 /* Change the registered uuuid addresses */
3591 if (exp && base != -1) {
3592 memset(&tuuid, 0, sizeof(afsUUID));
3593 afs_htonuuid(&tuuid);
3594 exp->ex_hostuuid = tuuid;
3597 DOFFSET(ntohl(ctx->ex_addr[0]->ex_contaddrs[base]),
3598 (char *)ctx->ex_addr[base], (char *)exp),
3599 (char *)&tuuid, sizeof(tuuid));
3604 /* Now change the host address entry */
3605 ctx->cheader->IpMappedAddr[ipaddr1_id] = htonl(ipaddr2);
3607 vlwrite(ctx->trans, DOFFSET(0, ctx->cheader, &ctx->cheader->IpMappedAddr[ipaddr1_id]),
3609 &ctx->cheader->IpMappedAddr[ipaddr1_id], sizeof(afs_int32));
3610 ctx->hostaddress[ipaddr1_id] = ipaddr2;
3617 /* see if the vlserver is back yet */
3619 SVL_ProbeServer(struct rx_call *rxcall)