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;
1663 char volumename[VL_MAXNAMELEN+2]; /* regex anchors */
1664 char rxstr[AFS_RXINFO_LEN];
1665 #ifdef HAVE_POSIX_REGEX
1667 int need_regfree = 0;
1672 countRequest(this_op);
1674 if (!afsconf_CheckRestrictedQuery(vldb_confdir, rxcall,
1675 restrictedQueryLevel))
1678 vldbentries->nbulkentries_val = 0;
1679 vldbentries->nbulkentries_len = 0;
1681 *nextstartindex = -1;
1683 code = Init_VLdbase(&ctx, LOCKREAD, this_op);
1687 Vldbentry = VldbentryFirst = vldbentries->nbulkentries_val =
1688 malloc(maxCount * sizeof(nvldbentry));
1689 if (Vldbentry == NULL) {
1690 countAbort(this_op);
1691 ubik_AbortTrans(ctx.trans);
1695 VldbentryLast = VldbentryFirst + maxCount;
1697 /* Handle the attribute by volume id totally separate of the rest
1698 * (thus additional Mask values are ignored if VLLIST_VOLUMEID is set!)
1700 if (attributes->Mask & VLLIST_VOLUMEID) {
1702 FindByID(&ctx, attributes->volumeid, -1, &tentry, &code);
1703 if (blockindex == 0) {
1708 put_nattributeentry(&ctx, &Vldbentry, &VldbentryFirst,
1709 &VldbentryLast, vldbentries, &tentry, 0,
1710 0, nentries, &maxCount);
1716 /* Search each entry in the database and return all entries
1717 * that match the request. It checks volumename (with
1718 * wildcarding), entry flags, server, and partition.
1721 /* Get the server index for matching server address */
1722 if (attributes->Mask & VLLIST_SERVER) {
1724 IpAddrToRelAddr(&ctx, attributes->server, 0);
1725 if (serverindex == -1)
1729 findpartition = ((attributes->Mask & VLLIST_PARTITION) ? 1 : 0);
1730 findflag = ((attributes->Mask & VLLIST_FLAG) ? 1 : 0);
1731 if (name && (strcmp(name, ".*") != 0) && (strcmp(name, "") != 0)) {
1732 sprintf(volumename, "^%s$", name);
1733 #ifdef HAVE_POSIX_REGEX
1734 if (regcomp(&re, volumename, REG_NOSUB) != 0) {
1740 t = (char *)re_comp(volumename);
1749 /* Read each entry and see if it is the one we want */
1750 blockindex = startindex;
1751 while ((blockindex = NextEntry(&ctx, blockindex, &tentry, &count))) {
1752 if (++pollcount > 50) {
1753 #ifndef AFS_PTHREAD_ENV
1759 /* Step through each server index searching for a match.
1760 * Match to an existing RW, BK, or RO volume name (preference
1761 * is in this order). Remember which index we matched against.
1763 namematchRWBK = namematchRO = 0; /* 0->notTried; 1->match; 2->noMatch */
1767 && (tentry.serverNumber[k] != BADSERVERID)); k++) {
1768 thismatch = 0; /* does this index match */
1770 /* Match against the RW or BK volume name. Remember
1771 * results in namematchRWBK. Prefer RW over BK.
1773 if (tentry.serverFlags[k] & VLSF_RWVOL) {
1774 /* Does the name match the RW name */
1775 if (tentry.flags & VLF_RWEXISTS) {
1777 sprintf(volumename, "%s", tentry.name);
1778 #ifdef HAVE_POSIX_REGEX
1779 if (regexec(&re, volumename, 0, NULL, 0) == 0) {
1780 thismatch = VLSF_RWVOL;
1783 if (re_exec(volumename)) {
1784 thismatch = VLSF_RWVOL;
1788 thismatch = VLSF_RWVOL;
1792 /* Does the name match the BK name */
1793 if (!thismatch && (tentry.flags & VLF_BACKEXISTS)) {
1795 sprintf(volumename, "%s.backup", tentry.name);
1796 #ifdef HAVE_POSIX_REGEX
1797 if (regexec(&re, volumename, 0, NULL, 0) == 0) {
1798 thismatch = VLSF_BACKVOL;
1801 if (re_exec(volumename)) {
1802 thismatch = VLSF_BACKVOL;
1806 thismatch = VLSF_BACKVOL;
1810 namematchRWBK = (thismatch ? 1 : 2);
1813 /* Match with the RO volume name. Compare once and
1814 * remember results in namematchRO. Note that this will
1815 * pick up entries marked NEWREPSITEs and DONTUSE.
1818 if (tentry.flags & VLF_ROEXISTS) {
1822 ((namematchRO == 1) ? VLSF_ROVOL : 0);
1824 sprintf(volumename, "%s.readonly",
1826 #ifdef HAVE_POSIX_REGEX
1827 if (regexec(&re, volumename, 0, NULL, 0) == 0) {
1828 thismatch = VLSF_ROVOL;
1831 if (re_exec(volumename))
1832 thismatch = VLSF_ROVOL;
1836 thismatch = VLSF_ROVOL;
1839 namematchRO = (thismatch ? 1 : 2);
1842 /* Is there a server match */
1843 if (thismatch && findserver
1844 && (tentry.serverNumber[k] != serverindex))
1847 /* Is there a partition match */
1848 if (thismatch && findpartition
1849 && (tentry.serverPartition[k] != attributes->partition))
1852 /* Is there a flag match */
1853 if (thismatch && findflag
1854 && !(tentry.flags & attributes->flag))
1857 /* We found a match. Remember the index, and type */
1861 matchtype = thismatch;
1864 /* Since we prefer RW and BK volume matches over RO matches,
1865 * if we have already checked the RWBK name, then we already
1866 * found the best match and so end the search.
1868 * If we tried matching against the RW, BK, and RO volume names
1869 * and both failed, then we end the search (none will match).
1871 if ((match && namematchRWBK)
1872 || ((namematchRWBK == 2) && (namematchRO == 2)))
1876 /* Passed all the tests. Take it */
1879 put_nattributeentry(&ctx, &Vldbentry, &VldbentryFirst,
1880 &VldbentryLast, vldbentries, &tentry,
1881 matchtype, matchindex, nentries,
1886 if (*nentries >= maxCount)
1887 break; /* collected the max */
1890 *nextstartindex = (blockindex ? blockindex : -1);
1894 #ifdef HAVE_POSIX_REGEX
1900 countAbort(this_op);
1901 ubik_AbortTrans(ctx.trans);
1902 if (vldbentries->nbulkentries_val)
1903 free(vldbentries->nbulkentries_val);
1904 vldbentries->nbulkentries_val = 0;
1905 vldbentries->nbulkentries_len = 0;
1906 *nextstartindex = -1;
1909 ("N2ListAttrs nentries=%d %s\n", vldbentries->nbulkentries_len,
1910 rxinfo(rxstr, rxcall)));
1911 code = ubik_EndTrans(ctx.trans);
1918 SVL_ListAttributesN2(struct rx_call *rxcall,
1919 struct VldbListByAttributes *attributes,
1920 char *name, /* Wildcarded volume name */
1921 afs_int32 startindex,
1922 afs_int32 *nentries,
1923 nbulkentries *vldbentries,
1924 afs_int32 *nextstartindex)
1928 code = ListAttributesN2(rxcall, attributes, name, startindex,
1929 nentries, vldbentries, nextstartindex);
1930 osi_auditU(rxcall, VLListAttributesN2Event, code, AUD_END);
1934 /* Retrieves in vldbentries all vldb entries that match the specified
1935 * attributes (by server number, partition, volume type, and flag); if
1936 * volume id is specified then the associated list for that entry is
1937 * returned. CAUTION: This could be a very expensive call since in most
1938 * cases sequential search of all vldb entries is performed.
1941 LinkedList(struct rx_call *rxcall,
1942 struct VldbListByAttributes *attributes,
1943 afs_int32 *nentries,
1944 vldb_list *vldbentries)
1946 int this_op = VLLINKEDLIST;
1949 struct nvlentry tentry;
1950 vldblist vllist, *vllistptr;
1951 afs_int32 blockindex, count, match;
1956 countRequest(this_op);
1958 if (!afsconf_CheckRestrictedQuery(vldb_confdir, rxcall,
1959 restrictedQueryLevel))
1962 if ((code = Init_VLdbase(&ctx, LOCKREAD, this_op)))
1966 vldbentries->node = NULL;
1967 vllistptr = &vldbentries->node;
1969 /* List by volumeid */
1970 if (attributes->Mask & VLLIST_VOLUMEID) {
1972 FindByID(&ctx, attributes->volumeid, -1, &tentry, &code);
1979 vllist = malloc(sizeof(single_vldbentry));
1980 if (vllist == NULL) {
1984 code = vlentry_to_vldbentry(&ctx, &tentry, &vllist->VldbEntry);
1988 vllist->next_vldb = NULL;
1990 *vllistptr = vllist; /* Thread onto list */
1991 vllistptr = &vllist->next_vldb;
1995 /* Search by server, partition, and flags */
1997 for (blockindex = NextEntry(&ctx, 0, &tentry, &count); blockindex;
1998 blockindex = NextEntry(&ctx, blockindex, &tentry, &count)) {
2001 if (++pollcount > 50) {
2002 #ifndef AFS_PTHREAD_ENV
2008 /* Does this volume exist on the desired server */
2009 if (attributes->Mask & VLLIST_SERVER) {
2011 IpAddrToRelAddr(&ctx, attributes->server, 0);
2012 if (serverindex == -1)
2014 for (k = 0; k < OMAXNSERVERS; k++) {
2015 if (tentry.serverNumber[k] == BADSERVERID)
2017 if (tentry.serverNumber[k] == serverindex) {
2026 /* Does this volume exist on the desired partition */
2027 if (attributes->Mask & VLLIST_PARTITION) {
2029 if (tentry.serverPartition[k] != attributes->partition)
2032 for (k = 0; k < OMAXNSERVERS; k++) {
2033 if (tentry.serverNumber[k] == BADSERVERID)
2035 if (tentry.serverPartition[k] ==
2036 attributes->partition) {
2046 /* Does this volume have the desired flags */
2047 if (attributes->Mask & VLLIST_FLAG) {
2048 if (!(tentry.flags & attributes->flag))
2052 vllist = malloc(sizeof(single_vldbentry));
2053 if (vllist == NULL) {
2057 code = vlentry_to_vldbentry(&ctx, &tentry, &vllist->VldbEntry);
2061 vllist->next_vldb = NULL;
2063 *vllistptr = vllist; /* Thread onto list */
2064 vllistptr = &vllist->next_vldb;
2066 if (smallMem && (*nentries >= VLDBALLOCCOUNT)) {
2067 code = VL_SIZEEXCEEDED;
2073 return ubik_EndTrans(ctx.trans);
2076 countAbort(this_op);
2077 ubik_AbortTrans(ctx.trans);
2082 SVL_LinkedList(struct rx_call *rxcall,
2083 struct VldbListByAttributes *attributes,
2084 afs_int32 *nentries,
2085 vldb_list *vldbentries)
2089 code = LinkedList(rxcall, attributes, nentries, vldbentries);
2090 osi_auditU(rxcall, VLLinkedListEvent, code, AUD_END);
2095 LinkedListN(struct rx_call *rxcall,
2096 struct VldbListByAttributes *attributes,
2097 afs_int32 *nentries,
2098 nvldb_list *vldbentries)
2100 int this_op = VLLINKEDLISTN;
2103 struct nvlentry tentry;
2104 nvldblist vllist, *vllistptr;
2105 afs_int32 blockindex, count, match;
2110 countRequest(this_op);
2112 if (!afsconf_CheckRestrictedQuery(vldb_confdir, rxcall,
2113 restrictedQueryLevel))
2116 if ((code = Init_VLdbase(&ctx, LOCKREAD, this_op)))
2120 vldbentries->node = NULL;
2121 vllistptr = &vldbentries->node;
2123 /* List by volumeid */
2124 if (attributes->Mask & VLLIST_VOLUMEID) {
2126 FindByID(&ctx, attributes->volumeid, -1, &tentry, &code);
2133 vllist = malloc(sizeof(single_nvldbentry));
2134 if (vllist == NULL) {
2138 code = vlentry_to_nvldbentry(&ctx, &tentry, &vllist->VldbEntry);
2142 vllist->next_vldb = NULL;
2144 *vllistptr = vllist; /* Thread onto list */
2145 vllistptr = &vllist->next_vldb;
2149 /* Search by server, partition, and flags */
2151 for (blockindex = NextEntry(&ctx, 0, &tentry, &count); blockindex;
2152 blockindex = NextEntry(&ctx, blockindex, &tentry, &count)) {
2155 if (++pollcount > 50) {
2156 #ifndef AFS_PTHREAD_ENV
2162 /* Does this volume exist on the desired server */
2163 if (attributes->Mask & VLLIST_SERVER) {
2165 IpAddrToRelAddr(&ctx, attributes->server, 0);
2166 if (serverindex == -1)
2168 for (k = 0; k < NMAXNSERVERS; k++) {
2169 if (tentry.serverNumber[k] == BADSERVERID)
2171 if (tentry.serverNumber[k] == serverindex) {
2180 /* Does this volume exist on the desired partition */
2181 if (attributes->Mask & VLLIST_PARTITION) {
2183 if (tentry.serverPartition[k] != attributes->partition)
2186 for (k = 0; k < NMAXNSERVERS; k++) {
2187 if (tentry.serverNumber[k] == BADSERVERID)
2189 if (tentry.serverPartition[k] ==
2190 attributes->partition) {
2200 /* Does this volume have the desired flags */
2201 if (attributes->Mask & VLLIST_FLAG) {
2202 if (!(tentry.flags & attributes->flag))
2206 vllist = malloc(sizeof(single_nvldbentry));
2207 if (vllist == NULL) {
2211 code = vlentry_to_nvldbentry(&ctx, &tentry, &vllist->VldbEntry);
2215 vllist->next_vldb = NULL;
2217 *vllistptr = vllist; /* Thread onto list */
2218 vllistptr = &vllist->next_vldb;
2220 if (smallMem && (*nentries >= VLDBALLOCCOUNT)) {
2221 code = VL_SIZEEXCEEDED;
2227 return ubik_EndTrans(ctx.trans);
2230 countAbort(this_op);
2231 ubik_AbortTrans(ctx.trans);
2236 SVL_LinkedListN(struct rx_call *rxcall,
2237 struct VldbListByAttributes *attributes,
2238 afs_int32 *nentries,
2239 nvldb_list *vldbentries)
2243 code = LinkedListN(rxcall, attributes, nentries, vldbentries);
2244 osi_auditU(rxcall, VLLinkedListNEvent, code, AUD_END);
2248 /* Get back vldb header statistics (allocs, frees, maxvolumeid,
2249 * totalentries, etc) and dynamic statistics (number of requests and/or
2250 * aborts per remote procedure call, etc)
2253 GetStats(struct rx_call *rxcall,
2255 vital_vlheader *vital_header)
2257 int this_op = VLGETSTATS;
2260 char rxstr[AFS_RXINFO_LEN];
2262 countRequest(this_op);
2264 if (!afsconf_CheckRestrictedQuery(vldb_confdir, rxcall,
2265 restrictedQueryLevel))
2268 if ((code = Init_VLdbase(&ctx, LOCKREAD, this_op)))
2270 VLog(5, ("GetStats %s\n", rxinfo(rxstr, rxcall)));
2271 memcpy((char *)vital_header, (char *)&ctx.cheader->vital_header,
2272 sizeof(vital_vlheader));
2273 memcpy((char *)stats, (char *)&dynamic_statistics, sizeof(vldstats));
2274 return ubik_EndTrans(ctx.trans);
2278 SVL_GetStats(struct rx_call *rxcall,
2280 vital_vlheader *vital_header)
2284 code = GetStats(rxcall, stats, vital_header);
2285 osi_auditU(rxcall, VLGetStatsEvent, code, AUD_END);
2289 /* Get the list of file server addresses from the VLDB. Currently it's pretty
2290 * easy to do. In the future, it might require a little bit of grunging
2291 * through the VLDB, but that's life.
2294 SVL_GetAddrs(struct rx_call *rxcall,
2297 struct VLCallBack *spare3,
2298 afs_int32 *nentries,
2301 int this_op = VLGETADDRS;
2307 countRequest(this_op);
2308 addrsp->bulkaddrs_len = *nentries = 0;
2309 addrsp->bulkaddrs_val = 0;
2310 memset(spare3, 0, sizeof(struct VLCallBack));
2312 if ((code = Init_VLdbase(&ctx, LOCKREAD, this_op)))
2315 VLog(5, ("GetAddrs\n"));
2316 addrsp->bulkaddrs_val = taddrp =
2317 malloc(sizeof(afs_uint32) * (MAXSERVERID + 1));
2318 nservers = *nentries = addrsp->bulkaddrs_len = 0;
2325 for (i = 0; i <= MAXSERVERID; i++) {
2326 if ((*taddrp = ntohl(ctx.cheader->IpMappedAddr[i]))) {
2332 addrsp->bulkaddrs_len = *nentries = nservers;
2333 return (ubik_EndTrans(ctx.trans));
2336 countAbort(this_op);
2337 ubik_AbortTrans(ctx.trans);
2342 append_addr(char *buffer, afs_uint32 addr, size_t buffer_size)
2344 int n = strlen(buffer);
2345 if (buffer_size > n) {
2346 snprintf(buffer + n, buffer_size - n, "%u.%u.%u.%u",
2347 (addr >> 24) & 0xff, (addr >> 16) & 0xff, (addr >> 8) & 0xff,
2353 SVL_RegisterAddrs(struct rx_call *rxcall, afsUUID *uuidp, afs_int32 spare1,
2356 int this_op = VLREGADDR;
2359 int cnt, h, i, j, k, m;
2360 struct extentaddr *exp = 0, *tex;
2363 afs_uint32 addrs[VL_MAXIPADDRS_PERMH];
2365 int count, willChangeEntry, foundUuidEntry, willReplaceCnt;
2366 int WillReplaceEntry, WillChange[MAXSERVERID + 1];
2368 int ReplaceEntry = 0;
2371 countRequest(this_op);
2372 if (!afsconf_SuperUser(vldb_confdir, rxcall, NULL))
2374 if ((code = Init_VLdbase(&ctx, LOCKWRITE, this_op)))
2377 /* Eliminate duplicates from IP address list */
2378 for (k = 0, cnt = 0; k < addrsp->bulkaddrs_len; k++) {
2379 if (addrsp->bulkaddrs_val[k] == 0)
2381 for (m = 0; m < cnt; m++) {
2382 if (addrs[m] == addrsp->bulkaddrs_val[k])
2386 if (m == VL_MAXIPADDRS_PERMH) {
2388 ("Number of addresses exceeds %d. Cannot register IP addr 0x%x in VLDB\n",
2389 VL_MAXIPADDRS_PERMH, addrsp->bulkaddrs_val[k]));
2391 addrs[m] = addrsp->bulkaddrs_val[k];
2397 code = VL_INDEXERANGE;
2404 /* For each server registered within the VLDB */
2405 for (srvidx = 0; srvidx <= MAXSERVERID; srvidx++) {
2406 willChangeEntry = 0;
2407 WillReplaceEntry = 1;
2408 code = multiHomedExtent(&ctx, srvidx, &exp);
2413 /* See if the addresses to register will change this server entry */
2414 tuuid = exp->ex_hostuuid;
2415 afs_ntohuuid(&tuuid);
2416 if (afs_uuid_equal(uuidp, &tuuid)) {
2420 for (mhidx = 0; mhidx < VL_MAXIPADDRS_PERMH; mhidx++) {
2421 if (!exp->ex_addrs[mhidx])
2423 for (k = 0; k < cnt; k++) {
2424 if (ntohl(exp->ex_addrs[mhidx]) == addrs[k]) {
2425 willChangeEntry = 1;
2426 WillChange[count] = srvidx;
2431 WillReplaceEntry = 0;
2435 /* The server is not registered as a multihomed.
2436 * See if the addresses to register will replace this server entry.
2438 for (k = 0; k < cnt; k++) {
2439 if (ctx.hostaddress[srvidx] == addrs[k]) {
2440 willChangeEntry = 1;
2441 WillChange[count] = srvidx;
2442 WillReplaceEntry = 1;
2447 if (willChangeEntry) {
2448 if (WillReplaceEntry) {
2450 ReplaceEntry = srvidx;
2456 /* If we found the uuid in the VLDB and if we are replacing another
2457 * entire entry, then complain and fail. Also, if we did not find
2458 * the uuid in the VLDB and the IP addresses being registered was
2459 * found in more than one other entry, then we don't know which one
2460 * to replace and will complain and fail.
2462 if ((foundUuidEntry && (willReplaceCnt > 0))
2463 || (!foundUuidEntry && (count > 1))) {
2465 ("The following fileserver is being registered in the VLDB:\n"));
2466 for (addrbuf[0] = '\0', k = 0; k < cnt; k++) {
2468 strlcat(addrbuf, " ", sizeof(addrbuf));
2469 append_addr(addrbuf, addrs[k], sizeof(addrbuf));
2471 VLog(0, (" [%s]\n", addrbuf));
2473 if (foundUuidEntry) {
2474 code = multiHomedExtent(&ctx, FoundUuid, &exp);
2476 VLog(0, (" It would have replaced the existing VLDB server "
2478 for (addrbuf[0] = '\0', mhidx = 0; mhidx < VL_MAXIPADDRS_PERMH; mhidx++) {
2479 if (!exp->ex_addrs[mhidx])
2482 strlcat(addrbuf, " ", sizeof(addrbuf));
2483 append_addr(addrbuf, ntohl(exp->ex_addrs[mhidx]), sizeof(addrbuf));
2485 VLog(0, (" entry %d: [%s]\n", FoundUuid, addrbuf));
2490 VLog(0, (" Yet another VLDB server entry exists:\n"));
2492 VLog(0, (" Yet other VLDB server entries exist:\n"));
2493 for (j = 0; j < count; j++) {
2494 srvidx = WillChange[j];
2495 VLog(0, (" entry %d: ", srvidx));
2497 code = multiHomedExtent(&ctx, srvidx, &exp);
2503 for (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));
2511 append_addr(addrbuf, ctx.hostaddress[srvidx], sizeof(addrbuf));
2513 VLog(0, (" entry %d: [%s]\n", srvidx, addrbuf));
2517 VLog(0, (" You must 'vos changeaddr' this other server entry\n"));
2520 (" You must 'vos changeaddr' these other server entries\n"));
2523 (" and/or remove the sysid file from the registering fileserver\n"));
2524 VLog(0, (" before the fileserver can be registered in the VLDB.\n"));
2526 code = VL_MULTIPADDR;
2530 /* Passed the checks. Now find and update the existing mh entry, or create
2533 if (foundUuidEntry) {
2534 /* Found the entry with same uuid. See if we need to change it */
2537 code = multiHomedExtentBase(&ctx, FoundUuid, &exp, &base);
2541 /* Determine if the entry has changed */
2542 for (k = 0; ((k < cnt) && !change); k++) {
2543 if (ntohl(exp->ex_addrs[k]) != addrs[k])
2546 for (; ((k < VL_MAXIPADDRS_PERMH) && !change); k++) {
2547 if (exp->ex_addrs[k] != 0)
2551 return (ubik_EndTrans(ctx.trans));
2555 VLog(0, ("The following fileserver is being registered in the VLDB:\n"));
2556 for (addrbuf[0] = '\0', k = 0; k < cnt; k++) {
2558 strlcat(addrbuf, " ", sizeof(addrbuf));
2559 append_addr(addrbuf, addrs[k], sizeof(addrbuf));
2561 VLog(0, (" [%s]\n", addrbuf));
2563 if (foundUuidEntry) {
2565 (" It will replace the following existing entry in the VLDB (same uuid):\n"));
2566 for (addrbuf[0] = '\0', k = 0; k < VL_MAXIPADDRS_PERMH; k++) {
2567 if (exp->ex_addrs[k] == 0)
2570 strlcat(addrbuf, " ", sizeof(addrbuf));
2571 append_addr(addrbuf, ntohl(exp->ex_addrs[k]), sizeof(addrbuf));
2573 VLog(0, (" entry %d: [%s]\n", FoundUuid, addrbuf));
2574 } else if (willReplaceCnt || (count == 1)) {
2575 /* If we are not replacing an entry and there is only one entry to change,
2576 * then we will replace that entry.
2578 if (!willReplaceCnt) {
2579 ReplaceEntry = WillChange[0];
2583 /* Have an entry that needs to be replaced */
2584 code = multiHomedExtentBase(&ctx, ReplaceEntry, &exp, &base);
2590 (" It will replace the following existing entry in the VLDB (new 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", ReplaceEntry, addrbuf));
2600 /* Not a mh entry. So we have to create a new mh entry and
2601 * put it on the ReplaceEntry slot of the ctx.hostaddress array.
2604 append_addr(addrbuf, ctx.hostaddress[ReplaceEntry], sizeof(addrbuf));
2605 VLog(0, (" It will replace existing entry %d, %s,"
2606 " in the VLDB (new uuid):\n", ReplaceEntry, addrbuf));
2608 FindExtentBlock(&ctx, uuidp, 1, ReplaceEntry, &exp, &base);
2616 /* There is no entry for this server, must create a new mh entry as
2617 * well as use a new slot of the ctx.hostaddress array.
2619 VLog(0, (" It will create a new entry in the VLDB.\n"));
2620 code = FindExtentBlock(&ctx, uuidp, 1, -1, &exp, &base);
2628 /* Now we have a mh entry to fill in. Update the uuid, bump the
2629 * uniquifier, and fill in its IP addresses.
2632 afs_htonuuid(&tuuid);
2633 exp->ex_hostuuid = tuuid;
2634 exp->ex_uniquifier = htonl(ntohl(exp->ex_uniquifier) + 1);
2635 for (k = 0; k < cnt; k++) {
2636 exp->ex_addrs[k] = htonl(addrs[k]);
2638 for (; k < VL_MAXIPADDRS_PERMH; k++) {
2639 exp->ex_addrs[k] = 0;
2642 /* Write the new mh entry out */
2645 DOFFSET(ntohl(ctx.ex_addr[0]->ex_contaddrs[base]),
2646 (char *)ctx.ex_addr[base], (char *)exp), (char *)exp,
2652 /* Remove any common addresses from other mh entres. We know these entries
2653 * are being changed and not replaced so they are mh entries.
2656 for (i = 0; i < count; i++) {
2659 /* Skip the entry we replaced */
2660 if (willReplaceCnt && (WillChange[i] == ReplaceEntry))
2663 code = multiHomedExtentBase(&ctx, WillChange[i], &tex, &base);
2669 (" The following existing entries in the VLDB will be updated:\n"));
2671 for (addrbuf[0] = '\0', h = j = 0; j < VL_MAXIPADDRS_PERMH; j++) {
2672 if (tex->ex_addrs[j]) {
2674 strlcat(addrbuf, " ", sizeof(addrbuf));
2675 append_addr(addrbuf, ntohl(tex->ex_addrs[j]), sizeof(addrbuf));
2678 for (k = 0; k < cnt; k++) {
2679 if (ntohl(tex->ex_addrs[j]) == addrs[k])
2683 /* Not found, so we keep it */
2684 tex->ex_addrs[h] = tex->ex_addrs[j];
2688 for (j = h; j < VL_MAXIPADDRS_PERMH; j++) {
2689 tex->ex_addrs[j] = 0; /* zero rest of mh entry */
2691 VLog(0, (" entry %d: [%s]\n", WillChange[i], addrbuf));
2693 /* Write out the modified mh entry */
2694 tex->ex_uniquifier = htonl(ntohl(tex->ex_uniquifier) + 1);
2696 DOFFSET(ntohl(ctx.ex_addr[0]->ex_contaddrs[base]),
2697 (char *)ctx.ex_addr[base], (char *)tex);
2698 if (vlwrite(ctx.trans, doff, (char *)tex, sizeof(*tex))) {
2704 return (ubik_EndTrans(ctx.trans));
2707 countAbort(this_op);
2708 ubik_AbortTrans(ctx.trans);
2713 SVL_GetAddrsU(struct rx_call *rxcall,
2714 struct ListAddrByAttributes *attributes,
2716 afs_int32 *uniquifier,
2717 afs_int32 *nentries,
2720 int this_op = VLGETADDRSU;
2721 afs_int32 code, index;
2723 int nservers, i, j, base = 0;
2724 struct extentaddr *exp = 0;
2726 afs_uint32 *taddrp, taddr;
2727 char rxstr[AFS_RXINFO_LEN];
2729 countRequest(this_op);
2730 addrsp->bulkaddrs_len = *nentries = 0;
2731 addrsp->bulkaddrs_val = 0;
2732 VLog(5, ("GetAddrsU %s\n", rxinfo(rxstr, rxcall)));
2733 if ((code = Init_VLdbase(&ctx, LOCKREAD, this_op)))
2736 if (attributes->Mask & VLADDR_IPADDR) {
2737 if (attributes->Mask & (VLADDR_INDEX | VLADDR_UUID)) {
2741 /* Search for a server registered with the VLDB with this ip address. */
2742 for (index = 0; index <= MAXSERVERID; index++) {
2743 code = multiHomedExtent(&ctx, index, &exp);
2748 for (j = 0; j < VL_MAXIPADDRS_PERMH; j++) {
2749 if (exp->ex_addrs[j]
2750 && (ntohl(exp->ex_addrs[j]) == attributes->ipaddr)) {
2754 if (j < VL_MAXIPADDRS_PERMH)
2758 if (index > MAXSERVERID) {
2762 } else if (attributes->Mask & VLADDR_INDEX) {
2763 if (attributes->Mask & (VLADDR_IPADDR | VLADDR_UUID)) {
2767 /* VLADDR_INDEX index is one based */
2768 if (attributes->index < 1 || attributes->index > MAXSERVERID) {
2769 code = VL_INDEXERANGE;
2772 index = attributes->index - 1;
2773 code = multiHomedExtent(&ctx, index, &exp);
2778 } else if (attributes->Mask & VLADDR_UUID) {
2779 if (attributes->Mask & (VLADDR_IPADDR | VLADDR_INDEX)) {
2783 if (!ctx.ex_addr[0]) { /* mh servers probably aren't setup on this vldb */
2787 code = FindExtentBlock(&ctx, &attributes->uuid, 0, -1, &exp, &base);
2799 addrsp->bulkaddrs_val = taddrp =
2800 malloc(sizeof(afs_uint32) * (MAXSERVERID + 1));
2801 nservers = *nentries = addrsp->bulkaddrs_len = 0;
2806 tuuid = exp->ex_hostuuid;
2807 afs_ntohuuid(&tuuid);
2808 if (afs_uuid_is_nil(&tuuid)) {
2815 *uniquifier = ntohl(exp->ex_uniquifier);
2816 for (i = 0; i < VL_MAXIPADDRS_PERMH; i++) {
2817 if (exp->ex_addrs[i]) {
2818 taddr = ntohl(exp->ex_addrs[i]);
2819 /* Weed out duplicates */
2820 for (j = 0; j < nservers; j++) {
2821 if (taddrp[j] == taddr)
2824 if ((j == nservers) && (j <= MAXSERVERID)) {
2825 taddrp[nservers] = taddr;
2830 addrsp->bulkaddrs_len = *nentries = nservers;
2831 return (ubik_EndTrans(ctx.trans));
2834 countAbort(this_op);
2835 ubik_AbortTrans(ctx.trans);
2839 /* ============> End of Exported vldb RPC functions <============= */
2842 /* Routine that copies the given vldb entry to the output buffer, vldbentries. */
2844 put_attributeentry(struct vl_ctx *ctx,
2845 struct vldbentry **Vldbentry,
2846 struct vldbentry **VldbentryFirst,
2847 struct vldbentry **VldbentryLast,
2848 bulkentries *vldbentries,
2849 struct nvlentry *entry,
2850 afs_int32 *nentries,
2851 afs_int32 *alloccnt)
2857 if (*Vldbentry == *VldbentryLast) {
2859 return VL_SIZEEXCEEDED; /* no growing if smallMem defined */
2861 /* Allocate another set of memory; each time allocate twice as
2862 * many blocks as the last time. When we reach VLDBALLOCLIMIT,
2863 * then grow in increments of VLDBALLOCINCR.
2865 allo = (*alloccnt > VLDBALLOCLIMIT) ? VLDBALLOCINCR : *alloccnt;
2866 reall = realloc(*VldbentryFirst,
2867 (*alloccnt + allo) * sizeof(vldbentry));
2871 *VldbentryFirst = vldbentries->bulkentries_val = reall;
2872 *Vldbentry = *VldbentryFirst + *alloccnt;
2873 *VldbentryLast = *Vldbentry + allo;
2877 code = vlentry_to_vldbentry(ctx, entry, *Vldbentry);
2883 vldbentries->bulkentries_len++;
2888 put_nattributeentry(struct vl_ctx *ctx,
2889 struct nvldbentry **Vldbentry,
2890 struct nvldbentry **VldbentryFirst,
2891 struct nvldbentry **VldbentryLast,
2892 nbulkentries *vldbentries,
2893 struct nvlentry *entry,
2894 afs_int32 matchtype,
2895 afs_int32 matchindex,
2896 afs_int32 *nentries,
2897 afs_int32 *alloccnt)
2903 if (*Vldbentry == *VldbentryLast) {
2905 return VL_SIZEEXCEEDED; /* no growing if smallMem defined */
2907 /* Allocate another set of memory; each time allocate twice as
2908 * many blocks as the last time. When we reach VLDBALLOCLIMIT,
2909 * then grow in increments of VLDBALLOCINCR.
2911 allo = (*alloccnt > VLDBALLOCLIMIT) ? VLDBALLOCINCR : *alloccnt;
2912 reall = realloc(*VldbentryFirst,
2913 (*alloccnt + allo) * sizeof(nvldbentry));
2917 *VldbentryFirst = vldbentries->nbulkentries_val = reall;
2918 *Vldbentry = *VldbentryFirst + *alloccnt;
2919 *VldbentryLast = *Vldbentry + allo;
2922 code = vlentry_to_nvldbentry(ctx, entry, *Vldbentry);
2926 (*Vldbentry)->matchindex = (matchtype << 16) + matchindex;
2929 vldbentries->nbulkentries_len++;
2934 /* Common code to actually remove a vldb entry from the database. */
2936 RemoveEntry(struct vl_ctx *ctx, afs_int32 entryptr,
2937 struct nvlentry *tentry)
2941 if ((code = UnthreadVLentry(ctx, entryptr, tentry)))
2943 if ((code = FreeBlock(ctx, entryptr)))
2949 ReleaseEntry(struct nvlentry *tentry, afs_int32 releasetype)
2951 if (releasetype & LOCKREL_TIMESTAMP)
2952 tentry->LockTimestamp = 0;
2953 if (releasetype & LOCKREL_OPCODE)
2954 tentry->flags &= ~VLOP_ALLOPERS;
2955 if (releasetype & LOCKREL_AFSID)
2956 tentry->LockAfsId = 0;
2960 /* Verify that the incoming vldb entry is valid; multi type of error codes
2963 check_vldbentry(struct vldbentry *aentry)
2967 if (InvalidVolname(aentry->name))
2969 if (aentry->nServers <= 0 || aentry->nServers > OMAXNSERVERS)
2970 return VL_BADSERVER;
2971 for (i = 0; i < aentry->nServers; i++) {
2972 /* if (aentry->serverNumber[i] < 0 || aentry->serverNumber[i] > MAXSERVERID)
2973 return VL_BADSERVER; */
2974 if (aentry->serverPartition[i] < 0
2975 || aentry->serverPartition[i] > MAXPARTITIONID)
2976 return VL_BADPARTITION;
2977 if (aentry->serverFlags[i] < 0
2978 || aentry->serverFlags[i] > MAXSERVERFLAG)
2979 return VL_BADSERVERFLAG;
2985 check_nvldbentry(struct nvldbentry *aentry)
2989 if (InvalidVolname(aentry->name))
2991 if (aentry->nServers <= 0 || aentry->nServers > NMAXNSERVERS)
2992 return VL_BADSERVER;
2993 for (i = 0; i < aentry->nServers; i++) {
2994 /* if (aentry->serverNumber[i] < 0 || aentry->serverNumber[i] > MAXSERVERID)
2995 return VL_BADSERVER; */
2996 if (aentry->serverPartition[i] < 0
2997 || aentry->serverPartition[i] > MAXPARTITIONID)
2998 return VL_BADPARTITION;
2999 if (aentry->serverFlags[i] < 0
3000 || aentry->serverFlags[i] > MAXSERVERFLAG)
3001 return VL_BADSERVERFLAG;
3007 /* Convert from the external vldb entry representation to its internal
3008 (more compact) form. This call should not change the hash chains! */
3010 vldbentry_to_vlentry(struct vl_ctx *ctx,
3011 struct vldbentry *VldbEntry,
3012 struct nvlentry *VlEntry)
3016 if (strcmp(VlEntry->name, VldbEntry->name))
3017 strncpy(VlEntry->name, VldbEntry->name, sizeof(VlEntry->name));
3018 for (i = 0; i < VldbEntry->nServers; i++) {
3019 serverindex = IpAddrToRelAddr(ctx, VldbEntry->serverNumber[i], 1);
3020 if (serverindex == -1)
3021 return VL_BADSERVER;
3022 VlEntry->serverNumber[i] = serverindex;
3023 VlEntry->serverPartition[i] = VldbEntry->serverPartition[i];
3024 VlEntry->serverFlags[i] = VldbEntry->serverFlags[i];
3026 for (; i < OMAXNSERVERS; i++)
3027 VlEntry->serverNumber[i] = VlEntry->serverPartition[i] =
3028 VlEntry->serverFlags[i] = BADSERVERID;
3029 for (i = 0; i < MAXTYPES; i++)
3030 VlEntry->volumeId[i] = VldbEntry->volumeId[i];
3031 VlEntry->cloneId = VldbEntry->cloneId;
3032 VlEntry->flags = VldbEntry->flags;
3037 nvldbentry_to_vlentry(struct vl_ctx *ctx,
3038 struct nvldbentry *VldbEntry,
3039 struct nvlentry *VlEntry)
3043 if (strcmp(VlEntry->name, VldbEntry->name))
3044 strncpy(VlEntry->name, VldbEntry->name, sizeof(VlEntry->name));
3045 for (i = 0; i < VldbEntry->nServers; i++) {
3046 serverindex = IpAddrToRelAddr(ctx, VldbEntry->serverNumber[i], 1);
3047 if (serverindex == -1)
3048 return VL_BADSERVER;
3049 VlEntry->serverNumber[i] = serverindex;
3050 VlEntry->serverPartition[i] = VldbEntry->serverPartition[i];
3051 VlEntry->serverFlags[i] = VldbEntry->serverFlags[i];
3053 for (; i < NMAXNSERVERS; i++)
3054 VlEntry->serverNumber[i] = VlEntry->serverPartition[i] =
3055 VlEntry->serverFlags[i] = BADSERVERID;
3056 for (i = 0; i < MAXTYPES; i++)
3057 VlEntry->volumeId[i] = VldbEntry->volumeId[i];
3058 VlEntry->cloneId = VldbEntry->cloneId;
3059 VlEntry->flags = VldbEntry->flags;
3064 /* Update the vldb entry with the new fields as indicated by the value of
3065 * the Mask entry in the updateentry structure. All necessary validation
3066 * checks are performed.
3069 get_vldbupdateentry(struct vl_ctx *ctx,
3070 afs_int32 blockindex,
3071 struct VldbUpdateEntry *updateentry,
3072 struct nvlentry *VlEntry)
3074 int i, j, code, serverindex;
3075 afs_uint32 checkids[MAXTYPES];
3077 /* check if any specified new IDs are already present in the db. Do
3078 * this check before doing anything else, so we don't get a half-
3080 memset(&checkids, 0, sizeof(checkids));
3081 if (updateentry->Mask & VLUPDATE_RWID) {
3082 checkids[RWVOL] = updateentry->spares3; /* rw id */
3084 if (updateentry->Mask & VLUPDATE_READONLYID) {
3085 checkids[ROVOL] = updateentry->ReadOnlyId;
3087 if (updateentry->Mask & VLUPDATE_BACKUPID) {
3088 checkids[BACKVOL] = updateentry->BackupId;
3091 if (EntryIDExists(ctx, checkids, MAXTYPES, &code)) {
3097 if (updateentry->Mask & VLUPDATE_VOLUMENAME) {
3098 struct nvlentry tentry;
3100 if (InvalidVolname(updateentry->name))
3103 if (FindByName(ctx, updateentry->name, &tentry, &code)) {
3104 return VL_NAMEEXIST;
3109 if ((code = UnhashVolname(ctx, blockindex, VlEntry)))
3111 strncpy(VlEntry->name, updateentry->name, sizeof(VlEntry->name));
3112 HashVolname(ctx, blockindex, VlEntry);
3115 if (updateentry->Mask & VLUPDATE_VOLNAMEHASH) {
3116 if ((code = UnhashVolname(ctx, blockindex, VlEntry))) {
3117 if (code != VL_NOENT)
3120 HashVolname(ctx, blockindex, VlEntry);
3123 if (updateentry->Mask & VLUPDATE_FLAGS) {
3124 VlEntry->flags = updateentry->flags;
3126 if (updateentry->Mask & VLUPDATE_CLONEID) {
3127 VlEntry->cloneId = updateentry->cloneId;
3129 if (updateentry->Mask & VLUPDATE_RWID) {
3130 if ((code = UnhashVolid(ctx, RWVOL, blockindex, VlEntry))) {
3131 if (code != VL_NOENT)
3134 VlEntry->volumeId[RWVOL] = updateentry->spares3; /* rw id */
3135 if ((code = HashVolid(ctx, RWVOL, blockindex, VlEntry)))
3138 if (updateentry->Mask & VLUPDATE_READONLYID) {
3139 if ((code = UnhashVolid(ctx, ROVOL, blockindex, VlEntry))) {
3140 if (code != VL_NOENT)
3143 VlEntry->volumeId[ROVOL] = updateentry->ReadOnlyId;
3144 if ((code = HashVolid(ctx, ROVOL, blockindex, VlEntry)))
3147 if (updateentry->Mask & VLUPDATE_BACKUPID) {
3148 if ((code = UnhashVolid(ctx, BACKVOL, blockindex, VlEntry))) {
3149 if (code != VL_NOENT)
3152 VlEntry->volumeId[BACKVOL] = updateentry->BackupId;
3153 if ((code = HashVolid(ctx, BACKVOL, blockindex, VlEntry)))
3156 if (updateentry->Mask & VLUPDATE_REPSITES) {
3157 if (updateentry->nModifiedRepsites <= 0
3158 || updateentry->nModifiedRepsites > OMAXNSERVERS)
3159 return VL_BADSERVER;
3160 for (i = 0; i < updateentry->nModifiedRepsites; i++) {
3161 /* if (updateentry->RepsitesTargetServer[i] < 0 || updateentry->RepsitesTargetServer[i] > MAXSERVERID)
3162 return VL_BADSERVER; */
3163 if (updateentry->RepsitesTargetPart[i] < 0
3164 || updateentry->RepsitesTargetPart[i] > MAXPARTITIONID)
3165 return VL_BADPARTITION;
3166 if (updateentry->RepsitesMask[i] & VLUPDATE_REPS_DELETE) {
3168 repsite_exists(VlEntry,
3169 IpAddrToRelAddr(ctx, updateentry->
3170 RepsitesTargetServer[i],
3172 updateentry->RepsitesTargetPart[i])) !=
3174 repsite_compress(VlEntry, j);
3176 return VL_NOREPSERVER;
3178 if (updateentry->RepsitesMask[i] & VLUPDATE_REPS_ADD) {
3179 /* if (updateentry->RepsitesNewServer[i] < 0 || updateentry->RepsitesNewServer[i] > MAXSERVERID)
3180 return VL_BADSERVER; */
3181 if (updateentry->RepsitesNewPart[i] < 0
3182 || updateentry->RepsitesNewPart[i] > MAXPARTITIONID)
3183 return VL_BADPARTITION;
3186 IpAddrToRelAddr(ctx, updateentry->RepsitesNewServer[i], 1),
3187 updateentry->RepsitesNewPart[i]) != -1)
3188 return VL_DUPREPSERVER;
3190 VlEntry->serverNumber[j] != BADSERVERID
3191 && j < OMAXNSERVERS; j++);
3192 if (j >= OMAXNSERVERS)
3195 IpAddrToRelAddr(ctx, updateentry->RepsitesNewServer[i],
3197 return VL_BADSERVER;
3198 VlEntry->serverNumber[j] = serverindex;
3199 VlEntry->serverPartition[j] = updateentry->RepsitesNewPart[i];
3200 if (updateentry->RepsitesNewFlags[i] < 0
3201 || updateentry->RepsitesNewFlags[i] > MAXSERVERFLAG)
3202 return VL_BADSERVERFLAG;
3203 VlEntry->serverFlags[j] = updateentry->RepsitesNewFlags[i];
3205 if (updateentry->RepsitesMask[i] & VLUPDATE_REPS_MODSERV) {
3206 /*n if (updateentry->RepsitesNewServer[i] < 0 || updateentry->RepsitesNewServer[i] > MAXSERVERID)
3207 return VL_BADSERVER; */
3209 repsite_exists(VlEntry,
3210 IpAddrToRelAddr(ctx, updateentry->
3211 RepsitesTargetServer[i],
3213 updateentry->RepsitesTargetPart[i])) !=
3215 VlEntry->serverNumber[j] =
3216 IpAddrToRelAddr(ctx, updateentry->RepsitesNewServer[i],
3219 return VL_NOREPSERVER;
3221 if (updateentry->RepsitesMask[i] & VLUPDATE_REPS_MODPART) {
3222 if (updateentry->RepsitesNewPart[i] < 0
3223 || updateentry->RepsitesNewPart[i] > MAXPARTITIONID)
3224 return VL_BADPARTITION;
3226 repsite_exists(VlEntry,
3227 IpAddrToRelAddr(ctx, updateentry->
3228 RepsitesTargetServer[i],
3230 updateentry->RepsitesTargetPart[i])) !=
3232 VlEntry->serverPartition[j] =
3233 updateentry->RepsitesNewPart[i];
3235 return VL_NOREPSERVER;
3237 if (updateentry->RepsitesMask[i] & VLUPDATE_REPS_MODFLAG) {
3239 repsite_exists(VlEntry,
3240 IpAddrToRelAddr(ctx, updateentry->
3241 RepsitesTargetServer[i],
3243 updateentry->RepsitesTargetPart[i])) !=
3245 if (updateentry->RepsitesNewFlags[i] < 0
3246 || updateentry->RepsitesNewFlags[i] > MAXSERVERFLAG)
3247 return VL_BADSERVERFLAG;
3248 VlEntry->serverFlags[j] =
3249 updateentry->RepsitesNewFlags[i];
3251 return VL_NOREPSERVER;
3259 /* Check if the specified [server,partition] entry is found in the vldb
3260 * entry's repsite table; it's offset in the table is returned, if it's
3263 repsite_exists(struct nvlentry *VlEntry, int server, int partition)
3267 for (i = 0; VlEntry->serverNumber[i] != BADSERVERID && i < OMAXNSERVERS;
3269 if ((VlEntry->serverNumber[i] == server)
3270 && (VlEntry->serverPartition[i] == partition))
3278 /* Repsite table compression: used when deleting a repsite entry so that
3279 * all active repsite entries are on the top of the table. */
3281 repsite_compress(struct nvlentry *VlEntry, int offset)
3283 int repsite_offset = offset;
3285 VlEntry->serverNumber[repsite_offset] != BADSERVERID
3286 && repsite_offset < OMAXNSERVERS - 1; repsite_offset++) {
3287 VlEntry->serverNumber[repsite_offset] =
3288 VlEntry->serverNumber[repsite_offset + 1];
3289 VlEntry->serverPartition[repsite_offset] =
3290 VlEntry->serverPartition[repsite_offset + 1];
3291 VlEntry->serverFlags[repsite_offset] =
3292 VlEntry->serverFlags[repsite_offset + 1];
3294 VlEntry->serverNumber[repsite_offset] = BADSERVERID;
3298 /* Convert from the internal (compacted) vldb entry to the external
3299 * representation used by the interface. */
3301 vlentry_to_vldbentry(struct vl_ctx *ctx, struct nvlentry *VlEntry,
3302 struct vldbentry *VldbEntry)
3305 struct extentaddr *exp;
3307 memset(VldbEntry, 0, sizeof(struct vldbentry));
3308 strncpy(VldbEntry->name, VlEntry->name, sizeof(VldbEntry->name));
3309 for (i = 0; i < OMAXNSERVERS; i++) {
3310 if (VlEntry->serverNumber[i] == BADSERVERID)
3312 code = multiHomedExtent(ctx, VlEntry->serverNumber[i], &exp);
3316 /* For now return the first ip address back */
3317 for (j = 0; j < VL_MAXIPADDRS_PERMH; j++) {
3318 if (exp->ex_addrs[j]) {
3319 VldbEntry->serverNumber[i] = ntohl(exp->ex_addrs[j]);
3324 VldbEntry->serverNumber[i] =
3325 ctx->hostaddress[VlEntry->serverNumber[i]];
3326 VldbEntry->serverPartition[i] = VlEntry->serverPartition[i];
3327 VldbEntry->serverFlags[i] = VlEntry->serverFlags[i];
3329 VldbEntry->nServers = i;
3330 for (i = 0; i < MAXTYPES; i++)
3331 VldbEntry->volumeId[i] = VlEntry->volumeId[i];
3332 VldbEntry->cloneId = VlEntry->cloneId;
3333 VldbEntry->flags = VlEntry->flags;
3339 /* Convert from the internal (compacted) vldb entry to the external
3340 * representation used by the interface. */
3342 vlentry_to_nvldbentry(struct vl_ctx *ctx, struct nvlentry *VlEntry,
3343 struct nvldbentry *VldbEntry)
3346 struct extentaddr *exp;
3348 memset(VldbEntry, 0, sizeof(struct nvldbentry));
3349 strncpy(VldbEntry->name, VlEntry->name, sizeof(VldbEntry->name));
3350 for (i = 0; i < NMAXNSERVERS; i++) {
3351 if (VlEntry->serverNumber[i] == BADSERVERID)
3353 code = multiHomedExtent(ctx, VlEntry->serverNumber[i], &exp);
3358 /* For now return the first ip address back */
3359 for (j = 0; j < VL_MAXIPADDRS_PERMH; j++) {
3360 if (exp->ex_addrs[j]) {
3361 VldbEntry->serverNumber[i] = ntohl(exp->ex_addrs[j]);
3366 VldbEntry->serverNumber[i] =
3367 ctx->hostaddress[VlEntry->serverNumber[i]];
3368 VldbEntry->serverPartition[i] = VlEntry->serverPartition[i];
3369 VldbEntry->serverFlags[i] = VlEntry->serverFlags[i];
3371 VldbEntry->nServers = i;
3372 for (i = 0; i < MAXTYPES; i++)
3373 VldbEntry->volumeId[i] = VlEntry->volumeId[i];
3374 VldbEntry->cloneId = VlEntry->cloneId;
3375 VldbEntry->flags = VlEntry->flags;
3381 vlentry_to_uvldbentry(struct vl_ctx *ctx, struct nvlentry *VlEntry,
3382 struct uvldbentry *VldbEntry)
3385 struct extentaddr *exp;
3387 memset(VldbEntry, 0, sizeof(struct uvldbentry));
3388 strncpy(VldbEntry->name, VlEntry->name, sizeof(VldbEntry->name));
3389 for (i = 0; i < NMAXNSERVERS; i++) {
3390 if (VlEntry->serverNumber[i] == BADSERVERID)
3392 VldbEntry->serverFlags[i] = VlEntry->serverFlags[i];
3393 VldbEntry->serverUnique[i] = 0;
3394 code = multiHomedExtent(ctx, VlEntry->serverNumber[i], &exp);
3401 tuuid = exp->ex_hostuuid;
3402 afs_ntohuuid(&tuuid);
3403 VldbEntry->serverFlags[i] |= VLSF_UUID;
3404 VldbEntry->serverNumber[i] = tuuid;
3405 VldbEntry->serverUnique[i] = ntohl(exp->ex_uniquifier);
3407 VldbEntry->serverNumber[i].time_low =
3408 ctx->hostaddress[VlEntry->serverNumber[i]];
3410 VldbEntry->serverPartition[i] = VlEntry->serverPartition[i];
3413 VldbEntry->nServers = i;
3414 for (i = 0; i < MAXTYPES; i++)
3415 VldbEntry->volumeId[i] = VlEntry->volumeId[i];
3416 VldbEntry->cloneId = VlEntry->cloneId;
3417 VldbEntry->flags = VlEntry->flags;
3422 #define LEGALCHARS ".ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"
3425 /* Verify that the volname is a valid volume name. */
3427 InvalidVolname(char *volname)
3433 slen = strlen(volname);
3434 if (slen >= VL_MAXNAMELEN)
3436 return (slen != strspn(volname, map));
3440 /* Verify that the given volume type is valid. */
3442 InvalidVoltype(afs_int32 voltype)
3444 if (voltype != RWVOL && voltype != ROVOL && voltype != BACKVOL)
3451 InvalidOperation(afs_int32 voloper)
3453 if (voloper != VLOP_MOVE && voloper != VLOP_RELEASE
3454 && voloper != VLOP_BACKUP && voloper != VLOP_DELETE
3455 && voloper != VLOP_DUMP)
3461 InvalidReleasetype(afs_int32 releasetype)
3463 if ((releasetype & LOCKREL_TIMESTAMP) || (releasetype & LOCKREL_OPCODE)
3464 || (releasetype & LOCKREL_AFSID))
3470 IpAddrToRelAddr(struct vl_ctx *ctx, afs_uint32 ipaddr, int create)
3474 struct extentaddr *exp;
3476 for (i = 0; i <= MAXSERVERID; i++) {
3477 if (ctx->hostaddress[i] == ipaddr)
3479 code = multiHomedExtent(ctx, i, &exp);
3483 for (j = 0; j < VL_MAXIPADDRS_PERMH; j++) {
3484 if (exp->ex_addrs[j] && (ntohl(exp->ex_addrs[j]) == ipaddr)) {
3491 /* allocate the new server a server id pronto */
3493 for (i = 0; i <= MAXSERVERID; i++) {
3494 if (ctx->cheader->IpMappedAddr[i] == 0) {
3495 ctx->cheader->IpMappedAddr[i] = htonl(ipaddr);
3498 DOFFSET(0, ctx->cheader, &ctx->cheader->IpMappedAddr[i]),
3499 (char *)&ctx->cheader->IpMappedAddr[i],
3501 ctx->hostaddress[i] = ipaddr;
3512 ChangeIPAddr(struct vl_ctx *ctx, afs_uint32 ipaddr1, afs_uint32 ipaddr2)
3516 struct extentaddr *exp = NULL;
3520 afs_int32 blockindex, count;
3522 struct nvlentry tentry;
3523 int ipaddr1_id = -1, ipaddr2_id = -1;
3527 /* Don't let addr change to 255.*.*.* : Causes internal error below */
3528 if ((ipaddr2 & 0xff000000) == 0xff000000)
3529 return (VL_BADSERVER);
3531 /* If we are removing an address, ip1 will be -1 and ip2 will be
3532 * the original address. This prevents an older revision vlserver
3533 * from removing the IP address (won't find server 0xfffffff in
3534 * the VLDB). An older revision vlserver does not have the check
3535 * to see if any volumes exist on the server being removed.
3537 if (ipaddr1 == 0xffffffff) {
3542 for (i = 0; i <= MAXSERVERID; i++) {
3543 struct extentaddr *texp = NULL;
3546 code = multiHomedExtentBase(ctx, i, &texp, &tbase);
3551 for (mhidx = 0; mhidx < VL_MAXIPADDRS_PERMH; mhidx++) {
3552 if (!texp->ex_addrs[mhidx])
3554 if (ntohl(texp->ex_addrs[mhidx]) == ipaddr1) {
3559 if (ipaddr2 != 0 && ntohl(texp->ex_addrs[mhidx]) == ipaddr2) {
3564 if (ctx->hostaddress[i] == ipaddr1) {
3569 if (ipaddr2 != 0 && ctx->hostaddress[i] == ipaddr2) {
3574 if (ipaddr1_id >= 0 && (ipaddr2 == 0 || ipaddr2_id >= 0)) {
3575 /* we've either found both IPs already in the VLDB, or we found
3576 * ipaddr1, and we're not going to find ipaddr2 because it's 0 */
3581 if (ipaddr1_id < 0) {
3582 return VL_NOENT; /* not found */
3585 if (ipaddr2_id >= 0 && ipaddr2_id != ipaddr1_id) {
3586 char buf1[16], buf2[16];
3587 VLog(0, ("Cannot change IP address from %s to %s because the latter "
3588 "is in use by server id %d\n",
3589 afs_inet_ntoa_r(htonl(ipaddr1), buf1),
3590 afs_inet_ntoa_r(htonl(ipaddr2), buf2),
3592 return VL_MULTIPADDR;
3595 /* If we are removing a server entry, a volume cannot
3596 * exist on the server. If one does, don't remove the
3597 * server entry: return error "volume entry exists".
3600 for (blockindex = NextEntry(ctx, 0, &tentry, &count); blockindex;
3601 blockindex = NextEntry(ctx, blockindex, &tentry, &count)) {
3602 if (++pollcount > 50) {
3603 #ifndef AFS_PTHREAD_ENV
3608 for (j = 0; j < NMAXNSERVERS; j++) {
3609 if (tentry.serverNumber[j] == BADSERVERID)
3611 if (tentry.serverNumber[j] == ipaddr1_id) {
3617 /* Do not allow changing addresses in multi-homed entries.
3618 Older versions of this RPC would silently "downgrade" mh entries
3619 to single-homed entries and orphan the mh enties. */
3621 append_addr(addrbuf1, ipaddr1, sizeof(addrbuf1));
3622 VLog(0, ("Refusing to change address %s in multi-homed entry; "
3623 "use RegisterAddrs instead.\n", addrbuf1));
3624 return VL_NOENT; /* single-homed entry not found */
3627 /* Log a message saying we are changing/removing an IP address */
3629 ("The following IP address is being %s:\n",
3630 (ipaddr2 ? "changed" : "removed")));
3631 addrbuf1[0] = addrbuf2[0] = '\0';
3633 for (mhidx = 0; mhidx < VL_MAXIPADDRS_PERMH; mhidx++) {
3634 if (!exp->ex_addrs[mhidx])
3637 strlcat(addrbuf1, " ", sizeof(addrbuf1));
3638 append_addr(addrbuf1, ntohl(exp->ex_addrs[mhidx]), sizeof(addrbuf1));
3641 append_addr(addrbuf1, ipaddr1, sizeof(addrbuf1));
3644 append_addr(addrbuf2, ipaddr2, sizeof(addrbuf2));
3646 VLog(0, (" entry %d: [%s] -> [%s]\n", ipaddr1_id, addrbuf1, addrbuf2));
3648 /* Change the registered uuuid addresses */
3649 if (exp && base != -1) {
3650 memset(&tuuid, 0, sizeof(afsUUID));
3651 afs_htonuuid(&tuuid);
3652 exp->ex_hostuuid = tuuid;
3655 DOFFSET(ntohl(ctx->ex_addr[0]->ex_contaddrs[base]),
3656 (char *)ctx->ex_addr[base], (char *)exp),
3657 (char *)&tuuid, sizeof(tuuid));
3662 /* Now change the host address entry */
3663 ctx->cheader->IpMappedAddr[ipaddr1_id] = htonl(ipaddr2);
3665 vlwrite(ctx->trans, DOFFSET(0, ctx->cheader, &ctx->cheader->IpMappedAddr[ipaddr1_id]),
3667 &ctx->cheader->IpMappedAddr[ipaddr1_id], sizeof(afs_int32));
3668 ctx->hostaddress[ipaddr1_id] = ipaddr2;
3675 /* see if the vlserver is back yet */
3677 SVL_ProbeServer(struct rx_call *rxcall)