The commit is pushed to "branch-rh9-5.14.0-427.44.1.vz9.80.x-ovz" and will 
appear at g...@bitbucket.org:openvz/vzkernel.git
after rh9-5.14.0-427.44.1.vz9.80.24
------>
commit 79d0b81cf496e6037f8fe88b3233987b48cd0cee
Author: Liu Kui <kui....@virtuozzo.com>
Date:   Sat Apr 5 10:22:03 2025 +0800

    fs/fuse kio: refactor code related to the 'krpc_send' kthread
    
    This patch is purely for code beautification patch that won't
    affect any functionality.
    
    Signed-off-by: Liu Kui <kui....@virtuozzo.com>
    Acked-by: Alexey Kuznetsov <kuz...@virtuozzo.com>
    
    Feature: fuse: kRPC - single RPC for kernel and userspace
---
 fs/fuse/kio/pcs/pcs_krpc.c | 66 ++++++++++++++++++++++++----------------------
 1 file changed, 35 insertions(+), 31 deletions(-)

diff --git a/fs/fuse/kio/pcs/pcs_krpc.c b/fs/fuse/kio/pcs/pcs_krpc.c
index 78180bdb4993..087d1d966e0d 100644
--- a/fs/fuse/kio/pcs/pcs_krpc.c
+++ b/fs/fuse/kio/pcs/pcs_krpc.c
@@ -632,18 +632,18 @@ static void kreq_submit(struct krpc_req *kreq)
 static int krpc_threadfn(void *data)
 {
        struct pcs_krpc_set *krpcs = data;
+       struct llist_node *ll;
+       struct krpc_req *kreq, *kreq_next;
 
        kthread_use_mm(krpcs->mm);
 
        for (;;) {
-               struct llist_node *ll;
-
                set_current_state(TASK_INTERRUPTIBLE);
 
                ll = llist_del_all(&krpcs->req_llist);
 
-               if (ll == NULL) {
-                       if (kthread_should_stop()) {
+               if (!ll) {
+                       if (unlikely(kthread_should_stop())) {
                                __set_current_state(TASK_RUNNING);
                                break;
                        }
@@ -654,52 +654,56 @@ static int krpc_threadfn(void *data)
                __set_current_state(TASK_RUNNING);
 
                ll = llist_reverse_order(ll);
-               while (ll) {
-                       struct llist_node *next = ll->next;
-                       struct krpc_req *kreq = container_of(ll, struct 
krpc_req, llist_link);
-
+               llist_for_each_entry_safe(kreq, kreq_next, ll, llist_link)
                        kreq_submit(kreq);
-
-                       ll = next;
-               }
        }
 
        kthread_unuse_mm(krpcs->mm);
        return 0;
 }
 
+static struct task_struct *pcs_krpc_task_create(struct pcs_krpc_set *krpcs)
+{
+       struct task_struct *tsk;
+       struct mm_struct *mm;
+
+       WARN_ON_ONCE(krpcs->krpc_task);
+
+       mm = get_task_mm(current);
+       if (!mm)
+               return NULL;
+
+       tsk = kthread_create(krpc_threadfn, krpcs, "krpc_send");
+       if (!tsk || IS_ERR(tsk)) {
+               mmput(mm);
+               return NULL;
+       }
+
+       krpcs->krpc_task = get_task_struct(tsk);
+       krpcs->mm = mm;
+       atomic_inc(&current->files->count);
+       tsk->files = current->files;
+
+       return tsk;
+}
+
 static int pcs_krpc_ioctl_send_msg(struct krpc_req *kreq)
 {
        struct task_struct *tsk;
-       struct pcs_cluster_core *cc;
+       struct pcs_krpc_set *krpcs = kreq->krpc->krpcs;
 
        if (pcs_krpc_use_thread) {
-               cc = container_of(kreq->krpc->krpcs, struct pcs_cluster_core, 
krpcs);
-               tsk = cc->krpcs.krpc_task;
-               if (unlikely(tsk == NULL)) {
-                       cc->krpcs.mm = get_task_mm(current);
-                       if (cc->krpcs.mm) {
-                               tsk = kthread_create(krpc_threadfn, &cc->krpcs, 
"krpc_send");
-                               if (tsk && !IS_ERR(tsk)) {
-                                       cc->krpcs.krpc_task = 
get_task_struct(tsk);
-                                       atomic_inc(&current->files->count);
-                                       tsk->files = current->files;
-                               } else {
-                                       mmput(cc->krpcs.mm);
-                                       cc->krpcs.mm = NULL;
-                               }
-                       }
-               }
+               tsk = krpcs->krpc_task;
+               if (unlikely(!tsk))
+                       tsk = pcs_krpc_task_create(krpcs);
 
                if (likely(tsk)) {
-                       llist_add(&kreq->llist_link, 
&kreq->krpc->krpcs->req_llist);
+                       llist_add(&kreq->llist_link, &krpcs->req_llist);
                        wake_up_process(tsk);
                        return 0;
                }
        }
-
        kreq_submit(kreq);
-
        return 0;
 }
 
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel

Reply via email to