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>
22 #include <sys/types.h>
26 #include <netinet/in.h>
35 #include <afs/voldefs.h>
38 #include <afs/vlserver.h>
40 #include <afs/afsint.h>
45 /* Finds an index in VLDB entry that matches the volume type, server, and partition.
46 * If type is zero, will match first index of ANY type (RW, BK, or RO).
47 * If server is zero, will match first index of ANY server and partition
48 * Zero is a valid partition field.
50 int FindIndex(entry, server, part, type)
51 struct nvldbentry *entry;
52 afs_int32 server, part, type;
57 for (e=0; (e < entry->nServers) && !error; e++) {
58 if (!type || (entry->serverFlags[e] & type)) {
59 if ( (!server || (entry->serverPartition[e] == part)) &&
60 (!server || VLDB_IsSameAddrs(entry->serverNumber[e],server,&error)) )
63 return -1; /* quit when we are looking for RW entry (there's only 1) */
69 "Failed to get info about server's %d address(es) from vlserver (err=%d)\n",
70 entry->serverNumber[e], error);
74 if (e >= entry->nServers)
75 return -1; /* Didn't find it */
77 return e; /* return the index */
80 /* Changes the rw site only */
82 SetAValue (entry, oserver, opart, nserver, npart, type)
83 struct nvldbentry *entry;
84 afs_int32 oserver, opart, nserver, npart, type;
89 e = FindIndex(entry, oserver, opart, type);
91 return; /* If didn't find it, just return */
93 entry->serverNumber[e] = nserver;
94 entry->serverPartition[e] = npart;
96 /* Now move rest of entries up */
97 if ((nserver == 0L) && (npart == 0L)) {
98 for (e++; e<entry->nServers; e++) {
99 entry->serverNumber[e-1] = entry->serverNumber[e];
100 entry->serverPartition[e-1] = entry->serverPartition[e];
101 entry->serverFlags[e-1] = entry->serverFlags[e];
106 /* Changes the RW site only */
107 Lp_SetRWValue (entry, oserver, opart, nserver, npart)
108 struct nvldbentry *entry;
109 afs_int32 oserver, opart, nserver, npart;
111 SetAValue (entry, oserver, opart, nserver, npart, ITSRWVOL);
114 /* 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>*/
155 /*add <elem> in front of queue <ahead> */
162 if(ahead->count == 0) {
175 Lp_QScan(ahead,id,success, elem)
177 struct aqueue **elem;
180 { struct aqueue *cptr;
183 while(cptr != NULL) {
184 if(cptr->ids[RWVOL] == id) {
195 /*return the element in the beginning of the queue <ahead>, free
196 *the space used by that element . <success> indicates if enumeration was ok*/
197 Lp_QEnumerate(ahead,success, elem)
205 if(ahead->count > 0) {/*more elements left */
208 ahead->next = ahead->next->next;
209 strncpy(elem->name,temp->name,VOLSER_OLDMAXVOLNAME);
210 for(i= 0; i < 3; i++){
211 elem->ids[i] = temp->ids[i];
212 elem->copyDate[i] = temp->copyDate[i];
213 elem->isValid[i] = temp->isValid[i];
219 else /*queue is empty*/
227 struct aqueue *old, *new;
231 count = ahead->count;
232 printf("traversing the internal queue, which groups all the related volumes on a per partition basis\n");
234 printf("---------------------------\n");
235 printf("%s RW-Id %u",old->name,old->ids[RWVOL]);
236 if(old->isValid[RWVOL])
238 else printf(" invalid ");
239 printf("RO-Id %u",old->ids[ROVOL]);
240 if(old->isValid[ROVOL])
242 else printf(" invalid ");
243 printf("BACKUP-Id %u",old->ids[BACKVOL]);
244 if(old->isValid[BACKVOL])
246 else printf(" invalid ");
248 printf("---------------------------\n");
250 if(count != 1) new = new->next;