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 #include "vsutils_prototypes.h"
41 #include "lockprocs_prototypes.h"
43 /* Finds an index in VLDB entry that matches the volume type, server, and partition.
44 * If type is zero, will match first index of ANY type (RW, BK, or RO).
45 * If server is zero, will match first index of ANY server and partition
46 * Zero is a valid partition field.
49 FindIndex(struct nvldbentry *entry, afs_int32 server, afs_int32 part, afs_int32 type)
54 for (e = 0; (e < entry->nServers) && !error; e++) {
55 if (!type || (entry->serverFlags[e] & type)) {
56 if ((!server || (entry->serverPartition[e] == part))
58 || VLDB_IsSameAddrs(entry->serverNumber[e], server,
62 return -1; /* quit when we are looking for RW entry (there's only 1) */
68 "Failed to get info about server's %d address(es) from vlserver (err=%d)\n",
69 entry->serverNumber[e], error);
73 if (e >= entry->nServers)
74 return -1; /* Didn't find it */
76 return e; /* return the index */
79 /* Changes the rw site only */
81 SetAValue(struct nvldbentry *entry, afs_int32 oserver, afs_int32 opart,
82 afs_int32 nserver, afs_int32 npart, afs_int32 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 */
106 Lp_SetRWValue(struct nvldbentry *entry, afs_int32 oserver, afs_int32 opart,
107 afs_int32 nserver, afs_int32 npart)
109 SetAValue(entry, oserver, opart, nserver, npart, ITSRWVOL);
112 /* Changes the RO site only */
114 Lp_SetROValue(struct nvldbentry *entry, afs_int32 oserver,
115 afs_int32 opart, afs_int32 nserver, afs_int32 npart)
117 SetAValue(entry, oserver, opart, nserver, npart, ITSROVOL);
120 /* Returns success if this server and partition matches the RW entry */
122 Lp_Match(afs_int32 server, afs_int32 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 */
132 Lp_ROMatch(afs_int32 server, afs_int32 part, struct nvldbentry *entry)
134 return (FindIndex(entry, server, part, ITSROVOL) + 1);
137 /* Return the index of the RW entry if it exists, else return -1 */
139 Lp_GetRwIndex(struct nvldbentry *entry)
141 return (FindIndex(entry, 0, 0, ITSRWVOL));
144 /*initialize queue pointed by <ahead>*/
146 Lp_QInit(struct qHead *ahead)
152 /*add <elem> in front of queue <ahead> */
154 Lp_QAdd(struct qHead *ahead, struct aqueue *elem)
158 if (ahead->count == 0) {
171 Lp_QScan(struct qHead *ahead, afs_int32 id, int *success, struct aqueue **elem)
176 while (cptr != NULL) {
177 if (cptr->ids[RWVOL] == id) {
188 /*return the element in the beginning of the queue <ahead>, free
189 *the space used by that element . <success> indicates if enumeration was ok*/
191 Lp_QEnumerate(struct qHead *ahead, int *success, struct aqueue *elem)
196 if (ahead->count > 0) { /*more elements left */
199 ahead->next = ahead->next->next;
200 strncpy(elem->name, temp->name, VOLSER_OLDMAXVOLNAME);
201 for (i = 0; i < 3; i++) {
202 elem->ids[i] = temp->ids[i];
203 elem->copyDate[i] = temp->copyDate[i];
204 elem->isValid[i] = temp->isValid[i];
209 } else /*queue is empty */
214 Lp_QTraverse(struct qHead *ahead)
217 struct aqueue *old, *new;
221 count = ahead->count;
223 ("traversing the internal queue, which groups all the related volumes on a per partition basis\n");
225 printf("---------------------------\n");
226 printf("%s RW-Id %lu", old->name, (unsigned long)old->ids[RWVOL]);
227 if (old->isValid[RWVOL])
231 printf("RO-Id %lu", (unsigned long)old->ids[ROVOL]);
232 if (old->isValid[ROVOL])
236 printf("BACKUP-Id %lu", (unsigned long)old->ids[BACKVOL]);
237 if (old->isValid[BACKVOL])
242 printf("---------------------------\n");