Commit c698dbf9 authored by Trond Myklebust's avatar Trond Myklebust

Merge branch 'fscache' of...

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

Pull fs-cache fixes from David Howells:

Can you pull these commits to fix an issue with NFS whereby caching can be
enabled on a file that is open for writing by subsequently opening it for
reading.  This can be made to crash by opening it for writing again if you're
quick enough.

The gist of the patchset is that the cookie should be acquired at inode
creation only and subsequently enabled and disabled as appropriate (which
dispenses with the backing objects when they're not needed).

The extra synchronisation that NFS does can then be dispensed with as it is
thenceforth managed by FS-Cache.

Could you send these on to Linus?

This likely will need fixing also in CIFS and 9P also once the FS-Cache
changes are upstream.  AFS and Ceph are probably safe.

* 'fscache' of git://git.kernel.org/pub/scm/linux/kernel/git/dhowells/linux-fs:
  NFS: Use i_writecount to control whether to get an fscache cookie in nfs_open()
  FS-Cache: Provide the ability to enable/disable cookies
  FS-Cache: Add use/unuse/wake cookie wrappers
parents a3f432bf f1fe29b4
...@@ -33,11 +33,12 @@ This document contains the following sections: ...@@ -33,11 +33,12 @@ This document contains the following sections:
(10) Page alloc/read/write (10) Page alloc/read/write
(11) Page uncaching (11) Page uncaching
(12) Index and data file consistency (12) Index and data file consistency
(13) Miscellaneous cookie operations (13) Cookie enablement
(14) Cookie unregistration (14) Miscellaneous cookie operations
(15) Index invalidation (15) Cookie unregistration
(16) Data file invalidation (16) Index invalidation
(17) FS-Cache specific page flags. (17) Data file invalidation
(18) FS-Cache specific page flags.
============================= =============================
...@@ -334,7 +335,8 @@ the path to the file: ...@@ -334,7 +335,8 @@ the path to the file:
struct fscache_cookie * struct fscache_cookie *
fscache_acquire_cookie(struct fscache_cookie *parent, fscache_acquire_cookie(struct fscache_cookie *parent,
const struct fscache_object_def *def, const struct fscache_object_def *def,
void *netfs_data); void *netfs_data,
bool enable);
This function creates an index entry in the index represented by parent, 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. filling in the index entry by calling the operations pointed to by def.
...@@ -350,6 +352,10 @@ object needs to be created somewhere down the hierarchy. Furthermore, an index ...@@ -350,6 +352,10 @@ object needs to be created somewhere down the hierarchy. Furthermore, an index
may be created in several different caches independently at different times. may be created in several different caches independently at different times.
This is all handled transparently, and the netfs doesn't see any of it. This is all handled transparently, and the netfs doesn't see any of it.
A cookie will be created in the disabled state if enabled is false. A cookie
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 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 entry would have a dependent inode containing a volume location index for the
volume mappings within this cell: volume mappings within this cell:
...@@ -357,7 +363,7 @@ volume mappings within this cell: ...@@ -357,7 +363,7 @@ volume mappings within this cell:
cell->cache = cell->cache =
fscache_acquire_cookie(afs_cache_netfs.primary_index, fscache_acquire_cookie(afs_cache_netfs.primary_index,
&afs_cell_cache_index_def, &afs_cell_cache_index_def,
cell); cell, true);
Then when a volume location was accessed, it would be entered into the cell's 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 index and an inode would be allocated that acts as a volume type and hash chain
...@@ -366,7 +372,7 @@ combination: ...@@ -366,7 +372,7 @@ combination:
vlocation->cache = vlocation->cache =
fscache_acquire_cookie(cell->cache, fscache_acquire_cookie(cell->cache,
&afs_vlocation_cache_index_def, &afs_vlocation_cache_index_def,
vlocation); vlocation, true);
And then a particular flavour of volume (R/O for example) could be added to 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): that index, creating another index for vnodes (AFS inode equivalents):
...@@ -374,7 +380,7 @@ that index, creating another index for vnodes (AFS inode equivalents): ...@@ -374,7 +380,7 @@ that index, creating another index for vnodes (AFS inode equivalents):
volume->cache = volume->cache =
fscache_acquire_cookie(vlocation->cache, fscache_acquire_cookie(vlocation->cache,
&afs_volume_cache_index_def, &afs_volume_cache_index_def,
volume); volume, true);
====================== ======================
...@@ -388,7 +394,7 @@ the object definition should be something other than index type. ...@@ -388,7 +394,7 @@ the object definition should be something other than index type.
vnode->cache = vnode->cache =
fscache_acquire_cookie(volume->cache, fscache_acquire_cookie(volume->cache,
&afs_vnode_cache_object_def, &afs_vnode_cache_object_def,
vnode); vnode, true);
================================= =================================
...@@ -404,7 +410,7 @@ it would be some other type of object such as a data file. ...@@ -404,7 +410,7 @@ it would be some other type of object such as a data file.
xattr->cache = xattr->cache =
fscache_acquire_cookie(vnode->cache, fscache_acquire_cookie(vnode->cache,
&afs_xattr_cache_object_def, &afs_xattr_cache_object_def,
xattr); xattr, true);
Miscellaneous objects might be used to store extended attributes or directory Miscellaneous objects might be used to store extended attributes or directory
entries for example. entries for example.
...@@ -733,6 +739,47 @@ Note that partial updates may happen automatically at other times, such as when ...@@ -733,6 +739,47 @@ Note that partial updates may happen automatically at other times, such as when
data blocks are added to a data file object. data blocks are added to a data file object.
=================
COOKIE ENABLEMENT
=================
Cookies exist in one of two states: enabled and disabled. If a cookie is
disabled, it ignores all attempts to acquire child cookies; check, update or
invalidate its state; allocate, read or write backing pages - though it is
still possible to uncache pages and relinquish the cookie.
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,
bool invalidate);
If the cookie is not already disabled, this locks the cookie against other
enable and disable ops, marks the cookie as being disabled, discards or
invalidates any backing objects and waits for cessation of activity on any
associated object before unlocking the cookie.
All possible failures are handled internally. The caller should consider
calling fscache_uncache_all_inode_pages() afterwards to make sure all page
markings are cleared up.
Cookies can be enabled or reenabled with:
void fscache_enable_cookie(struct fscache_cookie *cookie,
bool (*can_enable)(void *data),
void *data)
If the cookie is not already enabled, this locks the cookie against other
enable and disable ops, invokes can_enable() and, if the cookie is not an index
cookie, will begin the procedure of acquiring backing objects.
The optional can_enable() function is passed the data argument and returns a
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.
=============================== ===============================
MISCELLANEOUS COOKIE OPERATIONS MISCELLANEOUS COOKIE OPERATIONS
=============================== ===============================
...@@ -778,7 +825,7 @@ COOKIE UNREGISTRATION ...@@ -778,7 +825,7 @@ COOKIE UNREGISTRATION
To get rid of a cookie, this function should be called. To get rid of a cookie, this function should be called.
void fscache_relinquish_cookie(struct fscache_cookie *cookie, void fscache_relinquish_cookie(struct fscache_cookie *cookie,
int retire); bool retire);
If retire is non-zero, then the object will be marked for recycling, and all If retire is non-zero, then the object will be marked for recycling, and all
copies of it will be removed from all active caches in which it is present. copies of it will be removed from all active caches in which it is present.
......
...@@ -90,7 +90,7 @@ void v9fs_cache_session_get_cookie(struct v9fs_session_info *v9ses) ...@@ -90,7 +90,7 @@ void v9fs_cache_session_get_cookie(struct v9fs_session_info *v9ses)
v9ses->fscache = fscache_acquire_cookie(v9fs_cache_netfs.primary_index, v9ses->fscache = fscache_acquire_cookie(v9fs_cache_netfs.primary_index,
&v9fs_cache_session_index_def, &v9fs_cache_session_index_def,
v9ses); v9ses, true);
p9_debug(P9_DEBUG_FSC, "session %p get cookie %p\n", p9_debug(P9_DEBUG_FSC, "session %p get cookie %p\n",
v9ses, v9ses->fscache); v9ses, v9ses->fscache);
} }
...@@ -204,7 +204,7 @@ void v9fs_cache_inode_get_cookie(struct inode *inode) ...@@ -204,7 +204,7 @@ void v9fs_cache_inode_get_cookie(struct inode *inode)
v9ses = v9fs_inode2v9ses(inode); v9ses = v9fs_inode2v9ses(inode);
v9inode->fscache = fscache_acquire_cookie(v9ses->fscache, v9inode->fscache = fscache_acquire_cookie(v9ses->fscache,
&v9fs_cache_inode_index_def, &v9fs_cache_inode_index_def,
v9inode); v9inode, true);
p9_debug(P9_DEBUG_FSC, "inode %p get cookie %p\n", p9_debug(P9_DEBUG_FSC, "inode %p get cookie %p\n",
inode, v9inode->fscache); inode, v9inode->fscache);
...@@ -271,7 +271,7 @@ void v9fs_cache_inode_reset_cookie(struct inode *inode) ...@@ -271,7 +271,7 @@ void v9fs_cache_inode_reset_cookie(struct inode *inode)
v9ses = v9fs_inode2v9ses(inode); v9ses = v9fs_inode2v9ses(inode);
v9inode->fscache = fscache_acquire_cookie(v9ses->fscache, v9inode->fscache = fscache_acquire_cookie(v9ses->fscache,
&v9fs_cache_inode_index_def, &v9fs_cache_inode_index_def,
v9inode); v9inode, true);
p9_debug(P9_DEBUG_FSC, "inode %p revalidating cookie old %p new %p\n", p9_debug(P9_DEBUG_FSC, "inode %p revalidating cookie old %p new %p\n",
inode, old, v9inode->fscache); inode, old, v9inode->fscache);
......
...@@ -179,7 +179,7 @@ struct afs_cell *afs_cell_create(const char *name, unsigned namesz, ...@@ -179,7 +179,7 @@ struct afs_cell *afs_cell_create(const char *name, unsigned namesz,
/* put it up for caching (this never returns an error) */ /* put it up for caching (this never returns an error) */
cell->cache = fscache_acquire_cookie(afs_cache_netfs.primary_index, cell->cache = fscache_acquire_cookie(afs_cache_netfs.primary_index,
&afs_cell_cache_index_def, &afs_cell_cache_index_def,
cell); cell, true);
#endif #endif
/* add to the cell lists */ /* add to the cell lists */
......
...@@ -259,7 +259,7 @@ struct inode *afs_iget(struct super_block *sb, struct key *key, ...@@ -259,7 +259,7 @@ struct inode *afs_iget(struct super_block *sb, struct key *key,
#ifdef CONFIG_AFS_FSCACHE #ifdef CONFIG_AFS_FSCACHE
vnode->cache = fscache_acquire_cookie(vnode->volume->cache, vnode->cache = fscache_acquire_cookie(vnode->volume->cache,
&afs_vnode_cache_index_def, &afs_vnode_cache_index_def,
vnode); vnode, true);
#endif #endif
ret = afs_inode_map_status(vnode, key); ret = afs_inode_map_status(vnode, key);
......
...@@ -308,7 +308,8 @@ static int afs_vlocation_fill_in_record(struct afs_vlocation *vl, ...@@ -308,7 +308,8 @@ static int afs_vlocation_fill_in_record(struct afs_vlocation *vl,
/* see if we have an in-cache copy (will set vl->valid if there is) */ /* see if we have an in-cache copy (will set vl->valid if there is) */
#ifdef CONFIG_AFS_FSCACHE #ifdef CONFIG_AFS_FSCACHE
vl->cache = fscache_acquire_cookie(vl->cell->cache, vl->cache = fscache_acquire_cookie(vl->cell->cache,
&afs_vlocation_cache_index_def, vl); &afs_vlocation_cache_index_def, vl,
true);
#endif #endif
if (vl->valid) { if (vl->valid) {
......
...@@ -131,7 +131,7 @@ struct afs_volume *afs_volume_lookup(struct afs_mount_params *params) ...@@ -131,7 +131,7 @@ struct afs_volume *afs_volume_lookup(struct afs_mount_params *params)
#ifdef CONFIG_AFS_FSCACHE #ifdef CONFIG_AFS_FSCACHE
volume->cache = fscache_acquire_cookie(vlocation->cache, volume->cache = fscache_acquire_cookie(vlocation->cache,
&afs_volume_cache_index_def, &afs_volume_cache_index_def,
volume); volume, true);
#endif #endif
afs_get_vlocation(vlocation); afs_get_vlocation(vlocation);
volume->vlocation = vlocation; volume->vlocation = vlocation;
......
...@@ -270,7 +270,7 @@ static void cachefiles_drop_object(struct fscache_object *_object) ...@@ -270,7 +270,7 @@ static void cachefiles_drop_object(struct fscache_object *_object)
#endif #endif
/* delete retired objects */ /* delete retired objects */
if (test_bit(FSCACHE_COOKIE_RETIRED, &object->fscache.cookie->flags) && if (test_bit(FSCACHE_OBJECT_RETIRED, &object->fscache.flags) &&
_object != cache->cache.fsdef _object != cache->cache.fsdef
) { ) {
_debug("- retire object OBJ%x", object->fscache.debug_id); _debug("- retire object OBJ%x", object->fscache.debug_id);
......
...@@ -68,7 +68,7 @@ int ceph_fscache_register_fs(struct ceph_fs_client* fsc) ...@@ -68,7 +68,7 @@ int ceph_fscache_register_fs(struct ceph_fs_client* fsc)
{ {
fsc->fscache = fscache_acquire_cookie(ceph_cache_netfs.primary_index, fsc->fscache = fscache_acquire_cookie(ceph_cache_netfs.primary_index,
&ceph_fscache_fsid_object_def, &ceph_fscache_fsid_object_def,
fsc); fsc, true);
if (fsc->fscache == NULL) { if (fsc->fscache == NULL) {
pr_err("Unable to resgister fsid: %p fscache cookie", fsc); pr_err("Unable to resgister fsid: %p fscache cookie", fsc);
...@@ -204,7 +204,7 @@ void ceph_fscache_register_inode_cookie(struct ceph_fs_client* fsc, ...@@ -204,7 +204,7 @@ void ceph_fscache_register_inode_cookie(struct ceph_fs_client* fsc,
ci->fscache = fscache_acquire_cookie(fsc->fscache, ci->fscache = fscache_acquire_cookie(fsc->fscache,
&ceph_fscache_inode_object_def, &ceph_fscache_inode_object_def,
ci); ci, true);
done: done:
mutex_unlock(&inode->i_mutex); mutex_unlock(&inode->i_mutex);
......
...@@ -27,7 +27,7 @@ void cifs_fscache_get_client_cookie(struct TCP_Server_Info *server) ...@@ -27,7 +27,7 @@ void cifs_fscache_get_client_cookie(struct TCP_Server_Info *server)
{ {
server->fscache = server->fscache =
fscache_acquire_cookie(cifs_fscache_netfs.primary_index, fscache_acquire_cookie(cifs_fscache_netfs.primary_index,
&cifs_fscache_server_index_def, server); &cifs_fscache_server_index_def, server, true);
cifs_dbg(FYI, "%s: (0x%p/0x%p)\n", cifs_dbg(FYI, "%s: (0x%p/0x%p)\n",
__func__, server, server->fscache); __func__, server, server->fscache);
} }
...@@ -46,7 +46,7 @@ void cifs_fscache_get_super_cookie(struct cifs_tcon *tcon) ...@@ -46,7 +46,7 @@ void cifs_fscache_get_super_cookie(struct cifs_tcon *tcon)
tcon->fscache = tcon->fscache =
fscache_acquire_cookie(server->fscache, fscache_acquire_cookie(server->fscache,
&cifs_fscache_super_index_def, tcon); &cifs_fscache_super_index_def, tcon, true);
cifs_dbg(FYI, "%s: (0x%p/0x%p)\n", cifs_dbg(FYI, "%s: (0x%p/0x%p)\n",
__func__, server->fscache, tcon->fscache); __func__, server->fscache, tcon->fscache);
} }
...@@ -69,7 +69,7 @@ static void cifs_fscache_enable_inode_cookie(struct inode *inode) ...@@ -69,7 +69,7 @@ static void cifs_fscache_enable_inode_cookie(struct inode *inode)
if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_FSCACHE) { if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_FSCACHE) {
cifsi->fscache = fscache_acquire_cookie(tcon->fscache, cifsi->fscache = fscache_acquire_cookie(tcon->fscache,
&cifs_fscache_inode_object_def, cifsi); &cifs_fscache_inode_object_def, cifsi, true);
cifs_dbg(FYI, "%s: got FH cookie (0x%p/0x%p)\n", cifs_dbg(FYI, "%s: got FH cookie (0x%p/0x%p)\n",
__func__, tcon->fscache, cifsi->fscache); __func__, tcon->fscache, cifsi->fscache);
} }
...@@ -119,7 +119,7 @@ void cifs_fscache_reset_inode_cookie(struct inode *inode) ...@@ -119,7 +119,7 @@ void cifs_fscache_reset_inode_cookie(struct inode *inode)
cifsi->fscache = fscache_acquire_cookie( cifsi->fscache = fscache_acquire_cookie(
cifs_sb_master_tcon(cifs_sb)->fscache, cifs_sb_master_tcon(cifs_sb)->fscache,
&cifs_fscache_inode_object_def, &cifs_fscache_inode_object_def,
cifsi); cifsi, true);
cifs_dbg(FYI, "%s: new cookie 0x%p oldcookie 0x%p\n", cifs_dbg(FYI, "%s: new cookie 0x%p oldcookie 0x%p\n",
__func__, cifsi->fscache, old); __func__, cifsi->fscache, old);
} }
......
...@@ -58,15 +58,16 @@ void fscache_cookie_init_once(void *_cookie) ...@@ -58,15 +58,16 @@ void fscache_cookie_init_once(void *_cookie)
struct fscache_cookie *__fscache_acquire_cookie( struct fscache_cookie *__fscache_acquire_cookie(
struct fscache_cookie *parent, struct fscache_cookie *parent,
const struct fscache_cookie_def *def, const struct fscache_cookie_def *def,
void *netfs_data) void *netfs_data,
bool enable)
{ {
struct fscache_cookie *cookie; struct fscache_cookie *cookie;
BUG_ON(!def); BUG_ON(!def);
_enter("{%s},{%s},%p", _enter("{%s},{%s},%p,%u",
parent ? (char *) parent->def->name : "<no-parent>", parent ? (char *) parent->def->name : "<no-parent>",
def->name, netfs_data); def->name, netfs_data, enable);
fscache_stat(&fscache_n_acquires); fscache_stat(&fscache_n_acquires);
...@@ -106,7 +107,7 @@ struct fscache_cookie *__fscache_acquire_cookie( ...@@ -106,7 +107,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
cookie->def = def; cookie->def = def;
cookie->parent = parent; cookie->parent = parent;
cookie->netfs_data = netfs_data; cookie->netfs_data = netfs_data;
cookie->flags = 0; cookie->flags = (1 << FSCACHE_COOKIE_NO_DATA_YET);
/* radix tree insertion won't use the preallocation pool unless it's /* radix tree insertion won't use the preallocation pool unless it's
* told it may not wait */ * told it may not wait */
...@@ -124,17 +125,23 @@ struct fscache_cookie *__fscache_acquire_cookie( ...@@ -124,17 +125,23 @@ struct fscache_cookie *__fscache_acquire_cookie(
break; break;
} }
/* if the object is an index then we need do nothing more here - we if (enable) {
* create indices on disk when we need them as an index may exist in /* if the object is an index then we need do nothing more here
* multiple caches */ * - we create indices on disk when we need them as an index
* may exist in multiple caches */
if (cookie->def->type != FSCACHE_COOKIE_TYPE_INDEX) { if (cookie->def->type != FSCACHE_COOKIE_TYPE_INDEX) {
if (fscache_acquire_non_index_cookie(cookie) < 0) { if (fscache_acquire_non_index_cookie(cookie) == 0) {
set_bit(FSCACHE_COOKIE_ENABLED, &cookie->flags);
} else {
atomic_dec(&parent->n_children); atomic_dec(&parent->n_children);
__fscache_cookie_put(cookie); __fscache_cookie_put(cookie);
fscache_stat(&fscache_n_acquires_nobufs); fscache_stat(&fscache_n_acquires_nobufs);
_leave(" = NULL"); _leave(" = NULL");
return NULL; return NULL;
} }
} else {
set_bit(FSCACHE_COOKIE_ENABLED, &cookie->flags);
}
} }
fscache_stat(&fscache_n_acquires_ok); fscache_stat(&fscache_n_acquires_ok);
...@@ -143,6 +150,39 @@ struct fscache_cookie *__fscache_acquire_cookie( ...@@ -143,6 +150,39 @@ struct fscache_cookie *__fscache_acquire_cookie(
} }
EXPORT_SYMBOL(__fscache_acquire_cookie); EXPORT_SYMBOL(__fscache_acquire_cookie);
/*
* Enable a cookie to permit it to accept new operations.
*/
void __fscache_enable_cookie(struct fscache_cookie *cookie,
bool (*can_enable)(void *data),
void *data)
{
_enter("%p", cookie);
wait_on_bit_lock(&cookie->flags, FSCACHE_COOKIE_ENABLEMENT_LOCK,
fscache_wait_bit, TASK_UNINTERRUPTIBLE);
if (test_bit(FSCACHE_COOKIE_ENABLED, &cookie->flags))
goto out_unlock;
if (can_enable && !can_enable(data)) {
/* The netfs decided it didn't want to enable after all */
} else if (cookie->def->type != FSCACHE_COOKIE_TYPE_INDEX) {
/* Wait for outstanding disablement to complete */
__fscache_wait_on_invalidate(cookie);
if (fscache_acquire_non_index_cookie(cookie) == 0)
set_bit(FSCACHE_COOKIE_ENABLED, &cookie->flags);
} else {
set_bit(FSCACHE_COOKIE_ENABLED, &cookie->flags);
}
out_unlock:
clear_bit_unlock(FSCACHE_COOKIE_ENABLEMENT_LOCK, &cookie->flags);
wake_up_bit(&cookie->flags, FSCACHE_COOKIE_ENABLEMENT_LOCK);
}
EXPORT_SYMBOL(__fscache_enable_cookie);
/* /*
* acquire a non-index cookie * acquire a non-index cookie
* - this must make sure the index chain is instantiated and instantiate the * - this must make sure the index chain is instantiated and instantiate the
...@@ -157,7 +197,7 @@ static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie) ...@@ -157,7 +197,7 @@ static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie)
_enter(""); _enter("");
cookie->flags = 1 << FSCACHE_COOKIE_UNAVAILABLE; set_bit(FSCACHE_COOKIE_UNAVAILABLE, &cookie->flags);
/* now we need to see whether the backing objects for this cookie yet /* now we need to see whether the backing objects for this cookie yet
* exist, if not there'll be nothing to search */ * exist, if not there'll be nothing to search */
...@@ -180,9 +220,7 @@ static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie) ...@@ -180,9 +220,7 @@ static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie)
_debug("cache %s", cache->tag->name); _debug("cache %s", cache->tag->name);
cookie->flags = set_bit(FSCACHE_COOKIE_LOOKING_UP, &cookie->flags);
(1 << FSCACHE_COOKIE_LOOKING_UP) |
(1 << FSCACHE_COOKIE_NO_DATA_YET);
/* ask the cache to allocate objects for this cookie and its parent /* ask the cache to allocate objects for this cookie and its parent
* chain */ * chain */
...@@ -398,7 +436,8 @@ void __fscache_invalidate(struct fscache_cookie *cookie) ...@@ -398,7 +436,8 @@ void __fscache_invalidate(struct fscache_cookie *cookie)
if (!hlist_empty(&cookie->backing_objects)) { if (!hlist_empty(&cookie->backing_objects)) {
spin_lock(&cookie->lock); spin_lock(&cookie->lock);
if (!hlist_empty(&cookie->backing_objects) && if (fscache_cookie_enabled(cookie) &&
!hlist_empty(&cookie->backing_objects) &&
!test_and_set_bit(FSCACHE_COOKIE_INVALIDATING, !test_and_set_bit(FSCACHE_COOKIE_INVALIDATING,
&cookie->flags)) { &cookie->flags)) {
object = hlist_entry(cookie->backing_objects.first, object = hlist_entry(cookie->backing_objects.first,
...@@ -452,11 +491,15 @@ void __fscache_update_cookie(struct fscache_cookie *cookie) ...@@ -452,11 +491,15 @@ void __fscache_update_cookie(struct fscache_cookie *cookie)
spin_lock(&cookie->lock); spin_lock(&cookie->lock);
/* update the index entry on disk in each cache backing this cookie */ if (fscache_cookie_enabled(cookie)) {
/* update the index entry on disk in each cache backing this
* cookie.
*/
hlist_for_each_entry(object, hlist_for_each_entry(object,
&cookie->backing_objects, cookie_link) { &cookie->backing_objects, cookie_link) {
fscache_raise_event(object, FSCACHE_OBJECT_EV_UPDATE); fscache_raise_event(object, FSCACHE_OBJECT_EV_UPDATE);
} }
}
spin_unlock(&cookie->lock); spin_unlock(&cookie->lock);
_leave(""); _leave("");
...@@ -464,28 +507,14 @@ void __fscache_update_cookie(struct fscache_cookie *cookie) ...@@ -464,28 +507,14 @@ void __fscache_update_cookie(struct fscache_cookie *cookie)
EXPORT_SYMBOL(__fscache_update_cookie); EXPORT_SYMBOL(__fscache_update_cookie);
/* /*
* release a cookie back to the cache * Disable a cookie to stop it from accepting new requests from the netfs.
* - the object will be marked as recyclable on disk if retire is true
* - all dependents of this cookie must have already been unregistered
* (indices/files/pages)
*/ */
void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire) void __fscache_disable_cookie(struct fscache_cookie *cookie, bool invalidate)
{ {
struct fscache_object *object; struct fscache_object *object;
bool awaken = false;
fscache_stat(&fscache_n_relinquishes); _enter("%p,%u", cookie, invalidate);
if (retire)
fscache_stat(&fscache_n_relinquishes_retire);
if (!cookie) {
fscache_stat(&fscache_n_relinquishes_null);
_leave(" [no cookie]");
return;
}
_enter("%p{%s,%p,%d},%d",
cookie, cookie->def->name, cookie->netfs_data,
atomic_read(&cookie->n_active), retire);
ASSERTCMP(atomic_read(&cookie->n_active), >, 0); ASSERTCMP(atomic_read(&cookie->n_active), >, 0);
...@@ -495,24 +524,82 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire) ...@@ -495,24 +524,82 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
BUG(); BUG();
} }
/* No further netfs-accessing operations on this cookie permitted */ wait_on_bit_lock(&cookie->flags, FSCACHE_COOKIE_ENABLEMENT_LOCK,
set_bit(FSCACHE_COOKIE_RELINQUISHED, &cookie->flags); fscache_wait_bit, TASK_UNINTERRUPTIBLE);
if (retire) if (!test_and_clear_bit(FSCACHE_COOKIE_ENABLED, &cookie->flags))
set_bit(FSCACHE_COOKIE_RETIRED, &cookie->flags); goto out_unlock_enable;
/* If the cookie is being invalidated, wait for that to complete first
* so that we can reuse the flag.
*/
__fscache_wait_on_invalidate(cookie);
/* Dispose of the backing objects */
set_bit(FSCACHE_COOKIE_INVALIDATING, &cookie->flags);
spin_lock(&cookie->lock); spin_lock(&cookie->lock);
if (!hlist_empty(&cookie->backing_objects)) {
hlist_for_each_entry(object, &cookie->backing_objects, cookie_link) { hlist_for_each_entry(object, &cookie->backing_objects, cookie_link) {
if (invalidate)
set_bit(FSCACHE_OBJECT_RETIRED, &object->flags);
fscache_raise_event(object, FSCACHE_OBJECT_EV_KILL); fscache_raise_event(object, FSCACHE_OBJECT_EV_KILL);
} }
} else {
if (test_and_clear_bit(FSCACHE_COOKIE_INVALIDATING, &cookie->flags))
awaken = true;
}
spin_unlock(&cookie->lock); spin_unlock(&cookie->lock);
if (awaken)
wake_up_bit(&cookie->flags, FSCACHE_COOKIE_INVALIDATING);
/* Wait for cessation of activity requiring access to the netfs (when /* Wait for cessation of activity requiring access to the netfs (when
* n_active reaches 0). * n_active reaches 0). This makes sure outstanding reads and writes
* have completed.
*/ */
if (!atomic_dec_and_test(&cookie->n_active)) if (!atomic_dec_and_test(&cookie->n_active))
wait_on_atomic_t(&cookie->n_active, fscache_wait_atomic_t, wait_on_atomic_t(&cookie->n_active, fscache_wait_atomic_t,
TASK_UNINTERRUPTIBLE); TASK_UNINTERRUPTIBLE);
/* Reset the cookie state if it wasn't relinquished */
if (!test_bit(FSCACHE_COOKIE_RELINQUISHED, &cookie->flags)) {
atomic_inc(&cookie->n_active);
set_bit(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
}
out_unlock_enable:
clear_bit_unlock(FSCACHE_COOKIE_ENABLEMENT_LOCK, &cookie->flags);
wake_up_bit(&cookie->flags, FSCACHE_COOKIE_ENABLEMENT_LOCK);
_leave("");
}
EXPORT_SYMBOL(__fscache_disable_cookie);
/*
* release a cookie back to the cache
* - the object will be marked as recyclable on disk if retire is true
* - all dependents of this cookie must have already been unregistered
* (indices/files/pages)
*/
void __fscache_relinquish_cookie(struct fscache_cookie *cookie, bool retire)
{
fscache_stat(&fscache_n_relinquishes);
if (retire)
fscache_stat(&fscache_n_relinquishes_retire);
if (!cookie) {
fscache_stat(&fscache_n_relinquishes_null);
_leave(" [no cookie]");
return;
}
_enter("%p{%s,%p,%d},%d",
cookie, cookie->def->name, cookie->netfs_data,
atomic_read(&cookie->n_active), retire);
/* No further netfs-accessing operations on this cookie permitted */
set_bit(FSCACHE_COOKIE_RELINQUISHED, &cookie->flags);
__fscache_disable_cookie(cookie, retire);
/* Clear pointers back to the netfs */ /* Clear pointers back to the netfs */
cookie->netfs_data = NULL; cookie->netfs_data = NULL;
cookie->def = NULL; cookie->def = NULL;
...@@ -568,6 +655,7 @@ int __fscache_check_consistency(struct fscache_cookie *cookie) ...@@ -568,6 +655,7 @@ int __fscache_check_consistency(struct fscache_cookie *cookie)
{ {
struct fscache_operation *op; struct fscache_operation *op;
struct fscache_object *object; struct fscache_object *object;
bool wake_cookie = false;
int ret; int ret;
_enter("%p,", cookie); _enter("%p,", cookie);
...@@ -591,7 +679,8 @@ int __fscache_check_consistency(struct fscache_cookie *cookie) ...@@ -591,7 +679,8 @@ int __fscache_check_consistency(struct fscache_cookie *cookie)
spin_lock(&cookie->lock); spin_lock(&cookie->lock);
if (hlist_empty(&cookie->backing_objects)) if (!fscache_cookie_enabled(cookie) ||
hlist_empty(&cookie->backing_objects))
goto inconsistent; goto inconsistent;
object = hlist_entry(cookie->backing_objects.first, object = hlist_entry(cookie->backing_objects.first,
struct fscache_object, cookie_link); struct fscache_object, cookie_link);
...@@ -600,7 +689,7 @@ int __fscache_check_consistency(struct fscache_cookie *cookie) ...@@ -600,7 +689,7 @@ int __fscache_check_consistency(struct fscache_cookie *cookie)
op->debug_id = atomic_inc_return(&fscache_op_debug_id); op->debug_id = atomic_inc_return(&fscache_op_debug_id);
atomic_inc(&cookie->n_active); __fscache_use_cookie(cookie);
if (fscache_submit_op(object, op) < 0) if (fscache_submit_op(object, op) < 0)
goto submit_failed; goto submit_failed;
...@@ -622,9 +711,11 @@ int __fscache_check_consistency(struct fscache_cookie *cookie) ...@@ -622,9 +711,11 @@ int __fscache_check_consistency(struct fscache_cookie *cookie)
return ret; return ret;
submit_failed: submit_failed:
atomic_dec(&cookie->n_active); wake_cookie = __fscache_unuse_cookie(cookie);
inconsistent: inconsistent:
spin_unlock(&cookie->lock); spin_unlock(&cookie->lock);
if (wake_cookie)
__fscache_wake_unused_cookie(cookie);
kfree(op); kfree(op);
_leave(" = -ESTALE"); _leave(" = -ESTALE");
return -ESTALE; return -ESTALE;
......
...@@ -59,6 +59,7 @@ struct fscache_cookie fscache_fsdef_index = { ...@@ -59,6 +59,7 @@ struct fscache_cookie fscache_fsdef_index = {
.lock = __SPIN_LOCK_UNLOCKED(fscache_fsdef_index.lock), .lock = __SPIN_LOCK_UNLOCKED(fscache_fsdef_index.lock),
.backing_objects = HLIST_HEAD_INIT, .backing_objects = HLIST_HEAD_INIT,
.def = &fscache_fsdef_index_def, .def = &fscache_fsdef_index_def,
.flags = 1 << FSCACHE_COOKIE_ENABLED,
}; };
EXPORT_SYMBOL(fscache_fsdef_index); EXPORT_SYMBOL(fscache_fsdef_index);
......
...@@ -45,6 +45,7 @@ int __fscache_register_netfs(struct fscache_netfs *netfs) ...@@ -45,6 +45,7 @@ int __fscache_register_netfs(struct fscache_netfs *netfs)
netfs->primary_index->def = &fscache_fsdef_netfs_def; netfs->primary_index->def = &fscache_fsdef_netfs_def;
netfs->primary_index->parent = &fscache_fsdef_index; netfs->primary_index->parent = &fscache_fsdef_index;
netfs->primary_index->netfs_data = netfs; netfs->primary_index->netfs_data = netfs;
netfs->primary_index->flags = 1 << FSCACHE_COOKIE_ENABLED;
atomic_inc(&netfs->primary_index->parent->usage); atomic_inc(&netfs->primary_index->parent->usage);
atomic_inc(&netfs->primary_index->parent->n_children); atomic_inc(&netfs->primary_index->parent->n_children);
......
...@@ -495,6 +495,7 @@ void fscache_object_lookup_negative(struct fscache_object *object) ...@@ -495,6 +495,7 @@ void fscache_object_lookup_negative(struct fscache_object *object)
* returning ENODATA. * returning ENODATA.
*/ */
set_bit(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags); set_bit(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
clear_bit(FSCACHE_COOKIE_UNAVAILABLE, &cookie->flags);
_debug("wake up lookup %p", &cookie->flags); _debug("wake up lookup %p", &cookie->flags);
clear_bit_unlock(FSCACHE_COOKIE_LOOKING_UP, &cookie->flags); clear_bit_unlock(FSCACHE_COOKIE_LOOKING_UP, &cookie->flags);
...@@ -527,6 +528,7 @@ void fscache_obtained_object(struct fscache_object *object) ...@@ -527,6 +528,7 @@ void fscache_obtained_object(struct fscache_object *object)
/* We do (presumably) have data */ /* We do (presumably) have data */
clear_bit_unlock(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags); clear_bit_unlock(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
clear_bit(FSCACHE_COOKIE_UNAVAILABLE, &cookie->flags);
/* Allow write requests to begin stacking up and read requests /* Allow write requests to begin stacking up and read requests
* to begin shovelling data. * to begin shovelling data.
...@@ -679,7 +681,8 @@ static const struct fscache_state *fscache_drop_object(struct fscache_object *ob ...@@ -679,7 +681,8 @@ static const struct fscache_state *fscache_drop_object(struct fscache_object *ob
*/ */
spin_lock(&cookie->lock); spin_lock(&cookie->lock);
hlist_del_init(&object->cookie_link); hlist_del_init(&object->cookie_link);
if (test_and_clear_bit(FSCACHE_COOKIE_INVALIDATING, &cookie->flags)) if (hlist_empty(&cookie->backing_objects) &&
test_and_clear_bit(FSCACHE_COOKIE_INVALIDATING, &cookie->flags))
awaken = true; awaken = true;
spin_unlock(&cookie->lock); spin_unlock(&cookie->lock);
...@@ -927,7 +930,7 @@ static const struct fscache_state *_fscache_invalidate_object(struct fscache_obj ...@@ -927,7 +930,7 @@ static const struct fscache_state *_fscache_invalidate_object(struct fscache_obj
*/ */
if (!fscache_use_cookie(object)) { if (!fscache_use_cookie(object)) {
ASSERT(object->cookie->stores.rnode == NULL); ASSERT(object->cookie->stores.rnode == NULL);
set_bit(FSCACHE_COOKIE_RETIRED, &cookie->flags); set_bit(FSCACHE_OBJECT_RETIRED, &object->flags);
_leave(" [no cookie]"); _leave(" [no cookie]");
return transit_to(KILL_OBJECT); return transit_to(KILL_OBJECT);
} }
......
...@@ -163,12 +163,10 @@ static void fscache_attr_changed_op(struct fscache_operation *op) ...@@ -163,12 +163,10 @@ static void fscache_attr_changed_op(struct fscache_operation *op)
fscache_stat(&fscache_n_attr_changed_calls); fscache_stat(&fscache_n_attr_changed_calls);
if (fscache_object_is_active(object) && if (fscache_object_is_active(object)) {
fscache_use_cookie(object)) {
fscache_stat(&fscache_n_cop_attr_changed); fscache_stat(&fscache_n_cop_attr_changed);
ret = object->cache->ops->attr_changed(object); ret = object->cache->ops->attr_changed(object);
fscache_stat_d(&fscache_n_cop_attr_changed); fscache_stat_d(&fscache_n_cop_attr_changed);
fscache_unuse_cookie(object);
if (ret < 0) if (ret < 0)
fscache_abort_object(object); fscache_abort_object(object);
} }
...@@ -184,6 +182,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie) ...@@ -184,6 +182,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
{ {
struct fscache_operation *op; struct fscache_operation *op;
struct fscache_object *object; struct fscache_object *object;
bool wake_cookie;
_enter("%p", cookie); _enter("%p", cookie);
...@@ -199,15 +198,19 @@ int __fscache_attr_changed(struct fscache_cookie *cookie) ...@@ -199,15 +198,19 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
} }
fscache_operation_init(op, fscache_attr_changed_op, NULL); fscache_operation_init(op, fscache_attr_changed_op, NULL);
op->flags = FSCACHE_OP_ASYNC | (1 << FSCACHE_OP_EXCLUSIVE); op->flags = FSCACHE_OP_ASYNC |
(1 << FSCACHE_OP_EXCLUSIVE) |
(1 << FSCACHE_OP_UNUSE_COOKIE);
spin_lock(&cookie->lock); spin_lock(&cookie->lock);
if (hlist_empty(&cookie->backing_objects)) if (!fscache_cookie_enabled(cookie) ||
hlist_empty(&cookie->backing_objects))
goto nobufs; goto nobufs;
object = hlist_entry(cookie->backing_objects.first, object = hlist_entry(cookie->backing_objects.first,
struct fscache_object, cookie_link); struct fscache_object, cookie_link);
__fscache_use_cookie(cookie);
if (fscache_submit_exclusive_op(object, op) < 0) if (fscache_submit_exclusive_op(object, op) < 0)
goto nobufs; goto nobufs;
spin_unlock(&cookie->lock); spin_unlock(&cookie->lock);
...@@ -217,8 +220,11 @@ int __fscache_attr_changed(struct fscache_cookie *cookie) ...@@ -217,8 +220,11 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
return 0; return 0;
nobufs: nobufs:
wake_cookie = __fscache_unuse_cookie(cookie);
spin_unlock(&cookie->lock); spin_unlock(&cookie->lock);
kfree(op); kfree(op);
if (wake_cookie)
__fscache_wake_unused_cookie(cookie);
fscache_stat(&fscache_n_attr_changed_nobufs); fscache_stat(&fscache_n_attr_changed_nobufs);
_leave(" = %d", -ENOBUFS); _leave(" = %d", -ENOBUFS);
return -ENOBUFS; return -ENOBUFS;
...@@ -263,7 +269,6 @@ static struct fscache_retrieval *fscache_alloc_retrieval( ...@@ -263,7 +269,6 @@ static struct fscache_retrieval *fscache_alloc_retrieval(
} }
fscache_operation_init(&op->op, NULL, fscache_release_retrieval_op); fscache_operation_init(&op->op, NULL, fscache_release_retrieval_op);
atomic_inc(&cookie->n_active);
op->op.flags = FSCACHE_OP_MYTHREAD | op->op.flags = FSCACHE_OP_MYTHREAD |
(1UL << FSCACHE_OP_WAITING) | (1UL << FSCACHE_OP_WAITING) |
(1UL << FSCACHE_OP_UNUSE_COOKIE); (1UL << FSCACHE_OP_UNUSE_COOKIE);
...@@ -384,6 +389,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie, ...@@ -384,6 +389,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
{ {
struct fscache_retrieval *op; struct fscache_retrieval *op;
struct fscache_object *object; struct fscache_object *object;
bool wake_cookie = false;
int ret; int ret;
_enter("%p,%p,,,", cookie, page); _enter("%p,%p,,,", cookie, page);
...@@ -405,7 +411,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie, ...@@ -405,7 +411,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
return -ERESTARTSYS; return -ERESTARTSYS;
op = fscache_alloc_retrieval(cookie, page->mapping, op = fscache_alloc_retrieval(cookie, page->mapping,
end_io_func,context); end_io_func, context);
if (!op) { if (!op) {
_leave(" = -ENOMEM"); _leave(" = -ENOMEM");
return -ENOMEM; return -ENOMEM;
...@@ -414,13 +420,15 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie, ...@@ -414,13 +420,15 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
spin_lock(&cookie->lock); spin_lock(&cookie->lock);
if (hlist_empty(&cookie->backing_objects)) if (!fscache_cookie_enabled(cookie) ||
hlist_empty(&cookie->backing_objects))
goto nobufs_unlock; goto nobufs_unlock;
object = hlist_entry(cookie->backing_objects.first, object = hlist_entry(cookie->backing_objects.first,
struct fscache_object, cookie_link); struct fscache_object, cookie_link);
ASSERT(test_bit(FSCACHE_OBJECT_IS_LOOKED_UP, &object->flags)); ASSERT(test_bit(FSCACHE_OBJECT_IS_LOOKED_UP, &object->flags));
__fscache_use_cookie(cookie);
atomic_inc(&object->n_reads); atomic_inc(&object->n_reads);
__set_bit(FSCACHE_OP_DEC_READ_CNT, &op->op.flags); __set_bit(FSCACHE_OP_DEC_READ_CNT, &op->op.flags);
...@@ -475,9 +483,11 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie, ...@@ -475,9 +483,11 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
nobufs_unlock_dec: nobufs_unlock_dec:
atomic_dec(&object->n_reads); atomic_dec(&object->n_reads);
wake_cookie = __fscache_unuse_cookie(cookie);
nobufs_unlock: nobufs_unlock:
spin_unlock(&cookie->lock); spin_unlock(&cookie->lock);
atomic_dec(&cookie->n_active); if (wake_cookie)
__fscache_wake_unused_cookie(cookie);
kfree(op); kfree(op);
nobufs: nobufs:
fscache_stat(&fscache_n_retrievals_nobufs); fscache_stat(&fscache_n_retrievals_nobufs);
...@@ -514,6 +524,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie, ...@@ -514,6 +524,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
{ {
struct fscache_retrieval *op; struct fscache_retrieval *op;
struct fscache_object *object; struct fscache_object *object;
bool wake_cookie = false;
int ret; int ret;
_enter("%p,,%d,,,", cookie, *nr_pages); _enter("%p,,%d,,,", cookie, *nr_pages);
...@@ -542,11 +553,13 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie, ...@@ -542,11 +553,13 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
spin_lock(&cookie->lock); spin_lock(&cookie->lock);
if (hlist_empty(&cookie->backing_objects)) if (!fscache_cookie_enabled(cookie) ||
hlist_empty(&cookie->backing_objects))
goto nobufs_unlock; goto nobufs_unlock;
object = hlist_entry(cookie->backing_objects.first, object = hlist_entry(cookie->backing_objects.first,
struct fscache_object, cookie_link); struct fscache_object, cookie_link);
__fscache_use_cookie(cookie);
atomic_inc(&object->n_reads); atomic_inc(&object->n_reads);
__set_bit(FSCACHE_OP_DEC_READ_CNT, &op->op.flags); __set_bit(FSCACHE_OP_DEC_READ_CNT, &op->op.flags);
...@@ -601,10 +614,12 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie, ...@@ -601,10 +614,12 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
nobufs_unlock_dec: nobufs_unlock_dec:
atomic_dec(&object->n_reads); atomic_dec(&object->n_reads);
wake_cookie = __fscache_unuse_cookie(cookie);
nobufs_unlock: nobufs_unlock:
spin_unlock(&cookie->lock); spin_unlock(&cookie->lock);
atomic_dec(&cookie->n_active);
kfree(op); kfree(op);
if (wake_cookie)
__fscache_wake_unused_cookie(cookie);
nobufs: nobufs:
fscache_stat(&fscache_n_retrievals_nobufs); fscache_stat(&fscache_n_retrievals_nobufs);
_leave(" = -ENOBUFS"); _leave(" = -ENOBUFS");
...@@ -626,6 +641,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie, ...@@ -626,6 +641,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
{ {
struct fscache_retrieval *op; struct fscache_retrieval *op;
struct fscache_object *object; struct fscache_object *object;
bool wake_cookie = false;
int ret; int ret;
_enter("%p,%p,,,", cookie, page); _enter("%p,%p,,,", cookie, page);
...@@ -653,13 +669,15 @@ int __fscache_alloc_page(struct fscache_cookie *cookie, ...@@ -653,13 +669,15 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
spin_lock(&cookie->lock); spin_lock(&cookie->lock);
if (hlist_empty(&cookie->backing_objects)) if (!fscache_cookie_enabled(cookie) ||
hlist_empty(&cookie->backing_objects))
goto nobufs_unlock; goto nobufs_unlock;
object = hlist_entry(cookie->backing_objects.first, object = hlist_entry(cookie->backing_objects.first,
struct fscache_object, cookie_link); struct fscache_object, cookie_link);
__fscache_use_cookie(cookie);
if (fscache_submit_op(object, &op->op) < 0) if (fscache_submit_op(object, &op->op) < 0)
goto nobufs_unlock; goto nobufs_unlock_dec;
spin_unlock(&cookie->lock); spin_unlock(&cookie->lock);
fscache_stat(&fscache_n_alloc_ops); fscache_stat(&fscache_n_alloc_ops);
...@@ -689,10 +707,13 @@ int __fscache_alloc_page(struct fscache_cookie *cookie, ...@@ -689,10 +707,13 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
_leave(" = %d", ret); _leave(" = %d", ret);
return ret; return ret;
nobufs_unlock_dec:
wake_cookie = __fscache_unuse_cookie(cookie);
nobufs_unlock: nobufs_unlock:
spin_unlock(&cookie->lock); spin_unlock(&cookie->lock);
atomic_dec(&cookie->n_active);
kfree(op); kfree(op);
if (wake_cookie)
__fscache_wake_unused_cookie(cookie);
nobufs: nobufs:
fscache_stat(&fscache_n_allocs_nobufs); fscache_stat(&fscache_n_allocs_nobufs);
_leave(" = -ENOBUFS"); _leave(" = -ENOBUFS");
...@@ -889,6 +910,7 @@ int __fscache_write_page(struct fscache_cookie *cookie, ...@@ -889,6 +910,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
{ {
struct fscache_storage *op; struct fscache_storage *op;
struct fscache_object *object; struct fscache_object *object;
bool wake_cookie = false;
int ret; int ret;
_enter("%p,%x,", cookie, (u32) page->flags); _enter("%p,%x,", cookie, (u32) page->flags);
...@@ -920,7 +942,8 @@ int __fscache_write_page(struct fscache_cookie *cookie, ...@@ -920,7 +942,8 @@ int __fscache_write_page(struct fscache_cookie *cookie,
ret = -ENOBUFS; ret = -ENOBUFS;
spin_lock(&cookie->lock); spin_lock(&cookie->lock);
if (hlist_empty(&cookie->backing_objects)) if (!fscache_cookie_enabled(cookie) ||
hlist_empty(&cookie->backing_objects))
goto nobufs; goto nobufs;
object = hlist_entry(cookie->backing_objects.first, object = hlist_entry(cookie->backing_objects.first,
struct fscache_object, cookie_link); struct fscache_object, cookie_link);
...@@ -957,7 +980,7 @@ int __fscache_write_page(struct fscache_cookie *cookie, ...@@ -957,7 +980,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
op->op.debug_id = atomic_inc_return(&fscache_op_debug_id); op->op.debug_id = atomic_inc_return(&fscache_op_debug_id);
op->store_limit = object->store_limit; op->store_limit = object->store_limit;
atomic_inc(&cookie->n_active); __fscache_use_cookie(cookie);
if (fscache_submit_op(object, &op->op) < 0) if (fscache_submit_op(object, &op->op) < 0)
goto submit_failed; goto submit_failed;
...@@ -984,10 +1007,10 @@ int __fscache_write_page(struct fscache_cookie *cookie, ...@@ -984,10 +1007,10 @@ int __fscache_write_page(struct fscache_cookie *cookie,
return 0; return 0;
submit_failed: submit_failed:
atomic_dec(&cookie->n_active);
spin_lock(&cookie->stores_lock); spin_lock(&cookie->stores_lock);
radix_tree_delete(&cookie->stores, page->index); radix_tree_delete(&cookie->stores, page->index);
spin_unlock(&cookie->stores_lock); spin_unlock(&cookie->stores_lock);
wake_cookie = __fscache_unuse_cookie(cookie);
page_cache_release(page); page_cache_release(page);
ret = -ENOBUFS; ret = -ENOBUFS;
goto nobufs; goto nobufs;
...@@ -999,6 +1022,8 @@ int __fscache_write_page(struct fscache_cookie *cookie, ...@@ -999,6 +1022,8 @@ int __fscache_write_page(struct fscache_cookie *cookie,
spin_unlock(&cookie->lock); spin_unlock(&cookie->lock);
radix_tree_preload_end(); radix_tree_preload_end();
kfree(op); kfree(op);
if (wake_cookie)
__fscache_wake_unused_cookie(cookie);
fscache_stat(&fscache_n_stores_nobufs); fscache_stat(&fscache_n_stores_nobufs);
_leave(" = -ENOBUFS"); _leave(" = -ENOBUFS");
return -ENOBUFS; return -ENOBUFS;
......
...@@ -1387,7 +1387,7 @@ static struct nfs_open_context *create_nfs_open_context(struct dentry *dentry, i ...@@ -1387,7 +1387,7 @@ static struct nfs_open_context *create_nfs_open_context(struct dentry *dentry, i
static int do_open(struct inode *inode, struct file *filp) static int do_open(struct inode *inode, struct file *filp)
{ {
nfs_fscache_set_inode_cookie(inode, filp); nfs_fscache_open_file(inode, filp);
return 0; return 0;
} }
......
This diff is collapsed.
...@@ -76,11 +76,9 @@ extern void nfs_fscache_release_client_cookie(struct nfs_client *); ...@@ -76,11 +76,9 @@ extern void nfs_fscache_release_client_cookie(struct nfs_client *);
extern void nfs_fscache_get_super_cookie(struct super_block *, const char *, int); extern void nfs_fscache_get_super_cookie(struct super_block *, const char *, int);
extern void nfs_fscache_release_super_cookie(struct super_block *); extern void nfs_fscache_release_super_cookie(struct super_block *);
extern void nfs_fscache_init_inode_cookie(struct inode *); extern void nfs_fscache_init_inode(struct inode *);
extern void nfs_fscache_release_inode_cookie(struct inode *); extern void nfs_fscache_clear_inode(struct inode *);
extern void nfs_fscache_zap_inode_cookie(struct inode *); extern void nfs_fscache_open_file(struct inode *, struct file *);
extern void nfs_fscache_set_inode_cookie(struct inode *, struct file *);
extern void nfs_fscache_reset_inode_cookie(struct inode *);
extern void __nfs_fscache_invalidate_page(struct page *, struct inode *); extern void __nfs_fscache_invalidate_page(struct page *, struct inode *);
extern int nfs_fscache_release_page(struct page *, gfp_t); extern int nfs_fscache_release_page(struct page *, gfp_t);
...@@ -187,12 +185,10 @@ static inline void nfs_fscache_release_client_cookie(struct nfs_client *clp) {} ...@@ -187,12 +185,10 @@ static inline void nfs_fscache_release_client_cookie(struct nfs_client *clp) {}
static inline void nfs_fscache_release_super_cookie(struct super_block *sb) {} static inline void nfs_fscache_release_super_cookie(struct super_block *sb) {}
static inline void nfs_fscache_init_inode_cookie(struct inode *inode) {} static inline void nfs_fscache_init_inode(struct inode *inode) {}
static inline void nfs_fscache_release_inode_cookie(struct inode *inode) {} static inline void nfs_fscache_clear_inode(struct inode *inode) {}
static inline void nfs_fscache_zap_inode_cookie(struct inode *inode) {} static inline void nfs_fscache_open_file(struct inode *inode,
static inline void nfs_fscache_set_inode_cookie(struct inode *inode,
struct file *filp) {} struct file *filp) {}
static inline void nfs_fscache_reset_inode_cookie(struct inode *inode) {}
static inline int nfs_fscache_release_page(struct page *page, gfp_t gfp) static inline int nfs_fscache_release_page(struct page *page, gfp_t gfp)
{ {
......
...@@ -122,7 +122,7 @@ void nfs_clear_inode(struct inode *inode) ...@@ -122,7 +122,7 @@ void nfs_clear_inode(struct inode *inode)
WARN_ON_ONCE(!list_empty(&NFS_I(inode)->open_files)); WARN_ON_ONCE(!list_empty(&NFS_I(inode)->open_files));
nfs_zap_acl_cache(inode); nfs_zap_acl_cache(inode);
nfs_access_zap_cache(inode); nfs_access_zap_cache(inode);
nfs_fscache_release_inode_cookie(inode); nfs_fscache_clear_inode(inode);
} }
EXPORT_SYMBOL_GPL(nfs_clear_inode); EXPORT_SYMBOL_GPL(nfs_clear_inode);
...@@ -459,7 +459,7 @@ nfs_fhget(struct super_block *sb, struct nfs_fh *fh, struct nfs_fattr *fattr, st ...@@ -459,7 +459,7 @@ nfs_fhget(struct super_block *sb, struct nfs_fh *fh, struct nfs_fattr *fattr, st
nfsi->attrtimeo_timestamp = now; nfsi->attrtimeo_timestamp = now;
nfsi->access_cache = RB_ROOT; nfsi->access_cache = RB_ROOT;
nfs_fscache_init_inode_cookie(inode); nfs_fscache_init_inode(inode);
unlock_new_inode(inode); unlock_new_inode(inode);
} else } else
...@@ -854,7 +854,7 @@ int nfs_open(struct inode *inode, struct file *filp) ...@@ -854,7 +854,7 @@ int nfs_open(struct inode *inode, struct file *filp)
return PTR_ERR(ctx); return PTR_ERR(ctx);
nfs_file_set_open_context(filp, ctx); nfs_file_set_open_context(filp, ctx);
put_nfs_open_context(ctx); put_nfs_open_context(ctx);
nfs_fscache_set_inode_cookie(inode, filp); nfs_fscache_open_file(inode, filp);
return 0; return 0;
} }
......
...@@ -75,7 +75,7 @@ nfs4_file_open(struct inode *inode, struct file *filp) ...@@ -75,7 +75,7 @@ nfs4_file_open(struct inode *inode, struct file *filp)
nfs_set_verifier(dentry, nfs_save_change_attribute(dir)); nfs_set_verifier(dentry, nfs_save_change_attribute(dir));
nfs_file_set_open_context(filp, ctx); nfs_file_set_open_context(filp, ctx);
nfs_fscache_set_inode_cookie(inode, filp); nfs_fscache_open_file(inode, filp);
err = 0; err = 0;
out_put_ctx: out_put_ctx:
......
...@@ -2292,6 +2292,11 @@ static inline void allow_write_access(struct file *file) ...@@ -2292,6 +2292,11 @@ static inline void allow_write_access(struct file *file)
if (file) if (file)
atomic_inc(&file_inode(file)->i_writecount); atomic_inc(&file_inode(file)->i_writecount);
} }
static inline bool inode_is_open_for_write(const struct inode *inode)
{
return atomic_read(&inode->i_writecount) > 0;
}
#ifdef CONFIG_IMA #ifdef CONFIG_IMA
static inline void i_readcount_dec(struct inode *inode) static inline void i_readcount_dec(struct inode *inode)
{ {
......
...@@ -308,36 +308,6 @@ struct fscache_cache_ops { ...@@ -308,36 +308,6 @@ struct fscache_cache_ops {
void (*dissociate_pages)(struct fscache_cache *cache); void (*dissociate_pages)(struct fscache_cache *cache);
}; };
/*
* data file or index object cookie
* - a file will only appear in one cache
* - a request to cache a file may or may not be honoured, subject to
* constraints such as disk space
* - indices are created on disk just-in-time
*/
struct fscache_cookie {
atomic_t usage; /* number of users of this cookie */
atomic_t n_children; /* number of children of this cookie */
atomic_t n_active; /* number of active users of netfs ptrs */
spinlock_t lock;
spinlock_t stores_lock; /* lock on page store tree */
struct hlist_head backing_objects; /* object(s) backing this file/index */
const struct fscache_cookie_def *def; /* definition */
struct fscache_cookie *parent; /* parent of this entry */
void *netfs_data; /* back pointer to netfs */
struct radix_tree_root stores; /* pages to be stored on this cookie */
#define FSCACHE_COOKIE_PENDING_TAG 0 /* pages tag: pending write to cache */
#define FSCACHE_COOKIE_STORING_TAG 1 /* pages tag: writing to cache */
unsigned long flags;
#define FSCACHE_COOKIE_LOOKING_UP 0 /* T if non-index cookie being looked up still */
#define FSCACHE_COOKIE_NO_DATA_YET 1 /* T if new object with no cached data yet */
#define FSCACHE_COOKIE_UNAVAILABLE 2 /* T if cookie is unavailable (error, etc) */
#define FSCACHE_COOKIE_INVALIDATING 3 /* T if cookie is being invalidated */
#define FSCACHE_COOKIE_RELINQUISHED 4 /* T if cookie has been relinquished */
#define FSCACHE_COOKIE_RETIRED 5 /* T if cookie was retired */
};
extern struct fscache_cookie fscache_fsdef_index; extern struct fscache_cookie fscache_fsdef_index;
/* /*
...@@ -400,6 +370,7 @@ struct fscache_object { ...@@ -400,6 +370,7 @@ struct fscache_object {
#define FSCACHE_OBJECT_IS_LIVE 3 /* T if object is not withdrawn or relinquished */ #define FSCACHE_OBJECT_IS_LIVE 3 /* T if object is not withdrawn or relinquished */
#define FSCACHE_OBJECT_IS_LOOKED_UP 4 /* T if object has been looked up */ #define FSCACHE_OBJECT_IS_LOOKED_UP 4 /* T if object has been looked up */
#define FSCACHE_OBJECT_IS_AVAILABLE 5 /* T if object has become active */ #define FSCACHE_OBJECT_IS_AVAILABLE 5 /* T if object has become active */
#define FSCACHE_OBJECT_RETIRED 6 /* T if object was retired on relinquishment */
struct list_head cache_link; /* link in cache->object_list */ struct list_head cache_link; /* link in cache->object_list */
struct hlist_node cookie_link; /* link in cookie->backing_objects */ struct hlist_node cookie_link; /* link in cookie->backing_objects */
...@@ -511,6 +482,11 @@ static inline void fscache_end_io(struct fscache_retrieval *op, ...@@ -511,6 +482,11 @@ static inline void fscache_end_io(struct fscache_retrieval *op,
op->end_io_func(page, op->context, error); op->end_io_func(page, op->context, error);
} }
static inline void __fscache_use_cookie(struct fscache_cookie *cookie)
{
atomic_inc(&cookie->n_active);
}
/** /**
* fscache_use_cookie - Request usage of cookie attached to an object * fscache_use_cookie - Request usage of cookie attached to an object
* @object: Object description * @object: Object description
...@@ -524,6 +500,16 @@ static inline bool fscache_use_cookie(struct fscache_object *object) ...@@ -524,6 +500,16 @@ static inline bool fscache_use_cookie(struct fscache_object *object)
return atomic_inc_not_zero(&cookie->n_active) != 0; return atomic_inc_not_zero(&cookie->n_active) != 0;
} }
static inline bool __fscache_unuse_cookie(struct fscache_cookie *cookie)
{
return atomic_dec_and_test(&cookie->n_active);
}
static inline void __fscache_wake_unused_cookie(struct fscache_cookie *cookie)
{
wake_up_atomic_t(&cookie->n_active);
}
/** /**
* fscache_unuse_cookie - Cease usage of cookie attached to an object * fscache_unuse_cookie - Cease usage of cookie attached to an object
* @object: Object description * @object: Object description
...@@ -534,8 +520,8 @@ static inline bool fscache_use_cookie(struct fscache_object *object) ...@@ -534,8 +520,8 @@ static inline bool fscache_use_cookie(struct fscache_object *object)
static inline void fscache_unuse_cookie(struct fscache_object *object) static inline void fscache_unuse_cookie(struct fscache_object *object)
{ {
struct fscache_cookie *cookie = object->cookie; struct fscache_cookie *cookie = object->cookie;
if (atomic_dec_and_test(&cookie->n_active)) if (__fscache_unuse_cookie(cookie))
wake_up_atomic_t(&cookie->n_active); __fscache_wake_unused_cookie(cookie);
} }
/* /*
......
...@@ -166,6 +166,42 @@ struct fscache_netfs { ...@@ -166,6 +166,42 @@ struct fscache_netfs {
struct list_head link; /* internal link */ struct list_head link; /* internal link */
}; };
/*
* data file or index object cookie
* - a file will only appear in one cache
* - a request to cache a file may or may not be honoured, subject to
* constraints such as disk space
* - indices are created on disk just-in-time
*/
struct fscache_cookie {
atomic_t usage; /* number of users of this cookie */
atomic_t n_children; /* number of children of this cookie */
atomic_t n_active; /* number of active users of netfs ptrs */
spinlock_t lock;
spinlock_t stores_lock; /* lock on page store tree */
struct hlist_head backing_objects; /* object(s) backing this file/index */
const struct fscache_cookie_def *def; /* definition */
struct fscache_cookie *parent; /* parent of this entry */
void *netfs_data; /* back pointer to netfs */
struct radix_tree_root stores; /* pages to be stored on this cookie */
#define FSCACHE_COOKIE_PENDING_TAG 0 /* pages tag: pending write to cache */
#define FSCACHE_COOKIE_STORING_TAG 1 /* pages tag: writing to cache */
unsigned long flags;
#define FSCACHE_COOKIE_LOOKING_UP 0 /* T if non-index cookie being looked up still */
#define FSCACHE_COOKIE_NO_DATA_YET 1 /* T if new object with no cached data yet */
#define FSCACHE_COOKIE_UNAVAILABLE 2 /* T if cookie is unavailable (error, etc) */
#define FSCACHE_COOKIE_INVALIDATING 3 /* T if cookie is being invalidated */
#define FSCACHE_COOKIE_RELINQUISHED 4 /* T if cookie has been relinquished */
#define FSCACHE_COOKIE_ENABLED 5 /* T if cookie is enabled */
#define FSCACHE_COOKIE_ENABLEMENT_LOCK 6 /* T if cookie is being en/disabled */
};
static inline bool fscache_cookie_enabled(struct fscache_cookie *cookie)
{
return test_bit(FSCACHE_COOKIE_ENABLED, &cookie->flags);
}
/* /*
* slow-path functions for when there is actually caching available, and the * slow-path functions for when there is actually caching available, and the
* netfs does actually have a valid token * netfs does actually have a valid token
...@@ -181,8 +217,8 @@ extern void __fscache_release_cache_tag(struct fscache_cache_tag *); ...@@ -181,8 +217,8 @@ extern void __fscache_release_cache_tag(struct fscache_cache_tag *);
extern struct fscache_cookie *__fscache_acquire_cookie( extern struct fscache_cookie *__fscache_acquire_cookie(
struct fscache_cookie *, struct fscache_cookie *,
const struct fscache_cookie_def *, const struct fscache_cookie_def *,
void *); void *, bool);
extern void __fscache_relinquish_cookie(struct fscache_cookie *, int); extern void __fscache_relinquish_cookie(struct fscache_cookie *, bool);
extern int __fscache_check_consistency(struct fscache_cookie *); extern int __fscache_check_consistency(struct fscache_cookie *);
extern void __fscache_update_cookie(struct fscache_cookie *); extern void __fscache_update_cookie(struct fscache_cookie *);
extern int __fscache_attr_changed(struct fscache_cookie *); extern int __fscache_attr_changed(struct fscache_cookie *);
...@@ -211,6 +247,9 @@ extern void __fscache_uncache_all_inode_pages(struct fscache_cookie *, ...@@ -211,6 +247,9 @@ extern void __fscache_uncache_all_inode_pages(struct fscache_cookie *,
struct inode *); struct inode *);
extern void __fscache_readpages_cancel(struct fscache_cookie *cookie, extern void __fscache_readpages_cancel(struct fscache_cookie *cookie,
struct list_head *pages); struct list_head *pages);
extern void __fscache_disable_cookie(struct fscache_cookie *, bool);
extern void __fscache_enable_cookie(struct fscache_cookie *,
bool (*)(void *), void *);
/** /**
* fscache_register_netfs - Register a filesystem as desiring caching services * fscache_register_netfs - Register a filesystem as desiring caching services
...@@ -289,6 +328,7 @@ void fscache_release_cache_tag(struct fscache_cache_tag *tag) ...@@ -289,6 +328,7 @@ void fscache_release_cache_tag(struct fscache_cache_tag *tag)
* @def: A description of the cache object, including callback operations * @def: A description of the cache object, including callback operations
* @netfs_data: An arbitrary piece of data to be kept in the cookie to * @netfs_data: An arbitrary piece of data to be kept in the cookie to
* represent the cache object to the netfs * represent the cache object to the netfs
* @enable: Whether or not to enable a data cookie immediately
* *
* This function is used to inform FS-Cache about part of an index hierarchy * This function is used to inform FS-Cache about part of an index hierarchy
* that can be used to locate files. This is done by requesting a cookie for * that can be used to locate files. This is done by requesting a cookie for
...@@ -301,10 +341,12 @@ static inline ...@@ -301,10 +341,12 @@ static inline
struct fscache_cookie *fscache_acquire_cookie( struct fscache_cookie *fscache_acquire_cookie(
struct fscache_cookie *parent, struct fscache_cookie *parent,
const struct fscache_cookie_def *def, const struct fscache_cookie_def *def,
void *netfs_data) void *netfs_data,
bool enable)
{ {
if (fscache_cookie_valid(parent)) if (fscache_cookie_valid(parent) && fscache_cookie_enabled(parent))
return __fscache_acquire_cookie(parent, def, netfs_data); return __fscache_acquire_cookie(parent, def, netfs_data,
enable);
else else
return NULL; return NULL;
} }
...@@ -322,7 +364,7 @@ struct fscache_cookie *fscache_acquire_cookie( ...@@ -322,7 +364,7 @@ struct fscache_cookie *fscache_acquire_cookie(
* description. * description.
*/ */
static inline static inline
void fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire) void fscache_relinquish_cookie(struct fscache_cookie *cookie, bool retire)
{ {
if (fscache_cookie_valid(cookie)) if (fscache_cookie_valid(cookie))
__fscache_relinquish_cookie(cookie, retire); __fscache_relinquish_cookie(cookie, retire);
...@@ -341,7 +383,7 @@ void fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire) ...@@ -341,7 +383,7 @@ void fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
static inline static inline
int fscache_check_consistency(struct fscache_cookie *cookie) int fscache_check_consistency(struct fscache_cookie *cookie)
{ {
if (fscache_cookie_valid(cookie)) if (fscache_cookie_valid(cookie) && fscache_cookie_enabled(cookie))
return __fscache_check_consistency(cookie); return __fscache_check_consistency(cookie);
else else
return 0; return 0;
...@@ -360,7 +402,7 @@ int fscache_check_consistency(struct fscache_cookie *cookie) ...@@ -360,7 +402,7 @@ int fscache_check_consistency(struct fscache_cookie *cookie)
static inline static inline
void fscache_update_cookie(struct fscache_cookie *cookie) void fscache_update_cookie(struct fscache_cookie *cookie)
{ {
if (fscache_cookie_valid(cookie)) if (fscache_cookie_valid(cookie) && fscache_cookie_enabled(cookie))
__fscache_update_cookie(cookie); __fscache_update_cookie(cookie);
} }
...@@ -407,7 +449,7 @@ void fscache_unpin_cookie(struct fscache_cookie *cookie) ...@@ -407,7 +449,7 @@ void fscache_unpin_cookie(struct fscache_cookie *cookie)
static inline static inline
int fscache_attr_changed(struct fscache_cookie *cookie) int fscache_attr_changed(struct fscache_cookie *cookie)
{ {
if (fscache_cookie_valid(cookie)) if (fscache_cookie_valid(cookie) && fscache_cookie_enabled(cookie))
return __fscache_attr_changed(cookie); return __fscache_attr_changed(cookie);
else else
return -ENOBUFS; return -ENOBUFS;
...@@ -429,7 +471,7 @@ int fscache_attr_changed(struct fscache_cookie *cookie) ...@@ -429,7 +471,7 @@ int fscache_attr_changed(struct fscache_cookie *cookie)
static inline static inline
void fscache_invalidate(struct fscache_cookie *cookie) void fscache_invalidate(struct fscache_cookie *cookie)
{ {
if (fscache_cookie_valid(cookie)) if (fscache_cookie_valid(cookie) && fscache_cookie_enabled(cookie))
__fscache_invalidate(cookie); __fscache_invalidate(cookie);
} }
...@@ -503,7 +545,7 @@ int fscache_read_or_alloc_page(struct fscache_cookie *cookie, ...@@ -503,7 +545,7 @@ int fscache_read_or_alloc_page(struct fscache_cookie *cookie,
void *context, void *context,
gfp_t gfp) gfp_t gfp)
{ {
if (fscache_cookie_valid(cookie)) if (fscache_cookie_valid(cookie) && fscache_cookie_enabled(cookie))
return __fscache_read_or_alloc_page(cookie, page, end_io_func, return __fscache_read_or_alloc_page(cookie, page, end_io_func,
context, gfp); context, gfp);
else else
...@@ -554,7 +596,7 @@ int fscache_read_or_alloc_pages(struct fscache_cookie *cookie, ...@@ -554,7 +596,7 @@ int fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
void *context, void *context,
gfp_t gfp) gfp_t gfp)
{ {
if (fscache_cookie_valid(cookie)) if (fscache_cookie_valid(cookie) && fscache_cookie_enabled(cookie))
return __fscache_read_or_alloc_pages(cookie, mapping, pages, return __fscache_read_or_alloc_pages(cookie, mapping, pages,
nr_pages, end_io_func, nr_pages, end_io_func,
context, gfp); context, gfp);
...@@ -585,7 +627,7 @@ int fscache_alloc_page(struct fscache_cookie *cookie, ...@@ -585,7 +627,7 @@ int fscache_alloc_page(struct fscache_cookie *cookie,
struct page *page, struct page *page,
gfp_t gfp) gfp_t gfp)
{ {
if (fscache_cookie_valid(cookie)) if (fscache_cookie_valid(cookie) && fscache_cookie_enabled(cookie))
return __fscache_alloc_page(cookie, page, gfp); return __fscache_alloc_page(cookie, page, gfp);
else else
return -ENOBUFS; return -ENOBUFS;
...@@ -634,7 +676,7 @@ int fscache_write_page(struct fscache_cookie *cookie, ...@@ -634,7 +676,7 @@ int fscache_write_page(struct fscache_cookie *cookie,
struct page *page, struct page *page,
gfp_t gfp) gfp_t gfp)
{ {
if (fscache_cookie_valid(cookie)) if (fscache_cookie_valid(cookie) && fscache_cookie_enabled(cookie))
return __fscache_write_page(cookie, page, gfp); return __fscache_write_page(cookie, page, gfp);
else else
return -ENOBUFS; return -ENOBUFS;
...@@ -744,4 +786,47 @@ void fscache_uncache_all_inode_pages(struct fscache_cookie *cookie, ...@@ -744,4 +786,47 @@ void fscache_uncache_all_inode_pages(struct fscache_cookie *cookie,
__fscache_uncache_all_inode_pages(cookie, inode); __fscache_uncache_all_inode_pages(cookie, inode);
} }
/**
* fscache_disable_cookie - Disable a cookie
* @cookie: The cookie representing the cache object
* @invalidate: Invalidate the backing object
*
* Disable a cookie from accepting further alloc, read, write, invalidate,
* update or acquire operations. Outstanding operations can still be waited
* upon and pages can still be uncached and the cookie relinquished.
*
* This will not return until all outstanding operations have completed.
*
* If @invalidate is set, then the backing object will be invalidated and
* detached, otherwise it will just be detached.
*/
static inline
void fscache_disable_cookie(struct fscache_cookie *cookie, bool invalidate)
{
if (fscache_cookie_valid(cookie) && fscache_cookie_enabled(cookie))
__fscache_disable_cookie(cookie, invalidate);
}
/**
* fscache_enable_cookie - Reenable a cookie
* @cookie: The cookie representing the cache object
* @can_enable: A function to permit enablement once lock is held
* @data: Data for can_enable()
*
* Reenable a previously disabled cookie, allowing it to accept further alloc,
* read, write, invalidate, update or acquire operations. An attempt will be
* made to immediately reattach the cookie to a backing object.
*
* The can_enable() function is called (if not NULL) once the enablement lock
* is held to rule on whether enablement is still permitted to go ahead.
*/
static inline
void fscache_enable_cookie(struct fscache_cookie *cookie,
bool (*can_enable)(void *data),
void *data)
{
if (fscache_cookie_valid(cookie) && !fscache_cookie_enabled(cookie))
__fscache_enable_cookie(cookie, can_enable, data);
}
#endif /* _LINUX_FSCACHE_H */ #endif /* _LINUX_FSCACHE_H */
...@@ -269,9 +269,13 @@ static inline int NFS_STALE(const struct inode *inode) ...@@ -269,9 +269,13 @@ static inline int NFS_STALE(const struct inode *inode)
return test_bit(NFS_INO_STALE, &NFS_I(inode)->flags); return test_bit(NFS_INO_STALE, &NFS_I(inode)->flags);
} }
static inline int NFS_FSCACHE(const struct inode *inode) static inline struct fscache_cookie *nfs_i_fscache(struct inode *inode)
{ {
return test_bit(NFS_INO_FSCACHE, &NFS_I(inode)->flags); #ifdef CONFIG_NFS_FSCACHE
return NFS_I(inode)->fscache;
#else
return NULL;
#endif
} }
static inline __u64 NFS_FILEID(const struct inode *inode) static inline __u64 NFS_FILEID(const struct inode *inode)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment