All of lore.kernel.org
 help / color / mirror / Atom feed
From: Li Zhijian <lizhijian@cn.fujitsu.com>
To: <quintela@redhat.com>, <dgilbert@redhat.com>
Cc: qemu-devel@nongnu.org, Li Zhijian <lizhijian@cn.fujitsu.com>
Subject: [PATCH RESEND 4/4] migration/rdma: source: get accept cm_event from return path in non-block mode
Date: Thu, 20 May 2021 16:11:48 +0800	[thread overview]
Message-ID: <20210520081148.17001-4-lizhijian@cn.fujitsu.com> (raw)
In-Reply-To: <20210520081148.17001-1-lizhijian@cn.fujitsu.com>

source side always blocks if postcopy is only enabled at source side.
users are not able to cancel this migration in this case.

Here we try to get the cm_event every 100ms tile timeout.

Signed-off-by: Li Zhijian <lizhijian@cn.fujitsu.com>
---
 migration/rdma.c | 59 ++++++++++++++++++++++++++++++++++++++++++++----
 1 file changed, 55 insertions(+), 4 deletions(-)

diff --git a/migration/rdma.c b/migration/rdma.c
index 3b228c46eb..181ad03849 100644
--- a/migration/rdma.c
+++ b/migration/rdma.c
@@ -2458,7 +2458,54 @@ err_rdma_source_init:
     return -1;
 }
 
-static int qemu_rdma_connect(RDMAContext *rdma, Error **errp)
+#define RDMA_GET_EVENT_INTERVAL 100000 /* 100ms */
+static int qemu_get_cm_event_timeout(RDMAContext *rdma,
+                                     struct rdma_cm_event **cm_event,
+                                     long sec, Error **errp)
+{
+    long wait_ns = 0;
+    int ret;
+    int flags = fcntl(rdma->channel->fd, F_GETFL), save_flags;
+
+    if (flags == -1) {
+        perror("failed to get file flags");
+        return flags;
+    }
+    save_flags = flags;
+    flags |= O_NONBLOCK;
+    ret = fcntl(rdma->channel->fd, F_SETFL, flags);
+    if (ret) {
+        perror("failed to set file flags nonblocking");
+        return ret;
+    }
+
+retry:
+    ret = rdma_get_cm_event(rdma->channel, cm_event);
+    if (ret && errno == EAGAIN) {
+        if (wait_ns < sec * 1000000) {
+            perror("rdma_get_cm_event after rdma_connect");
+            wait_ns += RDMA_GET_EVENT_INTERVAL;
+            usleep(RDMA_GET_EVENT_INTERVAL);
+            goto retry;
+        }
+    }
+    if (ret) {
+        perror("rdma_get_cm_event after rdma_connect");
+        ERROR(errp, "connecting to destination!");
+        return ret;
+    }
+
+    /* restore flags */
+    ret = fcntl(rdma->channel->fd, F_SETFL, save_flags);
+    if (ret) {
+        rdma_ack_cm_event(*cm_event);
+        perror("failed to restore file flags");
+    }
+
+    return ret;
+}
+
+static int qemu_rdma_connect(RDMAContext *rdma, Error **errp, bool return_path)
 {
     RDMACapabilities cap = {
                                 .version = RDMA_CONTROL_VERSION_CURRENT,
@@ -2496,7 +2543,11 @@ static int qemu_rdma_connect(RDMAContext *rdma, Error **errp)
         goto err_rdma_source_connect;
     }
 
-    ret = rdma_get_cm_event(rdma->channel, &cm_event);
+    if (return_path) {
+        ret = qemu_get_cm_event_timeout(rdma, &cm_event, 2, errp);
+    } else {
+        ret = rdma_get_cm_event(rdma->channel, &cm_event);
+    }
     if (ret) {
         perror("rdma_get_cm_event after rdma_connect");
         ERROR(errp, "connecting to destination!");
@@ -4108,7 +4159,7 @@ void rdma_start_outgoing_migration(void *opaque,
     }
 
     trace_rdma_start_outgoing_migration_after_rdma_source_init();
-    ret = qemu_rdma_connect(rdma, errp);
+    ret = qemu_rdma_connect(rdma, errp, false);
 
     if (ret) {
         goto err;
@@ -4129,7 +4180,7 @@ void rdma_start_outgoing_migration(void *opaque,
             goto return_path_err;
         }
 
-        ret = qemu_rdma_connect(rdma_return_path, errp);
+        ret = qemu_rdma_connect(rdma_return_path, errp, true);
 
         if (ret) {
             goto return_path_err;
-- 
2.30.2





  parent reply	other threads:[~2021-05-20  8:25 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-20  8:11 [PATCH RESEND 1/4] migration/rdma: cleanup rmda in rdma_start_incoming_migration error path Li Zhijian
2021-05-20  8:11 ` [PATCH RESEND 2/4] migration/rdma: Fix rdma_addrinfo res leaks Li Zhijian
2021-05-24 19:03   ` Dr. David Alan Gilbert
2021-05-20  8:11 ` [PATCH RESEND 3/4] migration/rdma: destination: create the return patch after the first accept Li Zhijian
2021-05-20  8:30   ` lizhijian
2021-05-24 19:08     ` Dr. David Alan Gilbert
2021-05-20  8:11 ` Li Zhijian [this message]
2021-05-24 19:06 ` [PATCH RESEND 1/4] migration/rdma: cleanup rmda in rdma_start_incoming_migration error path Dr. David Alan Gilbert

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210520081148.17001-4-lizhijian@cn.fujitsu.com \
    --to=lizhijian@cn.fujitsu.com \
    --cc=dgilbert@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=quintela@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.