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"
17 /* Finds an index in VLDB entry that matches the volume type, server, and partition.
18 * If type is zero, will match first index of ANY type (RW, BK, or RO).
19 * If server is zero, will match first index of ANY server and partition
20 * Zero is a valid partition field.
23 FindIndex(afs_cell_handle_p cellHandle
, struct nvldbentry
*entry
,
24 afs_int32 server
, afs_int32 part
, afs_int32 type
)
30 for (e
= 0; (e
< entry
->nServers
) && !tst
; e
++) {
31 if (!type
|| (entry
->serverFlags
[e
] & type
)) {
32 VLDB_IsSameAddrs(cellHandle
, entry
->serverNumber
[e
], server
,
34 if ((!server
|| (entry
->serverPartition
[e
] == part
))
35 && (!server
|| equal
)) {
38 if (type
== VLSF_RWVOL
) {
39 /* quit when we are looking for RW entry (there's only 1) */
45 if (e
>= entry
->nServers
) {
46 return -1; /* Didn't find it */
49 return e
; /* return the index */
52 /* Changes the rw site only */
54 SetAValue(afs_cell_handle_p cellHandle
, struct nvldbentry
*entry
,
55 afs_int32 oserver
, afs_int32 opart
, afs_int32 nserver
,
56 afs_int32 npart
, afs_int32 type
)
60 e
= FindIndex(cellHandle
, entry
, oserver
, opart
, type
);
62 return; /* If didn't find it, just return */
64 entry
->serverNumber
[e
] = nserver
;
65 entry
->serverPartition
[e
] = npart
;
67 /* Now move rest of entries up */
68 if ((nserver
== 0L) && (npart
== 0L)) {
69 for (e
++; e
< entry
->nServers
; e
++) {
70 entry
->serverNumber
[e
- 1] = entry
->serverNumber
[e
];
71 entry
->serverPartition
[e
- 1] = entry
->serverPartition
[e
];
72 entry
->serverFlags
[e
- 1] = entry
->serverFlags
[e
];
77 /* Changes the RW site only */
79 Lp_SetRWValue(afs_cell_handle_p cellHandle
, struct nvldbentry
*entry
,
80 afs_int32 oserver
, afs_int32 opart
, afs_int32 nserver
,
83 SetAValue(cellHandle
, entry
, oserver
, opart
, nserver
, npart
, VLSF_RWVOL
);
86 /* Changes the RO site only */
88 Lp_SetROValue(afs_cell_handle_p cellHandle
, struct nvldbentry
*entry
,
89 afs_int32 oserver
, afs_int32 opart
, afs_int32 nserver
,
92 SetAValue(cellHandle
, entry
, oserver
, opart
, nserver
, npart
, VLSF_ROVOL
);
95 /* Returns success if this server and partition matches the RW entry */
97 Lp_Match(afs_cell_handle_p cellHandle
, struct nvldbentry
*entry
,
98 afs_int32 server
, afs_int32 part
, afs_status_p st
)
100 if (FindIndex(cellHandle
, entry
, server
, part
, VLSF_RWVOL
) == -1)
105 /* Return the index of the RO entry (plus 1) if it exists, else return 0 */
107 Lp_ROMatch(afs_cell_handle_p cellHandle
, struct nvldbentry
*entry
,
108 afs_int32 server
, afs_int32 part
, afs_status_p st
)
110 return (FindIndex(cellHandle
, entry
, server
, part
, VLSF_ROVOL
) + 1);
113 /* Return the index of the RW entry if it exists, else return -1 */
115 Lp_GetRwIndex(afs_cell_handle_p cellHandle
, struct nvldbentry
*entry
,
118 return (FindIndex(cellHandle
, entry
, 0, 0, VLSF_RWVOL
));
121 /*initialize queue pointed by <ahead>*/
123 Lp_QInit(struct qHead
*ahead
)
129 /*add <elem> in front of queue <ahead> */
131 Lp_QAdd(struct qHead
*ahead
, struct aqueue
*elem
)
135 if (ahead
->count
== 0) {
148 Lp_QScan(struct qHead
*ahead
, afs_int32 id
, int *success
,
149 struct aqueue
**elem
, afs_status_p st
)
154 while (cptr
!= NULL
) {
155 if (cptr
->ids
[RWVOL
] == id
) {
166 /*return the element in the beginning of the queue <ahead>, free
167 *the space used by that element . <success> indicates if enumeration was ok*/
169 Lp_QEnumerate(struct qHead
*ahead
, int *success
, struct aqueue
*elem
,
175 if (ahead
->count
> 0) { /*more elements left */
178 ahead
->next
= ahead
->next
->next
;
179 strncpy(elem
->name
, temp
->name
, VOLSER_OLDMAXVOLNAME
);
180 for (i
= 0; i
< 3; i
++) {
181 elem
->ids
[i
] = temp
->ids
[i
];
182 elem
->copyDate
[i
] = temp
->copyDate
[i
];
183 elem
->isValid
[i
] = temp
->isValid
[i
];
188 } else /*queue is empty */