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>
28 #include <afs/voldefs.h>
31 #include <afs/vlserver.h>
33 #include <afs/afsint.h>
38 /* Finds an index in VLDB entry that matches the volume type, server, and partition.
39 * If type is zero, will match first index of ANY type (RW, BK, or RO).
40 * If server is zero, will match first index of ANY server and partition
41 * Zero is a valid partition field.
43 int FindIndex(entry, server, part, type)
44 struct nvldbentry *entry;
45 afs_int32 server, part, type;
50 for (e=0; (e < entry->nServers) && !error; e++) {
51 if (!type || (entry->serverFlags[e] & type)) {
52 if ( (!server || (entry->serverPartition[e] == part)) &&
53 (!server || VLDB_IsSameAddrs(entry->serverNumber[e],server,&error)) )
56 return -1; /* quit when we are looking for RW entry (there's only 1) */
62 "Failed to get info about server's %d address(es) from vlserver (err=%d)\n",
63 entry->serverNumber[e], error);
67 if (e >= entry->nServers)
68 return -1; /* Didn't find it */
70 return e; /* return the index */
73 /* Changes the rw site only */
74 SetAValue (entry, oserver, opart, nserver, npart, type)
75 struct nvldbentry *entry;
76 afs_int32 oserver, opart, nserver, npart, type;
81 e = FindIndex(entry, oserver, opart, type);
83 return; /* If didn't find it, just return */
85 entry->serverNumber[e] = nserver;
86 entry->serverPartition[e] = npart;
88 /* Now move rest of entries up */
89 if ((nserver == 0L) && (npart == 0L)) {
90 for (e++; e<entry->nServers; e++) {
91 entry->serverNumber[e-1] = entry->serverNumber[e];
92 entry->serverPartition[e-1] = entry->serverPartition[e];
93 entry->serverFlags[e-1] = entry->serverFlags[e];
98 /* Changes the RW site only */
99 Lp_SetRWValue (entry, oserver, opart, nserver, npart)
100 struct nvldbentry *entry;
101 afs_int32 oserver, opart, nserver, npart;
103 SetAValue (entry, oserver, opart, nserver, npart, ITSRWVOL);
106 /* Changes the RO site only */
107 Lp_SetROValue(entry, oserver, opart, nserver, npart)
108 struct nvldbentry *entry;
109 afs_int32 oserver, opart, nserver, npart;
111 SetAValue (entry, oserver, opart, nserver, npart, ITSROVOL);
114 /* Returns success if this server and partition matches the RW entry */
115 Lp_Match(server, part, entry)
116 afs_int32 server, part;
117 struct nvldbentry *entry;
119 if (FindIndex(entry, server, part, ITSRWVOL) == -1)
124 /* Return the index of the RO entry (plus 1) if it exists, else return 0 */
125 Lp_ROMatch(server, part, entry)
126 afs_int32 server, part;
127 struct nvldbentry *entry;
129 return (FindIndex(entry,server,part,ITSROVOL) + 1);
132 /* Return the index of the RW entry if it exists, else return -1 */
134 struct nvldbentry *entry;
136 return (FindIndex(entry,0,0,ITSRWVOL));
139 /*initialize queue pointed by <ahead>*/
144 ahead->next = (struct aqueue *)0;
147 /*add <elem> in front of queue <ahead> */
154 if(ahead->count == 0) {
157 elem->next = (struct aqueue *)0;
167 Lp_QScan(ahead,id,success, elem)
169 struct aqueue **elem;
172 { struct aqueue *cptr;
175 while(cptr != (struct aqueue *)0) {
176 if(cptr->ids[RWVOL] == id) {
187 /*return the element in the beginning of the queue <ahead>, free
188 *the space used by that element . <success> indicates if enumeration was ok*/
189 Lp_QEnumerate(ahead,success, elem)
197 if(ahead->count > 0) {/*more elements left */
200 ahead->next = ahead->next->next;
201 strncpy(elem->name,temp->name,VOLSER_OLDMAXVOLNAME);
202 for(i= 0; i < 3; i++){
203 elem->ids[i] = temp->ids[i];
204 elem->copyDate[i] = temp->copyDate[i];
205 elem->isValid[i] = temp->isValid[i];
207 elem->next = (struct aqueue *)0;
211 else /*queue is empty*/
219 struct aqueue *old, *new;
223 count = ahead->count;
224 printf("traversing the internal queue, which groups all the related volumes on a per partition basis\n");
226 printf("---------------------------\n");
227 printf("%s RW-Id %u",old->name,old->ids[RWVOL]);
228 if(old->isValid[RWVOL])
230 else printf(" invalid ");
231 printf("RO-Id %u",old->ids[ROVOL]);
232 if(old->isValid[ROVOL])
234 else printf(" invalid ");
235 printf("BACKUP-Id %u",old->ids[BACKVOL]);
236 if(old->isValid[BACKVOL])
238 else printf(" invalid ");
240 printf("---------------------------\n");
242 if(count != 1) new = new->next;