summaryrefslogtreecommitdiffstats
path: root/include/linux/fscache.h
diff options
context:
space:
mode:
authorDavid Howells <dhowells@redhat.com>2018-04-04 08:41:28 -0400
committerDavid Howells <dhowells@redhat.com>2018-04-04 08:41:28 -0400
commit402cb8dda949d9b8c0df20ad2527d139faad7ca1 (patch)
tree83cdb77f5490a0990eade886aa7f8dd087864996 /include/linux/fscache.h
parent08c2e3d087840cd1e7141b62d92f3dc897147984 (diff)
fscache: Attach the index key and aux data to the cookie
Attach copies of the index key and auxiliary data to the fscache cookie so that: (1) The callbacks to the netfs for this stuff can be eliminated. This can simplify things in the cache as the information is still available, even after the cache has relinquished the cookie. (2) Simplifies the locking requirements of accessing the information as we don't have to worry about the netfs object going away on us. (3) The cache can do lazy updating of the coherency information on disk. As long as the cache is flushed before reboot/poweroff, there's no need to update the coherency info on disk every time it changes. (4) Cookies can be hashed or put in a tree as the index key is easily available. This allows: (a) Checks for duplicate cookies can be made at the top fscache layer rather than down in the bowels of the cache backend. (b) Caching can be added to a netfs object that has a cookie if the cache is brought online after the netfs object is allocated. A certain amount of space is made in the cookie for inline copies of the data, but if it won't fit there, extra memory will be allocated for it. The downside of this is that live cache operation requires more memory. Signed-off-by: David Howells <dhowells@redhat.com> Acked-by: Anna Schumaker <anna.schumaker@netapp.com> Tested-by: Steve Dickson <steved@redhat.com>
Diffstat (limited to 'include/linux/fscache.h')
-rw-r--r--include/linux/fscache.h110
1 files changed, 65 insertions, 45 deletions
diff --git a/include/linux/fscache.h b/include/linux/fscache.h
index fe0c349684fa..a2d3a2116248 100644
--- a/include/linux/fscache.h
+++ b/include/linux/fscache.h
@@ -83,17 +83,6 @@ struct fscache_cookie_def {
83 const void *parent_netfs_data, 83 const void *parent_netfs_data,
84 const void *cookie_netfs_data); 84 const void *cookie_netfs_data);
85 85
86 /* get an index key
87 * - should store the key data in the buffer
88 * - should return the amount of data stored
89 * - not permitted to return an error
90 * - the netfs data from the cookie being used as the source is
91 * presented
92 */
93 uint16_t (*get_key)(const void *cookie_netfs_data,
94 void *buffer,
95 uint16_t bufmax);
96
97 /* get certain file attributes from the netfs data 86 /* get certain file attributes from the netfs data
98 * - this function can be absent for an index 87 * - this function can be absent for an index
99 * - not permitted to return an error 88 * - not permitted to return an error
@@ -102,18 +91,6 @@ struct fscache_cookie_def {
102 */ 91 */
103 void (*get_attr)(const void *cookie_netfs_data, uint64_t *size); 92 void (*get_attr)(const void *cookie_netfs_data, uint64_t *size);
104 93
105 /* get the auxiliary data from netfs data
106 * - this function can be absent if the index carries no state data
107 * - should store the auxiliary data in the buffer
108 * - should return the amount of amount stored
109 * - not permitted to return an error
110 * - the netfs data from the cookie being used as the source is
111 * presented
112 */
113 uint16_t (*get_aux)(const void *cookie_netfs_data,
114 void *buffer,
115 uint16_t bufmax);
116
117 /* consult the netfs about the state of an object 94 /* consult the netfs about the state of an object
118 * - this function can be absent if the index carries no state data 95 * - this function can be absent if the index carries no state data
119 * - the netfs data from the cookie being used as the target is 96 * - the netfs data from the cookie being used as the target is
@@ -186,6 +163,19 @@ struct fscache_cookie {
186#define FSCACHE_COOKIE_RELINQUISHED 4 /* T if cookie has been relinquished */ 163#define FSCACHE_COOKIE_RELINQUISHED 4 /* T if cookie has been relinquished */
187#define FSCACHE_COOKIE_ENABLED 5 /* T if cookie is enabled */ 164#define FSCACHE_COOKIE_ENABLED 5 /* T if cookie is enabled */
188#define FSCACHE_COOKIE_ENABLEMENT_LOCK 6 /* T if cookie is being en/disabled */ 165#define FSCACHE_COOKIE_ENABLEMENT_LOCK 6 /* T if cookie is being en/disabled */
166#define FSCACHE_COOKIE_AUX_UPDATED 7 /* T if the auxiliary data was updated */
167
168 u8 type; /* Type of object */
169 u8 key_len; /* Length of index key */
170 u8 aux_len; /* Length of auxiliary data */
171 union {
172 void *key; /* Index key */
173 u8 inline_key[16]; /* - If the key is short enough */
174 };
175 union {
176 void *aux; /* Auxiliary data */
177 u8 inline_aux[8]; /* - If the aux data is short enough */
178 };
189}; 179};
190 180
191static inline bool fscache_cookie_enabled(struct fscache_cookie *cookie) 181static inline bool fscache_cookie_enabled(struct fscache_cookie *cookie)
@@ -208,10 +198,12 @@ extern void __fscache_release_cache_tag(struct fscache_cache_tag *);
208extern struct fscache_cookie *__fscache_acquire_cookie( 198extern struct fscache_cookie *__fscache_acquire_cookie(
209 struct fscache_cookie *, 199 struct fscache_cookie *,
210 const struct fscache_cookie_def *, 200 const struct fscache_cookie_def *,
201 const void *, size_t,
202 const void *, size_t,
211 void *, bool); 203 void *, bool);
212extern void __fscache_relinquish_cookie(struct fscache_cookie *, bool); 204extern void __fscache_relinquish_cookie(struct fscache_cookie *, const void *, bool);
213extern int __fscache_check_consistency(struct fscache_cookie *); 205extern int __fscache_check_consistency(struct fscache_cookie *, const void *);
214extern void __fscache_update_cookie(struct fscache_cookie *); 206extern void __fscache_update_cookie(struct fscache_cookie *, const void *);
215extern int __fscache_attr_changed(struct fscache_cookie *); 207extern int __fscache_attr_changed(struct fscache_cookie *);
216extern void __fscache_invalidate(struct fscache_cookie *); 208extern void __fscache_invalidate(struct fscache_cookie *);
217extern void __fscache_wait_on_invalidate(struct fscache_cookie *); 209extern void __fscache_wait_on_invalidate(struct fscache_cookie *);
@@ -238,8 +230,8 @@ extern void __fscache_uncache_all_inode_pages(struct fscache_cookie *,
238 struct inode *); 230 struct inode *);
239extern void __fscache_readpages_cancel(struct fscache_cookie *cookie, 231extern void __fscache_readpages_cancel(struct fscache_cookie *cookie,
240 struct list_head *pages); 232 struct list_head *pages);
241extern void __fscache_disable_cookie(struct fscache_cookie *, bool); 233extern void __fscache_disable_cookie(struct fscache_cookie *, const void *, bool);
242extern void __fscache_enable_cookie(struct fscache_cookie *, 234extern void __fscache_enable_cookie(struct fscache_cookie *, const void *,
243 bool (*)(void *), void *); 235 bool (*)(void *), void *);
244 236
245/** 237/**
@@ -317,6 +309,10 @@ void fscache_release_cache_tag(struct fscache_cache_tag *tag)
317 * fscache_acquire_cookie - Acquire a cookie to represent a cache object 309 * fscache_acquire_cookie - Acquire a cookie to represent a cache object
318 * @parent: The cookie that's to be the parent of this one 310 * @parent: The cookie that's to be the parent of this one
319 * @def: A description of the cache object, including callback operations 311 * @def: A description of the cache object, including callback operations
312 * @index_key: The index key for this cookie
313 * @index_key_len: Size of the index key
314 * @aux_data: The auxiliary data for the cookie (may be NULL)
315 * @aux_data_len: Size of the auxiliary data buffer
320 * @netfs_data: An arbitrary piece of data to be kept in the cookie to 316 * @netfs_data: An arbitrary piece of data to be kept in the cookie to
321 * represent the cache object to the netfs 317 * represent the cache object to the netfs
322 * @enable: Whether or not to enable a data cookie immediately 318 * @enable: Whether or not to enable a data cookie immediately
@@ -332,12 +328,18 @@ static inline
332struct fscache_cookie *fscache_acquire_cookie( 328struct fscache_cookie *fscache_acquire_cookie(
333 struct fscache_cookie *parent, 329 struct fscache_cookie *parent,
334 const struct fscache_cookie_def *def, 330 const struct fscache_cookie_def *def,
331 const void *index_key,
332 size_t index_key_len,
333 const void *aux_data,
334 size_t aux_data_len,
335 void *netfs_data, 335 void *netfs_data,
336 bool enable) 336 bool enable)
337{ 337{
338 if (fscache_cookie_valid(parent) && fscache_cookie_enabled(parent)) 338 if (fscache_cookie_valid(parent) && fscache_cookie_enabled(parent))
339 return __fscache_acquire_cookie(parent, def, netfs_data, 339 return __fscache_acquire_cookie(parent, def,
340 enable); 340 index_key, index_key_len,
341 aux_data, aux_data_len,
342 netfs_data, enable);
341 else 343 else
342 return NULL; 344 return NULL;
343} 345}
@@ -346,36 +348,44 @@ struct fscache_cookie *fscache_acquire_cookie(
346 * fscache_relinquish_cookie - Return the cookie to the cache, maybe discarding 348 * fscache_relinquish_cookie - Return the cookie to the cache, maybe discarding
347 * it 349 * it
348 * @cookie: The cookie being returned 350 * @cookie: The cookie being returned
351 * @aux_data: The updated auxiliary data for the cookie (may be NULL)
349 * @retire: True if the cache object the cookie represents is to be discarded 352 * @retire: True if the cache object the cookie represents is to be discarded
350 * 353 *
351 * This function returns a cookie to the cache, forcibly discarding the 354 * This function returns a cookie to the cache, forcibly discarding the
352 * associated cache object if retire is set to true. 355 * associated cache object if retire is set to true. The opportunity is
356 * provided to update the auxiliary data in the cache before the object is
357 * disconnected.
353 * 358 *
354 * See Documentation/filesystems/caching/netfs-api.txt for a complete 359 * See Documentation/filesystems/caching/netfs-api.txt for a complete
355 * description. 360 * description.
356 */ 361 */
357static inline 362static inline
358void fscache_relinquish_cookie(struct fscache_cookie *cookie, bool retire) 363void fscache_relinquish_cookie(struct fscache_cookie *cookie,
364 const void *aux_data,
365 bool retire)
359{ 366{
360 if (fscache_cookie_valid(cookie)) 367 if (fscache_cookie_valid(cookie))
361 __fscache_relinquish_cookie(cookie, retire); 368 __fscache_relinquish_cookie(cookie, aux_data, retire);
362} 369}
363 370
364/** 371/**
365 * fscache_check_consistency - Request that if the cache is updated 372 * fscache_check_consistency - Request validation of a cache's auxiliary data
366 * @cookie: The cookie representing the cache object 373 * @cookie: The cookie representing the cache object
374 * @aux_data: The updated auxiliary data for the cookie (may be NULL)
367 * 375 *
368 * Request an consistency check from fscache, which passes the request 376 * Request an consistency check from fscache, which passes the request to the
369 * to the backing cache. 377 * backing cache. The auxiliary data on the cookie will be updated first if
378 * @aux_data is set.
370 * 379 *
371 * Returns 0 if consistent and -ESTALE if inconsistent. May also 380 * Returns 0 if consistent and -ESTALE if inconsistent. May also
372 * return -ENOMEM and -ERESTARTSYS. 381 * return -ENOMEM and -ERESTARTSYS.
373 */ 382 */
374static inline 383static inline
375int fscache_check_consistency(struct fscache_cookie *cookie) 384int fscache_check_consistency(struct fscache_cookie *cookie,
385 const void *aux_data)
376{ 386{
377 if (fscache_cookie_valid(cookie) && fscache_cookie_enabled(cookie)) 387 if (fscache_cookie_valid(cookie) && fscache_cookie_enabled(cookie))
378 return __fscache_check_consistency(cookie); 388 return __fscache_check_consistency(cookie, aux_data);
379 else 389 else
380 return 0; 390 return 0;
381} 391}
@@ -383,18 +393,20 @@ int fscache_check_consistency(struct fscache_cookie *cookie)
383/** 393/**
384 * fscache_update_cookie - Request that a cache object be updated 394 * fscache_update_cookie - Request that a cache object be updated
385 * @cookie: The cookie representing the cache object 395 * @cookie: The cookie representing the cache object
396 * @aux_data: The updated auxiliary data for the cookie (may be NULL)
386 * 397 *
387 * Request an update of the index data for the cache object associated with the 398 * Request an update of the index data for the cache object associated with the
388 * cookie. 399 * cookie. The auxiliary data on the cookie will be updated first if @aux_data
400 * is set.
389 * 401 *
390 * See Documentation/filesystems/caching/netfs-api.txt for a complete 402 * See Documentation/filesystems/caching/netfs-api.txt for a complete
391 * description. 403 * description.
392 */ 404 */
393static inline 405static inline
394void fscache_update_cookie(struct fscache_cookie *cookie) 406void fscache_update_cookie(struct fscache_cookie *cookie, const void *aux_data)
395{ 407{
396 if (fscache_cookie_valid(cookie) && fscache_cookie_enabled(cookie)) 408 if (fscache_cookie_valid(cookie) && fscache_cookie_enabled(cookie))
397 __fscache_update_cookie(cookie); 409 __fscache_update_cookie(cookie, aux_data);
398} 410}
399 411
400/** 412/**
@@ -780,6 +792,7 @@ void fscache_uncache_all_inode_pages(struct fscache_cookie *cookie,
780/** 792/**
781 * fscache_disable_cookie - Disable a cookie 793 * fscache_disable_cookie - Disable a cookie
782 * @cookie: The cookie representing the cache object 794 * @cookie: The cookie representing the cache object
795 * @aux_data: The updated auxiliary data for the cookie (may be NULL)
783 * @invalidate: Invalidate the backing object 796 * @invalidate: Invalidate the backing object
784 * 797 *
785 * Disable a cookie from accepting further alloc, read, write, invalidate, 798 * Disable a cookie from accepting further alloc, read, write, invalidate,
@@ -790,34 +803,41 @@ void fscache_uncache_all_inode_pages(struct fscache_cookie *cookie,
790 * 803 *
791 * If @invalidate is set, then the backing object will be invalidated and 804 * If @invalidate is set, then the backing object will be invalidated and
792 * detached, otherwise it will just be detached. 805 * detached, otherwise it will just be detached.
806 *
807 * If @aux_data is set, then auxiliary data will be updated from that.
793 */ 808 */
794static inline 809static inline
795void fscache_disable_cookie(struct fscache_cookie *cookie, bool invalidate) 810void fscache_disable_cookie(struct fscache_cookie *cookie,
811 const void *aux_data,
812 bool invalidate)
796{ 813{
797 if (fscache_cookie_valid(cookie) && fscache_cookie_enabled(cookie)) 814 if (fscache_cookie_valid(cookie) && fscache_cookie_enabled(cookie))
798 __fscache_disable_cookie(cookie, invalidate); 815 __fscache_disable_cookie(cookie, aux_data, invalidate);
799} 816}
800 817
801/** 818/**
802 * fscache_enable_cookie - Reenable a cookie 819 * fscache_enable_cookie - Reenable a cookie
803 * @cookie: The cookie representing the cache object 820 * @cookie: The cookie representing the cache object
821 * @aux_data: The updated auxiliary data for the cookie (may be NULL)
804 * @can_enable: A function to permit enablement once lock is held 822 * @can_enable: A function to permit enablement once lock is held
805 * @data: Data for can_enable() 823 * @data: Data for can_enable()
806 * 824 *
807 * Reenable a previously disabled cookie, allowing it to accept further alloc, 825 * Reenable a previously disabled cookie, allowing it to accept further alloc,
808 * read, write, invalidate, update or acquire operations. An attempt will be 826 * read, write, invalidate, update or acquire operations. An attempt will be
809 * made to immediately reattach the cookie to a backing object. 827 * made to immediately reattach the cookie to a backing object. If @aux_data
828 * is set, the auxiliary data attached to the cookie will be updated.
810 * 829 *
811 * The can_enable() function is called (if not NULL) once the enablement lock 830 * The can_enable() function is called (if not NULL) once the enablement lock
812 * is held to rule on whether enablement is still permitted to go ahead. 831 * is held to rule on whether enablement is still permitted to go ahead.
813 */ 832 */
814static inline 833static inline
815void fscache_enable_cookie(struct fscache_cookie *cookie, 834void fscache_enable_cookie(struct fscache_cookie *cookie,
835 const void *aux_data,
816 bool (*can_enable)(void *data), 836 bool (*can_enable)(void *data),
817 void *data) 837 void *data)
818{ 838{
819 if (fscache_cookie_valid(cookie) && !fscache_cookie_enabled(cookie)) 839 if (fscache_cookie_valid(cookie) && !fscache_cookie_enabled(cookie))
820 __fscache_enable_cookie(cookie, can_enable, data); 840 __fscache_enable_cookie(cookie, aux_data, can_enable, data);
821} 841}
822 842
823#endif /* _LINUX_FSCACHE_H */ 843#endif /* _LINUX_FSCACHE_H */