Commit c5e4d5e9 authored by Linus Torvalds's avatar Linus Torvalds

Merge tag 'fscache-fixes-20220831' of...

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

Pull fscache/cachefiles fixes from David Howells:

 - Fix kdoc on fscache_use/unuse_cookie().

 - Fix the error returned by cachefiles_ondemand_copen() from an upcall
   result.

 - Fix the distribution of requests in on-demand mode in cachefiles to
   be fairer by cycling through them rather than picking the one with
   the lowest ID each time (IDs being reused).

* tag 'fscache-fixes-20220831' of git://git.kernel.org/pub/scm/linux/kernel/git/dhowells/linux-fs:
  cachefiles: make on-demand request distribution fairer
  cachefiles: fix error return code in cachefiles_ondemand_copen()
  fscache: fix misdocumented parameter
parents a1f76426 1122f400
...@@ -111,6 +111,7 @@ struct cachefiles_cache { ...@@ -111,6 +111,7 @@ struct cachefiles_cache {
char *tag; /* cache binding tag */ char *tag; /* cache binding tag */
refcount_t unbind_pincount;/* refcount to do daemon unbind */ refcount_t unbind_pincount;/* refcount to do daemon unbind */
struct xarray reqs; /* xarray of pending on-demand requests */ struct xarray reqs; /* xarray of pending on-demand requests */
unsigned long req_id_next;
struct xarray ondemand_ids; /* xarray for ondemand_id allocation */ struct xarray ondemand_ids; /* xarray for ondemand_id allocation */
u32 ondemand_id_next; u32 ondemand_id_next;
}; };
......
...@@ -158,9 +158,13 @@ int cachefiles_ondemand_copen(struct cachefiles_cache *cache, char *args) ...@@ -158,9 +158,13 @@ int cachefiles_ondemand_copen(struct cachefiles_cache *cache, char *args)
/* fail OPEN request if daemon reports an error */ /* fail OPEN request if daemon reports an error */
if (size < 0) { if (size < 0) {
if (!IS_ERR_VALUE(size)) if (!IS_ERR_VALUE(size)) {
size = -EINVAL; req->error = -EINVAL;
ret = -EINVAL;
} else {
req->error = size; req->error = size;
ret = 0;
}
goto out; goto out;
} }
...@@ -238,14 +242,19 @@ ssize_t cachefiles_ondemand_daemon_read(struct cachefiles_cache *cache, ...@@ -238,14 +242,19 @@ ssize_t cachefiles_ondemand_daemon_read(struct cachefiles_cache *cache,
unsigned long id = 0; unsigned long id = 0;
size_t n; size_t n;
int ret = 0; int ret = 0;
XA_STATE(xas, &cache->reqs, 0); XA_STATE(xas, &cache->reqs, cache->req_id_next);
/* /*
* Search for a request that has not ever been processed, to prevent * Cyclically search for a request that has not ever been processed,
* requests from being processed repeatedly. * to prevent requests from being processed repeatedly, and make
* request distribution fair.
*/ */
xa_lock(&cache->reqs); xa_lock(&cache->reqs);
req = xas_find_marked(&xas, UINT_MAX, CACHEFILES_REQ_NEW); req = xas_find_marked(&xas, UINT_MAX, CACHEFILES_REQ_NEW);
if (!req && cache->req_id_next > 0) {
xas_set(&xas, 0);
req = xas_find_marked(&xas, cache->req_id_next - 1, CACHEFILES_REQ_NEW);
}
if (!req) { if (!req) {
xa_unlock(&cache->reqs); xa_unlock(&cache->reqs);
return 0; return 0;
...@@ -260,6 +269,7 @@ ssize_t cachefiles_ondemand_daemon_read(struct cachefiles_cache *cache, ...@@ -260,6 +269,7 @@ ssize_t cachefiles_ondemand_daemon_read(struct cachefiles_cache *cache,
} }
xas_clear_mark(&xas, CACHEFILES_REQ_NEW); xas_clear_mark(&xas, CACHEFILES_REQ_NEW);
cache->req_id_next = xas.xa_index + 1;
xa_unlock(&cache->reqs); xa_unlock(&cache->reqs);
id = xas.xa_index; id = xas.xa_index;
......
...@@ -258,7 +258,7 @@ struct fscache_cookie *fscache_acquire_cookie(struct fscache_volume *volume, ...@@ -258,7 +258,7 @@ struct fscache_cookie *fscache_acquire_cookie(struct fscache_volume *volume,
/** /**
* 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 * @cookie: The cookie representing the cache object
* @will_modify: If cache is expected to be modified locally * @will_modify: If cache is expected to be modified locally
* *
* Request usage of the cookie attached to an object. The caller should tell * Request usage of the cookie attached to an object. The caller should tell
...@@ -274,7 +274,7 @@ static inline void fscache_use_cookie(struct fscache_cookie *cookie, ...@@ -274,7 +274,7 @@ static inline void fscache_use_cookie(struct fscache_cookie *cookie,
/** /**
* 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 * @cookie: The cookie representing the cache object
* @aux_data: Updated auxiliary data (or NULL) * @aux_data: Updated auxiliary data (or NULL)
* @object_size: Revised size of the object (or NULL) * @object_size: Revised size of the object (or NULL)
* *
......
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