All Virtuozzo development lists (kernel + QEMU)
 help / color / mirror / Atom feed
From: "Denis V. Lunev" <den@openvz.org>
To: svt-core@virtuozzo.com
Cc: andrey.drobyshev@virtuozzo.com, den@openvz.org
Subject: [PATCH hci-8.1 2/2] tests/qtest/migration: test cancel before the channel connects #VSTOR-155277
Date: Wed, 25 Nov 2026 20:32:04 +0100	[thread overview]
Message-ID: <20261125193204.1424799-3-den@openvz.org> (raw)
In-Reply-To: <20261125193204.1424799-1-den@openvz.org>

From: Denis V. Lunev <den@openvz.org>

Cancel a migration while the source is still connecting, then let the
connection succeed. The source must end up in "cancelled", and a
second migration afterwards must complete.

To keep the source waiting in connect(), the test points it at a unix
socket of its own whose listen queue is already full. On Linux,
connect() then blocks until the test accepts a connection, so the test
is Linux-only.

The return-path capability is on because the hang this test guards
against is the cleanup waiting for the return path thread.

Signed-off-by: Denis V. Lunev <den@openvz.org>
Cc: Peter Xu <peterx@redhat.com>
Cc: Fabiano Rosas <farosas@suse.de>
Cc: Laurent Vivier <lvivier@redhat.com>
---
 tests/qtest/migration/precopy-tests.c | 67 +++++++++++++++++++++++++++
 1 file changed, 67 insertions(+)

diff --git a/tests/qtest/migration/precopy-tests.c b/tests/qtest/migration/precopy-tests.c
index bb38292550c..2b0afdbd48d 100644
--- a/tests/qtest/migration/precopy-tests.c
+++ b/tests/qtest/migration/precopy-tests.c
@@ -821,6 +821,69 @@ static void test_cancel_src_after_status(void *opaque)
     migrate_end(from, to, false);
 }
 
+#ifdef CONFIG_LINUX
+/* On Linux connect() to a unix socket with a full backlog blocks */
+static int unix_listen_full(const char *path, int *filler)
+{
+    struct sockaddr_un addr = { .sun_family = AF_UNIX };
+    int lfd = socket(AF_UNIX, SOCK_STREAM, 0);
+
+    *filler = socket(AF_UNIX, SOCK_STREAM, 0);
+    g_assert_cmpint(lfd, >=, 0);
+    g_assert_cmpint(*filler, >=, 0);
+
+    g_assert_cmpuint(strlen(path), <, sizeof(addr.sun_path));
+    strcpy(addr.sun_path, path);
+    g_assert_cmpint(bind(lfd, (struct sockaddr *)&addr, sizeof(addr)), ==, 0);
+    g_assert_cmpint(listen(lfd, 0), ==, 0);
+    g_assert_cmpint(connect(*filler, (struct sockaddr *)&addr, sizeof(addr)),
+                    ==, 0);
+    return lfd;
+}
+
+static void test_cancel_src_before_connect(void)
+{
+    g_autofree char *full_path = g_strdup_printf("%s/migsocket-full", tmpfs);
+    g_autofree char *full_uri = g_strdup_printf("unix:%s", full_path);
+    g_autofree char *uri = g_strdup_printf("unix:%s/migsocket", tmpfs);
+    QTestState *from, *to;
+    MigrateStart args = {};
+    int lfd, filler, accepted;
+
+    if (migrate_start(&from, &to, "defer", &args)) {
+        return;
+    }
+
+    migrate_set_capability(from, "return-path", true);
+    migrate_set_capability(to, "return-path", true);
+
+    lfd = unix_listen_full(full_path, &filler);
+    migrate_qmp(from, to, full_uri, NULL, "{}");
+    migrate_cancel(from);
+
+    /* Taking the filler off the backlog lets the source's connect() finish */
+    accepted = accept(lfd, NULL, NULL);
+    g_assert_cmpint(accepted, >=, 0);
+
+    wait_for_migration_status(from, "cancelled",
+                              (const char * []) { "completed", NULL });
+
+    close(accepted);
+    close(filler);
+    close(lfd);
+    unlink(full_path);
+
+    migrate_incoming_qmp(to, uri, NULL, "{}");
+    wait_for_serial("src_serial");
+    migrate_ensure_converge(from);
+    migrate_qmp(from, to, uri, NULL, "{}");
+    wait_for_migration_complete(from);
+    wait_for_migration_complete(to);
+
+    migrate_end(from, to, true);
+}
+#endif
+
 static void calc_dirty_rate(QTestState *who, uint64_t calc_time)
 {
     qtest_qmp_assert_success(who,
@@ -1334,4 +1397,8 @@ void migration_test_add_precopy(MigrationTestEnv *env)
                                       test_cancel_src_after_status);
         }
     }
+#ifdef CONFIG_LINUX
+    migration_test_add("/migration/cancel/src/before/connect",
+                       test_cancel_src_before_connect);
+#endif
 }
-- 
2.55.0


  parent reply	other threads:[~2026-11-25 19:32 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-25 19:32 [PATCH hci-8.1/hci-dev 0/2] migration: fix a source hang on " Denis V. Lunev
2026-11-25 19:32 ` [PATCH hci-8.1 1/2] migration: fix " Denis V. Lunev
2026-12-01  0:30   ` no-reply
2026-11-25 19:32 ` Denis V. Lunev [this message]
2026-12-01  0:31   ` [PATCH hci-8.1 2/2] tests/qtest/migration: test " no-reply
2026-11-25 20:14 ` [PATCH hci-8.1/hci-dev 0/2] migration: fix a source hang on " Andrey Drobyshev

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=20261125193204.1424799-3-den@openvz.org \
    --to=den@openvz.org \
    --cc=andrey.drobyshev@virtuozzo.com \
    --cc=svt-core@virtuozzo.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.