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>
23 #include <sys/types.h>
27 #include <netinet/in.h>
30 #include <afs/voldefs.h>
33 #include <afs/vlserver.h>
35 #include <afs/afsint.h>
40 /* Finds an index in VLDB entry that matches the volume type, server, and partition.
41 * If type is zero, will match first index of ANY type (RW, BK, or RO).
42 * If server is zero, will match first index of ANY server and partition
43 * Zero is a valid partition field.
46 FindIndex(entry, server, part, type)
47 struct nvldbentry *entry;
48 afs_int32 server, part, type;
53 for (e = 0; (e < entry->nServers) && !error; e++) {
54 if (!type || (entry->serverFlags[e] & type)) {
55 if ((!server || (entry->serverPartition[e] == part))
57 || VLDB_IsSameAddrs(entry->serverNumber[e], server,
61 return -1; /* quit when we are looking for RW entry (there's only 1) */
67 "Failed to get info about server's %d address(es) from vlserver (err=%d)\n",
68 entry->serverNumber[e], error);
72 if (e >= entry->nServers)
73 return -1; /* Didn't find it */
75 return e; /* return the index */
78 /* Changes the rw site only */
80 SetAValue(entry, oserver, opart, nserver, npart, type)
81 struct nvldbentry *entry;
82 afs_int32 oserver, opart, nserver, npart, type;
87 e = FindIndex(entry, oserver, opart, type);
89 return; /* If didn't find it, just return */
91 entry->serverNumber[e] = nserver;
92 entry->serverPartition[e] = npart;
94 /* Now move rest of entries up */
95 if ((nserver == 0L) && (npart == 0L)) {
96 for (e++; e < entry->nServers; e++) {
97 entry->serverNumber[e - 1] = entry->serverNumber[e];
98 entry->serverPartition[e - 1] = entry->serverPartition[e];
99 entry->serverFlags[e - 1] = entry->serverFlags[e];
104 /* Changes the RW site only */
106 Lp_SetRWValue(entry, oserver, opart, nserver, npart)
107 struct nvldbentry *entry;
108 afs_int32 oserver, opart, nserver, npart;
110 SetAValue(entry, oserver, opart, nserver, npart, ITSRWVOL);
113 /* Changes the RO site only */
115 Lp_SetROValue(entry, oserver, opart, nserver, npart)
116 struct nvldbentry *entry;
117 afs_int32 oserver, opart, nserver, npart;
119 SetAValue(entry, oserver, opart, nserver, npart, ITSROVOL);
122 /* Returns success if this server and partition matches the RW entry */
123 Lp_Match(server, part, entry)
124 afs_int32 server, part;
125 struct nvldbentry *entry;
127 if (FindIndex(entry, server, part, ITSRWVOL) == -1)
132 /* Return the index of the RO entry (plus 1) if it exists, else return 0 */
133 Lp_ROMatch(server, part, entry)
134 afs_int32 server, part;
135 struct nvldbentry *entry;
137 return (FindIndex(entry, server, part, ITSROVOL) + 1);
140 /* Return the index of the RW entry if it exists, else return -1 */
142 struct nvldbentry *entry;
144 return (FindIndex(entry, 0, 0, ITSRWVOL));
147 /*initialize queue pointed by <ahead>*/
156 /*add <elem> in front of queue <ahead> */
164 if (ahead->count == 0) {
176 Lp_QScan(ahead, id, success, elem)
178 struct aqueue **elem;
185 while (cptr != NULL) {
186 if (cptr->ids[RWVOL] == id) {
197 /*return the element in the beginning of the queue <ahead>, free
198 *the space used by that element . <success> indicates if enumeration was ok*/
200 Lp_QEnumerate(ahead, success, elem)
208 if (ahead->count > 0) { /*more elements left */
211 ahead->next = ahead->next->next;
212 strncpy(elem->name, temp->name, VOLSER_OLDMAXVOLNAME);
213 for (i = 0; i < 3; i++) {
214 elem->ids[i] = temp->ids[i];
215 elem->copyDate[i] = temp->copyDate[i];
216 elem->isValid[i] = temp->isValid[i];
221 } else /*queue is empty */
230 struct aqueue *old, *new;
234 count = ahead->count;
236 ("traversing the internal queue, which groups all the related volumes on a per partition basis\n");
238 printf("---------------------------\n");
239 printf("%s RW-Id %lu", old->name, (unsigned long)old->ids[RWVOL]);
240 if (old->isValid[RWVOL])
244 printf("RO-Id %lu", (unsigned long)old->ids[ROVOL]);
245 if (old->isValid[ROVOL])
249 printf("BACKUP-Id %lu", (unsigned long)old->ids[BACKVOL]);
250 if (old->isValid[BACKVOL])
255 printf("---------------------------\n");