aboutsummaryrefslogtreecommitdiffstats
path: root/Documentation
diff options
context:
space:
mode:
authorNeilBrown <neilb@suse.de>2006-03-27 04:15:12 -0500
committerLinus Torvalds <torvalds@g5.osdl.org>2006-03-27 11:44:43 -0500
commit491214716755894986b99e0cf0a08b830d244577 (patch)
treefb23b729de181f6ea13bc9e5f4f778ca8a0b0e4a /Documentation
parentad1b5229def92b71631a927895b034ceec06c991 (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.txt121
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 @@
1This document gives a brief introduction to the caching 1 This document gives a brief introduction to the caching
2mechanisms in the sunrpc layer that is used, in particular, 2mechanisms in the sunrpc layer that is used, in particular,
3for NFS authentication. 3for 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
38The code for performing a cache lookup is also common, but in the form
39of a template. i.e. a #define.
40Each cache defines a lookup function by using the DefineCacheLookup
41macro, or the simpler DefineSimpleCacheLookup macro
42 34
43Creating a Cache 35Creating a Cache
44---------------- 36----------------
45 37
461/ A cache needs a datum to cache. This is in the form of a 381/ 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.
532/ A cache needs a "cache_detail" structure that 452/ 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
563/ 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 *)
634/ 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
913/ 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
68Using a cache 95Using a cache
69------------- 96-------------
70 97
71To find a value in a cache, call the lookup function passing it a the 98To find a value in a cache, call sunrpc_cache_lookup passing a pointer
72datum which contains key, and possibly content, and a flag saying 99to the cache_head in a sample item with the 'key' fields filled in.
73whether to update the cache with new data from the datum. Depending 100This will be passed to ->match to identify the target entry. If no
74on how the cache lookup function was defined, it may take an extra 101entry is found, a new entry will be create, added to the cache, and
75argument to identify the particular cache in question. 102marked as not containing valid data.
76 103
77Except in cases of kmalloc failure, the lookup function 104The item returned is typically passed to cache_check which will check
78will return a new datum which will store the key and 105if the data is valid, and may initiate an up-call to get fresh data.
79may contain valid content, or may not. 106cache_check will return -ENOENT in the entry is negative or if an up
80This datum is typically passed to cache_check which determines the 107call is needed but not possible, -EAGAIN if an upcall is pending,
81validity of the datum and may later initiate an upcall to fill 108or 0 if the data is valid;
82in the data.
83 109
84cache_check can be passed a "struct cache_req *". This structure is 110cache_check can be passed a "struct cache_req *". This structure is
85typically embedded in the actual request and can be used to create a 111typically 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
90revisited (->revisit). It is expected that this method will 116revisited (->revisit). It is expected that this method will
91reschedule the request for processing. 117reschedule the request for processing.
92 118
119The value returned by sunrpc_cache_lookup can also be passed to
120sunrpc_cache_update to set the content for the item. A second item is
121passed which should hold the content. If the item found by _lookup
122has valid data, then it is discarded and a new item is created. This
123saves any user of an item from worrying about content changing while
124it is being inspected. If the item found by _lookup does not contain
125valid data, then the content is copied across and CACHE_VALID is set.
93 126
94Populating a cache 127Populating a cache
95------------------ 128------------------
@@ -114,8 +147,8 @@ should be create or updated to have the given content, and the
114expiry time should be set on that item. 147expiry time should be set on that item.
115 148
116Reading from a channel is a bit more interesting. When a cache 149Reading from a channel is a bit more interesting. When a cache
117lookup fail, or when it suceeds but finds an entry that may soon 150lookup fails, or when it succeeds but finds an entry that may soon
118expiry, a request is lodged for that cache item to be updated by 151expire, a request is lodged for that cache item to be updated by
119user-space. These requests appear in the channel file. 152user-space. These requests appear in the channel file.
120 153
121Successive reads will return successive requests. 154Successive 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
133If it dies and needs to be restarted, any requests that have not be 166If it dies and needs to be restarted, any requests that have not been
134answered will still appear in the file and will be read by the new 167answered will still appear in the file and will be read by the new
135instance of the helper. 168instance of the helper.
136 169
@@ -142,10 +175,9 @@ Each cache should also define a "cache_request" method which
142takes a cache item and encodes a request into the buffer 175takes a cache item and encodes a request into the buffer
143provided. 176provided.
144 177
145
146Note: If a cache has no active readers on the channel, and has had not 178Note: If a cache has no active readers on the channel, and has had not
147active readers for more than 60 seconds, further requests will not be 179active readers for more than 60 seconds, further requests will not be
148added to the channel but instead all looks that do not find a valid 180added to the channel but instead all lookups that do not find a valid
149entry will fail. This is partly for backward compatibility: The 181entry will fail. This is partly for backward compatibility: The
150previous nfs exports table was deemed to be authoritative and a 182previous nfs exports table was deemed to be authoritative and a
151failed lookup meant a definite 'no'. 183failed lookup meant a definite 'no'.
@@ -154,18 +186,17 @@ request/response format
154----------------------- 186-----------------------
155 187
156While each cache is free to use it's own format for requests 188While each cache is free to use it's own format for requests
157and responses over channel, the following is recommended are 189and responses over channel, the following is recommended as
158appropriate and support routines are available to help: 190appropriate and support routines are available to help:
159Each request or response record should be printable ASCII 191Each request or response record should be printable ASCII
160with precisely one newline character which should be at the end. 192with precisely one newline character which should be at the end.
161Fields within the record should be separated by spaces, normally one. 193Fields within the record should be separated by spaces, normally one.
162If spaces, newlines, or nul characters are needed in a field they 194If spaces, newlines, or nul characters are needed in a field they
163much be quotes. two mechanisms are available: 195much be quoted. two mechanisms are available:
1641/ If a field begins '\x' then it must contain an even number of 1961/ 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.
1672/ otherwise a \ in the field must be followed by 3 octal digits 1992/ 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