[CRIU] [PATCH 12/12] sockets: Helper for scheduling acc job
Pavel Emelyanov
xemul at parallels.com
Tue Feb 7 07:00:13 EST 2012
There's only one place with this, but the helper makes the code look
almost perfectly.
Signed-off-by: Pavel Emelyanov <xemul at parallels.com>
---
-------------- next part --------------
From 398b890f1cb70aaaaa58c56089297697f8e68880 Mon Sep 17 00:00:00 2001
From: root <root at dhcp-10-30-23-222.sw.ru>
Date: Tue, 7 Feb 2012 14:40:17 +0300
Subject: [PATCH 12/12] schedule acc job helper
---
sockets.c | 64 +++++++++++++++++++++++++++++++-----------------------------
1 files changed, 33 insertions(+), 31 deletions(-)
diff --git a/sockets.c b/sockets.c
index ba25a5f..62d0afe 100644
--- a/sockets.c
+++ b/sockets.c
@@ -784,6 +784,36 @@ struct unix_accept_job {
static struct unix_accept_job *accept_jobs;
+static int schedule_acc_job(int sk, struct unix_sk_entry *ue)
+{
+ struct sockaddr_un addr;
+ int len;
+ struct unix_accept_job *aj;
+
+ prep_conn_addr(ue->id, &addr, &len);
+ if (bind(sk, (struct sockaddr *)&addr, len) < 0) {
+ pr_perror("Can't bind socket");
+ goto err;
+ }
+
+ if (listen(sk, 1) < 0) {
+ pr_perror("Can't listen socket");
+ goto err;
+ }
+
+ aj = xmalloc(sizeof(*aj));
+ if (aj == NULL)
+ goto err;
+
+ aj->fd = ue->fd;
+ aj->next = accept_jobs;
+ accept_jobs = aj;
+ unix_show_job("Sched acc", ue->fd, ue->id);
+ return 0;
+err:
+ return -1;
+}
+
static int run_accept_jobs(void)
{
struct unix_accept_job *aj, *next;
@@ -892,37 +922,9 @@ static int open_unix_sk_stream(int sk, struct unix_sk_entry *ue, int img_fd)
* deferred to connect() later.
*/
- if (ue->peer < ue->id && !(ue->flags & USK_INFLIGHT)) {
- struct sockaddr_un addr;
- int len;
- struct unix_accept_job *aj;
-
- /*
- * Will become a server
- */
-
- ret = -1;
- prep_conn_addr(ue->id, &addr, &len);
- if (bind(sk, (struct sockaddr *)&addr, len) < 0) {
- pr_perror("Can't bind socket");
- goto out;
- }
-
- if (listen(sk, 1) < 0) {
- pr_perror("Can't listen socket");
- goto out;
- }
-
- aj = xmalloc(sizeof(*aj));
- if (aj == NULL)
- goto out;
-
- aj->fd = ue->fd;
- aj->next = accept_jobs;
- accept_jobs = aj;
- unix_show_job("Sched acc", ue->fd, ue->id);
- ret = 0;
- } else
+ if (ue->peer < ue->id && !(ue->flags & USK_INFLIGHT))
+ ret = schedule_acc_job(sk, ue);
+ else
ret = schedule_conn_job((ue->flags & USK_INFLIGHT) ?
CJ_STREAM_INFLIGHT : CJ_STREAM, ue);
} else {
--
1.6.5.2
More information about the CRIU
mailing list