From patchwork Tue Sep 28 13:53:06 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 12522879 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C8C78C433EF for ; Tue, 28 Sep 2021 14:01:46 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 284F461058 for ; Tue, 28 Sep 2021 14:01:46 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 284F461058 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=nongnu.org Received: from localhost ([::1]:35928 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mVDg1-0004Nb-82 for qemu-devel@archiver.kernel.org; Tue, 28 Sep 2021 10:01:45 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:52620) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mVDYJ-0003NW-JZ for qemu-devel@nongnu.org; Tue, 28 Sep 2021 09:53:47 -0400 Received: from mail-ed1-x535.google.com ([2a00:1450:4864:20::535]:39934) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mVDYH-0004lg-VV for qemu-devel@nongnu.org; Tue, 28 Sep 2021 09:53:47 -0400 Received: by mail-ed1-x535.google.com with SMTP id x7so68925286edd.6 for ; Tue, 28 Sep 2021 06:53:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=YUuWRaYOqtXVrbNdK1ZefmQ6EAecdKXF8ILSBKR+oFE=; b=idTPRsNaZ7zosTWLBFEK582nJkC8zkL39evSuVEZ+BaOHiLeHeY3EapKsQNaKplPR0 HvrZuJsKYWU5R3BL+5dXVi+DZqFCegT6+nMbf7/Zb1vny86I64D51/GsIZOBfk5OW6du y4yB1awQiFvch5HTzeKMDf4zAMiyZIi8p4MGmVt9CVVtXsCBQskW+h5EGpo07ikrc0au LuATj4EQHq+lqttHgp46lFBBNTWTXncsPAQ1T/PzQoDZE5tzvI8M7paRpYGlfBY7qAzM hhtG7f8UM1uQMs7ew6i77c58TSxBTO8W7WZdXw4NplJ22nFVzsF9jlKsZF5HtxXFvJxS P6XQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=YUuWRaYOqtXVrbNdK1ZefmQ6EAecdKXF8ILSBKR+oFE=; b=KaMJ6qYhEOv56em0RE/qDTwDozI2jTWy/8p0Z/u0agpnnh+xXppUpZOGT6XisjgoeP 7wmk8Pdce6h1uLgeXnWTle3k1Uu5Pl752Dqkxlp4xcgc5pXX1/SAafhGNlFJkEiUUgae eqT/MgRCvUUpdSzkrFlQJohF/48epyVH7DQQJpj0kafgpq6L+dutHwNV7zoU/zTZWGsG CilABk1O6twFnx2CV/+SJEzwidE/aJpfOvpvoUdDhNGckRdiZFO7X2Ke5qANv3zpii5N fBuSz+4gI8kR6mjXbV4mUymCPqpqKd6OCl0Ej8gu/ihFn/RM314ndkNaH8aY6Ph0c6a7 aSGw== X-Gm-Message-State: AOAM531nd0oQwWHPRyciw9Z07bsBaUqPDO08Zpr8UQhncrbUx+0xsaZw 5CNXboLPit/T+rwvYiMeVCZttkVDg6k= X-Google-Smtp-Source: ABdhPJzuaayZpOLp84pDvpk3mPa2XsmQh/5xNHlYUAYAv55ylCn4Uf/w+Fbeg2pfxwLoMZmy7oOMCQ== X-Received: by 2002:a17:906:1109:: with SMTP id h9mr6900974eja.296.1632837191588; Tue, 28 Sep 2021 06:53:11 -0700 (PDT) Received: from avogadro.lan ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id v13sm10373247ejh.62.2021.09.28.06.53.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Sep 2021 06:53:11 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PATCH 1/4] python: stop using socket_scm_helper Date: Tue, 28 Sep 2021 15:53:06 +0200 Message-Id: <20210928135309.199796-2-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210928135309.199796-1-pbonzini@redhat.com> References: <20210928135309.199796-1-pbonzini@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::535; envelope-from=paolo.bonzini@gmail.com; helo=mail-ed1-x535.google.com X-Spam_score_int: -14 X-Spam_score: -1.5 X-Spam_bar: - X-Spam_report: (-1.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.249, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: jsnow@redhat.com Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Python is able to call sendmsg, it does not need a helper. Write the code directly; for now, keep the weird calling convention. Signed-off-by: Paolo Bonzini --- python/qemu/machine/machine.py | 48 ++++++++++++---------------------- python/qemu/qmp/__init__.py | 15 +++++++++++ 2 files changed, 32 insertions(+), 31 deletions(-) diff --git a/python/qemu/machine/machine.py b/python/qemu/machine/machine.py index 34131884a5..e4356ea99e 100644 --- a/python/qemu/machine/machine.py +++ b/python/qemu/machine/machine.py @@ -213,48 +213,34 @@ def add_fd(self: _T, fd: int, fdset: int, def send_fd_scm(self, fd: Optional[int] = None, file_path: Optional[str] = None) -> int: """ - Send an fd or file_path to socket_scm_helper. + Send an fd or file_path via QMP. Exactly one of fd and file_path must be given. - If it is file_path, the helper will open that file and pass its own fd. + If it is file_path, the function will open that file and pass + its own fd. """ # In iotest.py, the qmp should always use unix socket. assert self._qmp.is_scm_available() - if self._socket_scm_helper is None: - raise QEMUMachineError("No path to socket_scm_helper set") - if not os.path.exists(self._socket_scm_helper): - raise QEMUMachineError("%s does not exist" % - self._socket_scm_helper) - - # This did not exist before 3.4, but since then it is - # mandatory for our purpose - if hasattr(os, 'set_inheritable'): - os.set_inheritable(self._qmp.get_sock_fd(), True) - if fd is not None: - os.set_inheritable(fd, True) - - fd_param = ["%s" % self._socket_scm_helper, - "%d" % self._qmp.get_sock_fd()] if file_path is not None: assert fd is None - fd_param.append(file_path) + fd = -1 + try: + fd = os.open(file_path, os.O_RDONLY) + self._qmp.send_fd(fd) + except OSError: + return 1 + finally: + if fd != -1: + os.close(fd) else: assert fd is not None - fd_param.append(str(fd)) + try: + self._qmp.send_fd(fd) + except OSError: + return 1 - proc = subprocess.run( - fd_param, - stdin=subprocess.DEVNULL, - stdout=subprocess.PIPE, - stderr=subprocess.STDOUT, - check=False, - close_fds=False, - ) - if proc.stdout: - LOG.debug(proc.stdout) - - return proc.returncode + return 0 @staticmethod def _remove_if_exists(path: str) -> None: diff --git a/python/qemu/qmp/__init__.py b/python/qemu/qmp/__init__.py index 269516a79b..27a3e8f7af 100644 --- a/python/qemu/qmp/__init__.py +++ b/python/qemu/qmp/__init__.py @@ -17,6 +17,7 @@ # This work is licensed under the terms of the GNU GPL, version 2. See # the COPYING file in the top-level directory. +import array import errno import json import logging @@ -421,3 +422,17 @@ def is_scm_available(self) -> bool: @return True if SCM_RIGHTS is available, otherwise False. """ return self.__sock.family == socket.AF_UNIX + + def send_fd(self, fd: int) -> None: + """ + Send a file descriptor to QEMU via SCM_RIGHTS. + + @param fd (int): file descriptor do be sent + + @raise OSError: if the sendmsg system call fails. + """ + # Send a single space so that QEMU looks at the ancillary data + self.__sock.sendmsg((b" ", ), + [(socket.SOL_SOCKET, + socket.SCM_RIGHTS, + array.array("i", [fd]).tobytes())]) From patchwork Tue Sep 28 13:53:07 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 12522851 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 21581C433EF for ; Tue, 28 Sep 2021 13:56:21 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 88810611BD for ; Tue, 28 Sep 2021 13:56:20 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 88810611BD Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=nongnu.org Received: from localhost ([::1]:53222 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mVDal-0005Ht-KP for qemu-devel@archiver.kernel.org; Tue, 28 Sep 2021 09:56:19 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:52546) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mVDY7-0003D6-BA for qemu-devel@nongnu.org; Tue, 28 Sep 2021 09:53:35 -0400 Received: from mail-ed1-x529.google.com ([2a00:1450:4864:20::529]:38858) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mVDY5-0004b3-BV for qemu-devel@nongnu.org; Tue, 28 Sep 2021 09:53:35 -0400 Received: by mail-ed1-x529.google.com with SMTP id dj4so83949116edb.5 for ; Tue, 28 Sep 2021 06:53:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=P3G2rOFbzL2AJNth2e4x1d5wKOFB9Eezzp7M6JLqg3c=; b=mlb+KwuMzOZj/Cy9KqyZ2NI9MSDH68FXQm3CycHWppnB2u3zUMWnJshW7X8dpkP7hI E/ZMBFVtmAf1ajROCWjpJZ1ZQxV0Fgub27p2UivGsX6WyI4KPwAIP+bKL2W5caDuT379 etgrCUSSHBktOUUbT2icNLwCQg25ZnyJ54JEsNt45E61Fk9pyf/n/ZeSxJ8Zy0ZmrIxm GC68MTTp1bWna60n+Bi6jYjZ+D0/fkm1XlPG25Vx3NGesktm1C0sKBCT172kROoIP10f pTKvneNV75wgos5c6aTCKFPhi9sByPB9sr87xBeA9CHMtAX5mNm1112ajSzJyl0AdIFX d2tQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=P3G2rOFbzL2AJNth2e4x1d5wKOFB9Eezzp7M6JLqg3c=; b=FrRGymb5lJGgoFZm1HD1GIHQNp+Nxb8KgfhbOyPxK2JdtA12L/xqBP27XyZcIQNJLs BuBq33TbTdfi7hkcUNELndKO5WbKVIkAVisPvzfYrrqiDiGTfGBewa1LQUOzdK+1dzu1 wyh6t3Dcg8DcnEj7CEe0HqUlgT+5YrZAhBmSzl8huxHbyliq0J/VrEo+kBcfs4ltPHQj Y2/Tkbxu39iYYfrz2dklcyTfKBS6VeXPsbP2rBJkJpPipTcC/UWa4k65rkNqpU0tNqRy YCsO/EKH8QO63hTB6chBgUPdcCvZe+5Q994c18xh+lkB3CnIMCYoHH07h3JRR+IpILYc Zlsg== X-Gm-Message-State: AOAM532HXRzLw/lBsNDhLvVi8NA3fNJsiLEHpmZNI8d9gLVavtbtr1pW 5f0oC7XUeXe9+B6OoRHBszkZ1Rud4Yo= X-Google-Smtp-Source: ABdhPJz0hlkSXhP1K0AHcKDjOat0Dl8L+VC+C40fB1+g9Zd3P84J0lBne3gK8AYffSwH/+FU5MPSGQ== X-Received: by 2002:a17:906:fc0b:: with SMTP id ov11mr6934640ejb.22.1632837192403; Tue, 28 Sep 2021 06:53:12 -0700 (PDT) Received: from avogadro.lan ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id v13sm10373247ejh.62.2021.09.28.06.53.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Sep 2021 06:53:12 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PATCH 2/4] socket_scm_helper: remove Date: Tue, 28 Sep 2021 15:53:07 +0200 Message-Id: <20210928135309.199796-3-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210928135309.199796-1-pbonzini@redhat.com> References: <20210928135309.199796-1-pbonzini@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::529; envelope-from=paolo.bonzini@gmail.com; helo=mail-ed1-x529.google.com X-Spam_score_int: -14 X-Spam_score: -1.5 X-Spam_bar: - X-Spam_report: (-1.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.249, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: jsnow@redhat.com Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" It is not used anymore, remove the source and all remaning traces of it. Signed-off-by: Paolo Bonzini --- python/qemu/machine/machine.py | 3 - python/qemu/machine/qtest.py | 2 - tests/Makefile.include | 5 +- tests/meson.build | 4 - tests/qemu-iotests/iotests.py | 3 - tests/qemu-iotests/meson.build | 5 - tests/qemu-iotests/socket_scm_helper.c | 136 ------------------------- tests/qemu-iotests/testenv.py | 8 +- 8 files changed, 2 insertions(+), 164 deletions(-) delete mode 100644 tests/qemu-iotests/meson.build delete mode 100644 tests/qemu-iotests/socket_scm_helper.c diff --git a/python/qemu/machine/machine.py b/python/qemu/machine/machine.py index e4356ea99e..d230915fbf 100644 --- a/python/qemu/machine/machine.py +++ b/python/qemu/machine/machine.py @@ -98,7 +98,6 @@ def __init__(self, name: Optional[str] = None, base_temp_dir: str = "/var/tmp", monitor_address: Optional[SocketAddrT] = None, - socket_scm_helper: Optional[str] = None, sock_dir: Optional[str] = None, drain_console: bool = False, console_log: Optional[str] = None, @@ -113,7 +112,6 @@ def __init__(self, @param name: prefix for socket and log file names (default: qemu-PID) @param base_temp_dir: default location where temp files are created @param monitor_address: address for QMP monitor - @param socket_scm_helper: helper program, required for send_fd_scm() @param sock_dir: where to create socket (defaults to base_temp_dir) @param drain_console: (optional) True to drain console socket to buffer @param console_log: (optional) path to console log file @@ -134,7 +132,6 @@ def __init__(self, self._base_temp_dir = base_temp_dir self._sock_dir = sock_dir or self._base_temp_dir self._log_dir = log_dir - self._socket_scm_helper = socket_scm_helper if monitor_address is not None: self._monitor_address = monitor_address diff --git a/python/qemu/machine/qtest.py b/python/qemu/machine/qtest.py index 395cc8fbfe..f2f9aaa5e5 100644 --- a/python/qemu/machine/qtest.py +++ b/python/qemu/machine/qtest.py @@ -115,7 +115,6 @@ def __init__(self, wrapper: Sequence[str] = (), name: Optional[str] = None, base_temp_dir: str = "/var/tmp", - socket_scm_helper: Optional[str] = None, sock_dir: Optional[str] = None, qmp_timer: Optional[float] = None): # pylint: disable=too-many-arguments @@ -126,7 +125,6 @@ def __init__(self, sock_dir = base_temp_dir super().__init__(binary, args, wrapper=wrapper, name=name, base_temp_dir=base_temp_dir, - socket_scm_helper=socket_scm_helper, sock_dir=sock_dir, qmp_timer=qmp_timer) self._qtest: Optional[QEMUQtestProtocol] = None self._qtest_path = os.path.join(sock_dir, name + "-qtest.sock") diff --git a/tests/Makefile.include b/tests/Makefile.include index 7426522bbe..86dc8286b4 100644 --- a/tests/Makefile.include +++ b/tests/Makefile.include @@ -148,17 +148,14 @@ check-acceptance: check-venv $(TESTS_RESULTS_DIR) get-vm-images check: ifeq ($(CONFIG_TOOLS)$(CONFIG_POSIX),yy) -QEMU_IOTESTS_HELPERS-$(CONFIG_LINUX) = tests/qemu-iotests/socket_scm_helper$(EXESUF) check: check-block export PYTHON check-block: $(SRC_PATH)/tests/check-block.sh qemu-img$(EXESUF) \ - qemu-io$(EXESUF) qemu-nbd$(EXESUF) $(QEMU_IOTESTS_HELPERS-y) \ + qemu-io$(EXESUF) qemu-nbd$(EXESUF) \ $(filter qemu-system-%, $(ninja-targets)) @$< endif -check-build: $(QEMU_IOTESTS_HELPERS-y) - check-clean: rm -rf $(TESTS_VENV_DIR) $(TESTS_RESULTS_DIR) diff --git a/tests/meson.build b/tests/meson.build index 55a7b08275..3f3882748a 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -67,10 +67,6 @@ if have_tools and 'CONFIG_VHOST_USER' in config_host and 'CONFIG_LINUX' in confi dependencies: [qemuutil, vhost_user]) endif -if have_system and 'CONFIG_POSIX' in config_host - subdir('qemu-iotests') -endif - test('decodetree', sh, args: [ files('decode/check.sh'), config_host['PYTHON'], files('../scripts/decodetree.py') ], workdir: meson.current_source_dir() / 'decode', diff --git a/tests/qemu-iotests/iotests.py b/tests/qemu-iotests/iotests.py index ce06cf5630..9afa258a40 100644 --- a/tests/qemu-iotests/iotests.py +++ b/tests/qemu-iotests/iotests.py @@ -109,8 +109,6 @@ qemu_valgrind = ['valgrind', valgrind_logfile, '--error-exitcode=99'] -socket_scm_helper = os.environ.get('SOCKET_SCM_HELPER', 'socket_scm_helper') - luks_default_secret_object = 'secret,id=keysec0,data=' + \ os.environ.get('IMGKEYSECRET', '') luks_default_key_secret_opt = 'key-secret=keysec0' @@ -600,7 +598,6 @@ def __init__(self, path_suffix=''): super().__init__(qemu_prog, qemu_opts, wrapper=wrapper, name=name, base_temp_dir=test_dir, - socket_scm_helper=socket_scm_helper, sock_dir=sock_dir, qmp_timer=timer) self._num_drives = 0 diff --git a/tests/qemu-iotests/meson.build b/tests/qemu-iotests/meson.build deleted file mode 100644 index 67aed1e492..0000000000 --- a/tests/qemu-iotests/meson.build +++ /dev/null @@ -1,5 +0,0 @@ -if 'CONFIG_LINUX' in config_host - socket_scm_helper = executable('socket_scm_helper', 'socket_scm_helper.c') -else - socket_scm_helper = [] -endif diff --git a/tests/qemu-iotests/socket_scm_helper.c b/tests/qemu-iotests/socket_scm_helper.c deleted file mode 100644 index eb76d31aa9..0000000000 --- a/tests/qemu-iotests/socket_scm_helper.c +++ /dev/null @@ -1,136 +0,0 @@ -/* - * SCM_RIGHTS with unix socket help program for test - * - * Copyright IBM, Inc. 2013 - * - * Authors: - * Wenchao Xia - * - * This work is licensed under the terms of the GNU LGPL, version 2 or later. - * See the COPYING.LIB file in the top-level directory. - */ - -#include "qemu/osdep.h" -#include -#include - -/* #define SOCKET_SCM_DEBUG */ - -/* - * @fd and @fd_to_send will not be checked for validation in this function, - * a blank will be sent as iov data to notify qemu. - */ -static int send_fd(int fd, int fd_to_send) -{ - struct msghdr msg; - struct iovec iov[1]; - int ret; - char control[CMSG_SPACE(sizeof(int))]; - struct cmsghdr *cmsg; - - memset(&msg, 0, sizeof(msg)); - memset(control, 0, sizeof(control)); - - /* Send a blank to notify qemu */ - iov[0].iov_base = (void *)" "; - iov[0].iov_len = 1; - - msg.msg_iov = iov; - msg.msg_iovlen = 1; - - msg.msg_control = control; - msg.msg_controllen = sizeof(control); - - cmsg = CMSG_FIRSTHDR(&msg); - - cmsg->cmsg_len = CMSG_LEN(sizeof(int)); - cmsg->cmsg_level = SOL_SOCKET; - cmsg->cmsg_type = SCM_RIGHTS; - memcpy(CMSG_DATA(cmsg), &fd_to_send, sizeof(int)); - - do { - ret = sendmsg(fd, &msg, 0); - } while (ret < 0 && errno == EINTR); - - if (ret < 0) { - fprintf(stderr, "Failed to send msg, reason: %s\n", strerror(errno)); - } - - return ret; -} - -/* Convert string to fd number. */ -static int get_fd_num(const char *fd_str, bool silent) -{ - int sock; - char *err; - - errno = 0; - sock = strtol(fd_str, &err, 10); - if (errno) { - if (!silent) { - fprintf(stderr, "Failed in strtol for socket fd, reason: %s\n", - strerror(errno)); - } - return -1; - } - if (!*fd_str || *err || sock < 0) { - if (!silent) { - fprintf(stderr, "bad numerical value for socket fd '%s'\n", fd_str); - } - return -1; - } - - return sock; -} - -/* - * To make things simple, the caller needs to specify: - * 1. socket fd. - * 2. path of the file to be sent. - */ -int main(int argc, char **argv, char **envp) -{ - int sock, fd, ret; - -#ifdef SOCKET_SCM_DEBUG - int i; - for (i = 0; i < argc; i++) { - fprintf(stderr, "Parameter %d: %s\n", i, argv[i]); - } -#endif - - if (argc != 3) { - fprintf(stderr, - "Usage: %s < socket-fd > < file-path >\n", - argv[0]); - return EXIT_FAILURE; - } - - - sock = get_fd_num(argv[1], false); - if (sock < 0) { - return EXIT_FAILURE; - } - - fd = get_fd_num(argv[2], true); - if (fd < 0) { - /* Now only open a file in readonly mode for test purpose. If more - precise control is needed, use python script in file operation, which - is supposed to fork and exec this program. */ - fd = open(argv[2], O_RDONLY); - if (fd < 0) { - fprintf(stderr, "Failed to open file '%s'\n", argv[2]); - return EXIT_FAILURE; - } - } - - ret = send_fd(sock, fd); - if (ret < 0) { - close(fd); - return EXIT_FAILURE; - } - - close(fd); - return EXIT_SUCCESS; -} diff --git a/tests/qemu-iotests/testenv.py b/tests/qemu-iotests/testenv.py index 70da0d60c8..207bafb649 100644 --- a/tests/qemu-iotests/testenv.py +++ b/tests/qemu-iotests/testenv.py @@ -68,7 +68,7 @@ class TestEnv(ContextManager['TestEnv']): env_variables = ['PYTHONPATH', 'TEST_DIR', 'SOCK_DIR', 'SAMPLE_IMG_DIR', 'OUTPUT_DIR', 'PYTHON', 'QEMU_PROG', 'QEMU_IMG_PROG', 'QEMU_IO_PROG', 'QEMU_NBD_PROG', 'QSD_PROG', - 'SOCKET_SCM_HELPER', 'QEMU_OPTIONS', 'QEMU_IMG_OPTIONS', + 'QEMU_OPTIONS', 'QEMU_IMG_OPTIONS', 'QEMU_IO_OPTIONS', 'QEMU_IO_OPTIONS_NO_FMT', 'QEMU_NBD_OPTIONS', 'IMGOPTS', 'IMGFMT', 'IMGPROTO', 'AIOMODE', 'CACHEMODE', 'VALGRIND_QEMU', @@ -137,7 +137,6 @@ def init_binaries(self) -> None: """Init binary path variables: PYTHON (for bash tests) QEMU_PROG, QEMU_IMG_PROG, QEMU_IO_PROG, QEMU_NBD_PROG, QSD_PROG - SOCKET_SCM_HELPER """ self.python = sys.executable @@ -171,10 +170,6 @@ def root(*names: str) -> str: if not isxfile(b): sys.exit('Not executable: ' + b) - helper_path = os.path.join(self.build_iotests, 'socket_scm_helper') - if isxfile(helper_path): - self.socket_scm_helper = helper_path # SOCKET_SCM_HELPER - def __init__(self, imgfmt: str, imgproto: str, aiomode: str, cachemode: Optional[str] = None, imgopts: Optional[str] = None, @@ -300,7 +295,6 @@ def print_env(self) -> None: PLATFORM -- {platform} TEST_DIR -- {TEST_DIR} SOCK_DIR -- {SOCK_DIR} -SOCKET_SCM_HELPER -- {SOCKET_SCM_HELPER} GDB_OPTIONS -- {GDB_OPTIONS} VALGRIND_QEMU -- {VALGRIND_QEMU} PRINT_QEMU_OUTPUT -- {PRINT_QEMU} From patchwork Tue Sep 28 13:53:08 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 12522853 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E08F3C433F5 for ; Tue, 28 Sep 2021 13:58:10 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 955A460041 for ; Tue, 28 Sep 2021 13:58:10 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 955A460041 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=nongnu.org Received: from localhost ([::1]:59350 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mVDcX-000152-Qy for qemu-devel@archiver.kernel.org; Tue, 28 Sep 2021 09:58:09 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:52560) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mVDY8-0003DN-5w for qemu-devel@nongnu.org; Tue, 28 Sep 2021 09:53:36 -0400 Received: from mail-ed1-x52e.google.com ([2a00:1450:4864:20::52e]:33653) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mVDY6-0004bo-JI for qemu-devel@nongnu.org; Tue, 28 Sep 2021 09:53:35 -0400 Received: by mail-ed1-x52e.google.com with SMTP id b26so35363422edt.0 for ; Tue, 28 Sep 2021 06:53:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=BOPI/djqKYjPQXTHJfdqx0D8MPqvpJzkEAEUycpoQkc=; b=olDeXsstxdJRYtxZToGZATDvISf412WeD+UmgnV3O38AyqmuDs6O/sszwBx8ing2LT PayCaehaWBPdPLmAgUo26VPJE/Oxm6ggB0EJC9QZ/jcAxgQ0D4y3y0/L9vWhEb/lr6DK irq2tnksIsInSzbLZadlPzxvo3U8CK6lfgzdmi4YjPtVzjnu2JEyIx6Ntzg2V/r5eH44 HcvORLrErpXIEJh/vbM2nJosPOXc3Jfb1O2JzADzerLEAXRNaSjpDfEDlUYUItVOiIAh fDykylttoZD4dMitwC1JcR+QzphO0DCyBi4PVpy7yytRHWxMBLoFYFwNIASiYfEApLeD ebNw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=BOPI/djqKYjPQXTHJfdqx0D8MPqvpJzkEAEUycpoQkc=; b=jlavmDKT/fKX4bdpMdoc5J+BzhSIgLR8Pde0jQ7gSLX9o/J/7sOXUxziMv/V3LPNjN 3v03c2wCR+4xz8oQVmvOc5FemV1HKyePWmoNEfAvYfJDRkglHi0fFxX0SbyySvHasbRr aibT5RLEm1TXa/+TB8wrLil4pfw8x2f9qmn+S63pBewJ89c09xYkm2/yBYucbxB+OR23 7eCQ5KkvYkf8QkaXjizcPiG/syb6gTcsUIKi4N6vMyakaLorfgmZbV75bADfOQCyMC+w rfianYalWZ5XZqzoY9kAAI89aPQ41ESlmEdLVHfhTPP7xJeBNpxu1KfkssKUWNbITEXw nhuw== X-Gm-Message-State: AOAM53285v7Gb8M1rpKxhmqvcdhwZBAsHXC/FYq5UF8X78r4s2JoPM3w vBYRu2WkkTJEsV7C913FDG6NYhQtf4g= X-Google-Smtp-Source: ABdhPJy7a6dCXdsefg3XFuD80iEHnZ2fxA7S8ZqWpZlWWA8l4O8tDokc6X1Ghgma0E0YXf8z7gUmWw== X-Received: by 2002:a17:906:2441:: with SMTP id a1mr3184782ejb.414.1632837193030; Tue, 28 Sep 2021 06:53:13 -0700 (PDT) Received: from avogadro.lan ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id v13sm10373247ejh.62.2021.09.28.06.53.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Sep 2021 06:53:12 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PATCH 3/4] python: raise OSError from send_fd_scm Date: Tue, 28 Sep 2021 15:53:08 +0200 Message-Id: <20210928135309.199796-4-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210928135309.199796-1-pbonzini@redhat.com> References: <20210928135309.199796-1-pbonzini@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::52e; envelope-from=paolo.bonzini@gmail.com; helo=mail-ed1-x52e.google.com X-Spam_score_int: 4 X-Spam_score: 0.4 X-Spam_bar: / X-Spam_report: (0.4 / 5.0 requ) DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.249, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: jsnow@redhat.com Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" The previous weird calling convention was a consequence of using socket_scm_helper. Just use exceptions now that it is gone. Signed-off-by: Paolo Bonzini --- python/qemu/machine/machine.py | 11 ++--------- tests/qemu-iotests/045 | 3 +-- tests/qemu-iotests/147 | 3 +-- 3 files changed, 4 insertions(+), 13 deletions(-) diff --git a/python/qemu/machine/machine.py b/python/qemu/machine/machine.py index d230915fbf..813ccb17c2 100644 --- a/python/qemu/machine/machine.py +++ b/python/qemu/machine/machine.py @@ -208,7 +208,7 @@ def add_fd(self: _T, fd: int, fdset: int, return self def send_fd_scm(self, fd: Optional[int] = None, - file_path: Optional[str] = None) -> int: + file_path: Optional[str] = None) -> None: """ Send an fd or file_path via QMP. @@ -225,19 +225,12 @@ def send_fd_scm(self, fd: Optional[int] = None, try: fd = os.open(file_path, os.O_RDONLY) self._qmp.send_fd(fd) - except OSError: - return 1 finally: if fd != -1: os.close(fd) else: assert fd is not None - try: - self._qmp.send_fd(fd) - except OSError: - return 1 - - return 0 + self._qmp.send_fd(fd) @staticmethod def _remove_if_exists(path: str) -> None: diff --git a/tests/qemu-iotests/045 b/tests/qemu-iotests/045 index 45eb239baa..3e6d42010e 100755 --- a/tests/qemu-iotests/045 +++ b/tests/qemu-iotests/045 @@ -141,8 +141,7 @@ class TestSCMFd(iotests.QMPTestCase): os.remove(image0) def _send_fd_by_SCM(self): - ret = self.vm.send_fd_scm(file_path=image0) - self.assertEqual(ret, 0, 'Failed to send fd with UNIX SCM') + self.vm.send_fd_scm(file_path=image0) def test_add_fd(self): self._send_fd_by_SCM() diff --git a/tests/qemu-iotests/147 b/tests/qemu-iotests/147 index 47dfa62e6b..58de6db52e 100755 --- a/tests/qemu-iotests/147 +++ b/tests/qemu-iotests/147 @@ -269,8 +269,7 @@ class BuiltinNBD(NBDBlockdevAddBase): sockfd = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) sockfd.connect(unix_socket) - result = self.vm.send_fd_scm(fd=sockfd.fileno()) - self.assertEqual(result, 0, 'Failed to send socket FD') + self.vm.send_fd_scm(fd=sockfd.fileno()) result = self.vm.qmp('getfd', fdname='nbd-fifo') self.assert_qmp(result, 'return', {}) From patchwork Tue Sep 28 13:53:09 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 12522849 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BC114C433F5 for ; Tue, 28 Sep 2021 13:56:19 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 6EE1C611CA for ; Tue, 28 Sep 2021 13:56:19 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 6EE1C611CA Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=nongnu.org Received: from localhost ([::1]:53234 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mVDak-0005IW-K5 for qemu-devel@archiver.kernel.org; Tue, 28 Sep 2021 09:56:18 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:52558) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mVDY8-0003DM-2Q for qemu-devel@nongnu.org; Tue, 28 Sep 2021 09:53:36 -0400 Received: from mail-ed1-x52a.google.com ([2a00:1450:4864:20::52a]:40920) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mVDY6-0004be-2I for qemu-devel@nongnu.org; Tue, 28 Sep 2021 09:53:35 -0400 Received: by mail-ed1-x52a.google.com with SMTP id g8so83670728edt.7 for ; Tue, 28 Sep 2021 06:53:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=2G1GFCQNbOJFx5keFGzEJBeOKV62iPssw9Ehaz2Zo6A=; b=bYYUGrYXregYTkMTDgF0DptZbRT7UfLw/ZpwzUrqS7qjU0sJ8KVTS283ZFqf7OFaB4 0vM/HCY7Otl2UCCJ2x99TcL/zK46yX4fDyNd6yAM4NmdGfJa7JPVu7mOLiR8xK2+P/WV E/FcPNh0x7/8Ojacen213lTZ1ITnnBtYqqjx4bFCxfNfjiEQL8z/uCMNnL0jCVfzwZ3C Er4IjKnwQtfC7VhPqc5CIuX2IhFw83PILfZavv3j26K4NKxEDErCj9G2rIC+3x4qZ3/d tWxIE3VVuWVvQX6Wrfu4BJ9DW6oQYzbdkLVrZUZLscfd0c/MVTTiKhjM8bi3oXO6ZIxr OQDw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=2G1GFCQNbOJFx5keFGzEJBeOKV62iPssw9Ehaz2Zo6A=; b=2xpVzuuLNFIOB5IXYp91xAz++WrDrPCxcXGseASn5ixiiRPUgm2O2aWXJMmPi8E0Ii TPzFbNa6xqMt6saWx0N9vOsFyWCg45LkIzfpGs6zEJh1wxkiDrX0WEC5ObDM/weHIA16 2l9kuZWto1gt68N4TW2sZzs1T1VcVT1nxw7z3su4PRixwOPELvEq15WupQRPy0jEvGWs Ir9T2qfqiI4aTC61dX9SOy3THSRCuXZqdrAimP2Y2moWGpenvN7du5ebHxkC+0AtQ1y8 fQ9aJnlKUs4lcuBhRLQbGZozppbsUOJ/VY3+zsLfylFMr8SmRVFkbX2//gEQytwudsf7 n4Ew== X-Gm-Message-State: AOAM531ZMpwg54ARg+c7aF8d06K9lJ9YftrH373isHoldi/Os9B9w2/g NWdqP0HG4LEaDJMfiCvZq6f9VmvhN8Q= X-Google-Smtp-Source: ABdhPJyPos1gQVNAF+PA3clI/u5wPU4EzOzdEFK54qXzIaoW6Szqzn2kqHqs/1hiRhSiSU51/230wA== X-Received: by 2002:a17:906:d8a4:: with SMTP id qc4mr7099372ejb.323.1632837193814; Tue, 28 Sep 2021 06:53:13 -0700 (PDT) Received: from avogadro.lan ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id v13sm10373247ejh.62.2021.09.28.06.53.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Sep 2021 06:53:13 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PATCH 4/4] python: split the two sides of send_fd_scm Date: Tue, 28 Sep 2021 15:53:09 +0200 Message-Id: <20210928135309.199796-5-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210928135309.199796-1-pbonzini@redhat.com> References: <20210928135309.199796-1-pbonzini@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::52a; envelope-from=paolo.bonzini@gmail.com; helo=mail-ed1-x52a.google.com X-Spam_score_int: -14 X-Spam_score: -1.5 X-Spam_bar: - X-Spam_report: (-1.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.249, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: jsnow@redhat.com Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" send_fd_scm can be used as a simple wrapper for self._qmp.send_fd, or it can be given a file that will be opened for the duration of the sendmsg system call. Split the two cases to separate functions. Signed-off-by: Paolo Bonzini --- python/qemu/machine/machine.py | 34 ++++++++++++++++------------------ tests/qemu-iotests/045 | 2 +- tests/qemu-iotests/147 | 2 +- 3 files changed, 18 insertions(+), 20 deletions(-) diff --git a/python/qemu/machine/machine.py b/python/qemu/machine/machine.py index 813ccb17c2..8ad3604049 100644 --- a/python/qemu/machine/machine.py +++ b/python/qemu/machine/machine.py @@ -207,30 +207,28 @@ def add_fd(self: _T, fd: int, fdset: int, self._args.append(','.join(options)) return self - def send_fd_scm(self, fd: Optional[int] = None, - file_path: Optional[str] = None) -> None: + def send_file_scm(self, file_path: str) -> None: """ - Send an fd or file_path via QMP. - - Exactly one of fd and file_path must be given. - If it is file_path, the function will open that file and pass - its own fd. + Open a file and pass it to QEMU as a file descriptor. """ # In iotest.py, the qmp should always use unix socket. assert self._qmp.is_scm_available() - if file_path is not None: - assert fd is None - fd = -1 - try: - fd = os.open(file_path, os.O_RDONLY) - self._qmp.send_fd(fd) - finally: - if fd != -1: - os.close(fd) - else: - assert fd is not None + fd = -1 + try: + fd = os.open(file_path, os.O_RDONLY) self._qmp.send_fd(fd) + finally: + if fd != -1: + os.close(fd) + + def send_fd_scm(self, fd: int) -> None: + """ + Send a file descriptor via QMP. + """ + # In iotest.py, the qmp should always use unix socket. + assert self._qmp.is_scm_available() + self._qmp.send_fd(fd) @staticmethod def _remove_if_exists(path: str) -> None: diff --git a/tests/qemu-iotests/045 b/tests/qemu-iotests/045 index 3e6d42010e..1d1fe4a19a 100755 --- a/tests/qemu-iotests/045 +++ b/tests/qemu-iotests/045 @@ -141,7 +141,7 @@ class TestSCMFd(iotests.QMPTestCase): os.remove(image0) def _send_fd_by_SCM(self): - self.vm.send_fd_scm(file_path=image0) + self.vm.send_file_scm(image0) def test_add_fd(self): self._send_fd_by_SCM() diff --git a/tests/qemu-iotests/147 b/tests/qemu-iotests/147 index 58de6db52e..e493ff4d0d 100755 --- a/tests/qemu-iotests/147 +++ b/tests/qemu-iotests/147 @@ -269,7 +269,7 @@ class BuiltinNBD(NBDBlockdevAddBase): sockfd = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) sockfd.connect(unix_socket) - self.vm.send_fd_scm(fd=sockfd.fileno()) + self.vm.send_fd_scm(sockfd.fileno()) result = self.vm.qmp('getfd', fdname='nbd-fifo') self.assert_qmp(result, 'return', {})