diff options
author | NeilBrown <neilb@suse.de> | 2006-03-27 04:15:12 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@g5.osdl.org> | 2006-03-27 11:44:43 -0500 |
commit | 491214716755894986b99e0cf0a08b830d244577 (patch) | |
tree | fb23b729de181f6ea13bc9e5f4f778ca8a0b0e4a /Documentation | |
parent | ad1b5229def92b71631a927895b034ceec06c991 (diff) |
[PATCH] knfsd: Update rpc-cache.txt to match recent changes
Signed-off-by: Neil Brown <neilb@suse.de>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Diffstat (limited to 'Documentation')
-rw-r--r-- | Documentation/rpc-cache.txt | 121 |
1 files changed, 76 insertions, 45 deletions
diff --git a/Documentation/rpc-cache.txt b/Documentation/rpc-cache.txt index 2b5d4434fa5a..5f757c8cf979 100644 --- a/Documentation/rpc-cache.txt +++ b/Documentation/rpc-cache.txt | |||
@@ -1,4 +1,4 @@ | |||
1 | This document gives a brief introduction to the caching | 1 | This document gives a brief introduction to the caching |
2 | mechanisms in the sunrpc layer that is used, in particular, | 2 | mechanisms in the sunrpc layer that is used, in particular, |
3 | for NFS authentication. | 3 | for NFS authentication. |
4 | 4 | ||
@@ -25,25 +25,17 @@ The common code handles such things as: | |||
25 | - supporting 'NEGATIVE' as well as positive entries | 25 | - supporting 'NEGATIVE' as well as positive entries |
26 | - allowing an EXPIRED time on cache items, and removing | 26 | - allowing an EXPIRED time on cache items, and removing |
27 | items after they expire, and are no longe in-use. | 27 | items after they expire, and are no longe in-use. |
28 | |||
29 | Future code extensions are expect to handle | ||
30 | - making requests to user-space to fill in cache entries | 28 | - making requests to user-space to fill in cache entries |
31 | - allowing user-space to directly set entries in the cache | 29 | - allowing user-space to directly set entries in the cache |
32 | - delaying RPC requests that depend on as-yet incomplete | 30 | - delaying RPC requests that depend on as-yet incomplete |
33 | cache entries, and replaying those requests when the cache entry | 31 | cache entries, and replaying those requests when the cache entry |
34 | is complete. | 32 | is complete. |
35 | - maintaining last-access times on cache entries | 33 | - clean out old entries as they expire. |
36 | - clean out old entries when the caches become full | ||
37 | |||
38 | The code for performing a cache lookup is also common, but in the form | ||
39 | of a template. i.e. a #define. | ||
40 | Each cache defines a lookup function by using the DefineCacheLookup | ||
41 | macro, or the simpler DefineSimpleCacheLookup macro | ||
42 | 34 | ||
43 | Creating a Cache | 35 | Creating a Cache |
44 | ---------------- | 36 | ---------------- |
45 | 37 | ||
46 | 1/ A cache needs a datum to cache. This is in the form of a | 38 | 1/ A cache needs a datum to store. This is in the form of a |
47 | structure definition that must contain a | 39 | structure definition that must contain a |
48 | struct cache_head | 40 | struct cache_head |
49 | as an element, usually the first. | 41 | as an element, usually the first. |
@@ -51,35 +43,69 @@ Creating a Cache | |||
51 | Each cache element is reference counted and contains | 43 | Each cache element is reference counted and contains |
52 | expiry and update times for use in cache management. | 44 | expiry and update times for use in cache management. |
53 | 2/ A cache needs a "cache_detail" structure that | 45 | 2/ A cache needs a "cache_detail" structure that |
54 | describes the cache. This stores the hash table, and some | 46 | describes the cache. This stores the hash table, some |
55 | parameters for cache management. | 47 | parameters for cache management, and some operations detailing how |
56 | 3/ A cache needs a lookup function. This is created using | 48 | to work with particular cache items. |
57 | the DefineCacheLookup macro. This lookup function is used both | 49 | The operations requires are: |
58 | to find entries and to update entries. The normal mode for | 50 | struct cache_head *alloc(void) |
59 | updating an entry is to replace the old entry with a new | 51 | This simply allocates appropriate memory and returns |
60 | entry. However it is possible to allow update-in-place | 52 | a pointer to the cache_detail embedded within the |
61 | for those caches where it makes sense (no atomicity issues | 53 | structure |
62 | or indirect reference counting issue) | 54 | void cache_put(struct kref *) |
63 | 4/ A cache needs to be registered using cache_register(). This | 55 | This is called when the last reference to an item is |
64 | includes in on a list of caches that will be regularly | 56 | is dropped. The pointer passed is to the 'ref' field |
65 | cleaned to discard old data. For this to work, some | 57 | in the cache_head. cache_put should release any |
66 | thread must periodically call cache_clean | 58 | references create by 'cache_init' and, if CACHE_VALID |
67 | 59 | is set, any references created by cache_update. | |
60 | It should then release the memory allocated by | ||
61 | 'alloc'. | ||
62 | int match(struct cache_head *orig, struct cache_head *new) | ||
63 | test if the keys in the two structures match. Return | ||
64 | 1 if they do, 0 if they don't. | ||
65 | void init(struct cache_head *orig, struct cache_head *new) | ||
66 | Set the 'key' fields in 'new' from 'orig'. This may | ||
67 | include taking references to shared objects. | ||
68 | void update(struct cache_head *orig, struct cache_head *new) | ||
69 | Set the 'content' fileds in 'new' from 'orig'. | ||
70 | int cache_show(struct seq_file *m, struct cache_detail *cd, | ||
71 | struct cache_head *h) | ||
72 | Optional. Used to provide a /proc file that lists the | ||
73 | contents of a cache. This should show one item, | ||
74 | usually on just one line. | ||
75 | int cache_request(struct cache_detail *cd, struct cache_head *h, | ||
76 | char **bpp, int *blen) | ||
77 | Format a request to be send to user-space for an item | ||
78 | to be instantiated. *bpp is a buffer of size *blen. | ||
79 | bpp should be moved forward over the encoded message, | ||
80 | and *blen should be reduced to show how much free | ||
81 | space remains. Return 0 on success or <0 if not | ||
82 | enough room or other problem. | ||
83 | int cache_parse(struct cache_detail *cd, char *buf, int len) | ||
84 | A message from user space has arrived to fill out a | ||
85 | cache entry. It is in 'buf' of length 'len'. | ||
86 | cache_parse should parse this, find the item in the | ||
87 | cache with sunrpc_cache_lookup, and update the item | ||
88 | with sunrpc_cache_update. | ||
89 | |||
90 | |||
91 | 3/ A cache needs to be registered using cache_register(). This | ||
92 | includes it on a list of caches that will be regularly | ||
93 | cleaned to discard old data. | ||
94 | |||
68 | Using a cache | 95 | Using a cache |
69 | ------------- | 96 | ------------- |
70 | 97 | ||
71 | To find a value in a cache, call the lookup function passing it a the | 98 | To find a value in a cache, call sunrpc_cache_lookup passing a pointer |
72 | datum which contains key, and possibly content, and a flag saying | 99 | to the cache_head in a sample item with the 'key' fields filled in. |
73 | whether to update the cache with new data from the datum. Depending | 100 | This will be passed to ->match to identify the target entry. If no |
74 | on how the cache lookup function was defined, it may take an extra | 101 | entry is found, a new entry will be create, added to the cache, and |
75 | argument to identify the particular cache in question. | 102 | marked as not containing valid data. |
76 | 103 | ||
77 | Except in cases of kmalloc failure, the lookup function | 104 | The item returned is typically passed to cache_check which will check |
78 | will return a new datum which will store the key and | 105 | if the data is valid, and may initiate an up-call to get fresh data. |
79 | may contain valid content, or may not. | 106 | cache_check will return -ENOENT in the entry is negative or if an up |
80 | This datum is typically passed to cache_check which determines the | 107 | call is needed but not possible, -EAGAIN if an upcall is pending, |
81 | validity of the datum and may later initiate an upcall to fill | 108 | or 0 if the data is valid; |
82 | in the data. | ||
83 | 109 | ||
84 | cache_check can be passed a "struct cache_req *". This structure is | 110 | cache_check can be passed a "struct cache_req *". This structure is |
85 | typically embedded in the actual request and can be used to create a | 111 | typically embedded in the actual request and can be used to create a |
@@ -90,6 +116,13 @@ item does become valid, the deferred copy of the request will be | |||
90 | revisited (->revisit). It is expected that this method will | 116 | revisited (->revisit). It is expected that this method will |
91 | reschedule the request for processing. | 117 | reschedule the request for processing. |
92 | 118 | ||
119 | The value returned by sunrpc_cache_lookup can also be passed to | ||
120 | sunrpc_cache_update to set the content for the item. A second item is | ||
121 | passed which should hold the content. If the item found by _lookup | ||
122 | has valid data, then it is discarded and a new item is created. This | ||
123 | saves any user of an item from worrying about content changing while | ||
124 | it is being inspected. If the item found by _lookup does not contain | ||
125 | valid data, then the content is copied across and CACHE_VALID is set. | ||
93 | 126 | ||
94 | Populating a cache | 127 | Populating a cache |
95 | ------------------ | 128 | ------------------ |
@@ -114,8 +147,8 @@ should be create or updated to have the given content, and the | |||
114 | expiry time should be set on that item. | 147 | expiry time should be set on that item. |
115 | 148 | ||
116 | Reading from a channel is a bit more interesting. When a cache | 149 | Reading from a channel is a bit more interesting. When a cache |
117 | lookup fail, or when it suceeds but finds an entry that may soon | 150 | lookup fails, or when it succeeds but finds an entry that may soon |
118 | expiry, a request is lodged for that cache item to be updated by | 151 | expire, a request is lodged for that cache item to be updated by |
119 | user-space. These requests appear in the channel file. | 152 | user-space. These requests appear in the channel file. |
120 | 153 | ||
121 | Successive reads will return successive requests. | 154 | Successive reads will return successive requests. |
@@ -130,7 +163,7 @@ Thus a user-space helper is likely to: | |||
130 | write a response | 163 | write a response |
131 | loop. | 164 | loop. |
132 | 165 | ||
133 | If it dies and needs to be restarted, any requests that have not be | 166 | If it dies and needs to be restarted, any requests that have not been |
134 | answered will still appear in the file and will be read by the new | 167 | answered will still appear in the file and will be read by the new |
135 | instance of the helper. | 168 | instance of the helper. |
136 | 169 | ||
@@ -142,10 +175,9 @@ Each cache should also define a "cache_request" method which | |||
142 | takes a cache item and encodes a request into the buffer | 175 | takes a cache item and encodes a request into the buffer |
143 | provided. | 176 | provided. |
144 | 177 | ||
145 | |||
146 | Note: If a cache has no active readers on the channel, and has had not | 178 | Note: If a cache has no active readers on the channel, and has had not |
147 | active readers for more than 60 seconds, further requests will not be | 179 | active readers for more than 60 seconds, further requests will not be |
148 | added to the channel but instead all looks that do not find a valid | 180 | added to the channel but instead all lookups that do not find a valid |
149 | entry will fail. This is partly for backward compatibility: The | 181 | entry will fail. This is partly for backward compatibility: The |
150 | previous nfs exports table was deemed to be authoritative and a | 182 | previous nfs exports table was deemed to be authoritative and a |
151 | failed lookup meant a definite 'no'. | 183 | failed lookup meant a definite 'no'. |
@@ -154,18 +186,17 @@ request/response format | |||
154 | ----------------------- | 186 | ----------------------- |
155 | 187 | ||
156 | While each cache is free to use it's own format for requests | 188 | While each cache is free to use it's own format for requests |
157 | and responses over channel, the following is recommended are | 189 | and responses over channel, the following is recommended as |
158 | appropriate and support routines are available to help: | 190 | appropriate and support routines are available to help: |
159 | Each request or response record should be printable ASCII | 191 | Each request or response record should be printable ASCII |
160 | with precisely one newline character which should be at the end. | 192 | with precisely one newline character which should be at the end. |
161 | Fields within the record should be separated by spaces, normally one. | 193 | Fields within the record should be separated by spaces, normally one. |
162 | If spaces, newlines, or nul characters are needed in a field they | 194 | If spaces, newlines, or nul characters are needed in a field they |
163 | much be quotes. two mechanisms are available: | 195 | much be quoted. two mechanisms are available: |
164 | 1/ If a field begins '\x' then it must contain an even number of | 196 | 1/ If a field begins '\x' then it must contain an even number of |
165 | hex digits, and pairs of these digits provide the bytes in the | 197 | hex digits, and pairs of these digits provide the bytes in the |
166 | field. | 198 | field. |
167 | 2/ otherwise a \ in the field must be followed by 3 octal digits | 199 | 2/ otherwise a \ in the field must be followed by 3 octal digits |
168 | which give the code for a byte. Other characters are treated | 200 | which give the code for a byte. Other characters are treated |
169 | as them selves. At the very least, space, newlines nul, and | 201 | as them selves. At the very least, space, newline, nul, and |
170 | '\' must be quoted in this way. | 202 | '\' must be quoted in this way. |
171 | |||