Skip to content

Commit c5e4d5e

Browse files
committed
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
2 parents a1f7642 + 1122f40 commit c5e4d5e

File tree

3 files changed

+19
-8
lines changed

3 files changed

+19
-8
lines changed

fs/cachefiles/internal.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ struct cachefiles_cache {
111111
char *tag; /* cache binding tag */
112112
refcount_t unbind_pincount;/* refcount to do daemon unbind */
113113
struct xarray reqs; /* xarray of pending on-demand requests */
114+
unsigned long req_id_next;
114115
struct xarray ondemand_ids; /* xarray for ondemand_id allocation */
115116
u32 ondemand_id_next;
116117
};

fs/cachefiles/ondemand.c

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -158,9 +158,13 @@ int cachefiles_ondemand_copen(struct cachefiles_cache *cache, char *args)
158158

159159
/* fail OPEN request if daemon reports an error */
160160
if (size < 0) {
161-
if (!IS_ERR_VALUE(size))
162-
size = -EINVAL;
163-
req->error = size;
161+
if (!IS_ERR_VALUE(size)) {
162+
req->error = -EINVAL;
163+
ret = -EINVAL;
164+
} else {
165+
req->error = size;
166+
ret = 0;
167+
}
164168
goto out;
165169
}
166170

@@ -238,14 +242,19 @@ ssize_t cachefiles_ondemand_daemon_read(struct cachefiles_cache *cache,
238242
unsigned long id = 0;
239243
size_t n;
240244
int ret = 0;
241-
XA_STATE(xas, &cache->reqs, 0);
245+
XA_STATE(xas, &cache->reqs, cache->req_id_next);
242246

243247
/*
244-
* Search for a request that has not ever been processed, to prevent
245-
* requests from being processed repeatedly.
248+
* Cyclically search for a request that has not ever been processed,
249+
* to prevent requests from being processed repeatedly, and make
250+
* request distribution fair.
246251
*/
247252
xa_lock(&cache->reqs);
248253
req = xas_find_marked(&xas, UINT_MAX, CACHEFILES_REQ_NEW);
254+
if (!req && cache->req_id_next > 0) {
255+
xas_set(&xas, 0);
256+
req = xas_find_marked(&xas, cache->req_id_next - 1, CACHEFILES_REQ_NEW);
257+
}
249258
if (!req) {
250259
xa_unlock(&cache->reqs);
251260
return 0;
@@ -260,6 +269,7 @@ ssize_t cachefiles_ondemand_daemon_read(struct cachefiles_cache *cache,
260269
}
261270

262271
xas_clear_mark(&xas, CACHEFILES_REQ_NEW);
272+
cache->req_id_next = xas.xa_index + 1;
263273
xa_unlock(&cache->reqs);
264274

265275
id = xas.xa_index;

include/linux/fscache.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ struct fscache_cookie *fscache_acquire_cookie(struct fscache_volume *volume,
258258

259259
/**
260260
* fscache_use_cookie - Request usage of cookie attached to an object
261-
* @object: Object description
261+
* @cookie: The cookie representing the cache object
262262
* @will_modify: If cache is expected to be modified locally
263263
*
264264
* 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,
274274

275275
/**
276276
* fscache_unuse_cookie - Cease usage of cookie attached to an object
277-
* @object: Object description
277+
* @cookie: The cookie representing the cache object
278278
* @aux_data: Updated auxiliary data (or NULL)
279279
* @object_size: Revised size of the object (or NULL)
280280
*

0 commit comments

Comments
 (0)