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
13 * Instituition: ITC, CMU
17 #include <afsconfig.h>
18 #include <afs/param.h>
21 #include <sys/types.h>
25 #include <netinet/in.h>
28 #include <afs/voldefs.h>
31 #include <afs/vlserver.h>
33 #include <afs/afsint.h>
38 #include "vsutils_prototypes.h"
39 #include "lockprocs_prototypes.h"
41 /* Finds an index in VLDB entry that matches the volume type, server, and partition.
42 * If type is zero, will match first index of ANY type (RW, BK, or RO).
43 * If server is zero, will match first index of ANY server and partition
44 * Zero is a valid partition field.
47 FindIndex(struct nvldbentry *entry, afs_int32 server, afs_int32 part, afs_int32 type)
52 for (e = 0; (e < entry->nServers) && !error; e++) {
53 if (!type || (entry->serverFlags[e] & type)) {
54 if ((!server || (entry->serverPartition[e] == part))
56 || VLDB_IsSameAddrs(entry->serverNumber[e], server,
60 return -1; /* quit when we are looking for RW entry (there's only 1) */
66 "Failed to get info about server's %d address(es) from vlserver (err=%d)\n",
67 entry->serverNumber[e], error);
71 if (e >= entry->nServers)
72 return -1; /* Didn't find it */
74 return e; /* return the index */
77 /* Changes the rw site only */
79 SetAValue(struct nvldbentry *entry, afs_int32 oserver, afs_int32 opart,
80 afs_int32 nserver, afs_int32 npart, afs_int32 type)
85 e = FindIndex(entry, oserver, opart, type);
87 return; /* If didn't find it, just return */
89 entry->serverNumber[e] = nserver;
90 entry->serverPartition[e] = npart;
92 /* Now move rest of entries up */
93 if ((nserver == 0L) && (npart == 0L)) {
94 for (e++; e < entry->nServers; e++) {
95 entry->serverNumber[e - 1] = entry->serverNumber[e];
96 entry->serverPartition[e - 1] = entry->serverPartition[e];
97 entry->serverFlags[e - 1] = entry->serverFlags[e];
102 /* Changes the RW site only */
104 Lp_SetRWValue(struct nvldbentry *entry, afs_int32 oserver, afs_int32 opart,
105 afs_int32 nserver, afs_int32 npart)
107 SetAValue(entry, oserver, opart, nserver, npart, ITSRWVOL);
110 /* Changes the RO site only */
112 Lp_SetROValue(struct nvldbentry *entry, afs_int32 oserver,
113 afs_int32 opart, afs_int32 nserver, afs_int32 npart)
115 SetAValue(entry, oserver, opart, nserver, npart, ITSROVOL);
118 /* Returns success if this server and partition matches the RW entry */
120 Lp_Match(afs_int32 server, afs_int32 part,
121 struct nvldbentry *entry)
123 if (FindIndex(entry, server, part, ITSRWVOL) == -1)
128 /* Return the index of the RO entry (plus 1) if it exists, else return 0 */
130 Lp_ROMatch(afs_int32 server, afs_int32 part, struct nvldbentry *entry)
132 return (FindIndex(entry, server, part, ITSROVOL) + 1);
135 /* Return the index of the RW entry if it exists, else return -1 */
137 Lp_GetRwIndex(struct nvldbentry *entry)
139 return (FindIndex(entry, 0, 0, ITSRWVOL));
142 /*initialize queue pointed by <ahead>*/
144 Lp_QInit(struct qHead *ahead)
150 /*add <elem> in front of queue <ahead> */
152 Lp_QAdd(struct qHead *ahead, struct aqueue *elem)
156 if (ahead->count == 0) {
169 Lp_QScan(struct qHead *ahead, afs_int32 id, int *success, struct aqueue **elem)
174 while (cptr != NULL) {
175 if (cptr->ids[RWVOL] == id) {
186 /*return the element in the beginning of the queue <ahead>, free
187 *the space used by that element . <success> indicates if enumeration was ok*/
189 Lp_QEnumerate(struct qHead *ahead, int *success, struct aqueue *elem)
194 if (ahead->count > 0) { /*more elements left */
197 ahead->next = ahead->next->next;
198 strncpy(elem->name, temp->name, VOLSER_OLDMAXVOLNAME);
199 for (i = 0; i < 3; i++) {
200 elem->ids[i] = temp->ids[i];
201 elem->copyDate[i] = temp->copyDate[i];
202 elem->isValid[i] = temp->isValid[i];
207 } else /*queue is empty */
212 Lp_QTraverse(struct qHead *ahead)
215 struct aqueue *old, *new;
219 count = ahead->count;
221 ("traversing the internal queue, which groups all the related volumes on a per partition basis\n");
223 printf("---------------------------\n");
224 printf("%s RW-Id %lu", old->name, (unsigned long)old->ids[RWVOL]);
225 if (old->isValid[RWVOL])
229 printf("RO-Id %lu", (unsigned long)old->ids[ROVOL]);
230 if (old->isValid[ROVOL])
234 printf("BACKUP-Id %lu", (unsigned long)old->ids[BACKVOL]);
235 if (old->isValid[BACKVOL])
240 printf("---------------------------\n");