From: Jingbo Xu jefflexu@linux.alibaba.com
anolis inclusion category: feature bugzilla: https://gitee.com/openeuler/kernel/issues/IB5UKT
Reference: https://gitee.com/anolis/cloud-kernel/commit/732d3a3bc657
--------------------------------
ANBZ: #3211
Refactor the code arrangement of cachefiles_ondemand_daemon_read() a bit to make it more consistent with that of upstream.
This is in prep for the following fix which makes on-demand request distribution fairer.
Signed-off-by: Jingbo Xu jefflexu@linux.alibaba.com Reviewed-by: Gao Xiang hsiangkao@linux.alibaba.com Acked-by: Joseph Qi joseph.qi@linux.alibaba.com Link: https://gitee.com/anolis/cloud-kernel/pulls/881 Link: https://gitee.com/anolis/cloud-kernel/pulls/884 Signed-off-by: Baokun Li libaokun1@huawei.com --- fs/cachefiles/ondemand.c | 68 +++++++++++++++++++++------------------- 1 file changed, 36 insertions(+), 32 deletions(-)
diff --git a/fs/cachefiles/ondemand.c b/fs/cachefiles/ondemand.c index 3095519841ef..68b8c2a4e6a8 100644 --- a/fs/cachefiles/ondemand.c +++ b/fs/cachefiles/ondemand.c @@ -253,7 +253,7 @@ static int cachefiles_ondemand_get_fd(struct cachefiles_req *req) ssize_t cachefiles_ondemand_daemon_read(struct cachefiles_cache *cache, char __user *_buffer, size_t buflen, loff_t *pos) { - struct cachefiles_req *req; + struct cachefiles_req *req = NULL; struct cachefiles_msg *msg; unsigned long id = 0; size_t n; @@ -268,46 +268,50 @@ ssize_t cachefiles_ondemand_daemon_read(struct cachefiles_cache *cache, xa_lock(&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); + req = radix_tree_deref_slot_protected(slot, &cache->reqs.xa_lock); + WARN_ON(!req); + break; + }
- msg = &req->msg; - n = msg->len; + /* no request tagged with CACHEFILES_REQ_NEW found */ + if (!req) { + xa_unlock(&cache->reqs); + return 0; + }
- if (n > buflen) { - xa_unlock(&cache->reqs); - return -EMSGSIZE; - } + msg = &req->msg; + n = msg->len;
- radix_tree_iter_tag_clear(&cache->reqs, &iter, - CACHEFILES_REQ_NEW); + if (n > buflen) { xa_unlock(&cache->reqs); + return -EMSGSIZE; + }
- id = iter.index; - msg->msg_id = id; + radix_tree_iter_tag_clear(&cache->reqs, &iter, CACHEFILES_REQ_NEW); + xa_unlock(&cache->reqs);
- if (msg->opcode == CACHEFILES_OP_OPEN) { - ret = cachefiles_ondemand_get_fd(req); - if (ret) - goto error; - } + id = iter.index; + msg->msg_id = id;
- if (copy_to_user(_buffer, msg, n) != 0) { - ret = -EFAULT; - goto err_put_fd; - } + if (msg->opcode == CACHEFILES_OP_OPEN) { + ret = cachefiles_ondemand_get_fd(req); + if (ret) + goto error; + }
- /* CLOSE request has no reply */ - if (msg->opcode == CACHEFILES_OP_CLOSE) { - xa_lock(&cache->reqs); - radix_tree_delete(&cache->reqs, id); - xa_unlock(&cache->reqs); - complete(&req->done); - } - return n; + if (copy_to_user(_buffer, msg, n) != 0) { + ret = -EFAULT; + goto err_put_fd; } - xa_unlock(&cache->reqs); - return 0; + + /* CLOSE request has no reply */ + if (msg->opcode == CACHEFILES_OP_CLOSE) { + xa_lock(&cache->reqs); + radix_tree_delete(&cache->reqs, id); + xa_unlock(&cache->reqs); + complete(&req->done); + } + return n;
err_put_fd: if (msg->opcode == CACHEFILES_OP_OPEN)