[Linux-cachefs] [PATCH 04/12] fscache, cachefiles: Fix checker warnings

2018-04-04 Thread David Howells
Fix a couple of checker warnings in fscache and cachefiles:

 (1) fscache_n_op_requeue is never used, so get rid of it.

 (2) cachefiles_uncache_page() is passed in a lock that it releases, so
 this needs annotating.

Signed-off-by: David Howells 
---

 fs/cachefiles/rdwr.c |1 +
 fs/fscache/stats.c   |1 -
 2 files changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/cachefiles/rdwr.c b/fs/cachefiles/rdwr.c
index 883bc7bb12c5..5082c8a49686 100644
--- a/fs/cachefiles/rdwr.c
+++ b/fs/cachefiles/rdwr.c
@@ -952,6 +952,7 @@ int cachefiles_write_page(struct fscache_storage *op, 
struct page *page)
  * - cache withdrawal is prevented by the caller
  */
 void cachefiles_uncache_page(struct fscache_object *_object, struct page *page)
+   __releases(>fscache.cookie->lock)
 {
struct cachefiles_object *object;
struct cachefiles_cache *cache;
diff --git a/fs/fscache/stats.c b/fs/fscache/stats.c
index 7ac6e839b065..fcc8c2f2690e 100644
--- a/fs/fscache/stats.c
+++ b/fs/fscache/stats.c
@@ -21,7 +21,6 @@
 atomic_t fscache_n_op_pend;
 atomic_t fscache_n_op_run;
 atomic_t fscache_n_op_enqueue;
-atomic_t fscache_n_op_requeue;
 atomic_t fscache_n_op_deferred_release;
 atomic_t fscache_n_op_initialised;
 atomic_t fscache_n_op_release;

--
Linux-cachefs mailing list
Linux-cachefs@redhat.com
https://www.redhat.com/mailman/listinfo/linux-cachefs


[Linux-cachefs] [PATCH 07/12] fscache: Fix hanging wait on page discarded by writeback

2018-04-04 Thread David Howells
If the fscache asynchronous write operation elects to discard a page that's
pending storage to the cache because the page would be over the store limit
then it needs to wake the page as someone may be waiting on completion of
the write.

The problem is that the store limit may be updated by a different
asynchronous operation - and so may miss the write - and that the store
limit may not even get updated until later by the netfs.

Fix the kernel hang by making fscache_write_op() mark as written any pages
that are over the limit.

Signed-off-by: David Howells 
---

 fs/fscache/page.c |   13 +
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/fs/fscache/page.c b/fs/fscache/page.c
index adc39c0c62df..b9f18bf4227d 100644
--- a/fs/fscache/page.c
+++ b/fs/fscache/page.c
@@ -778,6 +778,7 @@ static void fscache_write_op(struct fscache_operation *_op)
 
_enter("{OP%x,%d}", op->op.debug_id, atomic_read(>op.usage));
 
+again:
spin_lock(>lock);
cookie = object->cookie;
 
@@ -819,10 +820,6 @@ static void fscache_write_op(struct fscache_operation *_op)
goto superseded;
page = results[0];
_debug("gang %d [%lx]", n, page->index);
-   if (page->index >= op->store_limit) {
-   fscache_stat(_n_store_pages_over_limit);
-   goto superseded;
-   }
 
radix_tree_tag_set(>stores, page->index,
   FSCACHE_COOKIE_STORING_TAG);
@@ -832,6 +829,9 @@ static void fscache_write_op(struct fscache_operation *_op)
spin_unlock(>stores_lock);
spin_unlock(>lock);
 
+   if (page->index >= op->store_limit)
+   goto discard_page;
+
fscache_stat(_n_store_pages);
fscache_stat(_n_cop_write_page);
ret = object->cache->ops->write_page(op, page);
@@ -847,6 +847,11 @@ static void fscache_write_op(struct fscache_operation *_op)
_leave("");
return;
 
+discard_page:
+   fscache_stat(_n_store_pages_over_limit);
+   fscache_end_page_write(object, page);
+   goto again;
+
 superseded:
/* this writer is going away and there aren't any more things to
 * write */

--
Linux-cachefs mailing list
Linux-cachefs@redhat.com
https://www.redhat.com/mailman/listinfo/linux-cachefs


[Linux-cachefs] [PATCH 05/12] fscache: Pass the correct cancelled indications to fscache_op_complete()

2018-04-04 Thread David Howells
The last parameter to fscache_op_complete() is a bool indicating whether or
not the operation was cancelled.  A lot of the time the inverse value is
given or no differentiation is made.  Fix this.

Signed-off-by: David Howells 
---

 fs/fscache/page.c |   15 +--
 include/linux/fscache-cache.h |2 +-
 2 files changed, 10 insertions(+), 7 deletions(-)

diff --git a/fs/fscache/page.c b/fs/fscache/page.c
index 961029e04027..adc39c0c62df 100644
--- a/fs/fscache/page.c
+++ b/fs/fscache/page.c
@@ -185,9 +185,11 @@ static void fscache_attr_changed_op(struct 
fscache_operation *op)
fscache_stat_d(_n_cop_attr_changed);
if (ret < 0)
fscache_abort_object(object);
+   fscache_op_complete(op, ret < 0);
+   } else {
+   fscache_op_complete(op, true);
}
 
-   fscache_op_complete(op, true);
_leave("");
 }
 
@@ -780,11 +782,12 @@ static void fscache_write_op(struct fscache_operation 
*_op)
cookie = object->cookie;
 
if (!fscache_object_is_active(object)) {
-   /* If we get here, then the on-disk cache object likely longer
-* exists, so we should just cancel this write operation.
+   /* If we get here, then the on-disk cache object likely no
+* longer exists, so we should just cancel this write
+* operation.
 */
spin_unlock(>lock);
-   fscache_op_complete(>op, false);
+   fscache_op_complete(>op, true);
_leave(" [inactive]");
return;
}
@@ -797,7 +800,7 @@ static void fscache_write_op(struct fscache_operation *_op)
 * cancel this write operation.
 */
spin_unlock(>lock);
-   fscache_op_complete(>op, false);
+   fscache_op_complete(>op, true);
_leave(" [cancel] op{f=%lx s=%u} obj{s=%s f=%lx}",
   _op->flags, _op->state, object->state->short_name,
   object->flags);
@@ -851,7 +854,7 @@ static void fscache_write_op(struct fscache_operation *_op)
spin_unlock(>stores_lock);
clear_bit(FSCACHE_OBJECT_PENDING_WRITE, >flags);
spin_unlock(>lock);
-   fscache_op_complete(>op, true);
+   fscache_op_complete(>op, false);
_leave("");
 }
 
diff --git a/include/linux/fscache-cache.h b/include/linux/fscache-cache.h
index 3b03e29e2f1a..b19fa8592fc2 100644
--- a/include/linux/fscache-cache.h
+++ b/include/linux/fscache-cache.h
@@ -185,7 +185,7 @@ static inline void fscache_retrieval_complete(struct 
fscache_retrieval *op,
 {
atomic_sub(n_pages, >n_pages);
if (atomic_read(>n_pages) <= 0)
-   fscache_op_complete(>op, true);
+   fscache_op_complete(>op, false);
 }
 
 /**

--
Linux-cachefs mailing list
Linux-cachefs@redhat.com
https://www.redhat.com/mailman/listinfo/linux-cachefs


[Linux-cachefs] [PATCH 06/12] fscache: Detect multiple relinquishment of a cookie

2018-04-04 Thread David Howells
Report if an fscache cookie is relinquished multiple times by the netfs.

Signed-off-by: David 
---

 fs/fscache/cookie.c |3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/fs/fscache/cookie.c b/fs/fscache/cookie.c
index d705125665f0..98d22f495cd8 100644
--- a/fs/fscache/cookie.c
+++ b/fs/fscache/cookie.c
@@ -602,7 +602,8 @@ void __fscache_relinquish_cookie(struct fscache_cookie 
*cookie, bool retire)
   atomic_read(>n_active), retire);
 
/* No further netfs-accessing operations on this cookie permitted */
-   set_bit(FSCACHE_COOKIE_RELINQUISHED, >flags);
+   if (test_and_set_bit(FSCACHE_COOKIE_RELINQUISHED, >flags))
+   BUG();
 
__fscache_disable_cookie(cookie, retire);
 

--
Linux-cachefs mailing list
Linux-cachefs@redhat.com
https://www.redhat.com/mailman/listinfo/linux-cachefs


Re: [Linux-cachefs] [PATCH 06/12] fscache: Detect multiple relinquishment of a cookie

2018-04-04 Thread Linus Torvalds
On Wed, Apr 4, 2018 at 3:07 PM, David Howells  wrote:
> Report if an fscache cookie is relinquished multiple times by the netfs.
>
> -   set_bit(FSCACHE_COOKIE_RELINQUISHED, >flags);
> +   if (test_and_set_bit(FSCACHE_COOKIE_RELINQUISHED, >flags))
> +   BUG();

Ugh. Please try to avoid adding BUG() calls for reporting. They can
often cause the machine to be basically dead.

This one seem fairly ok, simply because it looks like the only caller
doesn't really hold a lot of locks (the superblock s_umount lock, but
that may be all).

So I'll pull this change, I just wanted people to realize that if this
is a "help make sure we notice if things go wrong", then
"WARN_ON_ONCE()" or something is usually a better choice than
"potentially kill the machine and make it harder to actually see the
error".

 Linus

--
Linux-cachefs mailing list
Linux-cachefs@redhat.com
https://www.redhat.com/mailman/listinfo/linux-cachefs


Re: [Linux-cachefs] [PATCH net-next 00/12] fscache: Fixes, traces and development

2018-04-04 Thread David Howells
> Subject: [PATCH net-next 00/12] fscache: Fixes, traces and development

Apologies: that shouldn't say net-next in there.  Cut'n'paste error.

David

--
Linux-cachefs mailing list
Linux-cachefs@redhat.com
https://www.redhat.com/mailman/listinfo/linux-cachefs