From nobody Sun Sep 28 15:28:10 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1758275840; cv=none; d=zohomail.com; s=zohoarc; b=AsYiu7y0aoWl1pZ9rdhQ6pQy835S0PCll+ZCBY4X4oOPf3lblQB84f4PapLI9pr4KMB1v0CA7w0atmbaKxbDvYyBifNnGFP4LW16rQKsjN1j/Ty3FK5xzAHZGZdC1YnrtuOmkNcTClaTo9A07p70IEvLhEm0/MV4534vp0Y5lhQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1758275840; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=VnjjGEpdrx+Fz6XfH6ULYBNOdX6UQVMGJsU+DGOMTo8=; b=RXJLwiN61S1FG0zEjt8H/9PjfCSWHWV9BtbSYCjorw8TK9eaIizM+yfUuH/NLcg9T3hiaeziwVfCsTsKc+ABsQKKd4ni75PGE5ya34zAuxY6WDFacQ3HYhhyMqytGUKEQnXbur1uLdaLC5eFrCJaP5lcFb5oRZMf7AYfEamXRUQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1758275840544224.45312220945686; Fri, 19 Sep 2025 02:57:20 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uzXqf-0005l0-TO; Fri, 19 Sep 2025 05:56:14 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uzXqW-0005eh-IW for qemu-devel@nongnu.org; Fri, 19 Sep 2025 05:56:06 -0400 Received: from forwardcorp1d.mail.yandex.net ([178.154.239.200]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uzXqQ-0004Z3-JE for qemu-devel@nongnu.org; Fri, 19 Sep 2025 05:56:03 -0400 Received: from mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net [IPv6:2a02:6b8:c0c:1621:0:640:12d9:0]) by forwardcorp1d.mail.yandex.net (Yandex) with ESMTPS id B643C80ECB; Fri, 19 Sep 2025 12:55:51 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:a72::1:38]) by mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id ntP1fK1GvGk0-5g2G55JV; Fri, 19 Sep 2025 12:55:51 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1758275751; bh=VnjjGEpdrx+Fz6XfH6ULYBNOdX6UQVMGJsU+DGOMTo8=; h=Cc:Message-ID:References:Date:In-Reply-To:Subject:To:From; b=0zQn9gXdpoykszQEZvpTtOhRkJbXvdptdslz0BhK+kdVOtlLLW79SsGPzapsuqJGJ jwTR0kYdKmwiID5TnDvLqhujPW48VlHTa/budoqZCaZuEiQZr5RhL9ZggmenMr7kND x7m0+rOQPwVM9Z07TstGXgXXSuLcJS6qiARoMBDI= Authentication-Results: mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: mst@redhat.com Cc: qemu-devel@nongnu.org, philmd@linaro.org, thuth@redhat.com, eblake@redhat.com, michael.roth@amd.com, armbru@redhat.com, farosas@suse.de, peterx@redhat.com, berrange@redhat.com, jasowang@redhat.com, steven.sistare@oracle.com, leiyang@redhat.com, davydov-max@yandex-team.ru, yc-core@yandex-team.ru, Vladimir Sementsov-Ogievskiy Subject: [PATCH v5 01/19] migration/qemu-file: don't make incoming fds blocking again Date: Fri, 19 Sep 2025 12:55:27 +0300 Message-ID: <20250919095545.1912042-2-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250919095545.1912042-1-vsementsov@yandex-team.ru> References: <20250919095545.1912042-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=178.154.239.200; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1d.mail.yandex.net X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @yandex-team.ru) X-ZM-MESSAGEID: 1758275842412116600 In migration we want to pass fd "as is", not changing its blocking status. The only current user of these fds is CPR state (through VMSTATE_FD), which of-course doesn't want to modify fds on target when source is still running and use these fds. Suggested-by: Daniel P. Berrang=C3=A9 Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Peter Xu Reviewed-by: Daniel P. Berrang=C3=A9 --- include/io/channel.h | 1 + io/channel-socket.c | 13 +++++++++---- migration/qemu-file.c | 3 ++- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/include/io/channel.h b/include/io/channel.h index 234e5db70d..12266256a8 100644 --- a/include/io/channel.h +++ b/include/io/channel.h @@ -36,6 +36,7 @@ OBJECT_DECLARE_TYPE(QIOChannel, QIOChannelClass, =20 #define QIO_CHANNEL_READ_FLAG_MSG_PEEK 0x1 #define QIO_CHANNEL_READ_FLAG_RELAXED_EOF 0x2 +#define QIO_CHANNEL_READ_FLAG_FD_PRESERVE_BLOCKING 0x4 =20 typedef enum QIOChannelFeature QIOChannelFeature; =20 diff --git a/io/channel-socket.c b/io/channel-socket.c index 3b7ca924ff..21f8f2e0c5 100644 --- a/io/channel-socket.c +++ b/io/channel-socket.c @@ -464,7 +464,8 @@ static void qio_channel_socket_finalize(Object *obj) =20 #ifndef WIN32 static void qio_channel_socket_copy_fds(struct msghdr *msg, - int **fds, size_t *nfds) + int **fds, size_t *nfds, + bool preserve_blocking) { struct cmsghdr *cmsg; =20 @@ -497,8 +498,10 @@ static void qio_channel_socket_copy_fds(struct msghdr = *msg, continue; } =20 - /* O_NONBLOCK is preserved across SCM_RIGHTS so reset it */ - qemu_socket_set_block(fd); + if (!preserve_blocking) { + /* O_NONBLOCK is preserved across SCM_RIGHTS so reset it */ + qemu_socket_set_block(fd); + } =20 #ifndef MSG_CMSG_CLOEXEC qemu_set_cloexec(fd); @@ -556,7 +559,9 @@ static ssize_t qio_channel_socket_readv(QIOChannel *ioc, } =20 if (fds && nfds) { - qio_channel_socket_copy_fds(&msg, fds, nfds); + qio_channel_socket_copy_fds( + &msg, fds, nfds, + flags & QIO_CHANNEL_READ_FLAG_FD_PRESERVE_BLOCKING); } =20 return ret; diff --git a/migration/qemu-file.c b/migration/qemu-file.c index b6ac190034..d5c6e7ec61 100644 --- a/migration/qemu-file.c +++ b/migration/qemu-file.c @@ -340,7 +340,8 @@ static ssize_t coroutine_mixed_fn qemu_fill_buffer(QEMU= File *f) =20 do { struct iovec iov =3D { f->buf + pending, IO_BUF_SIZE - pending }; - len =3D qio_channel_readv_full(f->ioc, &iov, 1, pfds, pnfd, 0, + len =3D qio_channel_readv_full(f->ioc, &iov, 1, pfds, pnfd, + QIO_CHANNEL_READ_FLAG_FD_PRESERVE_BLO= CKING, &local_error); if (len =3D=3D QIO_CHANNEL_ERR_BLOCK) { if (qemu_in_coroutine()) { --=20 2.48.1 From nobody Sun Sep 28 15:28:10 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1758275917; cv=none; d=zohomail.com; s=zohoarc; b=YFSN77eNLpHC4ytCdW0YqEHR+qdsTFxkWTScO+7Fpb9oQVZN30oe9Yu1PDZotEuXjXAUmZw14UT0hLyImv8mQj1nyORH8l8GFTLbuCKcRfm4p7ULKT/nPWlA4fpWIaZNtMQxPlf+HvuL6NILE/gGZSdmlpCTUYcztC//wMApPPU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1758275917; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=qObQrvMVyRCGspmUr6lxee7IIWmsVN+19cLKPz0e+Z4=; b=Zm5BMZ6JYRRE61iBZ80VWVAjAr5sHjCsb4bhVf+EEsmGrqJSob1H/7Kg8uqs0bznd2556ZP1PB+qHK08wxfNr8Rf30obc4ktWnZXqG2+pWBsa3ax24sr7uPqVM+hOxtsnfKFA9s9aBmEstM7vADXi6PVUgQA703A8In+xL6+C9s= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1758275917898522.2709783378896; Fri, 19 Sep 2025 02:58:37 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uzXql-00066e-Kz; Fri, 19 Sep 2025 05:56:19 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uzXqW-0005ef-Is for qemu-devel@nongnu.org; Fri, 19 Sep 2025 05:56:06 -0400 Received: from forwardcorp1d.mail.yandex.net ([178.154.239.200]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uzXqQ-0004ZC-Ok for qemu-devel@nongnu.org; Fri, 19 Sep 2025 05:56:03 -0400 Received: from mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net [IPv6:2a02:6b8:c0c:1621:0:640:12d9:0]) by forwardcorp1d.mail.yandex.net (Yandex) with ESMTPS id 9E70C80E9F; Fri, 19 Sep 2025 12:55:52 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:a72::1:38]) by mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id ntP1fK1GvGk0-qt91nNcN; Fri, 19 Sep 2025 12:55:52 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1758275752; bh=qObQrvMVyRCGspmUr6lxee7IIWmsVN+19cLKPz0e+Z4=; h=Cc:Message-ID:References:Date:In-Reply-To:Subject:To:From; b=eKb8P3lOT6S6YyZ1rHL/MvGWdRaha+3l4FkMfSBSYC1P6+ZTlYWImFPSCxWvGvQ/U j023zQowvpGFONMololm0dy+0eJNry5PF1gvpZmjhi2gL6zS0KZAOu/l6Te2PXKfT5 xHYQtB45/QIaojWpR1Iet3BClQejA4KuBEjATrZQ= Authentication-Results: mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: mst@redhat.com Cc: qemu-devel@nongnu.org, philmd@linaro.org, thuth@redhat.com, eblake@redhat.com, michael.roth@amd.com, armbru@redhat.com, farosas@suse.de, peterx@redhat.com, berrange@redhat.com, jasowang@redhat.com, steven.sistare@oracle.com, leiyang@redhat.com, davydov-max@yandex-team.ru, yc-core@yandex-team.ru, Vladimir Sementsov-Ogievskiy Subject: [PATCH v5 02/19] io/channel: document how qio_channel_readv_full() handles fds Date: Fri, 19 Sep 2025 12:55:28 +0300 Message-ID: <20250919095545.1912042-3-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250919095545.1912042-1-vsementsov@yandex-team.ru> References: <20250919095545.1912042-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=178.154.239.200; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1d.mail.yandex.net X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @yandex-team.ru) X-ZM-MESSAGEID: 1758275918455116600 The only realization, which may have incoming fds is qio_channel_socket_readv() (in io/channel-socket.c). qio_channel_socket_readv() do call (through qio_channel_socket_copy_fds()) qemu_socket_set_block() and qemu_set_cloexec() for each fd. Also, qio_channel_socket_copy_fds() is called at the end of qio_channel_socket_readv(), on success path. Signed-off-by: Vladimir Sementsov-Ogievskiy Acked-by: Peter Xu Reviewed-by: Daniel P. Berrang=C3=A9 --- include/io/channel.h | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/include/io/channel.h b/include/io/channel.h index 12266256a8..c7f64506f7 100644 --- a/include/io/channel.h +++ b/include/io/channel.h @@ -118,6 +118,15 @@ struct QIOChannelClass { size_t nfds, int flags, Error **errp); + + /* + * The io_readv handler must guarantee that all + * incoming fds are set BLOCKING (unless + * QIO_CHANNEL_READ_FLAG_FD_PRESERVE_BLOCKING flag is set) and + * CLOEXEC (if available). + * @fds and @nfds are set only on success path, and untouched + * in case of errors. + */ ssize_t (*io_readv)(QIOChannel *ioc, const struct iovec *iov, size_t niov, @@ -125,6 +134,7 @@ struct QIOChannelClass { size_t *nfds, int flags, Error **errp); + int (*io_close)(QIOChannel *ioc, Error **errp); GSource * (*io_create_watch)(QIOChannel *ioc, @@ -235,6 +245,13 @@ void qio_channel_set_name(QIOChannel *ioc, * was allocated. It is the callers responsibility * to call close() on each file descriptor and to * call g_free() on the array pointer in @fds. + * @fds allocated and set (and @nfds is set too) + * _only_ on success path. These parameters are + * untouched in case of errors. + * qio_channel_readv_full() guarantees that all + * incoming fds are set BLOCKING (unless + * QIO_CHANNEL_READ_FLAG_FD_PRESERVE_BLOCKING flag + * is set) and CLOEXEC (if available). * * It is an error to pass a non-NULL @fds parameter * unless qio_channel_has_feature() returns a true --=20 2.48.1 From nobody Sun Sep 28 15:28:10 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1758275850; cv=none; d=zohomail.com; s=zohoarc; b=LMDWN+YeFUMMVjJDfhgVGLuBt6s+UJ4ULtBUs1OC09ebCQCP+oj/iR7L0KLCrDTGDFwNJP6iBH6KbfonEWh2Vihc2zMMLDQ1MXzdGiBC8apKptAF1dyj0kG/kU2m2bvuYvHEvSWoaMcDYb0PHBOYDfdjU1KUvat6svW/iOs9vbE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1758275850; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=cq2SnBEaLRu/0mSFxt8cmSAJ0yXaJUJztucOvIMJ7YE=; b=guNAeh5QJONRDe0wEsRtq0WLOcAaFzMwBPT1sH9ufUhA1HdCCpDBmdgTnNsQtwoiKFGIMdEewBHxcE6HkWJP+O4wmbfuKQJwQVGvvKPQFlMrFhzNdaUdQGo8LyopvFZ8tDU5obmR4Uohl99GKnsBMgVx9qdbkajC9O2vgGW61N0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1758275850373456.897723486652; Fri, 19 Sep 2025 02:57:30 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uzXr3-0006Dz-O6; Fri, 19 Sep 2025 05:56:37 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uzXqY-0005ex-Ho for qemu-devel@nongnu.org; Fri, 19 Sep 2025 05:56:07 -0400 Received: from forwardcorp1d.mail.yandex.net ([178.154.239.200]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uzXqR-0004ZJ-NU for qemu-devel@nongnu.org; Fri, 19 Sep 2025 05:56:04 -0400 Received: from mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net [IPv6:2a02:6b8:c0c:1621:0:640:12d9:0]) by forwardcorp1d.mail.yandex.net (Yandex) with ESMTPS id 4C92180EC8; Fri, 19 Sep 2025 12:55:53 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:a72::1:38]) by mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id ntP1fK1GvGk0-S0UNffSb; Fri, 19 Sep 2025 12:55:52 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1758275752; bh=cq2SnBEaLRu/0mSFxt8cmSAJ0yXaJUJztucOvIMJ7YE=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=KhKqEiHBwaAP4nEtdqnpDVPtzOxxKlT7of3Ls6eNJyktcBmvwcr9ZqSOjfxawvYhc KRJhULlmpfs7eUMlURjYG2Tl5uVgq43lBaErQPA8Tld5DAuecjiPC8gORwqWv8I73D HA0ZfGcR6Jw3HtC4XNLhZHZE320eo0cqkdsQ9DZg= Authentication-Results: mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: mst@redhat.com Cc: qemu-devel@nongnu.org, philmd@linaro.org, thuth@redhat.com, eblake@redhat.com, michael.roth@amd.com, armbru@redhat.com, farosas@suse.de, peterx@redhat.com, berrange@redhat.com, jasowang@redhat.com, steven.sistare@oracle.com, leiyang@redhat.com, davydov-max@yandex-team.ru, yc-core@yandex-team.ru, Vladimir Sementsov-Ogievskiy Subject: [PATCH v5 03/19] net/tap: net_init_tap_one(): drop extra error propagation Date: Fri, 19 Sep 2025 12:55:29 +0300 Message-ID: <20250919095545.1912042-4-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250919095545.1912042-1-vsementsov@yandex-team.ru> References: <20250919095545.1912042-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=178.154.239.200; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1d.mail.yandex.net X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @yandex-team.ru) X-ZM-MESSAGEID: 1758275852822116600 Content-Type: text/plain; charset="utf-8" Signed-off-by: Vladimir Sementsov-Ogievskiy --- net/tap.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/net/tap.c b/net/tap.c index f7df702f97..10799ab055 100644 --- a/net/tap.c +++ b/net/tap.c @@ -724,9 +724,8 @@ static void net_init_tap_one(const NetdevTapOptions *ta= p, NetClientState *peer, } =20 if (vhostfdname) { - vhostfd =3D monitor_fd_param(monitor_cur(), vhostfdname, &err); + vhostfd =3D monitor_fd_param(monitor_cur(), vhostfdname, errp); if (vhostfd =3D=3D -1) { - error_propagate(errp, err); goto failed; } if (!g_unix_set_fd_nonblocking(vhostfd, true, NULL)) { --=20 2.48.1 From nobody Sun Sep 28 15:28:10 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1758276023; cv=none; d=zohomail.com; s=zohoarc; b=AiFhoKoNyhd2Y0oloQxz3IOb6Hgv6HAle2Op2HJLSUKwmGQ2+y9PziVC4/VpSE5k1b5wZE1xY5UoQVCM+f750EGrHhUxLnkFaDxx8QJaVEd0OD8uvd0KWt9oC/gpY92Z9YxrovypGM4Um4feH9U4FROiihwDZvceF1oqCOpqLGs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1758276023; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=ms1B1DzCY1b4N0NqMoMWin+rDUcMV30qs3x75+Q5/Gc=; b=lflNKrzSOVPxqMjPNXO3P1/bTZxcqkScmrALcuhRSjLwvLRCMV4VvxOmgCDu3sJHxbwHCNdxDKeHQiNXXJPQozDii0F1jmmllofTDw5EmU0ThOXhvpEOI0UxGpqicbQVDHRR7ecEqGI/ry8OuY1TLRbYQNXzpViBDty1P8+McYE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1758276023338370.8254290119354; Fri, 19 Sep 2025 03:00:23 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uzXr7-0006Ft-0M; Fri, 19 Sep 2025 05:56:41 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uzXqY-0005f4-K7 for qemu-devel@nongnu.org; Fri, 19 Sep 2025 05:56:07 -0400 Received: from forwardcorp1d.mail.yandex.net ([2a02:6b8:c41:1300:1:45:d181:df01]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uzXqS-0004ZW-Ec for qemu-devel@nongnu.org; Fri, 19 Sep 2025 05:56:06 -0400 Received: from mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net [IPv6:2a02:6b8:c0c:1621:0:640:12d9:0]) by forwardcorp1d.mail.yandex.net (Yandex) with ESMTPS id 8D11B80EA4; Fri, 19 Sep 2025 12:55:54 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:a72::1:38]) by mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id ntP1fK1GvGk0-hIyHZNeV; Fri, 19 Sep 2025 12:55:53 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1758275753; bh=ms1B1DzCY1b4N0NqMoMWin+rDUcMV30qs3x75+Q5/Gc=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=n6tmMnTNNQ9yLXGN2usMHAtOrM9ojh6ZQ8/ivfs5hG7QpVoCko2XGhg4nnhRzVOSg JjDRIe/uM3GG4L19twFoH+OolmeX2k0XE/pB8Ob72mz5EzOUClMSirMZ1mdx5VewCn dICHlCtAJPdfy1u0isxK3CtUIjqyGkh/iKkciAM8= Authentication-Results: mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: mst@redhat.com Cc: qemu-devel@nongnu.org, philmd@linaro.org, thuth@redhat.com, eblake@redhat.com, michael.roth@amd.com, armbru@redhat.com, farosas@suse.de, peterx@redhat.com, berrange@redhat.com, jasowang@redhat.com, steven.sistare@oracle.com, leiyang@redhat.com, davydov-max@yandex-team.ru, yc-core@yandex-team.ru, Vladimir Sementsov-Ogievskiy Subject: [PATCH v5 04/19] net/tap: net_init_tap_one(): move parameter checking earlier Date: Fri, 19 Sep 2025 12:55:30 +0300 Message-ID: <20250919095545.1912042-5-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250919095545.1912042-1-vsementsov@yandex-team.ru> References: <20250919095545.1912042-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a02:6b8:c41:1300:1:45:d181:df01; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1d.mail.yandex.net X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @yandex-team.ru) X-ZM-MESSAGEID: 1758276023830116600 Content-Type: text/plain; charset="utf-8" Let's keep all similar argument checking in net_init_tap() function. Signed-off-by: Vladimir Sementsov-Ogievskiy --- net/tap.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/net/tap.c b/net/tap.c index 10799ab055..e268d79a97 100644 --- a/net/tap.c +++ b/net/tap.c @@ -759,9 +759,6 @@ static void net_init_tap_one(const NetdevTapOptions *ta= p, NetClientState *peer, "vhost-net requested but could not be initialized"); goto failed; } - } else if (vhostfdname) { - error_setg(errp, "vhostfd(s)=3D is not valid without vhost"); - goto failed; } =20 return; @@ -823,6 +820,11 @@ int net_init_tap(const Netdev *netdev, const char *nam= e, return -1; } =20 + if (tap->has_vhost && !tap->vhost && (tap->vhostfds || tap->vhostfd)) { + error_setg(errp, "vhostfd(s)=3D is not valid without vhost"); + return -1; + } + if (tap->fd) { if (tap->ifname || tap->script || tap->downscript || tap->has_vnet_hdr || tap->helper || tap->has_queues || --=20 2.48.1 From nobody Sun Sep 28 15:28:10 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1758275896; cv=none; d=zohomail.com; s=zohoarc; b=AA0vEbrddu+PuZmgFfaxXu4/QkK07iLIjZfy97/ZaDw5bOrygWsTTqsUZXhUoQlkCyHQRWJEJ/AID8C86HK5Q2fd+OkYUA7G2K87nswwKtcpKl66fbamjSELBpNOxxFP8y0Cl8IThi6805YAzGKdavRxBhv8Vm5xSsevI6AK0F0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1758275896; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=CGQxVo0F5DM5TI71ogpEMoIKdtU4cMrWeEhuC0QhepU=; b=gTjrcGMopHmixPQR8v3KJZSyBuiGHfKURnvAwpgS67yxYMxY0/IrIPTTUlncbdQ8c4vc0raLFqVn1IfWLlKCqB1vEnRilOu+OgkI3DkgeTNXytl6YdQEVSUDw1rGnEpn30t86b0l3hCSdgVsc5EfIjClk845kOqz/0j2YZZ9ULc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1758275896462773.7417773383588; Fri, 19 Sep 2025 02:58:16 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uzXqs-00069f-AA; Fri, 19 Sep 2025 05:56:26 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uzXqb-0005g9-0s for qemu-devel@nongnu.org; Fri, 19 Sep 2025 05:56:11 -0400 Received: from forwardcorp1d.mail.yandex.net ([178.154.239.200]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uzXqS-0004Ze-Dv for qemu-devel@nongnu.org; Fri, 19 Sep 2025 05:56:08 -0400 Received: from mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net [IPv6:2a02:6b8:c0c:1621:0:640:12d9:0]) by forwardcorp1d.mail.yandex.net (Yandex) with ESMTPS id 4901080ED9; Fri, 19 Sep 2025 12:55:55 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:a72::1:38]) by mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id ntP1fK1GvGk0-Xm8jnOcW; Fri, 19 Sep 2025 12:55:54 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1758275754; bh=CGQxVo0F5DM5TI71ogpEMoIKdtU4cMrWeEhuC0QhepU=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=d5jTSKPgst2bvxOQadbULtYmK0vnrP49/9luf8Y27NhoL1o69iAascykaC+bZxXum bdN2NPrnGrngpvyOq98Jpcu30juyxu7XP0k2ZOOe5+JJXTVFS8cknw+A0Wff7Y7PGw F3b/k5j3Me8uIO0tbAawiwRDoyWF4BEcc3YGOUdg= Authentication-Results: mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: mst@redhat.com Cc: qemu-devel@nongnu.org, philmd@linaro.org, thuth@redhat.com, eblake@redhat.com, michael.roth@amd.com, armbru@redhat.com, farosas@suse.de, peterx@redhat.com, berrange@redhat.com, jasowang@redhat.com, steven.sistare@oracle.com, leiyang@redhat.com, davydov-max@yandex-team.ru, yc-core@yandex-team.ru, Vladimir Sementsov-Ogievskiy Subject: [PATCH v5 05/19] net/tap: rework net_tap_init() Date: Fri, 19 Sep 2025 12:55:31 +0300 Message-ID: <20250919095545.1912042-6-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250919095545.1912042-1-vsementsov@yandex-team.ru> References: <20250919095545.1912042-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=178.154.239.200; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1d.mail.yandex.net X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @yandex-team.ru) X-ZM-MESSAGEID: 1758275898254116600 Content-Type: text/plain; charset="utf-8" In future (to support live-TAP migration with fds passing through unix socket) we'll want to postpone fd-initialization to the later point, when QAPI structured parameters are not available. So, let's now rework the function to interface without "tap" parameter. Also, rename to net_tap_open(), as it's just a wrapper on tap_open(), and having net_tap_init() and net_init_tap() functions in one file is confusing. Signed-off-by: Vladimir Sementsov-Ogievskiy --- net/tap.c | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/net/tap.c b/net/tap.c index e268d79a97..1e5eaae6e7 100644 --- a/net/tap.c +++ b/net/tap.c @@ -643,20 +643,12 @@ int net_init_bridge(const Netdev *netdev, const char = *name, return 0; } =20 -static int net_tap_init(const NetdevTapOptions *tap, int *vnet_hdr, +static int net_tap_open(int *vnet_hdr, bool vnet_hdr_required, const char *setup_script, char *ifname, size_t ifname_sz, int mq_required, Error **errp) { Error *err =3D NULL; - int fd, vnet_hdr_required; - - if (tap->has_vnet_hdr) { - *vnet_hdr =3D tap->vnet_hdr; - vnet_hdr_required =3D *vnet_hdr; - } else { - *vnet_hdr =3D 1; - vnet_hdr_required =3D 0; - } + int fd; =20 fd =3D RETRY_ON_EINTR(tap_open(ifname, ifname_sz, vnet_hdr, vnet_hdr_r= equired, mq_required, errp)); @@ -973,6 +965,8 @@ free_fail: } else { g_autofree char *default_script =3D NULL; g_autofree char *default_downscript =3D NULL; + bool vnet_hdr_required =3D tap->has_vnet_hdr && tap->vnet_hdr; + if (tap->vhostfds) { error_setg(errp, "vhostfds=3D is invalid if fds=3D wasn't spec= ified"); return -1; @@ -993,7 +987,9 @@ free_fail: } =20 for (i =3D 0; i < queues; i++) { - fd =3D net_tap_init(tap, &vnet_hdr, i >=3D 1 ? "no" : script, + vnet_hdr =3D tap->has_vnet_hdr ? tap->vnet_hdr : 1; + fd =3D net_tap_open(&vnet_hdr, vnet_hdr_required, + i >=3D 1 ? "no" : script, ifname, sizeof ifname, queues > 1, errp); if (fd =3D=3D -1) { return -1; --=20 2.48.1 From nobody Sun Sep 28 15:28:10 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1758275808; cv=none; d=zohomail.com; s=zohoarc; b=VU9vkBHkcfUJ5FoBbSIN7k0rfsfHN0BwBkpqYRMixpevx+8kNkVw3QrhBkujAeJUvqsZyZ+CfxEp0R8rhqOu3oBazV2NpGw1PG5ydn3EZBE66ooXFTWePQgYICC/4z2zEXDid1NCUE1Leni0cEimb9/xIaG1s1GzjHKGDGjbpb8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1758275808; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=pY3iggxWbtv0yXEV6Sn/0zvk2K7amSFE6IZtW3rq9QU=; b=hvAh1zELCVmF/whCiNH46fwj5kCpran8Mm/MaIJ3P6oyyJAYMqc0982b3WlFHXy35mMTz2SZMW++l6w3j5ynRtp0qyfcnJ1Pc5NVpazN+WvUiJYa2c5qMPnbP0I5AiwkF3+/xYJeIbUi6l9fFbcoNpOItGTyzlFErlik0c+7nRE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 17582758075813.3647053833166183; Fri, 19 Sep 2025 02:56:47 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uzXqj-00062a-8z; Fri, 19 Sep 2025 05:56:17 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uzXqW-0005ei-Ig for qemu-devel@nongnu.org; Fri, 19 Sep 2025 05:56:06 -0400 Received: from forwardcorp1d.mail.yandex.net ([178.154.239.200]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uzXqR-0004Zj-7d for qemu-devel@nongnu.org; Fri, 19 Sep 2025 05:56:03 -0400 Received: from mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net [IPv6:2a02:6b8:c0c:1621:0:640:12d9:0]) by forwardcorp1d.mail.yandex.net (Yandex) with ESMTPS id E361280ED6; Fri, 19 Sep 2025 12:55:55 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:a72::1:38]) by mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id ntP1fK1GvGk0-zWVWDwbL; Fri, 19 Sep 2025 12:55:55 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1758275755; bh=pY3iggxWbtv0yXEV6Sn/0zvk2K7amSFE6IZtW3rq9QU=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=JghFl339YQlEWv9Twk2aGYSxGKG8u+phxyQdi50vqdlGVPFSTWe9SfVPfnvhlDlpN zJ5VY9O+g1yR8iCCP6ofhqhIRnbZEQT9FHv9viVWnJms0LiJFSz5/jTI0tBngsM2V4 aVCgUuHofBxgtsqR38ikj/GCkAaXh0zA/uK90VDk= Authentication-Results: mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: mst@redhat.com Cc: qemu-devel@nongnu.org, philmd@linaro.org, thuth@redhat.com, eblake@redhat.com, michael.roth@amd.com, armbru@redhat.com, farosas@suse.de, peterx@redhat.com, berrange@redhat.com, jasowang@redhat.com, steven.sistare@oracle.com, leiyang@redhat.com, davydov-max@yandex-team.ru, yc-core@yandex-team.ru, Vladimir Sementsov-Ogievskiy Subject: [PATCH v5 06/19] net/tap: setup exit notifier only when needed Date: Fri, 19 Sep 2025 12:55:32 +0300 Message-ID: <20250919095545.1912042-7-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250919095545.1912042-1-vsementsov@yandex-team.ru> References: <20250919095545.1912042-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=178.154.239.200; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1d.mail.yandex.net X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @yandex-team.ru) X-ZM-MESSAGEID: 1758275811069116600 Content-Type: text/plain; charset="utf-8" No reason to setup notifier on each queue of multique tap, when we actually want to run downscript only once. As well, let's not setup notifier, when downscript is not enabled (downsciprt=3D"no"). Signed-off-by: Vladimir Sementsov-Ogievskiy --- net/tap.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/net/tap.c b/net/tap.c index 1e5eaae6e7..eabfc0b8d8 100644 --- a/net/tap.c +++ b/net/tap.c @@ -301,11 +301,9 @@ static void tap_exit_notify(Notifier *notifier, void *= data) TAPState *s =3D container_of(notifier, TAPState, exit); Error *err =3D NULL; =20 - if (s->down_script[0]) { - launch_script(s->down_script, s->down_script_arg, s->fd, &err); - if (err) { - error_report_err(err); - } + launch_script(s->down_script, s->down_script_arg, s->fd, &err); + if (err) { + error_report_err(err); } } =20 @@ -321,8 +319,11 @@ static void tap_cleanup(NetClientState *nc) =20 qemu_purge_queued_packets(nc); =20 - tap_exit_notify(&s->exit, NULL); - qemu_remove_exit_notifier(&s->exit); + if (s->exit.notify) { + tap_exit_notify(&s->exit, NULL); + qemu_remove_exit_notifier(&s->exit); + s->exit.notify =3D NULL; + } =20 tap_read_poll(s, false); tap_write_poll(s, false); @@ -415,9 +416,6 @@ static TAPState *net_tap_fd_init(NetClientState *peer, tap_read_poll(s, true); s->vhost_net =3D NULL; =20 - s->exit.notify =3D tap_exit_notify; - qemu_add_exit_notifier(&s->exit); - return s; } =20 @@ -700,6 +698,8 @@ static void net_init_tap_one(const NetdevTapOptions *ta= p, NetClientState *peer, snprintf(s->down_script, sizeof(s->down_script), "%s", downscr= ipt); snprintf(s->down_script_arg, sizeof(s->down_script_arg), "%s", ifname); + s->exit.notify =3D tap_exit_notify; + qemu_add_exit_notifier(&s->exit); } } =20 --=20 2.48.1 From nobody Sun Sep 28 15:28:10 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1758275873; cv=none; d=zohomail.com; s=zohoarc; b=jfmeyG/XySm+Tgk1E16bV6K35OE32394p+cyzdrf0uo4Pbm32VHmAxLcjHeYak9GU4JMWQjg0f4i/9ztYGgnHyjypma1Tdgh3+IyKuY4dVAPiFR0nt/CIYyFXP8Xpt1SFJaRWOFFWu/qWlTI/5LQVfGGl6Lhf9vtqAf4SfJTcdo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1758275873; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=aMS72jc0f+G5CSAZlTvogS7DDRATM/PBfqOVSkLY5B4=; b=i7/uIsYleEOIouzsCjyifocCo7p4StnSt2p4+ZTOwASE9RYeqXAAqhxyc5VcW2NR1xfD4HKDYiAzKywGX8ndmFz2DqMOcdakRh+mXNlenhtMXMmkmWBVMP4friP3vYfR8xsdZ4kMmQgko+NCIdg0KKZjRkpHriKtWwmcwr3JlRg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1758275873686557.1984101458628; Fri, 19 Sep 2025 02:57:53 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uzXqq-00068B-O6; Fri, 19 Sep 2025 05:56:24 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uzXqa-0005g8-VH for qemu-devel@nongnu.org; Fri, 19 Sep 2025 05:56:11 -0400 Received: from forwardcorp1d.mail.yandex.net ([2a02:6b8:c41:1300:1:45:d181:df01]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uzXqS-0004Zp-9j for qemu-devel@nongnu.org; Fri, 19 Sep 2025 05:56:08 -0400 Received: from mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net [IPv6:2a02:6b8:c0c:1621:0:640:12d9:0]) by forwardcorp1d.mail.yandex.net (Yandex) with ESMTPS id 9756F80EE1; Fri, 19 Sep 2025 12:55:56 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:a72::1:38]) by mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id ntP1fK1GvGk0-UEe3IwxK; Fri, 19 Sep 2025 12:55:56 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1758275756; bh=aMS72jc0f+G5CSAZlTvogS7DDRATM/PBfqOVSkLY5B4=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=tWBOCqOfuwlj62KQvAGI6Au8kMB9ZpwPxIYeGyKJA6WdxcE0MtmnkhKPZLkQyLCn7 kMvgju+3zZxvz4usLMNjt5TnvSJ6KRQPJokdjOy2joMcCdErnNELYtb4eCaxUtfA/p sfrLMJgv22424AQriTcYb3ZkeYcohhdXdOcsADwc= Authentication-Results: mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: mst@redhat.com Cc: qemu-devel@nongnu.org, philmd@linaro.org, thuth@redhat.com, eblake@redhat.com, michael.roth@amd.com, armbru@redhat.com, farosas@suse.de, peterx@redhat.com, berrange@redhat.com, jasowang@redhat.com, steven.sistare@oracle.com, leiyang@redhat.com, davydov-max@yandex-team.ru, yc-core@yandex-team.ru, Vladimir Sementsov-Ogievskiy Subject: [PATCH v5 07/19] net/tap: split net_tap_fd_init() Date: Fri, 19 Sep 2025 12:55:33 +0300 Message-ID: <20250919095545.1912042-8-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250919095545.1912042-1-vsementsov@yandex-team.ru> References: <20250919095545.1912042-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a02:6b8:c41:1300:1:45:d181:df01; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1d.mail.yandex.net X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @yandex-team.ru) X-ZM-MESSAGEID: 1758275876161116600 Content-Type: text/plain; charset="utf-8" Split the function into separate net_tap_new() and net_tap_set_fd(). We start move to the following picture: net_tap_new() - take QAPI @tap parameter, but don't have @fd, initialize the net client, called during initialization. net_tap_setup() - don't have @tap (QAPI), but have @fd parameter, may be called at later point. In this commit we introduce the first function. Signed-off-by: Vladimir Sementsov-Ogievskiy --- net/tap.c | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/net/tap.c b/net/tap.c index eabfc0b8d8..3050fdea2e 100644 --- a/net/tap.c +++ b/net/tap.c @@ -386,19 +386,19 @@ static NetClientInfo net_tap_info =3D { .get_vhost_net =3D tap_get_vhost_net, }; =20 -static TAPState *net_tap_fd_init(NetClientState *peer, - const char *model, - const char *name, - int fd, - int vnet_hdr) +static TAPState *net_tap_new(NetClientState *peer, const char *model, + const char *name) { - NetClientState *nc; - TAPState *s; + NetClientState *nc =3D qemu_new_net_client(&net_tap_info, peer, model,= name); + TAPState *s =3D DO_UPCAST(TAPState, nc, nc); =20 - nc =3D qemu_new_net_client(&net_tap_info, peer, model, name); + s->fd =3D -1; =20 - s =3D DO_UPCAST(TAPState, nc, nc); + return s; +} =20 +static void net_tap_set_fd(TAPState *s, int fd, int vnet_hdr) +{ s->fd =3D fd; s->host_vnet_hdr_len =3D vnet_hdr ? sizeof(struct virtio_net_hdr) : 0; s->using_vnet_hdr =3D false; @@ -415,8 +415,6 @@ static TAPState *net_tap_fd_init(NetClientState *peer, } tap_read_poll(s, true); s->vhost_net =3D NULL; - - return s; } =20 static void close_all_fds_after_fork(int excluded_fd) @@ -634,7 +632,9 @@ int net_init_bridge(const Netdev *netdev, const char *n= ame, close(fd); return -1; } - s =3D net_tap_fd_init(peer, "bridge", name, fd, vnet_hdr); + + s =3D net_tap_new(peer, "bridge", name); + net_tap_set_fd(s, fd, vnet_hdr); =20 qemu_set_info_str(&s->nc, "helper=3D%s,br=3D%s", helper, br); =20 @@ -677,9 +677,11 @@ static void net_init_tap_one(const NetdevTapOptions *t= ap, NetClientState *peer, int vnet_hdr, int fd, Error **errp) { Error *err =3D NULL; - TAPState *s =3D net_tap_fd_init(peer, model, name, fd, vnet_hdr); + TAPState *s =3D net_tap_new(peer, model, name); int vhostfd; =20 + net_tap_set_fd(s, fd, vnet_hdr); + tap_set_sndbuf(s->fd, tap, &err); if (err) { error_propagate(errp, err); --=20 2.48.1 From nobody Sun Sep 28 15:28:10 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1758275945; cv=none; d=zohomail.com; s=zohoarc; b=VOaCZ1LlE25+rLibHhjU25qwWPeX/ucchLEcnViciR024cW1AtkUUBo1wrbe/uJcM1zFlPS8ys8CO1WwXY9doCZmGpTNI7wVObA44tEUyPjmm175Sf3HznQDgVGODIbLnWlSvMRBHEc2/W96+uHHqZwvpxTsA9wvdybQeKRFLm4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1758275945; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=w1cyWF78HXtHriBMncCUv10Xr+DAGRcqyUlrjqYm39s=; b=KD2t3OUNpl6TKzFNhgystkJK3RvIxO/DNCFXjXqR9C7d7avBXbrCAk4baAAF9yz5wVsz6B9qSMXsMUV4YwShkB0sdIpx1u3i9XYJ2zhL97OP1bUxcIWFIlQ5vvIIlhfV8FN+WvTt7aQyMEbAT8dFEnHlyZnuS3ypf79jq6B+Q0s= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1758275945852532.2782400827816; Fri, 19 Sep 2025 02:59:05 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uzXqi-0005vo-5H; Fri, 19 Sep 2025 05:56:16 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uzXqb-0005gA-0d for qemu-devel@nongnu.org; Fri, 19 Sep 2025 05:56:11 -0400 Received: from forwardcorp1d.mail.yandex.net ([2a02:6b8:c41:1300:1:45:d181:df01]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uzXqS-0004Zr-Co for qemu-devel@nongnu.org; Fri, 19 Sep 2025 05:56:08 -0400 Received: from mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net [IPv6:2a02:6b8:c0c:1621:0:640:12d9:0]) by forwardcorp1d.mail.yandex.net (Yandex) with ESMTPS id 4DCE780EE2; Fri, 19 Sep 2025 12:55:57 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:a72::1:38]) by mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id ntP1fK1GvGk0-oha60RWq; Fri, 19 Sep 2025 12:55:56 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1758275756; bh=w1cyWF78HXtHriBMncCUv10Xr+DAGRcqyUlrjqYm39s=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=QqknjA1w9gC+M735UytuhnsyMOOnXyA1uMGekSKGhYtlgEQGWql1+LzmghA810pFR rErKwhLj9p+9BTZGgVm8i/mkg6Z0WzwCUhbo7TTTvqbJiJlv6pqVKiGBM51YVpjZyH A1pEyUf+Prxwmx0AFOU+WqbQN6O3Ab5XZCVhKNSc= Authentication-Results: mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: mst@redhat.com Cc: qemu-devel@nongnu.org, philmd@linaro.org, thuth@redhat.com, eblake@redhat.com, michael.roth@amd.com, armbru@redhat.com, farosas@suse.de, peterx@redhat.com, berrange@redhat.com, jasowang@redhat.com, steven.sistare@oracle.com, leiyang@redhat.com, davydov-max@yandex-team.ru, yc-core@yandex-team.ru, Vladimir Sementsov-Ogievskiy Subject: [PATCH v5 08/19] net/tap: rework tap_set_sndbuf() Date: Fri, 19 Sep 2025 12:55:34 +0300 Message-ID: <20250919095545.1912042-9-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250919095545.1912042-1-vsementsov@yandex-team.ru> References: <20250919095545.1912042-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a02:6b8:c41:1300:1:45:d181:df01; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1d.mail.yandex.net X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @yandex-team.ru) X-ZM-MESSAGEID: 1758275946903116600 Content-Type: text/plain; charset="utf-8" First, follow common recommendations to avoid error propagation: add return value to tap_set_sndbuf(). Second, keep NetdevTapOptions related logic in tap.c, and make tap_set_sndbuf a simple system call wrapper, more like other functions in tap-linux.c Signed-off-by: Vladimir Sementsov-Ogievskiy --- net/tap-bsd.c | 3 ++- net/tap-linux.c | 19 +++++-------------- net/tap-solaris.c | 3 ++- net/tap-stub.c | 3 ++- net/tap.c | 9 +++++---- net/tap_int.h | 4 +--- 6 files changed, 17 insertions(+), 24 deletions(-) diff --git a/net/tap-bsd.c b/net/tap-bsd.c index b4c84441ba..3bfc1cc577 100644 --- a/net/tap-bsd.c +++ b/net/tap-bsd.c @@ -198,8 +198,9 @@ error: } #endif /* __FreeBSD__ */ =20 -void tap_set_sndbuf(int fd, const NetdevTapOptions *tap, Error **errp) +bool tap_set_sndbuf(int fd, int sndbuf, Error **errp) { + return true; } =20 int tap_probe_vnet_hdr(int fd, Error **errp) diff --git a/net/tap-linux.c b/net/tap-linux.c index 22ec2f45d2..c46f488c08 100644 --- a/net/tap-linux.c +++ b/net/tap-linux.c @@ -138,23 +138,14 @@ int tap_open(char *ifname, int ifname_size, int *vnet= _hdr, * Ethernet NICs generally have txqueuelen=3D1000, so 1Mb is * a good value, given a 1500 byte MTU. */ -#define TAP_DEFAULT_SNDBUF 0 - -void tap_set_sndbuf(int fd, const NetdevTapOptions *tap, Error **errp) +bool tap_set_sndbuf(int fd, int sndbuf, Error **errp) { - int sndbuf; - - sndbuf =3D !tap->has_sndbuf ? TAP_DEFAULT_SNDBUF : - tap->sndbuf > INT_MAX ? INT_MAX : - tap->sndbuf; - - if (!sndbuf) { - sndbuf =3D INT_MAX; - } - - if (ioctl(fd, TUNSETSNDBUF, &sndbuf) =3D=3D -1 && tap->has_sndbuf) { + if (ioctl(fd, TUNSETSNDBUF, &sndbuf) =3D=3D -1) { error_setg_errno(errp, errno, "TUNSETSNDBUF ioctl failed"); + return false; } + + return true; } =20 int tap_probe_vnet_hdr(int fd, Error **errp) diff --git a/net/tap-solaris.c b/net/tap-solaris.c index 51b7830bef..2932c2de39 100644 --- a/net/tap-solaris.c +++ b/net/tap-solaris.c @@ -202,8 +202,9 @@ int tap_open(char *ifname, int ifname_size, int *vnet_h= dr, return fd; } =20 -void tap_set_sndbuf(int fd, const NetdevTapOptions *tap, Error **errp) +bool tap_set_sndbuf(int fd, int sndbuf, Error **errp) { + return true; } =20 int tap_probe_vnet_hdr(int fd, Error **errp) diff --git a/net/tap-stub.c b/net/tap-stub.c index 38673434cb..326e76843e 100644 --- a/net/tap-stub.c +++ b/net/tap-stub.c @@ -33,8 +33,9 @@ int tap_open(char *ifname, int ifname_size, int *vnet_hdr, return -1; } =20 -void tap_set_sndbuf(int fd, const NetdevTapOptions *tap, Error **errp) +bool tap_set_sndbuf(int fd, int sndbuf, Error **errp) { + return true; } =20 int tap_probe_vnet_hdr(int fd, Error **errp) diff --git a/net/tap.c b/net/tap.c index 3050fdea2e..5cb639a71d 100644 --- a/net/tap.c +++ b/net/tap.c @@ -676,15 +676,16 @@ static void net_init_tap_one(const NetdevTapOptions *= tap, NetClientState *peer, const char *downscript, const char *vhostfdna= me, int vnet_hdr, int fd, Error **errp) { - Error *err =3D NULL; TAPState *s =3D net_tap_new(peer, model, name); int vhostfd; + bool sndbuf_required =3D tap->has_sndbuf; + int sndbuf =3D + (tap->has_sndbuf && tap->sndbuf) ? MIN(tap->sndbuf, INT_MAX) : INT= _MAX; =20 net_tap_set_fd(s, fd, vnet_hdr); =20 - tap_set_sndbuf(s->fd, tap, &err); - if (err) { - error_propagate(errp, err); + if (!tap_set_sndbuf(fd, sndbuf, sndbuf_required ? errp : NULL) && + sndbuf_required) { goto failed; } =20 diff --git a/net/tap_int.h b/net/tap_int.h index 8857ff299d..08e4a592a0 100644 --- a/net/tap_int.h +++ b/net/tap_int.h @@ -26,14 +26,12 @@ #ifndef NET_TAP_INT_H #define NET_TAP_INT_H =20 -#include "qapi/qapi-types-net.h" - int tap_open(char *ifname, int ifname_size, int *vnet_hdr, int vnet_hdr_required, int mq_required, Error **errp); =20 ssize_t tap_read_packet(int tapfd, uint8_t *buf, int maxlen); =20 -void tap_set_sndbuf(int fd, const NetdevTapOptions *tap, Error **errp); +bool tap_set_sndbuf(int fd, int sndbuf, Error **errp); int tap_probe_vnet_hdr(int fd, Error **errp); int tap_probe_has_ufo(int fd); int tap_probe_has_uso(int fd); --=20 2.48.1 From nobody Sun Sep 28 15:28:10 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1758275917; cv=none; d=zohomail.com; s=zohoarc; b=LRZCJKrQPUz575zOBg5DrN6WFFIEJuJ1gAXjfIUhiXs9xKMpbacLxQzRGDOb2GnXZrW9zAAip8QFPLBtia+td7NTiDHepFCrqQtYIWroceMvf4r94Fwnh+9aCFNZKjXHtsmWq+pYv2TdtIPZLaDAGQt7TBsqj85SEHzcLNZRqps= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1758275917; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=zqSGyfmGyqk84YZKBCXE8de3p61obh4ja5MyxHl4Leg=; b=VNLd11gyOO/XG1JBksaXfnstlqUGHyFqTzXW3NHilMyURTSdZY4kXal1cm3qrdklW2XveQsqKaAogLrBTtpnu+O0WCJCflMJGQdSNKUPYKoFyw8up/jkpPatO8TPonm6JZw9oi2oJ7lOXXeUBjPT8BNaORN8ipAG+o6unmyFX+c= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1758275917804429.8816949095043; Fri, 19 Sep 2025 02:58:37 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uzXqo-000677-6i; Fri, 19 Sep 2025 05:56:22 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uzXqY-0005f0-I2 for qemu-devel@nongnu.org; Fri, 19 Sep 2025 05:56:07 -0400 Received: from forwardcorp1d.mail.yandex.net ([2a02:6b8:c41:1300:1:45:d181:df01]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uzXqR-0004Zw-NV for qemu-devel@nongnu.org; Fri, 19 Sep 2025 05:56:06 -0400 Received: from mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net [IPv6:2a02:6b8:c0c:1621:0:640:12d9:0]) by forwardcorp1d.mail.yandex.net (Yandex) with ESMTPS id F363880EEA; Fri, 19 Sep 2025 12:55:57 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:a72::1:38]) by mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id ntP1fK1GvGk0-NAtC6eNj; Fri, 19 Sep 2025 12:55:57 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1758275757; bh=zqSGyfmGyqk84YZKBCXE8de3p61obh4ja5MyxHl4Leg=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=DfgL+xPuGLOZ9eIVLfdb+0m/ABZla9hkhm3iFbp21WlXkMzd87W8yZdgSJZ3T//VY LVwfXB2Ah+jvYCEyN5fkS0pa4pu+ZcNpjyFLHxEIYCAM4Dv0We6AyvJ6+logsyuhVJ vDRn0KgcYlcQQaN+65o1M/kmh0hpN3uqF84L7Tus= Authentication-Results: mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: mst@redhat.com Cc: qemu-devel@nongnu.org, philmd@linaro.org, thuth@redhat.com, eblake@redhat.com, michael.roth@amd.com, armbru@redhat.com, farosas@suse.de, peterx@redhat.com, berrange@redhat.com, jasowang@redhat.com, steven.sistare@oracle.com, leiyang@redhat.com, davydov-max@yandex-team.ru, yc-core@yandex-team.ru, Vladimir Sementsov-Ogievskiy Subject: [PATCH v5 09/19] net/tap: rework sndbuf handling Date: Fri, 19 Sep 2025 12:55:35 +0300 Message-ID: <20250919095545.1912042-10-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250919095545.1912042-1-vsementsov@yandex-team.ru> References: <20250919095545.1912042-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a02:6b8:c41:1300:1:45:d181:df01; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1d.mail.yandex.net X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, T_SPF_TEMPERROR=0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @yandex-team.ru) X-ZM-MESSAGEID: 1758275918489116600 Content-Type: text/plain; charset="utf-8" Continue the main idea: avoid dependency on @tap in net_tap_setup(). So, move QAPI parsing to net_tap_new(). Move setting sndbuf to net_tap_set_fd(), as it's more appropriate place (other initial fd settings are here). Note that net_tap_new() and net_tap_set_fd() are shared with net_init_bridge(), which didn't set sndbuf. Handle this case by sndbuf=3D0 (we never pass zero to tap_set_sndbuf(), so let this specific value mean that we don't want touch sndbuf). Signed-off-by: Vladimir Sementsov-Ogievskiy --- net/tap.c | 38 ++++++++++++++++++++++++++------------ 1 file changed, 26 insertions(+), 12 deletions(-) diff --git a/net/tap.c b/net/tap.c index 5cb639a71d..87d851203b 100644 --- a/net/tap.c +++ b/net/tap.c @@ -80,6 +80,9 @@ typedef struct TAPState { VHostNetState *vhost_net; unsigned host_vnet_hdr_len; Notifier exit; + + bool sndbuf_required; + int sndbuf; } TAPState; =20 static void launch_script(const char *setup_script, const char *ifname, @@ -387,17 +390,25 @@ static NetClientInfo net_tap_info =3D { }; =20 static TAPState *net_tap_new(NetClientState *peer, const char *model, - const char *name) + const char *name, const NetdevTapOptions *tap) { NetClientState *nc =3D qemu_new_net_client(&net_tap_info, peer, model,= name); TAPState *s =3D DO_UPCAST(TAPState, nc, nc); =20 s->fd =3D -1; =20 + if (!tap) { + return s; + } + + s->sndbuf_required =3D tap->has_sndbuf; + s->sndbuf =3D + (tap->has_sndbuf && tap->sndbuf) ? MIN(tap->sndbuf, INT_MAX) : INT= _MAX; + return s; } =20 -static void net_tap_set_fd(TAPState *s, int fd, int vnet_hdr) +static bool net_tap_set_fd(TAPState *s, int fd, int vnet_hdr, Error **errp) { s->fd =3D fd; s->host_vnet_hdr_len =3D vnet_hdr ? sizeof(struct virtio_net_hdr) : 0; @@ -415,6 +426,15 @@ static void net_tap_set_fd(TAPState *s, int fd, int vn= et_hdr) } tap_read_poll(s, true); s->vhost_net =3D NULL; + + if (s->sndbuf) { + Error **e =3D s->sndbuf_required ? errp : NULL; + if (!tap_set_sndbuf(s->fd, s->sndbuf, e) && s->sndbuf_required) { + return false; + } + } + + return true; } =20 static void close_all_fds_after_fork(int excluded_fd) @@ -633,8 +653,8 @@ int net_init_bridge(const Netdev *netdev, const char *n= ame, return -1; } =20 - s =3D net_tap_new(peer, "bridge", name); - net_tap_set_fd(s, fd, vnet_hdr); + s =3D net_tap_new(peer, "bridge", name, NULL); + net_tap_set_fd(s, fd, vnet_hdr, &error_abort); =20 qemu_set_info_str(&s->nc, "helper=3D%s,br=3D%s", helper, br); =20 @@ -676,16 +696,10 @@ static void net_init_tap_one(const NetdevTapOptions *= tap, NetClientState *peer, const char *downscript, const char *vhostfdna= me, int vnet_hdr, int fd, Error **errp) { - TAPState *s =3D net_tap_new(peer, model, name); + TAPState *s =3D net_tap_new(peer, model, name, tap); int vhostfd; - bool sndbuf_required =3D tap->has_sndbuf; - int sndbuf =3D - (tap->has_sndbuf && tap->sndbuf) ? MIN(tap->sndbuf, INT_MAX) : INT= _MAX; - - net_tap_set_fd(s, fd, vnet_hdr); =20 - if (!tap_set_sndbuf(fd, sndbuf, sndbuf_required ? errp : NULL) && - sndbuf_required) { + if (!net_tap_set_fd(s, fd, vnet_hdr, errp)) { goto failed; } =20 --=20 2.48.1 From nobody Sun Sep 28 15:28:10 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1758275918; cv=none; d=zohomail.com; s=zohoarc; b=XP9mG5iG2+ZPBGWgT8qikrSXVpGG9r2IVoWbINXb8RguigX11sVO1FCSUieKidYlMOst4UE7+Ad0Ik809vljGNXoFBG9uao7f242OyUsbFBHMyoiN/r6PW5XTgvK8+P7YdUX5SOaq1BoxdKsAudyLkPqlOqDKZGZ0jbaPghfH3w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1758275918; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=IIlPANs5RbiCijmZSg5eH14iKMIBRIq618g22rPPVqE=; b=m+2B8SBHUXkqsN6TW1Jn4QYsUNsJBNZYz4hno/cyqp2moHiIEH+U0gkNEw+6p79Ryo4aOATgbHowmqhGN6201yRQzeoUXfKR+MqI1M1Jz/ulKGTVvJDhxAgA2TIEokXQ+kHv7Gis15xqH8WEkSlzzHCxkGrJB673xMWP8msibSk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 175827591867585.29725959854693; Fri, 19 Sep 2025 02:58:38 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uzXqk-00066R-TJ; Fri, 19 Sep 2025 05:56:19 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uzXqc-0005hv-OQ for qemu-devel@nongnu.org; Fri, 19 Sep 2025 05:56:11 -0400 Received: from forwardcorp1d.mail.yandex.net ([178.154.239.200]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uzXqY-0004bK-E5 for qemu-devel@nongnu.org; Fri, 19 Sep 2025 05:56:10 -0400 Received: from mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net [IPv6:2a02:6b8:c0c:1621:0:640:12d9:0]) by forwardcorp1d.mail.yandex.net (Yandex) with ESMTPS id AA15A80EEB; Fri, 19 Sep 2025 12:55:58 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:a72::1:38]) by mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id ntP1fK1GvGk0-0NmJOvzS; Fri, 19 Sep 2025 12:55:58 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1758275758; bh=IIlPANs5RbiCijmZSg5eH14iKMIBRIq618g22rPPVqE=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=V+p/BvojW2sWfTCUDXhyi/5qvCgAW1nhzmc6XcE2n3MEcf5YCEQUYnTMN3OzyavcP JvTO3bT2DvMypmYmi2VbnBR0o3hA6uZGBZemV3kxfQuCveoZI+carxWl3VU2vrLktF xuAe+D5ffIzJfng9JCrJGmp4HLp3fyr3vKpoFyKU= Authentication-Results: mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: mst@redhat.com Cc: qemu-devel@nongnu.org, philmd@linaro.org, thuth@redhat.com, eblake@redhat.com, michael.roth@amd.com, armbru@redhat.com, farosas@suse.de, peterx@redhat.com, berrange@redhat.com, jasowang@redhat.com, steven.sistare@oracle.com, leiyang@redhat.com, davydov-max@yandex-team.ru, yc-core@yandex-team.ru, Vladimir Sementsov-Ogievskiy Subject: [PATCH v5 10/19] net/tap: introduce net_tap_setup() Date: Fri, 19 Sep 2025 12:55:36 +0300 Message-ID: <20250919095545.1912042-11-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250919095545.1912042-1-vsementsov@yandex-team.ru> References: <20250919095545.1912042-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=178.154.239.200; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1d.mail.yandex.net X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @yandex-team.ru) X-ZM-MESSAGEID: 1758275920468116600 Content-Type: text/plain; charset="utf-8" Move most of net_init_tap_one() to net_tap_setup() - future pair for net_tap_new(), for postponed setup. Signed-off-by: Vladimir Sementsov-Ogievskiy --- net/tap.c | 43 +++++++++++++++++++++++++++---------------- 1 file changed, 27 insertions(+), 16 deletions(-) diff --git a/net/tap.c b/net/tap.c index 87d851203b..b4682d7400 100644 --- a/net/tap.c +++ b/net/tap.c @@ -85,6 +85,10 @@ typedef struct TAPState { int sndbuf; } TAPState; =20 +static bool net_tap_setup(TAPState *s, const NetdevTapOptions *tap, + const char *vhostfdname, + int fd, int vnet_hdr, Error **errp); + static void launch_script(const char *setup_script, const char *ifname, int fd, Error **errp); =20 @@ -697,11 +701,6 @@ static void net_init_tap_one(const NetdevTapOptions *t= ap, NetClientState *peer, int vnet_hdr, int fd, Error **errp) { TAPState *s =3D net_tap_new(peer, model, name, tap); - int vhostfd; - - if (!net_tap_set_fd(s, fd, vnet_hdr, errp)) { - goto failed; - } =20 if (tap->fd || tap->fds) { qemu_set_info_str(&s->nc, "fd=3D%d", fd); @@ -720,6 +719,21 @@ static void net_init_tap_one(const NetdevTapOptions *t= ap, NetClientState *peer, } } =20 + if (!net_tap_setup(s, tap, vhostfdname, fd, vnet_hdr, errp)) { + qemu_del_net_client(&s->nc); + } +} + +static bool net_tap_setup(TAPState *s, const NetdevTapOptions *tap, + const char *vhostfdname, + int fd, int vnet_hdr, Error **errp) +{ + int vhostfd; + + if (!net_tap_set_fd(s, fd, vnet_hdr, errp)) { + return false; + } + if (tap->has_vhost ? tap->vhost : vhostfdname || (tap->has_vhostforce && tap->vhostforce)) { VhostNetOptions options; @@ -735,23 +749,23 @@ static void net_init_tap_one(const NetdevTapOptions *= tap, NetClientState *peer, if (vhostfdname) { vhostfd =3D monitor_fd_param(monitor_cur(), vhostfdname, errp); if (vhostfd =3D=3D -1) { - goto failed; + return false; } if (!g_unix_set_fd_nonblocking(vhostfd, true, NULL)) { - error_setg_errno(errp, errno, "%s: Can't use file descript= or %d", - name, fd); - goto failed; + error_setg_errno(errp, errno, "Can't use file descriptor %= d", + fd); + return false; } } else { vhostfd =3D open("/dev/vhost-net", O_RDWR); if (vhostfd < 0) { error_setg_errno(errp, errno, "tap: open vhost char device failed"); - goto failed; + return false; } if (!g_unix_set_fd_nonblocking(vhostfd, true, NULL)) { error_setg_errno(errp, errno, "Failed to set FD nonblockin= g"); - goto failed; + return false; } } options.opaque =3D (void *)(uintptr_t)vhostfd; @@ -766,14 +780,11 @@ static void net_init_tap_one(const NetdevTapOptions *= tap, NetClientState *peer, if (!s->vhost_net) { error_setg(errp, "vhost-net requested but could not be initialized"); - goto failed; + return false; } } =20 - return; - -failed: - qemu_del_net_client(&s->nc); + return true; } =20 static int get_fds(char *str, char *fds[], int max) --=20 2.48.1 From nobody Sun Sep 28 15:28:10 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1758275815; cv=none; d=zohomail.com; s=zohoarc; b=Tg1h5MtYG2sgI0uWgen2mBjP56UDxEJmABf0wvCZUBWNkKN3dF8BO/n7mLxl0YewJzPHWifKqJfSKBzfvpKtZFKgunvTIedEfnxkGZgR7U/h9c5dZsrWMldOWVe9l6pcqMXnO1tsAWfkZxSfBfTpOYt2ownsGtsvzzWf++W5FaY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1758275815; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=YfB/zHdqRSdlEQYKyrkvvHQ8ka4OYKqJMpFDAmzCODs=; b=YZneuc8HcaOOGoKLQCYBL4j7pvXXIMarctRxIVWq9wdU6a6Ym+U3wYKfK7Flvr4IcbwG1cwfT24ntPWaTQaO/nY8vFCB+m3hC8aO+hETx+suALc3+omuiCR09tkdachLMVvigTxWt4ZQEpPctmztv3JbJELjyY9LXIZY+JF+0Ag= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1758275814841204.0529226103307; Fri, 19 Sep 2025 02:56:54 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uzXqz-0006Cr-06; Fri, 19 Sep 2025 05:56:33 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uzXqj-00066T-RY for qemu-devel@nongnu.org; Fri, 19 Sep 2025 05:56:18 -0400 Received: from forwardcorp1d.mail.yandex.net ([178.154.239.200]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uzXqa-0004bJ-8S for qemu-devel@nongnu.org; Fri, 19 Sep 2025 05:56:16 -0400 Received: from mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net [IPv6:2a02:6b8:c0c:1621:0:640:12d9:0]) by forwardcorp1d.mail.yandex.net (Yandex) with ESMTPS id 6A30380EEC; Fri, 19 Sep 2025 12:55:59 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:a72::1:38]) by mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id ntP1fK1GvGk0-dH6gTk4y; Fri, 19 Sep 2025 12:55:58 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1758275758; bh=YfB/zHdqRSdlEQYKyrkvvHQ8ka4OYKqJMpFDAmzCODs=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=Ljd4lEAz+pw+i6QWFBIyvQ6Iwt23we8cqcwExgPeovYLNoWD6W0aYjgL6hZMHVgsc bLUHY7TozP3QsySFSymPvOFfOk7odBDtqfwD/KFqzm4qdPjXUjS3IoNda6ngtq2VLq PphrghqQF1eTUPB04GNN9pKhIEX5vjolpy8Ylioc= Authentication-Results: mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: mst@redhat.com Cc: qemu-devel@nongnu.org, philmd@linaro.org, thuth@redhat.com, eblake@redhat.com, michael.roth@amd.com, armbru@redhat.com, farosas@suse.de, peterx@redhat.com, berrange@redhat.com, jasowang@redhat.com, steven.sistare@oracle.com, leiyang@redhat.com, davydov-max@yandex-team.ru, yc-core@yandex-team.ru, Vladimir Sementsov-Ogievskiy Subject: [PATCH v5 11/19] net/tap: move vhost fd initialization to net_tap_new() Date: Fri, 19 Sep 2025 12:55:37 +0300 Message-ID: <20250919095545.1912042-12-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250919095545.1912042-1-vsementsov@yandex-team.ru> References: <20250919095545.1912042-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=178.154.239.200; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1d.mail.yandex.net X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, T_SPF_TEMPERROR=0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @yandex-team.ru) X-ZM-MESSAGEID: 1758275816439116600 Content-Type: text/plain; charset="utf-8" Last step to get rid of dependency on @tap in net_tap_setup(). Signed-off-by: Vladimir Sementsov-Ogievskiy --- net/tap.c | 96 ++++++++++++++++++++++++++++++------------------------- 1 file changed, 53 insertions(+), 43 deletions(-) diff --git a/net/tap.c b/net/tap.c index b4682d7400..b7175e4b10 100644 --- a/net/tap.c +++ b/net/tap.c @@ -83,11 +83,11 @@ typedef struct TAPState { =20 bool sndbuf_required; int sndbuf; + int vhostfd; + uint32_t vhost_busyloop_timeout; } TAPState; =20 -static bool net_tap_setup(TAPState *s, const NetdevTapOptions *tap, - const char *vhostfdname, - int fd, int vnet_hdr, Error **errp); +static bool net_tap_setup(TAPState *s, int fd, int vnet_hdr, Error **errp); =20 static void launch_script(const char *setup_script, const char *ifname, int fd, Error **errp); @@ -336,6 +336,11 @@ static void tap_cleanup(NetClientState *nc) tap_write_poll(s, false); close(s->fd); s->fd =3D -1; + + if (s->vhostfd !=3D -1) { + close(s->vhostfd); + s->vhostfd =3D -1; + } } =20 static void tap_poll(NetClientState *nc, bool enable) @@ -394,12 +399,14 @@ static NetClientInfo net_tap_info =3D { }; =20 static TAPState *net_tap_new(NetClientState *peer, const char *model, - const char *name, const NetdevTapOptions *tap) + const char *name, const NetdevTapOptions *tap, + const char *vhostfdname, Error **errp) { NetClientState *nc =3D qemu_new_net_client(&net_tap_info, peer, model,= name); TAPState *s =3D DO_UPCAST(TAPState, nc, nc); =20 s->fd =3D -1; + s->vhostfd =3D -1; =20 if (!tap) { return s; @@ -409,7 +416,39 @@ static TAPState *net_tap_new(NetClientState *peer, con= st char *model, s->sndbuf =3D (tap->has_sndbuf && tap->sndbuf) ? MIN(tap->sndbuf, INT_MAX) : INT= _MAX; =20 + if (tap->has_vhost ? tap->vhost : + vhostfdname || (tap->has_vhostforce && tap->vhostforce)) { + if (vhostfdname) { + s->vhostfd =3D monitor_fd_param(monitor_cur(), vhostfdname, er= rp); + if (s->vhostfd =3D=3D -1) { + goto failed; + } + if (!g_unix_set_fd_nonblocking(s->vhostfd, true, NULL)) { + error_setg_errno(errp, errno, "Can't use file descriptor %= d", + s->fd); + goto failed; + } + } else { + s->vhostfd =3D open("/dev/vhost-net", O_RDWR); + if (s->vhostfd < 0) { + error_setg_errno(errp, errno, + "tap: open vhost char device failed"); + goto failed; + } + if (!g_unix_set_fd_nonblocking(s->vhostfd, true, NULL)) { + error_setg_errno(errp, errno, "Failed to set FD nonblockin= g"); + goto failed; + } + } + + s->vhost_busyloop_timeout =3D tap->poll_us; + } + return s; + +failed: + qemu_del_net_client(&s->nc); + return NULL; } =20 static bool net_tap_set_fd(TAPState *s, int fd, int vnet_hdr, Error **errp) @@ -657,7 +696,7 @@ int net_init_bridge(const Netdev *netdev, const char *n= ame, return -1; } =20 - s =3D net_tap_new(peer, "bridge", name, NULL); + s =3D net_tap_new(peer, "bridge", name, NULL, NULL, &error_abort); net_tap_set_fd(s, fd, vnet_hdr, &error_abort); =20 qemu_set_info_str(&s->nc, "helper=3D%s,br=3D%s", helper, br); @@ -700,7 +739,10 @@ static void net_init_tap_one(const NetdevTapOptions *t= ap, NetClientState *peer, const char *downscript, const char *vhostfdna= me, int vnet_hdr, int fd, Error **errp) { - TAPState *s =3D net_tap_new(peer, model, name, tap); + TAPState *s =3D net_tap_new(peer, model, name, tap, vhostfdname, errp); + if (!s) { + return; + } =20 if (tap->fd || tap->fds) { qemu_set_info_str(&s->nc, "fd=3D%d", fd); @@ -719,56 +761,24 @@ static void net_init_tap_one(const NetdevTapOptions *= tap, NetClientState *peer, } } =20 - if (!net_tap_setup(s, tap, vhostfdname, fd, vnet_hdr, errp)) { + if (!net_tap_setup(s, fd, vnet_hdr, errp)) { qemu_del_net_client(&s->nc); } } =20 -static bool net_tap_setup(TAPState *s, const NetdevTapOptions *tap, - const char *vhostfdname, - int fd, int vnet_hdr, Error **errp) +static bool net_tap_setup(TAPState *s, int fd, int vnet_hdr, Error **errp) { - int vhostfd; - if (!net_tap_set_fd(s, fd, vnet_hdr, errp)) { return false; } =20 - if (tap->has_vhost ? tap->vhost : - vhostfdname || (tap->has_vhostforce && tap->vhostforce)) { + if (s->vhostfd !=3D -1) { VhostNetOptions options; =20 options.backend_type =3D VHOST_BACKEND_TYPE_KERNEL; options.net_backend =3D &s->nc; - if (tap->has_poll_us) { - options.busyloop_timeout =3D tap->poll_us; - } else { - options.busyloop_timeout =3D 0; - } - - if (vhostfdname) { - vhostfd =3D monitor_fd_param(monitor_cur(), vhostfdname, errp); - if (vhostfd =3D=3D -1) { - return false; - } - if (!g_unix_set_fd_nonblocking(vhostfd, true, NULL)) { - error_setg_errno(errp, errno, "Can't use file descriptor %= d", - fd); - return false; - } - } else { - vhostfd =3D open("/dev/vhost-net", O_RDWR); - if (vhostfd < 0) { - error_setg_errno(errp, errno, - "tap: open vhost char device failed"); - return false; - } - if (!g_unix_set_fd_nonblocking(vhostfd, true, NULL)) { - error_setg_errno(errp, errno, "Failed to set FD nonblockin= g"); - return false; - } - } - options.opaque =3D (void *)(uintptr_t)vhostfd; + options.busyloop_timeout =3D s->vhost_busyloop_timeout; + options.opaque =3D (void *)(uintptr_t)s->vhostfd; options.nvqs =3D 2; options.feature_bits =3D kernel_feature_bits; options.get_acked_features =3D NULL; --=20 2.48.1 From nobody Sun Sep 28 15:28:10 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1758276018; cv=none; d=zohomail.com; s=zohoarc; b=mIG4vKhX371QUJnWDz7z4ZeZBmzCgh8FtnIYwefkIpSVM43gHwh/EHeIqCAzjjRt+A837VGVfde+PteBEgYEbrldsnf5NZtRDqG1S12+pUkFIdFXbtw5wW72jwbdr6gYbv2vQbEFGhtTQzXf02A0IzUlT8N7lxX96v2K9Sh2ZuA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1758276018; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=2Br9SnRNFti6c0drviITVAgb0JbgHHv09a0Qx40m5tQ=; b=BvkoXLm95pRrHTPXvNQN5yoFThua0vxDvKkhyKUKwjXHEWAQjWwFNGGhmvFd+uIZJE8uXwGKI7XqV9QeFOgjtI+qVxoIueCQbGN642NLHgaFeXzvatihIJrH3ft4Kmhagi3kQFaPdZJbHs66RmiExuFB39HGN8e5fNQJ6fIJ7kE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1758276018388608.6093232593845; Fri, 19 Sep 2025 03:00:18 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uzXr4-0006E1-0G; Fri, 19 Sep 2025 05:56:38 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uzXqc-0005hL-18 for qemu-devel@nongnu.org; Fri, 19 Sep 2025 05:56:11 -0400 Received: from forwardcorp1d.mail.yandex.net ([2a02:6b8:c41:1300:1:45:d181:df01]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uzXqY-0004bN-9y for qemu-devel@nongnu.org; Fri, 19 Sep 2025 05:56:09 -0400 Received: from mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net [IPv6:2a02:6b8:c0c:1621:0:640:12d9:0]) by forwardcorp1d.mail.yandex.net (Yandex) with ESMTPS id 0CB5B80EB1; Fri, 19 Sep 2025 12:56:00 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:a72::1:38]) by mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id ntP1fK1GvGk0-y00Yv60n; Fri, 19 Sep 2025 12:55:59 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1758275759; bh=2Br9SnRNFti6c0drviITVAgb0JbgHHv09a0Qx40m5tQ=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=dgT9o8rQmOO0yP/TwrMXGlFsiDygA2qLDme7ULWQ6L4ZfoAxTNmCPAL3W2CkqgCBn 64Ivoh14/MuiPwVF2xuibaWJCQDeB6D3mw/ZcqBflt72pyCLUC1+lHykcAO5aR2qHS LSp9BrqmBZFb3WSkY01pFoaMge2/14/zlXY1+6iE= Authentication-Results: mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: mst@redhat.com Cc: qemu-devel@nongnu.org, philmd@linaro.org, thuth@redhat.com, eblake@redhat.com, michael.roth@amd.com, armbru@redhat.com, farosas@suse.de, peterx@redhat.com, berrange@redhat.com, jasowang@redhat.com, steven.sistare@oracle.com, leiyang@redhat.com, davydov-max@yandex-team.ru, yc-core@yandex-team.ru, Vladimir Sementsov-Ogievskiy Subject: [PATCH v5 12/19] net/tap: use net_tap_setup() in net_init_bridge() Date: Fri, 19 Sep 2025 12:55:38 +0300 Message-ID: <20250919095545.1912042-13-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250919095545.1912042-1-vsementsov@yandex-team.ru> References: <20250919095545.1912042-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a02:6b8:c41:1300:1:45:d181:df01; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1d.mail.yandex.net X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @yandex-team.ru) X-ZM-MESSAGEID: 1758276019749116600 Content-Type: text/plain; charset="utf-8" Finalize the concept of pair net_tap_new() + net_tap_setup(). Now, the only extra part for bridge in net_tap_setup() is initializing vhost_net, but it's under if (s->vhostfd !=3D -1), we never come into it for bridge case. Signed-off-by: Vladimir Sementsov-Ogievskiy --- net/tap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/tap.c b/net/tap.c index b7175e4b10..4ca3cc75d8 100644 --- a/net/tap.c +++ b/net/tap.c @@ -697,7 +697,7 @@ int net_init_bridge(const Netdev *netdev, const char *n= ame, } =20 s =3D net_tap_new(peer, "bridge", name, NULL, NULL, &error_abort); - net_tap_set_fd(s, fd, vnet_hdr, &error_abort); + net_tap_setup(s, fd, vnet_hdr, &error_abort); =20 qemu_set_info_str(&s->nc, "helper=3D%s,br=3D%s", helper, br); =20 --=20 2.48.1 From nobody Sun Sep 28 15:28:10 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1758275926; cv=none; d=zohomail.com; s=zohoarc; b=abQ85dV1PBcuchciWJM6xkoLQuDsLom7kTeJuw7IAnVgCnUfNkwKTU6BYYTwj4sPo8ZW978H4q+0wYyUNPUNtNXGwsDPxJLocbxRIaMY8qy2ncosfY7qWpzMfZgCQHjQIQnxaDkl4H/RvuHbkfE5TwtNPOD99SecK6XhrS5UcpA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1758275926; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=Gh2o10r8Hgw72PFYg3Npf/TMioTDDjuhs1yEouTvYWw=; b=OG2b+EAd9etg66LzeV6UGLG8Xnsz1vy7naUxsIqb9Jqd2cUgXnPkL+CZOOsZQrqazdvWmYyqD6tIfJleyq793F/AkXX73TCvVvPip1edjrUbQtZPtTIoSA0wTlo89ebtszENujyoUfuW/Xdx5geD3ODnUJmC0zKYPlKoWfliNWY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1758275926839306.06494335713; Fri, 19 Sep 2025 02:58:46 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uzXqz-0006Cs-0y; Fri, 19 Sep 2025 05:56:33 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uzXqh-0005w7-PE for qemu-devel@nongnu.org; Fri, 19 Sep 2025 05:56:15 -0400 Received: from forwardcorp1d.mail.yandex.net ([178.154.239.200]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uzXqa-0004bO-8M for qemu-devel@nongnu.org; Fri, 19 Sep 2025 05:56:14 -0400 Received: from mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net [IPv6:2a02:6b8:c0c:1621:0:640:12d9:0]) by forwardcorp1d.mail.yandex.net (Yandex) with ESMTPS id B5E1280EDF; Fri, 19 Sep 2025 12:56:00 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:a72::1:38]) by mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id ntP1fK1GvGk0-MLIEkHSs; Fri, 19 Sep 2025 12:56:00 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1758275760; bh=Gh2o10r8Hgw72PFYg3Npf/TMioTDDjuhs1yEouTvYWw=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=OSuVuHbAFUMFB+tCkBtkXQerSHeeOAhnp9sD2hpMfzfJBm5rHP6v2PnzvxEoo15gG A+7JBWKs8cG8zfAt8K1fE8ldn6MVtTqDq55NCvVJ7prCbscJcRliHDeqpxbkwZo+93 49hxi+YtKKFomixAT6llQS+90se2/LSMJf6VCPKg= Authentication-Results: mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: mst@redhat.com Cc: qemu-devel@nongnu.org, philmd@linaro.org, thuth@redhat.com, eblake@redhat.com, michael.roth@amd.com, armbru@redhat.com, farosas@suse.de, peterx@redhat.com, berrange@redhat.com, jasowang@redhat.com, steven.sistare@oracle.com, leiyang@redhat.com, davydov-max@yandex-team.ru, yc-core@yandex-team.ru, Vladimir Sementsov-Ogievskiy Subject: [PATCH v5 13/19] net/tap: finalize net_tap_set_fd() logic Date: Fri, 19 Sep 2025 12:55:39 +0300 Message-ID: <20250919095545.1912042-14-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250919095545.1912042-1-vsementsov@yandex-team.ru> References: <20250919095545.1912042-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=178.154.239.200; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1d.mail.yandex.net X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @yandex-team.ru) X-ZM-MESSAGEID: 1758275928654116600 Content-Type: text/plain; charset="utf-8" Let net_tap_set_fd() do only fd-related setup. Actually, for further fds-incoming migration we'll want to skip net_tap_set_fd() (as incoming fds are already prepared by source QEMU). So move tap_read_poll() to net_tap_setup(). Don't care about using_vnet_hdr and vhost_net, the state is zero-initialized. Signed-off-by: Vladimir Sementsov-Ogievskiy --- net/tap.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/net/tap.c b/net/tap.c index 4ca3cc75d8..29568ce5d2 100644 --- a/net/tap.c +++ b/net/tap.c @@ -455,7 +455,6 @@ static bool net_tap_set_fd(TAPState *s, int fd, int vne= t_hdr, Error **errp) { s->fd =3D fd; s->host_vnet_hdr_len =3D vnet_hdr ? sizeof(struct virtio_net_hdr) : 0; - s->using_vnet_hdr =3D false; s->has_ufo =3D tap_probe_has_ufo(s->fd); s->has_uso =3D tap_probe_has_uso(s->fd); s->enabled =3D true; @@ -467,8 +466,6 @@ static bool net_tap_set_fd(TAPState *s, int fd, int vne= t_hdr, Error **errp) if (vnet_hdr) { tap_fd_set_vnet_hdr_len(s->fd, s->host_vnet_hdr_len); } - tap_read_poll(s, true); - s->vhost_net =3D NULL; =20 if (s->sndbuf) { Error **e =3D s->sndbuf_required ? errp : NULL; @@ -772,6 +769,8 @@ static bool net_tap_setup(TAPState *s, int fd, int vnet= _hdr, Error **errp) return false; } =20 + tap_read_poll(s, true); + if (s->vhostfd !=3D -1) { VhostNetOptions options; =20 --=20 2.48.1 From nobody Sun Sep 28 15:28:10 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1758276019; cv=none; d=zohomail.com; s=zohoarc; b=k/2Ov8muEjCAF+aKsCzFSKBUfabMk2AUjm/a2MmbbgQH63zmeAq1wqPKXCBXpH0xxY5FK5WnLt1b3jAIdTf3J8EzYKgv2zswioHg0qg4b7wX09JUa499zHwVxLRT/CfqxN1q/K4b1ZMNdn6Kq2gCwT0ljFOG2fy3qJQGXJdinUQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1758276019; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=5HYkPbO4hAPLbFB3eh6cxR13ZYd+5c7xqpnj9WYGlKA=; b=ZXLx/CTNmm26dibsRz9A52YN+MS/eq6HuzAEdmtNmLC9ReCOdNaRDqhufd9jTlK+8dtzQU52MZ7QVhrbfwCjq0d/D2bWLLIFDXR/FXZ/+zPYCSnq3pqut9+we7HPeQG2F56X3VGKaHfHx8o3BVXcAApM6jnK2etz8/ukyihb8ac= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1758276019280628.3695909793961; Fri, 19 Sep 2025 03:00:19 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uzXr7-0006H6-Lo; Fri, 19 Sep 2025 05:56:41 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uzXqe-0005lU-Ql for qemu-devel@nongnu.org; Fri, 19 Sep 2025 05:56:13 -0400 Received: from forwardcorp1d.mail.yandex.net ([2a02:6b8:c41:1300:1:45:d181:df01]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uzXqa-0004bL-7r for qemu-devel@nongnu.org; Fri, 19 Sep 2025 05:56:12 -0400 Received: from mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net [IPv6:2a02:6b8:c0c:1621:0:640:12d9:0]) by forwardcorp1d.mail.yandex.net (Yandex) with ESMTPS id 6500380EF5; Fri, 19 Sep 2025 12:56:01 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:a72::1:38]) by mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id ntP1fK1GvGk0-izTsWkir; Fri, 19 Sep 2025 12:56:00 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1758275760; bh=5HYkPbO4hAPLbFB3eh6cxR13ZYd+5c7xqpnj9WYGlKA=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=O8PNS0M8q1PUQ+0d0seNOEuksM9LZ51zKKB4j32CXsFgEMLf2/BDCnwturFZM1iVX QiW1w9z99LTCJemKoJudjtCrPXgOV7dIu7ACZusjOSzsO2tUuPsq2CxiLskgqk5/Y8 D2U3cQQ9tFHOSTJ1sIBmUT4JqdKFyDimc88tVG3o= Authentication-Results: mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: mst@redhat.com Cc: qemu-devel@nongnu.org, philmd@linaro.org, thuth@redhat.com, eblake@redhat.com, michael.roth@amd.com, armbru@redhat.com, farosas@suse.de, peterx@redhat.com, berrange@redhat.com, jasowang@redhat.com, steven.sistare@oracle.com, leiyang@redhat.com, davydov-max@yandex-team.ru, yc-core@yandex-team.ru, Vladimir Sementsov-Ogievskiy Subject: [PATCH v5 14/19] migration: add MIG_EVENT_PRE_INCOMING Date: Fri, 19 Sep 2025 12:55:40 +0300 Message-ID: <20250919095545.1912042-15-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250919095545.1912042-1-vsementsov@yandex-team.ru> References: <20250919095545.1912042-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a02:6b8:c41:1300:1:45:d181:df01; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1d.mail.yandex.net X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @yandex-team.ru) X-ZM-MESSAGEID: 1758276019794116600 Content-Type: text/plain; charset="utf-8" We are going to implement fds-passing migration feature. When it's enabled (by setting migration parameter), TAP device (and later other devices of-course) is passed through migration channel (which should be a unix socket to pass fds) to a new QEMU. So we need to know during TAP initialization, should we open TAP device, or wait for incoming fds. But we can't check for migration parameter at TAP creation time, as use may set migration parameter later (especially when TAP is added by command line parameter). To solve this, we have prepared TAP initialization code so that opening the device may be postponed to later point. And this later point is obviously the early beginning of qmp_migrate_incoming(): here we already know all migration parameters and capabilities, but we are not in downtime, so we can continue initialization of TAP device. This commit introduces MIG_EVENT_PRE_INCOMING, to be used by TAP code in following commit. Signed-off-by: Vladimir Sementsov-Ogievskiy --- include/migration/misc.h | 1 + migration/migration.c | 8 +++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/include/migration/misc.h b/include/migration/misc.h index a261f99d89..5765fcc204 100644 --- a/include/migration/misc.h +++ b/include/migration/misc.h @@ -63,6 +63,7 @@ typedef enum MigrationEventType { MIG_EVENT_PRECOPY_SETUP, MIG_EVENT_PRECOPY_DONE, MIG_EVENT_PRECOPY_FAILED, + MIG_EVENT_PRE_INCOMING, MIG_EVENT_MAX } MigrationEventType; =20 diff --git a/migration/migration.c b/migration/migration.c index 10c216d25d..88daa13960 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -1696,7 +1696,8 @@ int migration_call_notifiers(MigrationState *s, Migra= tionEventType type, e.type =3D type; ret =3D notifier_with_return_list_notify(&migration_state_notifiers[mo= de], &e, errp); - assert(!ret || type =3D=3D MIG_EVENT_PRECOPY_SETUP); + assert(!ret || type =3D=3D MIG_EVENT_PRECOPY_SETUP || + type =3D=3D MIG_EVENT_PRE_INCOMING); return ret; } =20 @@ -1936,6 +1937,11 @@ void qmp_migrate_incoming(const char *uri, bool has_= channels, return; } =20 + if (migration_call_notifiers(migrate_get_current(), MIG_EVENT_PRE_INCO= MING, + errp)) { + return; + } + if (!yank_register_instance(MIGRATION_YANK_INSTANCE, errp)) { return; } --=20 2.48.1 From nobody Sun Sep 28 15:28:10 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1758275950; cv=none; d=zohomail.com; s=zohoarc; b=mMOZPlcy4ByJtDQ12FGVIwC5RUoYGcdTXykKBZpV8K2S5jrYWe5bf0WcG/+ELupJRI6Rt29J6GFVqqyH6gwBmHSTSz4fNl9A9hqMVr0mNTXok/j4/QnUFCMUl2/2gWBkTVdB50SwAd1i6EihFOPNqXbtIxaANFkqZAGMl76BZxc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1758275950; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=tg4Fw+5ieC9rDCMaIbHE9lHIwS+DZpwqjZgyZPXuNRo=; b=QRaWh5y6h9AM1ammIDtINX5KMHAXetNwJQwVFClO5zjTeRxzD/fTFlReoTkoPy0CuV+eWQR3+BUxQwY285NrN5zkS55bw+w5qB/wsS13cHk3veK1xGDtlfPOvr7y8YkYKK2P0a3yo2evBDeW7VwumM1tdcZl4C27N66T43XXido= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1758275950189120.56966641981273; Fri, 19 Sep 2025 02:59:10 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uzXqs-00069T-9x; Fri, 19 Sep 2025 05:56:26 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uzXqe-0005lA-F3 for qemu-devel@nongnu.org; Fri, 19 Sep 2025 05:56:13 -0400 Received: from forwardcorp1d.mail.yandex.net ([2a02:6b8:c41:1300:1:45:d181:df01]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uzXqY-0004bM-B8 for qemu-devel@nongnu.org; Fri, 19 Sep 2025 05:56:11 -0400 Received: from mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net [IPv6:2a02:6b8:c0c:1621:0:640:12d9:0]) by forwardcorp1d.mail.yandex.net (Yandex) with ESMTPS id 4219580EF9; Fri, 19 Sep 2025 12:56:02 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:a72::1:38]) by mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id ntP1fK1GvGk0-cK8eCDHk; Fri, 19 Sep 2025 12:56:01 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1758275761; bh=tg4Fw+5ieC9rDCMaIbHE9lHIwS+DZpwqjZgyZPXuNRo=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=t/q5qYZ6muX61Pk1rYtp6K9fmg9ZoLiWc4k8MFpuMBlASPJro/kmQBR25GBS7CJPl 01j7JuyoPpa5K3D4mmRZybTJkuF3tkFSOIR3H9anYBw1vI55suk8mszo52cto6iWUx sY3vTQ0Ndbi3afjB2kGDWv78FDvNRIsg88UVrqLY= Authentication-Results: mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: mst@redhat.com Cc: qemu-devel@nongnu.org, philmd@linaro.org, thuth@redhat.com, eblake@redhat.com, michael.roth@amd.com, armbru@redhat.com, farosas@suse.de, peterx@redhat.com, berrange@redhat.com, jasowang@redhat.com, steven.sistare@oracle.com, leiyang@redhat.com, davydov-max@yandex-team.ru, yc-core@yandex-team.ru, Vladimir Sementsov-Ogievskiy Subject: [PATCH v5 15/19] net/tap: postpone tap setup to pre-incoming Date: Fri, 19 Sep 2025 12:55:41 +0300 Message-ID: <20250919095545.1912042-16-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250919095545.1912042-1-vsementsov@yandex-team.ru> References: <20250919095545.1912042-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a02:6b8:c41:1300:1:45:d181:df01; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1d.mail.yandex.net X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @yandex-team.ru) X-ZM-MESSAGEID: 1758275951117116600 Content-Type: text/plain; charset="utf-8" As described in previous commit, to support fds-passing TAP migration, we need to postpone the decision to open the device or to wait for incoming fds up to pre-incoming point (when we actually can decide). This commit only postpones TAP-open case of initialization. We don't try to postpone the all cases of initialization, as it will require a lot more work of refactoring the code. So we postpone only the simple case, for which we are going to support fd-incoming migration: 1. No fds / fd parameters: obviously, if user give fd/fds the should be used, no incoming fds migration is possible. 2. No helper: just for simplicity. It probably possible to allow it (and just ignore in case of fds-incoming migration), to allow user use same cmdline on target QEMU.. But that questionable, and postponable. 3. No sciprt/downscript. It's not simple to support downscript: we should pass the responsiblity to call it on target QEMU with migration.. And back to source QEMU on migration failure. It feasible, but may be implemented later on demand. 3. Concrete ifname and vnet_hdr: to not try to share them between queues, when we only can setup queues as separate entities. Supporting undecided ifname will require to create some extra netdev state, connecting all the taps, to be able to iterate through them. No part of incoming-fds migration is here, we only prepare the code for future implementation of it. Are net-drivers prepared to postponed initialization of NICs? For future feature of fds-passing migration, we are mainly interested in virtio-net. So, let's prepare virtio-net to work with postponed initialization of TAP (two places about early set/get features) and for other drivers let's simply finalize initialization on setting netdev property. Support for other drivers may be added later if needed. Signed-off-by: Vladimir Sementsov-Ogievskiy --- hw/net/virtio-net.c | 65 ++++++++++++++++- include/net/tap.h | 2 + net/tap.c | 172 +++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 237 insertions(+), 2 deletions(-) diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c index 6b5b5dace3..70f688fc3a 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -688,6 +688,21 @@ default_value: return VIRTIO_NET_TX_QUEUE_DEFAULT_SIZE; } =20 +static bool peer_wait_incoming(VirtIONet *n) +{ + NetClientState *nc =3D qemu_get_queue(n->nic); + + if (!nc->peer) { + return false; + } + + if (nc->peer->info->type !=3D NET_CLIENT_DRIVER_TAP) { + return false; + } + + return tap_wait_incoming(nc->peer); +} + static int peer_attach(VirtIONet *n, int index) { NetClientState *nc =3D qemu_get_subqueue(n->nic, index); @@ -2999,7 +3014,17 @@ static void virtio_net_set_multiqueue(VirtIONet *n, = int multiqueue) n->multiqueue =3D multiqueue; virtio_net_change_num_queues(n, max * 2 + 1); =20 - virtio_net_set_queue_pairs(n); + /* + * virtio_net_set_multiqueue() called from set_features(0) on early + * reset, when peer may wait for incoming (and is not initialized + * yet). + * Don't worry about it: virtio_net_set_queue_pairs() will be called + * later form virtio_net_post_load_device(), and anyway will be + * noop for local incoming migration with live backend passing. + */ + if (!peer_wait_incoming(n)) { + virtio_net_set_queue_pairs(n); + } } =20 static int virtio_net_pre_load_queues(VirtIODevice *vdev, uint32_t n) @@ -3028,6 +3053,17 @@ static uint64_t virtio_net_get_features(VirtIODevice= *vdev, uint64_t features, =20 virtio_add_feature(&features, VIRTIO_NET_F_MAC); =20 + if (peer_wait_incoming(n)) { + /* + * Excessive feature set is OK for early initialization when + * we wait for local incoming migration: actual guest-negotiated + * features will come with migration stream anyway. And we are sure + * that we support same host-features as source, because the backe= nd + * is the same (the same TAP device, for example). + */ + return features; + } + if (!peer_has_vnet_hdr(n)) { virtio_clear_feature(&features, VIRTIO_NET_F_CSUM); virtio_clear_feature(&features, VIRTIO_NET_F_HOST_TSO4); @@ -3106,6 +3142,32 @@ static uint64_t virtio_net_get_features(VirtIODevice= *vdev, uint64_t features, return features; } =20 +static int virtio_net_update_host_features(VirtIONet *n) +{ + Error *local_err =3D NULL; + VirtIODevice *vdev =3D VIRTIO_DEVICE(n); + + peer_test_vnet_hdr(n); + + vdev->host_features =3D virtio_net_get_features(vdev, vdev->host_featu= res, + &local_err); + if (local_err) { + error_report_err(local_err); + return -EINVAL; + } + + return 0; +} + +static int virtio_net_pre_load_device(void *opaque) +{ + /* + * Probably backend initialization was postponed to + * pre-incoming point. So, update information now. + */ + return virtio_net_update_host_features(opaque); +} + static int virtio_net_post_load_device(void *opaque, int version_id) { VirtIONet *n =3D opaque; @@ -3498,6 +3560,7 @@ static const VMStateDescription vmstate_virtio_net_de= vice =3D { .name =3D "virtio-net-device", .version_id =3D VIRTIO_NET_VM_VERSION, .minimum_version_id =3D VIRTIO_NET_VM_VERSION, + .pre_load =3D virtio_net_pre_load_device, .post_load =3D virtio_net_post_load_device, .fields =3D (const VMStateField[]) { VMSTATE_UINT8_ARRAY(mac, VirtIONet, ETH_ALEN), diff --git a/include/net/tap.h b/include/net/tap.h index 6f34f13eae..c6f9c1aeb1 100644 --- a/include/net/tap.h +++ b/include/net/tap.h @@ -33,4 +33,6 @@ int tap_disable(NetClientState *nc); =20 int tap_get_fd(NetClientState *nc); =20 +bool tap_wait_incoming(NetClientState *nc); + #endif /* QEMU_NET_TAP_H */ diff --git a/net/tap.c b/net/tap.c index 29568ce5d2..13efea7e4f 100644 --- a/net/tap.c +++ b/net/tap.c @@ -35,7 +35,9 @@ #include "net/eth.h" #include "net/net.h" #include "clients.h" +#include "migration/misc.h" #include "monitor/monitor.h" +#include "system/runstate.h" #include "system/system.h" #include "qapi/error.h" #include "qemu/cutils.h" @@ -85,8 +87,20 @@ typedef struct TAPState { int sndbuf; int vhostfd; uint32_t vhost_busyloop_timeout; + + /* for postponed setup */ + QTAILQ_ENTRY(TAPState) next; + bool vnet_hdr_required; + int vnet_hdr; + bool mq_required; + char *ifname; } TAPState; =20 +static QTAILQ_HEAD(, TAPState) postponed_taps =3D + QTAILQ_HEAD_INITIALIZER(postponed_taps); +static NotifierWithReturn pre_incoming_notifier; + +static bool tap_postponed_init(TAPState *s, Error **errp); static bool net_tap_setup(TAPState *s, int fd, int vnet_hdr, Error **errp); =20 static void launch_script(const char *setup_script, const char *ifname, @@ -341,6 +355,8 @@ static void tap_cleanup(NetClientState *nc) close(s->vhostfd); s->vhostfd =3D -1; } + + g_free(s->ifname); } =20 static void tap_poll(NetClientState *nc, bool enable) @@ -358,6 +374,25 @@ static bool tap_set_steering_ebpf(NetClientState *nc, = int prog_fd) return tap_fd_set_steering_ebpf(s->fd, prog_fd) =3D=3D 0; } =20 +static bool tap_check_peer_type(NetClientState *nc, ObjectClass *oc, + Error **errp) +{ + TAPState *s =3D DO_UPCAST(TAPState, nc, nc); + const char *driver =3D object_class_get_name(oc); + + if (!g_str_has_prefix(driver, "virtio-net-")) { + /* + * Only virtio-net support postponed TAP initialization, so + * for other drivers let's finalize initialization now. + */ + if (tap_wait_incoming(nc)) { + return tap_postponed_init(s, errp); + } + } + + return true; +} + int tap_get_fd(NetClientState *nc) { TAPState *s =3D DO_UPCAST(TAPState, nc, nc); @@ -396,6 +431,7 @@ static NetClientInfo net_tap_info =3D { .set_vnet_be =3D tap_set_vnet_be, .set_steering_ebpf =3D tap_set_steering_ebpf, .get_vhost_net =3D tap_get_vhost_net, + .check_peer_type =3D tap_check_peer_type, }; =20 static TAPState *net_tap_new(NetClientState *peer, const char *model, @@ -822,6 +858,124 @@ static int get_fds(char *str, char *fds[], int max) return i; } =20 +#define TAP_OPEN_IFNAME_SZ 128 + +static bool tap_postponed_init(TAPState *s, Error **errp) +{ + char ifname[TAP_OPEN_IFNAME_SZ]; + int vnet_hdr =3D s->vnet_hdr; + int fd; + + pstrcpy(ifname, sizeof ifname, s->ifname); + fd =3D net_tap_open(&vnet_hdr, s->vnet_hdr_required, NULL, + ifname, sizeof(ifname), + s->mq_required, errp); + if (fd < 0) { + goto fail; + } + + if (!net_tap_setup(s, fd, vnet_hdr, errp)) { + goto fail; + } + + QTAILQ_REMOVE(&postponed_taps, s, next); + return true; + +fail: + QTAILQ_REMOVE(&postponed_taps, s, next); + qemu_del_net_client(&s->nc); + return false; +} + +static int tap_pre_incoming(NotifierWithReturn *notifier, + MigrationEvent *e, + Error **errp) +{ + TAPState *s; + bool ok =3D true; + + if (e->type !=3D MIG_EVENT_PRE_INCOMING) { + return 0; + } + + while (!QTAILQ_EMPTY(&postponed_taps)) { + s =3D QTAILQ_FIRST(&postponed_taps); + if (ok) { + ok =3D tap_postponed_init(s, errp); + } else { + QTAILQ_REMOVE(&postponed_taps, s, next); + qemu_del_net_client(&s->nc); + } + } + + return ok ? 0 : -1; +} + +static bool check_no_script(const char *script_arg) +{ + return script_arg && + (script_arg[0] =3D=3D '\0' || strcmp(script_arg, "no") =3D=3D 0); +} + +static bool tap_postpone_init(const NetdevTapOptions *tap, + const char *name, NetClientState *peer, + bool *postponed, Error **errp) +{ + int queues =3D tap->has_queues ? tap->queues : 1; + + *postponed =3D false; + + if (!runstate_check(RUN_STATE_INMIGRATE)) { + return true; + } + + if (tap->fd || tap->fds || tap->helper || tap->vhostfds) { + return true; + } + + if (!tap->ifname || tap->ifname[0] =3D=3D '\0' || + strstr(tap->ifname, "%d") !=3D NULL) { + /* + * It's hard to postpone logic of parsing template or + * absent ifname + */ + return true; + } + + /* + * Supporting downscipt means understanding and realizing the logic of + * transfer of responsibility to call it in target QEMU process. Or in + * source QEMU process in case of migration failure. So for simplicity= we + * don't support scripts together with fds migration. + */ + if (!check_no_script(tap->script) || !check_no_script(tap->downscript)= ) { + return true; + } + + for (int i =3D 0; i < queues; i++) { + TAPState *s =3D net_tap_new(peer, "tap", name, tap, NULL, errp); + if (!s) { + return false; + } + + s->vnet_hdr_required =3D tap->has_vnet_hdr && tap->vnet_hdr; + s->vnet_hdr =3D tap->has_vnet_hdr ? tap->vnet_hdr : 1; + s->mq_required =3D queues > 1; + s->ifname =3D g_strdup(tap->ifname); + qemu_set_info_str(&s->nc, "ifname=3D%s,script=3Dno,downscript=3Dno= ", + tap->ifname); + + QTAILQ_INSERT_TAIL(&postponed_taps, s, next); + } + + if (!pre_incoming_notifier.notify) { + migration_add_notifier(&pre_incoming_notifier, tap_pre_incoming); + } + + *postponed =3D true; + return true; +} + int net_init_tap(const Netdev *netdev, const char *name, NetClientState *peer, Error **errp) { @@ -832,8 +986,9 @@ int net_init_tap(const Netdev *netdev, const char *name, const char *downscript; Error *err =3D NULL; const char *vhostfdname; - char ifname[128]; + char ifname[TAP_OPEN_IFNAME_SZ]; int ret =3D 0; + bool postponed =3D false; =20 assert(netdev->type =3D=3D NET_CLIENT_DRIVER_TAP); tap =3D &netdev->u.tap; @@ -854,6 +1009,14 @@ int net_init_tap(const Netdev *netdev, const char *na= me, return -1; } =20 + if (!tap_postpone_init(tap, name, peer, &postponed, errp)) { + return -1; + } + + if (postponed) { + return 0; + } + if (tap->fd) { if (tap->ifname || tap->script || tap->downscript || tap->has_vnet_hdr || tap->helper || tap->has_queues || @@ -1089,3 +1252,10 @@ int tap_disable(NetClientState *nc) return ret; } } + +bool tap_wait_incoming(NetClientState *nc) +{ + TAPState *s =3D DO_UPCAST(TAPState, nc, nc); + + return s->fd =3D=3D -1; +} --=20 2.48.1 From nobody Sun Sep 28 15:28:10 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1758275818; cv=none; d=zohomail.com; s=zohoarc; b=E+KTD4dH3S7RLxn+/PdT6xsUfxy42xCNJaKuL8mRlCt5RnP5xv1uTMmAdd3dekMJNm8psumkHDPBYYwqwBuFG5WuZL0zb79yAq/xLyc/NVYAzDM0J+eZbTs5FPN1Gksyl3t6fpbtUfrFPzPtBxSWiOZo63cbR3UX/Bc8yg2Vlyg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1758275818; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=/RIOMdA4Vd4J0yxL7/kgfD4a4heO241Vzlzk0psOhtM=; b=SfyJXpRhwlyn6olTgkNHx1SfqZK6QaeckACEji+uQ1EshPwZy6mvQpCvIrXTG4YkOZRZyBFKQ3cN2MvfObQveyWWa3YsDtGNRyhS4QImIhyAIBd6d5WGzBaRp3agvs8PC4MVQKG3nAdoe0iF/F1JF5CF2ZAMElpBm11CA67PRG8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1758275818647373.58031616420317; Fri, 19 Sep 2025 02:56:58 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uzXr2-0006Dl-BC; Fri, 19 Sep 2025 05:56:36 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uzXqi-0005yU-1P for qemu-devel@nongnu.org; Fri, 19 Sep 2025 05:56:16 -0400 Received: from forwardcorp1d.mail.yandex.net ([178.154.239.200]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uzXqY-0004bS-Ad for qemu-devel@nongnu.org; Fri, 19 Sep 2025 05:56:15 -0400 Received: from mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net [IPv6:2a02:6b8:c0c:1621:0:640:12d9:0]) by forwardcorp1d.mail.yandex.net (Yandex) with ESMTPS id 33C4680616; Fri, 19 Sep 2025 12:56:03 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:a72::1:38]) by mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id ntP1fK1GvGk0-5r6DavdU; Fri, 19 Sep 2025 12:56:02 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1758275762; bh=/RIOMdA4Vd4J0yxL7/kgfD4a4heO241Vzlzk0psOhtM=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=U37ZjEdO2OM14Hn1HC5FH/aNtuhRvMXr2FgLy1LyRr9os+Dc7b5E/wuomg4LY4CJD ynUK6AqoOE9Gw/sFAdSTJcoePM4u+70JWUGFQDfhWD1kMp2xorwL9AfDzfyoMHiL53 qdw9pppe+WuZxsExPQcLGEKb8Ok7KVPm6mteMa9A= Authentication-Results: mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: mst@redhat.com Cc: qemu-devel@nongnu.org, philmd@linaro.org, thuth@redhat.com, eblake@redhat.com, michael.roth@amd.com, armbru@redhat.com, farosas@suse.de, peterx@redhat.com, berrange@redhat.com, jasowang@redhat.com, steven.sistare@oracle.com, leiyang@redhat.com, davydov-max@yandex-team.ru, yc-core@yandex-team.ru, Vladimir Sementsov-Ogievskiy Subject: [PATCH v5 16/19] qapi: add interface for local TAP migration Date: Fri, 19 Sep 2025 12:55:42 +0300 Message-ID: <20250919095545.1912042-17-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250919095545.1912042-1-vsementsov@yandex-team.ru> References: <20250919095545.1912042-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=178.154.239.200; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1d.mail.yandex.net X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @yandex-team.ru) X-ZM-MESSAGEID: 1758275820350116600 Content-Type: text/plain; charset="utf-8" To migrate virtio-net TAP device backend (including open fds) locally, user should simply set migration parameter fds =3D [virtio-net] Why not simple boolean? To simplify migration to further versions, when more devices will support fds migration. Alternatively, we may add per-device option to disable fds-migration, but still: 1. It's more comfortable to set same capabilities/parameters on both source and target QEMU, than care about each device. 2. To not break the design, that machine-type + device options + migration capabilites and parameters are fully define the resulting migration stream. We'll break this if add in future more fds-passing support in devices under same fds=3Dtrue parameter. Signed-off-by: Vladimir Sementsov-Ogievskiy --- include/qapi/util.h | 17 +++++++++++++++++ migration/options.c | 30 +++++++++++++++++++++++++++++ migration/options.h | 2 ++ qapi/migration.json | 46 ++++++++++++++++++++++++++++++++++++--------- 4 files changed, 86 insertions(+), 9 deletions(-) diff --git a/include/qapi/util.h b/include/qapi/util.h index 29bc4eb865..b953402416 100644 --- a/include/qapi/util.h +++ b/include/qapi/util.h @@ -69,4 +69,21 @@ int parse_qapi_name(const char *name, bool complete); _len; \ }) =20 +/* + * For any GenericList @list, return true if it contains specified + * element. + */ +#define QAPI_LIST_CONTAINS(list, el) \ + ({ \ + bool _found =3D false; \ + typeof_strip_qual(list) _tail; \ + for (_tail =3D list; _tail !=3D NULL; _tail =3D _tail->next) { \ + if (_tail->value =3D=3D el) { \ + _found =3D true; \ + break; \ + } \ + } \ + _found; \ + }) + #endif diff --git a/migration/options.c b/migration/options.c index 4e923a2e07..061a1b8eaf 100644 --- a/migration/options.c +++ b/migration/options.c @@ -13,6 +13,7 @@ =20 #include "qemu/osdep.h" #include "qemu/error-report.h" +#include "qapi/util.h" #include "exec/target_page.h" #include "qapi/clone-visitor.h" #include "qapi/error.h" @@ -262,6 +263,13 @@ bool migrate_mapped_ram(void) return s->capabilities[MIGRATION_CAPABILITY_MAPPED_RAM]; } =20 +bool migrate_fds_virtio_net(void) +{ + MigrationState *s =3D migrate_get_current(); + + return QAPI_LIST_CONTAINS(s->parameters.fds, FDS_TARGET_VIRTIO_NET); +} + bool migrate_ignore_shared(void) { MigrationState *s =3D migrate_get_current(); @@ -960,6 +968,11 @@ MigrationParameters *qmp_query_migrate_parameters(Erro= r **errp) params->has_direct_io =3D true; params->direct_io =3D s->parameters.direct_io; =20 + if (s->parameters.has_fds) { + params->has_fds =3D true; + params->fds =3D QAPI_CLONE(FdsTargetList, s->parameters.fds); + } + return params; } =20 @@ -1179,6 +1192,11 @@ bool migrate_params_check(MigrationParameters *param= s, Error **errp) return false; } =20 + if (params->has_fds) { + error_setg(errp, "Not implemented"); + return false; + } + return true; } =20 @@ -1297,6 +1315,11 @@ static void migrate_params_test_apply(MigrateSetPara= meters *params, if (params->has_direct_io) { dest->direct_io =3D params->direct_io; } + + if (params->has_fds) { + dest->has_fds =3D true; + dest->fds =3D params->fds; + } } =20 static void migrate_params_apply(MigrateSetParameters *params, Error **err= p) @@ -1429,6 +1452,13 @@ static void migrate_params_apply(MigrateSetParameter= s *params, Error **errp) if (params->has_direct_io) { s->parameters.direct_io =3D params->direct_io; } + + if (params->has_fds) { + qapi_free_FdsTargetList(s->parameters.fds); + + s->parameters.has_fds =3D true; + s->parameters.fds =3D QAPI_CLONE(FdsTargetList, params->fds); + } } =20 void qmp_migrate_set_parameters(MigrateSetParameters *params, Error **errp) diff --git a/migration/options.h b/migration/options.h index 82d839709e..a79472a235 100644 --- a/migration/options.h +++ b/migration/options.h @@ -87,6 +87,8 @@ const char *migrate_tls_hostname(void); uint64_t migrate_xbzrle_cache_size(void); ZeroPageDetection migrate_zero_page_detection(void); =20 +bool migrate_fds_virtio_net(void); + /* parameters helpers */ =20 bool migrate_params_check(MigrationParameters *params, Error **errp); diff --git a/qapi/migration.json b/qapi/migration.json index 2387c21e9c..6ef9629c6d 100644 --- a/qapi/migration.json +++ b/qapi/migration.json @@ -747,6 +747,19 @@ '*transform': 'BitmapMigrationBitmapAliasTransform' } } =20 +## +# @FdsTarget: +# +# @virtio-net: Enable live backend migration for virtio-net. +# The only supported backend is TAP device. When enabled, TAP fds +# and all related state is passed to target QEMU through migration +# channel (which should be unix socket). +# +# Since: 10.2 +## +{ 'enum': 'FdsTarget', + 'data': [ 'virtio-net' ] } + ## # @BitmapMigrationNodeAlias: # @@ -924,10 +937,14 @@ # only has effect if the @mapped-ram capability is enabled. # (Since 9.1) # +# @fds: List of targets to enable live-backend migration for. This +# requires migration channel to be a unix socket (to pass fds +# through). (Since 10.2) +# # Features: # -# @unstable: Members @x-checkpoint-delay and -# @x-vcpu-dirty-limit-period are experimental. +# @unstable: Members @x-checkpoint-delay, +# @x-vcpu-dirty-limit-period and @fds are experimental. # # Since: 2.4 ## @@ -950,7 +967,8 @@ 'vcpu-dirty-limit', 'mode', 'zero-page-detection', - 'direct-io'] } + 'direct-io', + 'fds' ] } =20 ## # @MigrateSetParameters: @@ -1105,10 +1123,14 @@ # only has effect if the @mapped-ram capability is enabled. # (Since 9.1) # +# @fds: List of targets to enable live-backend migration for. This +# requires migration channel to be a unix socket (to pass fds +# through). (Since 10.2) +# # Features: # -# @unstable: Members @x-checkpoint-delay and -# @x-vcpu-dirty-limit-period are experimental. +# @unstable: Members @x-checkpoint-delay, +# @x-vcpu-dirty-limit-period and @fds are experimental. # # TODO: either fuse back into `MigrationParameters`, or make # `MigrationParameters` members mandatory @@ -1146,7 +1168,8 @@ '*vcpu-dirty-limit': 'uint64', '*mode': 'MigMode', '*zero-page-detection': 'ZeroPageDetection', - '*direct-io': 'bool' } } + '*direct-io': 'bool', + '*fds': { 'type': [ 'FdsTarget' ], 'features': [ 'unstable' ] = } } } =20 ## # @migrate-set-parameters: @@ -1315,10 +1338,14 @@ # only has effect if the @mapped-ram capability is enabled. # (Since 9.1) # +# @fds: List of targets to enable live-backend migration for. This +# requires migration channel to be a unix socket (to pass fds +# through). (Since 10.2) +# # Features: # -# @unstable: Members @x-checkpoint-delay and -# @x-vcpu-dirty-limit-period are experimental. +# @unstable: Members @x-checkpoint-delay, +# @x-vcpu-dirty-limit-period and @fds are experimental. # # Since: 2.4 ## @@ -1353,7 +1380,8 @@ '*vcpu-dirty-limit': 'uint64', '*mode': 'MigMode', '*zero-page-detection': 'ZeroPageDetection', - '*direct-io': 'bool' } } + '*direct-io': 'bool', + '*fds': { 'type': [ 'FdsTarget' ], 'features': [ 'unstable' ] = } } } =20 ## # @query-migrate-parameters: --=20 2.48.1 From nobody Sun Sep 28 15:28:10 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1758276032; cv=none; d=zohomail.com; s=zohoarc; b=caZZL7MhhXotHjRGDmMsQMzXzDS3cMESi4c2BaLQ5kVL/RgTiALk7oxrkFxdxLa/9uhNnepFmxQPUa/t/fnYgFPtseKrP95mY4Mkar5fCUBrrenut3GwlUXTomj+Rfc2tEraEpf/chS84tdRhJxsHg34nkb4UXNdcv1iGVCbXb4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1758276032; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=ZOT4nc4PuASqIOudC/cUMhlxHtQE++eLa6dzdOEVzdA=; b=lC0VNNJN2f2IT/ym2WcsPWauGOzCo6paNqEfjWIIOfjz4NPbkRcQvyrtu8boIgbZS0o164cD6fxfanKNRKeLM1/heYfSG46Sbfnm8yYtcBZUFeVRnmlZszk/for5cYLAVDAP6lXOK9HfogLagVYmjuIXb1gWSZ386MKi8kQSBrQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1758276032487675.1598537434147; Fri, 19 Sep 2025 03:00:32 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uzXqu-0006AI-19; Fri, 19 Sep 2025 05:56:28 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uzXqf-0005nx-1f for qemu-devel@nongnu.org; Fri, 19 Sep 2025 05:56:13 -0400 Received: from forwardcorp1d.mail.yandex.net ([2a02:6b8:c41:1300:1:45:d181:df01]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uzXqY-0004bX-BI for qemu-devel@nongnu.org; Fri, 19 Sep 2025 05:56:12 -0400 Received: from mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net [IPv6:2a02:6b8:c0c:1621:0:640:12d9:0]) by forwardcorp1d.mail.yandex.net (Yandex) with ESMTPS id F080B80624; Fri, 19 Sep 2025 12:56:03 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:a72::1:38]) by mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id ntP1fK1GvGk0-7Md5G5IF; Fri, 19 Sep 2025 12:56:03 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1758275763; bh=ZOT4nc4PuASqIOudC/cUMhlxHtQE++eLa6dzdOEVzdA=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=IiSp9Mik+D3360kmAlIISMNRoLFyJZ6jff+PMaIrg2U7Tc1PhpKv3UHoByuMIL7cO RryXhzDZD1+PIINv1ms+6cmv+9ZiAaH7Hqd4WrrJi7R3zy3tx5T1brAM7XZOfkeioN TKTDkHemBLRIZQunCjxFBlX+c9x8NjHtis0pHNnA= Authentication-Results: mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: mst@redhat.com Cc: qemu-devel@nongnu.org, philmd@linaro.org, thuth@redhat.com, eblake@redhat.com, michael.roth@amd.com, armbru@redhat.com, farosas@suse.de, peterx@redhat.com, berrange@redhat.com, jasowang@redhat.com, steven.sistare@oracle.com, leiyang@redhat.com, davydov-max@yandex-team.ru, yc-core@yandex-team.ru, Vladimir Sementsov-Ogievskiy Subject: [PATCH v5 17/19] virtio-net: support fds migration of TAP backend Date: Fri, 19 Sep 2025 12:55:43 +0300 Message-ID: <20250919095545.1912042-18-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250919095545.1912042-1-vsementsov@yandex-team.ru> References: <20250919095545.1912042-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a02:6b8:c41:1300:1:45:d181:df01; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1d.mail.yandex.net X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @yandex-team.ru) X-ZM-MESSAGEID: 1758276034229116600 Content-Type: text/plain; charset="utf-8" Finally implement the new migration option fds =3D [virtio-net]. With this enabled (both on source and target) of-course, and with unix-socket used as migration-channel, we do "migrate" the virtio-net backend - TAP devices, with all its fds. This way management tool should not care about creating new TAP, and handling switching to it. Migration downtime become shorter. How it works: 1. For incoming migration, we postpone TAP initialization up to pre-incoming point. 2. At pre-incoming point we see that virtio-net target for fds migration is set, so we postpone TAP initialization up to post-load 3. During virtio-load, we get TAP state (and fds) as part of virtio-net state 4. In post-load we finalize TAP initialization Signed-off-by: Vladimir Sementsov-Ogievskiy --- hw/net/virtio-net.c | 73 +++++++++++++++++++++++++++++++++++++++++++++ include/net/tap.h | 3 ++ migration/options.c | 5 ---- net/tap.c | 54 ++++++++++++++++++++++++++++++++- 4 files changed, 129 insertions(+), 6 deletions(-) diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c index 70f688fc3a..2817c0f198 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -26,6 +26,7 @@ #include "qemu/option.h" #include "qemu/option_int.h" #include "qemu/config-file.h" +#include "qemu/typedefs.h" #include "qobject/qdict.h" #include "hw/virtio/virtio-net.h" #include "net/vhost_net.h" @@ -38,6 +39,8 @@ #include "qapi/qapi-events-migration.h" #include "hw/virtio/virtio-access.h" #include "migration/misc.h" +#include "migration/migration.h" +#include "migration/options.h" #include "standard-headers/linux/ethtool.h" #include "system/system.h" #include "system/replay.h" @@ -3147,6 +3150,11 @@ static int virtio_net_update_host_features(VirtIONet= *n) Error *local_err =3D NULL; VirtIODevice *vdev =3D VIRTIO_DEVICE(n); =20 + if (peer_wait_incoming(n)) { + /* It's too early for updating options. */ + return 0; + } + peer_test_vnet_hdr(n); =20 vdev->host_features =3D virtio_net_get_features(vdev, vdev->host_featu= res, @@ -3287,6 +3295,9 @@ struct VirtIONetMigTmp { uint16_t curr_queue_pairs_1; uint8_t has_ufo; uint32_t has_vnet_hdr; + + NetClientState *ncs; + uint32_t max_queue_pairs; }; =20 /* The 2nd and subsequent tx_waiting flags are loaded later than @@ -3556,6 +3567,65 @@ static const VMStateDescription vhost_user_net_backe= nd_state =3D { } }; =20 +static bool virtio_net_is_tap_fds_mig(void *opaque, int version_id) +{ + VirtIONet *n =3D opaque; + NetClientState *nc; + + nc =3D qemu_get_queue(n->nic); + + return migrate_fds_virtio_net() && nc->peer && + nc->peer->info->type =3D=3D NET_CLIENT_DRIVER_TAP; +} + +static int virtio_net_nic_pre_save(void *opaque) +{ + struct VirtIONetMigTmp *tmp =3D opaque; + + tmp->ncs =3D tmp->parent->nic->ncs; + tmp->max_queue_pairs =3D tmp->parent->max_queue_pairs; + + return 0; +} + +static int virtio_net_nic_pre_load(void *opaque) +{ + /* Reuse the pointer setup from save */ + virtio_net_nic_pre_save(opaque); + + return 0; +} + +static int virtio_net_nic_post_load(void *opaque, int version_id) +{ + struct VirtIONetMigTmp *tmp =3D opaque; + + return virtio_net_update_host_features(tmp->parent); +} + +static const VMStateDescription vmstate_virtio_net_nic_nc =3D { + .name =3D "virtio-net-nic-nc", + .fields =3D (const VMStateField[]) { + VMSTATE_STRUCT_POINTER(peer, NetClientState, vmstate_tap, + NetClientState), + VMSTATE_END_OF_LIST() + }, +}; + +static const VMStateDescription vmstate_virtio_net_nic =3D { + .name =3D "virtio-net-nic", + .pre_load =3D virtio_net_nic_pre_load, + .pre_save =3D virtio_net_nic_pre_save, + .post_load =3D virtio_net_nic_post_load, + .fields =3D (const VMStateField[]) { + VMSTATE_STRUCT_VARRAY_POINTER_UINT32(ncs, struct VirtIONetMigTmp, + max_queue_pairs, + vmstate_virtio_net_nic_nc, + struct NetClientState), + VMSTATE_END_OF_LIST() + }, +}; + static const VMStateDescription vmstate_virtio_net_device =3D { .name =3D "virtio-net-device", .version_id =3D VIRTIO_NET_VM_VERSION, @@ -3588,6 +3658,9 @@ static const VMStateDescription vmstate_virtio_net_de= vice =3D { * but based on the uint. */ VMSTATE_BUFFER_POINTER_UNSAFE(vlans, VirtIONet, 0, MAX_VLAN >> 3), + VMSTATE_WITH_TMP_TEST(VirtIONet, virtio_net_is_tap_fds_mig, + struct VirtIONetMigTmp, + vmstate_virtio_net_nic), VMSTATE_WITH_TMP(VirtIONet, struct VirtIONetMigTmp, vmstate_virtio_net_has_vnet), VMSTATE_UINT8(mac_table.multi_overflow, VirtIONet), diff --git a/include/net/tap.h b/include/net/tap.h index c6f9c1aeb1..0be083f8da 100644 --- a/include/net/tap.h +++ b/include/net/tap.h @@ -26,6 +26,7 @@ #ifndef QEMU_NET_TAP_H #define QEMU_NET_TAP_H =20 +#include "qemu/typedefs.h" #include "standard-headers/linux/virtio_net.h" =20 int tap_enable(NetClientState *nc); @@ -35,4 +36,6 @@ int tap_get_fd(NetClientState *nc); =20 bool tap_wait_incoming(NetClientState *nc); =20 +extern const VMStateDescription vmstate_tap; + #endif /* QEMU_NET_TAP_H */ diff --git a/migration/options.c b/migration/options.c index 061a1b8eaf..c6eeadaab5 100644 --- a/migration/options.c +++ b/migration/options.c @@ -1192,11 +1192,6 @@ bool migrate_params_check(MigrationParameters *param= s, Error **errp) return false; } =20 - if (params->has_fds) { - error_setg(errp, "Not implemented"); - return false; - } - return true; } =20 diff --git a/net/tap.c b/net/tap.c index 13efea7e4f..dcbc6466e5 100644 --- a/net/tap.c +++ b/net/tap.c @@ -36,6 +36,7 @@ #include "net/net.h" #include "clients.h" #include "migration/misc.h" +#include "migration/options.h" #include "monitor/monitor.h" #include "system/runstate.h" #include "system/system.h" @@ -94,6 +95,7 @@ typedef struct TAPState { int vnet_hdr; bool mq_required; char *ifname; + bool attached_to_virtio_net; } TAPState; =20 static QTAILQ_HEAD(, TAPState) postponed_taps =3D @@ -390,6 +392,8 @@ static bool tap_check_peer_type(NetClientState *nc, Obj= ectClass *oc, } } =20 + s->attached_to_virtio_net =3D true; + return true; } =20 @@ -801,7 +805,7 @@ static void net_init_tap_one(const NetdevTapOptions *ta= p, NetClientState *peer, =20 static bool net_tap_setup(TAPState *s, int fd, int vnet_hdr, Error **errp) { - if (!net_tap_set_fd(s, fd, vnet_hdr, errp)) { + if (fd > -1 && !net_tap_set_fd(s, fd, vnet_hdr, errp)) { return false; } =20 @@ -893,6 +897,7 @@ static int tap_pre_incoming(NotifierWithReturn *notifie= r, { TAPState *s; bool ok =3D true; + bool mig_fds =3D migrate_fds_virtio_net(); =20 if (e->type !=3D MIG_EVENT_PRE_INCOMING) { return 0; @@ -901,6 +906,11 @@ static int tap_pre_incoming(NotifierWithReturn *notifi= er, while (!QTAILQ_EMPTY(&postponed_taps)) { s =3D QTAILQ_FIRST(&postponed_taps); if (ok) { + if (mig_fds && s->attached_to_virtio_net) { + /* We'll get fds from incoming migration */ + QTAILQ_REMOVE(&postponed_taps, s, next); + continue; + } ok =3D tap_postponed_init(s, errp); } else { QTAILQ_REMOVE(&postponed_taps, s, next); @@ -1253,6 +1263,48 @@ int tap_disable(NetClientState *nc) } } =20 +static int tap_pre_load(void *opaque) +{ + TAPState *s =3D opaque; + + if (s->fd !=3D -1) { + error_report( + "TAP is already initialized and cannot receive incoming fd"); + return -EINVAL; + } + + return 0; +} + +static int tap_post_load(void *opaque, int version_id) +{ + TAPState *s =3D opaque; + Error *local_err =3D NULL; + + if (!net_tap_setup(s, -1, -1, &local_err)) { + error_report_err(local_err); + qemu_del_net_client(&s->nc); + return -EINVAL; + } + + return 0; +} + +const VMStateDescription vmstate_tap =3D { + .name =3D "net-tap", + .pre_load =3D tap_pre_load, + .post_load =3D tap_post_load, + .fields =3D (const VMStateField[]) { + VMSTATE_FD(fd, TAPState), + VMSTATE_BOOL(using_vnet_hdr, TAPState), + VMSTATE_BOOL(has_ufo, TAPState), + VMSTATE_BOOL(has_uso, TAPState), + VMSTATE_BOOL(enabled, TAPState), + VMSTATE_UINT32(host_vnet_hdr_len, TAPState), + VMSTATE_END_OF_LIST() + } +}; + bool tap_wait_incoming(NetClientState *nc) { TAPState *s =3D DO_UPCAST(TAPState, nc, nc); --=20 2.48.1 From nobody Sun Sep 28 15:28:10 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1758275863; cv=none; d=zohomail.com; s=zohoarc; b=D60uXPXrIseUEeEeoYiTnxrXqkfu8K+uaBSEtgUs7Ybc75ROmrySKyi+f1GDPq6DdB3QjFqiEyHOns8apxxwlHkQxzsCvV1EdXpmC+BUL93hw4YpcyuJnoeFf4QJMGJvZLvRJavJVf4bhXSeBEQRBiXSJ3SQs3UnEnHvhyQqffU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1758275863; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=bqNpK1Ki6H6lnmB55UWwMJXa8HleJsx45/pooWD8jq4=; b=XKWwhZ9doV+JtVUHChPg5TYiroySHnV0NrmaDM8q67CfQHWHupN3gjOcFFstYuG3udYmmoZZKqUIi5IwnHCgBaA1aCkj25i5GjZLB0tAXkZeysfZwSEYQ423rYhBLY858fwNpn9i3px7IFR6XEcinwdHm51WP/EUw+SMWqhnV68= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1758275863730798.7914251159667; Fri, 19 Sep 2025 02:57:43 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uzXr9-0006Kx-L7; Fri, 19 Sep 2025 05:56:43 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uzXqg-0005vh-Hv for qemu-devel@nongnu.org; Fri, 19 Sep 2025 05:56:15 -0400 Received: from forwardcorp1d.mail.yandex.net ([2a02:6b8:c41:1300:1:45:d181:df01]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uzXqa-0004cA-8o for qemu-devel@nongnu.org; Fri, 19 Sep 2025 05:56:14 -0400 Received: from mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net [IPv6:2a02:6b8:c0c:1621:0:640:12d9:0]) by forwardcorp1d.mail.yandex.net (Yandex) with ESMTPS id A72318099C; Fri, 19 Sep 2025 12:56:04 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:a72::1:38]) by mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id ntP1fK1GvGk0-pIjxN3qU; Fri, 19 Sep 2025 12:56:04 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1758275764; bh=bqNpK1Ki6H6lnmB55UWwMJXa8HleJsx45/pooWD8jq4=; h=Cc:Message-ID:References:Date:In-Reply-To:Subject:To:From; b=SsO65TG/Mk3gv/ERTaN5wnUmfhV55LC2LH5Wi/oCZVGRDC2WKRJ0gQW+uvADqitJi AQp0uxJVw9feeao9Kw6yhcDGoHovn8QiVEqlTuI3/g0WUKqsTb1qFh9HJkfIR5D+mO /rcB/Bk6zpFPHsaKObHpPGqzNRKRZCrPvIR92IPI= Authentication-Results: mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: mst@redhat.com Cc: qemu-devel@nongnu.org, philmd@linaro.org, thuth@redhat.com, eblake@redhat.com, michael.roth@amd.com, armbru@redhat.com, farosas@suse.de, peterx@redhat.com, berrange@redhat.com, jasowang@redhat.com, steven.sistare@oracle.com, leiyang@redhat.com, davydov-max@yandex-team.ru, yc-core@yandex-team.ru, Vladimir Sementsov-Ogievskiy Subject: [PATCH v5 18/19] tests/functional: add skipUnlessPasswordlessSudo() decorator Date: Fri, 19 Sep 2025 12:55:44 +0300 Message-ID: <20250919095545.1912042-19-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250919095545.1912042-1-vsementsov@yandex-team.ru> References: <20250919095545.1912042-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a02:6b8:c41:1300:1:45:d181:df01; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1d.mail.yandex.net X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @yandex-team.ru) X-ZM-MESSAGEID: 1758275866201116600 To be used in the next commit: that would be a test for TAP networking, and it will need to setup TAP device. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Daniel P. Berrang=C3=A9 Reviewed-by: Thomas Huth --- tests/functional/qemu_test/decorators.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tests/functional/qemu_test/decorators.py b/tests/functional/qe= mu_test/decorators.py index c0d1567b14..4b332804ef 100644 --- a/tests/functional/qemu_test/decorators.py +++ b/tests/functional/qemu_test/decorators.py @@ -6,6 +6,7 @@ import os import platform import resource +import subprocess from unittest import skipIf, skipUnless =20 from .cmd import which @@ -149,3 +150,18 @@ def skipLockedMemoryTest(locked_memory): ulimit_memory =3D=3D resource.RLIM_INFINITY or ulimit_memory >=3D = locked_memory * 1024, f'Test required {locked_memory} kB of available locked memory', ) + +''' +Decorator to skip execution of a test if passwordless +sudo command is not available. +''' +def skipUnlessPasswordlessSudo(): + proc =3D subprocess.run(["sudo", "-n", "/bin/true"], + stdin=3Dsubprocess.PIPE, + stdout=3Dsubprocess.PIPE, + stderr=3Dsubprocess.STDOUT, + universal_newlines=3DTrue, + check=3DFalse) + + return skipUnless(proc.returncode =3D=3D 0, + f'requires password-less sudo access: {proc.stdout}') --=20 2.48.1 From nobody Sun Sep 28 15:28:10 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1758275817; cv=none; d=zohomail.com; s=zohoarc; b=eq3YY42e7sJvArypzMvqAG2VkYawQOKSJHGaw29FJTFt7BrSdofBk+ZQz+IZqCGDlwxB3yK7SuxEkEw5MMpimSe3k3RMTJOd4X233gKZXIkW7x5kA4XMF5JMKG/n0R6VU460aCWAL4rRqTvw0nOjYbxkTeCkYa8j0FSbNoqToBs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1758275817; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=pIDrg/rZ+s0UiZVviHk+pKIioFxBN3VJMMLRvhTpcv0=; b=NxYATvs+fOJoNiIguERgg5XaKIjHTJXSuA4ake+RDgndWTa2lktEFJH8ZexzXgJRx1P7YOqbQY6WA7yXuQwf2rIS8RkefKIH3Xt1BPOjrNHr+WOU0mG5UzYCDvdnG8JVRsPLS/sa+BQj5zDPWgXSLlrqf+qFyvgUz/vg4ItrMOU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1758275817383925.4836693716767; Fri, 19 Sep 2025 02:56:57 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uzXqq-00067e-2n; Fri, 19 Sep 2025 05:56:24 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uzXqj-00065F-Bi for qemu-devel@nongnu.org; Fri, 19 Sep 2025 05:56:18 -0400 Received: from forwardcorp1d.mail.yandex.net ([178.154.239.200]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uzXqb-0004cB-BI for qemu-devel@nongnu.org; Fri, 19 Sep 2025 05:56:17 -0400 Received: from mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net [IPv6:2a02:6b8:c0c:1621:0:640:12d9:0]) by forwardcorp1d.mail.yandex.net (Yandex) with ESMTPS id 11CB780BA7; Fri, 19 Sep 2025 12:56:06 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:a72::1:38]) by mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id ntP1fK1GvGk0-0sQjC3U1; Fri, 19 Sep 2025 12:56:04 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1758275764; bh=pIDrg/rZ+s0UiZVviHk+pKIioFxBN3VJMMLRvhTpcv0=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=xmrqZ0x+fZ1JkhiGziBNITOhtufrJ/Qtr7oirysL4p+0wXjXmcfgqh2Tv4Mwx/u2+ rQUGlzC03BPiZrygROxEu+qKBUQcogiUMebxU4G3w0FTBrVjJ+zfwZJXDg248jVFOR aOIiJIbwOKsyP30wzL9LCXD52xEkzw2se0COWGC8= Authentication-Results: mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: mst@redhat.com Cc: qemu-devel@nongnu.org, philmd@linaro.org, thuth@redhat.com, eblake@redhat.com, michael.roth@amd.com, armbru@redhat.com, farosas@suse.de, peterx@redhat.com, berrange@redhat.com, jasowang@redhat.com, steven.sistare@oracle.com, leiyang@redhat.com, davydov-max@yandex-team.ru, yc-core@yandex-team.ru, Vladimir Sementsov-Ogievskiy Subject: [PATCH v5 19/19] tests/functional: add test_x86_64_tap_fd_migration Date: Fri, 19 Sep 2025 12:55:45 +0300 Message-ID: <20250919095545.1912042-20-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250919095545.1912042-1-vsementsov@yandex-team.ru> References: <20250919095545.1912042-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=178.154.239.200; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1d.mail.yandex.net X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @yandex-team.ru) X-ZM-MESSAGEID: 1758275818376116600 Content-Type: text/plain; charset="utf-8" Add test for a new feature of local TAP migration with fd passing through unix socket. Signed-off-by: Vladimir Sementsov-Ogievskiy --- .../test_x86_64_tap_fd_migration.py | 343 ++++++++++++++++++ 1 file changed, 343 insertions(+) create mode 100644 tests/functional/test_x86_64_tap_fd_migration.py diff --git a/tests/functional/test_x86_64_tap_fd_migration.py b/tests/funct= ional/test_x86_64_tap_fd_migration.py new file mode 100644 index 0000000000..ac80830eea --- /dev/null +++ b/tests/functional/test_x86_64_tap_fd_migration.py @@ -0,0 +1,343 @@ +#!/usr/bin/env python3 +# +# Functional test that tests TAP local migration +# with fd passing +# +# Copyright (c) Yandex +# +# SPDX-License-Identifier: GPL-2.0-or-later + +import os +import time +import subprocess +from subprocess import run +import signal +from typing import Tuple + +from qemu_test import ( + LinuxKernelTest, + Asset, + exec_command_and_wait_for_pattern, +) +from qemu_test.decorators import skipUnlessPasswordlessSudo + +GUEST_IP =3D "10.0.1.2" +GUEST_IP_MASK =3D f"{GUEST_IP}/24" +GUEST_MAC =3D "d6:0d:75:f8:0f:b7" +HOST_IP =3D "10.0.1.1" +HOST_IP_MASK =3D f"{HOST_IP}/24" +TAP_ID =3D "tap0" +TAP_MAC =3D "e6:1d:44:b5:03:5d" + + +def del_tap() -> None: + run( + ["sudo", "ip", "tuntap", "del", TAP_ID, "mode", "tap", "multi_queu= e"], + check=3DTrue, + ) + + +def init_tap() -> None: + run( + ["sudo", "ip", "tuntap", "add", "dev", TAP_ID, "mode", "tap", "mul= ti_queue"], + check=3DTrue, + ) + run(["sudo", "ip", "link", "set", "dev", TAP_ID, "address", TAP_MAC], = check=3DTrue) + run(["sudo", "ip", "addr", "add", HOST_IP_MASK, "dev", TAP_ID], check= =3DTrue) + run(["sudo", "ip", "link", "set", TAP_ID, "up"], check=3DTrue) + + +def parse_ping_line(line: str) -> float: + # suspect lines like + # [1748524876.590509] 64 bytes from 94.245.155.3 \ + # (94.245.155.3): icmp_seq=3D1 ttl=3D250 time=3D101 ms + spl =3D line.split() + return float(spl[0][1:-1]) + + +def parse_ping_output(out) -> Tuple[bool, float, float]: + lines =3D [x for x in out.split("\n") if x.startswith("[")] + + try: + first_no_ans =3D next( + (ind for ind in range(len(lines)) if lines[ind][20:26] =3D=3D = "no ans") + ) + except StopIteration: + return False, parse_ping_line(lines[0]), parse_ping_line(lines[-1]) + + last_no_ans =3D next( + (ind for ind in range(len(lines) - 1, -1, -1) if lines[ind][20:26]= =3D=3D "no ans") + ) + + return ( + True, + parse_ping_line(lines[first_no_ans]), + parse_ping_line(lines[last_no_ans]), + ) + + +def wait_migration_finish(source_vm, target_vm): + migr_events =3D ( + ("MIGRATION", {"data": {"status": "completed"}}), + ("MIGRATION", {"data": {"status": "failed"}}), + ) + + source_e =3D source_vm.events_wait(migr_events)["data"] + target_e =3D target_vm.events_wait(migr_events)["data"] + + source_s =3D source_vm.cmd("query-status")["status"] + target_s =3D target_vm.cmd("query-status")["status"] + + assert ( + source_e["status"] =3D=3D "completed" + and target_e["status"] =3D=3D "completed" + and source_s =3D=3D "postmigrate" + and target_s =3D=3D "paused" + ), f"""Migration failed: + SRC status: {source_s} + SRC event: {source_e} + TGT status: {target_s} + TGT event:{target_e}""" + + +@skipUnlessPasswordlessSudo() +class VhostUserBlkFdMigration(LinuxKernelTest): + + ASSET_KERNEL =3D Asset( + ( + "https://archives.fedoraproject.org/pub/archive/fedora/linux/r= eleases" + "/31/Server/x86_64/os/images/pxeboot/vmlinuz" + ), + "d4738d03dbbe083ca610d0821d0a8f1488bebbdccef54ce33e3adb35fda00129", + ) + + ASSET_INITRD =3D Asset( + ( + "https://archives.fedoraproject.org/pub/archive/fedora/linux/r= eleases" + "/31/Server/x86_64/os/images/pxeboot/initrd.img" + ), + "277cd6c7adf77c7e63d73bbb2cded8ef9e2d3a2f100000e92ff1f8396513cd8b", + ) + + ASSET_ALPINE_ISO =3D Asset( + ( + "https://dl-cdn.alpinelinux.org/" + "alpine/v3.22/releases/x86_64/alpine-standard-3.22.1-x86_64.is= o" + ), + "96d1b44ea1b8a5a884f193526d92edb4676054e9fa903ad2f016441a0fe13089", + ) + + def setUp(self): + super().setUp() + + init_tap() + + self.outer_ping_proc =3D None + + def tearDown(self): + try: + del_tap() + + if self.outer_ping_proc: + self.stop_outer_ping() + finally: + super().tearDown() + + def start_outer_ping(self) -> None: + assert self.outer_ping_proc is None + self.outer_ping_log =3D self.scratch_file("ping.log") + with open(self.outer_ping_log, "w") as f: + self.outer_ping_proc =3D subprocess.Popen( + ["ping", "-i", "0", "-O", "-D", GUEST_IP], + text=3DTrue, + stdout=3Df, + ) + + def stop_outer_ping(self) -> str: + assert self.outer_ping_proc + self.outer_ping_proc.send_signal(signal.SIGINT) + + self.outer_ping_proc.communicate(timeout=3D5) + self.outer_ping_proc =3D None + + with open(self.outer_ping_log) as f: + return f.read() + + def stop_ping_and_check(self, stop_time, resume_time): + ping_res =3D self.stop_outer_ping() + + discon, a, b =3D parse_ping_output(ping_res) + + if not discon: + text =3D f"STOP: {stop_time}, RESUME: {resume_time}," f"PING: = {a} - {b}" + if a > stop_time or b < resume_time: + self.fail(f"PING failed: {text}") + self.log.info(f"PING: no packets lost: {text}") + return + + text =3D ( + f"STOP: {stop_time}, RESUME: {resume_time}," f"PING: disconnec= t: {a} - {b}" + ) + self.log.info(text) + eps =3D 0.01 + if a < stop_time - eps or b > resume_time + eps: + self.fail(text) + + def one_ping_from_guest(self, vm) -> None: + exec_command_and_wait_for_pattern( + self, + f"ping -c 1 -W 1 {HOST_IP}", + "1 packets transmitted, 1 packets received", + "1 packets transmitted, 0 packets received", + vm=3Dvm, + ) + self.wait_for_console_pattern("# ", vm=3Dvm) + + def one_ping_from_host(self) -> None: + run(["ping", "-c", "1", "-W", "1", GUEST_IP]) + + def setup_shared_memory(self): + shm_path =3D f"/dev/shm/qemu_test_{os.getpid()}" + + try: + with open(shm_path, "wb") as f: + f.write(b"\0" * (1024 * 1024 * 1024)) # 1GB + except Exception as e: + self.fail(f"Failed to create shared memory file: {e}") + + return shm_path + + def prepare_and_launch_vm(self, shm_path, vhost, incoming=3DFalse, vm= =3DNone): + if not vm: + vm =3D self.vm + + vm.set_console() + vm.add_args("-accel", "kvm") + vm.add_args("-device", "pcie-pci-bridge,id=3Dpci.1,bus=3Dpcie.0") + vm.add_args("-m", "1G") + + vm.add_args( + "-object", + f"memory-backend-file,id=3Dram0,size=3D1G,mem-path=3D{shm_path= },share=3Don", + ) + vm.add_args("-machine", "memory-backend=3Dram0") + + vm.add_args( + "-drive", f"file=3D{self.ASSET_ALPINE_ISO.fetch()},media=3Dcdr= om,format=3Draw" + ) + + vm.add_args("-S") + + if incoming: + vm.add_args("-incoming", "defer") + + vm_s =3D "target" if incoming else "source" + self.log.info(f"Launching {vm_s} VM") + vm.launch() + + self.set_migration_capabilities(vm) + self.add_virtio_net(vm, vhost) + + def add_virtio_net(self, vm, vhost: bool): + netdev_params =3D { + "id": "netdev.1", + "vhost": vhost, + "type": "tap", + "ifname": "tap0", + "script": "no", + "downscript": "no", + "queues": 4, + "vnet_hdr": True, + } + + vm.cmd("netdev_add", netdev_params) + + vm.cmd( + "device_add", + driver=3D"virtio-net-pci", + romfile=3D"", + id=3D"vnet.1", + netdev=3D"netdev.1", + mq=3DTrue, + vectors=3D18, + bus=3D"pci.1", + mac=3DGUEST_MAC, + disable_legacy=3D"off", + ) + + def set_migration_capabilities(self, vm): + capabilities =3D [ + {"capability": "events", "state": True}, + {"capability": "x-ignore-shared", "state": True}, + ] + vm.cmd("migrate-set-capabilities", {"capabilities": capabilities}) + vm.cmd("migrate-set-parameters", {"fds": ["virtio-net"]}) + + def setup_guest_network(self) -> None: + exec_command_and_wait_for_pattern(self, "ip addr", "# ") + exec_command_and_wait_for_pattern( + self, + f"ip addr add {GUEST_IP_MASK} dev eth0 && ip link set eth0 up = && echo OK", + "OK", + ) + self.wait_for_console_pattern("# ") + + def do_test_tap_fd_migration(self, vhost): + self.require_accelerator("kvm") + self.set_machine("q35") + + socket_dir =3D self.socket_dir() + migration_socket =3D os.path.join(socket_dir.name, "migration.sock= ") + + shm_path =3D self.setup_shared_memory() + + self.prepare_and_launch_vm(shm_path, vhost) + self.vm.cmd("cont") + self.wait_for_console_pattern("login:") + exec_command_and_wait_for_pattern(self, "root", "# ") + + self.setup_guest_network() + + self.one_ping_from_guest(self.vm) + self.one_ping_from_host() + self.start_outer_ping() + + # Get some successful pings before migration + time.sleep(0.5) + + target_vm =3D self.get_vm(name=3D"target") + self.prepare_and_launch_vm(shm_path, vhost, incoming=3DTrue, vm=3D= target_vm) + + target_vm.cmd("migrate-incoming", {"uri": f"unix:{migration_socket= }"}) + + self.log.info("Starting migration") + freeze_start =3D time.time() + self.vm.cmd("migrate", {"uri": f"unix:{migration_socket}"}) + + self.log.info("Waiting for migration completion") + wait_migration_finish(self.vm, target_vm) + + target_vm.cmd("cont") + freeze_end =3D time.time() + + self.vm.shutdown() + + self.log.info("Verifying PING on target VM after migration") + self.one_ping_from_guest(target_vm) + self.one_ping_from_host() + + # And a bit more pings after source shutdown + time.sleep(0.3) + self.stop_ping_and_check(freeze_start, freeze_end) + + target_vm.shutdown() + + def test_tap_fd_migration(self): + self.do_test_tap_fd_migration(False) + + def test_tap_fd_migration_vhost(self): + self.do_test_tap_fd_migration(True) + + +if __name__ =3D=3D "__main__": + LinuxKernelTest.main() --=20 2.48.1