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>
36 #include <afs/voldefs.h>
39 #include <afs/vlserver.h>
41 #include <afs/afsint.h>
46 /* Finds an index in VLDB entry that matches the volume type, server, and partition.
47 * If type is zero, will match first index of ANY type (RW, BK, or RO).
48 * If server is zero, will match first index of ANY server and partition
49 * Zero is a valid partition field.
52 FindIndex(entry, server, part, type)
53 struct nvldbentry *entry;
54 afs_int32 server, part, type;
59 for (e = 0; (e < entry->nServers) && !error; e++) {
60 if (!type || (entry->serverFlags[e] & type)) {
61 if ((!server || (entry->serverPartition[e] == part))
63 || VLDB_IsSameAddrs(entry->serverNumber[e], server,
67 return -1; /* quit when we are looking for RW entry (there's only 1) */
73 "Failed to get info about server's %d address(es) from vlserver (err=%d)\n",
74 entry->serverNumber[e], error);
78 if (e >= entry->nServers)
79 return -1; /* Didn't find it */
81 return e; /* return the index */
84 /* Changes the rw site only */
86 SetAValue(entry, oserver, opart, nserver, npart, type)
87 struct nvldbentry *entry;
88 afs_int32 oserver, opart, nserver, npart, type;
93 e = FindIndex(entry, oserver, opart, type);
95 return; /* If didn't find it, just return */
97 entry->serverNumber[e] = nserver;
98 entry->serverPartition[e] = npart;
100 /* Now move rest of entries up */
101 if ((nserver == 0L) && (npart == 0L)) {
102 for (e++; e < entry->nServers; e++) {
103 entry->serverNumber[e - 1] = entry->serverNumber[e];
104 entry->serverPartition[e - 1] = entry->serverPartition[e];
105 entry->serverFlags[e - 1] = entry->serverFlags[e];
110 /* Changes the RW site only */
111 Lp_SetRWValue(entry, oserver, opart, nserver, npart)
112 struct nvldbentry *entry;
113 afs_int32 oserver, opart, nserver, npart;
115 SetAValue(entry, oserver, opart, nserver, npart, ITSRWVOL);
118 /* Changes the RO site only */
119 Lp_SetROValue(entry, oserver, opart, nserver, npart)
120 struct nvldbentry *entry;
121 afs_int32 oserver, opart, nserver, npart;
123 SetAValue(entry, oserver, opart, nserver, npart, ITSROVOL);
126 /* Returns success if this server and partition matches the RW entry */
127 Lp_Match(server, part, entry)
128 afs_int32 server, part;
129 struct nvldbentry *entry;
131 if (FindIndex(entry, server, part, ITSRWVOL) == -1)
136 /* Return the index of the RO entry (plus 1) if it exists, else return 0 */
137 Lp_ROMatch(server, part, entry)
138 afs_int32 server, part;
139 struct nvldbentry *entry;
141 return (FindIndex(entry, server, part, ITSROVOL) + 1);
144 /* Return the index of the RW entry if it exists, else return -1 */
146 struct nvldbentry *entry;
148 return (FindIndex(entry, 0, 0, ITSRWVOL));
151 /*initialize queue pointed by <ahead>*/
159 /*add <elem> in front of queue <ahead> */
166 if (ahead->count == 0) {
178 Lp_QScan(ahead, id, success, elem)
180 struct aqueue **elem;
187 while (cptr != NULL) {
188 if (cptr->ids[RWVOL] == id) {
199 /*return the element in the beginning of the queue <ahead>, free
200 *the space used by that element . <success> indicates if enumeration was ok*/
201 Lp_QEnumerate(ahead, success, elem)
209 if (ahead->count > 0) { /*more elements left */
212 ahead->next = ahead->next->next;
213 strncpy(elem->name, temp->name, VOLSER_OLDMAXVOLNAME);
214 for (i = 0; i < 3; i++) {
215 elem->ids[i] = temp->ids[i];
216 elem->copyDate[i] = temp->copyDate[i];
217 elem->isValid[i] = temp->isValid[i];
222 } 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");