From: Jia Zhu zhujia.zj@bytedance.com
anolis inclusion category: feature bugzilla: https://gitee.com/openeuler/kernel/issues/IB5UKT
Reference: https://gitee.com/anolis/cloud-kernel/commit/f8ecbc39993a
--------------------------------
ANBZ: #3213
cherry-picked from [1]
Don't trigger EPOLLIN when there are only reopening read requests in xarray.
Suggested-by: Xin Yin yinxin.x@bytedance.com Signed-off-by: Jia Zhu zhujia.zj@bytedance.com Reviewed-by: Jingbo Xu jefflexu@linux.alibaba.com Link: [1] https://lore.kernel.org/lkml/20221014080559.42108-5-zhujia.zj@bytedance.com/... Signed-off-by: Jingbo Xu jefflexu@linux.alibaba.com Acked-by: Gao Xiang hsiangkao@linux.alibaba.com Acked-by: Joseph Qi joseph.qi@linux.alibaba.com Link: https://gitee.com/anolis/cloud-kernel/pulls/894 Signed-off-by: Zizhi Wo wozizhi@huawei.com Signed-off-by: Baokun Li libaokun1@huawei.com --- fs/cachefiles/daemon.c | 16 ++++++++++++++-- fs/cachefiles/internal.h | 12 ++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-)
diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c index b531373400d7..075c227a336b 100644 --- a/fs/cachefiles/daemon.c +++ b/fs/cachefiles/daemon.c @@ -359,14 +359,26 @@ static __poll_t cachefiles_daemon_poll(struct file *file, struct poll_table_struct *poll) { struct cachefiles_cache *cache = file->private_data; + struct cachefiles_req *req; + struct radix_tree_iter iter; __poll_t mask; + void **slot;
poll_wait(file, &cache->daemon_pollwq, poll); mask = 0;
if (cachefiles_in_ondemand_mode(cache)) { - if (!radix_tree_empty(&cache->reqs)) - mask |= EPOLLIN; + if (!radix_tree_empty(&cache->reqs)) { + radix_tree_for_each_tagged(slot, &cache->reqs, &iter, 0, + CACHEFILES_REQ_NEW) { + req = radix_tree_deref_slot_protected(slot, + &cache->reqs.xa_lock); + if (!cachefiles_ondemand_is_reopening_read(req)) { + mask |= EPOLLIN; + break; + } + } + } } else { if (test_bit(CACHEFILES_STATE_CHANGED, &cache->flags)) mask |= EPOLLIN; diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h index 9f460188e1a8..435e8168f26f 100644 --- a/fs/cachefiles/internal.h +++ b/fs/cachefiles/internal.h @@ -293,6 +293,13 @@ cachefiles_ondemand_set_object_##_state(struct cachefiles_object *object) \ CACHEFILES_OBJECT_STATE_FUNCS(open); CACHEFILES_OBJECT_STATE_FUNCS(close); CACHEFILES_OBJECT_STATE_FUNCS(reopening); + +static inline bool cachefiles_ondemand_is_reopening_read(struct cachefiles_req *req) +{ + return cachefiles_ondemand_object_is_reopening(req->object) && + req->msg.opcode == CACHEFILES_OP_READ; +} + #else static inline ssize_t cachefiles_ondemand_daemon_read(struct cachefiles_cache *cache, char __user *_buffer, size_t buflen, loff_t *pos) @@ -318,6 +325,11 @@ static inline int cachefiles_ondemand_init_obj_info(struct cachefiles_object *ob { return 0; } + +static inline bool cachefiles_ondemand_is_reopening_read(struct cachefiles_req *req) +{ + return false; +} #endif
/*