From nobody Sun May 19 23:41:29 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 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=1568379076; cv=none; d=zoho.com; s=zohoarc; b=Tb59WEfOD/gnF0Hg581u9ytyTF3zU0ODawk0Epw7xuGxzfcB0k3+TFBGV9x1iCHRAb5uERP+Dg0eBt7lENF2A8+m29GGaRSzbACF6P4kHRIQz/vpmSTeVuuAMU7ghiAizsQmQAc+1TGNEgTs6UgNRMqxShE3O5r0nTinkhcFSHY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1568379076; h=Content-Type:Content-Transfer-Encoding:Cc: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:ARC-Authentication-Results; bh=PhDN6LCVkQIfyORsIm6n1pAESCBlyd0VzzfI0koHk2Y=; b=icIIGL1c/iK/RcrAc3Mtv7Tgzsd4RNHlW+McqV1OZUi2ruVWp3SCCa93y2ttEGU6fT7BwwsT6cOqnkaA99apCrvnEaExaVM9OhMgQ3jbH9ARipoptUVUVvR52+X4Z952eqN417o0DGVBK0XYNprR4IrKrMzby+4yMtLqUTY0dMk= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 156837907681490.12103648815469; Fri, 13 Sep 2019 05:51:16 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2889F1DA4; Fri, 13 Sep 2019 12:51:15 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id F267D60A9F; Fri, 13 Sep 2019 12:51:14 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id B9F90180221E; Fri, 13 Sep 2019 12:51:14 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x8DCpEO5027916 for ; Fri, 13 Sep 2019 08:51:14 -0400 Received: by smtp.corp.redhat.com (Postfix) id 38F41194B9; Fri, 13 Sep 2019 12:51:14 +0000 (UTC) Received: from localhost (ovpn-112-45.ams2.redhat.com [10.36.112.45]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1F37219C78; Fri, 13 Sep 2019 12:51:11 +0000 (UTC) From: marcandre.lureau@redhat.com To: libvir-list@redhat.com Date: Fri, 13 Sep 2019 16:50:38 +0400 Message-Id: <20190913125057.29333-2-marcandre.lureau@redhat.com> In-Reply-To: <20190913125057.29333-1-marcandre.lureau@redhat.com> References: <20190913125057.29333-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-loop: libvir-list@redhat.com Cc: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , jtomko@redhat.com Subject: [libvirt] [PATCH v4 01/20] qemu: generalize qemuFetchConfigs X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.71]); Fri, 13 Sep 2019 12:51:15 +0000 (UTC) From: Marc-Andr=C3=A9 Lureau The same config files disovery & priority rules are used for vhost-user backends. No functional change, the only difference is that qemuInteropFetchConfigs() takes a "name" argument and construct paths with it (ex: "firmware"). Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: J=C3=A1n Tomko --- src/qemu/Makefile.inc.am | 2 + src/qemu/qemu_firmware.c | 144 +------------------------- src/qemu/qemu_interop_config.c | 183 +++++++++++++++++++++++++++++++++ src/qemu/qemu_interop_config.h | 25 +++++ 4 files changed, 212 insertions(+), 142 deletions(-) create mode 100644 src/qemu/qemu_interop_config.c create mode 100644 src/qemu/qemu_interop_config.h diff --git a/src/qemu/Makefile.inc.am b/src/qemu/Makefile.inc.am index 48fd0332ec..7351dc0486 100644 --- a/src/qemu/Makefile.inc.am +++ b/src/qemu/Makefile.inc.am @@ -32,6 +32,8 @@ QEMU_DRIVER_SOURCES =3D \ qemu/qemu_hotplugpriv.h \ qemu/qemu_conf.c \ qemu/qemu_conf.h \ + qemu/qemu_interop_config.c \ + qemu/qemu_interop_config.h \ qemu/qemu_process.c \ qemu/qemu_process.h \ qemu/qemu_processpriv.h \ diff --git a/src/qemu/qemu_firmware.c b/src/qemu/qemu_firmware.c index f316a26a5b..aba2c359e7 100644 --- a/src/qemu/qemu_firmware.c +++ b/src/qemu/qemu_firmware.c @@ -23,13 +23,12 @@ #include =20 #include "qemu_firmware.h" +#include "qemu_interop_config.h" #include "configmake.h" #include "qemu_capabilities.h" #include "qemu_domain.h" #include "qemu_process.h" #include "virarch.h" -#include "virfile.h" -#include "virhash.h" #include "virjson.h" #include "virlog.h" #include "virstring.h" @@ -907,150 +906,11 @@ qemuFirmwareFormat(qemuFirmwarePtr fw) } =20 =20 -static int -qemuFirmwareBuildFileList(virHashTablePtr files, const char *dir) -{ - DIR *dirp; - struct dirent *ent =3D NULL; - int rc; - int ret =3D -1; - - if ((rc =3D virDirOpenIfExists(&dirp, dir)) < 0) - return -1; - - if (rc =3D=3D 0) - return 0; - - while ((rc =3D virDirRead(dirp, &ent, dir)) > 0) { - VIR_AUTOFREE(char *) filename =3D NULL; - VIR_AUTOFREE(char *) path =3D NULL; - struct stat sb; - - if (STRPREFIX(ent->d_name, ".")) - continue; - - if (VIR_STRDUP(filename, ent->d_name) < 0) - goto cleanup; - - if (virAsprintf(&path, "%s/%s", dir, filename) < 0) - goto cleanup; - - if (stat(path, &sb) < 0) { - virReportSystemError(errno, _("Unable to access %s"), path); - goto cleanup; - } - - if (!S_ISREG(sb.st_mode) && !S_ISLNK(sb.st_mode)) - continue; - - if (virHashUpdateEntry(files, filename, path) < 0) - goto cleanup; - - path =3D NULL; - } - - if (rc < 0) - goto cleanup; - - ret =3D 0; - cleanup: - virDirClose(&dirp); - return ret; -} - -static int -qemuFirmwareFilesSorter(const virHashKeyValuePair *a, - const virHashKeyValuePair *b) -{ - return strcmp(a->key, b->key); -} - -#define QEMU_FIRMWARE_SYSTEM_LOCATION PREFIX "/share/qemu/firmware" -#define QEMU_FIRMWARE_ETC_LOCATION SYSCONFDIR "/qemu/firmware" - int qemuFirmwareFetchConfigs(char ***firmwares, bool privileged) { - VIR_AUTOPTR(virHashTable) files =3D NULL; - VIR_AUTOFREE(char *) homeConfig =3D NULL; - VIR_AUTOFREE(char *) xdgConfig =3D NULL; - VIR_AUTOFREE(virHashKeyValuePairPtr) pairs =3D NULL; - virHashKeyValuePairPtr tmp =3D NULL; - - *firmwares =3D NULL; - - if (!privileged) { - /* This is a slight divergence from the specification. - * Since the system daemon runs as root, it doesn't make - * much sense to parse files in root's home directory. It - * makes sense only for session daemon which runs under - * regular user. */ - if (VIR_STRDUP(xdgConfig, getenv("XDG_CONFIG_HOME")) < 0) - return -1; - - if (!xdgConfig) { - VIR_AUTOFREE(char *) home =3D virGetUserDirectory(); - - if (!home) - return -1; - - if (virAsprintf(&xdgConfig, "%s/.config", home) < 0) - return -1; - } - - if (virAsprintf(&homeConfig, "%s/qemu/firmware", xdgConfig) < 0) - return -1; - } - - if (!(files =3D virHashCreate(10, virHashValueFree))) - return -1; - - if (qemuFirmwareBuildFileList(files, QEMU_FIRMWARE_SYSTEM_LOCATION) < = 0) - return -1; - - if (qemuFirmwareBuildFileList(files, QEMU_FIRMWARE_ETC_LOCATION) < 0) - return -1; - - if (homeConfig && - qemuFirmwareBuildFileList(files, homeConfig) < 0) - return -1; - - /* At this point, the @files hash table contains unique set of filenam= es - * where each filename (as key) has the highest priority full pathname - * associated with it. */ - - if (virHashSize(files) =3D=3D 0) - return 0; - - if (!(pairs =3D virHashGetItems(files, qemuFirmwareFilesSorter))) - return -1; - - for (tmp =3D pairs; tmp->key; tmp++) { - const char *path =3D tmp->value; - off_t len; - - if ((len =3D virFileLength(path, -1)) < 0) { - virReportSystemError(errno, - _("unable to get size of '%s'"), - path); - return -1; - } - - VIR_DEBUG("firmware description path '%s' len=3D%jd", - path, (intmax_t) len); - - if (len =3D=3D 0) { - /* Empty files are used to mask less specific instances - * of the same file. */ - continue; - } - - if (virStringListAdd(firmwares, path) < 0) - return -1; - } - - return 0; + return qemuInteropFetchConfigs("firmware", firmwares, privileged); } =20 =20 diff --git a/src/qemu/qemu_interop_config.c b/src/qemu/qemu_interop_config.c new file mode 100644 index 0000000000..1f39d4b576 --- /dev/null +++ b/src/qemu/qemu_interop_config.c @@ -0,0 +1,183 @@ +/* + * qemu_interop_config.c: QEMU firmware/vhost-user etc configs + * + * Copyright (C) 2019 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see + * . + */ + +#include + +#include "qemu_interop_config.h" +#include "configmake.h" +#include "viralloc.h" +#include "virenum.h" +#include "virfile.h" +#include "virhash.h" +#include "virlog.h" +#include "virstring.h" + +#define VIR_FROM_THIS VIR_FROM_QEMU + +VIR_LOG_INIT("qemu.qemu_configs"); + +static int +qemuBuildFileList(virHashTablePtr files, const char *dir) +{ + DIR *dirp; + struct dirent *ent =3D NULL; + int rc; + int ret =3D -1; + + if ((rc =3D virDirOpenIfExists(&dirp, dir)) < 0) + return -1; + + if (rc =3D=3D 0) + return 0; + + while ((rc =3D virDirRead(dirp, &ent, dir)) > 0) { + VIR_AUTOFREE(char *) filename =3D NULL; + VIR_AUTOFREE(char *) path =3D NULL; + struct stat sb; + + if (STRPREFIX(ent->d_name, ".")) + continue; + + if (VIR_STRDUP(filename, ent->d_name) < 0) + goto cleanup; + + if (virAsprintf(&path, "%s/%s", dir, filename) < 0) + goto cleanup; + + if (stat(path, &sb) < 0) { + virReportSystemError(errno, _("Unable to access %s"), path); + goto cleanup; + } + + if (!S_ISREG(sb.st_mode) && !S_ISLNK(sb.st_mode)) + continue; + + if (virHashUpdateEntry(files, filename, path) < 0) + goto cleanup; + + path =3D NULL; + } + + if (rc < 0) + goto cleanup; + + ret =3D 0; + cleanup: + virDirClose(&dirp); + return ret; +} + +static int +qemuConfigFilesSorter(const virHashKeyValuePair *a, + const virHashKeyValuePair *b) +{ + return strcmp(a->key, b->key); +} + +#define QEMU_SYSTEM_LOCATION PREFIX "/share/qemu" +#define QEMU_ETC_LOCATION SYSCONFDIR "/qemu" + +int +qemuInteropFetchConfigs(const char *name, + char ***configs, + bool privileged) +{ + VIR_AUTOPTR(virHashTable) files =3D NULL; + VIR_AUTOFREE(char *) homeConfig =3D NULL; + VIR_AUTOFREE(char *) xdgConfig =3D NULL; + VIR_AUTOFREE(char *) sysLocation =3D virFileBuildPath(QEMU_SYSTEM_LOCA= TION, name, NULL); + VIR_AUTOFREE(char *) etcLocation =3D virFileBuildPath(QEMU_ETC_LOCATIO= N, name, NULL); + VIR_AUTOFREE(virHashKeyValuePairPtr) pairs =3D NULL; + virHashKeyValuePairPtr tmp =3D NULL; + + *configs =3D NULL; + + if (!privileged) { + /* This is a slight divergence from the specification. + * Since the system daemon runs as root, it doesn't make + * much sense to parse files in root's home directory. It + * makes sense only for session daemon which runs under + * regular user. */ + if (VIR_STRDUP(xdgConfig, getenv("XDG_CONFIG_HOME")) < 0) + return -1; + + if (!xdgConfig) { + VIR_AUTOFREE(char *) home =3D virGetUserDirectory(); + + if (!home) + return -1; + + if (virAsprintf(&xdgConfig, "%s/.config", home) < 0) + return -1; + } + + if (virAsprintf(&homeConfig, "%s/qemu/%s", xdgConfig, name) < 0) + return -1; + } + + if (!(files =3D virHashCreate(10, virHashValueFree))) + return -1; + + if (qemuBuildFileList(files, sysLocation) < 0) + return -1; + + if (qemuBuildFileList(files, etcLocation) < 0) + return -1; + + if (homeConfig && + qemuBuildFileList(files, homeConfig) < 0) + return -1; + + /* At this point, the @files hash table contains unique set of filenam= es + * where each filename (as key) has the highest priority full pathname + * associated with it. */ + + if (virHashSize(files) =3D=3D 0) + return 0; + + if (!(pairs =3D virHashGetItems(files, qemuConfigFilesSorter))) + return -1; + + for (tmp =3D pairs; tmp->key; tmp++) { + const char *path =3D tmp->value; + off_t len; + + if ((len =3D virFileLength(path, -1)) < 0) { + virReportSystemError(errno, + _("unable to get size of '%s'"), + path); + return -1; + } + + VIR_DEBUG("%s description path '%s' len=3D%jd", + name, path, (intmax_t) len); + + if (len =3D=3D 0) { + /* Empty files are used to mask less specific instances + * of the same file. */ + continue; + } + + if (virStringListAdd(configs, path) < 0) + return -1; + } + + return 0; +} diff --git a/src/qemu/qemu_interop_config.h b/src/qemu/qemu_interop_config.h new file mode 100644 index 0000000000..9ac1fe9610 --- /dev/null +++ b/src/qemu/qemu_interop_config.h @@ -0,0 +1,25 @@ +/* + * qemu_interop_config.h: QEMU firmware/vhost-user etc configs + * + * Copyright (C) 2019 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see + * . + */ + +#pragma once + +#include "internal.h" + +int qemuInteropFetchConfigs(const char *name, char ***configs, bool privil= eged); --=20 2.23.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun May 19 23:41:29 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 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=1568379083; cv=none; d=zoho.com; s=zohoarc; b=D9Fo59+BDFs58rwfX8a4XetQ4kvJLnh6xw57IvJLkFf7B+6jGuPIs6S9/Z3VXCEY0DI0olDqI9qGwTd37VFUBW2P6djNvoY8o2GgxDPJh3DiGIsaaDwpWuJDG8BFkq/rnCjHC7RDHPvATsPtqKGe+EOM6tQDbtof5986/Xz1VHQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1568379083; h=Content-Type:Content-Transfer-Encoding:Cc: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:ARC-Authentication-Results; bh=E09iWV1QAaS9LnFuEeET+DGFdB1wtjcU6t/j9eF5B/s=; b=m25e0AcrSizDHTJDsiJpkhyWSuUsJxAusex+HinHRHKgdP5YbwrxtAYKAcGB8KL8YxnQ4dpPkOz5C0ZPfqx0G0cluYGUK5629+pnyFsL7ANHKvlEG63BlrPvWzf8eAelWiyU9wj9nA2a1C+Rjsp4yc3kpqXVcb42vjrG8a1sLy8= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 156837908346911.677703854820265; Fri, 13 Sep 2019 05:51:23 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D110E1DAC; Fri, 13 Sep 2019 12:51:21 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id AB55319C78; Fri, 13 Sep 2019 12:51:21 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 6B647180221F; Fri, 13 Sep 2019 12:51:21 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x8DCpJnA027934 for ; Fri, 13 Sep 2019 08:51:19 -0400 Received: by smtp.corp.redhat.com (Postfix) id A48484533; Fri, 13 Sep 2019 12:51:19 +0000 (UTC) Received: from localhost (ovpn-112-45.ams2.redhat.com [10.36.112.45]) by smtp.corp.redhat.com (Postfix) with ESMTP id A619019C78; Fri, 13 Sep 2019 12:51:18 +0000 (UTC) From: marcandre.lureau@redhat.com To: libvir-list@redhat.com Date: Fri, 13 Sep 2019 16:50:39 +0400 Message-Id: <20190913125057.29333-3-marcandre.lureau@redhat.com> In-Reply-To: <20190913125057.29333-1-marcandre.lureau@redhat.com> References: <20190913125057.29333-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-loop: libvir-list@redhat.com Cc: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , jtomko@redhat.com Subject: [libvirt] [PATCH v4 02/20] util: ignore EACCESS in virDirOpenIfExists X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.71]); Fri, 13 Sep 2019 12:51:22 +0000 (UTC) From: Marc-Andr=C3=A9 Lureau Whether a directory exists or is not readable shouldn't make a big diffence. This removes errors when firmare or vhost-user config is looked up from a user session libvirt if /etc/libvirt is not readable. Signed-off-by: Marc-Andr=C3=A9 Lureau --- src/util/virfile.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/util/virfile.c b/src/util/virfile.c index bb844c64e5..4d1fe50efc 100644 --- a/src/util/virfile.c +++ b/src/util/virfile.c @@ -2855,7 +2855,8 @@ virFileRemove(const char *path, #endif /* WIN32 */ =20 static int -virDirOpenInternal(DIR **dirp, const char *name, bool ignoreENOENT, bool q= uiet) +virDirOpenInternal(DIR **dirp, const char *name, + bool ignoreENOENT, bool ignoreEACCESS, bool quiet) { *dirp =3D opendir(name); /* exempt from syntax-check */ if (!*dirp) { @@ -2864,6 +2865,8 @@ virDirOpenInternal(DIR **dirp, const char *name, bool= ignoreENOENT, bool quiet) =20 if (ignoreENOENT && errno =3D=3D ENOENT) return 0; + if (ignoreEACCESS && errno =3D=3D EACCES) + return 0; virReportSystemError(errno, _("cannot open directory '%s'"), name); return -1; } @@ -2881,7 +2884,7 @@ virDirOpenInternal(DIR **dirp, const char *name, bool= ignoreENOENT, bool quiet) int virDirOpen(DIR **dirp, const char *name) { - return virDirOpenInternal(dirp, name, false, false); + return virDirOpenInternal(dirp, name, false, false, false); } =20 /** @@ -2890,13 +2893,13 @@ virDirOpen(DIR **dirp, const char *name) * @name: path of the directory * * Returns 1 on success. - * If opendir returns ENOENT, 0 is returned without reporting an error. + * If opendir returns ENOENT or EACCES, 0 is returned without reporting an= error. * On other errors, -1 is returned and an error is reported. */ int virDirOpenIfExists(DIR **dirp, const char *name) { - return virDirOpenInternal(dirp, name, true, false); + return virDirOpenInternal(dirp, name, true, true, false); } =20 /** @@ -2912,7 +2915,7 @@ virDirOpenIfExists(DIR **dirp, const char *name) int virDirOpenQuiet(DIR **dirp, const char *name) { - return virDirOpenInternal(dirp, name, false, true); + return virDirOpenInternal(dirp, name, false, false, true); } =20 /** --=20 2.23.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun May 19 23:41:29 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 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=1568379094; cv=none; d=zoho.com; s=zohoarc; b=Q1rthyRiDBBxh5Z3+oJnDec+Icwis1F7bJ32YSaErc/oO4Y50XUkRxScXMmZ/zpNOV6Fp0B0RIgFSQUt/U+IP6O/7HQB5HS2rYDhVpDbU7upsY+Ax9XIt3RPZmQw4I7A/xm9tSmBrRBkFKBv44UTFp6fC8g0NU8ZORiDQZ2whCQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1568379094; h=Content-Type:Content-Transfer-Encoding:Cc: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:ARC-Authentication-Results; bh=hXtqHTZfOS+x8kCxKsyjnLM7dqGAjGF/QOajLRU3A+4=; b=awA/u5MPBQmIUfVbhqzkPuMOQSqgNx7y+96OHq4KHAYOMoaYYf2y7yvd/EoTaBnKAtCmHBCFs+koL76jaZXkib+8mBcFJbxZUej1bxDr0qE0p0b9YNdVTlCvrXo7FDodFftY3W2BILpAbbKa2ekR02od7dWn2/Wr7m2FGBYm0ew= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1568379094028155.43362581142844; Fri, 13 Sep 2019 05:51:34 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 62CBA3090FD0; Fri, 13 Sep 2019 12:51:32 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3582F5C22F; Fri, 13 Sep 2019 12:51:32 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id F0A50246A3; Fri, 13 Sep 2019 12:51:31 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x8DCpUaw027987 for ; Fri, 13 Sep 2019 08:51:30 -0400 Received: by smtp.corp.redhat.com (Postfix) id 7F5F05C3FA; Fri, 13 Sep 2019 12:51:30 +0000 (UTC) Received: from localhost (ovpn-112-45.ams2.redhat.com [10.36.112.45]) by smtp.corp.redhat.com (Postfix) with ESMTP id 749285C290; Fri, 13 Sep 2019 12:51:23 +0000 (UTC) From: marcandre.lureau@redhat.com To: libvir-list@redhat.com Date: Fri, 13 Sep 2019 16:50:40 +0400 Message-Id: <20190913125057.29333-4-marcandre.lureau@redhat.com> In-Reply-To: <20190913125057.29333-1-marcandre.lureau@redhat.com> References: <20190913125057.29333-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Cc: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , jtomko@redhat.com Subject: [libvirt] [PATCH v4 03/20] conf: format/parse/rng/docs for video X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.43]); Fri, 13 Sep 2019 12:51:32 +0000 (UTC) From: Marc-Andr=C3=A9 Lureau Accept a new driver name attribute to specify usage of helper process, ex: Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: J=C3=A1n Tomko --- docs/formatdomain.html.in | 12 ++++++- docs/schemas/domaincommon.rng | 8 +++++ src/conf/domain_conf.c | 42 ++++++++++++++++++++++- src/conf/domain_conf.h | 12 +++++++ tests/qemuxml2argvdata/virtio-options.xml | 2 +- 5 files changed, 73 insertions(+), 3 deletions(-) diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in index 86a5261e47..60a47c812b 100644 --- a/docs/formatdomain.html.in +++ b/docs/formatdomain.html.in @@ -6997,6 +6997,7 @@ qemu-kvm -net nic,model=3D? /dev/null <model type=3D'vga' vram=3D'16384' heads=3D'1'> <acceleration accel3d=3D'yes' accel2d=3D'yes'/> </model> + <driver name=3D'qemu'/> </video> </devices> ... @@ -7097,7 +7098,16 @@ qemu-kvm -net nic,model=3D? /dev/null
The subelement driver can be used to tune the device:
-
virtio options
+
name
+
+ Specify the backend driver to use, either "qemu" or + "vhostuser" depending on the hypervisor features available + (since 5.8.0). "qemu" is the + default QEMU backend. "vhostuser" will use a separate + vhost-user process backend (for virtio + device). +
+
virtio options
Virtio-specific options can also= be set (Since 3.5.0) diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng index cae3be639e..7006d9f508 100644 --- a/docs/schemas/domaincommon.rng +++ b/docs/schemas/domaincommon.rng @@ -3565,6 +3565,14 @@ + + + + qemu + vhostuser + + + diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 96e9223e21..6f81af2d4c 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -728,6 +728,13 @@ VIR_ENUM_IMPL(virDomainPanicModel, "s390", ); =20 +VIR_ENUM_IMPL(virDomainVideoBackend, + VIR_DOMAIN_VIDEO_BACKEND_TYPE_LAST, + "default", + "qemu", + "vhostuser", +); + VIR_ENUM_IMPL(virDomainVideo, VIR_DOMAIN_VIDEO_TYPE_LAST, "default", @@ -6262,6 +6269,23 @@ virDomainVideoDefValidate(const virDomainVideoDef *v= ideo, } } =20 + switch (video->backend) { + case VIR_DOMAIN_VIDEO_BACKEND_TYPE_VHOSTUSER: + if (video->type !=3D VIR_DOMAIN_VIDEO_TYPE_VIRTIO) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("'vhostuser' driver is only supported with 'v= irtio' device")); + return -1; + } + break; + case VIR_DOMAIN_VIDEO_BACKEND_TYPE_DEFAULT: + case VIR_DOMAIN_VIDEO_BACKEND_TYPE_QEMU: + break; + case VIR_DOMAIN_VIDEO_BACKEND_TYPE_LAST: + default: + virReportEnumRangeError(virDomainInputType, video->backend); + return -1; + } + return 0; } =20 @@ -15405,6 +15429,7 @@ virDomainVideoDefParseXML(virDomainXMLOptionPtr xml= opt, xmlNodePtr cur; VIR_XPATH_NODE_AUTORESTORE(ctxt); VIR_AUTOFREE(char *) type =3D NULL; + VIR_AUTOFREE(char *) driver_name =3D NULL; VIR_AUTOFREE(char *) heads =3D NULL; VIR_AUTOFREE(char *) vram =3D NULL; VIR_AUTOFREE(char *) vram64 =3D NULL; @@ -15440,6 +15465,7 @@ virDomainVideoDefParseXML(virDomainXMLOptionPtr xml= opt, if (virXMLNodeNameEqual(cur, "driver")) { if (virDomainVirtioOptionsParseXML(cur, &def->virtio) < 0) goto error; + driver_name =3D virXMLPropString(cur, "name"); } } cur =3D cur->next; @@ -15455,6 +15481,16 @@ virDomainVideoDefParseXML(virDomainXMLOptionPtr xm= lopt, def->type =3D virDomainVideoDefaultType(dom); } =20 + if (driver_name) { + if ((def->backend =3D virDomainVideoBackendTypeFromString(driver_n= ame)) < 0) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("unknown video driver '%s'"), driver_name); + goto error; + } + } else { + def->backend =3D VIR_DOMAIN_VIDEO_BACKEND_TYPE_DEFAULT; + } + if (ram) { if (def->type !=3D VIR_DOMAIN_VIDEO_TYPE_QXL) { virReportError(VIR_ERR_XML_ERROR, "%s", @@ -26522,13 +26558,17 @@ virDomainVideoDefFormat(virBufferPtr buf, virDomainVirtioOptionsFormat(&driverBuf, def->virtio); if (virBufferCheckError(&driverBuf) < 0) goto cleanup; - if (virBufferUse(&driverBuf) || (def->driver && def->driver->vgaconf))= { + if (virBufferUse(&driverBuf) || (def->driver && def->driver->vgaconf) = || + def->backend !=3D VIR_DOMAIN_VIDEO_BACKEND_TYPE_DEFAULT) { virBufferAddLit(buf, "driver && def->driver->vgaconf) virBufferAsprintf(buf, " vgaconf=3D'%s'", virDomainVideoVGAConfTypeToString(def->drive= r->vgaconf)); + if (def->backend !=3D VIR_DOMAIN_VIDEO_BACKEND_TYPE_DEFAULT) + virBufferAsprintf(buf, " name=3D'%s'", + virDomainVideoBackendTypeToString(def->backe= nd)); virBufferAddLit(buf, "/>\n"); } virBufferAsprintf(buf, "
Enable 3D acceleration (for vbox driver since 0.7.1, qemu driver since 1.3.0)
+ +
rendernode
+
Absolute path to a host's DRI device to be used for + rendering (for 'vhostuser' driver only, since 5.8.0). If none is specified, + libvirt will pick one available.
=20 diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng index 7006d9f508..40eb4a2d75 100644 --- a/docs/schemas/domaincommon.rng +++ b/docs/schemas/domaincommon.rng @@ -3648,6 +3648,11 @@ + + + + + diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 6f81af2d4c..15fb8dea17 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -2840,6 +2840,8 @@ virDomainVideoDefClear(virDomainVideoDefPtr def) =20 virDomainDeviceInfoClear(&def->info); =20 + if (def->accel) + VIR_FREE(def->accel->rendernode); VIR_FREE(def->accel); VIR_FREE(def->virtio); VIR_FREE(def->driver); @@ -6279,6 +6281,11 @@ virDomainVideoDefValidate(const virDomainVideoDef *v= ideo, break; case VIR_DOMAIN_VIDEO_BACKEND_TYPE_DEFAULT: case VIR_DOMAIN_VIDEO_BACKEND_TYPE_QEMU: + if (video->accel && video->accel->rendernode) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("unsupported rendernode accel attribute witho= ut 'vhostuser'")); + return -1; + } break; case VIR_DOMAIN_VIDEO_BACKEND_TYPE_LAST: default: @@ -15341,6 +15348,7 @@ virDomainVideoAccelDefParseXML(xmlNodePtr node) int val; VIR_AUTOFREE(char *) accel2d =3D NULL; VIR_AUTOFREE(char *) accel3d =3D NULL; + VIR_AUTOFREE(char *) rendernode =3D NULL; =20 cur =3D node->children; while (cur !=3D NULL) { @@ -15349,12 +15357,13 @@ virDomainVideoAccelDefParseXML(xmlNodePtr node) virXMLNodeNameEqual(cur, "acceleration")) { accel3d =3D virXMLPropString(cur, "accel3d"); accel2d =3D virXMLPropString(cur, "accel2d"); + rendernode =3D virXMLPropString(cur, "rendernode"); } } cur =3D cur->next; } =20 - if (!accel3d && !accel2d) + if (!accel3d && !accel2d && !rendernode) return NULL; =20 if (VIR_ALLOC(def) < 0) @@ -15378,6 +15387,8 @@ virDomainVideoAccelDefParseXML(xmlNodePtr node) def->accel2d =3D val; } =20 + VIR_STEAL_PTR(def->rendernode, rendernode); + cleanup: return def; } @@ -26535,6 +26546,10 @@ virDomainVideoAccelDefFormat(virBufferPtr buf, virBufferAsprintf(buf, " accel2d=3D'%s'", virTristateBoolTypeToString(def->accel2d)); } + if (def->rendernode) { + virBufferAsprintf(buf, " rendernode=3D'%s'", + def->rendernode); + } virBufferAddLit(buf, "/>\n"); } =20 diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 7d60f3054c..16dacd4b43 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -1417,6 +1417,7 @@ VIR_ENUM_DECL(virDomainVideoVGAConf); struct _virDomainVideoAccelDef { int accel2d; /* enum virTristateBool */ int accel3d; /* enum virTristateBool */ + char *rendernode; }; =20 =20 diff --git a/tests/qemuxml2argvdata/virtio-options.xml b/tests/qemuxml2argv= data/virtio-options.xml index bdfadca22d..dd9a4f4a01 100644 --- a/tests/qemuxml2argvdata/virtio-options.xml +++ b/tests/qemuxml2argvdata/virtio-options.xml @@ -75,7 +75,7 @@