From patchwork Tue Aug 2 07:51:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Bin Meng X-Patchwork-Id: 12934420 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A3B14C00140 for ; Tue, 2 Aug 2022 09:17:31 +0000 (UTC) Received: from localhost ([::1]:55088 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oIo1q-00055b-K8 for qemu-devel@archiver.kernel.org; Tue, 02 Aug 2022 05:17:30 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58722) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oImhI-0006pb-62 for qemu-devel@nongnu.org; Tue, 02 Aug 2022 03:52:14 -0400 Received: from mail-pf1-x435.google.com ([2607:f8b0:4864:20::435]:43876) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oImhG-0007Zz-Md for qemu-devel@nongnu.org; Tue, 02 Aug 2022 03:52:11 -0400 Received: by mail-pf1-x435.google.com with SMTP id u133so6179641pfc.10 for ; Tue, 02 Aug 2022 00:52:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=CAT2FKyokp6jIbF5cQnfF4hEF5YeiWS/OD4dpe4OUP4=; b=IObT1ejy2FcCKX/O5nNt53uiNVeUa7Fp3hixbmvcn1l71anIH5nBje2YXmj/7nQKCv ZGcHgFnItQcQiwfS3kykEnoC3RqYDkyorondL6IPfxkjZVKjugz40wwUDqvMhBUitEOs aGML4JSZuzFzMOfE/di3W8bgoviv0FQKAEgvoHFSuR3W2MLoF3Pl+TqILTQlceRbRTCy FNTSd7+6skJWO6DU1Y1UqOvs9wlscKpKCFgoYRxU1CPEvKIIY2s1MsGT6VBAqcE34W/6 7GmMm4XPOFzNXGA1l9c9MQzyec+htf8r2TThlKgGTn4oiyw28wDEETB8citSsLwjg22Z OWyw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=CAT2FKyokp6jIbF5cQnfF4hEF5YeiWS/OD4dpe4OUP4=; b=NpHzxSUvr8J1viuLAbw6x5t2TTsDAYgq4O7HbtyOcXTfX5F5FAKKsh3jM92/tJyiZK yF/+S/7jwOXkkt9Y6RDiP7BNUbqz4fbfuSm6IrUJ8s5QAfnVlWUPDQym2KDlXPd1uPHB aL/wr+2ihPrzj1xXVafyV0j5fz2V9a29QQIhzMObG7wUmUx90zUJFgya1303IwNcl5rr GHXyASSu9qtNJHi8Y8+bt7S/LeksCFa68jx7F6u7GTD4a9DIkrC2VNWIggoFDhr3xMES eiKMApvhrMJXmF4+1NVuoohpTXKfAR+Ei1YVZtS/9Z6aJR8FZ6L3BpdSSsJ6XjprLFQ+ CKhA== X-Gm-Message-State: AJIora85qTfcm3cTDkcQAd/rARKecOlVAn+itzc3NvHRpmLSPlJCgaWv QnAX57aH0u5ncI/xTRpqm6KsbG0pOGA= X-Google-Smtp-Source: AGRyM1t/rWFoTCcgkXxEFWb/w6hx2rpRxjUIvPFOU7e0aMT2MtsKzisGFADoIFD+TyqgwjvoV4C/cw== X-Received: by 2002:a65:604f:0:b0:41a:77fe:2bbe with SMTP id a15-20020a65604f000000b0041a77fe2bbemr15658820pgp.242.1659426727715; Tue, 02 Aug 2022 00:52:07 -0700 (PDT) Received: from ubuntu.. (144.168.56.201.16clouds.com. [144.168.56.201]) by smtp.gmail.com with ESMTPSA id q19-20020aa79613000000b0052d92ccaad9sm3226098pfg.131.2022.08.02.00.52.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Aug 2022 00:52:07 -0700 (PDT) From: Bin Meng To: qemu-devel@nongnu.org Cc: Bin Meng , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= Subject: [PATCH v4 1/4] util/qemu-sockets: Replace the call to close a socket with closesocket() Date: Tue, 2 Aug 2022 15:51:57 +0800 Message-Id: <20220802075200.907360-2-bmeng.cn@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220802075200.907360-1-bmeng.cn@gmail.com> References: <20220802075200.907360-1-bmeng.cn@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::435; envelope-from=bmeng.cn@gmail.com; helo=mail-pf1-x435.google.com 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, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" From: Bin Meng close() is a *nix function. It works on any file descriptor, and sockets in *nix are an example of a file descriptor. closesocket() is a Windows-specific function, which works only specifically with sockets. Sockets on Windows do not use *nix-style file descriptors, and socket() returns a handle to a kernel object instead, so it must be closed with closesocket(). In QEMU there is already a logic to handle such platform difference in os-posix.h and os-win32.h, that: * closesocket maps to close on POSIX * closesocket maps to a wrapper that calls the real closesocket() on Windows Replace the call to close a socket with closesocket() instead. Signed-off-by: Bin Meng Reviewed-by: Marc-André Lureau --- (no changes since v1) util/qemu-sockets.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/util/qemu-sockets.c b/util/qemu-sockets.c index 13b5b197f9..0e2298278f 100644 --- a/util/qemu-sockets.c +++ b/util/qemu-sockets.c @@ -487,7 +487,7 @@ int inet_connect_saddr(InetSocketAddress *saddr, Error **errp) if (ret < 0) { error_setg_errno(errp, errno, "Unable to set KEEPALIVE"); - close(sock); + closesocket(sock); return -1; } } @@ -1050,7 +1050,7 @@ static int unix_connect_saddr(UnixSocketAddress *saddr, Error **errp) return sock; err: - close(sock); + closesocket(sock); return -1; } From patchwork Tue Aug 2 07:51:58 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Bin Meng X-Patchwork-Id: 12934398 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id F0169C19F2B for ; Tue, 2 Aug 2022 08:41:46 +0000 (UTC) Received: from localhost ([::1]:50240 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oInTG-0004Aa-1y for qemu-devel@archiver.kernel.org; Tue, 02 Aug 2022 04:41:46 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58768) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oImhS-0006zc-R3 for qemu-devel@nongnu.org; Tue, 02 Aug 2022 03:52:23 -0400 Received: from mail-pf1-x430.google.com ([2607:f8b0:4864:20::430]:46698) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oImhH-0007bC-QJ for qemu-devel@nongnu.org; Tue, 02 Aug 2022 03:52:20 -0400 Received: by mail-pf1-x430.google.com with SMTP id 130so5021042pfv.13 for ; Tue, 02 Aug 2022 00:52:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=HRVFtqjOEbn7bP+6aECBAKJ4Nuu9yVF32ANVebo29JQ=; b=Ej1MDnz1W4pF89gz5RRRZZnhGdyAfQanfCWPRa75ugs1669QPfMRPDb23lCuxXaKzD uRq8mzJ7TU3t8sOqGrtp3dGpcvQfAjWlvLGLynopQ8jFxtR779eRYiIpwjmL6VCQj5HJ V9ugRe05FIz3j8v6+iI1Rv2/1iTa29rvzAmlkb2g3FQTvY1Pvho8Ok3ivxIlqRPmSb7e QNgSeFBtwbn0jIZtfZptgzQWTev1jfMk0cG0HGzu8kTPm6cFpkE7VDKIk+g28bJbrFz5 2+IvGfZQb1cExhFJ3Nu0iE95LGiTkeXoGP1X4T311JC1sCrHEZElparViGL+7564Mto8 fgyw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=HRVFtqjOEbn7bP+6aECBAKJ4Nuu9yVF32ANVebo29JQ=; b=OD0WW8/11kkRRi3nTZIuTr5nacrYeIPsKhkQbl/cECT3s9VYiXodWegRJcecRwmngC C8HZmbcySGW/OOJfNp/RnJBcEvcU4ZbTZ4wKXIv1ZYVz1O2bm8SoxWvYHMnNKBHKIMOT MlGMNbNojelGL15NVEJS/HfcStE4UcQM85dfHdUxmDYfth89ZeqOtRJUTHn4LtyHHxhr MvvxxcVT/A2wjcIKfAKgRSUjBXU54ZUaf+YzSs0x9RCQ9kjSeEKtsSe263UBS4e6lAyz L+b4fVu2LRQZBjG3B32CtsKfVj6WIoXvRx19ugpKLTVjuwWUeJfY5kxbj3wSGALUJSoZ n5Sw== X-Gm-Message-State: ACgBeo3cwMJPNf/ym9xVoWiPRejW9bbqinYhMooMWHAyyv9Z/E5ApbH8 qGL6g1v5yvAyR2DEqqaH12Z6ylZQ2Dc= X-Google-Smtp-Source: AA6agR4JQD+SMQffUbWvntLMnN86eD93AQDFnnJa/kJbsOxYW+kRvKWwF1EWtdzsWx+hTwYydGgVgA== X-Received: by 2002:a63:8849:0:b0:41c:4216:d03c with SMTP id l70-20020a638849000000b0041c4216d03cmr4078591pgd.563.1659426730046; Tue, 02 Aug 2022 00:52:10 -0700 (PDT) Received: from ubuntu.. (144.168.56.201.16clouds.com. [144.168.56.201]) by smtp.gmail.com with ESMTPSA id q19-20020aa79613000000b0052d92ccaad9sm3226098pfg.131.2022.08.02.00.52.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Aug 2022 00:52:09 -0700 (PDT) From: Bin Meng To: qemu-devel@nongnu.org Cc: Bin Meng , Xuzhou Cheng , =?utf-8?q?Daniel_P=2E_Berrang?= =?utf-8?q?=C3=A9?= , Stefan Weil Subject: [PATCH v4 2/4] util/qemu-sockets: Enable unix socket support on Windows Date: Tue, 2 Aug 2022 15:51:58 +0800 Message-Id: <20220802075200.907360-3-bmeng.cn@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220802075200.907360-1-bmeng.cn@gmail.com> References: <20220802075200.907360-1-bmeng.cn@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::430; envelope-from=bmeng.cn@gmail.com; helo=mail-pf1-x430.google.com 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, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" From: Bin Meng Support for the unix socket has existed both in BSD and Linux for the longest time, but not on Windows. Since Windows 10 build 17063 [1], the native support for the unix socket has come to Windows. Starting this build, two Win32 processes can use the AF_UNIX address family over Winsock API to communicate with each other. [1] https://devblogs.microsoft.com/commandline/af_unix-comes-to-windows/ Signed-off-by: Xuzhou Cheng Signed-off-by: Bin Meng Reviewed-by: Marc-André Lureau --- Changes in v4: - instead of introducing CONFIG_AF_UNIX, add fallback afunix.h header in os-win32.h, and compile the AF_UNIX stuff for all Windows hosts Changes in v3: - drop the run-time check afunix_available() Changes in v2: - move #include to os-win32.h - define WIN_BUILD_AF_UNIX only when CONFIG_WIN32 meson.build | 3 +++ include/sysemu/os-win32.h | 17 +++++++++++++++++ util/qemu-sockets.c | 25 ------------------------- 3 files changed, 20 insertions(+), 25 deletions(-) diff --git a/meson.build b/meson.build index 294e9a8f32..6749223f1a 100644 --- a/meson.build +++ b/meson.build @@ -1890,6 +1890,9 @@ config_host_data.set('HAVE_PTY_H', cc.has_header('pty.h')) config_host_data.set('HAVE_SYS_DISK_H', cc.has_header('sys/disk.h')) config_host_data.set('HAVE_SYS_IOCCOM_H', cc.has_header('sys/ioccom.h')) config_host_data.set('HAVE_SYS_KCOV_H', cc.has_header('sys/kcov.h')) +if targetos == 'windows' + config_host_data.set('HAVE_AFUNIX_H', cc.has_header('afunix.h')) +endif # has_function config_host_data.set('CONFIG_ACCEPT4', cc.has_function('accept4')) diff --git a/include/sysemu/os-win32.h b/include/sysemu/os-win32.h index edc3b38a57..5b38c7bd04 100644 --- a/include/sysemu/os-win32.h +++ b/include/sysemu/os-win32.h @@ -30,6 +30,23 @@ #include #include +#ifdef HAVE_AFUNIX_H +#include +#else +/* + * Fallback definitions of things we need in afunix.h, if not available from + * the used Windows SDK or MinGW headers. + */ +#define UNIX_PATH_MAX 108 + +typedef struct sockaddr_un { + ADDRESS_FAMILY sun_family; + char sun_path[UNIX_PATH_MAX]; +} SOCKADDR_UN, *PSOCKADDR_UN; + +#define SIO_AF_UNIX_GETPEERPID _WSAIOR(IOC_VENDOR, 256) +#endif + #ifdef __cplusplus extern "C" { #endif diff --git a/util/qemu-sockets.c b/util/qemu-sockets.c index 0e2298278f..83f4bd6fd2 100644 --- a/util/qemu-sockets.c +++ b/util/qemu-sockets.c @@ -880,8 +880,6 @@ static int vsock_parse(VsockSocketAddress *addr, const char *str, } #endif /* CONFIG_AF_VSOCK */ -#ifndef _WIN32 - static bool saddr_is_abstract(UnixSocketAddress *saddr) { #ifdef CONFIG_LINUX @@ -1054,25 +1052,6 @@ static int unix_connect_saddr(UnixSocketAddress *saddr, Error **errp) return -1; } -#else - -static int unix_listen_saddr(UnixSocketAddress *saddr, - int num, - Error **errp) -{ - error_setg(errp, "unix sockets are not available on windows"); - errno = ENOTSUP; - return -1; -} - -static int unix_connect_saddr(UnixSocketAddress *saddr, Error **errp) -{ - error_setg(errp, "unix sockets are not available on windows"); - errno = ENOTSUP; - return -1; -} -#endif - /* compatibility wrapper */ int unix_listen(const char *str, Error **errp) { @@ -1335,7 +1314,6 @@ socket_sockaddr_to_address_inet(struct sockaddr_storage *sa, } -#ifndef WIN32 static SocketAddress * socket_sockaddr_to_address_unix(struct sockaddr_storage *sa, socklen_t salen, @@ -1362,7 +1340,6 @@ socket_sockaddr_to_address_unix(struct sockaddr_storage *sa, addr->u.q_unix.path = g_strndup(su->sun_path, salen); return addr; } -#endif /* WIN32 */ #ifdef CONFIG_AF_VSOCK static SocketAddress * @@ -1394,10 +1371,8 @@ socket_sockaddr_to_address(struct sockaddr_storage *sa, case AF_INET6: return socket_sockaddr_to_address_inet(sa, salen, errp); -#ifndef WIN32 case AF_UNIX: return socket_sockaddr_to_address_unix(sa, salen, errp); -#endif /* WIN32 */ #ifdef CONFIG_AF_VSOCK case AF_VSOCK: From patchwork Tue Aug 2 07:51:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Bin Meng X-Patchwork-Id: 12934409 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 5D0AFC00140 for ; Tue, 2 Aug 2022 08:58:59 +0000 (UTC) Received: from localhost ([::1]:52290 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oInju-0000MN-Gc for qemu-devel@archiver.kernel.org; Tue, 02 Aug 2022 04:58:58 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58750) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oImhL-0006qU-5u for qemu-devel@nongnu.org; Tue, 02 Aug 2022 03:52:15 -0400 Received: from mail-pf1-x430.google.com ([2607:f8b0:4864:20::430]:33308) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oImhJ-0007bb-Gs for qemu-devel@nongnu.org; Tue, 02 Aug 2022 03:52:14 -0400 Received: by mail-pf1-x430.google.com with SMTP id 17so12891379pfy.0 for ; Tue, 02 Aug 2022 00:52:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=UtUDFSo6V4EIqtNs5iElBXcUU9TWQlg0ugZhT/l98K4=; b=o5BTO4smTeeXBp+iR/TZZBMjKvZuIjSUzhIg/QISmrBBr3H+1RSZF7cpN7M9/vrK+K FtnNsntTISs7x9URuFJDNUS3AwdmavA6U3z1fKwJzz0rNDIv1S0eDmszCeMYbFOd/SwL LSYwbknKE+0w/DdxSyWo1kvNFVXFOu4ZYcfyVW1c4lQxm4lkdqz/TFKLXx1Q06GKcxaC 7QjegC3s8QbWccrLLK3YGUnTPC4b6TKBXpq0FkpOqt8gFQbjSYwi3tHhjIBA7Cfywwl5 vzqi06UiSj+S5mu3x9ZmBTEuXTWe9VGk4dxgh18xsaFvQXquMUOgBP+34Nb+a8J/lruo bdyA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=UtUDFSo6V4EIqtNs5iElBXcUU9TWQlg0ugZhT/l98K4=; b=cEZS5SyxTuOw8qn3DNwADOKzn17H47FnJvJFfz7y3LnCYo7G4bFqJTWgWB3eGY+b23 yPzLBDZtpsMezQE57Pj/MFCMmr+SjC6am2QMt6oBrU86eAvvDrOohbYLCXQ6j0TR9RSC popxq6b/0Xnf2WtJ9lyTa1Ghyt5oT/hvUSbicdAbtsuwsKYLu2wsMyzO46Z1Ro3Uh73D vb7HCQYpzDVJoP2ToZlhrNAae1goQ2wSyLUmrk5LcsGcDFzB+9s8jEFXsX2Zev+YE77b oGX7C7RkgvBWbCcx3JD37GH08sBiYd4wAnbGUQVEp5w+pkK0wNdLil6pWeN8ALJs3S0C kxgA== X-Gm-Message-State: AJIora/xcj4vlN8OREzAOQ038peAA06ZkWIGOwgm1dMFOpa8LGeC0VER 1RnQ1o3OGyDKRCySt4GfOFquWHLndTU= X-Google-Smtp-Source: AGRyM1vkoDpK83LXTIj5nnoUkqKUr8hWq7l2PHfh/oqTxtLlPGnae8t5hIhYGT8nfg6kB3UmdnH9cw== X-Received: by 2002:a63:2a0e:0:b0:41a:f82d:72f6 with SMTP id q14-20020a632a0e000000b0041af82d72f6mr16099301pgq.42.1659426732091; Tue, 02 Aug 2022 00:52:12 -0700 (PDT) Received: from ubuntu.. (144.168.56.201.16clouds.com. [144.168.56.201]) by smtp.gmail.com with ESMTPSA id q19-20020aa79613000000b0052d92ccaad9sm3226098pfg.131.2022.08.02.00.52.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Aug 2022 00:52:11 -0700 (PDT) From: Bin Meng To: qemu-devel@nongnu.org Cc: Bin Meng , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , Paolo Bonzini Subject: [PATCH v4 3/4] chardev/char-socket: Update AF_UNIX for Windows Date: Tue, 2 Aug 2022 15:51:59 +0800 Message-Id: <20220802075200.907360-4-bmeng.cn@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220802075200.907360-1-bmeng.cn@gmail.com> References: <20220802075200.907360-1-bmeng.cn@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::430; envelope-from=bmeng.cn@gmail.com; helo=mail-pf1-x430.google.com 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, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" From: Bin Meng Now that AF_UNIX has come to Windows, update the existing logic in qemu_chr_compute_filename() and qmp_chardev_open_socket() for Windows. Signed-off-by: Bin Meng Reviewed-by: Marc-André Lureau --- Changes in v4: - drop CONFIG_AF_UNIX Changes in v2: - drop #include as it is now already included in osdep.h chardev/char-socket.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/chardev/char-socket.c b/chardev/char-socket.c index dc4e218eeb..879564aa8a 100644 --- a/chardev/char-socket.c +++ b/chardev/char-socket.c @@ -557,12 +557,10 @@ static char *qemu_chr_compute_filename(SocketChardev *s) const char *left = "", *right = ""; switch (ss->ss_family) { -#ifndef _WIN32 case AF_UNIX: return g_strdup_printf("unix:%s%s", ((struct sockaddr_un *)(ss))->sun_path, s->is_listen ? ",server=on" : ""); -#endif case AF_INET6: left = "["; right = "]"; @@ -1372,10 +1370,12 @@ static void qmp_chardev_open_socket(Chardev *chr, } qemu_chr_set_feature(chr, QEMU_CHAR_FEATURE_RECONNECTABLE); +#ifndef _WIN32 /* TODO SOCKET_ADDRESS_FD where fd has AF_UNIX */ if (addr->type == SOCKET_ADDRESS_TYPE_UNIX) { qemu_chr_set_feature(chr, QEMU_CHAR_FEATURE_FD_PASS); } +#endif /* * In the chardev-change special-case, we shouldn't register a new yank From patchwork Tue Aug 2 07:52:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Bin Meng X-Patchwork-Id: 12934421 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id AB577C00140 for ; Tue, 2 Aug 2022 09:22:37 +0000 (UTC) Received: from localhost ([::1]:59926 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oIo6m-0000IB-Ki for qemu-devel@archiver.kernel.org; Tue, 02 Aug 2022 05:22:36 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58764) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oImhN-0006uA-Bj for qemu-devel@nongnu.org; Tue, 02 Aug 2022 03:52:17 -0400 Received: from mail-pj1-x102c.google.com ([2607:f8b0:4864:20::102c]:56033) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oImhL-0007bm-Ja for qemu-devel@nongnu.org; Tue, 02 Aug 2022 03:52:17 -0400 Received: by mail-pj1-x102c.google.com with SMTP id b10so12932806pjq.5 for ; Tue, 02 Aug 2022 00:52:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Z4zTRtehf6XdB5qciZM/5V8Sk8TNAjRjyBN00vz6ZKY=; b=Zw3+APO75m/ccau/2LlKwwJytmiwNSoA+5FnJgD6WQGzBZTS8+DmbD7nsLi1ALpO7D hek14y4fNdeWate917a/Wi02nYpwO7uDdB3GbgxkMWi9odrx/CkWQqpe7P2fKRmFLN69 fnVMNxW5zO3sUCDMOr+utM/YL4WsidD4sIBMBZyiC6SDi80g3mjv7ZSd9zjC5a2vrpB5 O9q/TVcCg+luIsrwj3umKG/ioBmNYe2KVIfZfsgQP4kI2CJpvEoE+BIBNn9dW9VVoYq8 T/EM8u7VS7W3BGLSGwvxHDD8Dov+af6Wiwpv72Lyy1rWpQvh4jmyvFS7VS57yxCW/F2m 4iKw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Z4zTRtehf6XdB5qciZM/5V8Sk8TNAjRjyBN00vz6ZKY=; b=vD6Rhr/ukLkEbD89nQU+Q4bWQ/JctvgNf6olE8p7VK+i3DqiTFwCCAbyx4JyQeuhAM QYe0wj4QkMx3CDPFGQ/FMIq+l+DxNcb83qrirTnV/GuhJBqNlDIS30oIJtcEzKEzTwgE +5AqnJ78p4eiVfv2gwFunl8I5Laqvz/304Ttt63J9/djjMq3cI9wwsfgoJ5h5vzSmeWN WFUiHC8ZgxQmfgX/c3K4cAuzVM0lBmln1BLbNZ3r/HVn5nDKznq4yz3QWA+XNU+SSknR zB3y4R418Ndrw9GgfKoNjQO0UyIaNUqUp5yCbqtn9/hHlV+vWykW5y9spnZ0Z1zrvF9A 7yPw== X-Gm-Message-State: ACgBeo26J8k8R0LoM0ZNDu/rZyRjzTLmP/dJ5k0rkthMcVYFFa5k8nRp HXWOuKZZT4Dj4RFZPzK6fBOuY6jHALU= X-Google-Smtp-Source: AA6agR43n4AgSRkLXeSQ04wAFxENFQB8tNUH75zCtrRxoS0Ybz4xzu3n3jX5SV4jYdUHIBD+el4p+A== X-Received: by 2002:a17:90a:4501:b0:1f4:d8b8:3552 with SMTP id u1-20020a17090a450100b001f4d8b83552mr16254608pjg.149.1659426733915; Tue, 02 Aug 2022 00:52:13 -0700 (PDT) Received: from ubuntu.. (144.168.56.201.16clouds.com. [144.168.56.201]) by smtp.gmail.com with ESMTPSA id q19-20020aa79613000000b0052d92ccaad9sm3226098pfg.131.2022.08.02.00.52.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Aug 2022 00:52:13 -0700 (PDT) From: Bin Meng To: qemu-devel@nongnu.org Cc: Bin Meng , =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= Subject: [PATCH v4 4/4] tests/unit: Update test-io-channel-socket.c for Windows Date: Tue, 2 Aug 2022 15:52:00 +0800 Message-Id: <20220802075200.907360-5-bmeng.cn@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220802075200.907360-1-bmeng.cn@gmail.com> References: <20220802075200.907360-1-bmeng.cn@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::102c; envelope-from=bmeng.cn@gmail.com; helo=mail-pj1-x102c.google.com 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, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" From: Bin Meng Change to dynamically include the test cases by checking AF_UNIX availability using a new helper socket_check_afunix_support(). With such changes testing on a Windows host can be covered as well. Signed-off-by: Bin Meng Reviewed-by: Marc-André Lureau --- Changes in v4: - introduce a new helper socket_check_afunix_support() to runtime-check the availability of AF_UNIX socket, and skip those appropriately Changes in v2: - new patch: tests/unit: Update test-io-channel-socket.c for Windows tests/unit/socket-helpers.h | 9 +++++++ tests/unit/socket-helpers.c | 16 +++++++++++++ tests/unit/test-io-channel-socket.c | 37 ++++++++++++++++++----------- 3 files changed, 48 insertions(+), 14 deletions(-) diff --git a/tests/unit/socket-helpers.h b/tests/unit/socket-helpers.h index 512a004811..ed8477ceb3 100644 --- a/tests/unit/socket-helpers.h +++ b/tests/unit/socket-helpers.h @@ -32,4 +32,13 @@ */ int socket_check_protocol_support(bool *has_ipv4, bool *has_ipv6); +/* + * @has_afunix: set to true on return if unix socket support is available + * + * Check whether unix domain socket support is available for use. + * On success, @has_afunix will be set to indicate whether AF_UNIX protocol + * is available. + */ +void socket_check_afunix_support(bool *has_afunix); + #endif diff --git a/tests/unit/socket-helpers.c b/tests/unit/socket-helpers.c index 5af4de513b..eecadf3a3c 100644 --- a/tests/unit/socket-helpers.c +++ b/tests/unit/socket-helpers.c @@ -154,3 +154,19 @@ int socket_check_protocol_support(bool *has_ipv4, bool *has_ipv6) return 0; } + +void socket_check_afunix_support(bool *has_afunix) +{ + int fd; + + fd = socket(PF_UNIX, SOCK_STREAM, 0); + closesocket(fd); + +#ifdef _WIN32 + *has_afunix = (fd != (int)INVALID_SOCKET); +#else + *has_afunix = (fd >= 0); +#endif + + return; +} diff --git a/tests/unit/test-io-channel-socket.c b/tests/unit/test-io-channel-socket.c index 6713886d02..b36a5d972a 100644 --- a/tests/unit/test-io-channel-socket.c +++ b/tests/unit/test-io-channel-socket.c @@ -179,10 +179,12 @@ static void test_io_channel(bool async, test_io_channel_setup_async(listen_addr, connect_addr, &srv, &src, &dst); +#ifndef _WIN32 g_assert(!passFD || qio_channel_has_feature(src, QIO_CHANNEL_FEATURE_FD_PASS)); g_assert(!passFD || qio_channel_has_feature(dst, QIO_CHANNEL_FEATURE_FD_PASS)); +#endif g_assert(qio_channel_has_feature(src, QIO_CHANNEL_FEATURE_SHUTDOWN)); g_assert(qio_channel_has_feature(dst, QIO_CHANNEL_FEATURE_SHUTDOWN)); @@ -206,10 +208,12 @@ static void test_io_channel(bool async, test_io_channel_setup_async(listen_addr, connect_addr, &srv, &src, &dst); +#ifndef _WIN32 g_assert(!passFD || qio_channel_has_feature(src, QIO_CHANNEL_FEATURE_FD_PASS)); g_assert(!passFD || qio_channel_has_feature(dst, QIO_CHANNEL_FEATURE_FD_PASS)); +#endif g_assert(qio_channel_has_feature(src, QIO_CHANNEL_FEATURE_SHUTDOWN)); g_assert(qio_channel_has_feature(dst, QIO_CHANNEL_FEATURE_SHUTDOWN)); @@ -236,10 +240,12 @@ static void test_io_channel(bool async, test_io_channel_setup_sync(listen_addr, connect_addr, &srv, &src, &dst); +#ifndef _WIN32 g_assert(!passFD || qio_channel_has_feature(src, QIO_CHANNEL_FEATURE_FD_PASS)); g_assert(!passFD || qio_channel_has_feature(dst, QIO_CHANNEL_FEATURE_FD_PASS)); +#endif g_assert(qio_channel_has_feature(src, QIO_CHANNEL_FEATURE_SHUTDOWN)); g_assert(qio_channel_has_feature(dst, QIO_CHANNEL_FEATURE_SHUTDOWN)); @@ -263,10 +269,12 @@ static void test_io_channel(bool async, test_io_channel_setup_sync(listen_addr, connect_addr, &srv, &src, &dst); +#ifndef _WIN32 g_assert(!passFD || qio_channel_has_feature(src, QIO_CHANNEL_FEATURE_FD_PASS)); g_assert(!passFD || qio_channel_has_feature(dst, QIO_CHANNEL_FEATURE_FD_PASS)); +#endif g_assert(qio_channel_has_feature(src, QIO_CHANNEL_FEATURE_SHUTDOWN)); g_assert(qio_channel_has_feature(dst, QIO_CHANNEL_FEATURE_SHUTDOWN)); @@ -367,7 +375,6 @@ static void test_io_channel_ipv6_async(void) } -#ifndef _WIN32 static void test_io_channel_unix(bool async) { SocketAddress *listen_addr = g_new0(SocketAddress, 1); @@ -398,6 +405,7 @@ static void test_io_channel_unix_async(void) return test_io_channel_unix(true); } +#ifndef _WIN32 static void test_io_channel_unix_fd_pass(void) { SocketAddress *listen_addr = g_new0(SocketAddress, 1); @@ -491,6 +499,7 @@ static void test_io_channel_unix_fd_pass(void) } g_free(fdrecv); } +#endif /* _WIN32 */ static void test_io_channel_unix_listen_cleanup(void) { @@ -522,9 +531,6 @@ static void test_io_channel_unix_listen_cleanup(void) unlink(TEST_SOCKET); } -#endif /* _WIN32 */ - - static void test_io_channel_ipv4_fd(void) { QIOChannel *ioc; @@ -555,7 +561,7 @@ static void test_io_channel_ipv4_fd(void) int main(int argc, char **argv) { - bool has_ipv4, has_ipv6; + bool has_ipv4, has_ipv6, has_afunix; module_call_init(MODULE_INIT_QOM); qemu_init_main_loop(&error_abort); @@ -588,16 +594,19 @@ int main(int argc, char **argv) test_io_channel_ipv6_async); } + socket_check_afunix_support(&has_afunix); + if (has_afunix) { + g_test_add_func("/io/channel/socket/unix-sync", + test_io_channel_unix_sync); + g_test_add_func("/io/channel/socket/unix-async", + test_io_channel_unix_async); #ifndef _WIN32 - g_test_add_func("/io/channel/socket/unix-sync", - test_io_channel_unix_sync); - g_test_add_func("/io/channel/socket/unix-async", - test_io_channel_unix_async); - g_test_add_func("/io/channel/socket/unix-fd-pass", - test_io_channel_unix_fd_pass); - g_test_add_func("/io/channel/socket/unix-listen-cleanup", - test_io_channel_unix_listen_cleanup); -#endif /* _WIN32 */ + g_test_add_func("/io/channel/socket/unix-fd-pass", + test_io_channel_unix_fd_pass); +#endif + g_test_add_func("/io/channel/socket/unix-listen-cleanup", + test_io_channel_unix_listen_cleanup); + } end: return g_test_run();