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);
628 countRequest(this_op);
630 if (InvalidVolname(volname))
632 if ((code = Init_VLdbase(&ctx, LOCKREAD, this_op)))
634 VLog(5, ("GetVolumeByName %s (%d) %s\n", volname, new, rxinfo(rxstr, rxcall)));
635 blockindex = FindByName(&ctx, volname, &tentry, &code);
636 if (blockindex == 0) { /* entry not found */
641 if (tentry.flags & VLDELETED) { /* Entry is deleted */
642 code = VL_ENTDELETED;
645 /* Convert to external entry representation */
647 code = vlentry_to_nvldbentry(&ctx, &tentry, (struct nvldbentry *)aentry);
649 code = vlentry_to_uvldbentry(&ctx, &tentry, (struct uvldbentry *)aentry);
651 code = vlentry_to_vldbentry(&ctx, &tentry, (struct vldbentry *)aentry);
656 return (ubik_EndTrans(ctx.trans));
660 ubik_AbortTrans(ctx.trans);
666 SVL_GetEntryByNameO(struct rx_call *rxcall,
668 struct vldbentry *aentry) /* entry data copied here */
670 return (GetEntryByName(rxcall, volname, (char *)aentry, 0,
675 SVL_GetEntryByNameN(struct rx_call *rxcall,
677 struct nvldbentry *aentry) /* entry data copied here */
679 return (GetEntryByName(rxcall, volname, (char *)aentry, 1,
684 SVL_GetEntryByNameU(struct rx_call *rxcall,
686 struct uvldbentry *aentry) /* entry data copied here */
688 return (GetEntryByName(rxcall, volname, (char *)aentry, 2,
692 /* Get the current value of the maximum volume id and bump the volume id counter by Maxvolidbump. */
694 getNewVolumeId(struct rx_call *rxcall, afs_uint32 Maxvolidbump,
695 afs_uint32 *newvolumeid)
697 int this_op = VLGETNEWVOLUMEID;
699 afs_uint32 maxvolumeid;
701 char rxstr[AFS_RXINFO_LEN];
703 countRequest(this_op);
704 if (!afsconf_SuperUser(vldb_confdir, rxcall, NULL))
707 if (Maxvolidbump > MAXBUMPCOUNT)
708 return VL_BADVOLIDBUMP;
710 if ((code = Init_VLdbase(&ctx, LOCKWRITE, this_op)))
713 *newvolumeid = maxvolumeid = NextUnusedID(&ctx,
714 ntohl(ctx.cheader->vital_header.MaxVolumeId), Maxvolidbump, &code);
719 maxvolumeid += Maxvolidbump;
720 VLog(1, ("GetNewVolid newmax=%u %s\n", maxvolumeid, rxinfo(rxstr, rxcall)));
721 ctx.cheader->vital_header.MaxVolumeId = htonl(maxvolumeid);
722 if (write_vital_vlheader(&ctx)) {
725 return ubik_EndTrans(ctx.trans);
729 ubik_AbortTrans(ctx.trans);
734 SVL_GetNewVolumeId(struct rx_call *rxcall, afs_uint32 Maxvolidbump,
735 afs_uint32 *newvolumeid)
739 code = getNewVolumeId(rxcall, Maxvolidbump, newvolumeid);
740 osi_auditU(rxcall, VLGetNewVolumeIdEvent, code, AUD_END);
745 /* Simple replace the contents of the vldb entry, volid, with
746 * newentry. No individual checking/updating per field (alike
747 * VLUpdateEntry) is done. */
750 ReplaceEntry(struct rx_call *rxcall, afs_uint32 volid, afs_int32 voltype,
751 struct vldbentry *newentry, afs_int32 releasetype)
753 int this_op = VLREPLACEENTRY;
755 afs_int32 blockindex, code, typeindex;
757 int hashVol[MAXTYPES];
758 struct nvlentry tentry;
759 afs_uint32 checkids[MAXTYPES];
760 char rxstr[AFS_RXINFO_LEN];
762 countRequest(this_op);
763 for (typeindex = 0; typeindex < MAXTYPES; typeindex++)
764 hashVol[typeindex] = 0;
766 if (!afsconf_SuperUser(vldb_confdir, rxcall, NULL))
769 if ((code = check_vldbentry(newentry)))
772 if (voltype != -1 && InvalidVoltype(voltype))
773 return VL_BADVOLTYPE;
775 if (releasetype && InvalidReleasetype(releasetype))
776 return VL_BADRELLOCKTYPE;
777 if ((code = Init_VLdbase(&ctx, LOCKWRITE, this_op)))
780 VLog(1, ("OReplace Volume %u %s\n", volid, rxinfo(rxstr, rxcall)));
781 /* find vlentry we're changing */
782 blockindex = FindByID(&ctx, volid, voltype, &tentry, &code);
783 if (blockindex == 0) { /* entry not found */
789 /* check that we're not trying to change the RW vol ID */
790 if (newentry->volumeId[RWVOL] != tentry.volumeId[RWVOL]) {
794 /* make sure none of the IDs we are changing to are already in use */
795 memset(&checkids, 0, sizeof(checkids));
796 for (typeindex = ROVOL; typeindex < MAXTYPES; typeindex++) {
797 if (tentry.volumeId[typeindex] != newentry->volumeId[typeindex]) {
798 checkids[typeindex] = newentry->volumeId[typeindex];
801 if (EntryIDExists(&ctx, checkids, MAXTYPES, &code)) {
807 /* make sure the name we're changing to doesn't already exist */
808 if (strcmp(newentry->name, tentry.name)) {
809 struct nvlentry tmp_entry;
810 if (FindByName(&ctx, newentry->name, &tmp_entry, &code)) {
817 /* unhash volid entries if they're disappearing or changing.
818 * Remember if we need to hash in the new value (we don't have to
819 * rehash if volid stays same */
820 for (typeindex = ROVOL; typeindex <= BACKVOL; typeindex++) {
821 if (tentry.volumeId[typeindex] != newentry->volumeId[typeindex]) {
822 if (tentry.volumeId[typeindex])
824 UnhashVolid(&ctx, typeindex, blockindex, &tentry))) {
827 /* we must rehash new id if the id is different and the ID is nonzero */
828 hashVol[typeindex] = 1; /* must rehash this guy if he exists */
832 /* Rehash volname if it changes */
833 if (strcmp(newentry->name, tentry.name)) { /* Name changes; redo hashing */
834 if ((code = UnhashVolname(&ctx, blockindex, &tentry))) {
840 /* after this, tentry is new entry, not old one. vldbentry_to_vlentry
841 * doesn't touch hash chains */
842 if ((code = vldbentry_to_vlentry(&ctx, newentry, &tentry))) {
846 for (typeindex = ROVOL; typeindex <= BACKVOL; typeindex++) {
847 if (hashVol[typeindex] && tentry.volumeId[typeindex]) {
848 if ((code = HashVolid(&ctx, typeindex, blockindex, &tentry))) {
855 HashVolname(&ctx, blockindex, &tentry);
858 ReleaseEntry(&tentry, releasetype); /* Unlock entry if necessary */
859 if (vlentrywrite(ctx.trans, blockindex, &tentry, sizeof(tentry))) {
863 return ubik_EndTrans(ctx.trans);
867 ubik_AbortTrans(ctx.trans);
872 SVL_ReplaceEntry(struct rx_call *rxcall, afs_uint32 volid, afs_int32 voltype,
873 struct vldbentry *newentry, afs_int32 releasetype)
877 code = ReplaceEntry(rxcall, volid, voltype, newentry, releasetype);
878 osi_auditU(rxcall, VLReplaceVLEntryEvent, code, AUD_LONG, volid, AUD_END);
883 ReplaceEntryN(struct rx_call *rxcall, afs_uint32 volid, afs_int32 voltype,
884 struct nvldbentry *newentry, afs_int32 releasetype)
886 int this_op = VLREPLACEENTRYN;
888 afs_int32 blockindex, code, typeindex;
890 int hashVol[MAXTYPES];
891 struct nvlentry tentry;
892 char rxstr[AFS_RXINFO_LEN];
894 countRequest(this_op);
895 for (typeindex = 0; typeindex < MAXTYPES; typeindex++)
896 hashVol[typeindex] = 0;
898 if (!afsconf_SuperUser(vldb_confdir, rxcall, NULL))
901 if ((code = check_nvldbentry(newentry)))
904 if (voltype != -1 && InvalidVoltype(voltype))
905 return VL_BADVOLTYPE;
907 if (releasetype && InvalidReleasetype(releasetype))
908 return VL_BADRELLOCKTYPE;
909 if ((code = Init_VLdbase(&ctx, LOCKWRITE, this_op)))
912 VLog(1, ("Replace Volume %u %s\n", volid, rxinfo(rxstr, rxcall)));
913 /* find vlentry we're changing */
914 blockindex = FindByID(&ctx, volid, voltype, &tentry, &code);
915 if (blockindex == 0) { /* entry not found */
921 /* check that we're not trying to change the RW vol ID */
922 if (newentry->volumeId[RWVOL] != tentry.volumeId[RWVOL]) {
926 /* unhash volid entries if they're disappearing or changing.
927 * Remember if we need to hash in the new value (we don't have to
928 * rehash if volid stays same */
929 for (typeindex = ROVOL; typeindex <= BACKVOL; typeindex++) {
930 if (tentry.volumeId[typeindex] != newentry->volumeId[typeindex]) {
931 if (tentry.volumeId[typeindex])
933 UnhashVolid(&ctx, typeindex, blockindex, &tentry))) {
936 /* we must rehash new id if the id is different and the ID is nonzero */
937 hashVol[typeindex] = 1; /* must rehash this guy if he exists */
941 /* Rehash volname if it changes */
942 if (strcmp(newentry->name, tentry.name)) { /* Name changes; redo hashing */
943 if ((code = UnhashVolname(&ctx, blockindex, &tentry))) {
949 /* after this, tentry is new entry, not old one. vldbentry_to_vlentry
950 * doesn't touch hash chains */
951 if ((code = nvldbentry_to_vlentry(&ctx, newentry, &tentry))) {
955 for (typeindex = ROVOL; typeindex <= BACKVOL; typeindex++) {
956 if (hashVol[typeindex] && tentry.volumeId[typeindex]) {
957 if ((code = HashVolid(&ctx, typeindex, blockindex, &tentry))) {
964 HashVolname(&ctx, blockindex, &tentry);
967 ReleaseEntry(&tentry, releasetype); /* Unlock entry if necessary */
968 if (vlentrywrite(ctx.trans, blockindex, &tentry, sizeof(tentry))) {
972 return ubik_EndTrans(ctx.trans);
976 ubik_AbortTrans(ctx.trans);
981 SVL_ReplaceEntryN(struct rx_call *rxcall, afs_uint32 volid, afs_int32 voltype,
982 struct nvldbentry *newentry, afs_int32 releasetype)
986 code = ReplaceEntryN(rxcall, volid, voltype, newentry, releasetype);
987 osi_auditU(rxcall, VLReplaceVLEntryEvent, code, AUD_LONG, volid, AUD_END);
992 /* Update a vldb entry (accessed thru its volume id). Almost all of the
993 * entry's fields can be modified in a single call by setting the
994 * appropriate bits in the Mask field in VldbUpdateentry. */
995 /* this routine may never have been tested; use replace entry instead
996 * unless you're brave */
998 UpdateEntry(struct rx_call *rxcall,
1001 struct VldbUpdateEntry *updateentry, /* Update entry copied here */
1002 afs_int32 releasetype)
1004 int this_op = VLUPDATEENTRY;
1006 afs_int32 blockindex, code;
1007 struct nvlentry tentry;
1008 char rxstr[AFS_RXINFO_LEN];
1010 countRequest(this_op);
1011 if (!afsconf_SuperUser(vldb_confdir, rxcall, NULL))
1013 if ((voltype != -1) && (InvalidVoltype(voltype)))
1014 return VL_BADVOLTYPE;
1015 if (releasetype && InvalidReleasetype(releasetype))
1016 return VL_BADRELLOCKTYPE;
1017 if ((code = Init_VLdbase(&ctx, LOCKWRITE, this_op)))
1020 VLog(1, ("Update Volume %u %s\n", volid, rxinfo(rxstr, rxcall)));
1021 blockindex = FindByID(&ctx, volid, voltype, &tentry, &code);
1022 if (blockindex == 0) { /* entry not found */
1028 /* Do the actual updating of the entry, tentry. */
1030 get_vldbupdateentry(&ctx, blockindex, updateentry, &tentry))) {
1034 ReleaseEntry(&tentry, releasetype); /* Unlock entry if necessary */
1035 if (vlentrywrite(ctx.trans, blockindex, &tentry, sizeof(tentry))) {
1038 return ubik_EndTrans(ctx.trans);
1041 countAbort(this_op);
1042 ubik_AbortTrans(ctx.trans);
1047 SVL_UpdateEntry(struct rx_call *rxcall,
1050 struct VldbUpdateEntry *updateentry,
1051 afs_int32 releasetype)
1055 code = UpdateEntry(rxcall, volid, voltype, updateentry, releasetype);
1056 osi_auditU(rxcall, VLUpdateEntryEvent, code, AUD_LONG, volid, AUD_END);
1061 UpdateEntryByName(struct rx_call *rxcall,
1063 struct VldbUpdateEntry *updateentry, /* Update entry copied here */
1064 afs_int32 releasetype)
1066 int this_op = VLUPDATEENTRYBYNAME;
1068 afs_int32 blockindex, code;
1069 struct nvlentry tentry;
1071 countRequest(this_op);
1072 if (!afsconf_SuperUser(vldb_confdir, rxcall, NULL))
1074 if (releasetype && InvalidReleasetype(releasetype))
1075 return VL_BADRELLOCKTYPE;
1076 if ((code = Init_VLdbase(&ctx, LOCKWRITE, this_op)))
1079 blockindex = FindByName(&ctx, volname, &tentry, &code);
1080 if (blockindex == 0) { /* entry not found */
1086 /* Do the actual updating of the entry, tentry. */
1088 get_vldbupdateentry(&ctx, blockindex, updateentry, &tentry))) {
1092 ReleaseEntry(&tentry, releasetype); /* Unlock entry if necessary */
1093 if (vlentrywrite(ctx.trans, blockindex, &tentry, sizeof(tentry))) {
1096 return ubik_EndTrans(ctx.trans);
1099 countAbort(this_op);
1100 ubik_AbortTrans(ctx.trans);
1105 SVL_UpdateEntryByName(struct rx_call *rxcall,
1107 struct VldbUpdateEntry *updateentry, /* Update entry copied here */
1108 afs_int32 releasetype)
1112 code = UpdateEntryByName(rxcall, volname, updateentry, releasetype);
1113 osi_auditU(rxcall, VLUpdateEntryEvent, code, AUD_LONG, -1, AUD_END);
1117 /* Set a lock to the vldb entry for volid (of type voltype if not -1). */
1119 SetLock(struct rx_call *rxcall, afs_uint32 volid, afs_int32 voltype,
1122 int this_op = VLSETLOCK;
1123 afs_int32 timestamp, blockindex, code;
1125 struct nvlentry tentry;
1126 char rxstr[AFS_RXINFO_LEN];
1128 countRequest(this_op);
1129 if (!afsconf_SuperUser(vldb_confdir, rxcall, NULL))
1131 if ((voltype != -1) && (InvalidVoltype(voltype)))
1132 return VL_BADVOLTYPE;
1133 if (InvalidOperation(voloper))
1134 return VL_BADVOLOPER;
1135 if ((code = Init_VLdbase(&ctx, LOCKWRITE, this_op)))
1138 VLog(1, ("SetLock Volume %u %s\n", volid, rxinfo(rxstr, rxcall)));
1139 blockindex = FindByID(&ctx, volid, voltype, &tentry, &code);
1140 if (blockindex == NULLO) {
1145 if (tentry.flags & VLDELETED) {
1146 ABORT(VL_ENTDELETED);
1148 timestamp = FT_ApproxTime();
1150 /* Check if entry is already locked; note that we unlock any entry
1151 * locked more than MAXLOCKTIME seconds */
1152 if ((tentry.LockTimestamp)
1153 && ((timestamp - tentry.LockTimestamp) < MAXLOCKTIME)) {
1154 ABORT(VL_ENTRYLOCKED);
1157 /* Consider it an unlocked entry: set current timestamp, caller
1158 * and active vol operation */
1159 tentry.LockTimestamp = timestamp;
1160 tentry.LockAfsId = 0; /* Not implemented yet */
1161 if (tentry.flags & VLOP_RELEASE) {
1162 ABORT(VL_RERELEASE);
1164 tentry.flags &= ~VLOP_ALLOPERS; /* Clear any possible older operation bit */
1165 tentry.flags |= voloper;
1167 if (vlentrywrite(ctx.trans, blockindex, &tentry, sizeof(tentry))) {
1170 return ubik_EndTrans(ctx.trans);
1173 countAbort(this_op);
1174 ubik_AbortTrans(ctx.trans);
1179 SVL_SetLock(struct rx_call *rxcall, afs_uint32 volid, afs_int32 voltype,
1184 code = SetLock(rxcall, volid, voltype, voloper);
1185 osi_auditU(rxcall, VLSetLockEvent, code, AUD_LONG, volid, AUD_END);
1189 /* Release an already locked vldb entry. Releasetype determines what
1190 * fields (afsid and/or volume operation) will be cleared along with
1191 * the lock time stamp. */
1194 ReleaseLock(struct rx_call *rxcall, afs_uint32 volid, afs_int32 voltype,
1195 afs_int32 releasetype)
1197 int this_op = VLRELEASELOCK;
1198 afs_int32 blockindex, code;
1200 struct nvlentry tentry;
1201 char rxstr[AFS_RXINFO_LEN];
1203 countRequest(this_op);
1204 if (!afsconf_SuperUser(vldb_confdir, rxcall, NULL))
1206 if ((voltype != -1) && (InvalidVoltype(voltype)))
1207 return VL_BADVOLTYPE;
1208 if (releasetype && InvalidReleasetype(releasetype))
1209 return VL_BADRELLOCKTYPE;
1210 if ((code = Init_VLdbase(&ctx, LOCKWRITE, this_op)))
1213 VLog(1, ("ReleaseLock Volume %u %s\n", volid, rxinfo(rxstr, rxcall)));
1214 blockindex = FindByID(&ctx, volid, voltype, &tentry, &code);
1215 if (blockindex == NULLO) {
1220 if (tentry.flags & VLDELETED) {
1221 ABORT(VL_ENTDELETED);
1224 ReleaseEntry(&tentry, releasetype); /* Unlock the appropriate fields */
1225 if (vlentrywrite(ctx.trans, blockindex, &tentry, sizeof(tentry))) {
1228 return ubik_EndTrans(ctx.trans);
1231 countAbort(this_op);
1232 ubik_AbortTrans(ctx.trans);
1237 SVL_ReleaseLock(struct rx_call *rxcall, afs_uint32 volid, afs_int32 voltype,
1238 afs_int32 releasetype)
1242 code = ReleaseLock(rxcall, volid, voltype, releasetype);
1243 osi_auditU(rxcall, VLReleaseLockEvent, code, AUD_LONG, volid, AUD_END);
1247 /* ListEntry returns a single vldb entry, aentry, with offset previous_index;
1248 * the remaining parameters (i.e. next_index) are used so that sequential
1249 * calls to this routine will get the next (all) vldb entries.
1252 ListEntry(struct rx_call *rxcall, afs_int32 previous_index,
1253 afs_int32 *count, afs_int32 *next_index,
1254 struct vldbentry *aentry)
1256 int this_op = VLLISTENTRY;
1259 struct nvlentry tentry;
1260 char rxstr[AFS_RXINFO_LEN];
1262 countRequest(this_op);
1264 if (!afsconf_CheckRestrictedQuery(vldb_confdir, rxcall,
1265 restrictedQueryLevel))
1268 if ((code = Init_VLdbase(&ctx, LOCKREAD, this_op)))
1270 VLog(25, ("OListEntry index=%d %s\n", previous_index,
1271 rxinfo(rxstr, rxcall)));
1272 *next_index = NextEntry(&ctx, previous_index, &tentry, count);
1274 code = vlentry_to_vldbentry(&ctx, &tentry, aentry);
1276 countAbort(this_op);
1277 ubik_AbortTrans(ctx.trans);
1281 return ubik_EndTrans(ctx.trans);
1285 SVL_ListEntry(struct rx_call *rxcall, afs_int32 previous_index,
1286 afs_int32 *count, afs_int32 *next_index,
1287 struct vldbentry *aentry)
1291 code = ListEntry(rxcall, previous_index, count, next_index, aentry);
1292 osi_auditU(rxcall, VLListEntryEvent, code, AUD_LONG, previous_index, AUD_END);
1296 /* ListEntry returns a single vldb entry, aentry, with offset previous_index;
1297 * the remaining parameters (i.e. next_index) are used so that sequential
1298 * calls to this routine will get the next (all) vldb entries.
1301 ListEntryN(struct rx_call *rxcall, afs_int32 previous_index,
1302 afs_int32 *count, afs_int32 *next_index,
1303 struct nvldbentry *aentry)
1305 int this_op = VLLISTENTRYN;
1308 struct nvlentry tentry;
1309 char rxstr[AFS_RXINFO_LEN];
1311 countRequest(this_op);
1313 if (!afsconf_CheckRestrictedQuery(vldb_confdir, rxcall,
1314 restrictedQueryLevel))
1317 if ((code = Init_VLdbase(&ctx, LOCKREAD, this_op)))
1319 VLog(25, ("ListEntry index=%d %s\n", previous_index, rxinfo(rxstr, rxcall)));
1320 *next_index = NextEntry(&ctx, previous_index, &tentry, count);
1322 code = vlentry_to_nvldbentry(&ctx, &tentry, aentry);
1324 countAbort(this_op);
1325 ubik_AbortTrans(ctx.trans);
1330 return ubik_EndTrans(ctx.trans);
1334 SVL_ListEntryN(struct rx_call *rxcall, afs_int32 previous_index,
1335 afs_int32 *count, afs_int32 *next_index,
1336 struct nvldbentry *aentry)
1340 code = ListEntryN(rxcall, previous_index, count, next_index, aentry);
1341 osi_auditU(rxcall, VLListEntryEventN, code, AUD_LONG, previous_index, AUD_END);
1345 /* Retrieves in vldbentries all vldb entries that match the specified
1346 * attributes (by server number, partition, volume type, and flag); if volume
1347 * id is specified then the associated list for that entry is returned.
1348 * CAUTION: This could be a very expensive call since in most cases
1349 * sequential search of all vldb entries is performed.
1352 ListAttributes(struct rx_call *rxcall,
1353 struct VldbListByAttributes *attributes,
1354 afs_int32 *nentries,
1355 bulkentries *vldbentries)
1357 int this_op = VLLISTATTRIBUTES;
1358 int code, allocCount = 0;
1360 struct nvlentry tentry;
1361 struct vldbentry *Vldbentry = 0, *VldbentryFirst = 0, *VldbentryLast = 0;
1363 char rxstr[AFS_RXINFO_LEN];
1365 countRequest(this_op);
1367 if (!afsconf_CheckRestrictedQuery(vldb_confdir, rxcall,
1368 restrictedQueryLevel))
1371 vldbentries->bulkentries_val = 0;
1372 vldbentries->bulkentries_len = *nentries = 0;
1373 if ((code = Init_VLdbase(&ctx, LOCKREAD, this_op)))
1375 allocCount = VLDBALLOCCOUNT;
1376 Vldbentry = VldbentryFirst = vldbentries->bulkentries_val =
1377 malloc(allocCount * sizeof(vldbentry));
1378 if (Vldbentry == NULL) {
1382 VldbentryLast = VldbentryFirst + allocCount;
1383 /* Handle the attribute by volume id totally separate of the rest
1384 * (thus additional Mask values are ignored if VLLIST_VOLUMEID is set!) */
1385 if (attributes->Mask & VLLIST_VOLUMEID) {
1386 afs_int32 blockindex;
1389 FindByID(&ctx, attributes->volumeid, -1, &tentry, &code);
1390 if (blockindex == 0) {
1396 code = put_attributeentry(&ctx, &Vldbentry, &VldbentryFirst,
1397 &VldbentryLast, vldbentries, &tentry,
1398 nentries, &allocCount);
1402 afs_int32 nextblockindex = 0, count = 0, k = 0, match = 0;
1403 while ((nextblockindex =
1404 NextEntry(&ctx, nextblockindex, &tentry, &count))) {
1405 if (++pollcount > 50) {
1406 #ifndef AFS_PTHREAD_ENV
1412 if (attributes->Mask & VLLIST_SERVER) {
1415 IpAddrToRelAddr(&ctx, attributes->server, 0)) == -1)
1417 for (k = 0; k < OMAXNSERVERS; k++) {
1418 if (tentry.serverNumber[k] == BADSERVERID)
1420 if (tentry.serverNumber[k] == serverindex) {
1428 if (attributes->Mask & VLLIST_PARTITION) {
1430 if (tentry.serverPartition[k] != attributes->partition)
1433 for (k = 0; k < OMAXNSERVERS; k++) {
1434 if (tentry.serverNumber[k] == BADSERVERID)
1436 if (tentry.serverPartition[k] ==
1437 attributes->partition) {
1447 if (attributes->Mask & VLLIST_FLAG) {
1448 if (!(tentry.flags & attributes->flag))
1451 code = put_attributeentry(&ctx, &Vldbentry, &VldbentryFirst,
1452 &VldbentryLast, vldbentries, &tentry,
1453 nentries, &allocCount);
1458 if (vldbentries->bulkentries_len
1459 && (allocCount > vldbentries->bulkentries_len)) {
1461 vldbentries->bulkentries_val =
1462 realloc(vldbentries->bulkentries_val,
1463 vldbentries->bulkentries_len * sizeof(vldbentry));
1464 if (vldbentries->bulkentries_val == NULL) {
1470 ("ListAttrs nentries=%d %s\n", vldbentries->bulkentries_len,
1471 rxinfo(rxstr, rxcall)));
1472 return ubik_EndTrans(ctx.trans);
1475 if (vldbentries->bulkentries_val)
1476 free(vldbentries->bulkentries_val);
1477 vldbentries->bulkentries_val = 0;
1478 vldbentries->bulkentries_len = 0;
1480 countAbort(this_op);
1481 ubik_AbortTrans(ctx.trans);
1486 SVL_ListAttributes(struct rx_call *rxcall,
1487 struct VldbListByAttributes *attributes,
1488 afs_int32 *nentries,
1489 bulkentries *vldbentries)
1493 code = ListAttributes(rxcall, attributes, nentries, vldbentries);
1494 osi_auditU(rxcall, VLListAttributesEvent, code, AUD_END);
1499 ListAttributesN(struct rx_call *rxcall,
1500 struct VldbListByAttributes *attributes,
1501 afs_int32 *nentries,
1502 nbulkentries *vldbentries)
1504 int this_op = VLLISTATTRIBUTESN;
1505 int code, allocCount = 0;
1507 struct nvlentry tentry;
1508 struct nvldbentry *Vldbentry = 0, *VldbentryFirst = 0, *VldbentryLast = 0;
1510 char rxstr[AFS_RXINFO_LEN];
1512 countRequest(this_op);
1514 if (!afsconf_CheckRestrictedQuery(vldb_confdir, rxcall,
1515 restrictedQueryLevel))
1518 vldbentries->nbulkentries_val = 0;
1519 vldbentries->nbulkentries_len = *nentries = 0;
1520 if ((code = Init_VLdbase(&ctx, LOCKREAD, this_op)))
1522 allocCount = VLDBALLOCCOUNT;
1523 Vldbentry = VldbentryFirst = vldbentries->nbulkentries_val =
1524 malloc(allocCount * sizeof(nvldbentry));
1525 if (Vldbentry == NULL) {
1529 VldbentryLast = VldbentryFirst + allocCount;
1530 /* Handle the attribute by volume id totally separate of the rest
1531 * (thus additional Mask values are ignored if VLLIST_VOLUMEID is set!) */
1532 if (attributes->Mask & VLLIST_VOLUMEID) {
1533 afs_int32 blockindex;
1536 FindByID(&ctx, attributes->volumeid, -1, &tentry, &code);
1537 if (blockindex == 0) {
1543 code = put_nattributeentry(&ctx, &Vldbentry, &VldbentryFirst,
1544 &VldbentryLast, vldbentries, &tentry,
1545 0, 0, nentries, &allocCount);
1549 afs_int32 nextblockindex = 0, count = 0, k = 0, match = 0;
1550 while ((nextblockindex =
1551 NextEntry(&ctx, nextblockindex, &tentry, &count))) {
1552 if (++pollcount > 50) {
1553 #ifndef AFS_PTHREAD_ENV
1560 if (attributes->Mask & VLLIST_SERVER) {
1563 IpAddrToRelAddr(&ctx, attributes->server, 0)) == -1)
1565 for (k = 0; k < NMAXNSERVERS; k++) {
1566 if (tentry.serverNumber[k] == BADSERVERID)
1568 if (tentry.serverNumber[k] == serverindex) {
1576 if (attributes->Mask & VLLIST_PARTITION) {
1578 if (tentry.serverPartition[k] != attributes->partition)
1581 for (k = 0; k < NMAXNSERVERS; k++) {
1582 if (tentry.serverNumber[k] == BADSERVERID)
1584 if (tentry.serverPartition[k] ==
1585 attributes->partition) {
1595 if (attributes->Mask & VLLIST_FLAG) {
1596 if (!(tentry.flags & attributes->flag))
1599 code = put_nattributeentry(&ctx, &Vldbentry, &VldbentryFirst,
1600 &VldbentryLast, vldbentries,
1601 &tentry, 0, 0, nentries, &allocCount);
1606 if (vldbentries->nbulkentries_len
1607 && (allocCount > vldbentries->nbulkentries_len)) {
1609 vldbentries->nbulkentries_val =
1610 realloc(vldbentries->nbulkentries_val,
1611 vldbentries->nbulkentries_len * sizeof(nvldbentry));
1612 if (vldbentries->nbulkentries_val == NULL) {
1618 ("NListAttrs nentries=%d %s\n", vldbentries->nbulkentries_len,
1619 rxinfo(rxstr, rxcall)));
1620 return ubik_EndTrans(ctx.trans);
1623 countAbort(this_op);
1624 ubik_AbortTrans(ctx.trans);
1625 if (vldbentries->nbulkentries_val)
1626 free(vldbentries->nbulkentries_val);
1627 vldbentries->nbulkentries_val = 0;
1628 vldbentries->nbulkentries_len = 0;
1633 SVL_ListAttributesN(struct rx_call *rxcall,
1634 struct VldbListByAttributes *attributes,
1635 afs_int32 *nentries,
1636 nbulkentries *vldbentries)
1640 code = ListAttributesN(rxcall, attributes, nentries, vldbentries);
1641 osi_auditU(rxcall, VLListAttributesNEvent, code, AUD_END);
1646 ListAttributesN2(struct rx_call *rxcall,
1647 struct VldbListByAttributes *attributes,
1648 char *name, /* Wildcarded volume name */
1649 afs_int32 startindex,
1650 afs_int32 *nentries,
1651 nbulkentries *vldbentries,
1652 afs_int32 *nextstartindex)
1654 int this_op = VLLISTATTRIBUTESN2;
1655 int code = 0, maxCount = VLDBALLOCCOUNT;
1657 struct nvlentry tentry;
1658 struct nvldbentry *Vldbentry = 0, *VldbentryFirst = 0, *VldbentryLast = 0;
1659 afs_int32 blockindex = 0, count = 0, k, match;
1660 afs_int32 matchindex = 0;
1661 int serverindex = -1; /* no server found */
1662 int findserver = 0, findpartition = 0, findflag = 0, findname = 0;
1664 int namematchRWBK, namematchRO, thismatch;
1667 char volumename[VL_MAXNAMELEN+3]; /* regex anchors */
1668 char rxstr[AFS_RXINFO_LEN];
1669 #ifdef HAVE_POSIX_REGEX
1671 int need_regfree = 0;
1676 countRequest(this_op);
1678 if (!afsconf_CheckRestrictedQuery(vldb_confdir, rxcall,
1679 restrictedQueryLevel))
1682 vldbentries->nbulkentries_val = 0;
1683 vldbentries->nbulkentries_len = 0;
1685 *nextstartindex = -1;
1687 code = Init_VLdbase(&ctx, LOCKREAD, this_op);
1691 Vldbentry = VldbentryFirst = vldbentries->nbulkentries_val =
1692 malloc(maxCount * sizeof(nvldbentry));
1693 if (Vldbentry == NULL) {
1694 countAbort(this_op);
1695 ubik_AbortTrans(ctx.trans);
1699 VldbentryLast = VldbentryFirst + maxCount;
1701 /* Handle the attribute by volume id totally separate of the rest
1702 * (thus additional Mask values are ignored if VLLIST_VOLUMEID is set!)
1704 if (attributes->Mask & VLLIST_VOLUMEID) {
1706 FindByID(&ctx, attributes->volumeid, -1, &tentry, &code);
1707 if (blockindex == 0) {
1712 put_nattributeentry(&ctx, &Vldbentry, &VldbentryFirst,
1713 &VldbentryLast, vldbentries, &tentry, 0,
1714 0, nentries, &maxCount);
1720 /* Search each entry in the database and return all entries
1721 * that match the request. It checks volumename (with
1722 * wildcarding), entry flags, server, and partition.
1725 /* Get the server index for matching server address */
1726 if (attributes->Mask & VLLIST_SERVER) {
1728 IpAddrToRelAddr(&ctx, attributes->server, 0);
1729 if (serverindex == -1)
1733 findpartition = ((attributes->Mask & VLLIST_PARTITION) ? 1 : 0);
1734 findflag = ((attributes->Mask & VLLIST_FLAG) ? 1 : 0);
1735 if (name && (strcmp(name, ".*") != 0) && (strcmp(name, "") != 0)) {
1736 if (!afsconf_SuperUser(vldb_confdir, rxcall, NULL)) {
1740 size = snprintf(volumename, sizeof(volumename), "^%s$", name);
1741 if (size < 0 || size >= sizeof(volumename)) {
1745 #ifdef HAVE_POSIX_REGEX
1746 if (regcomp(&re, volumename, REG_NOSUB) != 0) {
1752 t = (char *)re_comp(volumename);
1761 /* Read each entry and see if it is the one we want */
1762 blockindex = startindex;
1763 while ((blockindex = NextEntry(&ctx, blockindex, &tentry, &count))) {
1764 if (++pollcount > 50) {
1765 #ifndef AFS_PTHREAD_ENV
1771 /* Step through each server index searching for a match.
1772 * Match to an existing RW, BK, or RO volume name (preference
1773 * is in this order). Remember which index we matched against.
1775 namematchRWBK = namematchRO = 0; /* 0->notTried; 1->match; 2->noMatch */
1779 && (tentry.serverNumber[k] != BADSERVERID)); k++) {
1780 thismatch = 0; /* does this index match */
1782 /* Match against the RW or BK volume name. Remember
1783 * results in namematchRWBK. Prefer RW over BK.
1785 if (tentry.serverFlags[k] & VLSF_RWVOL) {
1786 /* Does the name match the RW name */
1787 if (tentry.flags & VLF_RWEXISTS) {
1789 size = snprintf(volumename, sizeof(volumename),
1791 if (size < 0 || size >= sizeof(volumename)) {
1795 #ifdef HAVE_POSIX_REGEX
1796 if (regexec(&re, volumename, 0, NULL, 0) == 0) {
1797 thismatch = VLSF_RWVOL;
1800 if (re_exec(volumename)) {
1801 thismatch = VLSF_RWVOL;
1805 thismatch = VLSF_RWVOL;
1809 /* Does the name match the BK name */
1810 if (!thismatch && (tentry.flags & VLF_BACKEXISTS)) {
1812 /* If this fails, the tentry.name is invalid */
1813 size = snprintf(volumename, sizeof(volumename),
1814 "%s.backup", tentry.name);
1815 if (size < 0 || size >= sizeof(volumename)) {
1819 #ifdef HAVE_POSIX_REGEX
1820 if (regexec(&re, volumename, 0, NULL, 0) == 0) {
1821 thismatch = VLSF_BACKVOL;
1824 if (re_exec(volumename)) {
1825 thismatch = VLSF_BACKVOL;
1829 thismatch = VLSF_BACKVOL;
1833 namematchRWBK = (thismatch ? 1 : 2);
1836 /* Match with the RO volume name. Compare once and
1837 * remember results in namematchRO. Note that this will
1838 * pick up entries marked NEWREPSITEs and DONTUSE.
1841 if (tentry.flags & VLF_ROEXISTS) {
1845 ((namematchRO == 1) ? VLSF_ROVOL : 0);
1847 /* If this fails, the tentry.name is invalid */
1848 size = snprintf(volumename, sizeof(volumename),
1849 "%s.readonly", tentry.name);
1850 if (size < 0 || size >= sizeof(volumename)) {
1854 #ifdef HAVE_POSIX_REGEX
1855 if (regexec(&re, volumename, 0, NULL, 0) == 0) {
1856 thismatch = VLSF_ROVOL;
1859 if (re_exec(volumename))
1860 thismatch = VLSF_ROVOL;
1864 thismatch = VLSF_ROVOL;
1867 namematchRO = (thismatch ? 1 : 2);
1870 /* Is there a server match */
1871 if (thismatch && findserver
1872 && (tentry.serverNumber[k] != serverindex))
1875 /* Is there a partition match */
1876 if (thismatch && findpartition
1877 && (tentry.serverPartition[k] != attributes->partition))
1880 /* Is there a flag match */
1881 if (thismatch && findflag
1882 && !(tentry.flags & attributes->flag))
1885 /* We found a match. Remember the index, and type */
1889 matchtype = thismatch;
1892 /* Since we prefer RW and BK volume matches over RO matches,
1893 * if we have already checked the RWBK name, then we already
1894 * found the best match and so end the search.
1896 * If we tried matching against the RW, BK, and RO volume names
1897 * and both failed, then we end the search (none will match).
1899 if ((match && namematchRWBK)
1900 || ((namematchRWBK == 2) && (namematchRO == 2)))
1904 /* Passed all the tests. Take it */
1907 put_nattributeentry(&ctx, &Vldbentry, &VldbentryFirst,
1908 &VldbentryLast, vldbentries, &tentry,
1909 matchtype, matchindex, nentries,
1914 if (*nentries >= maxCount)
1915 break; /* collected the max */
1918 *nextstartindex = (blockindex ? blockindex : -1);
1922 #ifdef HAVE_POSIX_REGEX
1928 countAbort(this_op);
1929 ubik_AbortTrans(ctx.trans);
1930 if (vldbentries->nbulkentries_val)
1931 free(vldbentries->nbulkentries_val);
1932 vldbentries->nbulkentries_val = 0;
1933 vldbentries->nbulkentries_len = 0;
1934 *nextstartindex = -1;
1937 ("N2ListAttrs nentries=%d %s\n", vldbentries->nbulkentries_len,
1938 rxinfo(rxstr, rxcall)));
1939 code = ubik_EndTrans(ctx.trans);
1946 SVL_ListAttributesN2(struct rx_call *rxcall,
1947 struct VldbListByAttributes *attributes,
1948 char *name, /* Wildcarded volume name */
1949 afs_int32 startindex,
1950 afs_int32 *nentries,
1951 nbulkentries *vldbentries,
1952 afs_int32 *nextstartindex)
1956 code = ListAttributesN2(rxcall, attributes, name, startindex,
1957 nentries, vldbentries, nextstartindex);
1958 osi_auditU(rxcall, VLListAttributesN2Event, code, AUD_END);
1962 /* Retrieves in vldbentries all vldb entries that match the specified
1963 * attributes (by server number, partition, volume type, and flag); if
1964 * volume id is specified then the associated list for that entry is
1965 * returned. CAUTION: This could be a very expensive call since in most
1966 * cases sequential search of all vldb entries is performed.
1969 LinkedList(struct rx_call *rxcall,
1970 struct VldbListByAttributes *attributes,
1971 afs_int32 *nentries,
1972 vldb_list *vldbentries)
1974 int this_op = VLLINKEDLIST;
1977 struct nvlentry tentry;
1978 vldblist vllist, *vllistptr;
1979 afs_int32 blockindex, count, match;
1984 countRequest(this_op);
1986 if (!afsconf_CheckRestrictedQuery(vldb_confdir, rxcall,
1987 restrictedQueryLevel))
1990 if ((code = Init_VLdbase(&ctx, LOCKREAD, this_op)))
1994 vldbentries->node = NULL;
1995 vllistptr = &vldbentries->node;
1997 /* List by volumeid */
1998 if (attributes->Mask & VLLIST_VOLUMEID) {
2000 FindByID(&ctx, attributes->volumeid, -1, &tentry, &code);
2007 vllist = malloc(sizeof(single_vldbentry));
2008 if (vllist == NULL) {
2012 code = vlentry_to_vldbentry(&ctx, &tentry, &vllist->VldbEntry);
2016 vllist->next_vldb = NULL;
2018 *vllistptr = vllist; /* Thread onto list */
2019 vllistptr = &vllist->next_vldb;
2023 /* Search by server, partition, and flags */
2025 for (blockindex = NextEntry(&ctx, 0, &tentry, &count); blockindex;
2026 blockindex = NextEntry(&ctx, blockindex, &tentry, &count)) {
2029 if (++pollcount > 50) {
2030 #ifndef AFS_PTHREAD_ENV
2036 /* Does this volume exist on the desired server */
2037 if (attributes->Mask & VLLIST_SERVER) {
2039 IpAddrToRelAddr(&ctx, attributes->server, 0);
2040 if (serverindex == -1)
2042 for (k = 0; k < OMAXNSERVERS; k++) {
2043 if (tentry.serverNumber[k] == BADSERVERID)
2045 if (tentry.serverNumber[k] == serverindex) {
2054 /* Does this volume exist on the desired partition */
2055 if (attributes->Mask & VLLIST_PARTITION) {
2057 if (tentry.serverPartition[k] != attributes->partition)
2060 for (k = 0; k < OMAXNSERVERS; k++) {
2061 if (tentry.serverNumber[k] == BADSERVERID)
2063 if (tentry.serverPartition[k] ==
2064 attributes->partition) {
2074 /* Does this volume have the desired flags */
2075 if (attributes->Mask & VLLIST_FLAG) {
2076 if (!(tentry.flags & attributes->flag))
2080 vllist = malloc(sizeof(single_vldbentry));
2081 if (vllist == NULL) {
2085 code = vlentry_to_vldbentry(&ctx, &tentry, &vllist->VldbEntry);
2089 vllist->next_vldb = NULL;
2091 *vllistptr = vllist; /* Thread onto list */
2092 vllistptr = &vllist->next_vldb;
2094 if (smallMem && (*nentries >= VLDBALLOCCOUNT)) {
2095 code = VL_SIZEEXCEEDED;
2101 return ubik_EndTrans(ctx.trans);
2104 countAbort(this_op);
2105 ubik_AbortTrans(ctx.trans);
2110 SVL_LinkedList(struct rx_call *rxcall,
2111 struct VldbListByAttributes *attributes,
2112 afs_int32 *nentries,
2113 vldb_list *vldbentries)
2117 code = LinkedList(rxcall, attributes, nentries, vldbentries);
2118 osi_auditU(rxcall, VLLinkedListEvent, code, AUD_END);
2123 LinkedListN(struct rx_call *rxcall,
2124 struct VldbListByAttributes *attributes,
2125 afs_int32 *nentries,
2126 nvldb_list *vldbentries)
2128 int this_op = VLLINKEDLISTN;
2131 struct nvlentry tentry;
2132 nvldblist vllist, *vllistptr;
2133 afs_int32 blockindex, count, match;
2138 countRequest(this_op);
2140 if (!afsconf_CheckRestrictedQuery(vldb_confdir, rxcall,
2141 restrictedQueryLevel))
2144 if ((code = Init_VLdbase(&ctx, LOCKREAD, this_op)))
2148 vldbentries->node = NULL;
2149 vllistptr = &vldbentries->node;
2151 /* List by volumeid */
2152 if (attributes->Mask & VLLIST_VOLUMEID) {
2154 FindByID(&ctx, attributes->volumeid, -1, &tentry, &code);
2161 vllist = malloc(sizeof(single_nvldbentry));
2162 if (vllist == NULL) {
2166 code = vlentry_to_nvldbentry(&ctx, &tentry, &vllist->VldbEntry);
2170 vllist->next_vldb = NULL;
2172 *vllistptr = vllist; /* Thread onto list */
2173 vllistptr = &vllist->next_vldb;
2177 /* Search by server, partition, and flags */
2179 for (blockindex = NextEntry(&ctx, 0, &tentry, &count); blockindex;
2180 blockindex = NextEntry(&ctx, blockindex, &tentry, &count)) {
2183 if (++pollcount > 50) {
2184 #ifndef AFS_PTHREAD_ENV
2190 /* Does this volume exist on the desired server */
2191 if (attributes->Mask & VLLIST_SERVER) {
2193 IpAddrToRelAddr(&ctx, attributes->server, 0);
2194 if (serverindex == -1)
2196 for (k = 0; k < NMAXNSERVERS; k++) {
2197 if (tentry.serverNumber[k] == BADSERVERID)
2199 if (tentry.serverNumber[k] == serverindex) {
2208 /* Does this volume exist on the desired partition */
2209 if (attributes->Mask & VLLIST_PARTITION) {
2211 if (tentry.serverPartition[k] != attributes->partition)
2214 for (k = 0; k < NMAXNSERVERS; k++) {
2215 if (tentry.serverNumber[k] == BADSERVERID)
2217 if (tentry.serverPartition[k] ==
2218 attributes->partition) {
2228 /* Does this volume have the desired flags */
2229 if (attributes->Mask & VLLIST_FLAG) {
2230 if (!(tentry.flags & attributes->flag))
2234 vllist = malloc(sizeof(single_nvldbentry));
2235 if (vllist == NULL) {
2239 code = vlentry_to_nvldbentry(&ctx, &tentry, &vllist->VldbEntry);
2243 vllist->next_vldb = NULL;
2245 *vllistptr = vllist; /* Thread onto list */
2246 vllistptr = &vllist->next_vldb;
2248 if (smallMem && (*nentries >= VLDBALLOCCOUNT)) {
2249 code = VL_SIZEEXCEEDED;
2255 return ubik_EndTrans(ctx.trans);
2258 countAbort(this_op);
2259 ubik_AbortTrans(ctx.trans);
2264 SVL_LinkedListN(struct rx_call *rxcall,
2265 struct VldbListByAttributes *attributes,
2266 afs_int32 *nentries,
2267 nvldb_list *vldbentries)
2271 code = LinkedListN(rxcall, attributes, nentries, vldbentries);
2272 osi_auditU(rxcall, VLLinkedListNEvent, code, AUD_END);
2276 /* Get back vldb header statistics (allocs, frees, maxvolumeid,
2277 * totalentries, etc) and dynamic statistics (number of requests and/or
2278 * aborts per remote procedure call, etc)
2281 GetStats(struct rx_call *rxcall,
2283 vital_vlheader *vital_header)
2285 int this_op = VLGETSTATS;
2288 char rxstr[AFS_RXINFO_LEN];
2290 countRequest(this_op);
2292 if (!afsconf_CheckRestrictedQuery(vldb_confdir, rxcall,
2293 restrictedQueryLevel))
2296 if ((code = Init_VLdbase(&ctx, LOCKREAD, this_op)))
2298 VLog(5, ("GetStats %s\n", rxinfo(rxstr, rxcall)));
2299 memcpy((char *)vital_header, (char *)&ctx.cheader->vital_header,
2300 sizeof(vital_vlheader));
2301 memcpy((char *)stats, (char *)&dynamic_statistics, sizeof(vldstats));
2302 return ubik_EndTrans(ctx.trans);
2306 SVL_GetStats(struct rx_call *rxcall,
2308 vital_vlheader *vital_header)
2312 code = GetStats(rxcall, stats, vital_header);
2313 osi_auditU(rxcall, VLGetStatsEvent, code, AUD_END);
2317 /* Get the list of file server addresses from the VLDB. Currently it's pretty
2318 * easy to do. In the future, it might require a little bit of grunging
2319 * through the VLDB, but that's life.
2322 SVL_GetAddrs(struct rx_call *rxcall,
2325 struct VLCallBack *spare3,
2326 afs_int32 *nentries,
2329 int this_op = VLGETADDRS;
2335 countRequest(this_op);
2336 addrsp->bulkaddrs_len = *nentries = 0;
2337 addrsp->bulkaddrs_val = 0;
2338 memset(spare3, 0, sizeof(struct VLCallBack));
2340 if ((code = Init_VLdbase(&ctx, LOCKREAD, this_op)))
2343 VLog(5, ("GetAddrs\n"));
2344 addrsp->bulkaddrs_val = taddrp =
2345 malloc(sizeof(afs_uint32) * (MAXSERVERID + 1));
2346 nservers = *nentries = addrsp->bulkaddrs_len = 0;
2353 for (i = 0; i <= MAXSERVERID; i++) {
2354 if ((*taddrp = ntohl(ctx.cheader->IpMappedAddr[i]))) {
2360 addrsp->bulkaddrs_len = *nentries = nservers;
2361 return (ubik_EndTrans(ctx.trans));
2364 countAbort(this_op);
2365 ubik_AbortTrans(ctx.trans);
2370 append_addr(char *buffer, afs_uint32 addr, size_t buffer_size)
2372 int n = strlen(buffer);
2373 if (buffer_size > n) {
2374 snprintf(buffer + n, buffer_size - n, "%u.%u.%u.%u",
2375 (addr >> 24) & 0xff, (addr >> 16) & 0xff, (addr >> 8) & 0xff,
2381 SVL_RegisterAddrs(struct rx_call *rxcall, afsUUID *uuidp, afs_int32 spare1,
2384 int this_op = VLREGADDR;
2387 int cnt, h, i, j, k, m;
2388 struct extentaddr *exp = 0, *tex;
2391 afs_uint32 addrs[VL_MAXIPADDRS_PERMH];
2393 int count, willChangeEntry, foundUuidEntry, willReplaceCnt;
2394 int WillReplaceEntry, WillChange[MAXSERVERID + 1];
2396 int ReplaceEntry = 0;
2399 countRequest(this_op);
2400 if (!afsconf_SuperUser(vldb_confdir, rxcall, NULL))
2402 if ((code = Init_VLdbase(&ctx, LOCKWRITE, this_op)))
2405 /* Eliminate duplicates from IP address list */
2406 for (k = 0, cnt = 0; k < addrsp->bulkaddrs_len; k++) {
2407 if (addrsp->bulkaddrs_val[k] == 0)
2409 for (m = 0; m < cnt; m++) {
2410 if (addrs[m] == addrsp->bulkaddrs_val[k])
2414 if (m == VL_MAXIPADDRS_PERMH) {
2416 ("Number of addresses exceeds %d. Cannot register IP addr 0x%x in VLDB\n",
2417 VL_MAXIPADDRS_PERMH, addrsp->bulkaddrs_val[k]));
2419 addrs[m] = addrsp->bulkaddrs_val[k];
2425 code = VL_INDEXERANGE;
2432 /* For each server registered within the VLDB */
2433 for (srvidx = 0; srvidx <= MAXSERVERID; srvidx++) {
2434 willChangeEntry = 0;
2435 WillReplaceEntry = 1;
2436 code = multiHomedExtent(&ctx, srvidx, &exp);
2441 /* See if the addresses to register will change this server entry */
2442 tuuid = exp->ex_hostuuid;
2443 afs_ntohuuid(&tuuid);
2444 if (afs_uuid_equal(uuidp, &tuuid)) {
2448 for (mhidx = 0; mhidx < VL_MAXIPADDRS_PERMH; mhidx++) {
2449 if (!exp->ex_addrs[mhidx])
2451 for (k = 0; k < cnt; k++) {
2452 if (ntohl(exp->ex_addrs[mhidx]) == addrs[k]) {
2453 willChangeEntry = 1;
2454 WillChange[count] = srvidx;
2459 WillReplaceEntry = 0;
2463 /* The server is not registered as a multihomed.
2464 * See if the addresses to register will replace this server entry.
2466 for (k = 0; k < cnt; k++) {
2467 if (ctx.hostaddress[srvidx] == addrs[k]) {
2468 willChangeEntry = 1;
2469 WillChange[count] = srvidx;
2470 WillReplaceEntry = 1;
2475 if (willChangeEntry) {
2476 if (WillReplaceEntry) {
2478 ReplaceEntry = srvidx;
2484 /* If we found the uuid in the VLDB and if we are replacing another
2485 * entire entry, then complain and fail. Also, if we did not find
2486 * the uuid in the VLDB and the IP addresses being registered was
2487 * found in more than one other entry, then we don't know which one
2488 * to replace and will complain and fail.
2490 if ((foundUuidEntry && (willReplaceCnt > 0))
2491 || (!foundUuidEntry && (count > 1))) {
2493 ("The following fileserver is being registered in the VLDB:\n"));
2494 for (addrbuf[0] = '\0', k = 0; k < cnt; k++) {
2496 strlcat(addrbuf, " ", sizeof(addrbuf));
2497 append_addr(addrbuf, addrs[k], sizeof(addrbuf));
2499 VLog(0, (" [%s]\n", addrbuf));
2501 if (foundUuidEntry) {
2502 code = multiHomedExtent(&ctx, FoundUuid, &exp);
2504 VLog(0, (" It would have replaced the existing VLDB server "
2506 for (addrbuf[0] = '\0', mhidx = 0; mhidx < VL_MAXIPADDRS_PERMH; mhidx++) {
2507 if (!exp->ex_addrs[mhidx])
2510 strlcat(addrbuf, " ", sizeof(addrbuf));
2511 append_addr(addrbuf, ntohl(exp->ex_addrs[mhidx]), sizeof(addrbuf));
2513 VLog(0, (" entry %d: [%s]\n", FoundUuid, addrbuf));
2518 VLog(0, (" Yet another VLDB server entry exists:\n"));
2520 VLog(0, (" Yet other VLDB server entries exist:\n"));
2521 for (j = 0; j < count; j++) {
2522 srvidx = WillChange[j];
2523 VLog(0, (" entry %d: ", srvidx));
2525 code = multiHomedExtent(&ctx, srvidx, &exp);
2531 for (mhidx = 0; mhidx < VL_MAXIPADDRS_PERMH; mhidx++) {
2532 if (!exp->ex_addrs[mhidx])
2535 strlcat(addrbuf, " ", sizeof(addrbuf));
2536 append_addr(addrbuf, ntohl(exp->ex_addrs[mhidx]), sizeof(addrbuf));
2539 append_addr(addrbuf, ctx.hostaddress[srvidx], sizeof(addrbuf));
2541 VLog(0, (" entry %d: [%s]\n", srvidx, addrbuf));
2545 VLog(0, (" You must 'vos changeaddr' this other server entry\n"));
2548 (" You must 'vos changeaddr' these other server entries\n"));
2551 (" and/or remove the sysid file from the registering fileserver\n"));
2552 VLog(0, (" before the fileserver can be registered in the VLDB.\n"));
2554 code = VL_MULTIPADDR;
2558 /* Passed the checks. Now find and update the existing mh entry, or create
2561 if (foundUuidEntry) {
2562 /* Found the entry with same uuid. See if we need to change it */
2565 code = multiHomedExtentBase(&ctx, FoundUuid, &exp, &base);
2569 /* Determine if the entry has changed */
2570 for (k = 0; ((k < cnt) && !change); k++) {
2571 if (ntohl(exp->ex_addrs[k]) != addrs[k])
2574 for (; ((k < VL_MAXIPADDRS_PERMH) && !change); k++) {
2575 if (exp->ex_addrs[k] != 0)
2579 return (ubik_EndTrans(ctx.trans));
2583 VLog(0, ("The following fileserver is being registered in the VLDB:\n"));
2584 for (addrbuf[0] = '\0', k = 0; k < cnt; k++) {
2586 strlcat(addrbuf, " ", sizeof(addrbuf));
2587 append_addr(addrbuf, addrs[k], sizeof(addrbuf));
2589 VLog(0, (" [%s]\n", addrbuf));
2591 if (foundUuidEntry) {
2593 (" It will replace the following existing entry in the VLDB (same uuid):\n"));
2594 for (addrbuf[0] = '\0', k = 0; k < VL_MAXIPADDRS_PERMH; k++) {
2595 if (exp->ex_addrs[k] == 0)
2598 strlcat(addrbuf, " ", sizeof(addrbuf));
2599 append_addr(addrbuf, ntohl(exp->ex_addrs[k]), sizeof(addrbuf));
2601 VLog(0, (" entry %d: [%s]\n", FoundUuid, addrbuf));
2602 } else if (willReplaceCnt || (count == 1)) {
2603 /* If we are not replacing an entry and there is only one entry to change,
2604 * then we will replace that entry.
2606 if (!willReplaceCnt) {
2607 ReplaceEntry = WillChange[0];
2611 /* Have an entry that needs to be replaced */
2612 code = multiHomedExtentBase(&ctx, ReplaceEntry, &exp, &base);
2618 (" It will replace the following existing entry in the VLDB (new uuid):\n"));
2619 for (addrbuf[0] = '\0', k = 0; k < VL_MAXIPADDRS_PERMH; k++) {
2620 if (exp->ex_addrs[k] == 0)
2623 strlcat(addrbuf, " ", sizeof(addrbuf));
2624 append_addr(addrbuf, ntohl(exp->ex_addrs[k]), sizeof(addrbuf));
2626 VLog(0, (" entry %d: [%s]\n", ReplaceEntry, addrbuf));
2628 /* Not a mh entry. So we have to create a new mh entry and
2629 * put it on the ReplaceEntry slot of the ctx.hostaddress array.
2632 append_addr(addrbuf, ctx.hostaddress[ReplaceEntry], sizeof(addrbuf));
2633 VLog(0, (" It will replace existing entry %d, %s,"
2634 " in the VLDB (new uuid):\n", ReplaceEntry, addrbuf));
2636 FindExtentBlock(&ctx, uuidp, 1, ReplaceEntry, &exp, &base);
2644 /* There is no entry for this server, must create a new mh entry as
2645 * well as use a new slot of the ctx.hostaddress array.
2647 VLog(0, (" It will create a new entry in the VLDB.\n"));
2648 code = FindExtentBlock(&ctx, uuidp, 1, -1, &exp, &base);
2656 /* Now we have a mh entry to fill in. Update the uuid, bump the
2657 * uniquifier, and fill in its IP addresses.
2660 afs_htonuuid(&tuuid);
2661 exp->ex_hostuuid = tuuid;
2662 exp->ex_uniquifier = htonl(ntohl(exp->ex_uniquifier) + 1);
2663 for (k = 0; k < cnt; k++) {
2664 exp->ex_addrs[k] = htonl(addrs[k]);
2666 for (; k < VL_MAXIPADDRS_PERMH; k++) {
2667 exp->ex_addrs[k] = 0;
2670 /* Write the new mh entry out */
2673 DOFFSET(ntohl(ctx.ex_addr[0]->ex_contaddrs[base]),
2674 (char *)ctx.ex_addr[base], (char *)exp), (char *)exp,
2680 /* Remove any common addresses from other mh entres. We know these entries
2681 * are being changed and not replaced so they are mh entries.
2684 for (i = 0; i < count; i++) {
2687 /* Skip the entry we replaced */
2688 if (willReplaceCnt && (WillChange[i] == ReplaceEntry))
2691 code = multiHomedExtentBase(&ctx, WillChange[i], &tex, &base);
2697 (" The following existing entries in the VLDB will be updated:\n"));
2699 for (addrbuf[0] = '\0', h = j = 0; j < VL_MAXIPADDRS_PERMH; j++) {
2700 if (tex->ex_addrs[j]) {
2702 strlcat(addrbuf, " ", sizeof(addrbuf));
2703 append_addr(addrbuf, ntohl(tex->ex_addrs[j]), sizeof(addrbuf));
2706 for (k = 0; k < cnt; k++) {
2707 if (ntohl(tex->ex_addrs[j]) == addrs[k])
2711 /* Not found, so we keep it */
2712 tex->ex_addrs[h] = tex->ex_addrs[j];
2716 for (j = h; j < VL_MAXIPADDRS_PERMH; j++) {
2717 tex->ex_addrs[j] = 0; /* zero rest of mh entry */
2719 VLog(0, (" entry %d: [%s]\n", WillChange[i], addrbuf));
2721 /* Write out the modified mh entry */
2722 tex->ex_uniquifier = htonl(ntohl(tex->ex_uniquifier) + 1);
2724 DOFFSET(ntohl(ctx.ex_addr[0]->ex_contaddrs[base]),
2725 (char *)ctx.ex_addr[base], (char *)tex);
2726 if (vlwrite(ctx.trans, doff, (char *)tex, sizeof(*tex))) {
2732 return (ubik_EndTrans(ctx.trans));
2735 countAbort(this_op);
2736 ubik_AbortTrans(ctx.trans);
2741 SVL_GetAddrsU(struct rx_call *rxcall,
2742 struct ListAddrByAttributes *attributes,
2744 afs_int32 *uniquifier,
2745 afs_int32 *nentries,
2748 int this_op = VLGETADDRSU;
2749 afs_int32 code, index;
2751 int nservers, i, j, base = 0;
2752 struct extentaddr *exp = 0;
2754 afs_uint32 *taddrp, taddr;
2755 char rxstr[AFS_RXINFO_LEN];
2757 countRequest(this_op);
2758 addrsp->bulkaddrs_len = *nentries = 0;
2759 addrsp->bulkaddrs_val = 0;
2760 VLog(5, ("GetAddrsU %s\n", rxinfo(rxstr, rxcall)));
2761 if ((code = Init_VLdbase(&ctx, LOCKREAD, this_op)))
2764 if (attributes->Mask & VLADDR_IPADDR) {
2765 if (attributes->Mask & (VLADDR_INDEX | VLADDR_UUID)) {
2769 /* Search for a server registered with the VLDB with this ip address. */
2770 for (index = 0; index <= MAXSERVERID; index++) {
2771 code = multiHomedExtent(&ctx, index, &exp);
2776 for (j = 0; j < VL_MAXIPADDRS_PERMH; j++) {
2777 if (exp->ex_addrs[j]
2778 && (ntohl(exp->ex_addrs[j]) == attributes->ipaddr)) {
2782 if (j < VL_MAXIPADDRS_PERMH)
2786 if (index > MAXSERVERID) {
2790 } else if (attributes->Mask & VLADDR_INDEX) {
2791 if (attributes->Mask & (VLADDR_IPADDR | VLADDR_UUID)) {
2795 /* VLADDR_INDEX index is one based */
2796 if (attributes->index < 1 || attributes->index > MAXSERVERID) {
2797 code = VL_INDEXERANGE;
2800 index = attributes->index - 1;
2801 code = multiHomedExtent(&ctx, index, &exp);
2806 } else if (attributes->Mask & VLADDR_UUID) {
2807 if (attributes->Mask & (VLADDR_IPADDR | VLADDR_INDEX)) {
2811 if (!ctx.ex_addr[0]) { /* mh servers probably aren't setup on this vldb */
2815 code = FindExtentBlock(&ctx, &attributes->uuid, 0, -1, &exp, &base);
2827 addrsp->bulkaddrs_val = taddrp =
2828 malloc(sizeof(afs_uint32) * (MAXSERVERID + 1));
2829 nservers = *nentries = addrsp->bulkaddrs_len = 0;
2834 tuuid = exp->ex_hostuuid;
2835 afs_ntohuuid(&tuuid);
2836 if (afs_uuid_is_nil(&tuuid)) {
2843 *uniquifier = ntohl(exp->ex_uniquifier);
2844 for (i = 0; i < VL_MAXIPADDRS_PERMH; i++) {
2845 if (exp->ex_addrs[i]) {
2846 taddr = ntohl(exp->ex_addrs[i]);
2847 /* Weed out duplicates */
2848 for (j = 0; j < nservers; j++) {
2849 if (taddrp[j] == taddr)
2852 if ((j == nservers) && (j <= MAXSERVERID)) {
2853 taddrp[nservers] = taddr;
2858 addrsp->bulkaddrs_len = *nentries = nservers;
2859 return (ubik_EndTrans(ctx.trans));
2862 countAbort(this_op);
2863 ubik_AbortTrans(ctx.trans);
2867 /* ============> End of Exported vldb RPC functions <============= */
2870 /* Routine that copies the given vldb entry to the output buffer, vldbentries. */
2872 put_attributeentry(struct vl_ctx *ctx,
2873 struct vldbentry **Vldbentry,
2874 struct vldbentry **VldbentryFirst,
2875 struct vldbentry **VldbentryLast,
2876 bulkentries *vldbentries,
2877 struct nvlentry *entry,
2878 afs_int32 *nentries,
2879 afs_int32 *alloccnt)
2885 if (*Vldbentry == *VldbentryLast) {
2887 return VL_SIZEEXCEEDED; /* no growing if smallMem defined */
2889 /* Allocate another set of memory; each time allocate twice as
2890 * many blocks as the last time. When we reach VLDBALLOCLIMIT,
2891 * then grow in increments of VLDBALLOCINCR.
2893 allo = (*alloccnt > VLDBALLOCLIMIT) ? VLDBALLOCINCR : *alloccnt;
2894 reall = realloc(*VldbentryFirst,
2895 (*alloccnt + allo) * sizeof(vldbentry));
2899 *VldbentryFirst = vldbentries->bulkentries_val = reall;
2900 *Vldbentry = *VldbentryFirst + *alloccnt;
2901 *VldbentryLast = *Vldbentry + allo;
2905 code = vlentry_to_vldbentry(ctx, entry, *Vldbentry);
2911 vldbentries->bulkentries_len++;
2916 put_nattributeentry(struct vl_ctx *ctx,
2917 struct nvldbentry **Vldbentry,
2918 struct nvldbentry **VldbentryFirst,
2919 struct nvldbentry **VldbentryLast,
2920 nbulkentries *vldbentries,
2921 struct nvlentry *entry,
2922 afs_int32 matchtype,
2923 afs_int32 matchindex,
2924 afs_int32 *nentries,
2925 afs_int32 *alloccnt)
2931 if (*Vldbentry == *VldbentryLast) {
2933 return VL_SIZEEXCEEDED; /* no growing if smallMem defined */
2935 /* Allocate another set of memory; each time allocate twice as
2936 * many blocks as the last time. When we reach VLDBALLOCLIMIT,
2937 * then grow in increments of VLDBALLOCINCR.
2939 allo = (*alloccnt > VLDBALLOCLIMIT) ? VLDBALLOCINCR : *alloccnt;
2940 reall = realloc(*VldbentryFirst,
2941 (*alloccnt + allo) * sizeof(nvldbentry));
2945 *VldbentryFirst = vldbentries->nbulkentries_val = reall;
2946 *Vldbentry = *VldbentryFirst + *alloccnt;
2947 *VldbentryLast = *Vldbentry + allo;
2950 code = vlentry_to_nvldbentry(ctx, entry, *Vldbentry);
2954 (*Vldbentry)->matchindex = (matchtype << 16) + matchindex;
2957 vldbentries->nbulkentries_len++;
2962 /* Common code to actually remove a vldb entry from the database. */
2964 RemoveEntry(struct vl_ctx *ctx, afs_int32 entryptr,
2965 struct nvlentry *tentry)
2969 if ((code = UnthreadVLentry(ctx, entryptr, tentry)))
2971 if ((code = FreeBlock(ctx, entryptr)))
2977 ReleaseEntry(struct nvlentry *tentry, afs_int32 releasetype)
2979 if (releasetype & LOCKREL_TIMESTAMP)
2980 tentry->LockTimestamp = 0;
2981 if (releasetype & LOCKREL_OPCODE)
2982 tentry->flags &= ~VLOP_ALLOPERS;
2983 if (releasetype & LOCKREL_AFSID)
2984 tentry->LockAfsId = 0;
2988 /* Verify that the incoming vldb entry is valid; multi type of error codes
2991 check_vldbentry(struct vldbentry *aentry)
2995 if (InvalidVolname(aentry->name))
2997 if (aentry->nServers <= 0 || aentry->nServers > OMAXNSERVERS)
2998 return VL_BADSERVER;
2999 for (i = 0; i < aentry->nServers; i++) {
3000 /* if (aentry->serverNumber[i] < 0 || aentry->serverNumber[i] > MAXSERVERID)
3001 return VL_BADSERVER; */
3002 if (aentry->serverPartition[i] < 0
3003 || aentry->serverPartition[i] > MAXPARTITIONID)
3004 return VL_BADPARTITION;
3005 if (aentry->serverFlags[i] < 0
3006 || aentry->serverFlags[i] > MAXSERVERFLAG)
3007 return VL_BADSERVERFLAG;
3013 check_nvldbentry(struct nvldbentry *aentry)
3017 if (InvalidVolname(aentry->name))
3019 if (aentry->nServers <= 0 || aentry->nServers > NMAXNSERVERS)
3020 return VL_BADSERVER;
3021 for (i = 0; i < aentry->nServers; i++) {
3022 /* if (aentry->serverNumber[i] < 0 || aentry->serverNumber[i] > MAXSERVERID)
3023 return VL_BADSERVER; */
3024 if (aentry->serverPartition[i] < 0
3025 || aentry->serverPartition[i] > MAXPARTITIONID)
3026 return VL_BADPARTITION;
3027 if (aentry->serverFlags[i] < 0
3028 || aentry->serverFlags[i] > MAXSERVERFLAG)
3029 return VL_BADSERVERFLAG;
3035 /* Convert from the external vldb entry representation to its internal
3036 (more compact) form. This call should not change the hash chains! */
3038 vldbentry_to_vlentry(struct vl_ctx *ctx,
3039 struct vldbentry *VldbEntry,
3040 struct nvlentry *VlEntry)
3044 if (strcmp(VlEntry->name, VldbEntry->name))
3045 strncpy(VlEntry->name, VldbEntry->name, sizeof(VlEntry->name));
3046 for (i = 0; i < VldbEntry->nServers; i++) {
3047 serverindex = IpAddrToRelAddr(ctx, VldbEntry->serverNumber[i], 1);
3048 if (serverindex == -1)
3049 return VL_BADSERVER;
3050 VlEntry->serverNumber[i] = serverindex;
3051 VlEntry->serverPartition[i] = VldbEntry->serverPartition[i];
3052 VlEntry->serverFlags[i] = VldbEntry->serverFlags[i];
3054 for (; i < OMAXNSERVERS; i++)
3055 VlEntry->serverNumber[i] = VlEntry->serverPartition[i] =
3056 VlEntry->serverFlags[i] = BADSERVERID;
3057 for (i = 0; i < MAXTYPES; i++)
3058 VlEntry->volumeId[i] = VldbEntry->volumeId[i];
3059 VlEntry->cloneId = VldbEntry->cloneId;
3060 VlEntry->flags = VldbEntry->flags;
3065 nvldbentry_to_vlentry(struct vl_ctx *ctx,
3066 struct nvldbentry *VldbEntry,
3067 struct nvlentry *VlEntry)
3071 if (strcmp(VlEntry->name, VldbEntry->name))
3072 strncpy(VlEntry->name, VldbEntry->name, sizeof(VlEntry->name));
3073 for (i = 0; i < VldbEntry->nServers; i++) {
3074 serverindex = IpAddrToRelAddr(ctx, VldbEntry->serverNumber[i], 1);
3075 if (serverindex == -1)
3076 return VL_BADSERVER;
3077 VlEntry->serverNumber[i] = serverindex;
3078 VlEntry->serverPartition[i] = VldbEntry->serverPartition[i];
3079 VlEntry->serverFlags[i] = VldbEntry->serverFlags[i];
3081 for (; i < NMAXNSERVERS; i++)
3082 VlEntry->serverNumber[i] = VlEntry->serverPartition[i] =
3083 VlEntry->serverFlags[i] = BADSERVERID;
3084 for (i = 0; i < MAXTYPES; i++)
3085 VlEntry->volumeId[i] = VldbEntry->volumeId[i];
3086 VlEntry->cloneId = VldbEntry->cloneId;
3087 VlEntry->flags = VldbEntry->flags;
3092 /* Update the vldb entry with the new fields as indicated by the value of
3093 * the Mask entry in the updateentry structure. All necessary validation
3094 * checks are performed.
3097 get_vldbupdateentry(struct vl_ctx *ctx,
3098 afs_int32 blockindex,
3099 struct VldbUpdateEntry *updateentry,
3100 struct nvlentry *VlEntry)
3102 int i, j, code, serverindex;
3103 afs_uint32 checkids[MAXTYPES];
3105 /* check if any specified new IDs are already present in the db. Do
3106 * this check before doing anything else, so we don't get a half-
3108 memset(&checkids, 0, sizeof(checkids));
3109 if (updateentry->Mask & VLUPDATE_RWID) {
3110 checkids[RWVOL] = updateentry->spares3; /* rw id */
3112 if (updateentry->Mask & VLUPDATE_READONLYID) {
3113 checkids[ROVOL] = updateentry->ReadOnlyId;
3115 if (updateentry->Mask & VLUPDATE_BACKUPID) {
3116 checkids[BACKVOL] = updateentry->BackupId;
3119 if (EntryIDExists(ctx, checkids, MAXTYPES, &code)) {
3125 if (updateentry->Mask & VLUPDATE_VOLUMENAME) {
3126 struct nvlentry tentry;
3128 if (InvalidVolname(updateentry->name))
3131 if (FindByName(ctx, updateentry->name, &tentry, &code)) {
3132 return VL_NAMEEXIST;
3137 if ((code = UnhashVolname(ctx, blockindex, VlEntry)))
3139 strncpy(VlEntry->name, updateentry->name, sizeof(VlEntry->name));
3140 HashVolname(ctx, blockindex, VlEntry);
3143 if (updateentry->Mask & VLUPDATE_VOLNAMEHASH) {
3144 if ((code = UnhashVolname(ctx, blockindex, VlEntry))) {
3145 if (code != VL_NOENT)
3148 HashVolname(ctx, blockindex, VlEntry);
3151 if (updateentry->Mask & VLUPDATE_FLAGS) {
3152 VlEntry->flags = updateentry->flags;
3154 if (updateentry->Mask & VLUPDATE_CLONEID) {
3155 VlEntry->cloneId = updateentry->cloneId;
3157 if (updateentry->Mask & VLUPDATE_RWID) {
3158 if ((code = UnhashVolid(ctx, RWVOL, blockindex, VlEntry))) {
3159 if (code != VL_NOENT)
3162 VlEntry->volumeId[RWVOL] = updateentry->spares3; /* rw id */
3163 if ((code = HashVolid(ctx, RWVOL, blockindex, VlEntry)))
3166 if (updateentry->Mask & VLUPDATE_READONLYID) {
3167 if ((code = UnhashVolid(ctx, ROVOL, blockindex, VlEntry))) {
3168 if (code != VL_NOENT)
3171 VlEntry->volumeId[ROVOL] = updateentry->ReadOnlyId;
3172 if ((code = HashVolid(ctx, ROVOL, blockindex, VlEntry)))
3175 if (updateentry->Mask & VLUPDATE_BACKUPID) {
3176 if ((code = UnhashVolid(ctx, BACKVOL, blockindex, VlEntry))) {
3177 if (code != VL_NOENT)
3180 VlEntry->volumeId[BACKVOL] = updateentry->BackupId;
3181 if ((code = HashVolid(ctx, BACKVOL, blockindex, VlEntry)))
3184 if (updateentry->Mask & VLUPDATE_REPSITES) {
3185 if (updateentry->nModifiedRepsites <= 0
3186 || updateentry->nModifiedRepsites > OMAXNSERVERS)
3187 return VL_BADSERVER;
3188 for (i = 0; i < updateentry->nModifiedRepsites; i++) {
3189 /* if (updateentry->RepsitesTargetServer[i] < 0 || updateentry->RepsitesTargetServer[i] > MAXSERVERID)
3190 return VL_BADSERVER; */
3191 if (updateentry->RepsitesTargetPart[i] < 0
3192 || updateentry->RepsitesTargetPart[i] > MAXPARTITIONID)
3193 return VL_BADPARTITION;
3194 if (updateentry->RepsitesMask[i] & VLUPDATE_REPS_DELETE) {
3196 repsite_exists(VlEntry,
3197 IpAddrToRelAddr(ctx, updateentry->
3198 RepsitesTargetServer[i],
3200 updateentry->RepsitesTargetPart[i])) !=
3202 repsite_compress(VlEntry, j);
3204 return VL_NOREPSERVER;
3206 if (updateentry->RepsitesMask[i] & VLUPDATE_REPS_ADD) {
3207 /* if (updateentry->RepsitesNewServer[i] < 0 || updateentry->RepsitesNewServer[i] > MAXSERVERID)
3208 return VL_BADSERVER; */
3209 if (updateentry->RepsitesNewPart[i] < 0
3210 || updateentry->RepsitesNewPart[i] > MAXPARTITIONID)
3211 return VL_BADPARTITION;
3214 IpAddrToRelAddr(ctx, updateentry->RepsitesNewServer[i], 1),
3215 updateentry->RepsitesNewPart[i]) != -1)
3216 return VL_DUPREPSERVER;
3218 VlEntry->serverNumber[j] != BADSERVERID
3219 && j < OMAXNSERVERS; j++);
3220 if (j >= OMAXNSERVERS)
3223 IpAddrToRelAddr(ctx, updateentry->RepsitesNewServer[i],
3225 return VL_BADSERVER;
3226 VlEntry->serverNumber[j] = serverindex;
3227 VlEntry->serverPartition[j] = updateentry->RepsitesNewPart[i];
3228 if (updateentry->RepsitesNewFlags[i] < 0
3229 || updateentry->RepsitesNewFlags[i] > MAXSERVERFLAG)
3230 return VL_BADSERVERFLAG;
3231 VlEntry->serverFlags[j] = updateentry->RepsitesNewFlags[i];
3233 if (updateentry->RepsitesMask[i] & VLUPDATE_REPS_MODSERV) {
3234 /*n if (updateentry->RepsitesNewServer[i] < 0 || updateentry->RepsitesNewServer[i] > MAXSERVERID)
3235 return VL_BADSERVER; */
3237 repsite_exists(VlEntry,
3238 IpAddrToRelAddr(ctx, updateentry->
3239 RepsitesTargetServer[i],
3241 updateentry->RepsitesTargetPart[i])) !=
3243 VlEntry->serverNumber[j] =
3244 IpAddrToRelAddr(ctx, updateentry->RepsitesNewServer[i],
3247 return VL_NOREPSERVER;
3249 if (updateentry->RepsitesMask[i] & VLUPDATE_REPS_MODPART) {
3250 if (updateentry->RepsitesNewPart[i] < 0
3251 || updateentry->RepsitesNewPart[i] > MAXPARTITIONID)
3252 return VL_BADPARTITION;
3254 repsite_exists(VlEntry,
3255 IpAddrToRelAddr(ctx, updateentry->
3256 RepsitesTargetServer[i],
3258 updateentry->RepsitesTargetPart[i])) !=
3260 VlEntry->serverPartition[j] =
3261 updateentry->RepsitesNewPart[i];
3263 return VL_NOREPSERVER;
3265 if (updateentry->RepsitesMask[i] & VLUPDATE_REPS_MODFLAG) {
3267 repsite_exists(VlEntry,
3268 IpAddrToRelAddr(ctx, updateentry->
3269 RepsitesTargetServer[i],
3271 updateentry->RepsitesTargetPart[i])) !=
3273 if (updateentry->RepsitesNewFlags[i] < 0
3274 || updateentry->RepsitesNewFlags[i] > MAXSERVERFLAG)
3275 return VL_BADSERVERFLAG;
3276 VlEntry->serverFlags[j] =
3277 updateentry->RepsitesNewFlags[i];
3279 return VL_NOREPSERVER;
3287 /* Check if the specified [server,partition] entry is found in the vldb
3288 * entry's repsite table; it's offset in the table is returned, if it's
3291 repsite_exists(struct nvlentry *VlEntry, int server, int partition)
3295 for (i = 0; VlEntry->serverNumber[i] != BADSERVERID && i < OMAXNSERVERS;
3297 if ((VlEntry->serverNumber[i] == server)
3298 && (VlEntry->serverPartition[i] == partition))
3306 /* Repsite table compression: used when deleting a repsite entry so that
3307 * all active repsite entries are on the top of the table. */
3309 repsite_compress(struct nvlentry *VlEntry, int offset)
3311 int repsite_offset = offset;
3313 VlEntry->serverNumber[repsite_offset] != BADSERVERID
3314 && repsite_offset < OMAXNSERVERS - 1; repsite_offset++) {
3315 VlEntry->serverNumber[repsite_offset] =
3316 VlEntry->serverNumber[repsite_offset + 1];
3317 VlEntry->serverPartition[repsite_offset] =
3318 VlEntry->serverPartition[repsite_offset + 1];
3319 VlEntry->serverFlags[repsite_offset] =
3320 VlEntry->serverFlags[repsite_offset + 1];
3322 VlEntry->serverNumber[repsite_offset] = BADSERVERID;
3326 /* Convert from the internal (compacted) vldb entry to the external
3327 * representation used by the interface. */
3329 vlentry_to_vldbentry(struct vl_ctx *ctx, struct nvlentry *VlEntry,
3330 struct vldbentry *VldbEntry)
3333 struct extentaddr *exp;
3335 memset(VldbEntry, 0, sizeof(struct vldbentry));
3336 strncpy(VldbEntry->name, VlEntry->name, sizeof(VldbEntry->name));
3337 for (i = 0; i < OMAXNSERVERS; i++) {
3338 if (VlEntry->serverNumber[i] == BADSERVERID)
3340 code = multiHomedExtent(ctx, VlEntry->serverNumber[i], &exp);
3344 /* For now return the first ip address back */
3345 for (j = 0; j < VL_MAXIPADDRS_PERMH; j++) {
3346 if (exp->ex_addrs[j]) {
3347 VldbEntry->serverNumber[i] = ntohl(exp->ex_addrs[j]);
3352 VldbEntry->serverNumber[i] =
3353 ctx->hostaddress[VlEntry->serverNumber[i]];
3354 VldbEntry->serverPartition[i] = VlEntry->serverPartition[i];
3355 VldbEntry->serverFlags[i] = VlEntry->serverFlags[i];
3357 VldbEntry->nServers = i;
3358 for (i = 0; i < MAXTYPES; i++)
3359 VldbEntry->volumeId[i] = VlEntry->volumeId[i];
3360 VldbEntry->cloneId = VlEntry->cloneId;
3361 VldbEntry->flags = VlEntry->flags;
3367 /* Convert from the internal (compacted) vldb entry to the external
3368 * representation used by the interface. */
3370 vlentry_to_nvldbentry(struct vl_ctx *ctx, struct nvlentry *VlEntry,
3371 struct nvldbentry *VldbEntry)
3374 struct extentaddr *exp;
3376 memset(VldbEntry, 0, sizeof(struct nvldbentry));
3377 strncpy(VldbEntry->name, VlEntry->name, sizeof(VldbEntry->name));
3378 for (i = 0; i < NMAXNSERVERS; i++) {
3379 if (VlEntry->serverNumber[i] == BADSERVERID)
3381 code = multiHomedExtent(ctx, VlEntry->serverNumber[i], &exp);
3386 /* For now return the first ip address back */
3387 for (j = 0; j < VL_MAXIPADDRS_PERMH; j++) {
3388 if (exp->ex_addrs[j]) {
3389 VldbEntry->serverNumber[i] = ntohl(exp->ex_addrs[j]);
3394 VldbEntry->serverNumber[i] =
3395 ctx->hostaddress[VlEntry->serverNumber[i]];
3396 VldbEntry->serverPartition[i] = VlEntry->serverPartition[i];
3397 VldbEntry->serverFlags[i] = VlEntry->serverFlags[i];
3399 VldbEntry->nServers = i;
3400 for (i = 0; i < MAXTYPES; i++)
3401 VldbEntry->volumeId[i] = VlEntry->volumeId[i];
3402 VldbEntry->cloneId = VlEntry->cloneId;
3403 VldbEntry->flags = VlEntry->flags;
3409 vlentry_to_uvldbentry(struct vl_ctx *ctx, struct nvlentry *VlEntry,
3410 struct uvldbentry *VldbEntry)
3413 struct extentaddr *exp;
3415 memset(VldbEntry, 0, sizeof(struct uvldbentry));
3416 strncpy(VldbEntry->name, VlEntry->name, sizeof(VldbEntry->name));
3417 for (i = 0; i < NMAXNSERVERS; i++) {
3418 if (VlEntry->serverNumber[i] == BADSERVERID)
3420 VldbEntry->serverFlags[i] = VlEntry->serverFlags[i];
3421 VldbEntry->serverUnique[i] = 0;
3422 code = multiHomedExtent(ctx, VlEntry->serverNumber[i], &exp);
3429 tuuid = exp->ex_hostuuid;
3430 afs_ntohuuid(&tuuid);
3431 VldbEntry->serverFlags[i] |= VLSF_UUID;
3432 VldbEntry->serverNumber[i] = tuuid;
3433 VldbEntry->serverUnique[i] = ntohl(exp->ex_uniquifier);
3435 VldbEntry->serverNumber[i].time_low =
3436 ctx->hostaddress[VlEntry->serverNumber[i]];
3438 VldbEntry->serverPartition[i] = VlEntry->serverPartition[i];
3441 VldbEntry->nServers = i;
3442 for (i = 0; i < MAXTYPES; i++)
3443 VldbEntry->volumeId[i] = VlEntry->volumeId[i];
3444 VldbEntry->cloneId = VlEntry->cloneId;
3445 VldbEntry->flags = VlEntry->flags;
3450 #define LEGALCHARS ".ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"
3453 /* Verify that the volname is a valid volume name. */
3455 InvalidVolname(char *volname)
3461 slen = strlen(volname);
3462 if (slen >= VL_MAXNAMELEN)
3464 return (slen != strspn(volname, map));
3468 /* Verify that the given volume type is valid. */
3470 InvalidVoltype(afs_int32 voltype)
3472 if (voltype != RWVOL && voltype != ROVOL && voltype != BACKVOL)
3479 InvalidOperation(afs_int32 voloper)
3481 if (voloper != VLOP_MOVE && voloper != VLOP_RELEASE
3482 && voloper != VLOP_BACKUP && voloper != VLOP_DELETE
3483 && voloper != VLOP_DUMP)
3489 InvalidReleasetype(afs_int32 releasetype)
3491 if ((releasetype & LOCKREL_TIMESTAMP) || (releasetype & LOCKREL_OPCODE)
3492 || (releasetype & LOCKREL_AFSID))
3498 IpAddrToRelAddr(struct vl_ctx *ctx, afs_uint32 ipaddr, int create)
3502 struct extentaddr *exp;
3504 for (i = 0; i <= MAXSERVERID; i++) {
3505 if (ctx->hostaddress[i] == ipaddr)
3507 code = multiHomedExtent(ctx, i, &exp);
3511 for (j = 0; j < VL_MAXIPADDRS_PERMH; j++) {
3512 if (exp->ex_addrs[j] && (ntohl(exp->ex_addrs[j]) == ipaddr)) {
3519 /* allocate the new server a server id pronto */
3521 for (i = 0; i <= MAXSERVERID; i++) {
3522 if (ctx->cheader->IpMappedAddr[i] == 0) {
3523 ctx->cheader->IpMappedAddr[i] = htonl(ipaddr);
3526 DOFFSET(0, ctx->cheader, &ctx->cheader->IpMappedAddr[i]),
3527 (char *)&ctx->cheader->IpMappedAddr[i],
3529 ctx->hostaddress[i] = ipaddr;
3540 ChangeIPAddr(struct vl_ctx *ctx, afs_uint32 ipaddr1, afs_uint32 ipaddr2)
3544 struct extentaddr *exp = NULL;
3548 afs_int32 blockindex, count;
3550 struct nvlentry tentry;
3551 int ipaddr1_id = -1, ipaddr2_id = -1;
3555 /* Don't let addr change to 255.*.*.* : Causes internal error below */
3556 if ((ipaddr2 & 0xff000000) == 0xff000000)
3557 return (VL_BADSERVER);
3559 /* If we are removing an address, ip1 will be -1 and ip2 will be
3560 * the original address. This prevents an older revision vlserver
3561 * from removing the IP address (won't find server 0xfffffff in
3562 * the VLDB). An older revision vlserver does not have the check
3563 * to see if any volumes exist on the server being removed.
3565 if (ipaddr1 == 0xffffffff) {
3570 for (i = 0; i <= MAXSERVERID; i++) {
3571 struct extentaddr *texp = NULL;
3574 code = multiHomedExtentBase(ctx, i, &texp, &tbase);
3579 for (mhidx = 0; mhidx < VL_MAXIPADDRS_PERMH; mhidx++) {
3580 if (!texp->ex_addrs[mhidx])
3582 if (ntohl(texp->ex_addrs[mhidx]) == ipaddr1) {
3587 if (ipaddr2 != 0 && ntohl(texp->ex_addrs[mhidx]) == ipaddr2) {
3592 if (ctx->hostaddress[i] == ipaddr1) {
3597 if (ipaddr2 != 0 && ctx->hostaddress[i] == ipaddr2) {
3602 if (ipaddr1_id >= 0 && (ipaddr2 == 0 || ipaddr2_id >= 0)) {
3603 /* we've either found both IPs already in the VLDB, or we found
3604 * ipaddr1, and we're not going to find ipaddr2 because it's 0 */
3609 if (ipaddr1_id < 0) {
3610 return VL_NOENT; /* not found */
3613 if (ipaddr2_id >= 0 && ipaddr2_id != ipaddr1_id) {
3614 char buf1[16], buf2[16];
3615 VLog(0, ("Cannot change IP address from %s to %s because the latter "
3616 "is in use by server id %d\n",
3617 afs_inet_ntoa_r(htonl(ipaddr1), buf1),
3618 afs_inet_ntoa_r(htonl(ipaddr2), buf2),
3620 return VL_MULTIPADDR;
3623 /* If we are removing a server entry, a volume cannot
3624 * exist on the server. If one does, don't remove the
3625 * server entry: return error "volume entry exists".
3628 for (blockindex = NextEntry(ctx, 0, &tentry, &count); blockindex;
3629 blockindex = NextEntry(ctx, blockindex, &tentry, &count)) {
3630 if (++pollcount > 50) {
3631 #ifndef AFS_PTHREAD_ENV
3636 for (j = 0; j < NMAXNSERVERS; j++) {
3637 if (tentry.serverNumber[j] == BADSERVERID)
3639 if (tentry.serverNumber[j] == ipaddr1_id) {
3645 /* Do not allow changing addresses in multi-homed entries.
3646 Older versions of this RPC would silently "downgrade" mh entries
3647 to single-homed entries and orphan the mh enties. */
3649 append_addr(addrbuf1, ipaddr1, sizeof(addrbuf1));
3650 VLog(0, ("Refusing to change address %s in multi-homed entry; "
3651 "use RegisterAddrs instead.\n", addrbuf1));
3652 return VL_NOENT; /* single-homed entry not found */
3655 /* Log a message saying we are changing/removing an IP address */
3657 ("The following IP address is being %s:\n",
3658 (ipaddr2 ? "changed" : "removed")));
3659 addrbuf1[0] = addrbuf2[0] = '\0';
3661 for (mhidx = 0; mhidx < VL_MAXIPADDRS_PERMH; mhidx++) {
3662 if (!exp->ex_addrs[mhidx])
3665 strlcat(addrbuf1, " ", sizeof(addrbuf1));
3666 append_addr(addrbuf1, ntohl(exp->ex_addrs[mhidx]), sizeof(addrbuf1));
3669 append_addr(addrbuf1, ipaddr1, sizeof(addrbuf1));
3672 append_addr(addrbuf2, ipaddr2, sizeof(addrbuf2));
3674 VLog(0, (" entry %d: [%s] -> [%s]\n", ipaddr1_id, addrbuf1, addrbuf2));
3676 /* Change the registered uuuid addresses */
3677 if (exp && base != -1) {
3678 memset(&tuuid, 0, sizeof(afsUUID));
3679 afs_htonuuid(&tuuid);
3680 exp->ex_hostuuid = tuuid;
3683 DOFFSET(ntohl(ctx->ex_addr[0]->ex_contaddrs[base]),
3684 (char *)ctx->ex_addr[base], (char *)exp),
3685 (char *)&tuuid, sizeof(tuuid));
3690 /* Now change the host address entry */
3691 ctx->cheader->IpMappedAddr[ipaddr1_id] = htonl(ipaddr2);
3693 vlwrite(ctx->trans, DOFFSET(0, ctx->cheader, &ctx->cheader->IpMappedAddr[ipaddr1_id]),
3695 &ctx->cheader->IpMappedAddr[ipaddr1_id], sizeof(afs_int32));
3696 ctx->hostaddress[ipaddr1_id] = ipaddr2;
3703 /* see if the vlserver is back yet */
3705 SVL_ProbeServer(struct rx_call *rxcall)