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>
15 #include "lockprocs.h"
18 /* Finds an index in VLDB entry that matches the volume type, server, and partition.
19 * If type is zero, will match first index of ANY type (RW, BK, or RO).
20 * If server is zero, will match first index of ANY server and partition
21 * Zero is a valid partition field.
24 FindIndex(afs_cell_handle_p cellHandle, struct nvldbentry *entry,
25 afs_int32 server, afs_int32 part, afs_int32 type)
31 for (e = 0; (e < entry->nServers) && !tst; e++) {
32 if (!type || (entry->serverFlags[e] & type)) {
33 VLDB_IsSameAddrs(cellHandle, entry->serverNumber[e], server,
35 if ((!server || (entry->serverPartition[e] == part))
36 && (!server || equal)) {
39 if (type == ITSRWVOL) {
40 /* quit when we are looking for RW entry (there's only 1) */
46 if (e >= entry->nServers) {
47 return -1; /* Didn't find it */
50 return e; /* return the index */
53 /* Changes the rw site only */
55 SetAValue(afs_cell_handle_p cellHandle, struct nvldbentry *entry,
56 afs_int32 oserver, afs_int32 opart, afs_int32 nserver,
57 afs_int32 npart, afs_int32 type)
61 e = FindIndex(cellHandle, entry, oserver, opart, type);
63 return; /* If didn't find it, just return */
65 entry->serverNumber[e] = nserver;
66 entry->serverPartition[e] = npart;
68 /* Now move rest of entries up */
69 if ((nserver == 0L) && (npart == 0L)) {
70 for (e++; e < entry->nServers; e++) {
71 entry->serverNumber[e - 1] = entry->serverNumber[e];
72 entry->serverPartition[e - 1] = entry->serverPartition[e];
73 entry->serverFlags[e - 1] = entry->serverFlags[e];
78 /* Changes the RW site only */
80 Lp_SetRWValue(afs_cell_handle_p cellHandle, struct nvldbentry *entry,
81 afs_int32 oserver, afs_int32 opart, afs_int32 nserver,
84 SetAValue(cellHandle, entry, oserver, opart, nserver, npart, ITSRWVOL);
87 /* Changes the RO site only */
89 Lp_SetROValue(afs_cell_handle_p cellHandle, struct nvldbentry *entry,
90 afs_int32 oserver, afs_int32 opart, afs_int32 nserver,
93 SetAValue(cellHandle, entry, oserver, opart, nserver, npart, ITSROVOL);
96 /* Returns success if this server and partition matches the RW entry */
98 Lp_Match(afs_cell_handle_p cellHandle, struct nvldbentry *entry,
99 afs_int32 server, afs_int32 part, afs_status_p st)
101 if (FindIndex(cellHandle, entry, server, part, ITSRWVOL) == -1)
106 /* Return the index of the RO entry (plus 1) if it exists, else return 0 */
108 Lp_ROMatch(afs_cell_handle_p cellHandle, struct nvldbentry *entry,
109 afs_int32 server, afs_int32 part, afs_status_p st)
111 return (FindIndex(cellHandle, entry, server, part, ITSROVOL) + 1);
114 /* Return the index of the RW entry if it exists, else return -1 */
116 Lp_GetRwIndex(afs_cell_handle_p cellHandle, struct nvldbentry *entry,
119 return (FindIndex(cellHandle, entry, 0, 0, ITSRWVOL));
122 /*initialize queue pointed by <ahead>*/
124 Lp_QInit(struct qHead *ahead)
130 /*add <elem> in front of queue <ahead> */
132 Lp_QAdd(struct qHead *ahead, struct aqueue *elem)
136 if (ahead->count == 0) {
149 Lp_QScan(struct qHead *ahead, afs_int32 id, int *success,
150 struct aqueue **elem, afs_status_p st)
155 while (cptr != NULL) {
156 if (cptr->ids[RWVOL] == id) {
167 /*return the element in the beginning of the queue <ahead>, free
168 *the space used by that element . <success> indicates if enumeration was ok*/
170 Lp_QEnumerate(struct qHead *ahead, int *success, struct aqueue *elem,
176 if (ahead->count > 0) { /*more elements left */
179 ahead->next = ahead->next->next;
180 strncpy(elem->name, temp->name, VOLSER_OLDMAXVOLNAME);
181 for (i = 0; i < 3; i++) {
182 elem->ids[i] = temp->ids[i];
183 elem->copyDate[i] = temp->copyDate[i];
184 elem->isValid[i] = temp->isValid[i];
189 } else /*queue is empty */