]> Git Repo - linux.git/commitdiff
cachefiles: add restore command to recover inflight ondemand read requests
authorJia Zhu <[email protected]>
Mon, 20 Nov 2023 04:14:22 +0000 (12:14 +0800)
committerChristian Brauner <[email protected]>
Sat, 25 Nov 2023 15:03:57 +0000 (16:03 +0100)
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]>
fs/cachefiles/daemon.c
fs/cachefiles/internal.h
fs/cachefiles/ondemand.c

index 70caa1946207dce70c228e3282fd2c2c9f612c94..3f24905f40661302936f08122394947d55e3d5f3 100644 (file)
@@ -77,6 +77,7 @@ static const struct cachefiles_daemon_cmd cachefiles_daemon_cmds[] = {
        { "tag",        cachefiles_daemon_tag           },
 #ifdef CONFIG_CACHEFILES_ONDEMAND
        { "copen",      cachefiles_ondemand_copen       },
+       { "restore",    cachefiles_ondemand_restore     },
 #endif
        { "",           NULL                            }
 };
index 26e5f8f123ef17e4fdb4785862f4fd52cd6f236f..4a87c9d714a9498b80599d15461c48f0ea1c3f68 100644 (file)
@@ -303,6 +303,9 @@ extern ssize_t cachefiles_ondemand_daemon_read(struct cachefiles_cache *cache,
 extern int cachefiles_ondemand_copen(struct cachefiles_cache *cache,
                                     char *args);
 
+extern int cachefiles_ondemand_restore(struct cachefiles_cache *cache,
+                                       char *args);
+
 extern int cachefiles_ondemand_init_object(struct cachefiles_object *object);
 extern void cachefiles_ondemand_clean_object(struct cachefiles_object *object);
 
index 8e130de952f7dcfc541c15ca5b515e2e387f7fe0..b8fbbb1961bbcefc158fd32306d3a6abd63e607c 100644 (file)
@@ -182,6 +182,29 @@ out:
        return ret;
 }
 
+int cachefiles_ondemand_restore(struct cachefiles_cache *cache, char *args)
+{
+       struct cachefiles_req *req;
+
+       XA_STATE(xas, &cache->reqs, 0);
+
+       if (!test_bit(CACHEFILES_ONDEMAND_MODE, &cache->flags))
+               return -EOPNOTSUPP;
+
+       /*
+        * Reset the requests to CACHEFILES_REQ_NEW state, so that the
+        * requests have been processed halfway before the crash of the
+        * user daemon could be reprocessed after the recovery.
+        */
+       xas_lock(&xas);
+       xas_for_each(&xas, req, ULONG_MAX)
+               xas_set_mark(&xas, CACHEFILES_REQ_NEW);
+       xas_unlock(&xas);
+
+       wake_up_all(&cache->daemon_pollwq);
+       return 0;
+}
+
 static int cachefiles_ondemand_get_fd(struct cachefiles_req *req)
 {
        struct cachefiles_object *object;
This page took 0.062785 seconds and 4 git commands to generate.