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"
19 /* Finds an index in VLDB entry that matches the volume type, server, and partition.
20 * If type is zero, will match first index of ANY type (RW, BK, or RO).
21 * If server is zero, will match first index of ANY server and partition
22 * Zero is a valid partition field.
25 FindIndex(afs_cell_handle_p cellHandle, struct nvldbentry *entry,
26 afs_int32 server, afs_int32 part, afs_int32 type)
32 for (e = 0; (e < entry->nServers) && !tst; e++) {
33 if (!type || (entry->serverFlags[e] & type)) {
34 VLDB_IsSameAddrs(cellHandle, entry->serverNumber[e], server,
36 if ((!server || (entry->serverPartition[e] == part))
37 && (!server || equal)) {
40 if (type == ITSRWVOL) {
41 /* quit when we are looking for RW entry (there's only 1) */
47 if (e >= entry->nServers) {
48 return -1; /* Didn't find it */
51 return e; /* return the index */
54 /* Changes the rw site only */
56 SetAValue(afs_cell_handle_p cellHandle, struct nvldbentry *entry,
57 afs_int32 oserver, afs_int32 opart, afs_int32 nserver,
58 afs_int32 npart, afs_int32 type)
62 e = FindIndex(cellHandle, entry, oserver, opart, type);
64 return; /* If didn't find it, just return */
66 entry->serverNumber[e] = nserver;
67 entry->serverPartition[e] = npart;
69 /* Now move rest of entries up */
70 if ((nserver == 0L) && (npart == 0L)) {
71 for (e++; e < entry->nServers; e++) {
72 entry->serverNumber[e - 1] = entry->serverNumber[e];
73 entry->serverPartition[e - 1] = entry->serverPartition[e];
74 entry->serverFlags[e - 1] = entry->serverFlags[e];
79 /* Changes the RW site only */
81 Lp_SetRWValue(afs_cell_handle_p cellHandle, struct nvldbentry *entry,
82 afs_int32 oserver, afs_int32 opart, afs_int32 nserver,
85 SetAValue(cellHandle, entry, oserver, opart, nserver, npart, ITSRWVOL);
88 /* Changes the RO site only */
90 Lp_SetROValue(afs_cell_handle_p cellHandle, struct nvldbentry *entry,
91 afs_int32 oserver, afs_int32 opart, afs_int32 nserver,
94 SetAValue(cellHandle, entry, oserver, opart, nserver, npart, ITSROVOL);
97 /* Returns success if this server and partition matches the RW entry */
99 Lp_Match(afs_cell_handle_p cellHandle, struct nvldbentry *entry,
100 afs_int32 server, afs_int32 part, afs_status_p st)
102 if (FindIndex(cellHandle, entry, server, part, ITSRWVOL) == -1)
107 /* Return the index of the RO entry (plus 1) if it exists, else return 0 */
109 Lp_ROMatch(afs_cell_handle_p cellHandle, struct nvldbentry *entry,
110 afs_int32 server, afs_int32 part, afs_status_p st)
112 return (FindIndex(cellHandle, entry, server, part, ITSROVOL) + 1);
115 /* Return the index of the RW entry if it exists, else return -1 */
117 Lp_GetRwIndex(afs_cell_handle_p cellHandle, struct nvldbentry *entry,
120 return (FindIndex(cellHandle, entry, 0, 0, ITSRWVOL));
123 /*initialize queue pointed by <ahead>*/
125 Lp_QInit(struct qHead *ahead)
131 /*add <elem> in front of queue <ahead> */
133 Lp_QAdd(struct qHead *ahead, struct aqueue *elem)
137 if (ahead->count == 0) {
150 Lp_QScan(struct qHead *ahead, afs_int32 id, int *success,
151 struct aqueue **elem, afs_status_p st)
156 while (cptr != NULL) {
157 if (cptr->ids[RWVOL] == id) {
168 /*return the element in the beginning of the queue <ahead>, free
169 *the space used by that element . <success> indicates if enumeration was ok*/
171 Lp_QEnumerate(struct qHead *ahead, int *success, struct aqueue *elem,
177 if (ahead->count > 0) { /*more elements left */
180 ahead->next = ahead->next->next;
181 strncpy(elem->name, temp->name, VOLSER_OLDMAXVOLNAME);
182 for (i = 0; i < 3; i++) {
183 elem->ids[i] = temp->ids[i];
184 elem->copyDate[i] = temp->copyDate[i];
185 elem->isValid[i] = temp->isValid[i];
190 } else /*queue is empty */