@@ -129,12 +129,10 @@ To define an object, a structure of the following type should be filled out:
129129 const void *parent_netfs_data,
130130 const void *cookie_netfs_data);
131131
132- void (*get_attr)(const void *cookie_netfs_data,
133- uint64_t *size);
134-
135132 enum fscache_checkaux (*check_aux)(void *cookie_netfs_data,
136133 const void *data,
137- uint16_t datalen);
134+ uint16_t datalen,
135+ loff_t object_size);
138136
139137 void (*get_context)(void *cookie_netfs_data, void *context);
140138
@@ -179,16 +177,7 @@ This has the following fields:
179177 cache in the parent's list will be chosen, or failing that, the first
180178 cache in the master list.
181179
182- (4) A function to retrieve attribute data from the netfs [optional].
183-
184- This function will be called with the netfs data that was passed to the
185- cookie acquisition function. It should return the size of the file if
186- this is a data file. The size may be used to govern how much cache must
187- be reserved for this file in the cache.
188-
189- If the function is absent, a file size of 0 is assumed.
190-
191- (5) A function to check the auxiliary data [optional].
180+ (4) A function to check the auxiliary data [optional].
192181
193182 This function will be called to check that a match found in the cache for
194183 this object is valid. For instance with AFS it could check the auxiliary
@@ -198,6 +187,9 @@ This has the following fields:
198187 If this function is absent, it will be assumed that matching objects in a
199188 cache are always valid.
200189
190+ The function is also passed the cache's idea of the object size and may
191+ use this to manage coherency also.
192+
201193 If present, the function should return one of the following values:
202194
203195 (*) FSCACHE_CHECKAUX_OKAY - the entry is okay as is
@@ -207,7 +199,7 @@ This has the following fields:
207199 This function can also be used to extract data from the auxiliary data in
208200 the cache and copy it into the netfs's structures.
209201
210- (6 ) A pair of functions to manage contexts for the completion callback
202+ (5 ) A pair of functions to manage contexts for the completion callback
211203 [optional].
212204
213205 The cache read/write functions are passed a context which is then passed
@@ -221,7 +213,7 @@ This has the following fields:
221213 required for indices as indices may not contain data. These functions may
222214 be called in interrupt context and so may not sleep.
223215
224- (7 ) A function to mark a page as retaining cache metadata [optional].
216+ (6 ) A function to mark a page as retaining cache metadata [optional].
225217
226218 This is called by the cache to indicate that it is retaining in-memory
227219 information for this page and that the netfs should uncache the page when
@@ -233,7 +225,7 @@ This has the following fields:
233225
234226 This function is not required for indices as they're not permitted data.
235227
236- (8 ) A function to unmark all the pages retaining cache metadata [mandatory].
228+ (7 ) A function to unmark all the pages retaining cache metadata [mandatory].
237229
238230 This is called by FS-Cache to indicate that a backing store is being
239231 unbound from a cookie and that all the marks on the pages should be
@@ -310,6 +302,7 @@ the path to the file:
310302 const void *aux_data,
311303 size_t aux_data_len,
312304 void *netfs_data,
305+ loff_t object_size,
313306 bool enable);
314307
315308This function creates an index entry in the index represented by parent,
@@ -326,6 +319,10 @@ The netfs may pass an arbitrary value in netfs_data and this will be presented
326319to it in the event of any calling back. This may also be used in tracing or
327320logging of messages.
328321
322+ The cache tracks the size of the data attached to an object and this set to be
323+ object_size. For indices, this should be 0. This value will be passed to the
324+ ->check_aux() callback.
325+
329326Note that this function never returns an error - all errors are handled
330327internally. It may, however, return NULL to indicate no cookie. It is quite
331328acceptable to pass this token back to this function as the parent to another
@@ -349,7 +346,7 @@ entry would have a dependent inode containing volume mappings within this cell:
349346 &afs_cell_cache_index_def,
350347 cell->name, strlen(cell->name),
351348 NULL, 0,
352- cell, true);
349+ cell, 0, true);
353350
354351And then a particular volume could be added to that index by ID, creating
355352another index for vnodes (AFS inode equivalents):
@@ -359,7 +356,7 @@ another index for vnodes (AFS inode equivalents):
359356 &afs_volume_cache_index_def,
360357 &volume->vid, sizeof(volume->vid),
361358 NULL, 0,
362- volume, true);
359+ volume, 0, true);
363360
364361
365362======================
@@ -375,7 +372,7 @@ the object definition should be something other than index type.
375372 &afs_vnode_cache_object_def,
376373 &key, sizeof(key),
377374 &aux, sizeof(aux),
378- vnode, true);
375+ vnode, vnode->status.size, true);
379376
380377
381378=================================
@@ -393,7 +390,7 @@ it would be some other type of object such as a data file.
393390 &afs_xattr_cache_object_def,
394391 &xattr->name, strlen(xattr->name),
395392 NULL, 0,
396- xattr, true);
393+ xattr, strlen(xattr->val), true);
397394
398395Miscellaneous objects might be used to store extended attributes or directory
399396entries for example.
@@ -410,8 +407,7 @@ cache to adjust its metadata for data tracking appropriately:
410407 int fscache_attr_changed(struct fscache_cookie *cookie);
411408
412409The cache will return -ENOBUFS if there is no backing cache or if there is no
413- space to allocate any extra metadata required in the cache. The attributes
414- will be accessed with the get_attr() cookie definition operation.
410+ space to allocate any extra metadata required in the cache.
415411
416412Note that attempts to read or write data pages in the cache over this size may
417413be rebuffed with -ENOBUFS.
@@ -536,12 +532,13 @@ written back to the cache:
536532
537533 int fscache_write_page(struct fscache_cookie *cookie,
538534 struct page *page,
535+ loff_t object_size,
539536 gfp_t gfp);
540537
541538The cookie argument must specify a data file cookie, the page specified should
542539contain the data to be written (and is also used to specify the page number),
543- and the gfp argument is used to control how any memory allocations made are
544- satisfied.
540+ object_size is the revised size of the object and the gfp argument is used to
541+ control how any memory allocations made are satisfied.
545542
546543The page must have first been read or allocated successfully and must not have
547544been uncached before writing is performed.
@@ -735,11 +732,11 @@ still possible to uncache pages and relinquish the cookie.
735732
736733The initial enablement state is set by fscache_acquire_cookie(), but the cookie
737734can be enabled or disabled later. To disable a cookie, call:
738-
735+
739736 void fscache_disable_cookie(struct fscache_cookie *cookie,
740737 const void *aux_data,
741738 bool invalidate);
742-
739+
743740If the cookie is not already disabled, this locks the cookie against other
744741enable and disable ops, marks the cookie as being disabled, discards or
745742invalidates any backing objects and waits for cessation of activity on any
@@ -748,14 +745,15 @@ associated object before unlocking the cookie.
748745All possible failures are handled internally. The caller should consider
749746calling fscache_uncache_all_inode_pages() afterwards to make sure all page
750747markings are cleared up.
751-
748+
752749Cookies can be enabled or reenabled with:
753-
750+
754751 void fscache_enable_cookie(struct fscache_cookie *cookie,
755752 const void *aux_data,
753+ loff_t object_size,
756754 bool (*can_enable)(void *data),
757755 void *data)
758-
756+
759757If the cookie is not already enabled, this locks the cookie against other
760758enable and disable ops, invokes can_enable() and, if the cookie is not an index
761759cookie, will begin the procedure of acquiring backing objects.
@@ -766,6 +764,9 @@ ruling as to whether or not enablement should actually be permitted to begin.
766764All possible failures are handled internally. The cookie will only be marked
767765as enabled if provisional backing objects are allocated.
768766
767+ The object's data size is updated from object_size and is passed to the
768+ ->check_aux() function.
769+
769770In both cases, the cookie's auxiliary data buffer is updated from aux_data if
770771that is non-NULL inside the enablement lock before proceeding.
771772
0 commit comments