]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
cachefiles: cancel all requests for the object that is being dropped
authorBaokun Li <libaokun1@huawei.com>
Fri, 28 Jun 2024 06:29:27 +0000 (14:29 +0800)
committerChristian Brauner <brauner@kernel.org>
Wed, 3 Jul 2024 08:36:15 +0000 (10:36 +0200)
Because after an object is dropped, requests for that object are useless,
cancel them to avoid causing other problems.

This prepares for the later addition of cancel_work_sync(). After the
reopen requests is generated, cancel it to avoid cancel_work_sync()
blocking by waiting for daemon to complete the reopen requests.

Signed-off-by: Baokun Li <libaokun1@huawei.com>
Link: https://lore.kernel.org/r/20240628062930.2467993-7-libaokun@huaweicloud.com
Acked-by: Jeff Layton <jlayton@kernel.org>
Reviewed-by: Gao Xiang <hsiangkao@linux.alibaba.com>
Reviewed-by: Jia Zhu <zhujia.zj@bytedance.com>
Signed-off-by: Christian Brauner <brauner@kernel.org>
fs/cachefiles/ondemand.c

index 73da4d4eaa9bc8abec79e9bfd8e26c67557953b3..be1d327a221942c7e69a35662983517d33625da0 100644 (file)
@@ -564,12 +564,31 @@ int cachefiles_ondemand_init_object(struct cachefiles_object *object)
 
 void cachefiles_ondemand_clean_object(struct cachefiles_object *object)
 {
+       unsigned long index;
+       struct cachefiles_req *req;
+       struct cachefiles_cache *cache;
+
        if (!object->ondemand)
                return;
 
        cachefiles_ondemand_send_req(object, CACHEFILES_OP_CLOSE, 0,
                        cachefiles_ondemand_init_close_req, NULL);
+
+       if (!object->ondemand->ondemand_id)
+               return;
+
+       /* Cancel all requests for the object that is being dropped. */
+       cache = object->volume->cache;
+       xa_lock(&cache->reqs);
        cachefiles_ondemand_set_object_dropping(object);
+       xa_for_each(&cache->reqs, index, req) {
+               if (req->object == object) {
+                       req->error = -EIO;
+                       complete(&req->done);
+                       __xa_erase(&cache->reqs, index);
+               }
+       }
+       xa_unlock(&cache->reqs);
 }
 
 int cachefiles_ondemand_init_obj_info(struct cachefiles_object *object,