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 <afs/param.h>
18 #include <sys/types.h>
22 #include <netinet/in.h>
24 #include <afs/voldefs.h>
27 #include <afs/vlserver.h>
29 #include <afs/afsint.h>
34 /* Finds an index in VLDB entry that matches the volume type, server, and partition.
35 * If type is zero, will match first index of ANY type (RW, BK, or RO).
36 * If server is zero, will match first index of ANY server and partition
37 * Zero is a valid partition field.
39 int FindIndex(entry, server, part, type)
40 struct nvldbentry *entry;
41 afs_int32 server, part, type;
46 for (e=0; (e < entry->nServers) && !error; e++) {
47 if (!type || (entry->serverFlags[e] & type)) {
48 if ( (!server || (entry->serverPartition[e] == part)) &&
49 (!server || VLDB_IsSameAddrs(entry->serverNumber[e],server,&error)) )
52 return -1; /* quit when we are looking for RW entry (there's only 1) */
58 "Failed to get info about server's %d address(es) from vlserver (err=%d)\n",
59 entry->serverNumber[e], error);
63 if (e >= entry->nServers)
64 return -1; /* Didn't find it */
66 return e; /* return the index */
69 /* Changes the rw site only */
70 SetAValue (entry, oserver, opart, nserver, npart, type)
71 struct nvldbentry *entry;
72 afs_int32 oserver, opart, nserver, npart, type;
77 e = FindIndex(entry, oserver, opart, type);
79 return; /* If didn't find it, just return */
81 entry->serverNumber[e] = nserver;
82 entry->serverPartition[e] = npart;
84 /* Now move rest of entries up */
85 if ((nserver == 0L) && (npart == 0L)) {
86 for (e++; e<entry->nServers; e++) {
87 entry->serverNumber[e-1] = entry->serverNumber[e];
88 entry->serverPartition[e-1] = entry->serverPartition[e];
89 entry->serverFlags[e-1] = entry->serverFlags[e];
94 /* Changes the RW site only */
95 Lp_SetRWValue (entry, oserver, opart, nserver, npart)
96 struct nvldbentry *entry;
97 afs_int32 oserver, opart, nserver, npart;
99 SetAValue (entry, oserver, opart, nserver, npart, ITSRWVOL);
102 /* Changes the RO site only */
103 Lp_SetROValue(entry, oserver, opart, nserver, npart)
104 struct nvldbentry *entry;
105 afs_int32 oserver, opart, nserver, npart;
107 SetAValue (entry, oserver, opart, nserver, npart, ITSROVOL);
110 /* Returns success if this server and partition matches the RW entry */
111 Lp_Match(server, part, entry)
112 afs_int32 server, part;
113 struct nvldbentry *entry;
115 if (FindIndex(entry, server, part, ITSRWVOL) == -1)
120 /* Return the index of the RO entry (plus 1) if it exists, else return 0 */
121 Lp_ROMatch(server, part, entry)
122 afs_int32 server, part;
123 struct nvldbentry *entry;
125 return (FindIndex(entry,server,part,ITSROVOL) + 1);
128 /* Return the index of the RW entry if it exists, else return -1 */
130 struct nvldbentry *entry;
132 return (FindIndex(entry,0,0,ITSRWVOL));
135 /*initialize queue pointed by <ahead>*/
140 ahead->next = (struct aqueue *)0;
143 /*add <elem> in front of queue <ahead> */
150 if(ahead->count == 0) {
153 elem->next = (struct aqueue *)0;
163 Lp_QScan(ahead,id,success, elem)
165 struct aqueue **elem;
168 { struct aqueue *cptr;
171 while(cptr != (struct aqueue *)0) {
172 if(cptr->ids[RWVOL] == id) {
183 /*return the element in the beginning of the queue <ahead>, free
184 *the space used by that element . <success> indicates if enumeration was ok*/
185 Lp_QEnumerate(ahead,success, elem)
193 if(ahead->count > 0) {/*more elements left */
196 ahead->next = ahead->next->next;
197 strncpy(elem->name,temp->name,VOLSER_OLDMAXVOLNAME);
198 for(i= 0; i < 3; i++){
199 elem->ids[i] = temp->ids[i];
200 elem->copyDate[i] = temp->copyDate[i];
201 elem->isValid[i] = temp->isValid[i];
203 elem->next = (struct aqueue *)0;
207 else /*queue is empty*/
215 struct aqueue *old, *new;
219 count = ahead->count;
220 printf("traversing the internal queue, which groups all the related volumes on a per partition basis\n");
222 printf("---------------------------\n");
223 printf("%s RW-Id %u",old->name,old->ids[RWVOL]);
224 if(old->isValid[RWVOL])
226 else printf(" invalid ");
227 printf("RO-Id %u",old->ids[ROVOL]);
228 if(old->isValid[ROVOL])
230 else printf(" invalid ");
231 printf("BACKUP-Id %u",old->ids[BACKVOL]);
232 if(old->isValid[BACKVOL])
234 else printf(" invalid ");
236 printf("---------------------------\n");
238 if(count != 1) new = new->next;