diff options
author | David Howells <dhowells@redhat.com> | 2018-04-04 13:41:28 +0100 |
---|---|---|
committer | David Howells <dhowells@redhat.com> | 2018-04-04 13:41:28 +0100 |
commit | 402cb8dda949d9b8c0df20ad2527d139faad7ca1 (patch) | |
tree | 83cdb77f5490a0990eade886aa7f8dd087864996 | |
parent | 08c2e3d087840cd1e7141b62d92f3dc897147984 (diff) |
fscache: Attach the index key and aux data to the cookie
Attach copies of the index key and auxiliary data to the fscache cookie so
that:
(1) The callbacks to the netfs for this stuff can be eliminated. This
can simplify things in the cache as the information is still
available, even after the cache has relinquished the cookie.
(2) Simplifies the locking requirements of accessing the information as we
don't have to worry about the netfs object going away on us.
(3) The cache can do lazy updating of the coherency information on disk.
As long as the cache is flushed before reboot/poweroff, there's no
need to update the coherency info on disk every time it changes.
(4) Cookies can be hashed or put in a tree as the index key is easily
available. This allows:
(a) Checks for duplicate cookies can be made at the top fscache layer
rather than down in the bowels of the cache backend.
(b) Caching can be added to a netfs object that has a cookie if the
cache is brought online after the netfs object is allocated.
A certain amount of space is made in the cookie for inline copies of the
data, but if it won't fit there, extra memory will be allocated for it.
The downside of this is that live cache operation requires more memory.
Signed-off-by: David Howells <dhowells@redhat.com>
Acked-by: Anna Schumaker <anna.schumaker@netapp.com>
Tested-by: Steve Dickson <steved@redhat.com>
-rw-r--r-- | Documentation/filesystems/caching/netfs-api.txt | 106 | ||||
-rw-r--r-- | fs/9p/cache.c | 73 | ||||
-rw-r--r-- | fs/afs/cache.c | 120 | ||||
-rw-r--r-- | fs/afs/cell.c | 4 | ||||
-rw-r--r-- | fs/afs/inode.c | 46 | ||||
-rw-r--r-- | fs/afs/internal.h | 7 | ||||
-rw-r--r-- | fs/afs/volume.c | 4 | ||||
-rw-r--r-- | fs/cachefiles/interface.c | 38 | ||||
-rw-r--r-- | fs/cachefiles/namei.c | 33 | ||||
-rw-r--r-- | fs/cachefiles/xattr.c | 2 | ||||
-rw-r--r-- | fs/ceph/cache.c | 93 | ||||
-rw-r--r-- | fs/cifs/cache.c | 153 | ||||
-rw-r--r-- | fs/cifs/fscache.c | 122 | ||||
-rw-r--r-- | fs/cifs/fscache.h | 13 | ||||
-rw-r--r-- | fs/fscache/cache.c | 2 | ||||
-rw-r--r-- | fs/fscache/cookie.c | 88 | ||||
-rw-r--r-- | fs/fscache/fsdef.c | 49 | ||||
-rw-r--r-- | fs/fscache/internal.h | 21 | ||||
-rw-r--r-- | fs/fscache/netfs.c | 17 | ||||
-rw-r--r-- | fs/fscache/object-list.c | 28 | ||||
-rw-r--r-- | fs/fscache/object.c | 22 | ||||
-rw-r--r-- | fs/fscache/operation.c | 2 | ||||
-rw-r--r-- | fs/nfs/fscache-index.c | 140 | ||||
-rw-r--r-- | fs/nfs/fscache.c | 83 | ||||
-rw-r--r-- | fs/nfs/fscache.h | 16 | ||||
-rw-r--r-- | include/linux/fscache.h | 110 |
26 files changed, 606 insertions, 786 deletions
diff --git a/Documentation/filesystems/caching/netfs-api.txt b/Documentation/filesystems/caching/netfs-api.txt index 0eb31de3a2c1..332840ad4151 100644 --- a/Documentation/filesystems/caching/netfs-api.txt +++ b/Documentation/filesystems/caching/netfs-api.txt @@ -129,17 +129,9 @@ To define an object, a structure of the following type should be filled out: const void *parent_netfs_data, const void *cookie_netfs_data); - uint16_t (*get_key)(const void *cookie_netfs_data, - void *buffer, - uint16_t bufmax); - void (*get_attr)(const void *cookie_netfs_data, uint64_t *size); - uint16_t (*get_aux)(const void *cookie_netfs_data, - void *buffer, - uint16_t bufmax); - enum fscache_checkaux (*check_aux)(void *cookie_netfs_data, const void *data, uint16_t datalen); @@ -187,14 +179,7 @@ This has the following fields: cache in the parent's list will be chosen, or failing that, the first cache in the master list. - (4) A function to retrieve an object's key from the netfs [mandatory]. - - This function will be called with the netfs data that was passed to the - cookie acquisition function and the maximum length of key data that it may - provide. It should write the required key data into the given buffer and - return the quantity it wrote. - - (5) A function to retrieve attribute data from the netfs [optional]. + (4) A function to retrieve attribute data from the netfs [optional]. This function will be called with the netfs data that was passed to the cookie acquisition function. It should return the size of the file if @@ -203,20 +188,7 @@ This has the following fields: If the function is absent, a file size of 0 is assumed. - (6) A function to retrieve auxiliary data from the netfs [optional]. - - This function will be called with the netfs data that was passed to the - cookie acquisition function and the maximum length of auxiliary data that - it may provide. It should write the auxiliary data into the given buffer - and return the quantity it wrote. - - If this function is absent, the auxiliary data length will be set to 0. - - The length of the auxiliary data buffer may be dependent on the key - length. A netfs mustn't rely on being able to provide more than 400 bytes - for both. - - (7) A function to check the auxiliary data [optional]. + (5) A function to check the auxiliary data [optional]. This function will be called to check that a match found in the cache for this object is valid. For instance with AFS it could check the auxiliary @@ -235,7 +207,7 @@ This has the following fields: This function can also be used to extract data from the auxiliary data in the cache and copy it into the netfs's structures. - (8) A pair of functions to manage contexts for the completion callback + (6) A pair of functions to manage contexts for the completion callback [optional]. The cache read/write functions are passed a context which is then passed @@ -249,7 +221,7 @@ This has the following fields: required for indices as indices may not contain data. These functions may be called in interrupt context and so may not sleep. - (9) A function to mark a page as retaining cache metadata [optional]. + (7) A function to mark a page as retaining cache metadata [optional]. This is called by the cache to indicate that it is retaining in-memory information for this page and that the netfs should uncache the page when @@ -261,7 +233,7 @@ This has the following fields: This function is not required for indices as they're not permitted data. -(10) A function to unmark all the pages retaining cache metadata [mandatory]. + (8) A function to unmark all the pages retaining cache metadata [mandatory]. This is called by FS-Cache to indicate that a backing store is being unbound from a cookie and that all the marks on the pages should be @@ -333,12 +305,27 @@ the path to the file: struct fscache_cookie * fscache_acquire_cookie(struct fscache_cookie *parent, const struct fscache_object_def *def, + const void *index_key, + size_t index_key_len, + const void *aux_data, + size_t aux_data_len, void *netfs_data, bool enable); This function creates an index entry in the index represented by parent, filling in the index entry by calling the operations pointed to by def. +A unique key that represents the object within the parent must be pointed to by +index_key and is of length index_key_len. + +An optional blob of auxiliary data that is to be stored within the cache can be +pointed to with aux_data and should be of length aux_data_len. This would +typically be used for storing coherency data. + +The netfs may pass an arbitrary value in netfs_data and this will be presented +to it in the event of any calling back. This may also be used in tracing or +logging of messages. + Note that this function never returns an error - all errors are handled internally. It may, however, return NULL to indicate no cookie. It is quite acceptable to pass this token back to this function as the parent to another @@ -355,29 +342,23 @@ must be enabled to do anything with it. A disabled cookie can be enabled by calling fscache_enable_cookie() (see below). For example, with AFS, a cell would be added to the primary index. This index -entry would have a dependent inode containing a volume location index for the -volume mappings within this cell: +entry would have a dependent inode containing volume mappings within this cell: cell->cache = fscache_acquire_cookie(afs_cache_netfs.primary_index, &afs_cell_cache_index_def, + cell->name, strlen(cell->name), + NULL, 0, cell, true); -Then when a volume location was accessed, it would be entered into the cell's -index and an inode would be allocated that acts as a volume type and hash chain -combination: - - vlocation->cache = - fscache_acquire_cookie(cell->cache, - &afs_vlocation_cache_index_def, - vlocation, true); - -And then a particular flavour of volume (R/O for example) could be added to -that index, creating another index for vnodes (AFS inode equivalents): +And then a particular volume could be added to that index by ID, creating +another index for vnodes (AFS inode equivalents): volume->cache = - fscache_acquire_cookie(vlocation->cache, + fscache_acquire_cookie(volume->cell->cache, &afs_volume_cache_index_def, + &volume->vid, sizeof(volume->vid), + NULL, 0, volume, true); @@ -392,6 +373,8 @@ the object definition should be something other than index type. vnode->cache = fscache_acquire_cookie(volume->cache, &afs_vnode_cache_object_def, + &key, sizeof(key), + &aux, sizeof(aux), vnode, true); @@ -408,6 +391,8 @@ it would be some other type of object such as a data file. xattr->cache = fscache_acquire_cookie(vnode->cache, &afs_xattr_cache_object_def, + &xattr->name, strlen(xattr->name), + NULL, 0, xattr, true); Miscellaneous objects might be used to store extended attributes or directory @@ -717,21 +702,23 @@ INDEX AND DATA FILE CONSISTENCY To find out whether auxiliary data for an object is up to data within the cache, the following function can be called: - int fscache_check_consistency(struct fscache_cookie *cookie) + int fscache_check_consistency(struct fscache_cookie *cookie, + const void *aux_data); This will call back to the netfs to check whether the auxiliary data associated -with a cookie is correct. It returns 0 if it is and -ESTALE if it isn't; it -may also return -ENOMEM and -ERESTARTSYS. +with a cookie is correct; if aux_data is non-NULL, it will update the auxiliary +data buffer first. It returns 0 if it is and -ESTALE if it isn't; it may also +return -ENOMEM and -ERESTARTSYS. To request an update of the index data for an index or other object, the following function should be called: - void fscache_update_cookie(struct fscache_cookie *cookie); + void fscache_update_cookie(struct fscache_cookie *cookie, + const void *aux_data); -This function will refer back to the netfs_data pointer stored in the cookie by -the acquisition function to obtain the data to write into each revised index -entry. The update method in the parent index definition will be called to -transfer the data. +This function will update the cookie's auxiliary data buffer from aux_data if +that is non-NULL and then schedule this to be stored on disk. The update +method in the parent index definition will be called to transfer the data. Note that partial updates may happen automatically at other times, such as when data blocks are added to a data file object. @@ -750,6 +737,7 @@ The initial enablement state is set by fscache_acquire_cookie(), but the cookie can be enabled or disabled later. To disable a cookie, call: void fscache_disable_cookie(struct fscache_cookie *cookie, + const void *aux_data, bool invalidate); If the cookie is not already disabled, this locks the cookie against other @@ -764,6 +752,7 @@ markings are cleared up. Cookies can be enabled or reenabled with: void fscache_enable_cookie(struct fscache_cookie *cookie, + const void *aux_data, bool (*can_enable)(void *data), void *data) @@ -777,6 +766,9 @@ ruling as to whether or not enablement should actually be permitted to begin. All possible failures are handled internally. The cookie will only be marked as enabled if provisional backing objects are allocated. +In both cases, the cookie's auxiliary data buffer is updated from aux_data if +that is non-NULL inside the enablement lock before proceeding. + =============================== MISCELLANEOUS COOKIE OPERATIONS @@ -823,6 +815,7 @@ COOKIE UNREGISTRATION To get rid of a cookie, this function should be called. void fscache_relinquish_cookie(struct fscache_cookie *cookie, + const void *aux_data, bool retire); If retire is non-zero, then the object will be marked for recycling, and all @@ -833,6 +826,9 @@ If retire is zero, then the object may be available again when next the acquisition function is called. Retirement here will overrule the pinning on a cookie. +The cookie's auxiliary data will be updated from aux_data if that is non-NULL +so that the cache can lazily update it on disk. + One very important note - relinquish must NOT be called for a cookie unless all the cookies for "child" indices, objects and pages have been relinquished first. diff --git a/fs/9p/cache.c b/fs/9p/cache.c index 64c58eb26159..9d0030af5672 100644 --- a/fs/9p/cache.c +++ b/fs/9p/cache.c @@ -55,41 +55,26 @@ int v9fs_random_cachetag(struct v9fs_session_info *v9ses) return scnprintf(v9ses->cachetag, CACHETAG_LEN, "%lu", jiffies); } -static uint16_t v9fs_cache_session_get_key(const void *cookie_netfs_data, - void *buffer, uint16_t bufmax) -{ - struct v9fs_session_info *v9ses; - uint16_t klen = 0; - - v9ses = (struct v9fs_session_info *)cookie_netfs_data; - p9_debug(P9_DEBUG_FSC, "session %p buf %p size %u\n", - v9ses, buffer, bufmax); - - if (v9ses->cachetag) - klen = strlen(v9ses->cachetag); - - if (klen > bufmax) - return 0; - - memcpy(buffer, v9ses->cachetag, klen); - p9_debug(P9_DEBUG_FSC, "cache session tag %s\n", v9ses->cachetag); - return klen; -} - const struct fscache_cookie_def v9fs_cache_session_index_def = { .name = "9P.session", .type = FSCACHE_COOKIE_TYPE_INDEX, - .get_key = v9fs_cache_session_get_key, }; void v9fs_cache_session_get_cookie(struct v9fs_session_info *v9ses) { /* If no cache session tag was specified, we generate a random one. */ - if (!v9ses->cachetag) - v9fs_random_cachetag(v9ses); + if (!v9ses->cachetag) { + if (v9fs_random_cachetag(v9ses) < 0) { + v9ses->fscache = NULL; + return; + } + } v9ses->fscache = fscache_acquire_cookie(v9fs_cache_netfs.primary_index, &v9fs_cache_session_index_def, + v9ses->cachetag, + strlen(v9ses->cachetag), + NULL, 0, v9ses, true); p9_debug(P9_DEBUG_FSC, "session %p get cookie %p\n", v9ses, v9ses->fscache); @@ -99,21 +84,10 @@ void v9fs_cache_session_put_cookie(struct v9fs_session_info *v9ses) { p9_debug(P9_DEBUG_FSC, "session %p put cookie %p\n", v9ses, v9ses->fscache); - fscache_relinquish_cookie(v9ses->fscache, 0); + fscache_relinquish_cookie(v9ses->fscache, NULL, false); v9ses->fscache = NULL; } - -static uint16_t v9fs_cache_inode_get_key(const void *cookie_netfs_data, - void *buffer, uint16_t bufmax) -{ - const struct v9fs_inode *v9inode = cookie_netfs_data; - memcpy(buffer, &v9inode->qid.path, sizeof(v9inode->qid.path)); - p9_debug(P9_DEBUG_FSC, "inode %p get key %llu\n", - &v9inode->vfs_inode, v9inode->qid.path); - return sizeof(v9inode->qid.path); -} - static void v9fs_cache_inode_get_attr(const void *cookie_netfs_data, uint64_t *size) { @@ -124,16 +98,6 @@ static void v9fs_cache_inode_get_attr(const void *cookie_netfs_data, &v9inode->vfs_inode, *size); } -static uint16_t v9fs_cache_inode_get_aux(const void *cookie_netfs_data, - void *buffer, uint16_t buflen) -{ - const struct v9fs_inode *v9inode = cookie_netfs_data; - memcpy(buffer, &v9inode->qid.version, sizeof(v9inode->qid.version)); - p9_debug(P9_DEBUG_FSC, "inode %p get aux %u\n", - &v9inode->vfs_inode, v9inode->qid.version); - return sizeof(v9inode->qid.version); -} - static enum fscache_checkaux v9fs_cache_inode_check_aux(void *cookie_netfs_data, const void *buffer, @@ -154,9 +118,7 @@ fscache_checkaux v9fs_cache_inode_check_aux(void *cookie_netfs_data, const struct fscache_cookie_def v9fs_cache_inode_index_def = { .name = "9p.inode", .type = FSCACHE_COOKIE_TYPE_DATAFILE, - .get_key = v9fs_cache_inode_get_key, .get_attr = v9fs_cache_inode_get_attr, - .get_aux = v9fs_cache_inode_get_aux, .check_aux = v9fs_cache_inode_check_aux, }; @@ -175,6 +137,10 @@ void v9fs_cache_inode_get_cookie(struct inode *inode) v9ses = v9fs_inode2v9ses(inode); v9inode->fscache = fscache_acquire_cookie(v9ses->fscache, &v9fs_cache_inode_index_def, + &v9inode->qid.path, + sizeof(v9inode->qid.path), + &v9inode->qid.version, + sizeof(v9inode->qid.version), v9inode, true); p9_debug(P9_DEBUG_FSC, "inode %p get cookie %p\n", @@ -190,7 +156,8 @@ void v9fs_cache_inode_put_cookie(struct inode *inode) p9_debug(P9_DEBUG_FSC, "inode %p put cookie %p\n", inode, v9inode->fscache); - fscache_relinquish_cookie(v9inode->fscache, 0); + fscache_relinquish_cookie(v9inode->fscache, &v9inode->qid.version, + false); v9inode->fscache = NULL; } @@ -203,7 +170,7 @@ void v9fs_cache_inode_flush_cookie(struct inode *inode) p9_debug(P9_DEBUG_FSC, "inode %p flush cookie %p\n", inode, v9inode->fscache); - fscache_relinquish_cookie(v9inode->fscache, 1); + fscache_relinquish_cookie(v9inode->fscache, NULL, true); v9inode->fscache = NULL; } @@ -236,11 +203,15 @@ void v9fs_cache_inode_reset_cookie(struct inode *inode) old = v9inode->fscache; mutex_lock(&v9inode->fscache_lock); - fscache_relinquish_cookie(v9inode->fscache, 1); + fscache_relinquish_cookie(v9inode->fscache, NULL, true); v9ses = v9fs_inode2v9ses(inode); v9inode->fscache = fscache_acquire_cookie(v9ses->fscache, &v9fs_cache_inode_index_def, + &v9inode->qid.path, + sizeof(v9inode->qid.path), + &v9inode->qid.version, + sizeof(v9inode->qid.version), v9inode, true); p9_debug(P9_DEBUG_FSC, "inode %p revalidating cookie old %p new %p\n", inode, old, v9inode->fscache); diff --git a/fs/afs/cache.c b/fs/afs/cache.c index cd857db9b112..a16f1e024cf3 100644 --- a/fs/afs/cache.c +++ b/fs/afs/cache.c @@ -12,17 +12,8 @@ #include <linux/sched.h> #include "internal.h" -static uint16_t afs_cell_cache_get_key(const void *cookie_netfs_data, - void *buffer, uint16_t buflen); -static uint16_t afs_volume_cache_get_key(const void *cookie_netfs_data, - void *buffer, uint16_t buflen); - -static uint16_t afs_vnode_cache_get_key(const void *cookie_netfs_data, - void *buffer, uint16_t buflen); static void afs_vnode_cache_get_attr(const void *cookie_netfs_data, uint64_t *size); -static uint16_t afs_vnode_cache_get_aux(const void *cookie_netfs_data, - void *buffer, uint16_t buflen); static enum fscache_checkaux afs_vnode_cache_check_aux(void *cookie_netfs_data, const void *buffer, uint16_t buflen); @@ -35,98 +26,21 @@ struct fscache_netfs afs_cache_netfs = { struct fscache_cookie_def afs_cell_cache_index_def = { .name = "AFS.cell", .type = FSCACHE_COOKIE_TYPE_INDEX, - .get_key = afs_cell_cache_get_key, }; struct fscache_cookie_def afs_volume_cache_index_def = { .name = "AFS.volume", .type = FSCACHE_COOKIE_TYPE_INDEX, - .get_key = afs_volume_cache_get_key, }; struct fscache_cookie_def afs_vnode_cache_index_def = { - .name = "AFS.vnode", - .type = FSCACHE_COOKIE_TYPE_DATAFILE, - .get_key = afs_vnode_cache_get_key, - .get_attr = afs_vnode_cache_get_attr, - .get_aux = afs_vnode_cache_get_aux, - .check_aux = afs_vnode_cache_check_aux, + .name = "AFS.vnode", + .type = FSCACHE_COOKIE_TYPE_DATAFILE, + .get_attr = afs_vnode_cache_get_attr, + .check_aux = afs_vnode_cache_check_aux, }; /* - * set the key for the index entry - */ -static uint16_t afs_cell_cache_get_key(const void *cookie_netfs_data, - void *buffer, uint16_t bufmax) -{ - const struct afs_cell *cell = cookie_netfs_data; - uint16_t klen; - - _enter("%p,%p,%u", cell, buffer, bufmax); - - klen = strlen(cell->name); - if (klen > bufmax) - return 0; - - memcpy(buffer, cell->name, klen); - return klen; -} - -/*****************************************************************************/ -/* - * set the key for the volume index entry - */ -static uint16_t afs_volume_cache_get_key(const void *cookie_netfs_data, - void *buffer, uint16_t bufmax) -{ - const struct afs_volume *volume = cookie_netfs_data; - struct { - u64 volid; - } __packed key; - - _enter("{%u},%p,%u", volume->type, buffer, bufmax); - - if (bufmax < sizeof(key)) - return 0; - - key.volid = volume->vid; - memcpy(buffer, &key, sizeof(key)); - return sizeof(key); -} - -/*****************************************************************************/ -/* - * set the key for the index entry - */ -static uint16_t afs_vnode_cache_get_key(const void *cookie_netfs_data, - void *buffer, uint16_t bufmax) -{ - const struct afs_vnode *vnode = cookie_netfs_data; - struct { - u32 vnode_id; - u32 unique; - u32 vnode_id_ext[2]; /* Allow for a 96-bit key */ - } __packed key; - - _enter("{%x,%x,%llx},%p,%u", - vnode->fid.vnode, vnode->fid.unique, vnode->status.data_version, - buffer, bufmax); - - /* Allow for a 96-bit key */ - memset(&key, 0, sizeof(key)); - key.vnode_id = vnode->fid.vnode; - key.unique = vnode->fid.unique; - key.vnode_id_ext[0] = 0; - key.vnode_id_ext[1] = 0; - - if (sizeof(key) > bufmax) - return 0; - - memcpy(buffer, &key, sizeof(key)); - return sizeof(key); -} - -/* * provide updated file attributes */ static void afs_vnode_cache_get_attr(const void *cookie_netfs_data, @@ -141,32 +55,6 @@ static void afs_vnode_cache_get_attr(const void *cookie_netfs_data, *size = vnode->status.size; } -struct afs_vnode_cache_aux { - u64 data_version; -} __packed; - -/* - * provide new auxiliary cache data - */ -static uint16_t afs_vnode_cache_get_aux(const void *cookie_netfs_data, - void *buffer, uint16_t bufmax) -{ - const struct afs_vnode *vnode = cookie_netfs_data; - struct afs_vnode_cache_aux aux; - - _enter("{%x,%x,%Lx},%p,%u", - vnode->fid.vnode, vnode->fid.unique, vnode->status.data_version, - buffer, bufmax); - - aux.data_version = vnode->status.data_version; - - if (bufmax < sizeof(aux)) - return 0; - - memcpy(buffer, &aux, sizeof(aux)); - return sizeof(aux); -} - /* * check that the auxiliary data indicates that the entry is still valid */ diff --git a/fs/afs/cell.c b/fs/afs/cell.c index 3d2c5e0e854e..0747460221cb 100644 --- a/fs/afs/cell.c +++ b/fs/afs/cell.c @@ -522,6 +522,8 @@ static int afs_activate_cell(struct afs_net *net, struct afs_cell *cell) #ifdef CONFIG_AFS_FSCACHE cell->cache = fscache_acquire_cookie(afs_cache_netfs.primary_index, &afs_cell_cache_index_def, + cell->name, strlen(cell->name), + NULL, 0, cell, true); #endif ret = afs_proc_cell_setup(net, cell); @@ -547,7 +549,7 @@ static void afs_deactivate_cell(struct afs_net *net, struct afs_cell *cell) spin_unlock(&net->proc_cells_lock); #ifdef CONFIG_AFS_FSCACHE - fscache_relinquish_cookie(cell->cache, 0); + fscache_relinquish_cookie(cell->cache, NULL, false); cell->cache = NULL; #endif diff --git a/fs/afs/inode.c b/fs/afs/inode.c index c942c79fc5f0..e499713efd2e 100644 --- a/fs/afs/inode.c +++ b/fs/afs/inode.c @@ -243,6 +243,33 @@ struct inode *afs_iget_pseudo_dir(struct super_block *sb, bool root) } /* + * Get a cache cookie for an inode. + */ +static void afs_get_inode_cache(struct afs_vnode *vnode) +{ +#ifdef CONFIG_AFS_FSCACHE + struct { + u32 vnode_id; + u32 unique; + u32 vnode_id_ext[2]; /* Allow for a 96-bit key */ + } __packed key; + struct afs_vnode_cache_aux aux; + + key.vnode_id = vnode->fid.vnode; + key.unique = vnode->fid.unique; + key.vnode_id_ext[0] = 0; + key.vnode_id_ext[1] = 0; + aux.data_version = vnode->status.data_version; + + vnode->cache = fscache_acquire_cookie(vnode->volume->cache, + &afs_vnode_cache_index_def, + &key, sizeof(key), + &aux, sizeof(aux), + vnode, true); +#endif +} + +/* * inode retrieval */ struct inode *afs_iget(struct super_block *sb, struct key *key, @@ -307,11 +334,7 @@ struct inode *afs_iget(struct super_block *sb, struct key *key, /* set up caching before mapping the status, as map-status reads the * first page of symlinks to see if they're really mountpoints */ inode->i_size = vnode->status.size; -#ifdef CONFIG_AFS_FSCACHE - vnode->cache = fscache_acquire_cookie(vnode->volume->cache, - &afs_vnode_cache_index_def, - vnode, true); -#endif + afs_get_inode_cache(vnode); ret = afs_inode_map_status(vnode, key); if (ret < 0) @@ -327,7 +350,7 @@ struct inode *afs_iget(struct super_block *sb, struct key *key, /* failure */ bad_inode: #ifdef CONFIG_AFS_FSCACHE - fscache_relinquish_cookie(vnode->cache, ret == -ENOENT); + fscache_relinquish_cookie(vnode->cache, NULL, ret == -ENOENT); vnode->cache = NULL; #endif iget_failed(inode); @@ -511,9 +534,14 @@ void afs_evict_inode(struct inode *inode) } #ifdef CONFIG_AFS_FSCACHE - fscache_relinquish_cookie(vnode->cache, - test_bit(AFS_VNODE_DELETED, &vnode->flags)); - vnode->cache = NULL; + { + struct afs_vnode_cache_aux aux; + + aux.data_version = vnode->status.data_version; + fscache_relinquish_cookie(vnode->cache, &aux, + test_bit(AFS_VNODE_DELETED, &vnode->flags)); + vnode->cache = NULL; + } #endif afs_put_permits(vnode->permit_cache); diff --git a/fs/afs/internal.h b/fs/afs/internal.h index 72217170b155..a6a1d75eee41 100644 --- a/fs/afs/internal.h +++ b/fs/afs/internal.h @@ -559,6 +559,13 @@ struct afs_fs_cursor { #define AFS_FS_CURSOR_NO_VSLEEP 0x0020 /* Set to prevent sleep on VBUSY, VOFFLINE, ... */ }; +/* + * Cache auxiliary data. + */ +struct afs_vnode_cache_aux { + u64 data_version; +} __packed; + #include <trace/events/afs.h> /*****************************************************************************/ diff --git a/fs/afs/volume.c b/fs/afs/volume.c index b517a588781f..345cb2d675d2 100644 --- a/fs/afs/volume.c +++ b/fs/afs/volume.c @@ -225,6 +225,8 @@ void afs_activate_volume(struct afs_volume *volume) #ifdef CONFIG_AFS_FSCACHE volume->cache = fscache_acquire_cookie(volume->cell->cache, &afs_volume_cache_index_def, + &volume->vid, sizeof(volume->vid), + NULL, 0, volume, true); #endif @@ -245,7 +247,7 @@ void afs_deactivate_volume(struct afs_volume *volume) write_unlock(&volume->cell->proc_lock); #ifdef CONFIG_AFS_FSCACHE - fscache_relinquish_cookie(volume->cache, + fscache_relinquish_cookie(volume->cache, NULL, test_bit(AFS_VOLUME_DELETED, &volume->flags)); volume->cache = NULL; #endif diff --git a/fs/cachefiles/interface.c b/fs/cachefiles/interface.c index 405ebc3932c2..3264dcfdc92a 100644 --- a/fs/cachefiles/interface.c +++ b/fs/cachefiles/interface.c @@ -32,7 +32,7 @@ static struct fscache_object *cachefiles_alloc_object( struct cachefiles_cache *cache; struct cachefiles_xattr *auxdata; unsigned keylen, auxlen; - void *buffer; + void *buffer, *p; char *key; cache = container_of(_cache, struct cachefiles_cache, cache); @@ -65,8 +65,12 @@ static struct fscache_object *cachefiles_alloc_object( if (!buffer) goto nomem_buffer; - keylen = cookie->def->get_key(cookie->netfs_data, buffer + 2, 512); - ASSERTCMP(keylen, <, 512); + keylen = cookie->key_len; + if (keylen <= sizeof(cookie->inline_key)) + p = cookie->inline_key; + else + p = cookie->key; + memcpy(buffer + 2, p, keylen); *(uint16_t *)buffer = keylen; ((char *)buffer)[keylen + 2] = 0; @@ -80,15 +84,17 @@ static struct fscache_object *cachefiles_alloc_object( /* get hold of the auxiliary data and prepend the object type */ auxdata = buffer; - auxlen = 0; - if (cookie->def->get_aux) { - auxlen = cookie->def->get_aux(cookie->netfs_data, - auxdata->data, 511); - ASSERTCMP(auxlen, <, 511); + auxlen = cookie->aux_len; + if (auxlen) { + if (auxlen <= sizeof(cookie->inline_aux)) + p = cookie->inline_aux; + else + p = cookie->aux; + memcpy(auxdata->data, p, auxlen); } auxdata->len = auxlen + 1; - auxdata->type = cookie->def->type; + auxdata->type = cookie->type; lookup_data->auxdata = auxdata; lookup_data->key = key; @@ -206,6 +212,7 @@ static void cachefiles_update_object(struct fscache_object *_object) struct cachefiles_cache *cache; struct fscache_cookie *cookie; const struct cred *saved_cred; + const void *aux; unsigned auxlen; _enter("{OBJ%x}", _object->debug_id); @@ -220,26 +227,29 @@ static void cachefiles_update_object(struct fscache_object *_object) } cookie = object->fscache.cookie; + auxlen = cookie->aux_len; - if (!cookie->def->get_aux) { + if (!auxlen) { fscache_unuse_cookie(_object); _leave(" [no aux]"); return; } - auxdata = kmalloc(2 + 512 + 3, cachefiles_gfp); + auxdata = kmalloc(2 + auxlen + 3, cachefiles_gfp); if (!auxdata) { fscache_unuse_cookie(_object); _leave(" [nomem]"); return; } - auxlen = cookie->def->get_aux(cookie->netfs_data, auxdata->data, 511); + aux = (auxlen <= sizeof(cookie->inline_aux)) ? + cookie->inline_aux : cookie->aux; + + memcpy(auxdata->data, aux, auxlen); fscache_unuse_cookie(_object); - ASSERTCMP(auxlen, <, 511); auxdata->len = auxlen + 1; - auxdata->type = cookie->def->type; + auxdata->type = cookie->type; cachefiles_begin_secure(cache, &saved_cred); cachefiles_update_object_xattr(object, auxdata); diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c index 5fc214256316..0daa1e3fe0df 100644 --- a/fs/cachefiles/namei.c +++ b/fs/cachefiles/namei.c @@ -30,11 +30,11 @@ < |