From: David Howells <dhowells@redhat.com>
To: moseleymark@gmail.com, mark@pogo.org.uk, jlayton@redhat.com,
steved@redhat.com
Cc: linux-cachefs@redhat.com, linux-fsdevel@vger.kernel.org,
linux-nfs@vger.kernel.org
Subject: [PATCH 12/13] CacheFiles: Implement invalidation
Date: Thu, 29 Sep 2011 15:48:02 +0100 [thread overview]
Message-ID: <20110929144802.5812.90480.stgit@warthog.procyon.org.uk> (raw)
In-Reply-To: <20110929144536.5812.84405.stgit@warthog.procyon.org.uk>
Implement invalidation for CacheFiles. This is in two parts:
(1) Provide an invalidation method (which just truncates the backing file).
(2) Abort attempts to copy anything read from the backing file whilst
invalidation is in progress.
Question: CacheFiles uses truncation in a couple of places. It has been using
notify_change() rather than sys_truncate() or something similar. This means
it bypasses a bunch of checks and suchlike that it possibly should be making
(security, file locking, lease breaking, vfsmount write). Should it be using
vfs_truncate() as added by a preceding patch or should it use notify_write()
and assume that anyone poking around in the cache files on disk gets
everything they deserve?
Signed-off-by: David Howells <dhowells@redhat.com>
---
fs/cachefiles/interface.c | 49 +++++++++++++++++++++++++++++++++++++++++++++
fs/cachefiles/rdwr.c | 5 ++++-
2 files changed, 53 insertions(+), 1 deletions(-)
diff --git a/fs/cachefiles/interface.c b/fs/cachefiles/interface.c
index 075b7a6..ef5c02d 100644
--- a/fs/cachefiles/interface.c
+++ b/fs/cachefiles/interface.c
@@ -442,6 +442,54 @@ truncate_failed:
}
/*
+ * Invalidate an object
+ */
+static void cachefiles_invalidate_object(struct fscache_operation *op)
+{
+ struct cachefiles_object *object;
+ struct cachefiles_cache *cache;
+ const struct cred *saved_cred;
+ struct path path;
+ uint64_t ni_size;
+ int ret;
+
+ object = container_of(op->object, struct cachefiles_object, fscache);
+ cache = container_of(object->fscache.cache,
+ struct cachefiles_cache, cache);
+
+ op->object->cookie->def->get_attr(op->object->cookie->netfs_data,
+ &ni_size);
+
+ _enter("{OBJ%x},[%llu]",
+ op->object->debug_id, (unsigned long long)ni_size);
+
+ if (object->backer) {
+ ASSERT(S_ISREG(object->backer->d_inode->i_mode));
+
+ fscache_set_store_limit(&object->fscache, ni_size);
+
+ path.dentry = object->backer;
+ path.mnt = cache->mnt;
+
+ cachefiles_begin_secure(cache, &saved_cred);
+ ret = vfs_truncate(&path, 0);
+ if (ret == 0)
+ ret = vfs_truncate(&path, ni_size);
+ cachefiles_end_secure(cache, saved_cred);
+
+ if (ret != 0) {
+ fscache_set_store_limit(&object->fscache, 0);
+ if (ret == -EIO)
+ cachefiles_io_error_obj(object,
+ "Invalidate failed");
+ }
+ }
+
+ fscache_op_complete(op);
+ _leave("");
+}
+
+/*
* dissociate a cache from all the pages it was backing
*/
static void cachefiles_dissociate_pages(struct fscache_cache *cache)
@@ -456,6 +504,7 @@ const struct fscache_cache_ops cachefiles_cache_ops = {
.lookup_complete = cachefiles_lookup_complete,
.grab_object = cachefiles_grab_object,
.update_object = cachefiles_update_object,
+ .invalidate_object = cachefiles_invalidate_object,
.drop_object = cachefiles_drop_object,
.put_object = cachefiles_put_object,
.sync_cache = cachefiles_sync_cache,
diff --git a/fs/cachefiles/rdwr.c b/fs/cachefiles/rdwr.c
index 4b2b821..637a27d 100644
--- a/fs/cachefiles/rdwr.c
+++ b/fs/cachefiles/rdwr.c
@@ -174,7 +174,10 @@ static void cachefiles_read_copier(struct fscache_operation *_op)
_debug("- copy {%lu}", monitor->back_page->index);
recheck:
- if (PageUptodate(monitor->back_page)) {
+ if (test_bit(FSCACHE_COOKIE_INVALIDATING,
+ &object->fscache.cookie->flags)) {
+ error = -ESTALE;
+ } else if (PageUptodate(monitor->back_page)) {
copy_highpage(monitor->netfs_page, monitor->back_page);
fscache_mark_page_cached(monitor->op,
monitor->netfs_page, true);
next prev parent reply other threads:[~2011-09-29 14:49 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-09-29 14:45 [RFC][PATCH 00/13] Fix FS-Cache problems David Howells
2011-09-29 14:45 ` [PATCH 01/13] Noisefs: A predictable noise producing fs for testing things David Howells
2011-09-29 14:46 ` [PATCH 02/13] CacheFiles: Fix the marking of cached pages David Howells
2011-09-29 14:46 ` [PATCH 03/13] FS-Cache: Validate page mapping pointer value David Howells
2011-09-29 14:46 ` [PATCH 04/13] CacheFiles: Downgrade the requirements passed to the allocator David Howells
2011-09-29 14:46 ` [PATCH 05/13] FS-Cache: Check that there are no read ops when cookie relinquished David Howells
2011-09-29 14:46 ` [PATCH 06/13] FS-Cache: Check cookie is still correct in __fscache_read_or_alloc_pages() David Howells
2011-09-29 14:47 ` [PATCH 07/13] CacheFiles: Make some debugging statements conditional David Howells
2011-09-29 14:47 ` [PATCH 08/13] FS-Cache: Make cookie relinquishment wait for outstanding reads David Howells
2011-09-29 14:47 ` [PATCH 09/13] FS-Cache: Fix operation state management and accounting David Howells
2011-09-29 14:47 ` [PATCH 10/13] FS-Cache: Provide proper invalidation David Howells
2011-09-29 14:47 ` [PATCH 11/13] VFS: Make more complete truncate operation available to CacheFiles David Howells
2011-09-29 14:48 ` David Howells [this message]
2011-09-29 14:48 ` [PATCH 13/13] NFS: Use FS-Cache invalidation David Howells
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20110929144802.5812.90480.stgit@warthog.procyon.org.uk \
--to=dhowells@redhat.com \
--cc=jlayton@redhat.com \
--cc=linux-cachefs@redhat.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-nfs@vger.kernel.org \
--cc=mark@pogo.org.uk \
--cc=moseleymark@gmail.com \
--cc=steved@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).