From nobody Tue May 7 15:36:28 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.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.133.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=1626274089; cv=none; d=zohomail.com; s=zohoarc; b=SGZHnCmblztlDDyejM68qIUjo81ZBd8GQ3bhXUkBg5WVVF20nztbkR3mpLwTI6HgCS0Pqw9eb4aiLY4/x4YcrkbHuVhSE4nA6dstOd55bU6pml6J/Px2hFvinVd9mgk5IxF5iLeyB5hn0naYD3oTm8SBYaeXj54Dn5/sVM9+2gE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1626274089; 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=PSlry0vR+k5rCND8sLRrQpDswEQXhy7xaBfECOcfdx4=; b=XYe+FnQr17dGj2IJGgxdix+ZWnblc5oog8o6aK1OtSB86z6OtygQJmDbMW0But7eLdx/q0QBqAZHRXqBhUmYdhATnU49w4Zk46mlKNhx8GxAOo0Wa1V0tliKw8oZ6tu+TbJGC7UHez02MnZzg2tam/LZMVrHtE7YScEFdiLPLjA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.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.133.124]) by mx.zohomail.com with SMTPS id 1626274089545793.892127329142; Wed, 14 Jul 2021 07:48:09 -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-37-Vvwb80hBOUqfFM0vwEW6JA-1; Wed, 14 Jul 2021 10:47:44 -0400 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 0BA54102C87E; Wed, 14 Jul 2021 14:47:23 +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 64EEA69327; Wed, 14 Jul 2021 14:47:22 +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 F23A64EA37; Wed, 14 Jul 2021 14:47:21 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 16EElEQT007364 for ; Wed, 14 Jul 2021 10:47:14 -0400 Received: by smtp.corp.redhat.com (Postfix) id ED01578DE1; Wed, 14 Jul 2021 14:47:13 +0000 (UTC) Received: from 48-A4-72-0B-E8-25.redhat.com (unknown [10.40.195.93]) by smtp.corp.redhat.com (Postfix) with ESMTP id D2F487B014 for ; Wed, 14 Jul 2021 14:47:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1626274088; 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=PSlry0vR+k5rCND8sLRrQpDswEQXhy7xaBfECOcfdx4=; b=VCpQg0QPm612OUGABEuetnWkpnUghHbj5kohm5AahovuxVWJIQ9Qeibxv7iO9XPuyxJ+KV 3CnCEfdzIkvn94ZSKHmh7OotaPu0f7AQTc2C4rBhOA/dxqxS206IA37lnx+UO6LzjlVcmM kIfcYyKf2R8nJ0ycnZNGG3lRJBKa4/4= X-MC-Unique: Vvwb80hBOUqfFM0vwEW6JA-1 From: Kristina Hanicova To: libvir-list@redhat.com Subject: [PATCH v2 1/3] qemu: Check for existing file in namespace Date: Wed, 14 Jul 2021 16:46:52 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 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.16 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: 1626274090605100001 Content-Type: text/plain; charset="utf-8" Signed-off-by: Kristina Hanicova Reviewed-by: Michal Privoznik --- src/qemu/qemu_namespace.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/qemu/qemu_namespace.c b/src/qemu/qemu_namespace.c index 98495e8ef8..eb048a2faa 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); + bool exists =3D false; + + if (virFileExists(data->file)) + exists =3D true; =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 exists ? 1 : 0; cleanup: if (ret < 0 && delDevice) { if (isDir) @@ -1069,15 +1073,21 @@ qemuNamespaceMknodHelper(pid_t pid G_GNUC_UNUSED, qemuNamespaceMknodData *data =3D opaque; size_t i; int ret =3D -1; + bool exists =3D false; =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; + + if (rc > 0) + exists =3D true; } =20 - ret =3D 0; + ret =3D exists ? 1 : 0; cleanup: qemuNamespaceMknodDataClear(data); return ret; --=20 2.31.1 From nobody Tue May 7 15:36:28 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=1626274057; cv=none; d=zohomail.com; s=zohoarc; b=PUwHwawO3Mgcd0/mbwx/f2iG/iSw2auTf2Kp2TK5qyF/DnckGcGjKmuajGMBKVtMwN8U4GjN3OnY7Br9NgDCvfv4NLLACnfDVWk0xkPIn1jjCpN3bySVFeWKW+y7kOKVgopYIcoHFw4QuM2ayJijnz2ttYERcNv3rkX9l7Jcv2k= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1626274057; 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=mf6lZUpcafa+iWl1d+BeZiZCPYanHOk4BiPYtyJJoKY=; b=ZZXACAjElyRKxoJ4qOSpZPE24XfPeNWRrEmEB47JtAliZNzE4CJM6DOpsMlwkPYTwOowEqzRp1q5z7RqCvRp81swJj1QEFhFsBiYT6LTwF9UIcAs6Yuhl/6Ht9k9hho59oqQgtdUnY+nLaHaFloWAyXpoVSMQIhqTmky+85+YoI= 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 1626274057283845.5471170106822; Wed, 14 Jul 2021 07:47:37 -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-161-q8b0nYxpOmeaOVSV8WdcOg-1; Wed, 14 Jul 2021 10:47:34 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E6E6A871234; Wed, 14 Jul 2021 14:47:17 +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 C2E4660C9F; Wed, 14 Jul 2021 14:47:17 +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 8BA724EA2A; Wed, 14 Jul 2021 14:47:17 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 16EElFUr007376 for ; Wed, 14 Jul 2021 10:47:16 -0400 Received: by smtp.corp.redhat.com (Postfix) id 959377E133; Wed, 14 Jul 2021 14:47:15 +0000 (UTC) Received: from 48-A4-72-0B-E8-25.redhat.com (unknown [10.40.195.93]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2F57278DFA for ; Wed, 14 Jul 2021 14:47:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1626274055; 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=mf6lZUpcafa+iWl1d+BeZiZCPYanHOk4BiPYtyJJoKY=; b=MAnaUVcxlm4SV1q/VUN226FwRHTWJ29AHdtoew9zUvtCci/w6p74AhXZqQhit+H1JhKCB+ qIP3IoeVDS8uwjATbHa3oLdASBKRMtgjaCZJYjL4kRx9ZfUAK+rgPN+ReG50RFJTCcaUSH Deqdsulh/QWBvdcFiQtWsrHjocXG/vE= X-MC-Unique: q8b0nYxpOmeaOVSV8WdcOg-1 From: Kristina Hanicova To: libvir-list@redhat.com Subject: [PATCH v2 2/3] virprocess: Return retval of the child on success, not 0 Date: Wed, 14 Jul 2021 16:46:53 +0200 Message-Id: <8a964d0ece08cffd5e57f37ca48d0092fec14eb6.1626270217.git.khanicov@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 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.12 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: 1626274058196100001 Content-Type: text/plain; charset="utf-8" Signed-off-by: Kristina Hanicova Reviewed-by: Michal Privoznik --- src/util/virprocess.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/util/virprocess.c b/src/util/virprocess.c index 01d5d01d02..67dd599b3e 100644 --- a/src/util/virprocess.c +++ b/src/util/virprocess.c @@ -1244,7 +1244,7 @@ static int virProcessNamespaceHelper(pid_t pid G_GNUC= _UNUSED, /* Run cb(opaque) in the mount namespace of pid. Return -1 with error * message raised if we fail to run the child, if the child dies from * a signal, or if the child has status EXIT_CANCELED; otherwise return - * the exit status of the child. The callback will be run in a child + * value is the retval of the callback. The callback will be run in a child * process so must be careful to only use async signal safe functions. */ int @@ -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 @@ -1344,7 +1346,7 @@ virProcessRunInForkHelper(int errfd, * On return, the returned value is either -1 with error message * reported if something went bad in the parent, if child has * died from a signal or if the child returned EXIT_CANCELED. - * Otherwise the returned value is the exit status of the child. + * Otherwise the returned value is the retval of the callback. */ int virProcessRunInFork(virProcessForkCallback cb, @@ -1377,7 +1379,7 @@ virProcessRunInFork(virProcessForkCallback cb, ret =3D virProcessWait(child, &status, false); if (ret =3D=3D 0) { ret =3D status =3D=3D EXIT_CANCELED ? -1 : status; - if (ret) { + if (ret < 0) { if (nread =3D=3D sizeof(*bin)) { bin =3D g_new0(errorDataBin, 1); memcpy(bin->bindata, buf, sizeof(*bin)); --=20 2.31.1 From nobody Tue May 7 15:36:28 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.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.133.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=1626274061; cv=none; d=zohomail.com; s=zohoarc; b=DWB9Dl3cNzu0bzyIYJ4Fb2mBokh4Vem7C9LiuieZikmK8pEPW56bOvyk3LsX82un5px4UpEd2YSwpa9AyOeGS/corK0V3Bmh9N4VjIvf4N7wfldKHQadQN52DjVpEo8bg96y3EbwRbB4h5zOjHTKU9mZCPmAVloO7Dxeebjzna4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1626274061; 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=rDFL7su+b1nd5TBp2o++8UEdUrbNDCbbJhs6/8nIZW0=; b=LLXBS3XN/PJn9osQiMaTr/zpiTpb7DqOu603+cgcCOPbw1iVHTnMEOTOK7ykAIOi1KgZIXPQCCkgMBaKfulz9f0/p5od96NMHdex8FEi55XbjT4ie1AO62yKK5Mv1C0eiS4UNAsAt6Z9wVCSxPuEkaP5FNboTGiG7jD65kEzyN0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.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.133.124]) by mx.zohomail.com with SMTPS id 1626274061763852.0140418402544; Wed, 14 Jul 2021 07:47:41 -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-492-V95WnnX2OV-J4qZ_TWxNgw-1; Wed, 14 Jul 2021 10:47:38 -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 73AC1192FDCA; Wed, 14 Jul 2021 14:47:25 +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 4EAF85DA61; Wed, 14 Jul 2021 14:47:25 +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 143EC1809C9A; Wed, 14 Jul 2021 14:47:25 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 16EElHGY007386 for ; Wed, 14 Jul 2021 10:47:17 -0400 Received: by smtp.corp.redhat.com (Postfix) id 270DE60CA1; Wed, 14 Jul 2021 14:47:17 +0000 (UTC) Received: from 48-A4-72-0B-E8-25.redhat.com (unknown [10.40.195.93]) by smtp.corp.redhat.com (Postfix) with ESMTP id CEE087FCEA for ; Wed, 14 Jul 2021 14:47:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1626274060; 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=rDFL7su+b1nd5TBp2o++8UEdUrbNDCbbJhs6/8nIZW0=; b=ctbWP0Fog4+9N8eKzIpo3hk7oUYyczspi+P7CkkEPVqmq2MP2PYGRBwobFgCexD/ktqVEC AIhvj2+SKz/lTrhB89EMNWmi7k2uTDvkruZC0xP3JGYXLfSmvJKKG/mtl9Gb5CSN3pZQyL FPZBuN9fTPej+Y2zocxfRN9I7WcTSfg= X-MC-Unique: V95WnnX2OV-J4qZ_TWxNgw-1 From: Kristina Hanicova To: libvir-list@redhat.com Subject: [PATCH v2 3/3] qemu: Do not erase duplicate devices from namespace if error occurs Date: Wed, 14 Jul 2021 16:46:54 +0200 Message-Id: <1890a680fcf1a7fcf30141abf337a447defbe25d.1626270217.git.khanicov@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 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: 1626274062319100002 Content-Type: text/plain; charset="utf-8" If the attempt to attach a device failed, we erased the unattached device from the namespace. This resulted in erasing an already attached device in case of a duplicate. We need to check for existing file in the namespace in order to determine erasing it in case of a failure. Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=3D1780508 Signed-off-by: Kristina Hanicova Reviewed-by: Michal Privoznik --- src/qemu/qemu_domain.c | 4 +-- src/qemu/qemu_hotplug.c | 27 +++++++------------ src/qemu/qemu_namespace.c | 55 +++++++++++++++++++++++---------------- src/qemu/qemu_namespace.h | 18 ++++++++----- src/qemu/qemu_process.c | 2 +- 5 files changed, 55 insertions(+), 51 deletions(-) diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 89e03fdf72..ac1d8ef151 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -7934,10 +7934,8 @@ qemuDomainStorageSourceAccessModify(virQEMUDriver *d= river, =20 revoke_nvme =3D true; =20 - if (qemuDomainNamespaceSetupDisk(vm, src) < 0) + if (qemuDomainNamespaceSetupDisk(vm, src, &revoke_namespace) < 0) goto revoke; - - revoke_namespace =3D true; } =20 if (qemuSecuritySetImageLabel(driver, vm, src, chain, chain_top) < 0) diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index cb6a4e4ea5..6743a8a742 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -1685,9 +1685,8 @@ qemuDomainAttachHostPCIDevice(virQEMUDriver *driver, goto error; teardownmemlock =3D true; =20 - if (qemuDomainNamespaceSetupHostdev(vm, hostdev) < 0) + if (qemuDomainNamespaceSetupHostdev(vm, hostdev, &teardowndevice) < 0) goto error; - teardowndevice =3D true; =20 if (qemuSetupHostdevCgroup(vm, hostdev) < 0) goto error; @@ -2219,9 +2218,8 @@ int qemuDomainAttachChrDevice(virQEMUDriver *driver, if (rc =3D=3D 1) need_release =3D true; =20 - if (qemuDomainNamespaceSetupChardev(vm, chr) < 0) + if (qemuDomainNamespaceSetupChardev(vm, chr, &teardowndevice) < 0) goto cleanup; - teardowndevice =3D true; =20 if (qemuSecuritySetChardevLabel(driver, vm, chr) < 0) goto cleanup; @@ -2332,9 +2330,8 @@ qemuDomainAttachRNGDevice(virQEMUDriver *driver, if (qemuDomainEnsureVirtioAddress(&releaseaddr, vm, &dev) < 0) return -1; =20 - if (qemuDomainNamespaceSetupRNG(vm, rng) < 0) + if (qemuDomainNamespaceSetupRNG(vm, rng, &teardowndevice) < 0) goto cleanup; - teardowndevice =3D true; =20 if (qemuSetupRNGCgroup(vm, rng) < 0) goto cleanup; @@ -2476,9 +2473,8 @@ qemuDomainAttachMemory(virQEMUDriver *driver, if (qemuProcessBuildDestroyMemoryPaths(driver, vm, mem, true) < 0) goto cleanup; =20 - if (qemuDomainNamespaceSetupMemory(vm, mem) < 0) + if (qemuDomainNamespaceSetupMemory(vm, mem, &teardowndevice) < 0) goto cleanup; - teardowndevice =3D true; =20 if (qemuSetupMemoryDevicesCgroup(vm, mem) < 0) goto cleanup; @@ -2592,9 +2588,8 @@ qemuDomainAttachHostUSBDevice(virQEMUDriver *driver, =20 added =3D true; =20 - if (qemuDomainNamespaceSetupHostdev(vm, hostdev) < 0) + if (qemuDomainNamespaceSetupHostdev(vm, hostdev, &teardowndevice) < 0) goto cleanup; - teardowndevice =3D true; =20 if (qemuSetupHostdevCgroup(vm, hostdev) < 0) goto cleanup; @@ -2673,9 +2668,8 @@ qemuDomainAttachHostSCSIDevice(virQEMUDriver *driver, if (qemuHostdevPrepareSCSIDevices(driver, vm->def->name, &hostdev, 1) = < 0) return -1; =20 - if (qemuDomainNamespaceSetupHostdev(vm, hostdev) < 0) + if (qemuDomainNamespaceSetupHostdev(vm, hostdev, &teardowndevice) < 0) goto cleanup; - teardowndevice =3D true; =20 if (qemuSetupHostdevCgroup(vm, hostdev) < 0) goto cleanup; @@ -2767,9 +2761,8 @@ qemuDomainAttachSCSIVHostDevice(virQEMUDriver *driver, if (qemuHostdevPrepareSCSIVHostDevices(driver, vm->def->name, &hostdev= , 1) < 0) return -1; =20 - if (qemuDomainNamespaceSetupHostdev(vm, hostdev) < 0) + if (qemuDomainNamespaceSetupHostdev(vm, hostdev, &teardowndevice) < 0) goto cleanup; - teardowndevice =3D true; =20 if (qemuSetupHostdevCgroup(vm, hostdev) < 0) goto cleanup; @@ -2894,9 +2887,8 @@ qemuDomainAttachMediatedDevice(virQEMUDriver *driver, goto cleanup; added =3D true; =20 - if (qemuDomainNamespaceSetupHostdev(vm, hostdev) < 0) + if (qemuDomainNamespaceSetupHostdev(vm, hostdev, &teardowndevice) < 0) goto cleanup; - teardowndevice =3D true; =20 if (qemuSetupHostdevCgroup(vm, hostdev) < 0) goto cleanup; @@ -3231,9 +3223,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 eb048a2faa..46ee95b8c8 100644 --- a/src/qemu/qemu_namespace.c +++ b/src/qemu/qemu_namespace.c @@ -610,7 +610,8 @@ qemuDomainSetupLaunchSecurity(virDomainObj *vm, =20 static int qemuNamespaceMknodPaths(virDomainObj *vm, - GSList *paths); + GSList *paths, + bool *created); =20 =20 int @@ -657,7 +658,7 @@ qemuDomainBuildNamespace(virQEMUDriverConfig *cfg, if (qemuDomainSetupLaunchSecurity(vm, &paths) < 0) return -1; =20 - if (qemuNamespaceMknodPaths(vm, paths) < 0) + if (qemuNamespaceMknodPaths(vm, paths, NULL) < 0) return -1; =20 return 0; @@ -1235,7 +1236,8 @@ qemuNamespacePrepareOneItem(qemuNamespaceMknodData *d= ata, =20 static int qemuNamespaceMknodPaths(virDomainObj *vm, - GSList *paths) + GSList *paths, + bool *created) { qemuDomainObjPrivate *priv =3D vm->privateData; virQEMUDriver *driver =3D priv->driver; @@ -1280,15 +1282,13 @@ 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); + if (ret =3D=3D 0 && created !=3D NULL) + *created =3D true; + qemuSecurityPostFork(driver->securityManager); =20 - ret =3D 0; cleanup: for (i =3D 0; i < data.nitems; i++) { if (data.items[i].bindmounted && @@ -1307,7 +1307,8 @@ qemuNamespaceMknodPaths(virDomainObj *vm, =20 static int qemuNamespaceMknodPaths(virDomainObj *vm G_GNUC_UNUSED, - GSList *paths G_GNUC_UNUSED) + GSList *paths G_GNUC_UNUSED, + bool *created G_GNUC_UNUSED) { virReportSystemError(ENOSYS, "%s", _("Namespaces are not supported on this platform.= ")); @@ -1393,7 +1394,8 @@ qemuNamespaceUnlinkPaths(virDomainObj *vm, =20 int qemuDomainNamespaceSetupDisk(virDomainObj *vm, - virStorageSource *src) + virStorageSource *src, + bool *created) { g_autoptr(virGSListString) paths =3D NULL; =20 @@ -1403,7 +1405,7 @@ qemuDomainNamespaceSetupDisk(virDomainObj *vm, if (qemuDomainSetupDisk(src, &paths) < 0) return -1; =20 - if (qemuNamespaceMknodPaths(vm, paths) < 0) + if (qemuNamespaceMknodPaths(vm, paths, created) < 0) return -1; =20 return 0; @@ -1437,7 +1439,8 @@ qemuDomainNamespaceTeardownDisk(virDomainObj *vm G_GN= UC_UNUSED, */ int qemuDomainNamespaceSetupHostdev(virDomainObj *vm, - virDomainHostdevDef *hostdev) + virDomainHostdevDef *hostdev, + bool *created) { g_autoptr(virGSListString) paths =3D NULL; =20 @@ -1450,7 +1453,7 @@ qemuDomainNamespaceSetupHostdev(virDomainObj *vm, &paths) < 0) return -1; =20 - if (qemuNamespaceMknodPaths(vm, paths) < 0) + if (qemuNamespaceMknodPaths(vm, paths, created) < 0) return -1; =20 return 0; @@ -1492,7 +1495,8 @@ qemuDomainNamespaceTeardownHostdev(virDomainObj *vm, =20 int qemuDomainNamespaceSetupMemory(virDomainObj *vm, - virDomainMemoryDef *mem) + virDomainMemoryDef *mem, + bool *created) { g_autoptr(virGSListString) paths =3D NULL; =20 @@ -1502,7 +1506,7 @@ qemuDomainNamespaceSetupMemory(virDomainObj *vm, if (qemuDomainSetupMemory(mem, &paths) < 0) return -1; =20 - if (qemuNamespaceMknodPaths(vm, paths) < 0) + if (qemuNamespaceMknodPaths(vm, paths, created) < 0) return -1; =20 return 0; @@ -1530,7 +1534,8 @@ qemuDomainNamespaceTeardownMemory(virDomainObj *vm, =20 int qemuDomainNamespaceSetupChardev(virDomainObj *vm, - virDomainChrDef *chr) + virDomainChrDef *chr, + bool *created) { g_autoptr(virGSListString) paths =3D NULL; =20 @@ -1540,7 +1545,7 @@ qemuDomainNamespaceSetupChardev(virDomainObj *vm, if (qemuDomainSetupChardev(vm->def, chr, &paths) < 0) return -1; =20 - if (qemuNamespaceMknodPaths(vm, paths) < 0) + if (qemuNamespaceMknodPaths(vm, paths, created) < 0) return -1; =20 return 0; @@ -1568,7 +1573,8 @@ qemuDomainNamespaceTeardownChardev(virDomainObj *vm, =20 int qemuDomainNamespaceSetupRNG(virDomainObj *vm, - virDomainRNGDef *rng) + virDomainRNGDef *rng, + bool *created) { g_autoptr(virGSListString) paths =3D NULL; =20 @@ -1578,7 +1584,7 @@ qemuDomainNamespaceSetupRNG(virDomainObj *vm, if (qemuDomainSetupRNG(rng, &paths) < 0) return -1; =20 - if (qemuNamespaceMknodPaths(vm, paths) < 0) + if (qemuNamespaceMknodPaths(vm, paths, created) < 0) return -1; =20 return 0; @@ -1606,9 +1612,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; @@ -1616,8 +1624,9 @@ qemuDomainNamespaceSetupInput(virDomainObj *vm, if (qemuDomainSetupInput(input, &paths) < 0) return -1; =20 - if (qemuNamespaceMknodPaths(vm, paths) < 0) + if ((ret =3D qemuNamespaceMknodPaths(vm, paths, created)) < 0) return -1; + return 0; } =20 diff --git a/src/qemu/qemu_namespace.h b/src/qemu/qemu_namespace.h index 771d7873ef..020aca13d8 100644 --- a/src/qemu/qemu_namespace.h +++ b/src/qemu/qemu_namespace.h @@ -50,37 +50,43 @@ void qemuDomainDestroyNamespace(virQEMUDriver *driver, bool qemuDomainNamespaceAvailable(qemuDomainNamespace ns); =20 int qemuDomainNamespaceSetupDisk(virDomainObj *vm, - virStorageSource *src); + virStorageSource *src, + bool *created); =20 int qemuDomainNamespaceTeardownDisk(virDomainObj *vm, virStorageSource *src); =20 int qemuDomainNamespaceSetupHostdev(virDomainObj *vm, - virDomainHostdevDef *hostdev); + virDomainHostdevDef *hostdev, + bool *created); =20 int qemuDomainNamespaceTeardownHostdev(virDomainObj *vm, virDomainHostdevDef *hostdev); =20 int qemuDomainNamespaceSetupMemory(virDomainObj *vm, - virDomainMemoryDef *memory); + virDomainMemoryDef *memory, + bool *created); =20 int qemuDomainNamespaceTeardownMemory(virDomainObj *vm, virDomainMemoryDef *memory); =20 int qemuDomainNamespaceSetupChardev(virDomainObj *vm, - virDomainChrDef *chr); + virDomainChrDef *chr, + bool *created); =20 int qemuDomainNamespaceTeardownChardev(virDomainObj *vm, virDomainChrDef *chr); =20 int qemuDomainNamespaceSetupRNG(virDomainObj *vm, - virDomainRNGDef *rng); + virDomainRNGDef *rng, + bool *created); =20 int qemuDomainNamespaceTeardownRNG(virDomainObj *vm, virDomainRNGDef *rng); =20 int qemuDomainNamespaceSetupInput(virDomainObj *vm, - virDomainInputDef *input); + virDomainInputDef *input, + bool *created); =20 int qemuDomainNamespaceTeardownInput(virDomainObj *vm, virDomainInputDef *input); diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 7487e12640..c972c90801 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -8452,7 +8452,7 @@ qemuProcessRefreshLegacyBlockjob(void *payload, =20 if (disk->mirror->format && disk->mirror->format !=3D VIR_STORAGE_FILE_RAW && - (qemuDomainNamespaceSetupDisk(vm, disk->mirror) < 0 || + (qemuDomainNamespaceSetupDisk(vm, disk->mirror, NULL) < 0 = || qemuSetupImageChainCgroup(vm, disk->mirror) < 0 || qemuSecuritySetImageLabel(priv->driver, vm, disk->mirror, true, true) < 0)) --=20 2.31.1