Skip to content

Commit e73fa11

Browse files
Jia Zhubrauner
Jia Zhu
authored andcommitted
cachefiles: add restore command to recover inflight ondemand read requests
Previously, in ondemand read scenario, if the anonymous fd was closed by user daemon, inflight and subsequent read requests would return EIO. As long as the device connection is not released, user daemon can hold and restore inflight requests by setting the request flag to CACHEFILES_REQ_NEW. Suggested-by: Gao Xiang <[email protected]> Signed-off-by: Jia Zhu <[email protected]> Signed-off-by: Xin Yin <[email protected]> Link: https://lore.kernel.org/r/[email protected] Reviewed-by: Jingbo Xu <[email protected]> Reviewed-by: David Howells <[email protected]> Signed-off-by: Christian Brauner <[email protected]>
1 parent b817e22 commit e73fa11

File tree

3 files changed

+27
-0
lines changed

3 files changed

+27
-0
lines changed

fs/cachefiles/daemon.c

+1
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ static const struct cachefiles_daemon_cmd cachefiles_daemon_cmds[] = {
7777
{ "tag", cachefiles_daemon_tag },
7878
#ifdef CONFIG_CACHEFILES_ONDEMAND
7979
{ "copen", cachefiles_ondemand_copen },
80+
{ "restore", cachefiles_ondemand_restore },
8081
#endif
8182
{ "", NULL }
8283
};

fs/cachefiles/internal.h

+3
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,9 @@ extern ssize_t cachefiles_ondemand_daemon_read(struct cachefiles_cache *cache,
303303
extern int cachefiles_ondemand_copen(struct cachefiles_cache *cache,
304304
char *args);
305305

306+
extern int cachefiles_ondemand_restore(struct cachefiles_cache *cache,
307+
char *args);
308+
306309
extern int cachefiles_ondemand_init_object(struct cachefiles_object *object);
307310
extern void cachefiles_ondemand_clean_object(struct cachefiles_object *object);
308311

fs/cachefiles/ondemand.c

+23
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,29 @@ int cachefiles_ondemand_copen(struct cachefiles_cache *cache, char *args)
182182
return ret;
183183
}
184184

185+
int cachefiles_ondemand_restore(struct cachefiles_cache *cache, char *args)
186+
{
187+
struct cachefiles_req *req;
188+
189+
XA_STATE(xas, &cache->reqs, 0);
190+
191+
if (!test_bit(CACHEFILES_ONDEMAND_MODE, &cache->flags))
192+
return -EOPNOTSUPP;
193+
194+
/*
195+
* Reset the requests to CACHEFILES_REQ_NEW state, so that the
196+
* requests have been processed halfway before the crash of the
197+
* user daemon could be reprocessed after the recovery.
198+
*/
199+
xas_lock(&xas);
200+
xas_for_each(&xas, req, ULONG_MAX)
201+
xas_set_mark(&xas, CACHEFILES_REQ_NEW);
202+
xas_unlock(&xas);
203+
204+
wake_up_all(&cache->daemon_pollwq);
205+
return 0;
206+
}
207+
185208
static int cachefiles_ondemand_get_fd(struct cachefiles_req *req)
186209
{
187210
struct cachefiles_object *object;

0 commit comments

Comments
 (0)