Coda Distributed File System
ds_rrlist.h
Go to the documentation of this file.
1#ifndef _DS_RRLIST_H_
2#define _DS_RRLIST_H_
3
4/*
5 ds_rrlist.h - the resource request list data structure
6*/
7
8#include <stdio.h>
9
10#include <odytypes.h>
11#include <ds_list.h> /* some calls return lists */
12
13/*
14
15 Resource request lists are used internally in the viceroy and
16 wardens. Abstractly, they contain a set of bounds, B, that have
17 been requested by processes, and a current integer value, v. Each
18 bound B consists of the following:
19
20 B.low - the low value of the bound
21 B.high - the high value of the bound
22 B.pid - the process id of the requesting process
23 B.reqid - the identifier granted to that requesting process
24
25 The following (public) invariants that hold for rrl's.
26
27 forall b in B, b.low <= v <= b.high.
28 forall b1, b2 in B s.t. b1!=b2, b1.pid != b2.pid
29 forall time, forall b1, b2 s.t. b1!=b2, b1.reqid != b2.reqid
30
31 (If requests on a resource come every 1/10sec, then it will take
32 six years for the number of reqid's to be exhausted.)
33
34*/
35
36/* Individual requests */
37/*
38 rrlist clients are fully responsible for allocating/deallocating
39 these. They're exposed because they are public, for all intents
40 and purposes; there are no real complicated operations on them, and
41 no serious invariants. Allocation and deallocation operations are
42 provided, but as macros. Treat the reqid field as const!
43 (This seemed easier than creating some opaque type unnecessarily)
44*/
45
46typedef struct ds_request_t {
48 long low; /* lower bound */
49 long high; /* upper bound */
50 long reqid; /* const: filled only by rrlists */
51 long pid; /* process id of requesting process */
53
54extern const magic_t ds_request_magic;
55
56#define DS_REQUEST_VALID(rp) ((rp) && ((rp)->magic == ds_request_magic))
57
58#define DS_REQUEST_ALLOCATE(X, l, h, p) \
59 do { \
60 ALLOC((X), ds_request_t); \
61 (X)->magic = ds_request_magic; \
62 (X)->low = (l); \
63 (X)->high = (h); \
64 (X)->reqid = 0; \
65 (X)->pid = (p); \
66 } while (0)
67
68#define DS_REQUEST_DESTROY(X) \
69 do { \
70 CODA_ASSERT(DS_REQUEST_VALID((X))); \
71 (X)->magic = 0; \
72 (X)->low = (X)->high = (X)->reqid = 0L; \
73 (X)->pid = 0; \
74 FREE((X)); \
75 } while (0)
76
77/* resource request lists */
78typedef struct ds_rrlist_t ds_rrlist_t; /* opaque */
79
80/*** Return Values ***/
81/* the functions can return more than one flag! */
82typedef enum
83{
90
91/*** Observers ***/
92
93extern bool ds_rrlist_valid(ds_rrlist_t *l);
94extern long ds_rrlist_value(ds_rrlist_t *l);
95
96/*** Mutators ***/
97
98/*
99 Create a new list: specify the initial value
100 of the resource. It is assumed that no function from this
101 package can be (legitimately) called before this one: it does
102 any internal setup necessary.
103*/
105
106/*
107 Destroy a rrlist. It must be empty.
108*/
110
111/*
112 Place a request. Returns:
113 DS_RRLIST_SUCCESS if request placed without incident
114
115 It can also return a value with one or more of the following flags
116 set:
117
118 DS_RRLIST_OUTOFWINDOW if current value is out of the request's window
119 DS_RRLIST_DUPLICATE if there was an old request for this pid
120
121 If the current value is out of the request's window, the OUT parameter
122 value is set to the current value.
123
124 If the current request supersedes an old one, the OUT parameter
125 '*old_req' is set to the old outstanding request, which is removed.
126*/
128 long *value,
129 ds_request_t **old_req);
130
131/*
132 Cancel a request. Returns:
133 DS_RRLIST_SUCCESS if successful
134 DS_RRLIST_NOSUCHREQ if the request isn't a valid one
135
136 If the call is successful, req is filled with the removed request.
137 Note that we don't need to (and often cannot) know what list the
138 request was granted from.
139*/
141
142/*
143 Purge a program's outstanding requests. Returns
144 DS_RRLIST_SUCCESS if successful
145 DS_RRLIST_NOSUCHPID if the process has no outstanding requests
146
147 If the call is successful, req is filled with the removed request
148*/
150 ds_request_t **req);
151
152/*
153 Change the value of the resource. Returns
154 DS_RRLIST_SUCCESS if successful
155
156 (But, check the return value anyway.)
157 The OUT parameter argument '*to_notify' is set to a (possibly NULL)
158 list of ds_request_t's that no longer enclose the current value.
159 It is the caller's responsibility to destroy *to_notify, which is
160 a "safe" list. See ds_list.h for more information.
161*/
163 ds_list_t **to_notify);
164
165/*
166 Debugging: print out a list.
167*/
168extern void ds_rrlist_dump(ds_rrlist_t *l, FILE *f, char *name);
169
170#endif /* _DS_RRLIST_H_ */
ds_rrlist_t * ds_rrlist_create(long value)
Definition: ds_rrlist.c:136
void ds_rrlist_destroy(ds_rrlist_t *l)
Definition: ds_rrlist.c:161
void ds_rrlist_dump(ds_rrlist_t *l, FILE *f, char *name)
Definition: ds_rrlist.c:396
ds_rrlist_return_t ds_rrlist_purge(ds_rrlist_t *l, int pid, ds_request_t **req)
Definition: ds_rrlist.c:265
const magic_t ds_request_magic
Definition: ds_rrlist.c:14
bool ds_rrlist_valid(ds_rrlist_t *l)
Definition: ds_rrlist.c:120
ds_rrlist_return_t
Definition: ds_rrlist.h:83
@ DS_RRLIST_NOSUCHPID
Definition: ds_rrlist.h:87
@ DS_RRLIST_SUCCESS
Definition: ds_rrlist.h:84
@ DS_RRLIST_NOSUCHREQ
Definition: ds_rrlist.h:88
@ DS_RRLIST_DUPLICATE
Definition: ds_rrlist.h:86
@ DS_RRLIST_OUTOFWINDOW
Definition: ds_rrlist.h:85
ds_rrlist_return_t ds_rrlist_request(ds_rrlist_t *l, ds_request_t *r, long *value, ds_request_t **old_req)
Definition: ds_rrlist.c:173
ds_rrlist_return_t ds_rrlist_cancel(long reqid, ds_request_t **req)
Definition: ds_rrlist.c:221
struct ds_request_t ds_request_t
long ds_rrlist_value(ds_rrlist_t *l)
Definition: ds_rrlist.c:128
ds_rrlist_return_t ds_rrlist_set_value(ds_rrlist_t *l, long newval, ds_list_t **to_notify)
Definition: ds_rrlist.c:298
name
Definition: pwdtopdbtool.py:40
unsigned long magic_t
Definition: odytypes.h:44
@ r
Definition: rvm_private.h:414
@ f
Definition: rvm_private.h:416
RPC2_PacketBuffer * req[]
Definition: sftp6.c:84
Definition: ds_list.private.h:41
Definition: ds_rrlist.h:46
long high
Definition: ds_rrlist.h:49
magic_t magic
Definition: ds_rrlist.h:47
long pid
Definition: ds_rrlist.h:51
long low
Definition: ds_rrlist.h:48
long reqid
Definition: ds_rrlist.h:50
Definition: ds_rrlist.private.h:28
long value
Definition: ds_rrlist.private.h:30