Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge tag 'fscache-next-20180406' of git://git.kernel.org/pub/scm/linux/kernel/git/dhowells/linux-fs

Pull fscache updates from David Howells:
"Three patches that fix some of AFS's usage of fscache:

(1) Need to invalidate the cache if a foreign data change is detected
on the server.

(2) Move the vnode ID uniquifier (equivalent to i_generation) from
the auxiliary data to the index key to prevent a race between
file delete and a subsequent file create seeing the same index
key.

(3) Need to retire cookies that correspond to files that we think got
deleted on the server.

Four patches to fix some things in fscache and cachefiles:

(4) Fix a couple of checker warnings.

(5) Correctly indicate to the end-of-operation callback whether an
operation completed or was cancelled.

(6) Add a check for multiple cookie relinquishment.

(7) Fix a path through the asynchronous write that doesn't wake up a
waiter for a page if the cache decides not to write that page,
but discards it instead.

A couple of patches to add tracepoints to fscache and cachefiles:

(8) Add tracepoints for cookie operators, object state machine
execution, cachefiles object management and cachefiles VFS
operations.

(9) Add tracepoints for fscache operation management and page
wrangling.

And then three development patches:

(10) Attach the index key and auxiliary data to the cookie, pass this
information through various fscache-netfs API functions and get
rid of the callbacks to the netfs to get it.

This means that the cache can get at this information, even if
the netfs goes away. It also means that the cache can be lazy in
updating the coherency data.

(11) Pass the object data size through various fscache-netfs API
rather than calling back to the netfs for it, and store the value
in the object.

This makes it easier to correctly resize the object, as the size
is updated on writes to the cache, rather than calling back out
to the netfs.

(12) Maintain a catalogue of allocated cookies. This makes it possible
to catch cookie collision up front rather than down in the bowels
of the cache being run from a service thread from the object
state machine.

This will also make it possible in the future to reconnect to a
cookie that's not gone dead yet because it's waiting for
finalisation of the storage and also make it possible to bring
cookies online if the cache is added after the cookie has been
obtained"

* tag 'fscache-next-20180406' of git://git.kernel.org/pub/scm/linux/kernel/git/dhowells/linux-fs:
fscache: Maintain a catalogue of allocated cookies
fscache: Pass object size in rather than calling back for it
fscache: Attach the index key and aux data to the cookie
fscache: Add more tracepoints
fscache: Add tracepoints
fscache: Fix hanging wait on page discarded by writeback
fscache: Detect multiple relinquishment of a cookie
fscache: Pass the correct cancelled indications to fscache_op_complete()
fscache, cachefiles: Fix checker warnings
afs: Be more aggressive in retiring cached vnodes
afs: Use the vnode ID uniquifier in the cache key not the aux data
afs: Invalidate cache on server data change

+2030 -1082
+77 -80
Documentation/filesystems/caching/netfs-api.txt
··· 129 129 const void *parent_netfs_data, 130 130 const void *cookie_netfs_data); 131 131 132 - uint16_t (*get_key)(const void *cookie_netfs_data, 133 - void *buffer, 134 - uint16_t bufmax); 135 - 136 - void (*get_attr)(const void *cookie_netfs_data, 137 - uint64_t *size); 138 - 139 - uint16_t (*get_aux)(const void *cookie_netfs_data, 140 - void *buffer, 141 - uint16_t bufmax); 142 - 143 132 enum fscache_checkaux (*check_aux)(void *cookie_netfs_data, 144 133 const void *data, 145 - uint16_t datalen); 134 + uint16_t datalen, 135 + loff_t object_size); 146 136 147 137 void (*get_context)(void *cookie_netfs_data, void *context); 148 138 ··· 177 187 cache in the parent's list will be chosen, or failing that, the first 178 188 cache in the master list. 179 189 180 - (4) A function to retrieve an object's key from the netfs [mandatory]. 181 - 182 - This function will be called with the netfs data that was passed to the 183 - cookie acquisition function and the maximum length of key data that it may 184 - provide. It should write the required key data into the given buffer and 185 - return the quantity it wrote. 186 - 187 - (5) A function to retrieve attribute data from the netfs [optional]. 188 - 189 - This function will be called with the netfs data that was passed to the 190 - cookie acquisition function. It should return the size of the file if 191 - this is a data file. The size may be used to govern how much cache must 192 - be reserved for this file in the cache. 193 - 194 - If the function is absent, a file size of 0 is assumed. 195 - 196 - (6) A function to retrieve auxiliary data from the netfs [optional]. 197 - 198 - This function will be called with the netfs data that was passed to the 199 - cookie acquisition function and the maximum length of auxiliary data that 200 - it may provide. It should write the auxiliary data into the given buffer 201 - and return the quantity it wrote. 202 - 203 - If this function is absent, the auxiliary data length will be set to 0. 204 - 205 - The length of the auxiliary data buffer may be dependent on the key 206 - length. A netfs mustn't rely on being able to provide more than 400 bytes 207 - for both. 208 - 209 - (7) A function to check the auxiliary data [optional]. 190 + (4) A function to check the auxiliary data [optional]. 210 191 211 192 This function will be called to check that a match found in the cache for 212 193 this object is valid. For instance with AFS it could check the auxiliary ··· 186 225 187 226 If this function is absent, it will be assumed that matching objects in a 188 227 cache are always valid. 228 + 229 + The function is also passed the cache's idea of the object size and may 230 + use this to manage coherency also. 189 231 190 232 If present, the function should return one of the following values: 191 233 ··· 199 235 This function can also be used to extract data from the auxiliary data in 200 236 the cache and copy it into the netfs's structures. 201 237 202 - (8) A pair of functions to manage contexts for the completion callback 238 + (5) A pair of functions to manage contexts for the completion callback 203 239 [optional]. 204 240 205 241 The cache read/write functions are passed a context which is then passed ··· 213 249 required for indices as indices may not contain data. These functions may 214 250 be called in interrupt context and so may not sleep. 215 251 216 - (9) A function to mark a page as retaining cache metadata [optional]. 252 + (6) A function to mark a page as retaining cache metadata [optional]. 217 253 218 254 This is called by the cache to indicate that it is retaining in-memory 219 255 information for this page and that the netfs should uncache the page when ··· 225 261 226 262 This function is not required for indices as they're not permitted data. 227 263 228 - (10) A function to unmark all the pages retaining cache metadata [mandatory]. 264 + (7) A function to unmark all the pages retaining cache metadata [mandatory]. 229 265 230 266 This is called by FS-Cache to indicate that a backing store is being 231 267 unbound from a cookie and that all the marks on the pages should be ··· 297 333 struct fscache_cookie * 298 334 fscache_acquire_cookie(struct fscache_cookie *parent, 299 335 const struct fscache_object_def *def, 336 + const void *index_key, 337 + size_t index_key_len, 338 + const void *aux_data, 339 + size_t aux_data_len, 300 340 void *netfs_data, 341 + loff_t object_size, 301 342 bool enable); 302 343 303 344 This function creates an index entry in the index represented by parent, 304 345 filling in the index entry by calling the operations pointed to by def. 346 + 347 + A unique key that represents the object within the parent must be pointed to by 348 + index_key and is of length index_key_len. 349 + 350 + An optional blob of auxiliary data that is to be stored within the cache can be 351 + pointed to with aux_data and should be of length aux_data_len. This would 352 + typically be used for storing coherency data. 353 + 354 + The netfs may pass an arbitrary value in netfs_data and this will be presented 355 + to it in the event of any calling back. This may also be used in tracing or 356 + logging of messages. 357 + 358 + The cache tracks the size of the data attached to an object and this set to be 359 + object_size. For indices, this should be 0. This value will be passed to the 360 + ->check_aux() callback. 305 361 306 362 Note that this function never returns an error - all errors are handled 307 363 internally. It may, however, return NULL to indicate no cookie. It is quite ··· 339 355 calling fscache_enable_cookie() (see below). 340 356 341 357 For example, with AFS, a cell would be added to the primary index. This index 342 - entry would have a dependent inode containing a volume location index for the 343 - volume mappings within this cell: 358 + entry would have a dependent inode containing volume mappings within this cell: 344 359 345 360 cell->cache = 346 361 fscache_acquire_cookie(afs_cache_netfs.primary_index, 347 362 &afs_cell_cache_index_def, 348 - cell, true); 363 + cell->name, strlen(cell->name), 364 + NULL, 0, 365 + cell, 0, true); 349 366 350 - Then when a volume location was accessed, it would be entered into the cell's 351 - index and an inode would be allocated that acts as a volume type and hash chain 352 - combination: 353 - 354 - vlocation->cache = 355 - fscache_acquire_cookie(cell->cache, 356 - &afs_vlocation_cache_index_def, 357 - vlocation, true); 358 - 359 - And then a particular flavour of volume (R/O for example) could be added to 360 - that index, creating another index for vnodes (AFS inode equivalents): 367 + And then a particular volume could be added to that index by ID, creating 368 + another index for vnodes (AFS inode equivalents): 361 369 362 370 volume->cache = 363 - fscache_acquire_cookie(vlocation->cache, 371 + fscache_acquire_cookie(volume->cell->cache, 364 372 &afs_volume_cache_index_def, 365 - volume, true); 373 + &volume->vid, sizeof(volume->vid), 374 + NULL, 0, 375 + volume, 0, true); 366 376 367 377 368 378 ====================== ··· 370 392 vnode->cache = 371 393 fscache_acquire_cookie(volume->cache, 372 394 &afs_vnode_cache_object_def, 373 - vnode, true); 395 + &key, sizeof(key), 396 + &aux, sizeof(aux), 397 + vnode, vnode->status.size, true); 374 398 375 399 376 400 ================================= ··· 388 408 xattr->cache = 389 409 fscache_acquire_cookie(vnode->cache, 390 410 &afs_xattr_cache_object_def, 391 - xattr, true); 411 + &xattr->name, strlen(xattr->name), 412 + NULL, 0, 413 + xattr, strlen(xattr->val), true); 392 414 393 415 Miscellaneous objects might be used to store extended attributes or directory 394 416 entries for example. ··· 407 425 int fscache_attr_changed(struct fscache_cookie *cookie); 408 426 409 427 The cache will return -ENOBUFS if there is no backing cache or if there is no 410 - space to allocate any extra metadata required in the cache. The attributes 411 - will be accessed with the get_attr() cookie definition operation. 428 + space to allocate any extra metadata required in the cache. 412 429 413 430 Note that attempts to read or write data pages in the cache over this size may 414 431 be rebuffed with -ENOBUFS. ··· 532 551 533 552 int fscache_write_page(struct fscache_cookie *cookie, 534 553 struct page *page, 554 + loff_t object_size, 535 555 gfp_t gfp); 536 556 537 557 The cookie argument must specify a data file cookie, the page specified should 538 558 contain the data to be written (and is also used to specify the page number), 539 - and the gfp argument is used to control how any memory allocations made are 540 - satisfied. 559 + object_size is the revised size of the object and the gfp argument is used to 560 + control how any memory allocations made are satisfied. 541 561 542 562 The page must have first been read or allocated successfully and must not have 543 563 been uncached before writing is performed. ··· 699 717 To find out whether auxiliary data for an object is up to data within the 700 718 cache, the following function can be called: 701 719 702 - int fscache_check_consistency(struct fscache_cookie *cookie) 720 + int fscache_check_consistency(struct fscache_cookie *cookie, 721 + const void *aux_data); 703 722 704 723 This will call back to the netfs to check whether the auxiliary data associated 705 - with a cookie is correct. It returns 0 if it is and -ESTALE if it isn't; it 706 - may also return -ENOMEM and -ERESTARTSYS. 724 + with a cookie is correct; if aux_data is non-NULL, it will update the auxiliary 725 + data buffer first. It returns 0 if it is and -ESTALE if it isn't; it may also 726 + return -ENOMEM and -ERESTARTSYS. 707 727 708 728 To request an update of the index data for an index or other object, the 709 729 following function should be called: 710 730 711 - void fscache_update_cookie(struct fscache_cookie *cookie); 731 + void fscache_update_cookie(struct fscache_cookie *cookie, 732 + const void *aux_data); 712 733 713 - This function will refer back to the netfs_data pointer stored in the cookie by 714 - the acquisition function to obtain the data to write into each revised index 715 - entry. The update method in the parent index definition will be called to 716 - transfer the data. 734 + This function will update the cookie's auxiliary data buffer from aux_data if 735 + that is non-NULL and then schedule this to be stored on disk. The update 736 + method in the parent index definition will be called to transfer the data. 717 737 718 738 Note that partial updates may happen automatically at other times, such as when 719 739 data blocks are added to a data file object. ··· 732 748 733 749 The initial enablement state is set by fscache_acquire_cookie(), but the cookie 734 750 can be enabled or disabled later. To disable a cookie, call: 735 - 751 + 736 752 void fscache_disable_cookie(struct fscache_cookie *cookie, 753 + const void *aux_data, 737 754 bool invalidate); 738 - 755 + 739 756 If the cookie is not already disabled, this locks the cookie against other 740 757 enable and disable ops, marks the cookie as being disabled, discards or 741 758 invalidates any backing objects and waits for cessation of activity on any ··· 745 760 All possible failures are handled internally. The caller should consider 746 761 calling fscache_uncache_all_inode_pages() afterwards to make sure all page 747 762 markings are cleared up. 748 - 763 + 749 764 Cookies can be enabled or reenabled with: 750 - 765 + 751 766 void fscache_enable_cookie(struct fscache_cookie *cookie, 767 + const void *aux_data, 768 + loff_t object_size, 752 769 bool (*can_enable)(void *data), 753 770 void *data) 754 - 771 + 755 772 If the cookie is not already enabled, this locks the cookie against other 756 773 enable and disable ops, invokes can_enable() and, if the cookie is not an index 757 774 cookie, will begin the procedure of acquiring backing objects. ··· 763 776 764 777 All possible failures are handled internally. The cookie will only be marked 765 778 as enabled if provisional backing objects are allocated. 779 + 780 + The object's data size is updated from object_size and is passed to the 781 + ->check_aux() function. 782 + 783 + In both cases, the cookie's auxiliary data buffer is updated from aux_data if 784 + that is non-NULL inside the enablement lock before proceeding. 766 785 767 786 768 787 =============================== ··· 816 823 To get rid of a cookie, this function should be called. 817 824 818 825 void fscache_relinquish_cookie(struct fscache_cookie *cookie, 826 + const void *aux_data, 819 827 bool retire); 820 828 821 829 If retire is non-zero, then the object will be marked for recycling, and all ··· 826 832 If retire is zero, then the object may be available again when next the 827 833 acquisition function is called. Retirement here will overrule the pinning on a 828 834 cookie. 835 + 836 + The cookie's auxiliary data will be updated from aux_data if that is non-NULL 837 + so that the cache can lazily update it on disk. 829 838 830 839 One very important note - relinquish must NOT be called for a cookie unless all 831 840 the cookies for "child" indices, objects and pages have been relinquished
+33 -67
fs/9p/cache.c
··· 55 55 return scnprintf(v9ses->cachetag, CACHETAG_LEN, "%lu", jiffies); 56 56 } 57 57 58 - static uint16_t v9fs_cache_session_get_key(const void *cookie_netfs_data, 59 - void *buffer, uint16_t bufmax) 60 - { 61 - struct v9fs_session_info *v9ses; 62 - uint16_t klen = 0; 63 - 64 - v9ses = (struct v9fs_session_info *)cookie_netfs_data; 65 - p9_debug(P9_DEBUG_FSC, "session %p buf %p size %u\n", 66 - v9ses, buffer, bufmax); 67 - 68 - if (v9ses->cachetag) 69 - klen = strlen(v9ses->cachetag); 70 - 71 - if (klen > bufmax) 72 - return 0; 73 - 74 - memcpy(buffer, v9ses->cachetag, klen); 75 - p9_debug(P9_DEBUG_FSC, "cache session tag %s\n", v9ses->cachetag); 76 - return klen; 77 - } 78 - 79 58 const struct fscache_cookie_def v9fs_cache_session_index_def = { 80 59 .name = "9P.session", 81 60 .type = FSCACHE_COOKIE_TYPE_INDEX, 82 - .get_key = v9fs_cache_session_get_key, 83 61 }; 84 62 85 63 void v9fs_cache_session_get_cookie(struct v9fs_session_info *v9ses) 86 64 { 87 65 /* If no cache session tag was specified, we generate a random one. */ 88 - if (!v9ses->cachetag) 89 - v9fs_random_cachetag(v9ses); 66 + if (!v9ses->cachetag) { 67 + if (v9fs_random_cachetag(v9ses) < 0) { 68 + v9ses->fscache = NULL; 69 + return; 70 + } 71 + } 90 72 91 73 v9ses->fscache = fscache_acquire_cookie(v9fs_cache_netfs.primary_index, 92 74 &v9fs_cache_session_index_def, 93 - v9ses, true); 75 + v9ses->cachetag, 76 + strlen(v9ses->cachetag), 77 + NULL, 0, 78 + v9ses, 0, true); 94 79 p9_debug(P9_DEBUG_FSC, "session %p get cookie %p\n", 95 80 v9ses, v9ses->fscache); 96 81 } ··· 84 99 { 85 100 p9_debug(P9_DEBUG_FSC, "session %p put cookie %p\n", 86 101 v9ses, v9ses->fscache); 87 - fscache_relinquish_cookie(v9ses->fscache, 0); 102 + fscache_relinquish_cookie(v9ses->fscache, NULL, false); 88 103 v9ses->fscache = NULL; 89 - } 90 - 91 - 92 - static uint16_t v9fs_cache_inode_get_key(const void *cookie_netfs_data, 93 - void *buffer, uint16_t bufmax) 94 - { 95 - const struct v9fs_inode *v9inode = cookie_netfs_data; 96 - memcpy(buffer, &v9inode->qid.path, sizeof(v9inode->qid.path)); 97 - p9_debug(P9_DEBUG_FSC, "inode %p get key %llu\n", 98 - &v9inode->vfs_inode, v9inode->qid.path); 99 - return sizeof(v9inode->qid.path); 100 - } 101 - 102 - static void v9fs_cache_inode_get_attr(const void *cookie_netfs_data, 103 - uint64_t *size) 104 - { 105 - const struct v9fs_inode *v9inode = cookie_netfs_data; 106 - *size = i_size_read(&v9inode->vfs_inode); 107 - 108 - p9_debug(P9_DEBUG_FSC, "inode %p get attr %llu\n", 109 - &v9inode->vfs_inode, *size); 110 - } 111 - 112 - static uint16_t v9fs_cache_inode_get_aux(const void *cookie_netfs_data, 113 - void *buffer, uint16_t buflen) 114 - { 115 - const struct v9fs_inode *v9inode = cookie_netfs_data; 116 - memcpy(buffer, &v9inode->qid.version, sizeof(v9inode->qid.version)); 117 - p9_debug(P9_DEBUG_FSC, "inode %p get aux %u\n", 118 - &v9inode->vfs_inode, v9inode->qid.version); 119 - return sizeof(v9inode->qid.version); 120 104 } 121 105 122 106 static enum 123 107 fscache_checkaux v9fs_cache_inode_check_aux(void *cookie_netfs_data, 124 108 const void *buffer, 125 - uint16_t buflen) 109 + uint16_t buflen, 110 + loff_t object_size) 126 111 { 127 112 const struct v9fs_inode *v9inode = cookie_netfs_data; 128 113 ··· 109 154 const struct fscache_cookie_def v9fs_cache_inode_index_def = { 110 155 .name = "9p.inode", 111 156 .type = FSCACHE_COOKIE_TYPE_DATAFILE, 112 - .get_key = v9fs_cache_inode_get_key, 113 - .get_attr = v9fs_cache_inode_get_attr, 114 - .get_aux = v9fs_cache_inode_get_aux, 115 157 .check_aux = v9fs_cache_inode_check_aux, 116 158 }; 117 159 ··· 127 175 v9ses = v9fs_inode2v9ses(inode); 128 176 v9inode->fscache = fscache_acquire_cookie(v9ses->fscache, 129 177 &v9fs_cache_inode_index_def, 130 - v9inode, true); 178 + &v9inode->qid.path, 179 + sizeof(v9inode->qid.path), 180 + &v9inode->qid.version, 181 + sizeof(v9inode->qid.version), 182 + v9inode, 183 + i_size_read(&v9inode->vfs_inode), 184 + true); 131 185 132 186 p9_debug(P9_DEBUG_FSC, "inode %p get cookie %p\n", 133 187 inode, v9inode->fscache); ··· 148 190 p9_debug(P9_DEBUG_FSC, "inode %p put cookie %p\n", 149 191 inode, v9inode->fscache); 150 192 151 - fscache_relinquish_cookie(v9inode->fscache, 0); 193 + fscache_relinquish_cookie(v9inode->fscache, &v9inode->qid.version, 194 + false); 152 195 v9inode->fscache = NULL; 153 196 } 154 197 ··· 162 203 p9_debug(P9_DEBUG_FSC, "inode %p flush cookie %p\n", 163 204 inode, v9inode->fscache); 164 205 165 - fscache_relinquish_cookie(v9inode->fscache, 1); 206 + fscache_relinquish_cookie(v9inode->fscache, NULL, true); 166 207 v9inode->fscache = NULL; 167 208 } 168 209 ··· 195 236 old = v9inode->fscache; 196 237 197 238 mutex_lock(&v9inode->fscache_lock); 198 - fscache_relinquish_cookie(v9inode->fscache, 1); 239 + fscache_relinquish_cookie(v9inode->fscache, NULL, true); 199 240 200 241 v9ses = v9fs_inode2v9ses(inode); 201 242 v9inode->fscache = fscache_acquire_cookie(v9ses->fscache, 202 243 &v9fs_cache_inode_index_def, 203 - v9inode, true); 244 + &v9inode->qid.path, 245 + sizeof(v9inode->qid.path), 246 + &v9inode->qid.version, 247 + sizeof(v9inode->qid.version), 248 + v9inode, 249 + i_size_read(&v9inode->vfs_inode), 250 + true); 204 251 p9_debug(P9_DEBUG_FSC, "inode %p revalidating cookie old %p new %p\n", 205 252 inode, old, v9inode->fscache); 206 253 ··· 332 367 const struct v9fs_inode *v9inode = V9FS_I(inode); 333 368 334 369 p9_debug(P9_DEBUG_FSC, "inode %p page %p\n", inode, page); 335 - ret = fscache_write_page(v9inode->fscache, page, GFP_KERNEL); 370 + ret = fscache_write_page(v9inode->fscache, page, 371 + i_size_read(&v9inode->vfs_inode), GFP_KERNEL); 336 372 p9_debug(P9_DEBUG_FSC, "ret = %d\n", ret); 337 373 if (ret != 0) 338 374 v9fs_uncache_page(inode, page);
+8 -142
fs/afs/cache.c
··· 12 12 #include <linux/sched.h> 13 13 #include "internal.h" 14 14 15 - static uint16_t afs_cell_cache_get_key(const void *cookie_netfs_data, 16 - void *buffer, uint16_t buflen); 17 - static uint16_t afs_volume_cache_get_key(const void *cookie_netfs_data, 18 - void *buffer, uint16_t buflen); 19 - 20 - static uint16_t afs_vnode_cache_get_key(const void *cookie_netfs_data, 21 - void *buffer, uint16_t buflen); 22 - static void afs_vnode_cache_get_attr(const void *cookie_netfs_data, 23 - uint64_t *size); 24 - static uint16_t afs_vnode_cache_get_aux(const void *cookie_netfs_data, 25 - void *buffer, uint16_t buflen); 26 15 static enum fscache_checkaux afs_vnode_cache_check_aux(void *cookie_netfs_data, 27 16 const void *buffer, 28 - uint16_t buflen); 17 + uint16_t buflen, 18 + loff_t object_size); 29 19 30 20 struct fscache_netfs afs_cache_netfs = { 31 21 .name = "afs", 32 - .version = 1, 22 + .version = 2, 33 23 }; 34 24 35 25 struct fscache_cookie_def afs_cell_cache_index_def = { 36 26 .name = "AFS.cell", 37 27 .type = FSCACHE_COOKIE_TYPE_INDEX, 38 - .get_key = afs_cell_cache_get_key, 39 28 }; 40 29 41 30 struct fscache_cookie_def afs_volume_cache_index_def = { 42 31 .name = "AFS.volume", 43 32 .type = FSCACHE_COOKIE_TYPE_INDEX, 44 - .get_key = afs_volume_cache_get_key, 45 33 }; 46 34 47 35 struct fscache_cookie_def afs_vnode_cache_index_def = { 48 - .name = "AFS.vnode", 49 - .type = FSCACHE_COOKIE_TYPE_DATAFILE, 50 - .get_key = afs_vnode_cache_get_key, 51 - .get_attr = afs_vnode_cache_get_attr, 52 - .get_aux = afs_vnode_cache_get_aux, 53 - .check_aux = afs_vnode_cache_check_aux, 36 + .name = "AFS.vnode", 37 + .type = FSCACHE_COOKIE_TYPE_DATAFILE, 38 + .check_aux = afs_vnode_cache_check_aux, 54 39 }; 55 - 56 - /* 57 - * set the key for the index entry 58 - */ 59 - static uint16_t afs_cell_cache_get_key(const void *cookie_netfs_data, 60 - void *buffer, uint16_t bufmax) 61 - { 62 - const struct afs_cell *cell = cookie_netfs_data; 63 - uint16_t klen; 64 - 65 - _enter("%p,%p,%u", cell, buffer, bufmax); 66 - 67 - klen = strlen(cell->name); 68 - if (klen > bufmax) 69 - return 0; 70 - 71 - memcpy(buffer, cell->name, klen); 72 - return klen; 73 - } 74 - 75 - /*****************************************************************************/ 76 - /* 77 - * set the key for the volume index entry 78 - */ 79 - static uint16_t afs_volume_cache_get_key(const void *cookie_netfs_data, 80 - void *buffer, uint16_t bufmax) 81 - { 82 - const struct afs_volume *volume = cookie_netfs_data; 83 - struct { 84 - u64 volid; 85 - } __packed key; 86 - 87 - _enter("{%u},%p,%u", volume->type, buffer, bufmax); 88 - 89 - if (bufmax < sizeof(key)) 90 - return 0; 91 - 92 - key.volid = volume->vid; 93 - memcpy(buffer, &key, sizeof(key)); 94 - return sizeof(key); 95 - } 96 - 97 - /*****************************************************************************/ 98 - /* 99 - * set the key for the index entry 100 - */ 101 - static uint16_t afs_vnode_cache_get_key(const void *cookie_netfs_data, 102 - void *buffer, uint16_t bufmax) 103 - { 104 - const struct afs_vnode *vnode = cookie_netfs_data; 105 - struct { 106 - u32 vnode_id[3]; 107 - } __packed key; 108 - 109 - _enter("{%x,%x,%llx},%p,%u", 110 - vnode->fid.vnode, vnode->fid.unique, vnode->status.data_version, 111 - buffer, bufmax); 112 - 113 - /* Allow for a 96-bit key */ 114 - memset(&key, 0, sizeof(key)); 115 - key.vnode_id[0] = vnode->fid.vnode; 116 - key.vnode_id[1] = 0; 117 - key.vnode_id[2] = 0; 118 - 119 - if (sizeof(key) > bufmax) 120 - return 0; 121 - 122 - memcpy(buffer, &key, sizeof(key)); 123 - return sizeof(key); 124 - } 125 - 126 - /* 127 - * provide updated file attributes 128 - */ 129 - static void afs_vnode_cache_get_attr(const void *cookie_netfs_data, 130 - uint64_t *size) 131 - { 132 - const struct afs_vnode *vnode = cookie_netfs_data; 133 - 134 - _enter("{%x,%x,%llx},", 135 - vnode->fid.vnode, vnode->fid.unique, 136 - vnode->status.data_version); 137 - 138 - *size = vnode->status.size; 139 - } 140 - 141 - struct afs_vnode_cache_aux { 142 - u64 data_version; 143 - u32 fid_unique; 144 - } __packed; 145 - 146 - /* 147 - * provide new auxiliary cache data 148 - */ 149 - static uint16_t afs_vnode_cache_get_aux(const void *cookie_netfs_data, 150 - void *buffer, uint16_t bufmax) 151 - { 152 - const struct afs_vnode *vnode = cookie_netfs_data; 153 - struct afs_vnode_cache_aux aux; 154 - 155 - _enter("{%x,%x,%Lx},%p,%u", 156 - vnode->fid.vnode, vnode->fid.unique, vnode->status.data_version, 157 - buffer, bufmax); 158 - 159 - memset(&aux, 0, sizeof(aux)); 160 - aux.data_version = vnode->status.data_version; 161 - aux.fid_unique = vnode->fid.unique; 162 - 163 - if (bufmax < sizeof(aux)) 164 - return 0; 165 - 166 - memcpy(buffer, &aux, sizeof(aux)); 167 - return sizeof(aux); 168 - } 169 40 170 41 /* 171 42 * check that the auxiliary data indicates that the entry is still valid 172 43 */ 173 44 static enum fscache_checkaux afs_vnode_cache_check_aux(void *cookie_netfs_data, 174 45 const void *buffer, 175 - uint16_t buflen) 46 + uint16_t buflen, 47 + loff_t object_size) 176 48 { 177 49 struct afs_vnode *vnode = cookie_netfs_data; 178 50 struct afs_vnode_cache_aux aux; ··· 58 186 /* check the size of the data is what we're expecting */ 59 187 if (buflen != sizeof(aux)) { 60 188 _leave(" = OBSOLETE [len %hx != %zx]", buflen, sizeof(aux)); 61 - return FSCACHE_CHECKAUX_OBSOLETE; 62 - } 63 - 64 - if (vnode->fid.unique != aux.fid_unique) { 65 - _leave(" = OBSOLETE [uniq %x != %x]", 66 - aux.fid_unique, vnode->fid.unique); 67 189 return FSCACHE_CHECKAUX_OBSOLETE; 68 190 } 69 191
+4 -2
fs/afs/cell.c
··· 522 522 #ifdef CONFIG_AFS_FSCACHE 523 523 cell->cache = fscache_acquire_cookie(afs_cache_netfs.primary_index, 524 524 &afs_cell_cache_index_def, 525 - cell, true); 525 + cell->name, strlen(cell->name), 526 + NULL, 0, 527 + cell, 0, true); 526 528 #endif 527 529 ret = afs_proc_cell_setup(net, cell); 528 530 if (ret < 0) ··· 549 547 spin_unlock(&net->proc_cells_lock); 550 548 551 549 #ifdef CONFIG_AFS_FSCACHE 552 - fscache_relinquish_cookie(cell->cache, 0); 550 + fscache_relinquish_cookie(cell->cache, NULL, false); 553 551 cell->cache = NULL; 554 552 #endif 555 553
+4 -2
fs/afs/file.c
··· 339 339 /* send the page to the cache */ 340 340 #ifdef CONFIG_AFS_FSCACHE 341 341 if (PageFsCache(page) && 342 - fscache_write_page(vnode->cache, page, GFP_KERNEL) != 0) { 342 + fscache_write_page(vnode->cache, page, vnode->status.size, 343 + GFP_KERNEL) != 0) { 343 344 fscache_uncache_page(vnode->cache, page); 344 345 BUG_ON(PageFsCache(page)); 345 346 } ··· 404 403 /* send the page to the cache */ 405 404 #ifdef CONFIG_AFS_FSCACHE 406 405 if (PageFsCache(page) && 407 - fscache_write_page(vnode->cache, page, GFP_KERNEL) != 0) { 406 + fscache_write_page(vnode->cache, page, vnode->status.size, 407 + GFP_KERNEL) != 0) { 408 408 fscache_uncache_page(vnode->cache, page); 409 409 BUG_ON(PageFsCache(page)); 410 410 }
+41 -8
fs/afs/inode.c
··· 243 243 } 244 244 245 245 /* 246 + * Get a cache cookie for an inode. 247 + */ 248 + static void afs_get_inode_cache(struct afs_vnode *vnode) 249 + { 250 + #ifdef CONFIG_AFS_FSCACHE 251 + struct { 252 + u32 vnode_id; 253 + u32 unique; 254 + u32 vnode_id_ext[2]; /* Allow for a 96-bit key */ 255 + } __packed key; 256 + struct afs_vnode_cache_aux aux; 257 + 258 + key.vnode_id = vnode->fid.vnode; 259 + key.unique = vnode->fid.unique; 260 + key.vnode_id_ext[0] = 0; 261 + key.vnode_id_ext[1] = 0; 262 + aux.data_version = vnode->status.data_version; 263 + 264 + vnode->cache = fscache_acquire_cookie(vnode->volume->cache, 265 + &afs_vnode_cache_index_def, 266 + &key, sizeof(key), 267 + &aux, sizeof(aux), 268 + vnode, vnode->status.size, true); 269 + #endif 270 + } 271 + 272 + /* 246 273 * inode retrieval 247 274 */ 248 275 struct inode *afs_iget(struct super_block *sb, struct key *key, ··· 334 307 /* set up caching before mapping the status, as map-status reads the 335 308 * first page of symlinks to see if they're really mountpoints */ 336 309 inode->i_size = vnode->status.size; 337 - #ifdef CONFIG_AFS_FSCACHE 338 - vnode->cache = fscache_acquire_cookie(vnode->volume->cache, 339 - &afs_vnode_cache_index_def, 340 - vnode, true); 341 - #endif 310 + afs_get_inode_cache(vnode); 342 311 343 312 ret = afs_inode_map_status(vnode, key); 344 313 if (ret < 0) ··· 350 327 /* failure */ 351 328 bad_inode: 352 329 #ifdef CONFIG_AFS_FSCACHE 353 - fscache_relinquish_cookie(vnode->cache, 0); 330 + fscache_relinquish_cookie(vnode->cache, NULL, ret == -ENOENT); 354 331 vnode->cache = NULL; 355 332 #endif 356 333 iget_failed(inode); ··· 365 342 void afs_zap_data(struct afs_vnode *vnode) 366 343 { 367 344 _enter("{%x:%u}", vnode->fid.vid, vnode->fid.vnode); 345 + 346 + #ifdef CONFIG_AFS_FSCACHE 347 + fscache_invalidate(vnode->cache); 348 + #endif 368 349 369 350 /* nuke all the non-dirty pages that aren't locked, mapped or being 370 351 * written back in a regular file and completely discard the pages in a ··· 534 507 } 535 508 536 509 #ifdef CONFIG_AFS_FSCACHE 537 - fscache_relinquish_cookie(vnode->cache, 0); 538 - vnode->cache = NULL; 510 + { 511 + struct afs_vnode_cache_aux aux; 512 + 513 + aux.data_version = vnode->status.data_version; 514 + fscache_relinquish_cookie(vnode->cache, &aux, 515 + test_bit(AFS_VNODE_DELETED, &vnode->flags)); 516 + vnode->cache = NULL; 517 + } 539 518 #endif 540 519 541 520 afs_put_permits(vnode->permit_cache);
+7
fs/afs/internal.h
··· 559 559 #define AFS_FS_CURSOR_NO_VSLEEP 0x0020 /* Set to prevent sleep on VBUSY, VOFFLINE, ... */ 560 560 }; 561 561 562 + /* 563 + * Cache auxiliary data. 564 + */ 565 + struct afs_vnode_cache_aux { 566 + u64 data_version; 567 + } __packed; 568 + 562 569 #include <trace/events/afs.h> 563 570 564 571 /*****************************************************************************/
+4 -2
fs/afs/volume.c
··· 225 225 #ifdef CONFIG_AFS_FSCACHE 226 226 volume->cache = fscache_acquire_cookie(volume->cell->cache, 227 227 &afs_volume_cache_index_def, 228 - volume, true); 228 + &volume->vid, sizeof(volume->vid), 229 + NULL, 0, 230 + volume, 0, true); 229 231 #endif 230 232 231 233 write_lock(&volume->cell->proc_lock); ··· 247 245 write_unlock(&volume->cell->proc_lock); 248 246 249 247 #ifdef CONFIG_AFS_FSCACHE 250 - fscache_relinquish_cookie(volume->cache, 248 + fscache_relinquish_cookie(volume->cache, NULL, 251 249 test_bit(AFS_VOLUME_DELETED, &volume->flags)); 252 250 volume->cache = NULL; 253 251 #endif
+40 -21
fs/cachefiles/interface.c
··· 32 32 struct cachefiles_cache *cache; 33 33 struct cachefiles_xattr *auxdata; 34 34 unsigned keylen, auxlen; 35 - void *buffer; 35 + void *buffer, *p; 36 36 char *key; 37 37 38 38 cache = container_of(_cache, struct cachefiles_cache, cache); ··· 65 65 if (!buffer) 66 66 goto nomem_buffer; 67 67 68 - keylen = cookie->def->get_key(cookie->netfs_data, buffer + 2, 512); 69 - ASSERTCMP(keylen, <, 512); 68 + keylen = cookie->key_len; 69 + if (keylen <= sizeof(cookie->inline_key)) 70 + p = cookie->inline_key; 71 + else 72 + p = cookie->key; 73 + memcpy(buffer + 2, p, keylen); 70 74 71 75 *(uint16_t *)buffer = keylen; 72 76 ((char *)buffer)[keylen + 2] = 0; ··· 84 80 85 81 /* get hold of the auxiliary data and prepend the object type */ 86 82 auxdata = buffer; 87 - auxlen = 0; 88 - if (cookie->def->get_aux) { 89 - auxlen = cookie->def->get_aux(cookie->netfs_data, 90 - auxdata->data, 511); 91 - ASSERTCMP(auxlen, <, 511); 83 + auxlen = cookie->aux_len; 84 + if (auxlen) { 85 + if (auxlen <= sizeof(cookie->inline_aux)) 86 + p = cookie->inline_aux; 87 + else 88 + p = cookie->aux; 89 + memcpy(auxdata->data, p, auxlen); 92 90 } 93 91 94 92 auxdata->len = auxlen + 1; 95 - auxdata->type = cookie->def->type; 93 + auxdata->type = cookie->type; 96 94 97 95 lookup_data->auxdata = auxdata; 98 96 lookup_data->key = key; ··· 183 177 * increment the usage count on an inode object (may fail if unmounting) 184 178 */ 185 179 static 186 - struct fscache_object *cachefiles_grab_object(struct fscache_object *_object) 180 + struct fscache_object *cachefiles_grab_object(struct fscache_object *_object, 181 + enum fscache_obj_ref_trace why) 187 182 { 188 183 struct cachefiles_object *object = 189 184 container_of(_object, struct cachefiles_object, fscache); 185 + int u; 190 186 191 187 _enter("{OBJ%x,%d}", _object->debug_id, atomic_read(&object->usage)); 192 188 ··· 196 188 ASSERT((atomic_read(&object->usage) & 0xffff0000) != 0x6b6b0000); 197 189 #endif 198 190 199 - atomic_inc(&object->usage); 191 + u = atomic_inc_return(&object->usage); 192 + trace_cachefiles_ref(object, _object->cookie, 193 + (enum cachefiles_obj_ref_trace)why, u); 200 194 return &object->fscache; 201 195 } 202 196 ··· 212 202 struct cachefiles_cache *cache; 213 203 struct fscache_cookie *cookie; 214 204 const struct cred *saved_cred; 205 + const void *aux; 215 206 unsigned auxlen; 216 207 217 208 _enter("{OBJ%x}", _object->debug_id); ··· 227 216 } 228 217 229 218 cookie = object->fscache.cookie; 219 + auxlen = cookie->aux_len; 230 220 231 - if (!cookie->def->get_aux) { 221 + if (!auxlen) { 232 222 fscache_unuse_cookie(_object); 233 223 _leave(" [no aux]"); 234 224 return; 235 225 } 236 226 237 - auxdata = kmalloc(2 + 512 + 3, cachefiles_gfp); 227 + auxdata = kmalloc(2 + auxlen + 3, cachefiles_gfp); 238 228 if (!auxdata) { 239 229 fscache_unuse_cookie(_object); 240 230 _leave(" [nomem]"); 241 231 return; 242 232 } 243 233 244 - auxlen = cookie->def->get_aux(cookie->netfs_data, auxdata->data, 511); 234 + aux = (auxlen <= sizeof(cookie->inline_aux)) ? 235 + cookie->inline_aux : cookie->aux; 236 + 237 + memcpy(auxdata->data, aux, auxlen); 245 238 fscache_unuse_cookie(_object); 246 - ASSERTCMP(auxlen, <, 511); 247 239 248 240 auxdata->len = auxlen + 1; 249 - auxdata->type = cookie->def->type; 241 + auxdata->type = cookie->type; 250 242 251 243 cachefiles_begin_secure(cache, &saved_cred); 252 244 cachefiles_update_object_xattr(object, auxdata); ··· 323 309 /* 324 310 * dispose of a reference to an object 325 311 */ 326 - static void cachefiles_put_object(struct fscache_object *_object) 312 + static void cachefiles_put_object(struct fscache_object *_object, 313 + enum fscache_obj_ref_trace why) 327 314 { 328 315 struct cachefiles_object *object; 329 316 struct fscache_cache *cache; 317 + int u; 330 318 331 319 ASSERT(_object); 332 320 ··· 344 328 ASSERTIFCMP(object->fscache.parent, 345 329 object->fscache.parent->n_children, >, 0); 346 330 347 - if (atomic_dec_and_test(&object->usage)) { 331 + u = atomic_dec_return(&object->usage); 332 + trace_cachefiles_ref(object, _object->cookie, 333 + (enum cachefiles_obj_ref_trace)why, u); 334 + ASSERTCMP(u, !=, -1); 335 + if (u == 0) { 348 336 _debug("- kill object OBJ%x", object->fscache.debug_id); 349 337 350 338 ASSERT(!test_bit(CACHEFILES_OBJECT_ACTIVE, &object->flags)); ··· 441 421 loff_t oi_size; 442 422 int ret; 443 423 444 - _object->cookie->def->get_attr(_object->cookie->netfs_data, &ni_size); 424 + ni_size = _object->store_limit_l; 445 425 446 426 _enter("{OBJ%x},[%llu]", 447 427 _object->debug_id, (unsigned long long) ni_size); ··· 513 493 cache = container_of(object->fscache.cache, 514 494 struct cachefiles_cache, cache); 515 495 516 - op->object->cookie->def->get_attr(op->object->cookie->netfs_data, 517 - &ni_size); 496 + ni_size = op->object->store_limit_l; 518 497 519 498 _enter("{OBJ%x},[%llu]", 520 499 op->object->debug_id, (unsigned long long)ni_size);
+2
fs/cachefiles/internal.h
··· 124 124 uint8_t data[]; 125 125 }; 126 126 127 + #include <trace/events/cachefiles.h> 128 + 127 129 /* 128 130 * note change of state for daemon 129 131 */
+1
fs/cachefiles/main.c
··· 22 22 #include <linux/statfs.h> 23 23 #include <linux/sysctl.h> 24 24 #include <linux/miscdevice.h> 25 + #define CREATE_TRACE_POINTS 25 26 #include "internal.h" 26 27 27 28 unsigned cachefiles_debug;
+44 -31
fs/cachefiles/namei.c
··· 30 30 */ 31 31 static noinline 32 32 void __cachefiles_printk_object(struct cachefiles_object *object, 33 - const char *prefix, 34 - u8 *keybuf) 33 + const char *prefix) 35 34 { 36 35 struct fscache_cookie *cookie; 37 - unsigned keylen, loop; 36 + const u8 *k; 37 + unsigned loop; 38 38 39 39 pr_err("%sobject: OBJ%x\n", prefix, object->fscache.debug_id); 40 40 pr_err("%sobjstate=%s fl=%lx wbusy=%x ev=%lx[%lx]\n", ··· 56 56 object->fscache.cookie->parent, 57 57 object->fscache.cookie->netfs_data, 58 58 object->fscache.cookie->flags); 59 - if (keybuf && cookie->def) 60 - keylen = cookie->def->get_key(cookie->netfs_data, keybuf, 61 - CACHEFILES_KEYBUF_SIZE); 62 - else 63 - keylen = 0; 59 + pr_err("%skey=[%u] '", prefix, cookie->key_len); 60 + k = (cookie->key_len <= sizeof(cookie->inline_key)) ? 61 + cookie->inline_key : cookie->key; 62 + for (loop = 0; loop < cookie->key_len; loop++) 63 + pr_cont("%02x", k[loop]); 64 + pr_cont("'\n"); 64 65 } else { 65 66 pr_err("%scookie=NULL\n", prefix); 66 - keylen = 0; 67 67 } 68 68 spin_unlock(&object->fscache.lock); 69 - 70 - if (keylen) { 71 - pr_err("%skey=[%u] '", prefix, keylen); 72 - for (loop = 0; loop < keylen; loop++) 73 - pr_cont("%02x", keybuf[loop]); 74 - pr_cont("'\n"); 75 - } 76 69 } 77 70 78 71 /* ··· 74 81 static noinline void cachefiles_printk_object(struct cachefiles_object *object, 75 82 struct cachefiles_object *xobject) 76 83 { 77 - u8 *keybuf; 78 - 79 - keybuf = kmalloc(CACHEFILES_KEYBUF_SIZE, GFP_NOIO); 80 84 if (object) 81 - __cachefiles_printk_object(object, "", keybuf); 85 + __cachefiles_printk_object(object, ""); 82 86 if (xobject) 83 - __cachefiles_printk_object(xobject, "x", keybuf); 84 - kfree(keybuf); 87 + __cachefiles_printk_object(xobject, "x"); 85 88 } 86 89 87 90 /* ··· 109 120 } 110 121 111 122 write_unlock(&cache->active_lock); 123 + trace_cachefiles_mark_buried(NULL, dentry, why); 112 124 _leave(" [no owner]"); 113 125 return; 114 126 ··· 119 129 object->fscache.debug_id, 120 130 object->fscache.state->name, 121 131 dentry); 132 + 133 + trace_cachefiles_mark_buried(object, dentry, why); 122 134 123 135 if (fscache_object_is_live(&object->fscache)) { 124 136 pr_err("\n"); ··· 150 158 try_again: 151 159 write_lock(&cache->active_lock); 152 160 161 + dentry = object->dentry; 162 + trace_cachefiles_mark_active(object, dentry); 163 + 153 164 if (test_and_set_bit(CACHEFILES_OBJECT_ACTIVE, &object->flags)) { 154 165 pr_err("Error: Object already active\n"); 155 166 cachefiles_printk_object(object, NULL); 156 167 BUG(); 157 168 } 158 169 159 - dentry = object->dentry; 160 170 _p = &cache->active_nodes.rb_node; 161 171 while (*_p) { 162 172 _parent = *_p; ··· 185 191 /* an old object from a previous incarnation is hogging the slot - we 186 192 * need to wait for it to be destroyed */ 187 193 wait_for_old_object: 194 + trace_cachefiles_wait_active(object, dentry, xobject); 195 + 188 196 if (fscache_object_is_live(&xobject->fscache)) { 189 197 pr_err("\n"); 190 198 pr_err("Error: Unexpected object collision\n"); ··· 244 248 245 249 ASSERT(!test_bit(CACHEFILES_OBJECT_ACTIVE, &xobject->flags)); 246 250 247 - cache->cache.ops->put_object(&xobject->fscache); 251 + cache->cache.ops->put_object(&xobject->fscache, cachefiles_obj_put_wait_retry); 248 252 goto try_again; 249 253 250 254 requeue: 251 255 clear_bit(CACHEFILES_OBJECT_ACTIVE, &object->flags); 252 - cache->cache.ops->put_object(&xobject->fscache); 256 + cache->cache.ops->put_object(&xobject->fscache, cachefiles_obj_put_wait_timeo); 253 257 _leave(" = -ETIMEDOUT"); 254 258 return -ETIMEDOUT; 255 259 } ··· 261 265 struct cachefiles_object *object, 262 266 blkcnt_t i_blocks) 263 267 { 268 + struct dentry *dentry = object->dentry; 269 + struct inode *inode = d_backing_inode(dentry); 270 + 271 + trace_cachefiles_mark_inactive(object, dentry, inode); 272 + 264 273 write_lock(&cache->active_lock); 265 274 rb_erase(&object->active_node, &cache->active_nodes); 266 275 clear_bit(CACHEFILES_OBJECT_ACTIVE, &object->flags); ··· 289 288 * - unlocks the directory mutex 290 289 */ 291 290 static int cachefiles_bury_object(struct cachefiles_cache *cache, 291 + struct cachefiles_object *object, 292 292 struct dentry *dir, 293 293 struct dentry *rep, 294 294 bool preemptive, ··· 314 312 if (ret < 0) { 315 313 cachefiles_io_error(cache, "Unlink security error"); 316 314 } else { 315 + trace_cachefiles_unlink(object, rep, why); 317 316 ret = vfs_unlink(d_inode(dir), rep, NULL); 318 317 319 318 if (preemptive) ··· 416 413 if (ret < 0) { 417 414 cachefiles_io_error(cache, "Rename security error %d", ret); 418 415 } else { 416 + trace_cachefiles_rename(object, rep, grave, why); 419 417 ret = vfs_rename(d_inode(dir), rep, 420 418 d_inode(cache->graveyard), grave, NULL, 0); 421 419 if (ret != 0 && ret != -ENOMEM) ··· 462 458 /* we need to check that our parent is _still_ our parent - it 463 459 * may have been renamed */ 464 460 if (dir == object->dentry->d_parent) { 465 - ret = cachefiles_bury_object(cache, dir, 461 + ret = cachefiles_bury_object(cache, object, dir, 466 462 object->dentry, false, 467 463 FSCACHE_OBJECT_WAS_RETIRED); 468 464 } else { ··· 490 486 { 491 487 struct cachefiles_cache *cache; 492 488 struct dentry *dir, *next = NULL; 489 + struct inode *inode; 493 490 struct path path; 494 491 unsigned long start; 495 492 const char *name; ··· 534 529 start = jiffies; 535 530 next = lookup_one_len(name, dir, nlen); 536 531 cachefiles_hist(cachefiles_lookup_histogram, start); 537 - if (IS_ERR(next)) 532 + if (IS_ERR(next)) { 533 + trace_cachefiles_lookup(object, next, NULL); 538 534 goto lookup_error; 535 + } 539 536 540 - _debug("next -> %p %s", next, d_backing_inode(next) ? "positive" : "negative"); 537 + inode = d_backing_inode(next); 538 + trace_cachefiles_lookup(object, next, inode); 539 + _debug("next -> %p %s", next, inode ? "positive" : "negative"); 541 540 542 541 if (!key) 543 - object->new = !d_backing_inode(next); 542 + object->new = !inode; 544 543 545 544 /* if this element of the path doesn't exist, then the lookup phase 546 545 * failed, and we can release any readers in the certain knowledge that ··· 567 558 start = jiffies; 568 559 ret = vfs_mkdir(d_inode(dir), next, 0); 569 560 cachefiles_hist(cachefiles_mkdir_histogram, start); 561 + if (!key) 562 + trace_cachefiles_mkdir(object, next, ret); 570 563 if (ret < 0) 571 564 goto create_error; 572 565 ··· 598 587 start = jiffies; 599 588 ret = vfs_create(d_inode(dir), next, S_IFREG, true); 600 589 cachefiles_hist(cachefiles_create_histogram, start); 590 + trace_cachefiles_create(object, next, ret); 601 591 if (ret < 0) 602 592 goto create_error; 603 593 ··· 641 629 * mutex) */ 642 630 object->dentry = NULL; 643 631 644 - ret = cachefiles_bury_object(cache, dir, next, true, 632 + ret = cachefiles_bury_object(cache, object, dir, next, 633 + true, 645 634 FSCACHE_OBJECT_IS_STALE); 646 635 dput(next); 647 636 next = NULL; ··· 968 955 /* actually remove the victim (drops the dir mutex) */ 969 956 _debug("bury"); 970 957 971 - ret = cachefiles_bury_object(cache, dir, victim, false, 958 + ret = cachefiles_bury_object(cache, NULL, dir, victim, false, 972 959 FSCACHE_OBJECT_WAS_CULLED); 973 960 if (ret < 0) 974 961 goto error;
+1
fs/cachefiles/rdwr.c
··· 952 952 * - cache withdrawal is prevented by the caller 953 953 */ 954 954 void cachefiles_uncache_page(struct fscache_object *_object, struct page *page) 955 + __releases(&object->fscache.cookie->lock) 955 956 { 956 957 struct cachefiles_object *object; 957 958 struct cachefiles_cache *cache;
+6 -2
fs/cachefiles/xattr.c
··· 113 113 /* attempt to install the cache metadata directly */ 114 114 _debug("SET #%u", auxdata->len); 115 115 116 + clear_bit(FSCACHE_COOKIE_AUX_UPDATED, &object->fscache.cookie->flags); 116 117 ret = vfs_setxattr(dentry, cachefiles_xattr_cache, 117 118 &auxdata->type, auxdata->len, 118 119 XATTR_CREATE); ··· 142 141 /* attempt to install the cache metadata directly */ 143 142 _debug("SET #%u", auxdata->len); 144 143 144 + clear_bit(FSCACHE_COOKIE_AUX_UPDATED, &object->fscache.cookie->flags); 145 145 ret = vfs_setxattr(dentry, cachefiles_xattr_cache, 146 146 &auxdata->type, auxdata->len, 147 147 XATTR_REPLACE); ··· 182 180 goto error; 183 181 184 182 xlen--; 185 - validity = fscache_check_aux(&object->fscache, &auxbuf->data, xlen); 183 + validity = fscache_check_aux(&object->fscache, &auxbuf->data, xlen, 184 + i_size_read(d_backing_inode(dentry))); 186 185 if (validity != FSCACHE_CHECKAUX_OKAY) 187 186 goto error; 188 187 ··· 252 249 object->fscache.cookie->def->name, dlen); 253 250 254 251 result = fscache_check_aux(&object->fscache, 255 - &auxbuf->data, dlen); 252 + &auxbuf->data, dlen, 253 + i_size_read(d_backing_inode(dentry))); 256 254 257 255 switch (result) { 258 256 /* entry okay as is */
+31 -82
fs/ceph/cache.c
··· 27 27 struct ceph_aux_inode { 28 28 u64 version; 29 29 struct timespec mtime; 30 - loff_t size; 31 30 }; 32 31 33 32 struct fscache_netfs ceph_cache_netfs = { ··· 40 41 struct ceph_fscache_entry { 41 42 struct list_head list; 42 43 struct fscache_cookie *fscache; 43 - struct ceph_fsid fsid; 44 44 size_t uniq_len; 45 + /* The following members must be last */ 46 + struct ceph_fsid fsid; 45 47 char uniquifier[0]; 46 48 }; 47 - 48 - static uint16_t ceph_fscache_session_get_key(const void *cookie_netfs_data, 49 - void *buffer, uint16_t maxbuf) 50 - { 51 - const struct ceph_fs_client* fsc = cookie_netfs_data; 52 - const char *fscache_uniq = fsc->mount_options->fscache_uniq; 53 - uint16_t fsid_len, uniq_len; 54 - 55 - fsid_len = sizeof(fsc->client->fsid); 56 - uniq_len = fscache_uniq ? strlen(fscache_uniq) : 0; 57 - if (fsid_len + uniq_len > maxbuf) 58 - return 0; 59 - 60 - memcpy(buffer, &fsc->client->fsid, fsid_len); 61 - if (uniq_len) 62 - memcpy(buffer + fsid_len, fscache_uniq, uniq_len); 63 - 64 - return fsid_len + uniq_len; 65 - } 66 49 67 50 static const struct fscache_cookie_def ceph_fscache_fsid_object_def = { 68 51 .name = "CEPH.fsid", 69 52 .type = FSCACHE_COOKIE_TYPE_INDEX, 70 - .get_key = ceph_fscache_session_get_key, 71 53 }; 72 54 73 55 int ceph_fscache_register(void) ··· 90 110 goto out_unlock; 91 111 } 92 112 113 + memcpy(&ent->fsid, fsid, sizeof(*fsid)); 114 + if (uniq_len > 0) { 115 + memcpy(&ent->uniquifier, fscache_uniq, uniq_len); 116 + ent->uniq_len = uniq_len; 117 + } 118 + 93 119 fsc->fscache = fscache_acquire_cookie(ceph_cache_netfs.primary_index, 94 120 &ceph_fscache_fsid_object_def, 95 - fsc, true); 121 + &ent->fsid, sizeof(ent->fsid) + uniq_len, 122 + NULL, 0, 123 + fsc, 0, true); 96 124 97 125 if (fsc->fscache) { 98 - memcpy(&ent->fsid, fsid, sizeof(*fsid)); 99 - if (uniq_len > 0) { 100 - memcpy(&ent->uniquifier, fscache_uniq, uniq_len); 101 - ent->uniq_len = uniq_len; 102 - } 103 126 ent->fscache = fsc->fscache; 104 127 list_add_tail(&ent->list, &ceph_fscache_list); 105 128 } else { ··· 116 133 return err; 117 134 } 118 135 119 - static uint16_t ceph_fscache_inode_get_key(const void *cookie_netfs_data, 120 - void *buffer, uint16_t maxbuf) 121 - { 122 - const struct ceph_inode_info* ci = cookie_netfs_data; 123 - uint16_t klen; 124 - 125 - /* use ceph virtual inode (id + snapshot) */ 126 - klen = sizeof(ci->i_vino); 127 - if (klen > maxbuf) 128 - return 0; 129 - 130 - memcpy(buffer, &ci->i_vino, klen); 131 - return klen; 132 - } 133 - 134 - static uint16_t ceph_fscache_inode_get_aux(const void *cookie_netfs_data, 135 - void *buffer, uint16_t bufmax) 136 - { 137 - struct ceph_aux_inode aux; 138 - const struct ceph_inode_info* ci = cookie_netfs_data; 139 - const struct inode* inode = &ci->vfs_inode; 140 - 141 - memset(&aux, 0, sizeof(aux)); 142 - aux.version = ci->i_version; 143 - aux.mtime = inode->i_mtime; 144 - aux.size = i_size_read(inode); 145 - 146 - memcpy(buffer, &aux, sizeof(aux)); 147 - 148 - return sizeof(aux); 149 - } 150 - 151 - static void ceph_fscache_inode_get_attr(const void *cookie_netfs_data, 152 - uint64_t *size) 153 - { 154 - const struct ceph_inode_info* ci = cookie_netfs_data; 155 - *size = i_size_read(&ci->vfs_inode); 156 - } 157 - 158 136 static enum fscache_checkaux ceph_fscache_inode_check_aux( 159 - void *cookie_netfs_data, const void *data, uint16_t dlen) 137 + void *cookie_netfs_data, const void *data, uint16_t dlen, 138 + loff_t object_size) 160 139 { 161 140 struct ceph_aux_inode aux; 162 141 struct ceph_inode_info* ci = cookie_netfs_data; 163 142 struct inode* inode = &ci->vfs_inode; 164 143 165 - if (dlen != sizeof(aux)) 144 + if (dlen != sizeof(aux) || 145 + i_size_read(inode) != object_size) 166 146 return FSCACHE_CHECKAUX_OBSOLETE; 167 147 168 148 memset(&aux, 0, sizeof(aux)); 169 149 aux.version = ci->i_version; 170 150 aux.mtime = inode->i_mtime; 171 - aux.size = i_size_read(inode); 172 151 173 152 if (memcmp(data, &aux, sizeof(aux)) != 0) 174 153 return FSCACHE_CHECKAUX_OBSOLETE; ··· 142 197 static const struct fscache_cookie_def ceph_fscache_inode_object_def = { 143 198 .name = "CEPH.inode", 144 199 .type = FSCACHE_COOKIE_TYPE_DATAFILE, 145 - .get_key = ceph_fscache_inode_get_key, 146 - .get_attr = ceph_fscache_inode_get_attr, 147 - .get_aux = ceph_fscache_inode_get_aux, 148 200 .check_aux = ceph_fscache_inode_check_aux, 149 201 }; 150 202 ··· 149 207 { 150 208 struct ceph_inode_info *ci = ceph_inode(inode); 151 209 struct ceph_fs_client *fsc = ceph_inode_to_client(inode); 210 + struct ceph_aux_inode aux; 152 211 153 212 /* No caching for filesystem */ 154 213 if (!fsc->fscache) ··· 161 218 162 219 inode_lock_nested(inode, I_MUTEX_CHILD); 163 220 if (!ci->fscache) { 221 + memset(&aux, 0, sizeof(aux)); 222 + aux.version = ci->i_version; 223 + aux.mtime = inode->i_mtime; 164 224 ci->fscache = fscache_acquire_cookie(fsc->fscache, 165 - &ceph_fscache_inode_object_def, 166 - ci, false); 225 + &ceph_fscache_inode_object_def, 226 + &ci->i_vino, sizeof(ci->i_vino), 227 + &aux, sizeof(aux), 228 + ci, i_size_read(inode), false); 167 229 } 168 230 inode_unlock(inode); 169 231 } ··· 183 235 ci->fscache = NULL; 184 236 185 237 fscache_uncache_all_inode_pages(cookie, &ci->vfs_inode); 186 - fscache_relinquish_cookie(cookie, 0); 238 + fscache_relinquish_cookie(cookie, &ci->i_vino, false); 187 239 } 188 240 189 241 static bool ceph_fscache_can_enable(void *data) ··· 202 254 if (inode_is_open_for_write(inode)) { 203 255 dout("fscache_file_set_cookie %p %p disabling cache\n", 204 256 inode, filp); 205 - fscache_disable_cookie(ci->fscache, false); 257 + fscache_disable_cookie(ci->fscache, &ci->i_vino, false); 206 258 fscache_uncache_all_inode_pages(ci->fscache, inode); 207 259 } else { 208 - fscache_enable_cookie(ci->fscache, ceph_fscache_can_enable, 209 - inode); 260 + fscache_enable_cookie(ci->fscache, &ci->i_vino, i_size_read(inode), 261 + ceph_fscache_can_enable, inode); 210 262 if (fscache_cookie_enabled(ci->fscache)) { 211 263 dout("fscache_file_set_cookie %p %p enabling cache\n", 212 264 inode, filp); ··· 299 351 if (!cache_valid(ci)) 300 352 return; 301 353 302 - ret = fscache_write_page(ci->fscache, page, GFP_KERNEL); 354 + ret = fscache_write_page(ci->fscache, page, i_size_read(inode), 355 + GFP_KERNEL); 303 356 if (ret) 304 357 fscache_uncache_page(ci->fscache, page); 305 358 } ··· 334 385 WARN_ON_ONCE(!found); 335 386 mutex_unlock(&ceph_fscache_lock); 336 387 337 - __fscache_relinquish_cookie(fsc->fscache, 0); 388 + __fscache_relinquish_cookie(fsc->fscache, NULL, false); 338 389 } 339 390 fsc->fscache = NULL; 340 391 } ··· 351 402 * truncate while the caller holds CEPH_CAP_FILE_RD */ 352 403 mutex_lock(&ci->i_truncate_mutex); 353 404 if (!cache_valid(ci)) { 354 - if (fscache_check_consistency(ci->fscache)) 405 + if (fscache_check_consistency(ci->fscache, &ci->i_vino)) 355 406 fscache_invalidate(ci->fscache); 356 407 spin_lock(&ci->i_ceph_lock); 357 408 ci->i_fscache_gen = ci->i_rdcache_gen;
+5 -163
fs/cifs/cache.c
··· 46 46 } 47 47 48 48 /* 49 - * Key layout of CIFS server cache index object 50 - */ 51 - struct cifs_server_key { 52 - uint16_t family; /* address family */ 53 - __be16 port; /* IP port */ 54 - union { 55 - struct in_addr ipv4_addr; 56 - struct in6_addr ipv6_addr; 57 - } addr[0]; 58 - }; 59 - 60 - /* 61 - * Server object keyed by {IPaddress,port,family} tuple 62 - */ 63 - static uint16_t cifs_server_get_key(const void *cookie_netfs_data, 64 - void *buffer, uint16_t maxbuf) 65 - { 66 - const struct TCP_Server_Info *server = cookie_netfs_data; 67 - const struct sockaddr *sa = (struct sockaddr *) &server->dstaddr; 68 - const struct sockaddr_in *addr = (struct sockaddr_in *) sa; 69 - const struct sockaddr_in6 *addr6 = (struct sockaddr_in6 *) sa; 70 - struct cifs_server_key *key = buffer; 71 - uint16_t key_len = sizeof(struct cifs_server_key); 72 - 73 - memset(key, 0, key_len); 74 - 75 - /* 76 - * Should not be a problem as sin_family/sin6_family overlays 77 - * sa_family field 78 - */ 79 - switch (sa->sa_family) { 80 - case AF_INET: 81 - key->family = sa->sa_family; 82 - key->port = addr->sin_port; 83 - key->addr[0].ipv4_addr = addr->sin_addr; 84 - key_len += sizeof(key->addr[0].ipv4_addr); 85 - break; 86 - 87 - case AF_INET6: 88 - key->family = sa->sa_family; 89 - key->port = addr6->sin6_port; 90 - key->addr[0].ipv6_addr = addr6->sin6_addr; 91 - key_len += sizeof(key->addr[0].ipv6_addr); 92 - break; 93 - 94 - default: 95 - cifs_dbg(VFS, "Unknown network family '%d'\n", sa->sa_family); 96 - key_len = 0; 97 - break; 98 - } 99 - 100 - return key_len; 101 - } 102 - 103 - /* 104 49 * Server object for FS-Cache 105 50 */ 106 51 const struct fscache_cookie_def cifs_fscache_server_index_def = { 107 52 .name = "CIFS.server", 108 53 .type = FSCACHE_COOKIE_TYPE_INDEX, 109 - .get_key = cifs_server_get_key, 110 54 }; 111 55 112 56 /* ··· 60 116 u64 resource_id; /* unique server resource id */ 61 117 }; 62 118 63 - static char *extract_sharename(const char *treename) 119 + char *extract_sharename(const char *treename) 64 120 { 65 121 const char *src; 66 122 char *delim, *dst; ··· 84 140 return dst; 85 141 } 86 142 87 - /* 88 - * Superblock object currently keyed by share name 89 - */ 90 - static uint16_t cifs_super_get_key(const void *cookie_netfs_data, void *buffer, 91 - uint16_t maxbuf) 92 - { 93 - const struct cifs_tcon *tcon = cookie_netfs_data; 94 - char *sharename; 95 - uint16_t len; 96 - 97 - sharename = extract_sharename(tcon->treeName); 98 - if (IS_ERR(sharename)) { 99 - cifs_dbg(FYI, "%s: couldn't extract sharename\n", __func__); 100 - sharename = NULL; 101 - return 0; 102 - } 103 - 104 - len = strlen(sharename); 105 - if (len > maxbuf) 106 - return 0; 107 - 108 - memcpy(buffer, sharename, len); 109 - 110 - kfree(sharename); 111 - 112 - return len; 113 - } 114 - 115 - static uint16_t 116 - cifs_fscache_super_get_aux(const void *cookie_netfs_data, void *buffer, 117 - uint16_t maxbuf) 118 - { 119 - struct cifs_fscache_super_auxdata auxdata; 120 - const struct cifs_tcon *tcon = cookie_netfs_data; 121 - 122 - memset(&auxdata, 0, sizeof(auxdata)); 123 - auxdata.resource_id = tcon->resource_id; 124 - 125 - if (maxbuf > sizeof(auxdata)) 126 - maxbuf = sizeof(auxdata); 127 - 128 - memcpy(buffer, &auxdata, maxbuf); 129 - 130 - return maxbuf; 131 - } 132 - 133 143 static enum 134 144 fscache_checkaux cifs_fscache_super_check_aux(void *cookie_netfs_data, 135 145 const void *data, 136 - uint16_t datalen) 146 + uint16_t datalen, 147 + loff_t object_size) 137 148 { 138 149 struct cifs_fscache_super_auxdata auxdata; 139 150 const struct cifs_tcon *tcon = cookie_netfs_data; ··· 111 212 const struct fscache_cookie_def cifs_fscache_super_index_def = { 112 213 .name = "CIFS.super", 113 214 .type = FSCACHE_COOKIE_TYPE_INDEX, 114 - .get_key = cifs_super_get_key, 115 - .get_aux = cifs_fscache_super_get_aux, 116 215 .check_aux = cifs_fscache_super_check_aux, 117 216 }; 118 - 119 - /* 120 - * Auxiliary data attached to CIFS inode within the cache 121 - */ 122 - struct cifs_fscache_inode_auxdata { 123 - struct timespec last_write_time; 124 - struct timespec last_change_time; 125 - u64 eof; 126 - }; 127 - 128 - static uint16_t cifs_fscache_inode_get_key(const void *cookie_netfs_data, 129 - void *buffer, uint16_t maxbuf) 130 - { 131 - const struct cifsInodeInfo *cifsi = cookie_netfs_data; 132 - uint16_t keylen; 133 - 134 - /* use the UniqueId as the key */ 135 - keylen = sizeof(cifsi->uniqueid); 136 - if (keylen > maxbuf) 137 - keylen = 0; 138 - else 139 - memcpy(buffer, &cifsi->uniqueid, keylen); 140 - 141 - return keylen; 142 - } 143 - 144 - static void 145 - cifs_fscache_inode_get_attr(const void *cookie_netfs_data, uint64_t *size) 146 - { 147 - const struct cifsInodeInfo *cifsi = cookie_netfs_data; 148 - 149 - *size = cifsi->vfs_inode.i_size; 150 - } 151 - 152 - static uint16_t 153 - cifs_fscache_inode_get_aux(const void *cookie_netfs_data, void *buffer, 154 - uint16_t maxbuf) 155 - { 156 - struct cifs_fscache_inode_auxdata auxdata; 157 - const struct cifsInodeInfo *cifsi = cookie_netfs_data; 158 - 159 - memset(&auxdata, 0, sizeof(auxdata)); 160 - auxdata.eof = cifsi->server_eof; 161 - auxdata.last_write_time = cifsi->vfs_inode.i_mtime; 162 - auxdata.last_change_time = cifsi->vfs_inode.i_ctime; 163 - 164 - if (maxbuf > sizeof(auxdata)) 165 - maxbuf = sizeof(auxdata); 166 - 167 - memcpy(buffer, &auxdata, maxbuf); 168 - 169 - return maxbuf; 170 - } 171 217 172 218 static enum 173 219 fscache_checkaux cifs_fscache_inode_check_aux(void *cookie_netfs_data, 174 220 const void *data, 175 - uint16_t datalen) 221 + uint16_t datalen, 222 + loff_t object_size) 176 223 { 177 224 struct cifs_fscache_inode_auxdata auxdata; 178 225 struct cifsInodeInfo *cifsi = cookie_netfs_data; ··· 140 295 const struct fscache_cookie_def cifs_fscache_inode_object_def = { 141 296 .name = "CIFS.uniqueid", 142 297 .type = FSCACHE_COOKIE_TYPE_DATAFILE, 143 - .get_key = cifs_fscache_inode_get_key, 144 - .get_attr = cifs_fscache_inode_get_attr, 145 - .get_aux = cifs_fscache_inode_get_aux, 146 298 .check_aux = cifs_fscache_inode_check_aux, 147 299 };
+109 -21
fs/cifs/fscache.c
··· 23 23 #include "cifs_debug.h" 24 24 #include "cifs_fs_sb.h" 25 25 26 + /* 27 + * Key layout of CIFS server cache index object 28 + */ 29 + struct cifs_server_key { 30 + struct { 31 + uint16_t family; /* address family */ 32 + __be16 port; /* IP port */ 33 + } hdr; 34 + union { 35 + struct in_addr ipv4_addr; 36 + struct in6_addr ipv6_addr; 37 + }; 38 + } __packed; 39 + 40 + /* 41 + * Get a cookie for a server object keyed by {IPaddress,port,family} tuple 42 + */ 26 43 void cifs_fscache_get_client_cookie(struct TCP_Server_Info *server) 27 44 { 45 + const struct sockaddr *sa = (struct sockaddr *) &server->dstaddr; 46 + const struct sockaddr_in *addr = (struct sockaddr_in *) sa; 47 + const struct sockaddr_in6 *addr6 = (struct sockaddr_in6 *) sa; 48 + struct cifs_server_key key; 49 + uint16_t key_len = sizeof(key.hdr); 50 + 51 + memset(&key, 0, sizeof(key)); 52 + 53 + /* 54 + * Should not be a problem as sin_family/sin6_family overlays 55 + * sa_family field 56 + */ 57 + key.hdr.family = sa->sa_family; 58 + switch (sa->sa_family) { 59 + case AF_INET: 60 + key.hdr.port = addr->sin_port; 61 + key.ipv4_addr = addr->sin_addr; 62 + key_len += sizeof(key.ipv4_addr); 63 + break; 64 + 65 + case AF_INET6: 66 + key.hdr.port = addr6->sin6_port; 67 + key.ipv6_addr = addr6->sin6_addr; 68 + key_len += sizeof(key.ipv6_addr); 69 + break; 70 + 71 + default: 72 + cifs_dbg(VFS, "Unknown network family '%d'\n", sa->sa_family); 73 + server->fscache = NULL; 74 + return; 75 + } 76 + 28 77 server->fscache = 29 78 fscache_acquire_cookie(cifs_fscache_netfs.primary_index, 30 - &cifs_fscache_server_index_def, server, true); 79 + &cifs_fscache_server_index_def, 80 + &key, key_len, 81 + NULL, 0, 82 + server, 0, true); 31 83 cifs_dbg(FYI, "%s: (0x%p/0x%p)\n", 32 84 __func__, server, server->fscache); 33 85 } ··· 88 36 { 89 37 cifs_dbg(FYI, "%s: (0x%p/0x%p)\n", 90 38 __func__, server, server->fscache); 91 - fscache_relinquish_cookie(server->fscache, 0); 39 + fscache_relinquish_cookie(server->fscache, NULL, false); 92 40 server->fscache = NULL; 93 41 } 94 42 95 43 void cifs_fscache_get_super_cookie(struct cifs_tcon *tcon) 96 44 { 97 45 struct TCP_Server_Info *server = tcon->ses->server; 46 + char *sharename; 47 + 48 + sharename = extract_sharename(tcon->treeName); 49 + if (IS_ERR(sharename)) { 50 + cifs_dbg(FYI, "%s: couldn't extract sharename\n", __func__); 51 + tcon->fscache = NULL; 52 + return; 53 + } 98 54 99 55 tcon->fscache = 100 56 fscache_acquire_cookie(server->fscache, 101 - &cifs_fscache_super_index_def, tcon, true); 57 + &cifs_fscache_super_index_def, 58 + sharename, strlen(sharename), 59 + &tcon->resource_id, sizeof(tcon->resource_id), 60 + tcon, 0, true); 61 + kfree(sharename); 102 62 cifs_dbg(FYI, "%s: (0x%p/0x%p)\n", 103 63 __func__, server->fscache, tcon->fscache); 104 64 } ··· 118 54 void cifs_fscache_release_super_cookie(struct cifs_tcon *tcon) 119 55 { 120 56 cifs_dbg(FYI, "%s: (0x%p)\n", __func__, tcon->fscache); 121 - fscache_relinquish_cookie(tcon->fscache, 0); 57 + fscache_relinquish_cookie(tcon->fscache, &tcon->resource_id, false); 122 58 tcon->fscache = NULL; 59 + } 60 + 61 + static void cifs_fscache_acquire_inode_cookie(struct cifsInodeInfo *cifsi, 62 + struct cifs_tcon *tcon) 63 + { 64 + struct cifs_fscache_inode_auxdata auxdata; 65 + 66 + memset(&auxdata, 0, sizeof(auxdata)); 67 + auxdata.eof = cifsi->server_eof; 68 + auxdata.last_write_time = cifsi->vfs_inode.i_mtime; 69 + auxdata.last_change_time = cifsi->vfs_inode.i_ctime; 70 + 71 + cifsi->fscache = 72 + fscache_acquire_cookie(tcon->fscache, 73 + &cifs_fscache_inode_object_def, 74 + &cifsi->uniqueid, sizeof(cifsi->uniqueid), 75 + &auxdata, sizeof(auxdata), 76 + cifsi, cifsi->vfs_inode.i_size, true); 123 77 } 124 78 125 79 static void cifs_fscache_enable_inode_cookie(struct inode *inode) ··· 149 67 if (cifsi->fscache) 150 68 return; 151 69 152 - if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_FSCACHE) { 153 - cifsi->fscache = fscache_acquire_cookie(tcon->fscache, 154 - &cifs_fscache_inode_object_def, cifsi, true); 155 - cifs_dbg(FYI, "%s: got FH cookie (0x%p/0x%p)\n", 156 - __func__, tcon->fscache, cifsi->fscache); 157 - } 70 + if (!(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_FSCACHE)) 71 + return; 72 + 73 + cifs_fscache_acquire_inode_cookie(cifsi, tcon); 74 + 75 + cifs_dbg(FYI, "%s: got FH cookie (0x%p/0x%p)\n", 76 + __func__, tcon->fscache, cifsi->fscache); 158 77 } 159 78 160 79 void cifs_fscache_release_inode_cookie(struct inode *inode) 161 80 { 81 + struct cifs_fscache_inode_auxdata auxdata; 162 82 struct cifsInodeInfo *cifsi = CIFS_I(inode); 163 83 164 84 if (cifsi->fscache) { 85 + memset(&auxdata, 0, sizeof(auxdata)); 86 + auxdata.eof = cifsi->server_eof; 87 + auxdata.last_write_time = cifsi->vfs_inode.i_mtime; 88 + auxdata.last_change_time = cifsi->vfs_inode.i_ctime; 89 + 165 90 cifs_dbg(FYI, "%s: (0x%p)\n", __func__, cifsi->fscache); 166 - fscache_relinquish_cookie(cifsi->fscache, 0); 91 + fscache_relinquish_cookie(cifsi->fscache, &auxdata, false); 167 92 cifsi->fscache = NULL; 168 93 } 169 94 } ··· 182 93 if (cifsi->fscache) { 183 94 cifs_dbg(FYI, "%s: (0x%p)\n", __func__, cifsi->fscache); 184 95 fscache_uncache_all_inode_pages(cifsi->fscache, inode); 185 - fscache_relinquish_cookie(cifsi->fscache, 1); 96 + fscache_relinquish_cookie(cifsi->fscache, NULL, true); 186 97 cifsi->fscache = NULL; 187 98 } 188 99 } ··· 199 110 { 200 111 struct cifsInodeInfo *cifsi = CIFS_I(inode); 201 112 struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb); 113 + struct cifs_tcon *tcon = cifs_sb_master_tcon(cifs_sb); 202 114 struct fscache_cookie *old = cifsi->fscache; 203 115 204 116 if (cifsi->fscache) { 205 117 /* retire the current fscache cache and get a new one */ 206 - fscache_relinquish_cookie(cifsi->fscache, 1); 118 + fscache_relinquish_cookie(cifsi->fscache, NULL, true); 207 119 208 - cifsi->fscache = fscache_acquire_cookie( 209 - cifs_sb_master_tcon(cifs_sb)->fscache, 210 - &cifs_fscache_inode_object_def, 211 - cifsi, true); 120 + cifs_fscache_acquire_inode_cookie(cifsi, tcon); 212 121 cifs_dbg(FYI, "%s: new cookie 0x%p oldcookie 0x%p\n", 213 122 __func__, cifsi->fscache, old); 214 123 } ··· 301 214 302 215 void __cifs_readpage_to_fscache(struct inode *inode, struct page *page) 303 216 { 217 + struct cifsInodeInfo *cifsi = CIFS_I(inode); 304 218 int ret; 305 219 306 220 cifs_dbg(FYI, "%s: (fsc: %p, p: %p, i: %p)\n", 307 - __func__, CIFS_I(inode)->fscache, page, inode); 308 - ret = fscache_write_page(CIFS_I(inode)->fscache, page, GFP_KERNEL); 221 + __func__, cifsi->fscache, page, inode); 222 + ret = fscache_write_page(cifsi->fscache, page, 223 + cifsi->vfs_inode.i_size, GFP_KERNEL); 309 224 if (ret != 0) 310 - fscache_uncache_page(CIFS_I(inode)->fscache, page); 225 + fscache_uncache_page(cifsi->fscache, page); 311 226 } 312 227 313 228 void __cifs_fscache_readpages_cancel(struct inode *inode, struct list_head *pages) ··· 328 239 fscache_wait_on_page_write(cookie, page); 329 240 fscache_uncache_page(cookie, page); 330 241 } 331 -
+13
fs/cifs/fscache.h
··· 27 27 28 28 #ifdef CONFIG_CIFS_FSCACHE 29 29 30 + /* 31 + * Auxiliary data attached to CIFS inode within the cache 32 + */ 33 + struct cifs_fscache_inode_auxdata { 34 + struct timespec last_write_time; 35 + struct timespec last_change_time; 36 + u64 eof; 37 + }; 38 + 39 + /* 40 + * cache.c 41 + */ 30 42 extern struct fscache_netfs cifs_fscache_netfs; 31 43 extern const struct fscache_cookie_def cifs_fscache_server_index_def; 32 44 extern const struct fscache_cookie_def cifs_fscache_super_index_def; ··· 46 34 47 35 extern int cifs_fscache_register(void); 48 36 extern void cifs_fscache_unregister(void); 37 + extern char *extract_sharename(const char *); 49 38 50 39 /* 51 40 * fscache.c
+1 -1
fs/fscache/cache.c
··· 125 125 } 126 126 127 127 /* the parent is unbacked */ 128 - if (cookie->def->type != FSCACHE_COOKIE_TYPE_INDEX) { 128 + if (cookie->type != FSCACHE_COOKIE_TYPE_INDEX) { 129 129 /* cookie not an index and is unbacked */ 130 130 spin_unlock(&cookie->lock); 131 131 _leave(" = NULL [cookie ub,ni]");
+317 -71
fs/fscache/cookie.c
··· 21 21 22 22 static atomic_t fscache_object_debug_id = ATOMIC_INIT(0); 23 23 24 - static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie); 24 + #define fscache_cookie_hash_shift 15 25 + static struct hlist_bl_head fscache_cookie_hash[1 << fscache_cookie_hash_shift]; 26 + 27 + static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie, 28 + loff_t object_size); 25 29 static int fscache_alloc_object(struct fscache_cache *cache, 26 30 struct fscache_cookie *cookie); 27 31 static int fscache_attach_object(struct fscache_cookie *cookie, 28 32 struct fscache_object *object); 33 + 34 + static void fscache_print_cookie(struct fscache_cookie *cookie, char prefix) 35 + { 36 + struct hlist_node *object; 37 + const u8 *k; 38 + unsigned loop; 39 + 40 + pr_err("%c-cookie c=%p [p=%p fl=%lx nc=%u na=%u]\n", 41 + prefix, cookie, cookie->parent, cookie->flags, 42 + atomic_read(&cookie->n_children), 43 + atomic_read(&cookie->n_active)); 44 + pr_err("%c-cookie d=%p n=%p\n", 45 + prefix, cookie->def, cookie->netfs_data); 46 + 47 + object = READ_ONCE(cookie->backing_objects.first); 48 + if (object) 49 + pr_err("%c-cookie o=%p\n", 50 + prefix, hlist_entry(object, struct fscache_object, cookie_link)); 51 + 52 + pr_err("%c-key=[%u] '", prefix, cookie->key_len); 53 + k = (cookie->key_len <= sizeof(cookie->inline_key)) ? 54 + cookie->inline_key : cookie->key; 55 + for (loop = 0; loop < cookie->key_len; loop++) 56 + pr_cont("%02x", k[loop]); 57 + pr_cont("'\n"); 58 + } 59 + 60 + void fscache_free_cookie(struct fscache_cookie *cookie) 61 + { 62 + if (cookie) { 63 + BUG_ON(!hlist_empty(&cookie->backing_objects)); 64 + if (cookie->aux_len > sizeof(cookie->inline_aux)) 65 + kfree(cookie->aux); 66 + if (cookie->key_len > sizeof(cookie->inline_key)) 67 + kfree(cookie->key); 68 + kmem_cache_free(fscache_cookie_jar, cookie); 69 + } 70 + } 29 71 30 72 /* 31 73 * initialise an cookie jar slab element prior to any use ··· 80 38 spin_lock_init(&cookie->lock); 81 39 spin_lock_init(&cookie->stores_lock); 82 40 INIT_HLIST_HEAD(&cookie->backing_objects); 41 + } 42 + 43 + /* 44 + * Set the index key in a cookie. The cookie struct has space for a 12-byte 45 + * key plus length and hash, but if that's not big enough, it's instead a 46 + * pointer to a buffer containing 3 bytes of hash, 1 byte of length and then 47 + * the key data. 48 + */ 49 + static int fscache_set_key(struct fscache_cookie *cookie, 50 + const void *index_key, size_t index_key_len) 51 + { 52 + unsigned long long h; 53 + u32 *buf; 54 + int i; 55 + 56 + cookie->key_len = index_key_len; 57 + 58 + if (index_key_len > sizeof(cookie->inline_key)) { 59 + buf = kzalloc(index_key_len, GFP_KERNEL); 60 + if (!buf) 61 + return -ENOMEM; 62 + cookie->key = buf; 63 + } else { 64 + buf = (u32 *)cookie->inline_key; 65 + buf[0] = 0; 66 + buf[1] = 0; 67 + buf[2] = 0; 68 + } 69 + 70 + memcpy(buf, index_key, index_key_len); 71 + 72 + /* Calculate a hash and combine this with the length in the first word 73 + * or first half word 74 + */ 75 + h = (unsigned long)cookie->parent; 76 + h += index_key_len + cookie->type; 77 + for (i = 0; i < (index_key_len + sizeof(u32) - 1) / sizeof(u32); i++) 78 + h += buf[i]; 79 + 80 + cookie->key_hash = h ^ (h >> 32); 81 + return 0; 82 + } 83 + 84 + static long fscache_compare_cookie(const struct fscache_cookie *a, 85 + const struct fscache_cookie *b) 86 + { 87 + const void *ka, *kb; 88 + 89 + if (a->key_hash != b->key_hash) 90 + return (long)a->key_hash - (long)b->key_hash; 91 + if (a->parent != b->parent) 92 + return (long)a->parent - (long)b->parent; 93 + if (a->key_len != b->key_len) 94 + return (long)a->key_len - (long)b->key_len; 95 + if (a->type != b->type) 96 + return (long)a->type - (long)b->type; 97 + 98 + if (a->key_len <= sizeof(a->inline_key)) { 99 + ka = &a->inline_key; 100 + kb = &b->inline_key; 101 + } else { 102 + ka = a->key; 103 + kb = b->key; 104 + } 105 + return memcmp(ka, kb, a->key_len); 106 + } 107 + 108 + /* 109 + * Allocate a cookie. 110 + */ 111 + struct fscache_cookie *fscache_alloc_cookie( 112 + struct fscache_cookie *parent, 113 + const struct fscache_cookie_def *def, 114 + const void *index_key, size_t index_key_len, 115 + const void *aux_data, size_t aux_data_len, 116 + void *netfs_data, 117 + loff_t object_size) 118 + { 119 + struct fscache_cookie *cookie; 120 + 121 + /* allocate and initialise a cookie */ 122 + cookie = kmem_cache_alloc(fscache_cookie_jar, GFP_KERNEL); 123 + if (!cookie) 124 + return NULL; 125 + 126 + cookie->key_len = index_key_len; 127 + cookie->aux_len = aux_data_len; 128 + 129 + if (fscache_set_key(cookie, index_key, index_key_len) < 0) 130 + goto nomem; 131 + 132 + if (cookie->aux_len <= sizeof(cookie->inline_aux)) { 133 + memcpy(cookie->inline_aux, aux_data, cookie->aux_len); 134 + } else { 135 + cookie->aux = kmemdup(aux_data, cookie->aux_len, GFP_KERNEL); 136 + if (!cookie->aux) 137 + goto nomem; 138 + } 139 + 140 + atomic_set(&cookie->usage, 1); 141 + atomic_set(&cookie->n_children, 0); 142 + 143 + /* We keep the active count elevated until relinquishment to prevent an 144 + * attempt to wake up every time the object operations queue quiesces. 145 + */ 146 + atomic_set(&cookie->n_active, 1); 147 + 148 + cookie->def = def; 149 + cookie->parent = parent; 150 + cookie->netfs_data = netfs_data; 151 + cookie->flags = (1 << FSCACHE_COOKIE_NO_DATA_YET); 152 + cookie->type = def->type; 153 + 154 + /* radix tree insertion won't use the preallocation pool unless it's 155 + * told it may not wait */ 156 + INIT_RADIX_TREE(&cookie->stores, GFP_NOFS & ~__GFP_DIRECT_RECLAIM); 157 + return cookie; 158 + 159 + nomem: 160 + fscache_free_cookie(cookie); 161 + return NULL; 162 + } 163 + 164 + /* 165 + * Attempt to insert the new cookie into the hash. If there's a collision, we 166 + * return the old cookie if it's not in use and an error otherwise. 167 + */ 168 + struct fscache_cookie *fscache_hash_cookie(struct fscache_cookie *candidate) 169 + { 170 + struct fscache_cookie *cursor; 171 + struct hlist_bl_head *h; 172 + struct hlist_bl_node *p; 173 + unsigned int bucket; 174 + 175 + bucket = candidate->key_hash & (ARRAY_SIZE(fscache_cookie_hash) - 1); 176 + h = &fscache_cookie_hash[bucket]; 177 + 178 + hlist_bl_lock(h); 179 + hlist_bl_for_each_entry(cursor, p, h, hash_link) { 180 + if (fscache_compare_cookie(candidate, cursor) == 0) 181 + goto collision; 182 + } 183 + 184 + __set_bit(FSCACHE_COOKIE_ACQUIRED, &candidate->flags); 185 + fscache_cookie_get(candidate->parent, fscache_cookie_get_acquire_parent); 186 + atomic_inc(&candidate->parent->n_children); 187 + hlist_bl_add_head(&candidate->hash_link, h); 188 + hlist_bl_unlock(h); 189 + return candidate; 190 + 191 + collision: 192 + if (test_and_set_bit(FSCACHE_COOKIE_ACQUIRED, &cursor->flags)) { 193 + trace_fscache_cookie(cursor, fscache_cookie_collision, 194 + atomic_read(&cursor->usage)); 195 + pr_err("Duplicate cookie detected\n"); 196 + fscache_print_cookie(cursor, 'O'); 197 + fscache_print_cookie(candidate, 'N'); 198 + hlist_bl_unlock(h); 199 + return NULL; 200 + } 201 + 202 + fscache_cookie_get(cursor, fscache_cookie_get_reacquire); 203 + hlist_bl_unlock(h); 204 + return cursor; 83 205 } 84 206 85 207 /* ··· 264 58 struct fscache_cookie *__fscache_acquire_cookie( 265 59 struct fscache_cookie *parent, 266 60 const struct fscache_cookie_def *def, 61 + const void *index_key, size_t index_key_len, 62 + const void *aux_data, size_t aux_data_len, 267 63 void *netfs_data, 64 + loff_t object_size, 268 65 bool enable) 269 66 { 270 - struct fscache_cookie *cookie; 67 + struct fscache_cookie *candidate, *cookie; 271 68 272 69 BUG_ON(!def); 273 70 274 71 _enter("{%s},{%s},%p,%u", 275 72 parent ? (char *) parent->def->name : "<no-parent>", 276 73 def->name, netfs_data, enable); 74 + 75 + if (!index_key || !index_key_len || index_key_len > 255 || aux_data_len > 255) 76 + return NULL; 77 + if (!aux_data || !aux_data_len) { 78 + aux_data = NULL; 79 + aux_data_len = 0; 80 + } 277 81 278 82 fscache_stat(&fscache_n_acquires); 279 83 ··· 295 79 } 296 80 297 81 /* validate the definition */ 298 - BUG_ON(!def->get_key); 299 82 BUG_ON(!def->name[0]); 300 83 301 84 BUG_ON(def->type == FSCACHE_COOKIE_TYPE_INDEX && 302 - parent->def->type != FSCACHE_COOKIE_TYPE_INDEX); 85 + parent->type != FSCACHE_COOKIE_TYPE_INDEX); 303 86 304 - /* allocate and initialise a cookie */ 305 - cookie = kmem_cache_alloc(fscache_cookie_jar, GFP_KERNEL); 306 - if (!cookie) { 87 + candidate = fscache_alloc_cookie(parent, def, 88 + index_key, index_key_len, 89 + aux_data, aux_data_len, 90 + netfs_data, object_size); 91 + if (!candidate) { 307 92 fscache_stat(&fscache_n_acquires_oom); 308 93 _leave(" [ENOMEM]"); 309 94 return NULL; 310 95 } 311 96 312 - atomic_set(&cookie->usage, 1); 313 - atomic_set(&cookie->n_children, 0); 97 + cookie = fscache_hash_cookie(candidate); 98 + if (!cookie) { 99 + trace_fscache_cookie(candidate, fscache_cookie_discard, 1); 100 + goto out; 101 + } 314 102 315 - /* We keep the active count elevated until relinquishment to prevent an 316 - * attempt to wake up every time the object operations queue quiesces. 317 - */ 318 - atomic_set(&cookie->n_active, 1); 103 + if (cookie == candidate) 104 + candidate = NULL; 319 105 320 - atomic_inc(&parent->usage); 321 - atomic_inc(&parent->n_children); 322 - 323 - cookie->def = def; 324 - cookie->parent = parent; 325 - cookie->netfs_data = netfs_data; 326 - cookie->flags = (1 << FSCACHE_COOKIE_NO_DATA_YET); 327 - 328 - /* radix tree insertion won't use the preallocation pool unless it's 329 - * told it may not wait */ 330 - INIT_RADIX_TREE(&cookie->stores, GFP_NOFS & ~__GFP_DIRECT_RECLAIM); 331 - 332 - switch (cookie->def->type) { 106 + switch (cookie->type) { 333 107 case FSCACHE_COOKIE_TYPE_INDEX: 334 108 fscache_stat(&fscache_n_cookie_index); 335 109 break; ··· 331 125 break; 332 126 } 333 127 128 + trace_fscache_acquire(cookie); 129 + 334 130 if (enable) { 335 131 /* if the object is an index then we need do nothing more here 336 132 * - we create indices on disk when we need them as an index 337 133 * may exist in multiple caches */ 338 - if (cookie->def->type != FSCACHE_COOKIE_TYPE_INDEX) { 339 - if (fscache_acquire_non_index_cookie(cookie) == 0) { 134 + if (cookie->type != FSCACHE_COOKIE_TYPE_INDEX) { 135 + if (fscache_acquire_non_index_cookie(cookie, object_size) == 0) { 340 136 set_bit(FSCACHE_COOKIE_ENABLED, &cookie->flags); 341 137 } else { 342 138 atomic_dec(&parent->n_children); 343 - __fscache_cookie_put(cookie); 139 + fscache_cookie_put(cookie, 140 + fscache_cookie_put_acquire_nobufs); 344 141 fscache_stat(&fscache_n_acquires_nobufs); 345 142 _leave(" = NULL"); 346 143 return NULL; ··· 354 145 } 355 146 356 147 fscache_stat(&fscache_n_acquires_ok); 357 - _leave(" = %p", cookie); 148 + 149 + out: 150 + fscache_free_cookie(candidate); 358 151 return cookie; 359 152 } 360 153 EXPORT_SYMBOL(__fscache_acquire_cookie); ··· 365 154 * Enable a cookie to permit it to accept new operations. 366 155 */ 367 156 void __fscache_enable_cookie(struct fscache_cookie *cookie, 157 + const void *aux_data, 158 + loff_t object_size, 368 159 bool (*can_enable)(void *data), 369 160 void *data) 370 161 { 371 162 _enter("%p", cookie); 372 163 164 + trace_fscache_enable(cookie); 165 + 373 166 wait_on_bit_lock(&cookie->flags, FSCACHE_COOKIE_ENABLEMENT_LOCK, 374 167 TASK_UNINTERRUPTIBLE); 168 + 169 + fscache_update_aux(cookie, aux_data); 375 170 376 171 if (test_bit(FSCACHE_COOKIE_ENABLED, &cookie->flags)) 377 172 goto out_unlock; 378 173 379 174 if (can_enable && !can_enable(data)) { 380 175 /* The netfs decided it didn't want to enable after all */ 381 - } else if (cookie->def->type != FSCACHE_COOKIE_TYPE_INDEX) { 176 + } else if (cookie->type != FSCACHE_COOKIE_TYPE_INDEX) { 382 177 /* Wait for outstanding disablement to complete */ 383 178 __fscache_wait_on_invalidate(cookie); 384 179 385 - if (fscache_acquire_non_index_cookie(cookie) == 0) 180 + if (fscache_acquire_non_index_cookie(cookie, object_size) == 0) 386 181 set_bit(FSCACHE_COOKIE_ENABLED, &cookie->flags); 387 182 } else { 388 183 set_bit(FSCACHE_COOKIE_ENABLED, &cookie->flags); ··· 405 188 * - this must make sure the index chain is instantiated and instantiate the 406 189 * object representation too 407 190 */ 408 - static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie) 191 + static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie, 192 + loff_t object_size) 409 193 { 410 194 struct fscache_object *object; 411 195 struct fscache_cache *cache; 412 - uint64_t i_size; 413 196 int ret; 414 197 415 198 _enter(""); ··· 448 231 return ret; 449 232 } 450 233 451 - /* pass on how big the object we're caching is supposed to be */ 452 - cookie->def->get_attr(cookie->netfs_data, &i_size); 453 - 454 234 spin_lock(&cookie->lock); 455 235 if (hlist_empty(&cookie->backing_objects)) { 456 236 spin_unlock(&cookie->lock); ··· 457 243 object = hlist_entry(cookie->backing_objects.first, 458 244 struct fscache_object, cookie_link); 459 245 460 - fscache_set_store_limit(object, i_size); 246 + fscache_set_store_limit(object, object_size); 461 247 462 248 /* initiate the process of looking up all the objects in the chain 463 249 * (done by fscache_initialise_object()) */ ··· 532 318 * attached to the cookie */ 533 319 if (fscache_attach_object(cookie, object) < 0) { 534 320 fscache_stat(&fscache_n_cop_put_object); 535 - cache->ops->put_object(object); 321 + cache->ops->put_object(object, fscache_obj_put_attach_fail); 536 322 fscache_stat_d(&fscache_n_cop_put_object); 537 323 } 538 324 ··· 552 338 553 339 error_put: 554 340 fscache_stat(&fscache_n_cop_put_object); 555 - cache->ops->put_object(object); 341 + cache->ops->put_object(object, fscache_obj_put_alloc_fail); 556 342 fscache_stat_d(&fscache_n_cop_put_object); 557 343 error: 558 344 _leave(" = %d", ret); ··· 612 398 613 399 /* attach to the cookie */ 614 400 object->cookie = cookie; 615 - atomic_inc(&cookie->usage); 401 + fscache_cookie_get(cookie, fscache_cookie_get_attach_object); 616 402 hlist_add_head(&object->cookie_link, &cookie->backing_objects); 617 403 618 404 fscache_objlist_add(object); ··· 640 426 * there, and if it's doing that, it may as well just retire the 641 427 * cookie. 642 428 */ 643 - ASSERTCMP(cookie->def->type, ==, FSCACHE_COOKIE_TYPE_DATAFILE); 644 - 645 - /* We will be updating the cookie too. */ 646 - BUG_ON(!cookie->def->get_aux); 429 + ASSERTCMP(cookie->type, ==, FSCACHE_COOKIE_TYPE_DATAFILE); 647 430 648 431 /* If there's an object, we tell the object state machine to handle the 649 432 * invalidation on our behalf, otherwise there's nothing to do. ··· 684 473 /* 685 474 * update the index entries backing a cookie 686 475 */ 687 - void __fscache_update_cookie(struct fscache_cookie *cookie) 476 + void __fscache_update_cookie(struct fscache_cookie *cookie, const void *aux_data) 688 477 { 689 478 struct fscache_object *object; 690 479 ··· 698 487 699 488 _enter("{%s}", cookie->def->name); 700 489 701 - BUG_ON(!cookie->def->get_aux); 702 - 703 490 spin_lock(&cookie->lock); 491 + 492 + fscache_update_aux(cookie, aux_data); 704 493 705 494 if (fscache_cookie_enabled(cookie)) { 706 495 /* update the index entry on disk in each cache backing this ··· 720 509 /* 721 510 * Disable a cookie to stop it from accepting new requests from the netfs. 722 511 */ 723 - void __fscache_disable_cookie(struct fscache_cookie *cookie, bool invalidate) 512 + void __fscache_disable_cookie(struct fscache_cookie *cookie, 513 + const void *aux_data, 514 + bool invalidate) 724 515 { 725 516 struct fscache_object *object; 726 517 bool awaken = false; 727 518 728 519 _enter("%p,%u", cookie, invalidate); 520 + 521 + trace_fscache_disable(cookie); 729 522 730 523 ASSERTCMP(atomic_read(&cookie->n_active), >, 0); 731 524 ··· 741 526 742 527 wait_on_bit_lock(&cookie->flags, FSCACHE_COOKIE_ENABLEMENT_LOCK, 743 528 TASK_UNINTERRUPTIBLE); 529 + 530 + fscache_update_aux(cookie, aux_data); 531 + 744 532 if (!test_and_clear_bit(FSCACHE_COOKIE_ENABLED, &cookie->flags)) 745 533 goto out_unlock_enable; 746 534 ··· 781 563 } 782 564 783 565 /* Make sure any pending writes are cancelled. */ 784 - if (cookie->def->type != FSCACHE_COOKIE_TYPE_INDEX) 566 + if (cookie->type != FSCACHE_COOKIE_TYPE_INDEX) 785 567 fscache_invalidate_writes(cookie); 786 568 787 569 /* Reset the cookie state if it wasn't relinquished */ ··· 803 585 * - all dependents of this cookie must have already been unregistered 804 586 * (indices/files/pages) 805 587 */ 806 - void __fscache_relinquish_cookie(struct fscache_cookie *cookie, bool retire) 588 + void __fscache_relinquish_cookie(struct fscache_cookie *cookie, 589 + const void *aux_data, 590 + bool retire) 807 591 { 808 592 fscache_stat(&fscache_n_relinquishes); 809 593 if (retire) ··· 821 601 cookie, cookie->def->name, cookie->netfs_data, 822 602 atomic_read(&cookie->n_active), retire); 823 603 824 - /* No further netfs-accessing operations on this cookie permitted */ 825 - set_bit(FSCACHE_COOKIE_RELINQUISHED, &cookie->flags); 604 + trace_fscache_relinquish(cookie, retire); 826 605 827 - __fscache_disable_cookie(cookie, retire); 606 + /* No further netfs-accessing operations on this cookie permitted */ 607 + if (test_and_set_bit(FSCACHE_COOKIE_RELINQUISHED, &cookie->flags)) 608 + BUG(); 609 + 610 + __fscache_disable_cookie(cookie, aux_data, retire); 828 611 829 612 /* Clear pointers back to the netfs */ 830 613 cookie->netfs_data = NULL; ··· 842 619 843 620 /* Dispose of the netfs's link to the cookie */ 844 621 ASSERTCMP(atomic_read(&cookie->usage), >, 0); 845 - fscache_cookie_put(cookie); 622 + fscache_cookie_put(cookie, fscache_cookie_put_relinquish); 846 623 847 624 _leave(""); 848 625 } 849 626 EXPORT_SYMBOL(__fscache_relinquish_cookie); 850 627 851 628 /* 852 - * destroy a cookie 629 + * Remove a cookie from the hash table. 853 630 */ 854 - void __fscache_cookie_put(struct fscache_cookie *cookie) 631 + static void fscache_unhash_cookie(struct fscache_cookie *cookie) 632 + { 633 + struct hlist_bl_head *h; 634 + unsigned int bucket; 635 + 636 + bucket = cookie->key_hash & (ARRAY_SIZE(fscache_cookie_hash) - 1); 637 + h = &fscache_cookie_hash[bucket]; 638 + 639 + hlist_bl_lock(h); 640 + hlist_bl_del(&cookie->hash_link); 641 + hlist_bl_unlock(h); 642 + } 643 + 644 + /* 645 + * Drop a reference to a cookie. 646 + */ 647 + void fscache_cookie_put(struct fscache_cookie *cookie, 648 + enum fscache_cookie_trace where) 855 649 { 856 650 struct fscache_cookie *parent; 651 + int usage; 857 652 858 653 _enter("%p", cookie); 859 654 860 - for (;;) { 861 - _debug("FREE COOKIE %p", cookie); 862 - parent = cookie->parent; 863 - BUG_ON(!hlist_empty(&cookie->backing_objects)); 864 - kmem_cache_free(fscache_cookie_jar, cookie); 655 + do { 656 + usage = atomic_dec_return(&cookie->usage); 657 + trace_fscache_cookie(cookie, where, usage); 865 658 866 - if (!parent) 867 - break; 659 + if (usage > 0) 660 + return; 661 + BUG_ON(usage < 0); 662 + 663 + parent = cookie->parent; 664 + fscache_unhash_cookie(cookie); 665 + fscache_free_cookie(cookie); 868 666 869 667 cookie = parent; 870 - BUG_ON(atomic_read(&cookie->usage) <= 0); 871 - if (!atomic_dec_and_test(&cookie->usage)) 872 - break; 873 - } 668 + where = fscache_cookie_put_parent; 669 + } while (cookie); 874 670 875 671 _leave(""); 876 672 } ··· 899 657 * 900 658 * NOTE: it only serves no-index type 901 659 */ 902 - int __fscache_check_consistency(struct fscache_cookie *cookie) 660 + int __fscache_check_consistency(struct fscache_cookie *cookie, 661 + const void *aux_data) 903 662 { 904 663 struct fscache_operation *op; 905 664 struct fscache_object *object; ··· 909 666 910 667 _enter("%p,", cookie); 911 668 912 - ASSERTCMP(cookie->def->type, ==, FSCACHE_COOKIE_TYPE_DATAFILE); 669 + ASSERTCMP(cookie->type, ==, FSCACHE_COOKIE_TYPE_DATAFILE); 913 670 914 671 if (fscache_wait_for_deferred_lookup(cookie) < 0) 915 672 return -ERESTARTSYS; ··· 921 678 if (!op) 922 679 return -ENOMEM; 923 680 924 - fscache_operation_init(op, NULL, NULL, NULL); 681 + fscache_operation_init(cookie, op, NULL, NULL, NULL); 925 682 op->flags = FSCACHE_OP_MYTHREAD | 926 683 (1 << FSCACHE_OP_WAITING) | 927 684 (1 << FSCACHE_OP_UNUSE_COOKIE); 685 + trace_fscache_page_op(cookie, NULL, op, fscache_page_op_check_consistency); 928 686 929 687 spin_lock(&cookie->lock); 688 + 689 + fscache_update_aux(cookie, aux_data); 930 690 931 691 if (!fscache_cookie_enabled(cookie) || 932 692 hlist_empty(&cookie->backing_objects))
+5 -50
fs/fscache/fsdef.c
··· 13 13 #include <linux/module.h> 14 14 #include "internal.h" 15 15 16 - static uint16_t fscache_fsdef_netfs_get_key(const void *cookie_netfs_data, 17 - void *buffer, uint16_t bufmax); 18 - 19 - static uint16_t fscache_fsdef_netfs_get_aux(const void *cookie_netfs_data, 20 - void *buffer, uint16_t bufmax); 21 - 22 16 static 23 17 enum fscache_checkaux fscache_fsdef_netfs_check_aux(void *cookie_netfs_data, 24 18 const void *data, 25 - uint16_t datalen); 19 + uint16_t datalen, 20 + loff_t object_size); 26 21 27 22 /* 28 23 * The root index is owned by FS-Cache itself. ··· 55 60 .backing_objects = HLIST_HEAD_INIT, 56 61 .def = &fscache_fsdef_index_def, 57 62 .flags = 1 << FSCACHE_COOKIE_ENABLED, 63 + .type = FSCACHE_COOKIE_TYPE_INDEX, 58 64 }; 59 65 EXPORT_SYMBOL(fscache_fsdef_index); 60 66 ··· 67 71 struct fscache_cookie_def fscache_fsdef_netfs_def = { 68 72 .name = "FSDEF.netfs", 69 73 .type = FSCACHE_COOKIE_TYPE_INDEX, 70 - .get_key = fscache_fsdef_netfs_get_key, 71 - .get_aux = fscache_fsdef_netfs_get_aux, 72 74 .check_aux = fscache_fsdef_netfs_check_aux, 73 75 }; 74 - 75 - /* 76 - * get the key data for an FSDEF index record - this is the name of the netfs 77 - * for which this entry is created 78 - */ 79 - static uint16_t fscache_fsdef_netfs_get_key(const void *cookie_netfs_data, 80 - void *buffer, uint16_t bufmax) 81 - { 82 - const struct fscache_netfs *netfs = cookie_netfs_data; 83 - unsigned klen; 84 - 85 - _enter("{%s.%u},", netfs->name, netfs->version); 86 - 87 - klen = strlen(netfs->name); 88 - if (klen > bufmax) 89 - return 0; 90 - 91 - memcpy(buffer, netfs->name, klen); 92 - return klen; 93 - } 94 - 95 - /* 96 - * get the auxiliary data for an FSDEF index record - this is the index 97 - * structure version number of the netfs for which this version is created 98 - */ 99 - static uint16_t fscache_fsdef_netfs_get_aux(const void *cookie_netfs_data, 100 - void *buffer, uint16_t bufmax) 101 - { 102 - const struct fscache_netfs *netfs = cookie_netfs_data; 103 - unsigned dlen; 104 - 105 - _enter("{%s.%u},", netfs->name, netfs->version); 106 - 107 - dlen = sizeof(uint32_t); 108 - if (dlen > bufmax) 109 - return 0; 110 - 111 - memcpy(buffer, &netfs->version, dlen); 112 - return dlen; 113 - } 114 76 115 77 /* 116 78 * check that the index structure version number stored in the auxiliary data ··· 77 123 static enum fscache_checkaux fscache_fsdef_netfs_check_aux( 78 124 void *cookie_netfs_data, 79 125 const void *data, 80 - uint16_t datalen) 126 + uint16_t datalen, 127 + loff_t object_size) 81 128 { 82 129 struct fscache_netfs *netfs = cookie_netfs_data; 83 130 uint32_t version;
+36 -8
fs/fscache/internal.h
··· 29 29 #define pr_fmt(fmt) "FS-Cache: " fmt 30 30 31 31 #include <linux/fscache-cache.h> 32 + #include <trace/events/fscache.h> 32 33 #include <linux/sched.h> 33 34 34 35 #define FSCACHE_MIN_THREADS 4 ··· 49 48 */ 50 49 extern struct kmem_cache *fscache_cookie_jar; 51 50 51 + extern void fscache_free_cookie(struct fscache_cookie *); 52 52 extern void fscache_cookie_init_once(void *); 53 - extern void __fscache_cookie_put(struct fscache_cookie *); 53 + extern struct fscache_cookie *fscache_alloc_cookie(struct fscache_cookie *, 54 + const struct fscache_cookie_def *, 55 + const void *, size_t, 56 + const void *, size_t, 57 + void *, loff_t); 58 + extern struct fscache_cookie *fscache_hash_cookie(struct fscache_cookie *); 59 + extern void fscache_cookie_put(struct fscache_cookie *, 60 + enum fscache_cookie_trace); 54 61 55 62 /* 56 63 * fsdef.c ··· 320 311 fscache_enqueue_object(object); 321 312 } 322 313 323 - /* 324 - * drop a reference to a cookie 325 - */ 326 - static inline void fscache_cookie_put(struct fscache_cookie *cookie) 314 + static inline void fscache_cookie_get(struct fscache_cookie *cookie, 315 + enum fscache_cookie_trace where) 327 316 { 328 - BUG_ON(atomic_read(&cookie->usage) <= 0); 329 - if (atomic_dec_and_test(&cookie->usage)) 330 - __fscache_cookie_put(cookie); 317 + int usage = atomic_inc_return(&cookie->usage); 318 + 319 + trace_fscache_cookie(cookie, where, usage); 331 320 } 332 321 333 322 /* ··· 347 340 { 348 341 if (cookie->def->put_context) 349 342 cookie->def->put_context(cookie->netfs_data, context); 343 + } 344 + 345 + /* 346 + * Update the auxiliary data on a cookie. 347 + */ 348 + static inline 349 + void fscache_update_aux(struct fscache_cookie *cookie, const void *aux_data) 350 + { 351 + void *p; 352 + 353 + if (!aux_data) 354 + return; 355 + if (cookie->aux_len <= sizeof(cookie->inline_aux)) 356 + p = cookie->inline_aux; 357 + else 358 + p = cookie->aux; 359 + 360 + if (memcmp(p, aux_data, cookie->aux_len) != 0) { 361 + memcpy(p, aux_data, cookie->aux_len); 362 + set_bit(FSCACHE_COOKIE_AUX_UPDATED, &cookie->flags); 363 + } 350 364 } 351 365 352 366 /*****************************************************************************/
+1
fs/fscache/main.c
··· 16 16 #include <linux/completion.h> 17 17 #include <linux/slab.h> 18 18 #include <linux/seq_file.h> 19 + #define CREATE_TRACE_POINTS 19 20 #include "internal.h" 20 21 21 22 MODULE_DESCRIPTION("FS Cache Manager");
+23 -48
fs/fscache/netfs.c
··· 14 14 #include <linux/slab.h> 15 15 #include "internal.h" 16 16 17 - static LIST_HEAD(fscache_netfs_list); 18 - 19 17 /* 20 18 * register a network filesystem for caching 21 19 */ 22 20 int __fscache_register_netfs(struct fscache_netfs *netfs) 23 21 { 24 - struct fscache_netfs *ptr; 25 - struct fscache_cookie *cookie; 26 - int ret; 22 + struct fscache_cookie *candidate, *cookie; 27 23 28 24 _enter("{%s}", netfs->name); 29 25 30 - INIT_LIST_HEAD(&netfs->link); 31 - 32 26 /* allocate a cookie for the primary index */ 33 - cookie = kmem_cache_zalloc(fscache_cookie_jar, GFP_KERNEL); 34 - 35 - if (!cookie) { 27 + candidate = fscache_alloc_cookie(&fscache_fsdef_index, 28 + &fscache_fsdef_netfs_def, 29 + netfs->name, strlen(netfs->name), 30 + &netfs->version, sizeof(netfs->version), 31 + netfs, 0); 32 + if (!candidate) { 36 33 _leave(" = -ENOMEM"); 37 34 return -ENOMEM; 38 35 } 39 36 40 - /* initialise the primary index cookie */ 41 - atomic_set(&cookie->usage, 1); 42 - atomic_set(&cookie->n_children, 0); 43 - atomic_set(&cookie->n_active, 1); 44 - 45 - cookie->def = &fscache_fsdef_netfs_def; 46 - cookie->parent = &fscache_fsdef_index; 47 - cookie->netfs_data = netfs; 48 - cookie->flags = 1 << FSCACHE_COOKIE_ENABLED; 49 - 50 - spin_lock_init(&cookie->lock); 51 - spin_lock_init(&cookie->stores_lock); 52 - INIT_HLIST_HEAD(&cookie->backing_objects); 37 + candidate->flags = 1 << FSCACHE_COOKIE_ENABLED; 53 38 54 39 /* check the netfs type is not already present */ 55 - down_write(&fscache_addremove_sem); 56 - 57 - ret = -EEXIST; 58 - list_for_each_entry(ptr, &fscache_netfs_list, link) { 59 - if (strcmp(ptr->name, netfs->name) == 0) 60 - goto already_registered; 40 + cookie = fscache_hash_cookie(candidate); 41 + if (!cookie) 42 + goto already_registered; 43 + if (cookie != candidate) { 44 + trace_fscache_cookie(candidate, fscache_cookie_discard, 1); 45 + fscache_free_cookie(candidate); 61 46 } 62 47 63 - atomic_inc(&cookie->parent->usage); 48 + fscache_cookie_get(cookie->parent, fscache_cookie_get_register_netfs); 64 49 atomic_inc(&cookie->parent->n_children); 65 50 66 51 netfs->primary_index = cookie; 67 - list_add(&netfs->link, &fscache_netfs_list); 68 - ret = 0; 69 52 70 53 pr_notice("Netfs '%s' registered for caching\n", netfs->name); 54 + trace_fscache_netfs(netfs); 55 + _leave(" = 0"); 56 + return 0; 71 57 72 58 already_registered: 73 - up_write(&fscache_addremove_sem); 74 - 75 - if (ret < 0) 76 - kmem_cache_free(fscache_cookie_jar, cookie); 77 - 78 - _leave(" = %d", ret); 79 - return ret; 59 + fscache_cookie_put(candidate, fscache_cookie_put_dup_netfs); 60 + _leave(" = -EEXIST"); 61 + return -EEXIST; 80 62 } 81 63 EXPORT_SYMBOL(__fscache_register_netfs); 82 64 ··· 70 88 { 71 89 _enter("{%s.%u}", netfs->name, netfs->version); 72 90 73 - down_write(&fscache_addremove_sem); 74 - 75 - list_del(&netfs->link); 76 - fscache_relinquish_cookie(netfs->primary_index, 0); 77 - 78 - up_write(&fscache_addremove_sem); 79 - 80 - pr_notice("Netfs '%s' unregistered from caching\n", 81 - netfs->name); 91 + fscache_relinquish_cookie(netfs->primary_index, NULL, false); 92 + pr_notice("Netfs '%s' unregistered from caching\n", netfs->name); 82 93 83 94 _leave(""); 84 95 }
+13 -15
fs/fscache/object-list.c
··· 36 36 #define FSCACHE_OBJLIST_CONFIG_NOEVENTS 0x00000800 /* show objects without no events */ 37 37 #define FSCACHE_OBJLIST_CONFIG_WORK 0x00001000 /* show objects with work */ 38 38 #define FSCACHE_OBJLIST_CONFIG_NOWORK 0x00002000 /* show objects without work */ 39 - 40 - u8 buf[512]; /* key and aux data buffer */ 41 39 }; 42 40 43 41 /* ··· 168 170 struct fscache_cookie *cookie; 169 171 unsigned long config = data->config; 170 172 char _type[3], *type; 171 - u8 *buf = data->buf, *p; 173 + u8 *p; 172 174 173 175 if ((unsigned long) v == 1) { 174 176 seq_puts(m, "OBJECT PARENT STAT CHLDN OPS OOP IPR EX READS" ··· 252 254 if (fscache_use_cookie(obj)) { 253 255 uint16_t keylen = 0, auxlen = 0; 254 256 255 - switch (cookie->def->type) { 257 + switch (cookie->type) { 256 258 case 0: 257 259 type = "IX"; 258 260 break; ··· 261 263 break; 262 264 default: 263 265 snprintf(_type, sizeof(_type), "%02u", 264 - cookie->def->type); 266 + cookie->type); 265 267 type = _type; 266 268 break; 267 269 } ··· 272 274 cookie->flags, 273 275 cookie->netfs_data); 274 276 275 - if (cookie->def->get_key && 276 - config & FSCACHE_OBJLIST_CONFIG_KEY) 277 - keylen = cookie->def->get_key(cookie->netfs_data, 278 - buf, 400); 277 + if (config & FSCACHE_OBJLIST_CONFIG_KEY) 278 + keylen = cookie->key_len; 279 279 280 - if (cookie->def->get_aux && 281 - config & FSCACHE_OBJLIST_CONFIG_AUX) 282 - auxlen = cookie->def->get_aux(cookie->netfs_data, 283 - buf + keylen, 512 - keylen); 284 - fscache_unuse_cookie(obj); 280 + if (config & FSCACHE_OBJLIST_CONFIG_AUX) 281 + auxlen = cookie->aux_len; 285 282 286 283 if (keylen > 0 || auxlen > 0) { 287 284 seq_puts(m, " "); 288 - for (p = buf; keylen > 0; keylen--) 285 + p = keylen <= sizeof(cookie->inline_key) ? 286 + cookie->inline_key : cookie->key; 287 + for (; keylen > 0; keylen--) 289 288 seq_printf(m, "%02x", *p++); 290 289 if (auxlen > 0) { 291 290 if (config & FSCACHE_OBJLIST_CONFIG_KEY) 292 291 seq_puts(m, ", "); 292 + p = auxlen <= sizeof(cookie->inline_aux) ? 293 + cookie->inline_aux : cookie->aux; 293 294 for (; auxlen > 0; auxlen--) 294 295 seq_printf(m, "%02x", *p++); 295 296 } 296 297 } 297 298 298 299 seq_puts(m, "\n"); 300 + fscache_unuse_cookie(obj); 299 301 } else { 300 302 seq_puts(m, "<no_netfs>\n"); 301 303 }
+46 -20
fs/fscache/object.c
··· 138 138 { 0, NULL } 139 139 }; 140 140 141 - static int fscache_get_object(struct fscache_object *); 142 - static void fscache_put_object(struct fscache_object *); 141 + static int fscache_get_object(struct fscache_object *, 142 + enum fscache_obj_ref_trace); 143 + static void fscache_put_object(struct fscache_object *, 144 + enum fscache_obj_ref_trace); 143 145 static bool fscache_enqueue_dependents(struct fscache_object *, int); 144 146 static void fscache_dequeue_object(struct fscache_object *); 147 + static void fscache_update_aux_data(struct fscache_object *); 145 148 146 149 /* 147 150 * we need to notify the parent when an op completes that we had outstanding ··· 173 170 const struct fscache_transition *t; 174 171 const struct fscache_state *state, *new_state; 175 172 unsigned long events, event_mask; 173 + bool oob; 176 174 int event = -1; 177 175 178 176 ASSERT(object != NULL); ··· 192 188 if (events & object->oob_event_mask) { 193 189 _debug("{OBJ%x} oob %lx", 194 190 object->debug_id, events & object->oob_event_mask); 191 + oob = true; 195 192 for (t = object->oob_table; t->events; t++) { 196 193 if (events & t->events) { 197 194 state = t->transit_to; ··· 204 199 } 205 200 } 206 201 } 202 + oob = false; 207 203 208 204 /* Wait states are just transition tables */ 209 205 if (!state->work) { ··· 213 207 if (events & t->events) { 214 208 new_state = t->transit_to; 215 209 event = fls(events & t->events) - 1; 210 + trace_fscache_osm(object, state, 211 + true, false, event); 216 212 clear_bit(event, &object->events); 217 213 _debug("{OBJ%x} ev %d: %s -> %s", 218 214 object->debug_id, event, ··· 234 226 execute_work_state: 235 227 _debug("{OBJ%x} exec %s", object->debug_id, state->name); 236 228 229 + trace_fscache_osm(object, state, false, oob, event); 237 230 new_state = state->work(object, event); 238 231 event = -1; 239 232 if (new_state == NO_TRANSIT) { ··· 288 279 start = jiffies; 289 280 fscache_object_sm_dispatcher(object); 290 281 fscache_hist(fscache_objs_histogram, start); 291 - fscache_put_object(object); 282 + fscache_put_object(object, fscache_obj_put_work); 292 283 } 293 284 294 285 /** ··· 406 397 fscache_stat(&fscache_n_cop_grab_object); 407 398 success = false; 408 399 if (fscache_object_is_live(parent) && 409 - object->cache->ops->grab_object(object)) { 400 + object->cache->ops->grab_object(object, fscache_obj_get_add_to_deps)) { 410 401 list_add(&object->dep_link, &parent->dependents); 411 402 success = true; 412 403 } ··· 712 703 ASSERT(cookie != NULL); 713 704 ASSERT(!hlist_unhashed(&object->cookie_link)); 714 705 706 + if (test_bit(FSCACHE_COOKIE_AUX_UPDATED, &cookie->flags)) { 707 + _debug("final update"); 708 + fscache_update_aux_data(object); 709 + } 710 + 715 711 /* Make sure the cookie no longer points here and that the netfs isn't 716 712 * waiting for us. 717 713 */ ··· 759 745 } 760 746 761 747 /* this just shifts the object release to the work processor */ 762 - fscache_put_object(object); 748 + fscache_put_object(object, fscache_obj_put_drop_obj); 763 749 fscache_stat(&fscache_n_object_dead); 764 750 765 751 _leave(""); ··· 769 755 /* 770 756 * get a ref on an object 771 757 */ 772 - static int fscache_get_object(struct fscache_object *object) 758 + static int fscache_get_object(struct fscache_object *object, 759 + enum fscache_obj_ref_trace why) 773 760 { 774 761 int ret; 775 762 776 763 fscache_stat(&fscache_n_cop_grab_object); 777 - ret = object->cache->ops->grab_object(object) ? 0 : -EAGAIN; 764 + ret = object->cache->ops->grab_object(object, why) ? 0 : -EAGAIN; 778 765 fscache_stat_d(&fscache_n_cop_grab_object); 779 766 return ret; 780 767 } ··· 783 768 /* 784 769 * Discard a ref on an object 785 770 */ 786 - static void fscache_put_object(struct fscache_object *object) 771 + static void fscache_put_object(struct fscache_object *object, 772 + enum fscache_obj_ref_trace why) 787 773 { 788 774 fscache_stat(&fscache_n_cop_put_object); 789 - object->cache->ops->put_object(object); 775 + object->cache->ops->put_object(object, why); 790 776 fscache_stat_d(&fscache_n_cop_put_object); 791 777 } 792 778 ··· 802 786 fscache_objlist_remove(object); 803 787 804 788 /* We can get rid of the cookie now */ 805 - fscache_cookie_put(object->cookie); 789 + fscache_cookie_put(object->cookie, fscache_cookie_put_object); 806 790 object->cookie = NULL; 807 791 } 808 792 EXPORT_SYMBOL(fscache_object_destroy); ··· 814 798 { 815 799 _enter("{OBJ%x}", object->debug_id); 816 800 817 - if (fscache_get_object(object) >= 0) { 801 + if (fscache_get_object(object, fscache_obj_get_queue) >= 0) { 818 802 wait_queue_head_t *cong_wq = 819 803 &get_cpu_var(fscache_object_cong_wait); 820 804 ··· 822 806 if (fscache_object_congested()) 823 807 wake_up(cong_wq); 824 808 } else 825 - fscache_put_object(object); 809 + fscache_put_object(object, fscache_obj_put_queue); 826 810 827 811 put_cpu_var(fscache_object_cong_wait); 828 812 } ··· 882 866 list_del_init(&dep->dep_link); 883 867 884 868 fscache_raise_event(dep, event); 885 - fscache_put_object(dep); 869 + fscache_put_object(dep, fscache_obj_put_enq_dep); 886 870 887 871 if (!list_empty(&object->dependents) && need_resched()) { 888 872 ret = false; ··· 922 906 * and creation). 923 907 */ 924 908 enum fscache_checkaux fscache_check_aux(struct fscache_object *object, 925 - const void *data, uint16_t datalen) 909 + const void *data, uint16_t datalen, 910 + loff_t object_size) 926 911 { 927 912 enum fscache_checkaux result; 928 913 ··· 933 916 } 934 917 935 918 result = object->cookie->def->check_aux(object->cookie->netfs_data, 936 - data, datalen); 919 + data, datalen, object_size); 937 920 switch (result) { 938 921 /* entry okay as is */ 939 922 case FSCACHE_CHECKAUX_OKAY: ··· 989 972 if (!op) 990 973 goto nomem; 991 974 992 - fscache_operation_init(op, object->cache->ops->invalidate_object, 975 + fscache_operation_init(cookie, op, object->cache->ops->invalidate_object, 993 976 NULL, NULL); 994 977 op->flags = FSCACHE_OP_ASYNC | 995 978 (1 << FSCACHE_OP_EXCLUSIVE) | 996 979 (1 << FSCACHE_OP_UNUSE_COOKIE); 980 + trace_fscache_page_op(cookie, NULL, op, fscache_page_op_invalidate); 997 981 998 982 spin_lock(&cookie->lock); 999 983 if (fscache_submit_exclusive_op(object, op) < 0) ··· 1044 1026 } 1045 1027 1046 1028 /* 1029 + * Update auxiliary data. 1030 + */ 1031 + static void fscache_update_aux_data(struct fscache_object *object) 1032 + { 1033 + fscache_stat(&fscache_n_updates_run); 1034 + fscache_stat(&fscache_n_cop_update_object); 1035 + object->cache->ops->update_object(object); 1036 + fscache_stat_d(&fscache_n_cop_update_object); 1037 + } 1038 + 1039 + /* 1047 1040 * Asynchronously update an object. 1048 1041 */ 1049 1042 static const struct fscache_state *fscache_update_object(struct fscache_object *object, ··· 1062 1033 { 1063 1034 _enter("{OBJ%x},%d", object->debug_id, event); 1064 1035 1065 - fscache_stat(&fscache_n_updates_run); 1066 - fscache_stat(&fscache_n_cop_update_object); 1067 - object->cache->ops->update_object(object); 1068 - fscache_stat_d(&fscache_n_cop_update_object); 1036 + fscache_update_aux_data(object); 1069 1037 1070 1038 _leave(""); 1071 1039 return transit_to(WAIT_FOR_CMD);
+25 -1
fs/fscache/operation.c
··· 32 32 * Do basic initialisation of an operation. The caller must still set flags, 33 33 * object and processor if needed. 34 34 */ 35 - void fscache_operation_init(struct fscache_operation *op, 35 + void fscache_operation_init(struct fscache_cookie *cookie, 36 + struct fscache_operation *op, 36 37 fscache_operation_processor_t processor, 37 38 fscache_operation_cancel_t cancel, 38 39 fscache_operation_release_t release) ··· 47 46 op->release = release; 48 47 INIT_LIST_HEAD(&op->pend_link); 49 48 fscache_stat(&fscache_n_op_initialised); 49 + trace_fscache_op(cookie, op, fscache_op_init); 50 50 } 51 51 EXPORT_SYMBOL(fscache_operation_init); 52 52 ··· 61 59 */ 62 60 void fscache_enqueue_operation(struct fscache_operation *op) 63 61 { 62 + struct fscache_cookie *cookie = op->object->cookie; 63 + 64 64 _enter("{OBJ%x OP%x,%u}", 65 65 op->object->debug_id, op->debug_id, atomic_read(&op->usage)); 66 66 ··· 75 71 fscache_stat(&fscache_n_op_enqueue); 76 72 switch (op->flags & FSCACHE_OP_TYPE) { 77 73 case FSCACHE_OP_ASYNC: 74 + trace_fscache_op(cookie, op, fscache_op_enqueue_async); 78 75 _debug("queue async"); 79 76 atomic_inc(&op->usage); 80 77 if (!queue_work(fscache_op_wq, &op->work)) 81 78 fscache_put_operation(op); 82 79 break; 83 80 case FSCACHE_OP_MYTHREAD: 81 + trace_fscache_op(cookie, op, fscache_op_enqueue_mythread); 84 82 _debug("queue for caller's attention"); 85 83 break; 86 84 default: ··· 107 101 wake_up_bit(&op->flags, FSCACHE_OP_WAITING); 108 102 if (op->processor) 109 103 fscache_enqueue_operation(op); 104 + else 105 + trace_fscache_op(object->cookie, op, fscache_op_run); 110 106 fscache_stat(&fscache_n_op_run); 111 107 } 112 108 ··· 162 154 int ret; 163 155 164 156 _enter("{OBJ%x OP%x},", object->debug_id, op->debug_id); 157 + 158 + trace_fscache_op(object->cookie, op, fscache_op_submit_ex); 165 159 166 160 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_INITIALISED); 167 161 ASSERTCMP(atomic_read(&op->usage), >, 0); ··· 249 239 250 240 _enter("{OBJ%x OP%x},{%u}", 251 241 object->debug_id, op->debug_id, atomic_read(&op->usage)); 242 + 243 + trace_fscache_op(object->cookie, op, fscache_op_submit); 252 244 253 245 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_INITIALISED); 254 246 ASSERTCMP(atomic_read(&op->usage), >, 0); ··· 369 357 370 358 _enter("OBJ%x OP%x}", op->object->debug_id, op->debug_id); 371 359 360 + trace_fscache_op(object->cookie, op, fscache_op_cancel); 361 + 372 362 ASSERTCMP(op->state, >=, FSCACHE_OP_ST_PENDING); 373 363 ASSERTCMP(op->state, !=, FSCACHE_OP_ST_CANCELLED); 374 364 ASSERTCMP(atomic_read(&op->usage), >, 0); ··· 433 419 fscache_stat(&fscache_n_op_cancelled); 434 420 list_del_init(&op->pend_link); 435 421 422 + trace_fscache_op(object->cookie, op, fscache_op_cancel_all); 423 + 436 424 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_PENDING); 437 425 op->cancel(op); 438 426 op->state = FSCACHE_OP_ST_CANCELLED; ··· 470 454 spin_lock(&object->lock); 471 455 472 456 if (!cancelled) { 457 + trace_fscache_op(object->cookie, op, fscache_op_completed); 473 458 op->state = FSCACHE_OP_ST_COMPLETE; 474 459 } else { 475 460 op->cancel(op); 461 + trace_fscache_op(object->cookie, op, fscache_op_cancelled); 476 462 op->state = FSCACHE_OP_ST_CANCELLED; 477 463 } 478 464 ··· 505 487 506 488 if (!atomic_dec_and_test(&op->usage)) 507 489 return; 490 + 491 + trace_fscache_op(op->object ? op->object->cookie : NULL, op, fscache_op_put); 508 492 509 493 _debug("PUT OP"); 510 494 ASSERTIFCMP(op->state != FSCACHE_OP_ST_INITIALISED && ··· 583 563 spin_unlock(&cache->op_gc_list_lock); 584 564 585 565 object = op->object; 566 + trace_fscache_op(object->cookie, op, fscache_op_gc); 567 + 586 568 spin_lock(&object->lock); 587 569 588 570 _debug("GC DEFERRED REL OBJ%x OP%x", ··· 622 600 623 601 _enter("{OBJ%x OP%x,%d}", 624 602 op->object->debug_id, op->debug_id, atomic_read(&op->usage)); 603 + 604 + trace_fscache_op(op->object->cookie, op, fscache_op_work); 625 605 626 606 ASSERT(op->processor != NULL); 627 607 start = jiffies;
+70 -14
fs/fscache/page.c
··· 27 27 rcu_read_lock(); 28 28 val = radix_tree_lookup(&cookie->stores, page->index); 29 29 rcu_read_unlock(); 30 + trace_fscache_check_page(cookie, page, val, 0); 30 31 31 32 return val != NULL; 32 33 } ··· 39 38 void __fscache_wait_on_page_write(struct fscache_cookie *cookie, struct page *page) 40 39 { 41 40 wait_queue_head_t *wq = bit_waitqueue(&cookie->flags, 0); 41 + 42 + trace_fscache_page(cookie, page, fscache_page_write_wait); 42 43 43 44 wait_event(*wq, !__fscache_check_page_write(cookie, page)); 44 45 } ··· 71 68 void *val; 72 69 73 70 _enter("%p,%p,%x", cookie, page, gfp); 71 + 72 + trace_fscache_page(cookie, page, fscache_page_maybe_release); 74 73 75 74 try_again: 76 75 rcu_read_lock(); ··· 106 101 } 107 102 108 103 xpage = radix_tree_delete(&cookie->stores, page->index); 104 + trace_fscache_page(cookie, page, fscache_page_radix_delete); 109 105 spin_unlock(&cookie->stores_lock); 110 106 111 107 if (xpage) { ··· 118 112 } 119 113 120 114 wake_up_bit(&cookie->flags, 0); 115 + trace_fscache_wake_cookie(cookie); 121 116 if (xpage) 122 117 put_page(xpage); 123 118 __fscache_uncache_page(cookie, page); ··· 151 144 struct page *page) 152 145 { 153 146 struct fscache_cookie *cookie; 154 - struct page *xpage = NULL; 147 + struct page *xpage = NULL, *val; 155 148 156 149 spin_lock(&object->lock); 157 150 cookie = object->cookie; ··· 161 154 spin_lock(&cookie->stores_lock); 162 155 radix_tree_tag_clear(&cookie->stores, page->index, 163 156 FSCACHE_COOKIE_STORING_TAG); 157 + trace_fscache_page(cookie, page, fscache_page_radix_clear_store); 164 158 if (!radix_tree_tag_get(&cookie->stores, page->index, 165 159 FSCACHE_COOKIE_PENDING_TAG)) { 166 160 fscache_stat(&fscache_n_store_radix_deletes); 167 161 xpage = radix_tree_delete(&cookie->stores, page->index); 162 + trace_fscache_page(cookie, page, fscache_page_radix_delete); 163 + trace_fscache_page(cookie, page, fscache_page_write_end); 164 + 165 + val = radix_tree_lookup(&cookie->stores, page->index); 166 + trace_fscache_check_page(cookie, page, val, 1); 167 + } else { 168 + trace_fscache_page(cookie, page, fscache_page_write_end_pend); 168 169 } 169 170 spin_unlock(&cookie->stores_lock); 170 171 wake_up_bit(&cookie->flags, 0); 172 + trace_fscache_wake_cookie(cookie); 173 + } else { 174 + trace_fscache_page(cookie, page, fscache_page_write_end_noc); 171 175 } 172 176 spin_unlock(&object->lock); 173 177 if (xpage) ··· 203 185 fscache_stat_d(&fscache_n_cop_attr_changed); 204 186 if (ret < 0) 205 187 fscache_abort_object(object); 188 + fscache_op_complete(op, ret < 0); 189 + } else { 190 + fscache_op_complete(op, true); 206 191 } 207 192 208 - fscache_op_complete(op, true); 209 193 _leave(""); 210 194 } 211 195 ··· 233 213 return -ENOMEM; 234 214 } 235 215 236 - fscache_operation_init(op, fscache_attr_changed_op, NULL, NULL); 216 + fscache_operation_init(cookie, op, fscache_attr_changed_op, NULL, NULL); 217 + trace_fscache_page_op(cookie, NULL, op, fscache_page_op_attr_changed); 237 218 op->flags = FSCACHE_OP_ASYNC | 238 219 (1 << FSCACHE_OP_EXCLUSIVE) | 239 220 (1 << FSCACHE_OP_UNUSE_COOKIE); ··· 318 297 return NULL; 319 298 } 320 299 321 - fscache_operation_init(&op->op, NULL, 300 + fscache_operation_init(cookie, &op->op, NULL, 322 301 fscache_do_cancel_retrieval, 323 302 fscache_release_retrieval_op); 324 303 op->op.flags = FSCACHE_OP_MYTHREAD | ··· 389 368 fscache_stat(stat_op_waits); 390 369 if (wait_on_bit(&op->flags, FSCACHE_OP_WAITING, 391 370 TASK_INTERRUPTIBLE) != 0) { 371 + trace_fscache_op(object->cookie, op, fscache_op_signal); 392 372 ret = fscache_cancel_op(op, false); 393 373 if (ret == 0) 394 374 return -ERESTARTSYS; ··· 411 389 if (unlikely(fscache_object_is_dying(object) || 412 390 fscache_cache_is_broken(object))) { 413 391 enum fscache_operation_state state = op->state; 392 + trace_fscache_op(object->cookie, op, fscache_op_signal); 414 393 fscache_cancel_op(op, true); 415 394 if (stat_object_dead) 416 395 fscache_stat(stat_object_dead); ··· 466 443 return -ENOMEM; 467 444 } 468 445 atomic_set(&op->n_pages, 1); 446 + trace_fscache_page_op(cookie, page, &op->op, fscache_page_op_retr_one); 469 447 470 448 spin_lock(&cookie->lock); 471 449 ··· 595 571 if (!op) 596 572 return -ENOMEM; 597 573 atomic_set(&op->n_pages, *nr_pages); 574 + trace_fscache_page_op(cookie, NULL, &op->op, fscache_page_op_retr_multi); 598 575 599 576 spin_lock(&cookie->lock); 600 577 ··· 707 682 if (!op) 708 683 return -ENOMEM; 709 684 atomic_set(&op->n_pages, 1); 685 + trace_fscache_page_op(cookie, page, &op->op, fscache_page_op_alloc_one); 710 686 711 687 spin_lock(&cookie->lock); 712 688 ··· 802 776 803 777 _enter("{OP%x,%d}", op->op.debug_id, atomic_read(&op->op.usage)); 804 778 779 + again: 805 780 spin_lock(&object->lock); 806 781 cookie = object->cookie; 807 782 808 783 if (!fscache_object_is_active(object)) { 809 - /* If we get here, then the on-disk cache object likely longer 810 - * exists, so we should just cancel this write operation. 784 + /* If we get here, then the on-disk cache object likely no 785 + * longer exists, so we should just cancel this write 786 + * operation. 811 787 */ 812 788 spin_unlock(&object->lock); 813 - fscache_op_complete(&op->op, false); 789 + fscache_op_complete(&op->op, true); 814 790 _leave(" [inactive]"); 815 791 return; 816 792 } ··· 825 797 * cancel this write operation. 826 798 */ 827 799 spin_unlock(&object->lock); 828 - fscache_op_complete(&op->op, false); 800 + fscache_op_complete(&op->op, true); 829 801 _leave(" [cancel] op{f=%lx s=%u} obj{s=%s f=%lx}", 830 802 _op->flags, _op->state, object->state->short_name, 831 803 object->flags); ··· 837 809 fscache_stat(&fscache_n_store_calls); 838 810 839 811 /* find a page to store */ 812 + results[0] = NULL; 840 813 page = NULL; 841 814 n = radix_tree_gang_lookup_tag(&cookie->stores, results, 0, 1, 842 815 FSCACHE_COOKIE_PENDING_TAG); 816 + trace_fscache_gang_lookup(cookie, &op->op, results, n, op->store_limit); 843 817 if (n != 1) 844 818 goto superseded; 845 819 page = results[0]; 846 820 _debug("gang %d [%lx]", n, page->index); 847 - if (page->index >= op->store_limit) { 848 - fscache_stat(&fscache_n_store_pages_over_limit); 849 - goto superseded; 850 - } 851 821 852 822 radix_tree_tag_set(&cookie->stores, page->index, 853 823 FSCACHE_COOKIE_STORING_TAG); 854 824 radix_tree_tag_clear(&cookie->stores, page->index, 855 825 FSCACHE_COOKIE_PENDING_TAG); 826 + trace_fscache_page(cookie, page, fscache_page_radix_pend2store); 856 827 857 828 spin_unlock(&cookie->stores_lock); 858 829 spin_unlock(&object->lock); 830 + 831 + if (page->index >= op->store_limit) 832 + goto discard_page; 859 833 860 834 fscache_stat(&fscache_n_store_pages); 861 835 fscache_stat(&fscache_n_cop_write_page); 862 836 ret = object->cache->ops->write_page(op, page); 863 837 fscache_stat_d(&fscache_n_cop_write_page); 838 + trace_fscache_wrote_page(cookie, page, &op->op, ret); 864 839 fscache_end_page_write(object, page); 865 840 if (ret < 0) { 866 841 fscache_abort_object(object); ··· 875 844 _leave(""); 876 845 return; 877 846 847 + discard_page: 848 + fscache_stat(&fscache_n_store_pages_over_limit); 849 + trace_fscache_wrote_page(cookie, page, &op->op, -ENOBUFS); 850 + fscache_end_page_write(object, page); 851 + goto again; 852 + 878 853 superseded: 879 854 /* this writer is going away and there aren't any more things to 880 855 * write */ ··· 888 851 spin_unlock(&cookie->stores_lock); 889 852 clear_bit(FSCACHE_OBJECT_PENDING_WRITE, &object->flags); 890 853 spin_unlock(&object->lock); 891 - fscache_op_complete(&op->op, true); 854 + fscache_op_complete(&op->op, false); 892 855 _leave(""); 893 856 } 894 857 ··· 916 879 for (i = n - 1; i >= 0; i--) { 917 880 page = results[i]; 918 881 radix_tree_delete(&cookie->stores, page->index); 882 + trace_fscache_page(cookie, page, fscache_page_radix_delete); 883 + trace_fscache_page(cookie, page, fscache_page_inval); 919 884 } 920 885 921 886 spin_unlock(&cookie->stores_lock); ··· 927 888 } 928 889 929 890 wake_up_bit(&cookie->flags, 0); 891 + trace_fscache_wake_cookie(cookie); 930 892 931 893 _leave(""); 932 894 } ··· 963 923 */ 964 924 int __fscache_write_page(struct fscache_cookie *cookie, 965 925 struct page *page, 926 + loff_t object_size, 966 927 gfp_t gfp) 967 928 { 968 929 struct fscache_storage *op; ··· 987 946 if (!op) 988 947 goto nomem; 989 948 990 - fscache_operation_init(&op->op, fscache_write_op, NULL, 949 + fscache_operation_init(cookie, &op->op, fscache_write_op, NULL, 991 950 fscache_release_write_op); 992 951 op->op.flags = FSCACHE_OP_ASYNC | 993 952 (1 << FSCACHE_OP_WAITING) | ··· 996 955 ret = radix_tree_maybe_preload(gfp & ~__GFP_HIGHMEM); 997 956 if (ret < 0) 998 957 goto nomem_free; 958 + 959 + trace_fscache_page_op(cookie, page, &op->op, fscache_page_op_write_one); 999 960 1000 961 ret = -ENOBUFS; 1001 962 spin_lock(&cookie->lock); ··· 1010 967 if (test_bit(FSCACHE_IOERROR, &object->cache->flags)) 1011 968 goto nobufs; 1012 969 970 + trace_fscache_page(cookie, page, fscache_page_write); 971 + 1013 972 /* add the page to the pending-storage radix tree on the backing 1014 973 * object */ 1015 974 spin_lock(&object->lock); 975 + 976 + if (object->store_limit_l != object_size) 977 + fscache_set_store_limit(object, object_size); 978 + 1016 979 spin_lock(&cookie->stores_lock); 1017 980 1018 981 _debug("store limit %llx", (unsigned long long) object->store_limit); ··· 1031 982 goto nobufs_unlock_obj; 1032 983 } 1033 984 985 + trace_fscache_page(cookie, page, fscache_page_radix_insert); 1034 986 radix_tree_tag_set(&cookie->stores, page->index, 1035 987 FSCACHE_COOKIE_PENDING_TAG); 988 + trace_fscache_page(cookie, page, fscache_page_radix_set_pend); 1036 989 get_page(page); 1037 990 1038 991 /* we only want one writer at a time, but we do need to queue new ··· 1077 1026 submit_failed: 1078 1027 spin_lock(&cookie->stores_lock); 1079 1028 radix_tree_delete(&cookie->stores, page->index); 1029 + trace_fscache_page(cookie, page, fscache_page_radix_delete); 1080 1030 spin_unlock(&cookie->stores_lock); 1081 1031 wake_cookie = __fscache_unuse_cookie(cookie); 1082 1032 put_page(page); ··· 1123 1071 /* cache withdrawal may beat us to it */ 1124 1072 if (!PageFsCache(page)) 1125 1073 goto done; 1074 + 1075 + trace_fscache_page(cookie, page, fscache_page_uncache); 1126 1076 1127 1077 /* get the object */ 1128 1078 spin_lock(&cookie->lock); ··· 1173 1119 #ifdef CONFIG_FSCACHE_STATS 1174 1120 atomic_inc(&fscache_n_marks); 1175 1121 #endif 1122 + 1123 + trace_fscache_page(cookie, page, fscache_page_cached); 1176 1124 1177 1125 _debug("- mark %p{%lx}", page, page->index); 1178 1126 if (TestSetPageFsCache(page)) {
-1
fs/fscache/stats.c
··· 21 21 atomic_t fscache_n_op_pend; 22 22 atomic_t fscache_n_op_run; 23 23 atomic_t fscache_n_op_enqueue; 24 - atomic_t fscache_n_op_requeue; 25 24 atomic_t fscache_n_op_deferred_release; 26 25 atomic_t fscache_n_op_initialised; 27 26 atomic_t fscache_n_op_release;
+2 -157
fs/nfs/fscache-index.c
··· 50 50 } 51 51 52 52 /* 53 - * Layout of the key for an NFS server cache object. 54 - */ 55 - struct nfs_server_key { 56 - uint16_t nfsversion; /* NFS protocol version */ 57 - uint16_t family; /* address family */ 58 - uint16_t port; /* IP port */ 59 - union { 60 - struct in_addr ipv4_addr; /* IPv4 address */ 61 - struct in6_addr ipv6_addr; /* IPv6 address */ 62 - } addr[0]; 63 - }; 64 - 65 - /* 66 - * Generate a key to describe a server in the main NFS index 67 - * - We return the length of the key, or 0 if we can't generate one 68 - */ 69 - static uint16_t nfs_server_get_key(const void *cookie_netfs_data, 70 - void *buffer, uint16_t bufmax) 71 - { 72 - const struct nfs_client *clp = cookie_netfs_data; 73 - const struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *) &clp->cl_addr; 74 - const struct sockaddr_in *sin = (struct sockaddr_in *) &clp->cl_addr; 75 - struct nfs_server_key *key = buffer; 76 - uint16_t len = sizeof(struct nfs_server_key); 77 - 78 - memset(key, 0, len); 79 - key->nfsversion = clp->rpc_ops->version; 80 - key->family = clp->cl_addr.ss_family; 81 - 82 - switch (clp->cl_addr.ss_family) { 83 - case AF_INET: 84 - key->port = sin->sin_port; 85 - key->addr[0].ipv4_addr = sin->sin_addr; 86 - len += sizeof(key->addr[0].ipv4_addr); 87 - break; 88 - 89 - case AF_INET6: 90 - key->port = sin6->sin6_port; 91 - key->addr[0].ipv6_addr = sin6->sin6_addr; 92 - len += sizeof(key->addr[0].ipv6_addr); 93 - break; 94 - 95 - default: 96 - printk(KERN_WARNING "NFS: Unknown network family '%d'\n", 97 - clp->cl_addr.ss_family); 98 - len = 0; 99 - break; 100 - } 101 - 102 - return len; 103 - } 104 - 105 - /* 106 53 * Define the server object for FS-Cache. This is used to describe a server 107 54 * object to fscache_acquire_cookie(). It is keyed by the NFS protocol and 108 55 * server address parameters. ··· 57 110 const struct fscache_cookie_def nfs_fscache_server_index_def = { 58 111 .name = "NFS.server", 59 112 .type = FSCACHE_COOKIE_TYPE_INDEX, 60 - .get_key = nfs_server_get_key, 61 113 }; 62 - 63 - /* 64 - * Generate a key to describe a superblock key in the main NFS index 65 - */ 66 - static uint16_t nfs_super_get_key(const void *cookie_netfs_data, 67 - void *buffer, uint16_t bufmax) 68 - { 69 - const struct nfs_fscache_key *key; 70 - const struct nfs_server *nfss = cookie_netfs_data; 71 - uint16_t len; 72 - 73 - key = nfss->fscache_key; 74 - len = sizeof(key->key) + key->key.uniq_len; 75 - if (len > bufmax) { 76 - len = 0; 77 - } else { 78 - memcpy(buffer, &key->key, sizeof(key->key)); 79 - memcpy(buffer + sizeof(key->key), 80 - key->key.uniquifier, key->key.uniq_len); 81 - } 82 - 83 - return len; 84 - } 85 114 86 115 /* 87 116 * Define the superblock object for FS-Cache. This is used to describe a ··· 67 144 const struct fscache_cookie_def nfs_fscache_super_index_def = { 68 145 .name = "NFS.super", 69 146 .type = FSCACHE_COOKIE_TYPE_INDEX, 70 - .get_key = nfs_super_get_key, 71 147 }; 72 - 73 - /* 74 - * Definition of the auxiliary data attached to NFS inode storage objects 75 - * within the cache. 76 - * 77 - * The contents of this struct are recorded in the on-disk local cache in the 78 - * auxiliary data attached to the data storage object backing an inode. This 79 - * permits coherency to be managed when a new inode binds to an already extant 80 - * cache object. 81 - */ 82 - struct nfs_fscache_inode_auxdata { 83 - struct timespec mtime; 84 - struct timespec ctime; 85 - loff_t size; 86 - u64 change_attr; 87 - }; 88 - 89 - /* 90 - * Generate a key to describe an NFS inode in an NFS server's index 91 - */ 92 - static uint16_t nfs_fscache_inode_get_key(const void *cookie_netfs_data, 93 - void *buffer, uint16_t bufmax) 94 - { 95 - const struct nfs_inode *nfsi = cookie_netfs_data; 96 - uint16_t nsize; 97 - 98 - /* use the inode's NFS filehandle as the key */ 99 - nsize = nfsi->fh.size; 100 - memcpy(buffer, nfsi->fh.data, nsize); 101 - return nsize; 102 - } 103 - 104 - /* 105 - * Get certain file attributes from the netfs data 106 - * - This function can be absent for an index 107 - * - Not permitted to return an error 108 - * - The netfs data from the cookie being used as the source is presented 109 - */ 110 - static void nfs_fscache_inode_get_attr(const void *cookie_netfs_data, 111 - uint64_t *size) 112 - { 113 - const struct nfs_inode *nfsi = cookie_netfs_data; 114 - 115 - *size = nfsi->vfs_inode.i_size; 116 - } 117 - 118 - /* 119 - * Get the auxiliary data from netfs data 120 - * - This function can be absent if the index carries no state data 121 - * - Should store the auxiliary data in the buffer 122 - * - Should return the amount of amount stored 123 - * - Not permitted to return an error 124 - * - The netfs data from the cookie being used as the source is presented 125 - */ 126 - static uint16_t nfs_fscache_inode_get_aux(const void *cookie_netfs_data, 127 - void *buffer, uint16_t bufmax) 128 - { 129 - struct nfs_fscache_inode_auxdata auxdata; 130 - const struct nfs_inode *nfsi = cookie_netfs_data; 131 - 132 - memset(&auxdata, 0, sizeof(auxdata)); 133 - auxdata.size = nfsi->vfs_inode.i_size; 134 - auxdata.mtime = nfsi->vfs_inode.i_mtime; 135 - auxdata.ctime = nfsi->vfs_inode.i_ctime; 136 - 137 - if (NFS_SERVER(&nfsi->vfs_inode)->nfs_client->rpc_ops->version == 4) 138 - auxdata.change_attr = inode_peek_iversion_raw(&nfsi->vfs_inode); 139 - 140 - if (bufmax > sizeof(auxdata)) 141 - bufmax = sizeof(auxdata); 142 - 143 - memcpy(buffer, &auxdata, bufmax); 144 - return bufmax; 145 - } 146 148 147 149 /* 148 150 * Consult the netfs about the state of an object ··· 78 230 static 79 231 enum fscache_checkaux nfs_fscache_inode_check_aux(void *cookie_netfs_data, 80 232 const void *data, 81 - uint16_t datalen) 233 + uint16_t datalen, 234 + loff_t object_size) 82 235 { 83 236 struct nfs_fscache_inode_auxdata auxdata; 84 237 struct nfs_inode *nfsi = cookie_netfs_data; ··· 88 239 return FSCACHE_CHECKAUX_OBSOLETE; 89 240 90 241 memset(&auxdata, 0, sizeof(auxdata)); 91 - auxdata.size = nfsi->vfs_inode.i_size; 92 242 auxdata.mtime = nfsi->vfs_inode.i_mtime; 93 243 auxdata.ctime = nfsi->vfs_inode.i_ctime; 94 244 ··· 136 288 const struct fscache_cookie_def nfs_fscache_inode_object_def = { 137 289 .name = "NFS.fh", 138 290 .type = FSCACHE_COOKIE_TYPE_DATAFILE, 139 - .get_key = nfs_fscache_inode_get_key, 140 - .get_attr = nfs_fscache_inode_get_attr, 141 - .get_aux = nfs_fscache_inode_get_aux, 142 291 .check_aux = nfs_fscache_inode_check_aux, 143 292 .get_context = nfs_fh_get_context, 144 293 .put_context = nfs_fh_put_context,
+80 -9
fs/nfs/fscache.c
··· 18 18 #include <linux/in6.h> 19 19 #include <linux/seq_file.h> 20 20 #include <linux/slab.h> 21 + #include <linux/iversion.h> 21 22 22 23 #include "internal.h" 23 24 #include "iostat.h" ··· 30 29 static DEFINE_SPINLOCK(nfs_fscache_keys_lock); 31 30 32 31 /* 32 + * Layout of the key for an NFS server cache object. 33 + */ 34 + struct nfs_server_key { 35 + struct { 36 + uint16_t nfsversion; /* NFS protocol version */ 37 + uint16_t family; /* address family */ 38 + __be16 port; /* IP port */ 39 + } hdr; 40 + union { 41 + struct in_addr ipv4_addr; /* IPv4 address */ 42 + struct in6_addr ipv6_addr; /* IPv6 address */ 43 + }; 44 + } __packed; 45 + 46 + /* 33 47 * Get the per-client index cookie for an NFS client if the appropriate mount 34 48 * flag was set 35 49 * - We always try and get an index cookie for the client, but get filehandle ··· 52 36 */ 53 37 void nfs_fscache_get_client_cookie(struct nfs_client *clp) 54 38 { 39 + const struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *) &clp->cl_addr; 40 + const struct sockaddr_in *sin = (struct sockaddr_in *) &clp->cl_addr; 41 + struct nfs_server_key key; 42 + uint16_t len = sizeof(key.hdr); 43 + 44 + memset(&key, 0, sizeof(key)); 45 + key.hdr.nfsversion = clp->rpc_ops->version; 46 + key.hdr.family = clp->cl_addr.ss_family; 47 + 48 + switch (clp->cl_addr.ss_family) { 49 + case AF_INET: 50 + key.hdr.port = sin->sin_port; 51 + key.ipv4_addr = sin->sin_addr; 52 + len += sizeof(key.ipv4_addr); 53 + break; 54 + 55 + case AF_INET6: 56 + key.hdr.port = sin6->sin6_port; 57 + key.ipv6_addr = sin6->sin6_addr; 58 + len += sizeof(key.ipv6_addr); 59 + break; 60 + 61 + default: 62 + printk(KERN_WARNING "NFS: Unknown network family '%d'\n", 63 + clp->cl_addr.ss_family); 64 + clp->fscache = NULL; 65 + return; 66 + } 67 + 55 68 /* create a cache index for looking up filehandles */ 56 69 clp->fscache = fscache_acquire_cookie(nfs_fscache_netfs.primary_index, 57 70 &nfs_fscache_server_index_def, 58 - clp, true); 71 + &key, len, 72 + NULL, 0, 73 + clp, 0, true); 59 74 dfprintk(FSCACHE, "NFS: get client cookie (0x%p/0x%p)\n", 60 75 clp, clp->fscache); 61 76 } ··· 99 52 dfprintk(FSCACHE, "NFS: releasing client cookie (0x%p/0x%p)\n", 100 53 clp, clp->fscache); 101 54 102 - fscache_relinquish_cookie(clp->fscache, 0); 55 + fscache_relinquish_cookie(clp->fscache, NULL, false); 103 56 clp->fscache = NULL; 104 57 } 105 58 ··· 186 139 /* create a cache index for looking up filehandles */ 187 140 nfss->fscache = fscache_acquire_cookie(nfss->nfs_client->fscache, 188 141 &nfs_fscache_super_index_def, 189 - nfss, true); 142 + key, sizeof(*key) + ulen, 143 + NULL, 0, 144 + nfss, 0, true); 190 145 dfprintk(FSCACHE, "NFS: get superblock cookie (0x%p/0x%p)\n", 191 146 nfss, nfss->fscache); 192 147 return; ··· 212 163 dfprintk(FSCACHE, "NFS: releasing superblock cookie (0x%p/0x%p)\n", 213 164 nfss, nfss->fscache); 214 165 215 - fscache_relinquish_cookie(nfss->fscache, 0); 166 + fscache_relinquish_cookie(nfss->fscache, NULL, false); 216 167 nfss->fscache = NULL; 217 168 218 169 if (nfss->fscache_key) { ··· 229 180 */ 230 181 void nfs_fscache_init_inode(struct inode *inode) 231 182 { 183 + struct nfs_fscache_inode_auxdata auxdata; 232 184 struct nfs_inode *nfsi = NFS_I(inode); 233 185 234 186 nfsi->fscache = NULL; 235 187 if (!S_ISREG(inode->i_mode)) 236 188 return; 189 + 190 + memset(&auxdata, 0, sizeof(auxdata)); 191 + auxdata.mtime = nfsi->vfs_inode.i_mtime; 192 + auxdata.ctime = nfsi->vfs_inode.i_ctime; 193 + 194 + if (NFS_SERVER(&nfsi->vfs_inode)->nfs_client->rpc_ops->version == 4) 195 + auxdata.change_attr = inode_peek_iversion_raw(&nfsi->vfs_inode); 196 + 237 197 nfsi->fscache = fscache_acquire_cookie(NFS_SB(inode->i_sb)->fscache, 238 198 &nfs_fscache_inode_object_def, 239 - nfsi, false); 199 + nfsi->fh.data, nfsi->fh.size, 200 + &auxdata, sizeof(auxdata), 201 + nfsi, nfsi->vfs_inode.i_size, false); 240 202 } 241 203 242 204 /* ··· 255 195 */ 256 196 void nfs_fscache_clear_inode(struct inode *inode) 257 197 { 198 + struct nfs_fscache_inode_auxdata auxdata; 258 199 struct nfs_inode *nfsi = NFS_I(inode); 259 200 struct fscache_cookie *cookie = nfs_i_fscache(inode); 260 201 261 202 dfprintk(FSCACHE, "NFS: clear cookie (0x%p/0x%p)\n", nfsi, cookie); 262 203 263 - fscache_relinquish_cookie(cookie, false); 204 + memset(&auxdata, 0, sizeof(auxdata)); 205 + auxdata.mtime = nfsi->vfs_inode.i_mtime; 206 + auxdata.ctime = nfsi->vfs_inode.i_ctime; 207 + fscache_relinquish_cookie(cookie, &auxdata, false); 264 208 nfsi->fscache = NULL; 265 209 } 266 210 ··· 296 232 */ 297 233 void nfs_fscache_open_file(struct inode *inode, struct file *filp) 298 234 { 235 + struct nfs_fscache_inode_auxdata auxdata; 299 236 struct nfs_inode *nfsi = NFS_I(inode); 300 237 struct fscache_cookie *cookie = nfs_i_fscache(inode); 301 238 302 239 if (!fscache_cookie_valid(cookie)) 303 240 return; 304 241 242 + memset(&auxdata, 0, sizeof(auxdata)); 243 + auxdata.mtime = nfsi->vfs_inode.i_mtime; 244 + auxdata.ctime = nfsi->vfs_inode.i_ctime; 245 + 305 246 if (inode_is_open_for_write(inode)) { 306 247 dfprintk(FSCACHE, "NFS: nfsi 0x%p disabling cache\n", nfsi); 307 248 clear_bit(NFS_INO_FSCACHE, &nfsi->flags); 308 - fscache_disable_cookie(cookie, true); 249 + fscache_disable_cookie(cookie, &auxdata, true); 309 250 fscache_uncache_all_inode_pages(cookie, inode); 310 251 } else { 311 252 dfprintk(FSCACHE, "NFS: nfsi 0x%p enabling cache\n", nfsi); 312 - fscache_enable_cookie(cookie, nfs_fscache_can_enable, inode); 253 + fscache_enable_cookie(cookie, &auxdata, nfsi->vfs_inode.i_size, 254 + nfs_fscache_can_enable, inode); 313 255 if (fscache_cookie_enabled(cookie)) 314 256 set_bit(NFS_INO_FSCACHE, &NFS_I(inode)->flags); 315 257 } ··· 492 422 "NFS: readpage_to_fscache(fsc:%p/p:%p(i:%lx f:%lx)/%d)\n", 493 423 nfs_i_fscache(inode), page, page->index, page->flags, sync); 494 424 495 - ret = fscache_write_page(nfs_i_fscache(inode), page, GFP_KERNEL); 425 + ret = fscache_write_page(nfs_i_fscache(inode), page, 426 + inode->i_size, GFP_KERNEL); 496 427 dfprintk(FSCACHE, 497 428 "NFS: readpage_to_fscache: p:%p(i:%lu f:%lx) ret %d\n", 498 429 page, page->index, page->flags, ret);
+15
fs/nfs/fscache.h
··· 57 57 }; 58 58 59 59 /* 60 + * Definition of the auxiliary data attached to NFS inode storage objects 61 + * within the cache. 62 + * 63 + * The contents of this struct are recorded in the on-disk local cache in the 64 + * auxiliary data attached to the data storage object backing an inode. This 65 + * permits coherency to be managed when a new inode binds to an already extant 66 + * cache object. 67 + */ 68 + struct nfs_fscache_inode_auxdata { 69 + struct timespec mtime; 70 + struct timespec ctime; 71 + u64 change_attr; 72 + }; 73 + 74 + /* 60 75 * fscache-index.c 61 76 */ 62 77 extern struct fscache_netfs nfs_fscache_netfs;
+21 -5
include/linux/fscache-cache.h
··· 29 29 struct fscache_object; 30 30 struct fscache_operation; 31 31 32 + enum fscache_obj_ref_trace { 33 + fscache_obj_get_add_to_deps, 34 + fscache_obj_get_queue, 35 + fscache_obj_put_alloc_fail, 36 + fscache_obj_put_attach_fail, 37 + fscache_obj_put_drop_obj, 38 + fscache_obj_put_enq_dep, 39 + fscache_obj_put_queue, 40 + fscache_obj_put_work, 41 + fscache_obj_ref__nr_traces 42 + }; 43 + 32 44 /* 33 45 * cache tag definition 34 46 */ ··· 135 123 extern void fscache_enqueue_operation(struct fscache_operation *); 136 124 extern void fscache_op_complete(struct fscache_operation *, bool); 137 125 extern void fscache_put_operation(struct fscache_operation *); 138 - extern void fscache_operation_init(struct fscache_operation *, 126 + extern void fscache_operation_init(struct fscache_cookie *, 127 + struct fscache_operation *, 139 128 fscache_operation_processor_t, 140 129 fscache_operation_cancel_t, 141 130 fscache_operation_release_t); ··· 198 185 { 199 186 atomic_sub(n_pages, &op->n_pages); 200 187 if (atomic_read(&op->n_pages) <= 0) 201 - fscache_op_complete(&op->op, true); 188 + fscache_op_complete(&op->op, false); 202 189 } 203 190 204 191 /** ··· 244 231 void (*lookup_complete)(struct fscache_object *object); 245 232 246 233 /* increment the usage count on this object (may fail if unmounting) */ 247 - struct fscache_object *(*grab_object)(struct fscache_object *object); 234 + struct fscache_object *(*grab_object)(struct fscache_object *object, 235 + enum fscache_obj_ref_trace why); 248 236 249 237 /* pin an object in the cache */ 250 238 int (*pin_object)(struct fscache_object *object); ··· 268 254 void (*drop_object)(struct fscache_object *object); 269 255 270 256 /* dispose of a reference to an object */ 271 - void (*put_object)(struct fscache_object *object); 257 + void (*put_object)(struct fscache_object *object, 258 + enum fscache_obj_ref_trace why); 272 259 273 260 /* sync a cache */ 274 261 void (*sync_cache)(struct fscache_cache *cache); ··· 553 538 554 539 extern enum fscache_checkaux fscache_check_aux(struct fscache_object *object, 555 540 const void *data, 556 - uint16_t datalen); 541 + uint16_t datalen, 542 + loff_t object_size); 557 543 558 544 extern void fscache_object_retrying_stale(struct fscache_object *object); 559 545
+83 -59
include/linux/fscache.h
··· 22 22 #include <linux/list.h> 23 23 #include <linux/pagemap.h> 24 24 #include <linux/pagevec.h> 25 + #include <linux/list_bl.h> 25 26 26 27 #if defined(CONFIG_FSCACHE) || defined(CONFIG_FSCACHE_MODULE) 27 28 #define fscache_available() (1) ··· 84 83 const void *parent_netfs_data, 85 84 const void *cookie_netfs_data); 86 85 87 - /* get an index key 88 - * - should store the key data in the buffer 89 - * - should return the amount of data stored 90 - * - not permitted to return an error 91 - * - the netfs data from the cookie being used as the source is 92 - * presented 93 - */ 94 - uint16_t (*get_key)(const void *cookie_netfs_data, 95 - void *buffer, 96 - uint16_t bufmax); 97 - 98 - /* get certain file attributes from the netfs data 99 - * - this function can be absent for an index 100 - * - not permitted to return an error 101 - * - the netfs data from the cookie being used as the source is 102 - * presented 103 - */ 104 - void (*get_attr)(const void *cookie_netfs_data, uint64_t *size); 105 - 106 - /* get the auxiliary data from netfs data 107 - * - this function can be absent if the index carries no state data 108 - * - should store the auxiliary data in the buffer 109 - * - should return the amount of amount stored 110 - * - not permitted to return an error 111 - * - the netfs data from the cookie being used as the source is 112 - * presented 113 - */ 114 - uint16_t (*get_aux)(const void *cookie_netfs_data, 115 - void *buffer, 116 - uint16_t bufmax); 117 - 118 86 /* consult the netfs about the state of an object 119 87 * - this function can be absent if the index carries no state data 120 88 * - the netfs data from the cookie being used as the target is 121 - * presented, as is the auxiliary data 89 + * presented, as is the auxiliary data and the object size 122 90 */ 123 91 enum fscache_checkaux (*check_aux)(void *cookie_netfs_data, 124 92 const void *data, 125 - uint16_t datalen); 93 + uint16_t datalen, 94 + loff_t object_size); 126 95 127 96 /* get an extra reference on a read context 128 97 * - this function can be absent if the completion function doesn't ··· 125 154 uint32_t version; /* indexing version */ 126 155 const char *name; /* filesystem name */ 127 156 struct fscache_cookie *primary_index; 128 - struct list_head link; /* internal link */ 129 157 }; 130 158 131 159 /* ··· 143 173 struct hlist_head backing_objects; /* object(s) backing this file/index */ 144 174 const struct fscache_cookie_def *def; /* definition */ 145 175 struct fscache_cookie *parent; /* parent of this entry */ 176 + struct hlist_bl_node hash_link; /* Link in hash table */ 146 177 void *netfs_data; /* back pointer to netfs */ 147 178 struct radix_tree_root stores; /* pages to be stored on this cookie */ 148 179 #define FSCACHE_COOKIE_PENDING_TAG 0 /* pages tag: pending write to cache */ ··· 157 186 #define FSCACHE_COOKIE_RELINQUISHED 4 /* T if cookie has been relinquished */ 158 187 #define FSCACHE_COOKIE_ENABLED 5 /* T if cookie is enabled */ 159 188 #define FSCACHE_COOKIE_ENABLEMENT_LOCK 6 /* T if cookie is being en/disabled */ 189 + #define FSCACHE_COOKIE_AUX_UPDATED 8 /* T if the auxiliary data was updated */ 190 + #define FSCACHE_COOKIE_ACQUIRED 9 /* T if cookie is in use */ 191 + #define FSCACHE_COOKIE_RELINQUISHING 10 /* T if cookie is being relinquished */ 192 + 193 + u8 type; /* Type of object */ 194 + u8 key_len; /* Length of index key */ 195 + u8 aux_len; /* Length of auxiliary data */ 196 + u32 key_hash; /* Hash of parent, type, key, len */ 197 + union { 198 + void *key; /* Index key */ 199 + u8 inline_key[16]; /* - If the key is short enough */ 200 + }; 201 + union { 202 + void *aux; /* Auxiliary data */ 203 + u8 inline_aux[8]; /* - If the aux data is short enough */ 204 + }; 160 205 }; 161 206 162 207 static inline bool fscache_cookie_enabled(struct fscache_cookie *cookie) ··· 195 208 extern struct fscache_cookie *__fscache_acquire_cookie( 196 209 struct fscache_cookie *, 197 210 const struct fscache_cookie_def *, 198 - void *, bool); 199 - extern void __fscache_relinquish_cookie(struct fscache_cookie *, bool); 200 - extern int __fscache_check_consistency(struct fscache_cookie *); 201 - extern void __fscache_update_cookie(struct fscache_cookie *); 211 + const void *, size_t, 212 + const void *, size_t, 213 + void *, loff_t, bool); 214 + extern void __fscache_relinquish_cookie(struct fscache_cookie *, const void *, bool); 215 + extern int __fscache_check_consistency(struct fscache_cookie *, const void *); 216 + extern void __fscache_update_cookie(struct fscache_cookie *, const void *); 202 217 extern int __fscache_attr_changed(struct fscache_cookie *); 203 218 extern void __fscache_invalidate(struct fscache_cookie *); 204 219 extern void __fscache_wait_on_invalidate(struct fscache_cookie *); ··· 217 228 void *, 218 229 gfp_t); 219 230 extern int __fscache_alloc_page(struct fscache_cookie *, struct page *, gfp_t); 220 - extern int __fscache_write_page(struct fscache_cookie *, struct page *, gfp_t); 231 + extern int __fscache_write_page(struct fscache_cookie *, struct page *, loff_t, gfp_t); 221 232 extern void __fscache_uncache_page(struct fscache_cookie *, struct page *); 222 233 extern bool __fscache_check_page_write(struct fscache_cookie *, struct page *); 223 234 extern void __fscache_wait_on_page_write(struct fscache_cookie *, struct page *); ··· 227 238 struct inode *); 228 239 extern void __fscache_readpages_cancel(struct fscache_cookie *cookie, 229 240 struct list_head *pages); 230 - extern void __fscache_disable_cookie(struct fscache_cookie *, bool); 231 - extern void __fscache_enable_cookie(struct fscache_cookie *, 241 + extern void __fscache_disable_cookie(struct fscache_cookie *, const void *, bool); 242 + extern void __fscache_enable_cookie(struct fscache_cookie *, const void *, loff_t, 232 243 bool (*)(void *), void *); 233 244 234 245 /** ··· 306 317 * fscache_acquire_cookie - Acquire a cookie to represent a cache object 307 318 * @parent: The cookie that's to be the parent of this one 308 319 * @def: A description of the cache object, including callback operations 320 + * @index_key: The index key for this cookie 321 + * @index_key_len: Size of the index key 322 + * @aux_data: The auxiliary data for the cookie (may be NULL) 323 + * @aux_data_len: Size of the auxiliary data buffer 309 324 * @netfs_data: An arbitrary piece of data to be kept in the cookie to 310 325 * represent the cache object to the netfs 326 + * @object_size: The initial size of object 311 327 * @enable: Whether or not to enable a data cookie immediately 312 328 * 313 329 * This function is used to inform FS-Cache about part of an index hierarchy ··· 326 332 struct fscache_cookie *fscache_acquire_cookie( 327 333 struct fscache_cookie *parent, 328 334 const struct fscache_cookie_def *def, 335 + const void *index_key, 336 + size_t index_key_len, 337 + const void *aux_data, 338 + size_t aux_data_len, 329 339 void *netfs_data, 340 + loff_t object_size, 330 341 bool enable) 331 342 { 332 343 if (fscache_cookie_valid(parent) && fscache_cookie_enabled(parent)) 333 - return __fscache_acquire_cookie(parent, def, netfs_data, 334 - enable); 344 + return __fscache_acquire_cookie(parent, def, 345 + index_key, index_key_len, 346 + aux_data, aux_data_len, 347 + netfs_data, object_size, enable); 335 348 else 336 349 return NULL; 337 350 } ··· 347 346 * fscache_relinquish_cookie - Return the cookie to the cache, maybe discarding 348 347 * it 349 348 * @cookie: The cookie being returned 349 + * @aux_data: The updated auxiliary data for the cookie (may be NULL) 350 350 * @retire: True if the cache object the cookie represents is to be discarded 351 351 * 352 352 * This function returns a cookie to the cache, forcibly discarding the 353 - * associated cache object if retire is set to true. 353 + * associated cache object if retire is set to true. The opportunity is 354 + * provided to update the auxiliary data in the cache before the object is 355 + * disconnected. 354 356 * 355 357 * See Documentation/filesystems/caching/netfs-api.txt for a complete 356 358 * description. 357 359 */ 358 360 static inline 359 - void fscache_relinquish_cookie(struct fscache_cookie *cookie, bool retire) 361 + void fscache_relinquish_cookie(struct fscache_cookie *cookie, 362 + const void *aux_data, 363 + bool retire) 360 364 { 361 365 if (fscache_cookie_valid(cookie)) 362 - __fscache_relinquish_cookie(cookie, retire); 366 + __fscache_relinquish_cookie(cookie, aux_data, retire); 363 367 } 364 368 365 369 /** 366 - * fscache_check_consistency - Request that if the cache is updated 370 + * fscache_check_consistency - Request validation of a cache's auxiliary data 367 371 * @cookie: The cookie representing the cache object 372 + * @aux_data: The updated auxiliary data for the cookie (may be NULL) 368 373 * 369 - * Request an consistency check from fscache, which passes the request 370 - * to the backing cache. 374 + * Request an consistency check from fscache, which passes the request to the 375 + * backing cache. The auxiliary data on the cookie will be updated first if 376 + * @aux_data is set. 371 377 * 372 378 * Returns 0 if consistent and -ESTALE if inconsistent. May also 373 379 * return -ENOMEM and -ERESTARTSYS. 374 380 */ 375 381 static inline 376 - int fscache_check_consistency(struct fscache_cookie *cookie) 382 + int fscache_check_consistency(struct fscache_cookie *cookie, 383 + const void *aux_data) 377 384 { 378 385 if (fscache_cookie_valid(cookie) && fscache_cookie_enabled(cookie)) 379 - return __fscache_check_consistency(cookie); 386 + return __fscache_check_consistency(cookie, aux_data); 380 387 else 381 388 return 0; 382 389 } ··· 392 383 /** 393 384 * fscache_update_cookie - Request that a cache object be updated 394 385 * @cookie: The cookie representing the cache object 386 + * @aux_data: The updated auxiliary data for the cookie (may be NULL) 395 387 * 396 388 * Request an update of the index data for the cache object associated with the 397 - * cookie. 389 + * cookie. The auxiliary data on the cookie will be updated first if @aux_data 390 + * is set. 398 391 * 399 392 * See Documentation/filesystems/caching/netfs-api.txt for a complete 400 393 * description. 401 394 */ 402 395 static inline 403 - void fscache_update_cookie(struct fscache_cookie *cookie) 396 + void fscache_update_cookie(struct fscache_cookie *cookie, const void *aux_data) 404 397 { 405 398 if (fscache_cookie_valid(cookie) && fscache_cookie_enabled(cookie)) 406 - __fscache_update_cookie(cookie); 399 + __fscache_update_cookie(cookie, aux_data); 407 400 } 408 401 409 402 /** ··· 659 648 * fscache_write_page - Request storage of a page in the cache 660 649 * @cookie: The cookie representing the cache object 661 650 * @page: The netfs page to store 651 + * @object_size: Updated size of object 662 652 * @gfp: The conditions under which memory allocation should be made 663 653 * 664 654 * Request the contents of the netfs page be written into the cache. This ··· 677 665 static inline 678 666 int fscache_write_page(struct fscache_cookie *cookie, 679 667 struct page *page, 668 + loff_t object_size, 680 669 gfp_t gfp) 681 670 { 682 671 if (fscache_cookie_valid(cookie) && fscache_cookie_enabled(cookie)) 683 - return __fscache_write_page(cookie, page, gfp); 672 + return __fscache_write_page(cookie, page, object_size, gfp); 684 673 else 685 674 return -ENOBUFS; 686 675 } ··· 793 780 /** 794 781 * fscache_disable_cookie - Disable a cookie 795 782 * @cookie: The cookie representing the cache object 783 + * @aux_data: The updated auxiliary data for the cookie (may be NULL) 796 784 * @invalidate: Invalidate the backing object 797 785 * 798 786 * Disable a cookie from accepting further alloc, read, write, invalidate, ··· 804 790 * 805 791 * If @invalidate is set, then the backing object will be invalidated and 806 792 * detached, otherwise it will just be detached. 793 + * 794 + * If @aux_data is set, then auxiliary data will be updated from that. 807 795 */ 808 796 static inline 809 - void fscache_disable_cookie(struct fscache_cookie *cookie, bool invalidate) 797 + void fscache_disable_cookie(struct fscache_cookie *cookie, 798 + const void *aux_data, 799 + bool invalidate) 810 800 { 811 801 if (fscache_cookie_valid(cookie) && fscache_cookie_enabled(cookie)) 812 - __fscache_disable_cookie(cookie, invalidate); 802 + __fscache_disable_cookie(cookie, aux_data, invalidate); 813 803 } 814 804 815 805 /** 816 806 * fscache_enable_cookie - Reenable a cookie 817 807 * @cookie: The cookie representing the cache object 808 + * @aux_data: The updated auxiliary data for the cookie (may be NULL) 809 + * @object_size: Current size of object 818 810 * @can_enable: A function to permit enablement once lock is held 819 811 * @data: Data for can_enable() 820 812 * 821 813 * Reenable a previously disabled cookie, allowing it to accept further alloc, 822 814 * read, write, invalidate, update or acquire operations. An attempt will be 823 - * made to immediately reattach the cookie to a backing object. 815 + * made to immediately reattach the cookie to a backing object. If @aux_data 816 + * is set, the auxiliary data attached to the cookie will be updated. 824 817 * 825 818 * The can_enable() function is called (if not NULL) once the enablement lock 826 819 * is held to rule on whether enablement is still permitted to go ahead. 827 820 */ 828 821 static inline 829 822 void fscache_enable_cookie(struct fscache_cookie *cookie, 823 + const void *aux_data, 824 + loff_t object_size, 830 825 bool (*can_enable)(void *data), 831 826 void *data) 832 827 { 833 828 if (fscache_cookie_valid(cookie) && !fscache_cookie_enabled(cookie)) 834 - __fscache_enable_cookie(cookie, can_enable, data); 829 + __fscache_enable_cookie(cookie, aux_data, object_size, 830 + can_enable, data); 835 831 } 836 832 837 833 #endif /* _LINUX_FSCACHE_H */
+325
include/trace/events/cachefiles.h
··· 1 + /* CacheFiles tracepoints 2 + * 3 + * Copyright (C) 2016 Red Hat, Inc. All Rights Reserved. 4 + * Written by David Howells (dhowells@redhat.com) 5 + * 6 + * This program is free software; you can redistribute it and/or 7 + * modify it under the terms of the GNU General Public Licence 8 + * as published by the Free Software Foundation; either version 9 + * 2 of the Licence, or (at your option) any later version. 10 + */ 11 + #undef TRACE_SYSTEM 12 + #define TRACE_SYSTEM cachefiles 13 + 14 + #if !defined(_TRACE_CACHEFILES_H) || defined(TRACE_HEADER_MULTI_READ) 15 + #define _TRACE_CACHEFILES_H 16 + 17 + #include <linux/tracepoint.h> 18 + 19 + /* 20 + * Define enums for tracing information. 21 + */ 22 + #ifndef __CACHEFILES_DECLARE_TRACE_ENUMS_ONCE_ONLY 23 + #define __CACHEFILES_DECLARE_TRACE_ENUMS_ONCE_ONLY 24 + 25 + enum cachefiles_obj_ref_trace { 26 + cachefiles_obj_put_wait_retry = fscache_obj_ref__nr_traces, 27 + cachefiles_obj_put_wait_timeo, 28 + cachefiles_obj_ref__nr_traces 29 + }; 30 + 31 + #endif 32 + 33 + /* 34 + * Define enum -> string mappings for display. 35 + */ 36 + #define cachefiles_obj_kill_traces \ 37 + EM(FSCACHE_OBJECT_IS_STALE, "stale") \ 38 + EM(FSCACHE_OBJECT_NO_SPACE, "no_space") \ 39 + EM(FSCACHE_OBJECT_WAS_RETIRED, "was_retired") \ 40 + E_(FSCACHE_OBJECT_WAS_CULLED, "was_culled") 41 + 42 + #define cachefiles_obj_ref_traces \ 43 + EM(fscache_obj_get_add_to_deps, "GET add_to_deps") \ 44 + EM(fscache_obj_get_queue, "GET queue") \ 45 + EM(fscache_obj_put_alloc_fail, "PUT alloc_fail") \ 46 + EM(fscache_obj_put_attach_fail, "PUT attach_fail") \ 47 + EM(fscache_obj_put_drop_obj, "PUT drop_obj") \ 48 + EM(fscache_obj_put_enq_dep, "PUT enq_dep") \ 49 + EM(fscache_obj_put_queue, "PUT queue") \ 50 + EM(fscache_obj_put_work, "PUT work") \ 51 + EM(cachefiles_obj_put_wait_retry, "PUT wait_retry") \ 52 + E_(cachefiles_obj_put_wait_timeo, "PUT wait_timeo") 53 + 54 + /* 55 + * Export enum symbols via userspace. 56 + */ 57 + #undef EM 58 + #undef E_ 59 + #define EM(a, b) TRACE_DEFINE_ENUM(a); 60 + #define E_(a, b) TRACE_DEFINE_ENUM(a); 61 + 62 + cachefiles_obj_kill_traces; 63 + cachefiles_obj_ref_traces; 64 + 65 + /* 66 + * Now redefine the EM() and E_() macros to map the enums to the strings that 67 + * will be printed in the output. 68 + */ 69 + #undef EM 70 + #undef E_ 71 + #define EM(a, b) { a, b }, 72 + #define E_(a, b) { a, b } 73 + 74 + 75 + TRACE_EVENT(cachefiles_ref, 76 + TP_PROTO(struct cachefiles_object *obj, 77 + struct fscache_cookie *cookie, 78 + enum cachefiles_obj_ref_trace why, 79 + int usage), 80 + 81 + TP_ARGS(obj, cookie, why, usage), 82 + 83 + /* Note that obj may be NULL */ 84 + TP_STRUCT__entry( 85 + __field(struct cachefiles_object *, obj ) 86 + __field(struct fscache_cookie *, cookie ) 87 + __field(enum cachefiles_obj_ref_trace, why ) 88 + __field(int, usage ) 89 + ), 90 + 91 + TP_fast_assign( 92 + __entry->obj = obj; 93 + __entry->cookie = cookie; 94 + __entry->usage = usage; 95 + __entry->why = why; 96 + ), 97 + 98 + TP_printk("c=%p o=%p u=%d %s", 99 + __entry->cookie, __entry->obj, __entry->usage, 100 + __print_symbolic(__entry->why, cachefiles_obj_ref_traces)) 101 + ); 102 + 103 + TRACE_EVENT(cachefiles_lookup, 104 + TP_PROTO(struct cachefiles_object *obj, 105 + struct dentry *de, 106 + struct inode *inode), 107 + 108 + TP_ARGS(obj, de, inode), 109 + 110 + TP_STRUCT__entry( 111 + __field(struct cachefiles_object *, obj ) 112 + __field(struct dentry *, de ) 113 + __field(struct inode *, inode ) 114 + ), 115 + 116 + TP_fast_assign( 117 + __entry->obj = obj; 118 + __entry->de = de; 119 + __entry->inode = inode; 120 + ), 121 + 122 + TP_printk("o=%p d=%p i=%p", 123 + __entry->obj, __entry->de, __entry->inode) 124 + ); 125 + 126 + TRACE_EVENT(cachefiles_mkdir, 127 + TP_PROTO(struct cachefiles_object *obj, 128 + struct dentry *de, int ret), 129 + 130 + TP_ARGS(obj, de, ret), 131 + 132 + TP_STRUCT__entry( 133 + __field(struct cachefiles_object *, obj ) 134 + __field(struct dentry *, de ) 135 + __field(int, ret ) 136 + ), 137 + 138 + TP_fast_assign( 139 + __entry->obj = obj; 140 + __entry->de = de; 141 + __entry->ret = ret; 142 + ), 143 + 144 + TP_printk("o=%p d=%p r=%u", 145 + __entry->obj, __entry->de, __entry->ret) 146 + ); 147 + 148 + TRACE_EVENT(cachefiles_create, 149 + TP_PROTO(struct cachefiles_object *obj, 150 + struct dentry *de, int ret), 151 + 152 + TP_ARGS(obj, de, ret), 153 + 154 + TP_STRUCT__entry( 155 + __field(struct cachefiles_object *, obj ) 156 + __field(struct dentry *, de ) 157 + __field(int, ret ) 158 + ), 159 + 160 + TP_fast_assign( 161 + __entry->obj = obj; 162 + __entry->de = de; 163 + __entry->ret = ret; 164 + ), 165 + 166 + TP_printk("o=%p d=%p r=%u", 167 + __entry->obj, __entry->de, __entry->ret) 168 + ); 169 + 170 + TRACE_EVENT(cachefiles_unlink, 171 + TP_PROTO(struct cachefiles_object *obj, 172 + struct dentry *de, 173 + enum fscache_why_object_killed why), 174 + 175 + TP_ARGS(obj, de, why), 176 + 177 + /* Note that obj may be NULL */ 178 + TP_STRUCT__entry( 179 + __field(struct cachefiles_object *, obj ) 180 + __field(struct dentry *, de ) 181 + __field(enum fscache_why_object_killed, why ) 182 + ), 183 + 184 + TP_fast_assign( 185 + __entry->obj = obj; 186 + __entry->de = de; 187 + __entry->why = why; 188 + ), 189 + 190 + TP_printk("o=%p d=%p w=%s", 191 + __entry->obj, __entry->de, 192 + __print_symbolic(__entry->why, cachefiles_obj_kill_traces)) 193 + ); 194 + 195 + TRACE_EVENT(cachefiles_rename, 196 + TP_PROTO(struct cachefiles_object *obj, 197 + struct dentry *de, 198 + struct dentry *to, 199 + enum fscache_why_object_killed why), 200 + 201 + TP_ARGS(obj, de, to, why), 202 + 203 + /* Note that obj may be NULL */ 204 + TP_STRUCT__entry( 205 + __field(struct cachefiles_object *, obj ) 206 + __field(struct dentry *, de ) 207 + __field(struct dentry *, to ) 208 + __field(enum fscache_why_object_killed, why ) 209 + ), 210 + 211 + TP_fast_assign( 212 + __entry->obj = obj; 213 + __entry->de = de; 214 + __entry->to = to; 215 + __entry->why = why; 216 + ), 217 + 218 + TP_printk("o=%p d=%p t=%p w=%s", 219 + __entry->obj, __entry->de, __entry->to, 220 + __print_symbolic(__entry->why, cachefiles_obj_kill_traces)) 221 + ); 222 + 223 + TRACE_EVENT(cachefiles_mark_active, 224 + TP_PROTO(struct cachefiles_object *obj, 225 + struct dentry *de), 226 + 227 + TP_ARGS(obj, de), 228 + 229 + /* Note that obj may be NULL */ 230 + TP_STRUCT__entry( 231 + __field(struct cachefiles_object *, obj ) 232 + __field(struct dentry *, de ) 233 + ), 234 + 235 + TP_fast_assign( 236 + __entry->obj = obj; 237 + __entry->de = de; 238 + ), 239 + 240 + TP_printk("o=%p d=%p", 241 + __entry->obj, __entry->de) 242 + ); 243 + 244 + TRACE_EVENT(cachefiles_wait_active, 245 + TP_PROTO(struct cachefiles_object *obj, 246 + struct dentry *de, 247 + struct cachefiles_object *xobj), 248 + 249 + TP_ARGS(obj, de, xobj), 250 + 251 + /* Note that obj may be NULL */ 252 + TP_STRUCT__entry( 253 + __field(struct cachefiles_object *, obj ) 254 + __field(struct dentry *, de ) 255 + __field(struct cachefiles_object *, xobj ) 256 + __field(u16, flags ) 257 + __field(u16, fsc_flags ) 258 + ), 259 + 260 + TP_fast_assign( 261 + __entry->obj = obj; 262 + __entry->de = de; 263 + __entry->xobj = xobj; 264 + __entry->flags = xobj->flags; 265 + __entry->fsc_flags = xobj->fscache.flags; 266 + ), 267 + 268 + TP_printk("o=%p d=%p wo=%p wf=%x wff=%x", 269 + __entry->obj, __entry->de, __entry->xobj, 270 + __entry->flags, __entry->fsc_flags) 271 + ); 272 + 273 + TRACE_EVENT(cachefiles_mark_inactive, 274 + TP_PROTO(struct cachefiles_object *obj, 275 + struct dentry *de, 276 + struct inode *inode), 277 + 278 + TP_ARGS(obj, de, inode), 279 + 280 + /* Note that obj may be NULL */ 281 + TP_STRUCT__entry( 282 + __field(struct cachefiles_object *, obj ) 283 + __field(struct dentry *, de ) 284 + __field(struct inode *, inode ) 285 + ), 286 + 287 + TP_fast_assign( 288 + __entry->obj = obj; 289 + __entry->de = de; 290 + __entry->inode = inode; 291 + ), 292 + 293 + TP_printk("o=%p d=%p i=%p", 294 + __entry->obj, __entry->de, __entry->inode) 295 + ); 296 + 297 + TRACE_EVENT(cachefiles_mark_buried, 298 + TP_PROTO(struct cachefiles_object *obj, 299 + struct dentry *de, 300 + enum fscache_why_object_killed why), 301 + 302 + TP_ARGS(obj, de, why), 303 + 304 + /* Note that obj may be NULL */ 305 + TP_STRUCT__entry( 306 + __field(struct cachefiles_object *, obj ) 307 + __field(struct dentry *, de ) 308 + __field(enum fscache_why_object_killed, why ) 309 + ), 310 + 311 + TP_fast_assign( 312 + __entry->obj = obj; 313 + __entry->de = de; 314 + __entry->why = why; 315 + ), 316 + 317 + TP_printk("o=%p d=%p w=%s", 318 + __entry->obj, __entry->de, 319 + __print_symbolic(__entry->why, cachefiles_obj_kill_traces)) 320 + ); 321 + 322 + #endif /* _TRACE_CACHEFILES_H */ 323 + 324 + /* This part must be outside protection */ 325 + #include <trace/define_trace.h>
+537
include/trace/events/fscache.h
··· 1 + /* FS-Cache tracepoints 2 + * 3 + * Copyright (C) 2016 Red Hat, Inc. All Rights Reserved. 4 + * Written by David Howells (dhowells@redhat.com) 5 + * 6 + * This program is free software; you can redistribute it and/or 7 + * modify it under the terms of the GNU General Public Licence 8 + * as published by the Free Software Foundation; either version 9 + * 2 of the Licence, or (at your option) any later version. 10 + */ 11 + #undef TRACE_SYSTEM 12 + #define TRACE_SYSTEM fscache 13 + 14 + #if !defined(_TRACE_FSCACHE_H) || defined(TRACE_HEADER_MULTI_READ) 15 + #define _TRACE_FSCACHE_H 16 + 17 + #include <linux/fscache.h> 18 + #include <linux/tracepoint.h> 19 + 20 + /* 21 + * Define enums for tracing information. 22 + */ 23 + #ifndef __FSCACHE_DECLARE_TRACE_ENUMS_ONCE_ONLY 24 + #define __FSCACHE_DECLARE_TRACE_ENUMS_ONCE_ONLY 25 + 26 + enum fscache_cookie_trace { 27 + fscache_cookie_collision, 28 + fscache_cookie_discard, 29 + fscache_cookie_get_acquire_parent, 30 + fscache_cookie_get_attach_object, 31 + fscache_cookie_get_reacquire, 32 + fscache_cookie_get_register_netfs, 33 + fscache_cookie_put_acquire_nobufs, 34 + fscache_cookie_put_dup_netfs, 35 + fscache_cookie_put_relinquish, 36 + fscache_cookie_put_object, 37 + fscache_cookie_put_parent, 38 + }; 39 + 40 + enum fscache_page_trace { 41 + fscache_page_cached, 42 + fscache_page_inval, 43 + fscache_page_maybe_release, 44 + fscache_page_radix_clear_store, 45 + fscache_page_radix_delete, 46 + fscache_page_radix_insert, 47 + fscache_page_radix_pend2store, 48 + fscache_page_radix_set_pend, 49 + fscache_page_uncache, 50 + fscache_page_write, 51 + fscache_page_write_end, 52 + fscache_page_write_end_pend, 53 + fscache_page_write_end_noc, 54 + fscache_page_write_wait, 55 + fscache_page_trace__nr 56 + }; 57 + 58 + enum fscache_op_trace { 59 + fscache_op_cancel, 60 + fscache_op_cancel_all, 61 + fscache_op_cancelled, 62 + fscache_op_completed, 63 + fscache_op_enqueue_async, 64 + fscache_op_enqueue_mythread, 65 + fscache_op_gc, 66 + fscache_op_init, 67 + fscache_op_put, 68 + fscache_op_run, 69 + fscache_op_signal, 70 + fscache_op_submit, 71 + fscache_op_submit_ex, 72 + fscache_op_work, 73 + fscache_op_trace__nr 74 + }; 75 + 76 + enum fscache_page_op_trace { 77 + fscache_page_op_alloc_one, 78 + fscache_page_op_attr_changed, 79 + fscache_page_op_check_consistency, 80 + fscache_page_op_invalidate, 81 + fscache_page_op_retr_multi, 82 + fscache_page_op_retr_one, 83 + fscache_page_op_write_one, 84 + fscache_page_op_trace__nr 85 + }; 86 + 87 + #endif 88 + 89 + /* 90 + * Declare tracing information enums and their string mappings for display. 91 + */ 92 + #define fscache_cookie_traces \ 93 + EM(fscache_cookie_collision, "*COLLISION*") \ 94 + EM(fscache_cookie_discard, "DISCARD") \ 95 + EM(fscache_cookie_get_acquire_parent, "GET prn") \ 96 + EM(fscache_cookie_get_attach_object, "GET obj") \ 97 + EM(fscache_cookie_get_reacquire, "GET raq") \ 98 + EM(fscache_cookie_get_register_netfs, "GET net") \ 99 + EM(fscache_cookie_put_acquire_nobufs, "PUT nbf") \ 100 + EM(fscache_cookie_put_dup_netfs, "PUT dnt") \ 101 + EM(fscache_cookie_put_relinquish, "PUT rlq") \ 102 + EM(fscache_cookie_put_object, "PUT obj") \ 103 + E_(fscache_cookie_put_parent, "PUT prn") 104 + 105 + #define fscache_page_traces \ 106 + EM(fscache_page_cached, "Cached ") \ 107 + EM(fscache_page_inval, "InvalPg") \ 108 + EM(fscache_page_maybe_release, "MayRels") \ 109 + EM(fscache_page_uncache, "Uncache") \ 110 + EM(fscache_page_radix_clear_store, "RxCStr ") \ 111 + EM(fscache_page_radix_delete, "RxDel ") \ 112 + EM(fscache_page_radix_insert, "RxIns ") \ 113 + EM(fscache_page_radix_pend2store, "RxP2S ") \ 114 + EM(fscache_page_radix_set_pend, "RxSPend ") \ 115 + EM(fscache_page_write, "WritePg") \ 116 + EM(fscache_page_write_end, "EndPgWr") \ 117 + EM(fscache_page_write_end_pend, "EndPgWP") \ 118 + EM(fscache_page_write_end_noc, "EndPgNC") \ 119 + E_(fscache_page_write_wait, "WtOnWrt") 120 + 121 + #define fscache_op_traces \ 122 + EM(fscache_op_cancel, "Cancel1") \ 123 + EM(fscache_op_cancel_all, "CancelA") \ 124 + EM(fscache_op_cancelled, "Canclld") \ 125 + EM(fscache_op_completed, "Complet") \ 126 + EM(fscache_op_enqueue_async, "EnqAsyn") \ 127 + EM(fscache_op_enqueue_mythread, "EnqMyTh") \ 128 + EM(fscache_op_gc, "GC ") \ 129 + EM(fscache_op_init, "Init ") \ 130 + EM(fscache_op_put, "Put ") \ 131 + EM(fscache_op_run, "Run ") \ 132 + EM(fscache_op_signal, "Signal ") \ 133 + EM(fscache_op_submit, "Submit ") \ 134 + EM(fscache_op_submit_ex, "SubmitX") \ 135 + E_(fscache_op_work, "Work ") 136 + 137 + #define fscache_page_op_traces \ 138 + EM(fscache_page_op_alloc_one, "Alloc1 ") \ 139 + EM(fscache_page_op_attr_changed, "AttrChg") \ 140 + EM(fscache_page_op_check_consistency, "CheckCn") \ 141 + EM(fscache_page_op_invalidate, "Inval ") \ 142 + EM(fscache_page_op_retr_multi, "RetrMul") \ 143 + EM(fscache_page_op_retr_one, "Retr1 ") \ 144 + E_(fscache_page_op_write_one, "Write1 ") 145 + 146 + /* 147 + * Export enum symbols via userspace. 148 + */ 149 + #undef EM 150 + #undef E_ 151 + #define EM(a, b) TRACE_DEFINE_ENUM(a); 152 + #define E_(a, b) TRACE_DEFINE_ENUM(a); 153 + 154 + fscache_cookie_traces; 155 + 156 + /* 157 + * Now redefine the EM() and E_() macros to map the enums to the strings that 158 + * will be printed in the output. 159 + */ 160 + #undef EM 161 + #undef E_ 162 + #define EM(a, b) { a, b }, 163 + #define E_(a, b) { a, b } 164 + 165 + 166 + TRACE_EVENT(fscache_cookie, 167 + TP_PROTO(struct fscache_cookie *cookie, 168 + enum fscache_cookie_trace where, 169 + int usage), 170 + 171 + TP_ARGS(cookie, where, usage), 172 + 173 + TP_STRUCT__entry( 174 + __field(struct fscache_cookie *, cookie ) 175 + __field(struct fscache_cookie *, parent ) 176 + __field(enum fscache_cookie_trace, where ) 177 + __field(int, usage ) 178 + __field(int, n_children ) 179 + __field(int, n_active ) 180 + __field(u8, flags ) 181 + ), 182 + 183 + TP_fast_assign( 184 + __entry->cookie = cookie; 185 + __entry->parent = cookie->parent; 186 + __entry->where = where; 187 + __entry->usage = usage; 188 + __entry->n_children = atomic_read(&cookie->n_children); 189 + __entry->n_active = atomic_read(&cookie->n_active); 190 + __entry->flags = cookie->flags; 191 + ), 192 + 193 + TP_printk("%s c=%p u=%d p=%p Nc=%d Na=%d f=%02x", 194 + __print_symbolic(__entry->where, fscache_cookie_traces), 195 + __entry->cookie, __entry->usage, 196 + __entry->parent, __entry->n_children, __entry->n_active, 197 + __entry->flags) 198 + ); 199 + 200 + TRACE_EVENT(fscache_netfs, 201 + TP_PROTO(struct fscache_netfs *netfs), 202 + 203 + TP_ARGS(netfs), 204 + 205 + TP_STRUCT__entry( 206 + __field(struct fscache_cookie *, cookie ) 207 + __array(char, name, 8 ) 208 + ), 209 + 210 + TP_fast_assign( 211 + __entry->cookie = netfs->primary_index; 212 + strncpy(__entry->name, netfs->name, 8); 213 + __entry->name[7] = 0; 214 + ), 215 + 216 + TP_printk("c=%p n=%s", 217 + __entry->cookie, __entry->name) 218 + ); 219 + 220 + TRACE_EVENT(fscache_acquire, 221 + TP_PROTO(struct fscache_cookie *cookie), 222 + 223 + TP_ARGS(cookie), 224 + 225 + TP_STRUCT__entry( 226 + __field(struct fscache_cookie *, cookie ) 227 + __field(struct fscache_cookie *, parent ) 228 + __array(char, name, 8 ) 229 + __field(int, p_usage ) 230 + __field(int, p_n_children ) 231 + __field(u8, p_flags ) 232 + ), 233 + 234 + TP_fast_assign( 235 + __entry->cookie = cookie; 236 + __entry->parent = cookie->parent; 237 + __entry->p_usage = atomic_read(&cookie->parent->usage); 238 + __entry->p_n_children = atomic_read(&cookie->parent->n_children); 239 + __entry->p_flags = cookie->parent->flags; 240 + memcpy(__entry->name, cookie->def->name, 8); 241 + __entry->name[7] = 0; 242 + ), 243 + 244 + TP_printk("c=%p p=%p pu=%d pc=%d pf=%02x n=%s", 245 + __entry->cookie, __entry->parent, __entry->p_usage, 246 + __entry->p_n_children, __entry->p_flags, __entry->name) 247 + ); 248 + 249 + TRACE_EVENT(fscache_relinquish, 250 + TP_PROTO(struct fscache_cookie *cookie, bool retire), 251 + 252 + TP_ARGS(cookie, retire), 253 + 254 + TP_STRUCT__entry( 255 + __field(struct fscache_cookie *, cookie ) 256 + __field(struct fscache_cookie *, parent ) 257 + __field(int, usage ) 258 + __field(int, n_children ) 259 + __field(int, n_active ) 260 + __field(u8, flags ) 261 + __field(bool, retire ) 262 + ), 263 + 264 + TP_fast_assign( 265 + __entry->cookie = cookie; 266 + __entry->parent = cookie->parent; 267 + __entry->usage = atomic_read(&cookie->usage); 268 + __entry->n_children = atomic_read(&cookie->n_children); 269 + __entry->n_active = atomic_read(&cookie->n_active); 270 + __entry->flags = cookie->flags; 271 + __entry->retire = retire; 272 + ), 273 + 274 + TP_printk("c=%p u=%d p=%p Nc=%d Na=%d f=%02x r=%u", 275 + __entry->cookie, __entry->usage, 276 + __entry->parent, __entry->n_children, __entry->n_active, 277 + __entry->flags, __entry->retire) 278 + ); 279 + 280 + TRACE_EVENT(fscache_enable, 281 + TP_PROTO(struct fscache_cookie *cookie), 282 + 283 + TP_ARGS(cookie), 284 + 285 + TP_STRUCT__entry( 286 + __field(struct fscache_cookie *, cookie ) 287 + __field(int, usage ) 288 + __field(int, n_children ) 289 + __field(int, n_active ) 290 + __field(u8, flags ) 291 + ), 292 + 293 + TP_fast_assign( 294 + __entry->cookie = cookie; 295 + __entry->usage = atomic_read(&cookie->usage); 296 + __entry->n_children = atomic_read(&cookie->n_children); 297 + __entry->n_active = atomic_read(&cookie->n_active); 298 + __entry->flags = cookie->flags; 299 + ), 300 + 301 + TP_printk("c=%p u=%d Nc=%d Na=%d f=%02x", 302 + __entry->cookie, __entry->usage, 303 + __entry->n_children, __entry->n_active, __entry->flags) 304 + ); 305 + 306 + TRACE_EVENT(fscache_disable, 307 + TP_PROTO(struct fscache_cookie *cookie), 308 + 309 + TP_ARGS(cookie), 310 + 311 + TP_STRUCT__entry( 312 + __field(struct fscache_cookie *, cookie ) 313 + __field(int, usage ) 314 + __field(int, n_children ) 315 + __field(int, n_active ) 316 + __field(u8, flags ) 317 + ), 318 + 319 + TP_fast_assign( 320 + __entry->cookie = cookie; 321 + __entry->usage = atomic_read(&cookie->usage); 322 + __entry->n_children = atomic_read(&cookie->n_children); 323 + __entry->n_active = atomic_read(&cookie->n_active); 324 + __entry->flags = cookie->flags; 325 + ), 326 + 327 + TP_printk("c=%p u=%d Nc=%d Na=%d f=%02x", 328 + __entry->cookie, __entry->usage, 329 + __entry->n_children, __entry->n_active, __entry->flags) 330 + ); 331 + 332 + TRACE_EVENT(fscache_osm, 333 + TP_PROTO(struct fscache_object *object, 334 + const struct fscache_state *state, 335 + bool wait, bool oob, s8 event_num), 336 + 337 + TP_ARGS(object, state, wait, oob, event_num), 338 + 339 + TP_STRUCT__entry( 340 + __field(struct fscache_cookie *, cookie ) 341 + __field(struct fscache_object *, object ) 342 + __array(char, state, 8 ) 343 + __field(bool, wait ) 344 + __field(bool, oob ) 345 + __field(s8, event_num ) 346 + ), 347 + 348 + TP_fast_assign( 349 + __entry->cookie = object->cookie; 350 + __entry->object = object; 351 + __entry->wait = wait; 352 + __entry->oob = oob; 353 + __entry->event_num = event_num; 354 + memcpy(__entry->state, state->short_name, 8); 355 + ), 356 + 357 + TP_printk("c=%p o=%p %s %s%sev=%d", 358 + __entry->cookie, 359 + __entry->object, 360 + __entry->state, 361 + __print_symbolic(__entry->wait, 362 + { true, "WAIT" }, 363 + { false, "WORK" }), 364 + __print_symbolic(__entry->oob, 365 + { true, " OOB " }, 366 + { false, " " }), 367 + __entry->event_num) 368 + ); 369 + 370 + TRACE_EVENT(fscache_page, 371 + TP_PROTO(struct fscache_cookie *cookie, struct page *page, 372 + enum fscache_page_trace why), 373 + 374 + TP_ARGS(cookie, page, why), 375 + 376 + TP_STRUCT__entry( 377 + __field(struct fscache_cookie *, cookie ) 378 + __field(pgoff_t, page ) 379 + __field(enum fscache_page_trace, why ) 380 + ), 381 + 382 + TP_fast_assign( 383 + __entry->cookie = cookie; 384 + __entry->page = page->index; 385 + __entry->why = why; 386 + ), 387 + 388 + TP_printk("c=%p %s pg=%lx", 389 + __entry->cookie, 390 + __print_symbolic(__entry->why, fscache_page_traces), 391 + __entry->page) 392 + ); 393 + 394 + TRACE_EVENT(fscache_check_page, 395 + TP_PROTO(struct fscache_cookie *cookie, struct page *page, 396 + void *val, int n), 397 + 398 + TP_ARGS(cookie, page, val, n), 399 + 400 + TP_STRUCT__entry( 401 + __field(struct fscache_cookie *, cookie ) 402 + __field(void *, page ) 403 + __field(void *, val ) 404 + __field(int, n ) 405 + ), 406 + 407 + TP_fast_assign( 408 + __entry->cookie = cookie; 409 + __entry->page = page; 410 + __entry->val = val; 411 + __entry->n = n; 412 + ), 413 + 414 + TP_printk("c=%p pg=%p val=%p n=%d", 415 + __entry->cookie, __entry->page, __entry->val, __entry->n) 416 + ); 417 + 418 + TRACE_EVENT(fscache_wake_cookie, 419 + TP_PROTO(struct fscache_cookie *cookie), 420 + 421 + TP_ARGS(cookie), 422 + 423 + TP_STRUCT__entry( 424 + __field(struct fscache_cookie *, cookie ) 425 + ), 426 + 427 + TP_fast_assign( 428 + __entry->cookie = cookie; 429 + ), 430 + 431 + TP_printk("c=%p", __entry->cookie) 432 + ); 433 + 434 + TRACE_EVENT(fscache_op, 435 + TP_PROTO(struct fscache_cookie *cookie, struct fscache_operation *op, 436 + enum fscache_op_trace why), 437 + 438 + TP_ARGS(cookie, op, why), 439 + 440 + TP_STRUCT__entry( 441 + __field(struct fscache_cookie *, cookie ) 442 + __field(struct fscache_operation *, op ) 443 + __field(enum fscache_op_trace, why ) 444 + ), 445 + 446 + TP_fast_assign( 447 + __entry->cookie = cookie; 448 + __entry->op = op; 449 + __entry->why = why; 450 + ), 451 + 452 + TP_printk("c=%p op=%p %s", 453 + __entry->cookie, __entry->op, 454 + __print_symbolic(__entry->why, fscache_op_traces)) 455 + ); 456 + 457 + TRACE_EVENT(fscache_page_op, 458 + TP_PROTO(struct fscache_cookie *cookie, struct page *page, 459 + struct fscache_operation *op, enum fscache_page_op_trace what), 460 + 461 + TP_ARGS(cookie, page, op, what), 462 + 463 + TP_STRUCT__entry( 464 + __field(struct fscache_cookie *, cookie ) 465 + __field(pgoff_t, page ) 466 + __field(struct fscache_operation *, op ) 467 + __field(enum fscache_page_op_trace, what ) 468 + ), 469 + 470 + TP_fast_assign( 471 + __entry->cookie = cookie; 472 + __entry->page = page ? page->index : 0; 473 + __entry->op = op; 474 + __entry->what = what; 475 + ), 476 + 477 + TP_printk("c=%p %s pg=%lx op=%p", 478 + __entry->cookie, 479 + __print_symbolic(__entry->what, fscache_page_op_traces), 480 + __entry->page, __entry->op) 481 + ); 482 + 483 + TRACE_EVENT(fscache_wrote_page, 484 + TP_PROTO(struct fscache_cookie *cookie, struct page *page, 485 + struct fscache_operation *op, int ret), 486 + 487 + TP_ARGS(cookie, page, op, ret), 488 + 489 + TP_STRUCT__entry( 490 + __field(struct fscache_cookie *, cookie ) 491 + __field(pgoff_t, page ) 492 + __field(struct fscache_operation *, op ) 493 + __field(int, ret ) 494 + ), 495 + 496 + TP_fast_assign( 497 + __entry->cookie = cookie; 498 + __entry->page = page->index; 499 + __entry->op = op; 500 + __entry->ret = ret; 501 + ), 502 + 503 + TP_printk("c=%p pg=%lx op=%p ret=%d", 504 + __entry->cookie, __entry->page, __entry->op, __entry->ret) 505 + ); 506 + 507 + TRACE_EVENT(fscache_gang_lookup, 508 + TP_PROTO(struct fscache_cookie *cookie, struct fscache_operation *op, 509 + void **results, int n, pgoff_t store_limit), 510 + 511 + TP_ARGS(cookie, op, results, n, store_limit), 512 + 513 + TP_STRUCT__entry( 514 + __field(struct fscache_cookie *, cookie ) 515 + __field(struct fscache_operation *, op ) 516 + __field(pgoff_t, results0 ) 517 + __field(int, n ) 518 + __field(pgoff_t, store_limit ) 519 + ), 520 + 521 + TP_fast_assign( 522 + __entry->cookie = cookie; 523 + __entry->op = op; 524 + __entry->results0 = results[0] ? ((struct page *)results[0])->index : (pgoff_t)-1; 525 + __entry->n = n; 526 + __entry->store_limit = store_limit; 527 + ), 528 + 529 + TP_printk("c=%p op=%p r0=%lx n=%d sl=%lx", 530 + __entry->cookie, __entry->op, __entry->results0, __entry->n, 531 + __entry->store_limit) 532 + ); 533 + 534 + #endif /* _TRACE_FSCACHE_H */ 535 + 536 + /* This part must be outside protection */ 537 + #include <trace/define_trace.h>