From nobody Sun May 19 13:54:46 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.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 216.205.24.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=1625654859; cv=none; d=zohomail.com; s=zohoarc; b=IVVoqXDxsn+mMI4o4qXS3W39sWH+LBr7DvPQARgw+C32bUP5lYGRtlaIbRo9ltku9k0QgtKzeOtDZ4YJfYJuQeOTlvWkaeS0n1D7G4Ya95vH9IfVj/u9ojlGW/nbq6c6cxox/XA/YAkANwasCI8POcxJgehI85x+gxPmTmBeElU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1625654859; 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=7/YWAX4cxGylvB35/Bw0f9LoPPm7O6bMvzd5d9joD6A=; b=VKi5IOPYkNo6RbHCorXKvX4t78liKDSmcE0YJMj2RjQki4lP1ke2v2KCYzbQTvDGeVjIijmOB1XDNA1yM1p8Hz0wkwdTF2rNkTnS0bzMRBaPyFUnFf8Ky3djBBc2CZP3pK/JnnOgmuPwUSZGVjwXwugJ9RPXQQUFd8Im0QaMG1c= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.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 [216.205.24.124]) by mx.zohomail.com with SMTPS id 1625654859595462.2153958707172; Wed, 7 Jul 2021 03:47:39 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-459-FUOXnmdjNjKtfBdY3rRqZQ-1; Wed, 07 Jul 2021 06:47:37 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 72DC081C85F; Wed, 7 Jul 2021 10:47:31 +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 66E365D6AB; Wed, 7 Jul 2021 10:47:30 +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 97E5E1809C99; Wed, 7 Jul 2021 10:47:28 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 167AlRFk022742 for ; Wed, 7 Jul 2021 06:47:27 -0400 Received: by smtp.corp.redhat.com (Postfix) id 95C1C1036D20; Wed, 7 Jul 2021 10:47:27 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.40.192.144]) by smtp.corp.redhat.com (Postfix) with ESMTP id 08EFB100EBAF for ; Wed, 7 Jul 2021 10:47:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1625654858; 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=7/YWAX4cxGylvB35/Bw0f9LoPPm7O6bMvzd5d9joD6A=; b=XxQpIy/VHMN1LZih97gIDd1hz2Dr9PnWGXf9YA2om4x1vp9+RoM6ZgRPCD/IhDa/cpPLyr ARmIic0nM0mNUUJk8ZdGhIXa2imEA9Is3q7r/aGrAsvjEb6MymjkKoDU2TxzEAkUvyiouy CiCrDjFHrQzN9Cuvj7CsDxEnFrEz2vw= X-MC-Unique: FUOXnmdjNjKtfBdY3rRqZQ-1 From: Kristina Hanicova To: libvir-list@redhat.com Subject: [PATCH 1/2] qemu: Check for existing file in namespace Date: Wed, 7 Jul 2021 12:46:51 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com 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: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com 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: 1625654861152100001 Content-Type: text/plain; charset="utf-8" Signed-off-by: Kristina Hanicova --- src/qemu/qemu_namespace.c | 24 ++++++++++++++---------- src/util/virprocess.c | 6 ++++-- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/src/qemu/qemu_namespace.c b/src/qemu/qemu_namespace.c index 98495e8ef8..154968acbd 100644 --- a/src/qemu/qemu_namespace.c +++ b/src/qemu/qemu_namespace.c @@ -929,6 +929,10 @@ qemuNamespaceMknodOne(qemuNamespaceMknodItem *data) bool isDev =3D S_ISCHR(data->sb.st_mode) || S_ISBLK(data->sb.st_mode); bool isReg =3D S_ISREG(data->sb.st_mode) || S_ISFIFO(data->sb.st_mode)= || S_ISSOCK(data->sb.st_mode); bool isDir =3D S_ISDIR(data->sb.st_mode); + int file_exists =3D 0; + + if (virFileExists(data->file)) + file_exists =3D 1; =20 if (virFileMakeParentPath(data->file) < 0) { virReportSystemError(errno, @@ -1039,7 +1043,7 @@ qemuNamespaceMknodOne(qemuNamespaceMknodItem *data) virFileMoveMount(data->target, data->file) < 0) goto cleanup; =20 - ret =3D 0; + ret =3D file_exists; cleanup: if (ret < 0 && delDevice) { if (isDir) @@ -1069,15 +1073,19 @@ qemuNamespaceMknodHelper(pid_t pid G_GNUC_UNUSED, qemuNamespaceMknodData *data =3D opaque; size_t i; int ret =3D -1; + int file_existed =3D 0; =20 qemuSecurityPostFork(data->driver->securityManager); =20 for (i =3D 0; i < data->nitems; i++) { - if (qemuNamespaceMknodOne(&data->items[i]) < 0) + int rc =3D 0; + + if ((rc =3D qemuNamespaceMknodOne(&data->items[i])) < 0) goto cleanup; + file_existed =3D file_existed || rc; } =20 - ret =3D 0; + ret =3D file_existed; cleanup: qemuNamespaceMknodDataClear(data); return ret; @@ -1270,15 +1278,11 @@ qemuNamespaceMknodPaths(virDomainObj *vm, if (qemuSecurityPreFork(driver->securityManager) < 0) goto cleanup; =20 - if (virProcessRunInMountNamespace(vm->pid, - qemuNamespaceMknodHelper, - &data) < 0) { - qemuSecurityPostFork(driver->securityManager); - goto cleanup; - } + ret =3D virProcessRunInMountNamespace(vm->pid, qemuNamespaceMknodHelpe= r, + &data); + qemuSecurityPostFork(driver->securityManager); =20 - ret =3D 0; cleanup: for (i =3D 0; i < data.nitems; i++) { if (data.items[i].bindmounted && diff --git a/src/util/virprocess.c b/src/util/virprocess.c index 01d5d01d02..49aef75779 100644 --- a/src/util/virprocess.c +++ b/src/util/virprocess.c @@ -1298,7 +1298,9 @@ virProcessRunInForkHelper(int errfd, virProcessForkCallback cb, void *opaque) { - if (cb(ppid, opaque) < 0) { + int ret =3D 0; + + if ((ret =3D cb(ppid, opaque)) < 0) { virErrorPtr err =3D virGetLastError(); =20 if (err) { @@ -1323,7 +1325,7 @@ virProcessRunInForkHelper(int errfd, return -1; } =20 - return 0; + return ret; } =20 =20 --=20 2.31.1 From nobody Sun May 19 13:54:46 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.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 216.205.24.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=1625654870; cv=none; d=zohomail.com; s=zohoarc; b=fxt7HGXD96BLR/kr8izl9sG0vdRl0gs85EEP/uyH7QsoQ2PKbrphU/fZFQ+SfIZjmuyZZdavQrsz25vITL0uKHp5ERK35Qm969QrLGUUCeJtlNQ8Rp6JxmhCsCBbc2oIQvzCRYgNcCfY2akPohP392EJMiTtC2yRqkWDPs9V2TA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1625654870; 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=2t8UxRRNZ0PAPkcSXNWZIhZh2m/T1/bE3BmH0Ejdjlg=; b=IVDHV28dzbTzAEX5Xabq9L1w7tTBLGxe4eIA5rVlgg8jc5DXED07vtvaMV06FEZZC0b7Qilhs1zNNEBRPtoRjQTtl31rnYBe1wfSOBQx69WauLhxvNveH/+0dCfB7U2qa544VMnzygvlIjf4qZVTr/OB+vRwnZU+70m31GSv/cQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.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 [216.205.24.124]) by mx.zohomail.com with SMTPS id 1625654870893278.8672847595715; Wed, 7 Jul 2021 03:47:50 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-199-D5k3kZrQMuqlmmp3-mmw0A-1; Wed, 07 Jul 2021 06:47:48 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 01EE1101F003; Wed, 7 Jul 2021 10:47:43 +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 D6CCB5D9FC; Wed, 7 Jul 2021 10:47:42 +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 A34DA4EA38; Wed, 7 Jul 2021 10:47:42 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 167AlSA9022750 for ; Wed, 7 Jul 2021 06:47:28 -0400 Received: by smtp.corp.redhat.com (Postfix) id 913C91036D20; Wed, 7 Jul 2021 10:47:28 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.40.192.144]) by smtp.corp.redhat.com (Postfix) with ESMTP id F40F7100EBAF for ; Wed, 7 Jul 2021 10:47:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1625654869; 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=2t8UxRRNZ0PAPkcSXNWZIhZh2m/T1/bE3BmH0Ejdjlg=; b=Qz71cShoKjcWu3ntjaBZh0oZ5VVyVjZB6x4MOtDkl5ZT7Te8fhOwWSAFWSSd5YJ1fn9cpo oUVBi868K+IQTkavMwzNTsfzV5RrxaHvQ5/gq8hN0DBf4TBw/MzE6khNw48ubzqPqMLTTh +BvWuRyknw/ycnZQ7yK+n09Fc3kFRTA= X-MC-Unique: D5k3kZrQMuqlmmp3-mmw0A-1 From: Kristina Hanicova To: libvir-list@redhat.com Subject: [PATCH 2/2] qemu: Do not erase input device from namespace if duplicate Date: Wed, 7 Jul 2021 12:46:52 +0200 Message-Id: <5718a7c5d20e94dc9b00c3350bdb8dc15a6e80b5.1625654575.git.khanicov@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com 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: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com 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: 1625654872048100001 Content-Type: text/plain; charset="utf-8" Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=3D1780508 Signed-off-by: Kristina Hanicova --- src/qemu/qemu_hotplug.c | 3 +-- src/qemu/qemu_namespace.c | 10 ++++++++-- src/qemu/qemu_namespace.h | 3 ++- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index d2a354d026..7002623924 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -3225,9 +3225,8 @@ qemuDomainAttachInputDevice(virQEMUDriver *driver, if (qemuBuildInputDevStr(&devstr, vm->def, input, priv->qemuCaps) < 0) goto cleanup; =20 - if (qemuDomainNamespaceSetupInput(vm, input) < 0) + if (qemuDomainNamespaceSetupInput(vm, input, &teardowndevice) < 0) goto cleanup; - teardowndevice =3D true; =20 if (qemuSetupInputCgroup(vm, input) < 0) goto cleanup; diff --git a/src/qemu/qemu_namespace.c b/src/qemu/qemu_namespace.c index 154968acbd..22bdda229a 100644 --- a/src/qemu/qemu_namespace.c +++ b/src/qemu/qemu_namespace.c @@ -1600,9 +1600,11 @@ qemuDomainNamespaceTeardownRNG(virDomainObj *vm, =20 int qemuDomainNamespaceSetupInput(virDomainObj *vm, - virDomainInputDef *input) + virDomainInputDef *input, + bool *created) { g_autoptr(virGSListString) paths =3D NULL; + int ret =3D 0; =20 if (!qemuDomainNamespaceEnabled(vm, QEMU_DOMAIN_NS_MOUNT)) return 0; @@ -1610,8 +1612,12 @@ qemuDomainNamespaceSetupInput(virDomainObj *vm, if (qemuDomainSetupInput(input, &paths) < 0) return -1; =20 - if (qemuNamespaceMknodPaths(vm, paths) < 0) + if ((ret =3D qemuNamespaceMknodPaths(vm, paths)) < 0) return -1; + + if (ret =3D=3D 0) + *created =3D true; + return 0; } =20 diff --git a/src/qemu/qemu_namespace.h b/src/qemu/qemu_namespace.h index 771d7873ef..5d9af123a9 100644 --- a/src/qemu/qemu_namespace.h +++ b/src/qemu/qemu_namespace.h @@ -80,7 +80,8 @@ int qemuDomainNamespaceTeardownRNG(virDomainObj *vm, virDomainRNGDef *rng); =20 int qemuDomainNamespaceSetupInput(virDomainObj *vm, - virDomainInputDef *input); + virDomainInputDef *input, + bool *created); =20 int qemuDomainNamespaceTeardownInput(virDomainObj *vm, virDomainInputDef *input); --=20 2.31.1