From 077813d7952a30ec9e5c12666f30b7c9cecb6499 Mon Sep 17 00:00:00 2001 From: Wensong Zhang Date: Fri, 13 Feb 2004 20:51:56 -0800 Subject: [PATCH] [IPVS] retry to run kernel_thread when memory is temporarily exhausted --- net/ipv4/ipvs/ip_vs_sync.c | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/net/ipv4/ipvs/ip_vs_sync.c b/net/ipv4/ipvs/ip_vs_sync.c index afc5e61ef5b13..2c1fdca48a3db 100644 --- a/net/ipv4/ipvs/ip_vs_sync.c +++ b/net/ipv4/ipvs/ip_vs_sync.c @@ -618,8 +618,6 @@ ip_vs_receive(struct socket *sock, char *buffer, const size_t buflen) } -static int errno; - static DECLARE_WAIT_QUEUE_HEAD(sync_wait); static pid_t sync_master_pid = 0; static pid_t sync_backup_pid = 0; @@ -766,10 +764,10 @@ static int sync_thread(void *startup) if (ip_vs_sync_state & IP_VS_STATE_MASTER && !sync_master_pid) { state = IP_VS_STATE_MASTER; - name = "ipvs syncmaster"; + name = "ipvs_syncmaster"; } else if (ip_vs_sync_state & IP_VS_STATE_BACKUP && !sync_backup_pid) { state = IP_VS_STATE_BACKUP; - name = "ipvs syncbackup"; + name = "ipvs_syncbackup"; } else { IP_VS_BUG(); ip_vs_use_count_dec(); @@ -827,10 +825,19 @@ static int sync_thread(void *startup) static int fork_sync_thread(void *startup) { + pid_t pid; + /* fork the sync thread here, then the parent process of the sync thread is the init process after this thread exits. */ - if (kernel_thread(sync_thread, startup, 0) < 0) - IP_VS_BUG(); + repeat: + if ((pid = kernel_thread(sync_thread, startup, 0)) < 0) { + IP_VS_ERR("could not create sync_thread due to %d... " + "retrying.\n", pid); + current->state = TASK_UNINTERRUPTIBLE; + schedule_timeout(HZ); + goto repeat; + } + return 0; } @@ -857,8 +864,14 @@ int start_sync_thread(int state, char *mcast_ifn, __u8 syncid) ip_vs_backup_syncid = syncid; } - if ((pid = kernel_thread(fork_sync_thread, &startup, 0)) < 0) - IP_VS_BUG(); + repeat: + if ((pid = kernel_thread(fork_sync_thread, &startup, 0)) < 0) { + IP_VS_ERR("could not create fork_sync_thread due to %d... " + "retrying.\n", pid); + current->state = TASK_UNINTERRUPTIBLE; + schedule_timeout(HZ); + goto repeat; + } wait_for_completion(&startup); -- 2.53.0