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, findname = 0;
1661 int namematchRWBK, namematchRO, thismatch;
1664 char volumename[VL_MAXNAMELEN+3]; /* regex anchors */
1665 char rxstr[AFS_RXINFO_LEN];
1666 #ifdef HAVE_POSIX_REGEX
1668 int need_regfree = 0;
1673 countRequest(this_op);
1675 if (!afsconf_CheckRestrictedQuery(vldb_confdir, rxcall,
1676 restrictedQueryLevel))
1679 vldbentries->nbulkentries_val = 0;
1680 vldbentries->nbulkentries_len = 0;
1682 *nextstartindex = -1;
1684 code = Init_VLdbase(&ctx, LOCKREAD, this_op);
1688 Vldbentry = VldbentryFirst = vldbentries->nbulkentries_val =
1689 malloc(maxCount * sizeof(nvldbentry));
1690 if (Vldbentry == NULL) {
1691 countAbort(this_op);
1692 ubik_AbortTrans(ctx.trans);
1696 VldbentryLast = VldbentryFirst + maxCount;
1698 /* Handle the attribute by volume id totally separate of the rest
1699 * (thus additional Mask values are ignored if VLLIST_VOLUMEID is set!)
1701 if (attributes->Mask & VLLIST_VOLUMEID) {
1703 FindByID(&ctx, attributes->volumeid, -1, &tentry, &code);
1704 if (blockindex == 0) {
1709 put_nattributeentry(&ctx, &Vldbentry, &VldbentryFirst,
1710 &VldbentryLast, vldbentries, &tentry, 0,
1711 0, nentries, &maxCount);
1717 /* Search each entry in the database and return all entries
1718 * that match the request. It checks volumename (with
1719 * wildcarding), entry flags, server, and partition.
1722 /* Get the server index for matching server address */
1723 if (attributes->Mask & VLLIST_SERVER) {
1725 IpAddrToRelAddr(&ctx, attributes->server, 0);
1726 if (serverindex == -1)
1730 findpartition = ((attributes->Mask & VLLIST_PARTITION) ? 1 : 0);
1731 findflag = ((attributes->Mask & VLLIST_FLAG) ? 1 : 0);
1732 if (name && (strcmp(name, ".*") != 0) && (strcmp(name, "") != 0)) {
1733 if (!afsconf_SuperUser(vldb_confdir, rxcall, NULL)) {
1737 size = snprintf(volumename, sizeof(volumename), "^%s$", name);
1738 if (size < 0 || size >= sizeof(volumename)) {
1742 #ifdef HAVE_POSIX_REGEX
1743 if (regcomp(&re, volumename, REG_NOSUB) != 0) {
1749 t = (char *)re_comp(volumename);
1758 /* Read each entry and see if it is the one we want */
1759 blockindex = startindex;
1760 while ((blockindex = NextEntry(&ctx, blockindex, &tentry, &count))) {
1761 if (++pollcount > 50) {
1762 #ifndef AFS_PTHREAD_ENV
1768 /* Step through each server index searching for a match.
1769 * Match to an existing RW, BK, or RO volume name (preference
1770 * is in this order). Remember which index we matched against.
1772 namematchRWBK = namematchRO = 0; /* 0->notTried; 1->match; 2->noMatch */
1776 && (tentry.serverNumber[k] != BADSERVERID)); k++) {
1777 thismatch = 0; /* does this index match */
1779 /* Match against the RW or BK volume name. Remember
1780 * results in namematchRWBK. Prefer RW over BK.
1782 if (tentry.serverFlags[k] & VLSF_RWVOL) {
1783 /* Does the name match the RW name */
1784 if (tentry.flags & VLF_RWEXISTS) {
1786 size = snprintf(volumename, sizeof(volumename),
1788 if (size < 0 || size >= sizeof(volumename)) {
1792 #ifdef HAVE_POSIX_REGEX
1793 if (regexec(&re, volumename, 0, NULL, 0) == 0) {
1794 thismatch = VLSF_RWVOL;
1797 if (re_exec(volumename)) {
1798 thismatch = VLSF_RWVOL;
1802 thismatch = VLSF_RWVOL;
1806 /* Does the name match the BK name */
1807 if (!thismatch && (tentry.flags & VLF_BACKEXISTS)) {
1809 /* If this fails, the tentry.name is invalid */
1810 size = snprintf(volumename, sizeof(volumename),
1811 "%s.backup", tentry.name);
1812 if (size < 0 || size >= sizeof(volumename)) {
1816 #ifdef HAVE_POSIX_REGEX
1817 if (regexec(&re, volumename, 0, NULL, 0) == 0) {
1818 thismatch = VLSF_BACKVOL;
1821 if (re_exec(volumename)) {
1822 thismatch = VLSF_BACKVOL;
1826 thismatch = VLSF_BACKVOL;
1830 namematchRWBK = (thismatch ? 1 : 2);
1833 /* Match with the RO volume name. Compare once and
1834 * remember results in namematchRO. Note that this will
1835 * pick up entries marked NEWREPSITEs and DONTUSE.
1838 if (tentry.flags & VLF_ROEXISTS) {
1842 ((namematchRO == 1) ? VLSF_ROVOL : 0);
1844 /* If this fails, the tentry.name is invalid */
1845 size = snprintf(volumename, sizeof(volumename),
1846 "%s.readonly", tentry.name);
1847 if (size < 0 || size >= sizeof(volumename)) {
1851 #ifdef HAVE_POSIX_REGEX
1852 if (regexec(&re, volumename, 0, NULL, 0) == 0) {
1853 thismatch = VLSF_ROVOL;
1856 if (re_exec(volumename))
1857 thismatch = VLSF_ROVOL;
1861 thismatch = VLSF_ROVOL;
1864 namematchRO = (thismatch ? 1 : 2);
1867 /* Is there a server match */
1868 if (thismatch && findserver
1869 && (tentry.serverNumber[k] != serverindex))
1872 /* Is there a partition match */
1873 if (thismatch && findpartition
1874 && (tentry.serverPartition[k] != attributes->partition))
1877 /* Is there a flag match */
1878 if (thismatch && findflag
1879 && !(tentry.flags & attributes->flag))
1882 /* We found a match. Remember the index, and type */
1886 matchtype = thismatch;
1889 /* Since we prefer RW and BK volume matches over RO matches,
1890 * if we have already checked the RWBK name, then we already
1891 * found the best match and so end the search.
1893 * If we tried matching against the RW, BK, and RO volume names
1894 * and both failed, then we end the search (none will match).
1896 if ((match && namematchRWBK)
1897 || ((namematchRWBK == 2) && (namematchRO == 2)))
1901 /* Passed all the tests. Take it */
1904 put_nattributeentry(&ctx, &Vldbentry, &VldbentryFirst,
1905 &VldbentryLast, vldbentries, &tentry,
1906 matchtype, matchindex, nentries,
1911 if (*nentries >= maxCount)
1912 break; /* collected the max */
1915 *nextstartindex = (blockindex ? blockindex : -1);
1919 #ifdef HAVE_POSIX_REGEX
1925 countAbort(this_op);
1926 ubik_AbortTrans(ctx.trans);
1927 if (vldbentries->nbulkentries_val)
1928 free(vldbentries->nbulkentries_val);
1929 vldbentries->nbulkentries_val = 0;
1930 vldbentries->nbulkentries_len = 0;
1931 *nextstartindex = -1;
1934 ("N2ListAttrs nentries=%d %s\n", vldbentries->nbulkentries_len,
1935 rxinfo(rxstr, rxcall)));
1936 code = ubik_EndTrans(ctx.trans);
1943 SVL_ListAttributesN2(struct rx_call *rxcall,
1944 struct VldbListByAttributes *attributes,
1945 char *name, /* Wildcarded volume name */
1946 afs_int32 startindex,
1947 afs_int32 *nentries,
1948 nbulkentries *vldbentries,
1949 afs_int32 *nextstartindex)
1953 code = ListAttributesN2(rxcall, attributes, name, startindex,
1954 nentries, vldbentries, nextstartindex);
1955 osi_auditU(rxcall, VLListAttributesN2Event, code, AUD_END);
1959 /* Retrieves in vldbentries all vldb entries that match the specified
1960 * attributes (by server number, partition, volume type, and flag); if
1961 * volume id is specified then the associated list for that entry is
1962 * returned. CAUTION: This could be a very expensive call since in most
1963 * cases sequential search of all vldb entries is performed.
1966 LinkedList(struct rx_call *rxcall,
1967 struct VldbListByAttributes *attributes,
1968 afs_int32 *nentries,
1969 vldb_list *vldbentries)
1971 int this_op = VLLINKEDLIST;
1974 struct nvlentry tentry;
1975 vldblist vllist, *vllistptr;
1976 afs_int32 blockindex, count, match;
1981 countRequest(this_op);
1983 if (!afsconf_CheckRestrictedQuery(vldb_confdir, rxcall,
1984 restrictedQueryLevel))
1987 if ((code = Init_VLdbase(&ctx, LOCKREAD, this_op)))
1991 vldbentries->node = NULL;
1992 vllistptr = &vldbentries->node;
1994 /* List by volumeid */
1995 if (attributes->Mask & VLLIST_VOLUMEID) {
1997 FindByID(&ctx, attributes->volumeid, -1, &tentry, &code);
2004 vllist = malloc(sizeof(single_vldbentry));
2005 if (vllist == NULL) {
2009 code = vlentry_to_vldbentry(&ctx, &tentry, &vllist->VldbEntry);
2013 vllist->next_vldb = NULL;
2015 *vllistptr = vllist; /* Thread onto list */
2016 vllistptr = &vllist->next_vldb;
2020 /* Search by server, partition, and flags */
2022 for (blockindex = NextEntry(&ctx, 0, &tentry, &count); blockindex;
2023 blockindex = NextEntry(&ctx, blockindex, &tentry, &count)) {
2026 if (++pollcount > 50) {
2027 #ifndef AFS_PTHREAD_ENV
2033 /* Does this volume exist on the desired server */
2034 if (attributes->Mask & VLLIST_SERVER) {
2036 IpAddrToRelAddr(&ctx, attributes->server, 0);
2037 if (serverindex == -1)
2039 for (k = 0; k < OMAXNSERVERS; k++) {
2040 if (tentry.serverNumber[k] == BADSERVERID)
2042 if (tentry.serverNumber[k] == serverindex) {
2051 /* Does this volume exist on the desired partition */
2052 if (attributes->Mask & VLLIST_PARTITION) {
2054 if (tentry.serverPartition[k] != attributes->partition)
2057 for (k = 0; k < OMAXNSERVERS; k++) {
2058 if (tentry.serverNumber[k] == BADSERVERID)
2060 if (tentry.serverPartition[k] ==
2061 attributes->partition) {
2071 /* Does this volume have the desired flags */
2072 if (attributes->Mask & VLLIST_FLAG) {
2073 if (!(tentry.flags & attributes->flag))
2077 vllist = malloc(sizeof(single_vldbentry));
2078 if (vllist == NULL) {
2082 code = vlentry_to_vldbentry(&ctx, &tentry, &vllist->VldbEntry);
2086 vllist->next_vldb = NULL;
2088 *vllistptr = vllist; /* Thread onto list */
2089 vllistptr = &vllist->next_vldb;
2091 if (smallMem && (*nentries >= VLDBALLOCCOUNT)) {
2092 code = VL_SIZEEXCEEDED;
2098 return ubik_EndTrans(ctx.trans);
2101 countAbort(this_op);
2102 ubik_AbortTrans(ctx.trans);
2107 SVL_LinkedList(struct rx_call *rxcall,
2108 struct VldbListByAttributes *attributes,
2109 afs_int32 *nentries,
2110 vldb_list *vldbentries)
2114 code = LinkedList(rxcall, attributes, nentries, vldbentries);
2115 osi_auditU(rxcall, VLLinkedListEvent, code, AUD_END);
2120 LinkedListN(struct rx_call *rxcall,
2121 struct VldbListByAttributes *attributes,
2122 afs_int32 *nentries,
2123 nvldb_list *vldbentries)
2125 int this_op = VLLINKEDLISTN;
2128 struct nvlentry tentry;
2129 nvldblist vllist, *vllistptr;
2130 afs_int32 blockindex, count, match;
2135 countRequest(this_op);
2137 if (!afsconf_CheckRestrictedQuery(vldb_confdir, rxcall,
2138 restrictedQueryLevel))
2141 if ((code = Init_VLdbase(&ctx, LOCKREAD, this_op)))
2145 vldbentries->node = NULL;
2146 vllistptr = &vldbentries->node;
2148 /* List by volumeid */
2149 if (attributes->Mask & VLLIST_VOLUMEID) {
2151 FindByID(&ctx, attributes->volumeid, -1, &tentry, &code);
2158 vllist = malloc(sizeof(single_nvldbentry));
2159 if (vllist == NULL) {
2163 code = vlentry_to_nvldbentry(&ctx, &tentry, &vllist->VldbEntry);
2167 vllist->next_vldb = NULL;
2169 *vllistptr = vllist; /* Thread onto list */
2170 vllistptr = &vllist->next_vldb;
2174 /* Search by server, partition, and flags */
2176 for (blockindex = NextEntry(&ctx, 0, &tentry, &count); blockindex;
2177 blockindex = NextEntry(&ctx, blockindex, &tentry, &count)) {
2180 if (++pollcount > 50) {
2181 #ifndef AFS_PTHREAD_ENV
2187 /* Does this volume exist on the desired server */
2188 if (attributes->Mask & VLLIST_SERVER) {
2190 IpAddrToRelAddr(&ctx, attributes->server, 0);
2191 if (serverindex == -1)
2193 for (k = 0; k < NMAXNSERVERS; k++) {
2194 if (tentry.serverNumber[k] == BADSERVERID)
2196 if (tentry.serverNumber[k] == serverindex) {
2205 /* Does this volume exist on the desired partition */
2206 if (attributes->Mask & VLLIST_PARTITION) {
2208 if (tentry.serverPartition[k] != attributes->partition)
2211 for (k = 0; k < NMAXNSERVERS; k++) {
2212 if (tentry.serverNumber[k] == BADSERVERID)
2214 if (tentry.serverPartition[k] ==
2215 attributes->partition) {
2225 /* Does this volume have the desired flags */
2226 if (attributes->Mask & VLLIST_FLAG) {
2227 if (!(tentry.flags & attributes->flag))
2231 vllist = malloc(sizeof(single_nvldbentry));
2232 if (vllist == NULL) {
2236 code = vlentry_to_nvldbentry(&ctx, &tentry, &vllist->VldbEntry);
2240 vllist->next_vldb = NULL;
2242 *vllistptr = vllist; /* Thread onto list */
2243 vllistptr = &vllist->next_vldb;
2245 if (smallMem && (*nentries >= VLDBALLOCCOUNT)) {
2246 code = VL_SIZEEXCEEDED;
2252 return ubik_EndTrans(ctx.trans);
2255 countAbort(this_op);
2256 ubik_AbortTrans(ctx.trans);
2261 SVL_LinkedListN(struct rx_call *rxcall,
2262 struct VldbListByAttributes *attributes,
2263 afs_int32 *nentries,
2264 nvldb_list *vldbentries)
2268 code = LinkedListN(rxcall, attributes, nentries, vldbentries);
2269 osi_auditU(rxcall, VLLinkedListNEvent, code, AUD_END);
2273 /* Get back vldb header statistics (allocs, frees, maxvolumeid,
2274 * totalentries, etc) and dynamic statistics (number of requests and/or
2275 * aborts per remote procedure call, etc)
2278 GetStats(struct rx_call *rxcall,
2280 vital_vlheader *vital_header)
2282 int this_op = VLGETSTATS;
2285 char rxstr[AFS_RXINFO_LEN];
2287 countRequest(this_op);
2289 if (!afsconf_CheckRestrictedQuery(vldb_confdir, rxcall,
2290 restrictedQueryLevel))
2293 if ((code = Init_VLdbase(&ctx, LOCKREAD, this_op)))
2295 VLog(5, ("GetStats %s\n", rxinfo(rxstr, rxcall)));
2296 memcpy((char *)vital_header, (char *)&ctx.cheader->vital_header,
2297 sizeof(vital_vlheader));
2298 memcpy((char *)stats, (char *)&dynamic_statistics, sizeof(vldstats));
2299 return ubik_EndTrans(ctx.trans);
2303 SVL_GetStats(struct rx_call *rxcall,
2305 vital_vlheader *vital_header)
2309 code = GetStats(rxcall, stats, vital_header);
2310 osi_auditU(rxcall, VLGetStatsEvent, code, AUD_END);
2314 /* Get the list of file server addresses from the VLDB. Currently it's pretty
2315 * easy to do. In the future, it might require a little bit of grunging
2316 * through the VLDB, but that's life.
2319 SVL_GetAddrs(struct rx_call *rxcall,
2322 struct VLCallBack *spare3,
2323 afs_int32 *nentries,
2326 int this_op = VLGETADDRS;
2332 countRequest(this_op);
2333 addrsp->bulkaddrs_len = *nentries = 0;
2334 addrsp->bulkaddrs_val = 0;
2335 memset(spare3, 0, sizeof(struct VLCallBack));
2337 if ((code = Init_VLdbase(&ctx, LOCKREAD, this_op)))
2340 VLog(5, ("GetAddrs\n"));
2341 addrsp->bulkaddrs_val = taddrp =
2342 malloc(sizeof(afs_uint32) * (MAXSERVERID + 1));
2343 nservers = *nentries = addrsp->bulkaddrs_len = 0;
2350 for (i = 0; i <= MAXSERVERID; i++) {
2351 if ((*taddrp = ntohl(ctx.cheader->IpMappedAddr[i]))) {
2357 addrsp->bulkaddrs_len = *nentries = nservers;
2358 return (ubik_EndTrans(ctx.trans));
2361 countAbort(this_op);
2362 ubik_AbortTrans(ctx.trans);
2367 append_addr(char *buffer, afs_uint32 addr, size_t buffer_size)
2369 int n = strlen(buffer);
2370 if (buffer_size > n) {
2371 snprintf(buffer + n, buffer_size - n, "%u.%u.%u.%u",
2372 (addr >> 24) & 0xff, (addr >> 16) & 0xff, (addr >> 8) & 0xff,
2378 SVL_RegisterAddrs(struct rx_call *rxcall, afsUUID *uuidp, afs_int32 spare1,
2381 int this_op = VLREGADDR;
2384 int cnt, h, i, j, k, m;
2385 struct extentaddr *exp = 0, *tex;
2388 afs_uint32 addrs[VL_MAXIPADDRS_PERMH];
2390 int count, willChangeEntry, foundUuidEntry, willReplaceCnt;
2391 int WillReplaceEntry, WillChange[MAXSERVERID + 1];
2393 int ReplaceEntry = 0;
2396 countRequest(this_op);
2397 if (!afsconf_SuperUser(vldb_confdir, rxcall, NULL))
2399 if ((code = Init_VLdbase(&ctx, LOCKWRITE, this_op)))
2402 /* Eliminate duplicates from IP address list */
2403 for (k = 0, cnt = 0; k < addrsp->bulkaddrs_len; k++) {
2404 if (addrsp->bulkaddrs_val[k] == 0)
2406 for (m = 0; m < cnt; m++) {
2407 if (addrs[m] == addrsp->bulkaddrs_val[k])
2411 if (m == VL_MAXIPADDRS_PERMH) {
2413 ("Number of addresses exceeds %d. Cannot register IP addr 0x%x in VLDB\n",
2414 VL_MAXIPADDRS_PERMH, addrsp->bulkaddrs_val[k]));
2416 addrs[m] = addrsp->bulkaddrs_val[k];
2422 code = VL_INDEXERANGE;
2429 /* For each server registered within the VLDB */
2430 for (srvidx = 0; srvidx <= MAXSERVERID; srvidx++) {
2431 willChangeEntry = 0;
2432 WillReplaceEntry = 1;
2433 code = multiHomedExtent(&ctx, srvidx, &exp);
2438 /* See if the addresses to register will change this server entry */
2439 tuuid = exp->ex_hostuuid;
2440 afs_ntohuuid(&tuuid);
2441 if (afs_uuid_equal(uuidp, &tuuid)) {
2445 for (mhidx = 0; mhidx < VL_MAXIPADDRS_PERMH; mhidx++) {
2446 if (!exp->ex_addrs[mhidx])
2448 for (k = 0; k < cnt; k++) {
2449 if (ntohl(exp->ex_addrs[mhidx]) == addrs[k]) {
2450 willChangeEntry = 1;
2451 WillChange[count] = srvidx;
2456 WillReplaceEntry = 0;
2460 /* The server is not registered as a multihomed.
2461 * See if the addresses to register will replace this server entry.
2463 for (k = 0; k < cnt; k++) {
2464 if (ctx.hostaddress[srvidx] == addrs[k]) {
2465 willChangeEntry = 1;
2466 WillChange[count] = srvidx;
2467 WillReplaceEntry = 1;
2472 if (willChangeEntry) {
2473 if (WillReplaceEntry) {
2475 ReplaceEntry = srvidx;
2481 /* If we found the uuid in the VLDB and if we are replacing another
2482 * entire entry, then complain and fail. Also, if we did not find
2483 * the uuid in the VLDB and the IP addresses being registered was
2484 * found in more than one other entry, then we don't know which one
2485 * to replace and will complain and fail.
2487 if ((foundUuidEntry && (willReplaceCnt > 0))
2488 || (!foundUuidEntry && (count > 1))) {
2490 ("The following fileserver is being registered in the VLDB:\n"));
2491 for (addrbuf[0] = '\0', k = 0; k < cnt; k++) {
2493 strlcat(addrbuf, " ", sizeof(addrbuf));
2494 append_addr(addrbuf, addrs[k], sizeof(addrbuf));
2496 VLog(0, (" [%s]\n", addrbuf));
2498 if (foundUuidEntry) {
2499 code = multiHomedExtent(&ctx, FoundUuid, &exp);
2501 VLog(0, (" It would have replaced the existing VLDB server "
2503 for (addrbuf[0] = '\0', mhidx = 0; mhidx < VL_MAXIPADDRS_PERMH; mhidx++) {
2504 if (!exp->ex_addrs[mhidx])
2507 strlcat(addrbuf, " ", sizeof(addrbuf));
2508 append_addr(addrbuf, ntohl(exp->ex_addrs[mhidx]), sizeof(addrbuf));
2510 VLog(0, (" entry %d: [%s]\n", FoundUuid, addrbuf));
2515 VLog(0, (" Yet another VLDB server entry exists:\n"));
2517 VLog(0, (" Yet other VLDB server entries exist:\n"));
2518 for (j = 0; j < count; j++) {
2519 srvidx = WillChange[j];
2520 VLog(0, (" entry %d: ", srvidx));
2522 code = multiHomedExtent(&ctx, srvidx, &exp);
2528 for (mhidx = 0; mhidx < VL_MAXIPADDRS_PERMH; mhidx++) {
2529 if (!exp->ex_addrs[mhidx])
2532 strlcat(addrbuf, " ", sizeof(addrbuf));
2533 append_addr(addrbuf, ntohl(exp->ex_addrs[mhidx]), sizeof(addrbuf));
2536 append_addr(addrbuf, ctx.hostaddress[srvidx], sizeof(addrbuf));
2538 VLog(0, (" entry %d: [%s]\n", srvidx, addrbuf));
2542 VLog(0, (" You must 'vos changeaddr' this other server entry\n"));
2545 (" You must 'vos changeaddr' these other server entries\n"));
2548 (" and/or remove the sysid file from the registering fileserver\n"));
2549 VLog(0, (" before the fileserver can be registered in the VLDB.\n"));
2551 code = VL_MULTIPADDR;
2555 /* Passed the checks. Now find and update the existing mh entry, or create
2558 if (foundUuidEntry) {
2559 /* Found the entry with same uuid. See if we need to change it */
2562 code = multiHomedExtentBase(&ctx, FoundUuid, &exp, &base);
2566 /* Determine if the entry has changed */
2567 for (k = 0; ((k < cnt) && !change); k++) {
2568 if (ntohl(exp->ex_addrs[k]) != addrs[k])
2571 for (; ((k < VL_MAXIPADDRS_PERMH) && !change); k++) {
2572 if (exp->ex_addrs[k] != 0)
2576 return (ubik_EndTrans(ctx.trans));
2580 VLog(0, ("The following fileserver is being registered in the VLDB:\n"));
2581 for (addrbuf[0] = '\0', k = 0; k < cnt; k++) {
2583 strlcat(addrbuf, " ", sizeof(addrbuf));
2584 append_addr(addrbuf, addrs[k], sizeof(addrbuf));
2586 VLog(0, (" [%s]\n", addrbuf));
2588 if (foundUuidEntry) {
2590 (" It will replace the following existing entry in the VLDB (same uuid):\n"));
2591 for (addrbuf[0] = '\0', k = 0; k < VL_MAXIPADDRS_PERMH; k++) {
2592 if (exp->ex_addrs[k] == 0)
2595 strlcat(addrbuf, " ", sizeof(addrbuf));
2596 append_addr(addrbuf, ntohl(exp->ex_addrs[k]), sizeof(addrbuf));
2598 VLog(0, (" entry %d: [%s]\n", FoundUuid, addrbuf));
2599 } else if (willReplaceCnt || (count == 1)) {
2600 /* If we are not replacing an entry and there is only one entry to change,
2601 * then we will replace that entry.
2603 if (!willReplaceCnt) {
2604 ReplaceEntry = WillChange[0];
2608 /* Have an entry that needs to be replaced */
2609 code = multiHomedExtentBase(&ctx, ReplaceEntry, &exp, &base);
2615 (" It will replace the following existing entry in the VLDB (new uuid):\n"));
2616 for (addrbuf[0] = '\0', k = 0; k < VL_MAXIPADDRS_PERMH; k++) {
2617 if (exp->ex_addrs[k] == 0)
2620 strlcat(addrbuf, " ", sizeof(addrbuf));
2621 append_addr(addrbuf, ntohl(exp->ex_addrs[k]), sizeof(addrbuf));
2623 VLog(0, (" entry %d: [%s]\n", ReplaceEntry, addrbuf));
2625 /* Not a mh entry. So we have to create a new mh entry and
2626 * put it on the ReplaceEntry slot of the ctx.hostaddress array.
2629 append_addr(addrbuf, ctx.hostaddress[ReplaceEntry], sizeof(addrbuf));
2630 VLog(0, (" It will replace existing entry %d, %s,"
2631 " in the VLDB (new uuid):\n", ReplaceEntry, addrbuf));
2633 FindExtentBlock(&ctx, uuidp, 1, ReplaceEntry, &exp, &base);
2641 /* There is no entry for this server, must create a new mh entry as
2642 * well as use a new slot of the ctx.hostaddress array.
2644 VLog(0, (" It will create a new entry in the VLDB.\n"));
2645 code = FindExtentBlock(&ctx, uuidp, 1, -1, &exp, &base);
2653 /* Now we have a mh entry to fill in. Update the uuid, bump the
2654 * uniquifier, and fill in its IP addresses.
2657 afs_htonuuid(&tuuid);
2658 exp->ex_hostuuid = tuuid;
2659 exp->ex_uniquifier = htonl(ntohl(exp->ex_uniquifier) + 1);
2660 for (k = 0; k < cnt; k++) {
2661 exp->ex_addrs[k] = htonl(addrs[k]);
2663 for (; k < VL_MAXIPADDRS_PERMH; k++) {
2664 exp->ex_addrs[k] = 0;
2667 /* Write the new mh entry out */
2670 DOFFSET(ntohl(ctx.ex_addr[0]->ex_contaddrs[base]),
2671 (char *)ctx.ex_addr[base], (char *)exp), (char *)exp,
2677 /* Remove any common addresses from other mh entres. We know these entries
2678 * are being changed and not replaced so they are mh entries.
2681 for (i = 0; i < count; i++) {
2684 /* Skip the entry we replaced */
2685 if (willReplaceCnt && (WillChange[i] == ReplaceEntry))
2688 code = multiHomedExtentBase(&ctx, WillChange[i], &tex, &base);
2694 (" The following existing entries in the VLDB will be updated:\n"));
2696 for (addrbuf[0] = '\0', h = j = 0; j < VL_MAXIPADDRS_PERMH; j++) {
2697 if (tex->ex_addrs[j]) {
2699 strlcat(addrbuf, " ", sizeof(addrbuf));
2700 append_addr(addrbuf, ntohl(tex->ex_addrs[j]), sizeof(addrbuf));
2703 for (k = 0; k < cnt; k++) {
2704 if (ntohl(tex->ex_addrs[j]) == addrs[k])
2708 /* Not found, so we keep it */
2709 tex->ex_addrs[h] = tex->ex_addrs[j];
2713 for (j = h; j < VL_MAXIPADDRS_PERMH; j++) {
2714 tex->ex_addrs[j] = 0; /* zero rest of mh entry */
2716 VLog(0, (" entry %d: [%s]\n", WillChange[i], addrbuf));
2718 /* Write out the modified mh entry */
2719 tex->ex_uniquifier = htonl(ntohl(tex->ex_uniquifier) + 1);
2721 DOFFSET(ntohl(ctx.ex_addr[0]->ex_contaddrs[base]),
2722 (char *)ctx.ex_addr[base], (char *)tex);
2723 if (vlwrite(ctx.trans, doff, (char *)tex, sizeof(*tex))) {
2729 return (ubik_EndTrans(ctx.trans));
2732 countAbort(this_op);
2733 ubik_AbortTrans(ctx.trans);
2738 SVL_GetAddrsU(struct rx_call *rxcall,
2739 struct ListAddrByAttributes *attributes,
2741 afs_int32 *uniquifier,
2742 afs_int32 *nentries,
2745 int this_op = VLGETADDRSU;
2746 afs_int32 code, index;
2748 int nservers, i, j, base = 0;
2749 struct extentaddr *exp = 0;
2751 afs_uint32 *taddrp, taddr;
2752 char rxstr[AFS_RXINFO_LEN];
2754 countRequest(this_op);
2755 addrsp->bulkaddrs_len = *nentries = 0;
2756 addrsp->bulkaddrs_val = 0;
2757 VLog(5, ("GetAddrsU %s\n", rxinfo(rxstr, rxcall)));
2758 if ((code = Init_VLdbase(&ctx, LOCKREAD, this_op)))
2761 if (attributes->Mask & VLADDR_IPADDR) {
2762 if (attributes->Mask & (VLADDR_INDEX | VLADDR_UUID)) {
2766 /* Search for a server registered with the VLDB with this ip address. */
2767 for (index = 0; index <= MAXSERVERID; index++) {
2768 code = multiHomedExtent(&ctx, index, &exp);
2773 for (j = 0; j < VL_MAXIPADDRS_PERMH; j++) {
2774 if (exp->ex_addrs[j]
2775 && (ntohl(exp->ex_addrs[j]) == attributes->ipaddr)) {
2779 if (j < VL_MAXIPADDRS_PERMH)
2783 if (index > MAXSERVERID) {
2787 } else if (attributes->Mask & VLADDR_INDEX) {
2788 if (attributes->Mask & (VLADDR_IPADDR | VLADDR_UUID)) {
2792 /* VLADDR_INDEX index is one based */
2793 if (attributes->index < 1 || attributes->index > MAXSERVERID) {
2794 code = VL_INDEXERANGE;
2797 index = attributes->index - 1;
2798 code = multiHomedExtent(&ctx, index, &exp);
2803 } else if (attributes->Mask & VLADDR_UUID) {
2804 if (attributes->Mask & (VLADDR_IPADDR | VLADDR_INDEX)) {
2808 if (!ctx.ex_addr[0]) { /* mh servers probably aren't setup on this vldb */
2812 code = FindExtentBlock(&ctx, &attributes->uuid, 0, -1, &exp, &base);
2824 addrsp->bulkaddrs_val = taddrp =
2825 malloc(sizeof(afs_uint32) * (MAXSERVERID + 1));
2826 nservers = *nentries = addrsp->bulkaddrs_len = 0;
2831 tuuid = exp->ex_hostuuid;
2832 afs_ntohuuid(&tuuid);
2833 if (afs_uuid_is_nil(&tuuid)) {
2840 *uniquifier = ntohl(exp->ex_uniquifier);
2841 for (i = 0; i < VL_MAXIPADDRS_PERMH; i++) {
2842 if (exp->ex_addrs[i]) {
2843 taddr = ntohl(exp->ex_addrs[i]);
2844 /* Weed out duplicates */
2845 for (j = 0; j < nservers; j++) {
2846 if (taddrp[j] == taddr)
2849 if ((j == nservers) && (j <= MAXSERVERID)) {
2850 taddrp[nservers] = taddr;
2855 addrsp->bulkaddrs_len = *nentries = nservers;
2856 return (ubik_EndTrans(ctx.trans));
2859 countAbort(this_op);
2860 ubik_AbortTrans(ctx.trans);
2864 /* ============> End of Exported vldb RPC functions <============= */
2867 /* Routine that copies the given vldb entry to the output buffer, vldbentries. */
2869 put_attributeentry(struct vl_ctx *ctx,
2870 struct vldbentry **Vldbentry,
2871 struct vldbentry **VldbentryFirst,
2872 struct vldbentry **VldbentryLast,
2873 bulkentries *vldbentries,
2874 struct nvlentry *entry,
2875 afs_int32 *nentries,
2876 afs_int32 *alloccnt)
2882 if (*Vldbentry == *VldbentryLast) {
2884 return VL_SIZEEXCEEDED; /* no growing if smallMem defined */
2886 /* Allocate another set of memory; each time allocate twice as
2887 * many blocks as the last time. When we reach VLDBALLOCLIMIT,
2888 * then grow in increments of VLDBALLOCINCR.
2890 allo = (*alloccnt > VLDBALLOCLIMIT) ? VLDBALLOCINCR : *alloccnt;
2891 reall = realloc(*VldbentryFirst,
2892 (*alloccnt + allo) * sizeof(vldbentry));
2896 *VldbentryFirst = vldbentries->bulkentries_val = reall;
2897 *Vldbentry = *VldbentryFirst + *alloccnt;
2898 *VldbentryLast = *Vldbentry + allo;
2902 code = vlentry_to_vldbentry(ctx, entry, *Vldbentry);
2908 vldbentries->bulkentries_len++;
2913 put_nattributeentry(struct vl_ctx *ctx,
2914 struct nvldbentry **Vldbentry,
2915 struct nvldbentry **VldbentryFirst,
2916 struct nvldbentry **VldbentryLast,
2917 nbulkentries *vldbentries,
2918 struct nvlentry *entry,
2919 afs_int32 matchtype,
2920 afs_int32 matchindex,
2921 afs_int32 *nentries,
2922 afs_int32 *alloccnt)
2928 if (*Vldbentry == *VldbentryLast) {
2930 return VL_SIZEEXCEEDED; /* no growing if smallMem defined */
2932 /* Allocate another set of memory; each time allocate twice as
2933 * many blocks as the last time. When we reach VLDBALLOCLIMIT,
2934 * then grow in increments of VLDBALLOCINCR.
2936 allo = (*alloccnt > VLDBALLOCLIMIT) ? VLDBALLOCINCR : *alloccnt;
2937 reall = realloc(*VldbentryFirst,
2938 (*alloccnt + allo) * sizeof(nvldbentry));
2942 *VldbentryFirst = vldbentries->nbulkentries_val = reall;
2943 *Vldbentry = *VldbentryFirst + *alloccnt;
2944 *VldbentryLast = *Vldbentry + allo;
2947 code = vlentry_to_nvldbentry(ctx, entry, *Vldbentry);
2951 (*Vldbentry)->matchindex = (matchtype << 16) + matchindex;
2954 vldbentries->nbulkentries_len++;
2959 /* Common code to actually remove a vldb entry from the database. */
2961 RemoveEntry(struct vl_ctx *ctx, afs_int32 entryptr,
2962 struct nvlentry *tentry)
2966 if ((code = UnthreadVLentry(ctx, entryptr, tentry)))
2968 if ((code = FreeBlock(ctx, entryptr)))
2974 ReleaseEntry(struct nvlentry *tentry, afs_int32 releasetype)
2976 if (releasetype & LOCKREL_TIMESTAMP)
2977 tentry->LockTimestamp = 0;
2978 if (releasetype & LOCKREL_OPCODE)
2979 tentry->flags &= ~VLOP_ALLOPERS;
2980 if (releasetype & LOCKREL_AFSID)
2981 tentry->LockAfsId = 0;
2985 /* Verify that the incoming vldb entry is valid; multi type of error codes
2988 check_vldbentry(struct vldbentry *aentry)
2992 if (InvalidVolname(aentry->name))
2994 if (aentry->nServers <= 0 || aentry->nServers > OMAXNSERVERS)
2995 return VL_BADSERVER;
2996 for (i = 0; i < aentry->nServers; i++) {
2997 /* if (aentry->serverNumber[i] < 0 || aentry->serverNumber[i] > MAXSERVERID)
2998 return VL_BADSERVER; */
2999 if (aentry->serverPartition[i] < 0
3000 || aentry->serverPartition[i] > MAXPARTITIONID)
3001 return VL_BADPARTITION;
3002 if (aentry->serverFlags[i] < 0
3003 || aentry->serverFlags[i] > MAXSERVERFLAG)
3004 return VL_BADSERVERFLAG;
3010 check_nvldbentry(struct nvldbentry *aentry)
3014 if (InvalidVolname(aentry->name))
3016 if (aentry->nServers <= 0 || aentry->nServers > NMAXNSERVERS)
3017 return VL_BADSERVER;
3018 for (i = 0; i < aentry->nServers; i++) {
3019 /* if (aentry->serverNumber[i] < 0 || aentry->serverNumber[i] > MAXSERVERID)
3020 return VL_BADSERVER; */
3021 if (aentry->serverPartition[i] < 0
3022 || aentry->serverPartition[i] > MAXPARTITIONID)
3023 return VL_BADPARTITION;
3024 if (aentry->serverFlags[i] < 0
3025 || aentry->serverFlags[i] > MAXSERVERFLAG)
3026 return VL_BADSERVERFLAG;
3032 /* Convert from the external vldb entry representation to its internal
3033 (more compact) form. This call should not change the hash chains! */
3035 vldbentry_to_vlentry(struct vl_ctx *ctx,
3036 struct vldbentry *VldbEntry,
3037 struct nvlentry *VlEntry)
3041 if (strcmp(VlEntry->name, VldbEntry->name))
3042 strncpy(VlEntry->name, VldbEntry->name, sizeof(VlEntry->name));
3043 for (i = 0; i < VldbEntry->nServers; i++) {
3044 serverindex = IpAddrToRelAddr(ctx, VldbEntry->serverNumber[i], 1);
3045 if (serverindex == -1)
3046 return VL_BADSERVER;
3047 VlEntry->serverNumber[i] = serverindex;
3048 VlEntry->serverPartition[i] = VldbEntry->serverPartition[i];
3049 VlEntry->serverFlags[i] = VldbEntry->serverFlags[i];
3051 for (; i < OMAXNSERVERS; i++)
3052 VlEntry->serverNumber[i] = VlEntry->serverPartition[i] =
3053 VlEntry->serverFlags[i] = BADSERVERID;
3054 for (i = 0; i < MAXTYPES; i++)
3055 VlEntry->volumeId[i] = VldbEntry->volumeId[i];
3056 VlEntry->cloneId = VldbEntry->cloneId;
3057 VlEntry->flags = VldbEntry->flags;
3062 nvldbentry_to_vlentry(struct vl_ctx *ctx,
3063 struct nvldbentry *VldbEntry,
3064 struct nvlentry *VlEntry)
3068 if (strcmp(VlEntry->name, VldbEntry->name))
3069 strncpy(VlEntry->name, VldbEntry->name, sizeof(VlEntry->name));
3070 for (i = 0; i < VldbEntry->nServers; i++) {
3071 serverindex = IpAddrToRelAddr(ctx, VldbEntry->serverNumber[i], 1);
3072 if (serverindex == -1)
3073 return VL_BADSERVER;
3074 VlEntry->serverNumber[i] = serverindex;
3075 VlEntry->serverPartition[i] = VldbEntry->serverPartition[i];
3076 VlEntry->serverFlags[i] = VldbEntry->serverFlags[i];
3078 for (; i < NMAXNSERVERS; i++)
3079 VlEntry->serverNumber[i] = VlEntry->serverPartition[i] =
3080 VlEntry->serverFlags[i] = BADSERVERID;
3081 for (i = 0; i < MAXTYPES; i++)
3082 VlEntry->volumeId[i] = VldbEntry->volumeId[i];
3083 VlEntry->cloneId = VldbEntry->cloneId;
3084 VlEntry->flags = VldbEntry->flags;
3089 /* Update the vldb entry with the new fields as indicated by the value of
3090 * the Mask entry in the updateentry structure. All necessary validation
3091 * checks are performed.
3094 get_vldbupdateentry(struct vl_ctx *ctx,
3095 afs_int32 blockindex,
3096 struct VldbUpdateEntry *updateentry,
3097 struct nvlentry *VlEntry)
3099 int i, j, code, serverindex;
3100 afs_uint32 checkids[MAXTYPES];
3102 /* check if any specified new IDs are already present in the db. Do
3103 * this check before doing anything else, so we don't get a half-
3105 memset(&checkids, 0, sizeof(checkids));
3106 if (updateentry->Mask & VLUPDATE_RWID) {
3107 checkids[RWVOL] = updateentry->spares3; /* rw id */
3109 if (updateentry->Mask & VLUPDATE_READONLYID) {
3110 checkids[ROVOL] = updateentry->ReadOnlyId;
3112 if (updateentry->Mask & VLUPDATE_BACKUPID) {
3113 checkids[BACKVOL] = updateentry->BackupId;
3116 if (EntryIDExists(ctx, checkids, MAXTYPES, &code)) {
3122 if (updateentry->Mask & VLUPDATE_VOLUMENAME) {
3123 struct nvlentry tentry;
3125 if (InvalidVolname(updateentry->name))
3128 if (FindByName(ctx, updateentry->name, &tentry, &code)) {
3129 return VL_NAMEEXIST;
3134 if ((code = UnhashVolname(ctx, blockindex, VlEntry)))
3136 strncpy(VlEntry->name, updateentry->name, sizeof(VlEntry->name));
3137 HashVolname(ctx, blockindex, VlEntry);
3140 if (updateentry->Mask & VLUPDATE_VOLNAMEHASH) {
3141 if ((code = UnhashVolname(ctx, blockindex, VlEntry))) {
3142 if (code != VL_NOENT)
3145 HashVolname(ctx, blockindex, VlEntry);
3148 if (updateentry->Mask & VLUPDATE_FLAGS) {
3149 VlEntry->flags = updateentry->flags;
3151 if (updateentry->Mask & VLUPDATE_CLONEID) {
3152 VlEntry->cloneId = updateentry->cloneId;
3154 if (updateentry->Mask & VLUPDATE_RWID) {
3155 if ((code = UnhashVolid(ctx, RWVOL, blockindex, VlEntry))) {
3156 if (code != VL_NOENT)
3159 VlEntry->volumeId[RWVOL] = updateentry->spares3; /* rw id */
3160 if ((code = HashVolid(ctx, RWVOL, blockindex, VlEntry)))
3163 if (updateentry->Mask & VLUPDATE_READONLYID) {
3164 if ((code = UnhashVolid(ctx, ROVOL, blockindex, VlEntry))) {
3165 if (code != VL_NOENT)
3168 VlEntry->volumeId[ROVOL] = updateentry->ReadOnlyId;
3169 if ((code = HashVolid(ctx, ROVOL, blockindex, VlEntry)))
3172 if (updateentry->Mask & VLUPDATE_BACKUPID) {
3173 if ((code = UnhashVolid(ctx, BACKVOL, blockindex, VlEntry))) {
3174 if (code != VL_NOENT)
3177 VlEntry->volumeId[BACKVOL] = updateentry->BackupId;
3178 if ((code = HashVolid(ctx, BACKVOL, blockindex, VlEntry)))
3181 if (updateentry->Mask & VLUPDATE_REPSITES) {
3182 if (updateentry->nModifiedRepsites <= 0
3183 || updateentry->nModifiedRepsites > OMAXNSERVERS)
3184 return VL_BADSERVER;
3185 for (i = 0; i < updateentry->nModifiedRepsites; i++) {
3186 /* if (updateentry->RepsitesTargetServer[i] < 0 || updateentry->RepsitesTargetServer[i] > MAXSERVERID)
3187 return VL_BADSERVER; */
3188 if (updateentry->RepsitesTargetPart[i] < 0
3189 || updateentry->RepsitesTargetPart[i] > MAXPARTITIONID)
3190 return VL_BADPARTITION;
3191 if (updateentry->RepsitesMask[i] & VLUPDATE_REPS_DELETE) {
3193 repsite_exists(VlEntry,
3194 IpAddrToRelAddr(ctx, updateentry->
3195 RepsitesTargetServer[i],
3197 updateentry->RepsitesTargetPart[i])) !=
3199 repsite_compress(VlEntry, j);
3201 return VL_NOREPSERVER;
3203 if (updateentry->RepsitesMask[i] & VLUPDATE_REPS_ADD) {
3204 /* if (updateentry->RepsitesNewServer[i] < 0 || updateentry->RepsitesNewServer[i] > MAXSERVERID)
3205 return VL_BADSERVER; */
3206 if (updateentry->RepsitesNewPart[i] < 0
3207 || updateentry->RepsitesNewPart[i] > MAXPARTITIONID)
3208 return VL_BADPARTITION;
3211 IpAddrToRelAddr(ctx, updateentry->RepsitesNewServer[i], 1),
3212 updateentry->RepsitesNewPart[i]) != -1)
3213 return VL_DUPREPSERVER;
3215 VlEntry->serverNumber[j] != BADSERVERID
3216 && j < OMAXNSERVERS; j++);
3217 if (j >= OMAXNSERVERS)
3220 IpAddrToRelAddr(ctx, updateentry->RepsitesNewServer[i],
3222 return VL_BADSERVER;
3223 VlEntry->serverNumber[j] = serverindex;
3224 VlEntry->serverPartition[j] = updateentry->RepsitesNewPart[i];
3225 if (updateentry->RepsitesNewFlags[i] < 0
3226 || updateentry->RepsitesNewFlags[i] > MAXSERVERFLAG)
3227 return VL_BADSERVERFLAG;
3228 VlEntry->serverFlags[j] = updateentry->RepsitesNewFlags[i];
3230 if (updateentry->RepsitesMask[i] & VLUPDATE_REPS_MODSERV) {
3231 /*n if (updateentry->RepsitesNewServer[i] < 0 || updateentry->RepsitesNewServer[i] > MAXSERVERID)
3232 return VL_BADSERVER; */
3234 repsite_exists(VlEntry,
3235 IpAddrToRelAddr(ctx, updateentry->
3236 RepsitesTargetServer[i],
3238 updateentry->RepsitesTargetPart[i])) !=
3240 VlEntry->serverNumber[j] =
3241 IpAddrToRelAddr(ctx, updateentry->RepsitesNewServer[i],
3244 return VL_NOREPSERVER;
3246 if (updateentry->RepsitesMask[i] & VLUPDATE_REPS_MODPART) {
3247 if (updateentry->RepsitesNewPart[i] < 0
3248 || updateentry->RepsitesNewPart[i] > MAXPARTITIONID)
3249 return VL_BADPARTITION;
3251 repsite_exists(VlEntry,
3252 IpAddrToRelAddr(ctx, updateentry->
3253 RepsitesTargetServer[i],
3255 updateentry->RepsitesTargetPart[i])) !=
3257 VlEntry->serverPartition[j] =
3258 updateentry->RepsitesNewPart[i];
3260 return VL_NOREPSERVER;
3262 if (updateentry->RepsitesMask[i] & VLUPDATE_REPS_MODFLAG) {
3264 repsite_exists(VlEntry,
3265 IpAddrToRelAddr(ctx, updateentry->
3266 RepsitesTargetServer[i],
3268 updateentry->RepsitesTargetPart[i])) !=
3270 if (updateentry->RepsitesNewFlags[i] < 0
3271 || updateentry->RepsitesNewFlags[i] > MAXSERVERFLAG)
3272 return VL_BADSERVERFLAG;
3273 VlEntry->serverFlags[j] =
3274 updateentry->RepsitesNewFlags[i];
3276 return VL_NOREPSERVER;
3284 /* Check if the specified [server,partition] entry is found in the vldb
3285 * entry's repsite table; it's offset in the table is returned, if it's
3288 repsite_exists(struct nvlentry *VlEntry, int server, int partition)
3292 for (i = 0; VlEntry->serverNumber[i] != BADSERVERID && i < OMAXNSERVERS;
3294 if ((VlEntry->serverNumber[i] == server)
3295 && (VlEntry->serverPartition[i] == partition))
3303 /* Repsite table compression: used when deleting a repsite entry so that
3304 * all active repsite entries are on the top of the table. */
3306 repsite_compress(struct nvlentry *VlEntry, int offset)
3308 int repsite_offset = offset;
3310 VlEntry->serverNumber[repsite_offset] != BADSERVERID
3311 && repsite_offset < OMAXNSERVERS - 1; repsite_offset++) {
3312 VlEntry->serverNumber[repsite_offset] =
3313 VlEntry->serverNumber[repsite_offset + 1];
3314 VlEntry->serverPartition[repsite_offset] =
3315 VlEntry->serverPartition[repsite_offset + 1];
3316 VlEntry->serverFlags[repsite_offset] =
3317 VlEntry->serverFlags[repsite_offset + 1];
3319 VlEntry->serverNumber[repsite_offset] = BADSERVERID;
3323 /* Convert from the internal (compacted) vldb entry to the external
3324 * representation used by the interface. */
3326 vlentry_to_vldbentry(struct vl_ctx *ctx, struct nvlentry *VlEntry,
3327 struct vldbentry *VldbEntry)
3330 struct extentaddr *exp;
3332 memset(VldbEntry, 0, sizeof(struct vldbentry));
3333 strncpy(VldbEntry->name, VlEntry->name, sizeof(VldbEntry->name));
3334 for (i = 0; i < OMAXNSERVERS; i++) {
3335 if (VlEntry->serverNumber[i] == BADSERVERID)
3337 code = multiHomedExtent(ctx, VlEntry->serverNumber[i], &exp);
3341 /* For now return the first ip address back */
3342 for (j = 0; j < VL_MAXIPADDRS_PERMH; j++) {
3343 if (exp->ex_addrs[j]) {
3344 VldbEntry->serverNumber[i] = ntohl(exp->ex_addrs[j]);
3349 VldbEntry->serverNumber[i] =
3350 ctx->hostaddress[VlEntry->serverNumber[i]];
3351 VldbEntry->serverPartition[i] = VlEntry->serverPartition[i];
3352 VldbEntry->serverFlags[i] = VlEntry->serverFlags[i];
3354 VldbEntry->nServers = i;
3355 for (i = 0; i < MAXTYPES; i++)
3356 VldbEntry->volumeId[i] = VlEntry->volumeId[i];
3357 VldbEntry->cloneId = VlEntry->cloneId;
3358 VldbEntry->flags = VlEntry->flags;
3364 /* Convert from the internal (compacted) vldb entry to the external
3365 * representation used by the interface. */
3367 vlentry_to_nvldbentry(struct vl_ctx *ctx, struct nvlentry *VlEntry,
3368 struct nvldbentry *VldbEntry)
3371 struct extentaddr *exp;
3373 memset(VldbEntry, 0, sizeof(struct nvldbentry));
3374 strncpy(VldbEntry->name, VlEntry->name, sizeof(VldbEntry->name));
3375 for (i = 0; i < NMAXNSERVERS; i++) {
3376 if (VlEntry->serverNumber[i] == BADSERVERID)
3378 code = multiHomedExtent(ctx, VlEntry->serverNumber[i], &exp);
3383 /* For now return the first ip address back */
3384 for (j = 0; j < VL_MAXIPADDRS_PERMH; j++) {
3385 if (exp->ex_addrs[j]) {
3386 VldbEntry->serverNumber[i] = ntohl(exp->ex_addrs[j]);
3391 VldbEntry->serverNumber[i] =
3392 ctx->hostaddress[VlEntry->serverNumber[i]];
3393 VldbEntry->serverPartition[i] = VlEntry->serverPartition[i];
3394 VldbEntry->serverFlags[i] = VlEntry->serverFlags[i];
3396 VldbEntry->nServers = i;
3397 for (i = 0; i < MAXTYPES; i++)
3398 VldbEntry->volumeId[i] = VlEntry->volumeId[i];
3399 VldbEntry->cloneId = VlEntry->cloneId;
3400 VldbEntry->flags = VlEntry->flags;
3406 vlentry_to_uvldbentry(struct vl_ctx *ctx, struct nvlentry *VlEntry,
3407 struct uvldbentry *VldbEntry)
3410 struct extentaddr *exp;
3412 memset(VldbEntry, 0, sizeof(struct uvldbentry));
3413 strncpy(VldbEntry->name, VlEntry->name, sizeof(VldbEntry->name));
3414 for (i = 0; i < NMAXNSERVERS; i++) {
3415 if (VlEntry->serverNumber[i] == BADSERVERID)
3417 VldbEntry->serverFlags[i] = VlEntry->serverFlags[i];
3418 VldbEntry->serverUnique[i] = 0;
3419 code = multiHomedExtent(ctx, VlEntry->serverNumber[i], &exp);
3426 tuuid = exp->ex_hostuuid;
3427 afs_ntohuuid(&tuuid);
3428 VldbEntry->serverFlags[i] |= VLSF_UUID;
3429 VldbEntry->serverNumber[i] = tuuid;
3430 VldbEntry->serverUnique[i] = ntohl(exp->ex_uniquifier);
3432 VldbEntry->serverNumber[i].time_low =
3433 ctx->hostaddress[VlEntry->serverNumber[i]];
3435 VldbEntry->serverPartition[i] = VlEntry->serverPartition[i];
3438 VldbEntry->nServers = i;
3439 for (i = 0; i < MAXTYPES; i++)
3440 VldbEntry->volumeId[i] = VlEntry->volumeId[i];
3441 VldbEntry->cloneId = VlEntry->cloneId;
3442 VldbEntry->flags = VlEntry->flags;
3447 #define LEGALCHARS ".ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"
3450 /* Verify that the volname is a valid volume name. */
3452 InvalidVolname(char *volname)
3458 slen = strlen(volname);
3459 if (slen >= VL_MAXNAMELEN)
3461 return (slen != strspn(volname, map));
3465 /* Verify that the given volume type is valid. */
3467 InvalidVoltype(afs_int32 voltype)
3469 if (voltype != RWVOL && voltype != ROVOL && voltype != BACKVOL)
3476 InvalidOperation(afs_int32 voloper)
3478 if (voloper != VLOP_MOVE && voloper != VLOP_RELEASE
3479 && voloper != VLOP_BACKUP && voloper != VLOP_DELETE
3480 && voloper != VLOP_DUMP)
3486 InvalidReleasetype(afs_int32 releasetype)
3488 if ((releasetype & LOCKREL_TIMESTAMP) || (releasetype & LOCKREL_OPCODE)
3489 || (releasetype & LOCKREL_AFSID))
3495 IpAddrToRelAddr(struct vl_ctx *ctx, afs_uint32 ipaddr, int create)
3499 struct extentaddr *exp;
3501 for (i = 0; i <= MAXSERVERID; i++) {
3502 if (ctx->hostaddress[i] == ipaddr)
3504 code = multiHomedExtent(ctx, i, &exp);
3508 for (j = 0; j < VL_MAXIPADDRS_PERMH; j++) {
3509 if (exp->ex_addrs[j] && (ntohl(exp->ex_addrs[j]) == ipaddr)) {
3516 /* allocate the new server a server id pronto */
3518 for (i = 0; i <= MAXSERVERID; i++) {
3519 if (ctx->cheader->IpMappedAddr[i] == 0) {
3520 ctx->cheader->IpMappedAddr[i] = htonl(ipaddr);
3523 DOFFSET(0, ctx->cheader, &ctx->cheader->IpMappedAddr[i]),
3524 (char *)&ctx->cheader->IpMappedAddr[i],
3526 ctx->hostaddress[i] = ipaddr;
3537 ChangeIPAddr(struct vl_ctx *ctx, afs_uint32 ipaddr1, afs_uint32 ipaddr2)
3541 struct extentaddr *exp = NULL;
3545 afs_int32 blockindex, count;
3547 struct nvlentry tentry;
3548 int ipaddr1_id = -1, ipaddr2_id = -1;
3552 /* Don't let addr change to 255.*.*.* : Causes internal error below */
3553 if ((ipaddr2 & 0xff000000) == 0xff000000)
3554 return (VL_BADSERVER);
3556 /* If we are removing an address, ip1 will be -1 and ip2 will be
3557 * the original address. This prevents an older revision vlserver
3558 * from removing the IP address (won't find server 0xfffffff in
3559 * the VLDB). An older revision vlserver does not have the check
3560 * to see if any volumes exist on the server being removed.
3562 if (ipaddr1 == 0xffffffff) {
3567 for (i = 0; i <= MAXSERVERID; i++) {
3568 struct extentaddr *texp = NULL;
3571 code = multiHomedExtentBase(ctx, i, &texp, &tbase);
3576 for (mhidx = 0; mhidx < VL_MAXIPADDRS_PERMH; mhidx++) {
3577 if (!texp->ex_addrs[mhidx])
3579 if (ntohl(texp->ex_addrs[mhidx]) == ipaddr1) {
3584 if (ipaddr2 != 0 && ntohl(texp->ex_addrs[mhidx]) == ipaddr2) {
3589 if (ctx->hostaddress[i] == ipaddr1) {
3594 if (ipaddr2 != 0 && ctx->hostaddress[i] == ipaddr2) {
3599 if (ipaddr1_id >= 0 && (ipaddr2 == 0 || ipaddr2_id >= 0)) {
3600 /* we've either found both IPs already in the VLDB, or we found
3601 * ipaddr1, and we're not going to find ipaddr2 because it's 0 */
3606 if (ipaddr1_id < 0) {
3607 return VL_NOENT; /* not found */
3610 if (ipaddr2_id >= 0 && ipaddr2_id != ipaddr1_id) {
3611 char buf1[16], buf2[16];
3612 VLog(0, ("Cannot change IP address from %s to %s because the latter "
3613 "is in use by server id %d\n",
3614 afs_inet_ntoa_r(htonl(ipaddr1), buf1),
3615 afs_inet_ntoa_r(htonl(ipaddr2), buf2),
3617 return VL_MULTIPADDR;
3620 /* If we are removing a server entry, a volume cannot
3621 * exist on the server. If one does, don't remove the
3622 * server entry: return error "volume entry exists".
3625 for (blockindex = NextEntry(ctx, 0, &tentry, &count); blockindex;
3626 blockindex = NextEntry(ctx, blockindex, &tentry, &count)) {
3627 if (++pollcount > 50) {
3628 #ifndef AFS_PTHREAD_ENV
3633 for (j = 0; j < NMAXNSERVERS; j++) {
3634 if (tentry.serverNumber[j] == BADSERVERID)
3636 if (tentry.serverNumber[j] == ipaddr1_id) {
3642 /* Do not allow changing addresses in multi-homed entries.
3643 Older versions of this RPC would silently "downgrade" mh entries
3644 to single-homed entries and orphan the mh enties. */
3646 append_addr(addrbuf1, ipaddr1, sizeof(addrbuf1));
3647 VLog(0, ("Refusing to change address %s in multi-homed entry; "
3648 "use RegisterAddrs instead.\n", addrbuf1));
3649 return VL_NOENT; /* single-homed entry not found */
3652 /* Log a message saying we are changing/removing an IP address */
3654 ("The following IP address is being %s:\n",
3655 (ipaddr2 ? "changed" : "removed")));
3656 addrbuf1[0] = addrbuf2[0] = '\0';
3658 for (mhidx = 0; mhidx < VL_MAXIPADDRS_PERMH; mhidx++) {
3659 if (!exp->ex_addrs[mhidx])
3662 strlcat(addrbuf1, " ", sizeof(addrbuf1));
3663 append_addr(addrbuf1, ntohl(exp->ex_addrs[mhidx]), sizeof(addrbuf1));
3666 append_addr(addrbuf1, ipaddr1, sizeof(addrbuf1));
3669 append_addr(addrbuf2, ipaddr2, sizeof(addrbuf2));
3671 VLog(0, (" entry %d: [%s] -> [%s]\n", ipaddr1_id, addrbuf1, addrbuf2));
3673 /* Change the registered uuuid addresses */
3674 if (exp && base != -1) {
3675 memset(&tuuid, 0, sizeof(afsUUID));
3676 afs_htonuuid(&tuuid);
3677 exp->ex_hostuuid = tuuid;
3680 DOFFSET(ntohl(ctx->ex_addr[0]->ex_contaddrs[base]),
3681 (char *)ctx->ex_addr[base], (char *)exp),
3682 (char *)&tuuid, sizeof(tuuid));
3687 /* Now change the host address entry */
3688 ctx->cheader->IpMappedAddr[ipaddr1_id] = htonl(ipaddr2);
3690 vlwrite(ctx->trans, DOFFSET(0, ctx->cheader, &ctx->cheader->IpMappedAddr[ipaddr1_id]),
3692 &ctx->cheader->IpMappedAddr[ipaddr1_id], sizeof(afs_int32));
3693 ctx->hostaddress[ipaddr1_id] = ipaddr2;
3700 /* see if the vlserver is back yet */
3702 SVL_ProbeServer(struct rx_call *rxcall)