From nobody Mon Sep 16 19:19:29 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1683309721; cv=none; d=zohomail.com; s=zohoarc; b=c17Etl0JmZId1kqH2ymEQFRCh8p/Ydq9kKPN0qiJFpUCmd+vbqstcBCnq2Z0fuFeP8IMWV1jHDJLfJoE1rR66sHXi8VWXNd6Etc1otLVaIQD9+0znGaWZlP6Yn082QrZG3I9ileRNMUW584rbhO47qfWVWotXOJmu0yVNTl17s0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1683309721; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=4mqDuGq2Whjk3WsKzlVkaKWFuPGtBLN7iytaSFNgkrw=; b=QOa3G20PmDG3eEBQ5uWKTUnRkmS0MklJkFg+ZjTXzvfxDBGca7XlrnR4D9fQ6OL8xH7ZbgjgLXmGpXkOd/WhEVPQWbrKMeozj7DzwjqVZdBfhzwFOKDgjV82Yi76UFIGo5bXoO01XQWxfJ4qBa/YIhjoi+K6OnYM2usyEWKnfFA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.zohomail.com with SMTPS id 1683309721816119.66232397599731; Fri, 5 May 2023 11:02:01 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-589--rbJvJ3FOm6g03FBhhDJhA-1; Fri, 05 May 2023 14:01:57 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 06E8A1C07540; Fri, 5 May 2023 18:01:53 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id E667540C6F41; Fri, 5 May 2023 18:01:52 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id C8D071946A48; Fri, 5 May 2023 18:01:52 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id CD2621946A4A for ; Fri, 5 May 2023 18:01:50 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id BC6B82026D3C; Fri, 5 May 2023 18:01:50 +0000 (UTC) Received: from harajuku.usersys.redhat.com.homenet.telecomitalia.it (unknown [10.45.224.44]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 4B6642026D16 for ; Fri, 5 May 2023 18:01:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1683309719; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=4mqDuGq2Whjk3WsKzlVkaKWFuPGtBLN7iytaSFNgkrw=; b=V78y/z98406qAOnkSldTQIhHzdTKAMex9Df3wrMigH7WP0j65p9MFakfrWkgy49LktHrOW hN9jUDTtv3CmiLb/1X+bxdUQiVy34VWDzRVaK4JC1me4MzHRKh867AnH6955gbJzK7WF8/ XHr1dszpA8LeHRiBw7qq9Irsee3XXyw= X-MC-Unique: -rbJvJ3FOm6g03FBhhDJhA-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Andrea Bolognani To: libvir-list@redhat.com Subject: [libvirt PATCH 3/5] qemu: Find helpers at runtime Date: Fri, 5 May 2023 20:01:44 +0200 Message-Id: <20230505180146.551086-4-abologna@redhat.com> In-Reply-To: <20230505180146.551086-1-abologna@redhat.com> References: <20230505180146.551086-1-abologna@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1683309723106100005 Content-Type: text/plain; charset="utf-8"; x-default="true" Use the recently introduced virFindFileInPathFull() function to discover the path for qemu-bridge-helper and qemu-pr-helper at runtime. Note that it's still possible for the administrator to prevent this lookup and use arbitrary binaries by setting the appropriate keys in qemu.conf: this simply removes the need to perform the lookup at build time, and thus to have the helpers installed in the build environment. Signed-off-by: Andrea Bolognani --- src/qemu/qemu_interface.c | 15 +++++++++++++-- src/qemu/qemu_process.c | 17 +++++++++++++---- 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/src/qemu/qemu_interface.c b/src/qemu/qemu_interface.c index e395bfcc5b..e875de48ee 100644 --- a/src/qemu/qemu_interface.c +++ b/src/qemu/qemu_interface.c @@ -327,7 +327,14 @@ qemuCreateInBridgePortWithHelper(virQEMUDriverConfig *= cfg, int *tapfd, unsigned int flags) { + const char *const bridgeHelperDirs[] =3D { + "/usr/libexec", + "/usr/lib/qemu", + "/usr/lib", + NULL, + }; g_autoptr(virCommand) cmd =3D NULL; + g_autofree char *bridgeHelperPath =3D NULL; char *errbuf =3D NULL, *cmdstr =3D NULL; int pair[2] =3D { -1, -1 }; =20 @@ -339,13 +346,17 @@ qemuCreateInBridgePortWithHelper(virQEMUDriverConfig = *cfg, return -1; } =20 - if (!virFileIsExecutable(cfg->bridgeHelperName)) { + bridgeHelperPath =3D virFindFileInPathFull(cfg->bridgeHelperName, brid= geHelperDirs); + + if (!bridgeHelperPath) { virReportSystemError(errno, _("'%1$s' is not a suitable bridge hel= per"), cfg->bridgeHelperName); return -1; } =20 - cmd =3D virCommandNew(cfg->bridgeHelperName); + VIR_DEBUG("Using qemu-bridge-helper: %s", bridgeHelperPath); + + cmd =3D virCommandNew(bridgeHelperPath); if (flags & VIR_NETDEV_TAP_CREATE_VNET_HDR) virCommandAddArgFormat(cmd, "--use-vnet"); virCommandAddArgFormat(cmd, "--br=3D%s", brname); diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 952814d663..bb4cf35226 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -2818,10 +2818,15 @@ qemuProcessStartPRDaemonHook(void *opaque) int qemuProcessStartManagedPRDaemon(virDomainObj *vm) { + const char *const prHelperDirs[] =3D { + "/usr/libexec", + NULL, + }; qemuDomainObjPrivate *priv =3D vm->privateData; virQEMUDriver *driver =3D priv->driver; g_autoptr(virQEMUDriverConfig) cfg =3D NULL; int errfd =3D -1; + g_autofree char *prHelperPath =3D NULL; g_autofree char *pidfile =3D NULL; g_autofree char *socketPath =3D NULL; pid_t cpid =3D -1; @@ -2832,12 +2837,16 @@ qemuProcessStartManagedPRDaemon(virDomainObj *vm) =20 cfg =3D virQEMUDriverGetConfig(driver); =20 - if (!virFileIsExecutable(cfg->prHelperName)) { + prHelperPath =3D virFindFileInPathFull(cfg->prHelperName, prHelperDirs= ); + + if (!prHelperPath) { virReportSystemError(errno, _("'%1$s' is not a suitable pr helper"= ), cfg->prHelperName); goto cleanup; } =20 + VIR_DEBUG("Using qemu-pr-helper: %s", prHelperPath); + if (!(pidfile =3D qemuProcessBuildPRHelperPidfilePath(vm))) goto cleanup; =20 @@ -2853,7 +2862,7 @@ qemuProcessStartManagedPRDaemon(virDomainObj *vm) goto cleanup; } =20 - if (!(cmd =3D virCommandNewArgList(cfg->prHelperName, + if (!(cmd =3D virCommandNewArgList(prHelperPath, "-k", socketPath, NULL))) goto cleanup; @@ -2881,7 +2890,7 @@ qemuProcessStartManagedPRDaemon(virDomainObj *vm) if (virPidFileReadPath(pidfile, &cpid) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("pr helper %1$s didn't show up"), - cfg->prHelperName); + prHelperPath); goto cleanup; } =20 @@ -2899,7 +2908,7 @@ qemuProcessStartManagedPRDaemon(virDomainObj *vm) if (saferead(errfd, errbuf, sizeof(errbuf) - 1) < 0) { virReportSystemError(errno, _("pr helper %1$s died unexpectedly"), - cfg->prHelperName); + prHelperPath); } else { virReportError(VIR_ERR_OPERATION_FAILED, _("pr helper died and reported: %1$s"), errbuf); --=20 2.40.1