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 */
105 Lp_SetRWValue(entry, oserver, opart, nserver, npart)
106 struct nvldbentry *entry;
107 afs_int32 oserver, opart, nserver, npart;
109 SetAValue(entry, oserver, opart, nserver, npart, ITSRWVOL);
112 /* Changes the RO site only */
113 Lp_SetROValue(entry, oserver, opart, nserver, npart)
114 struct nvldbentry *entry;
115 afs_int32 oserver, opart, nserver, npart;
117 SetAValue(entry, oserver, opart, nserver, npart, ITSROVOL);
120 /* Returns success if this server and partition matches the RW entry */
121 Lp_Match(server, part, entry)
122 afs_int32 server, part;
123 struct nvldbentry *entry;
125 if (FindIndex(entry, server, part, ITSRWVOL) == -1)
130 /* Return the index of the RO entry (plus 1) if it exists, else return 0 */
131 Lp_ROMatch(server, part, entry)
132 afs_int32 server, part;
133 struct nvldbentry *entry;
135 return (FindIndex(entry, server, part, ITSROVOL) + 1);
138 /* Return the index of the RW entry if it exists, else return -1 */
140 struct nvldbentry *entry;
142 return (FindIndex(entry, 0, 0, ITSRWVOL));
145 /*initialize queue pointed by <ahead>*/
153 /*add <elem> in front of queue <ahead> */
160 if (ahead->count == 0) {
172 Lp_QScan(ahead, id, success, elem)
174 struct aqueue **elem;
181 while (cptr != NULL) {
182 if (cptr->ids[RWVOL] == id) {
193 /*return the element in the beginning of the queue <ahead>, free
194 *the space used by that element . <success> indicates if enumeration was ok*/
195 Lp_QEnumerate(ahead, success, elem)
203 if (ahead->count > 0) { /*more elements left */
206 ahead->next = ahead->next->next;
207 strncpy(elem->name, temp->name, VOLSER_OLDMAXVOLNAME);
208 for (i = 0; i < 3; i++) {
209 elem->ids[i] = temp->ids[i];
210 elem->copyDate[i] = temp->copyDate[i];
211 elem->isValid[i] = temp->isValid[i];
216 } else /*queue is empty */
224 struct aqueue *old, *new;
228 count = ahead->count;
230 ("traversing the internal queue, which groups all the related volumes on a per partition basis\n");
232 printf("---------------------------\n");
233 printf("%s RW-Id %lu", old->name, (unsigned long)old->ids[RWVOL]);
234 if (old->isValid[RWVOL])
238 printf("RO-Id %lu", (unsigned long)old->ids[ROVOL]);
239 if (old->isValid[ROVOL])
243 printf("BACKUP-Id %lu", (unsigned long)old->ids[BACKVOL]);
244 if (old->isValid[BACKVOL])
249 printf("---------------------------\n");