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
10 #include <afsconfig.h>
11 #include <afs/param.h>
16 #include "lockprocs.h"
25 /* Finds an index in VLDB entry that matches the volume type, server, and partition.
26 * If type is zero, will match first index of ANY type (RW, BK, or RO).
27 * If server is zero, will match first index of ANY server and partition
28 * Zero is a valid partition field.
31 FindIndex(afs_cell_handle_p cellHandle, struct nvldbentry *entry,
32 afs_int32 server, afs_int32 part, afs_int32 type)
38 for (e = 0; (e < entry->nServers) && !tst; e++) {
39 if (!type || (entry->serverFlags[e] & type)) {
40 VLDB_IsSameAddrs(cellHandle, entry->serverNumber[e], server,
42 if ((!server || (entry->serverPartition[e] == part))
43 && (!server || equal)) {
46 if (type == ITSRWVOL) {
47 /* quit when we are looking for RW entry (there's only 1) */
53 if (e >= entry->nServers) {
54 return -1; /* Didn't find it */
57 return e; /* return the index */
60 /* Changes the rw site only */
62 SetAValue(afs_cell_handle_p cellHandle, struct nvldbentry *entry,
63 afs_int32 oserver, afs_int32 opart, afs_int32 nserver,
64 afs_int32 npart, afs_int32 type)
68 e = FindIndex(cellHandle, entry, oserver, opart, type);
70 return; /* If didn't find it, just return */
72 entry->serverNumber[e] = nserver;
73 entry->serverPartition[e] = npart;
75 /* Now move rest of entries up */
76 if ((nserver == 0L) && (npart == 0L)) {
77 for (e++; e < entry->nServers; e++) {
78 entry->serverNumber[e - 1] = entry->serverNumber[e];
79 entry->serverPartition[e - 1] = entry->serverPartition[e];
80 entry->serverFlags[e - 1] = entry->serverFlags[e];
85 /* Changes the RW site only */
87 Lp_SetRWValue(afs_cell_handle_p cellHandle, struct nvldbentry *entry,
88 afs_int32 oserver, afs_int32 opart, afs_int32 nserver,
91 SetAValue(cellHandle, entry, oserver, opart, nserver, npart, ITSRWVOL);
94 /* Changes the RO site only */
96 Lp_SetROValue(afs_cell_handle_p cellHandle, struct nvldbentry *entry,
97 afs_int32 oserver, afs_int32 opart, afs_int32 nserver,
100 SetAValue(cellHandle, entry, oserver, opart, nserver, npart, ITSROVOL);
103 /* Returns success if this server and partition matches the RW entry */
105 Lp_Match(afs_cell_handle_p cellHandle, struct nvldbentry *entry,
106 afs_int32 server, afs_int32 part, afs_status_p st)
108 if (FindIndex(cellHandle, entry, server, part, ITSRWVOL) == -1)
113 /* Return the index of the RO entry (plus 1) if it exists, else return 0 */
115 Lp_ROMatch(afs_cell_handle_p cellHandle, struct nvldbentry *entry,
116 afs_int32 server, afs_int32 part, afs_status_p st)
118 return (FindIndex(cellHandle, entry, server, part, ITSROVOL) + 1);
121 /* Return the index of the RW entry if it exists, else return -1 */
123 Lp_GetRwIndex(afs_cell_handle_p cellHandle, struct nvldbentry *entry,
126 return (FindIndex(cellHandle, entry, 0, 0, ITSRWVOL));
129 /*initialize queue pointed by <ahead>*/
131 Lp_QInit(struct qHead *ahead)
137 /*add <elem> in front of queue <ahead> */
139 Lp_QAdd(struct qHead *ahead, struct aqueue *elem)
143 if (ahead->count == 0) {
156 Lp_QScan(struct qHead *ahead, afs_int32 id, int *success,
157 struct aqueue **elem, afs_status_p st)
162 while (cptr != NULL) {
163 if (cptr->ids[RWVOL] == id) {
174 /*return the element in the beginning of the queue <ahead>, free
175 *the space used by that element . <success> indicates if enumeration was ok*/
177 Lp_QEnumerate(struct qHead *ahead, int *success, struct aqueue *elem,
183 if (ahead->count > 0) { /*more elements left */
186 ahead->next = ahead->next->next;
187 strncpy(elem->name, temp->name, VOLSER_OLDMAXVOLNAME);
188 for (i = 0; i < 3; i++) {
189 elem->ids[i] = temp->ids[i];
190 elem->copyDate[i] = temp->copyDate[i];
191 elem->isValid[i] = temp->isValid[i];
196 } else /*queue is empty */