From nobody Thu Mar 28 15:05:59 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.74 as permitted sender) client-ip=63.128.21.74; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-74.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.74 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=1584552780; cv=none; d=zohomail.com; s=zohoarc; b=P0MoW8Xfr+PBxmvD6PtGker7xs1ffOLyRreMKigtt6Xrj2GLZvSkUMhor+rc4a77+Hal0jGoble9KoefTf79pqvnudAoFCterC7+UQic6cVp8q0tKJKpYHVdCe0+omo9l88DIKHw+nG0844eyEdGSymQyYiHhaOYTz9+hglRKyk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1584552780; 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=vY5SnaUIFW+cBhTtBQJUPMO7mEN5gdGPS8I4dNozjT8=; b=ncFn7Hnrc55RjUFWcxlwFpFbUo68yn5cEO22nK8OWjvBg6gmEqw8Wvzn/UU/H6nAjI56sACmObIOBYcMGbBNp534CWh7HqyQteZyYl+COZR1LOmGmYUHvM4wXMMqe4Fow9Y/BmYbK+Qiq8w4jr4i/37WljCPwDe1B6QbCQlKrxs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.74 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-74.mimecast.com (us-smtp-delivery-74.mimecast.com [63.128.21.74]) by mx.zohomail.com with SMTPS id 1584552780797938.1099038916544; Wed, 18 Mar 2020 10:33:00 -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-346-B3weTHFnM0-bXbiOc9eAzg-1; Wed, 18 Mar 2020 13:32:57 -0400 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id E46CA18B9F69; Wed, 18 Mar 2020 17:32:28 +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 285415C1A0; Wed, 18 Mar 2020 17:32:28 +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 8291418089CD; Wed, 18 Mar 2020 17:32:27 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 02IHWOEj029235 for ; Wed, 18 Mar 2020 13:32:24 -0400 Received: by smtp.corp.redhat.com (Postfix) id 7BFD417B91; Wed, 18 Mar 2020 17:32:24 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.192.91]) by smtp.corp.redhat.com (Postfix) with ESMTP id ED544627D8 for ; Wed, 18 Mar 2020 17:32:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1584552779; 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=vY5SnaUIFW+cBhTtBQJUPMO7mEN5gdGPS8I4dNozjT8=; b=T+84/SbYlthQ0xvREKQZZT5bQfWQSVc7MxfdrVlhi511S/DF9oLosMK8u1EvBPVBMR/sEb zidrMRJn7rmTgU5YbeE5PGPDbZEZRohSwx6dcUJl6HAkf+hsrzSy6mu7Da8vpX26QNzkXJ EKY2Fz9Yz9LyyDMIrfzgaHdF7CyZGiM= X-MC-Unique: B3weTHFnM0-bXbiOc9eAzg-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 1/6] qemuDomainCreateDeviceRecursive: Report error if mkdir() fails Date: Wed, 18 Mar 2020 18:32:11 +0100 Message-Id: <1e4c186830ac98af83d9da9636a78977645c23d9.1584552044.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 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.13 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" The virFileMakePathWithMode() which is our recursive version of mkdir() fails, it simply just returns a negative value with errno set. No error is reported (as compared to virFileTouch() for instance). Signed-off-by: Michal Privoznik Reviewed-by: Pavel Mores --- src/qemu/qemu_domain.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 0e2252f6cf..48bf5ae559 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -14643,8 +14643,12 @@ qemuDomainCreateDeviceRecursive(const char *device, * proper owner and mode. Bind mount only after that. */ } else if (isDir) { if (create && - virFileMakePathWithMode(devicePath, sb.st_mode) < 0) + virFileMakePathWithMode(devicePath, sb.st_mode) < 0) { + virReportSystemError(errno, + _("Unable to make dir %s"), + devicePath); goto cleanup; + } } else { virReportError(VIR_ERR_OPERATION_UNSUPPORTED, _("unsupported device type %s 0%o"), --=20 2.24.1 From nobody Thu Mar 28 15:05:59 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.74 as permitted sender) client-ip=63.128.21.74; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-74.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.74 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=1584552785; cv=none; d=zohomail.com; s=zohoarc; b=M3Qx6cFxdogG2QZdw/5TATmrIssOMRnvdn8DEKNkWslG/HMWXktYVWbNRTJvkM19J+AEmRPNGXB063JWgpP1IL5ZO6XhRmNgu3L3VwmcH2/7/vL3UFJlwEeThp1bWNZzFPnHjSO9Gn4Chjv0YWiEijohHh6ZEUzRl7RbxdD4J84= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1584552785; 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=Ske6LjggHOsVS16OXeYDD4bYs3PyrjYDZNwE5sqTxXs=; b=TiR6fCc9OAjtLi3UBMhpcGqOuAl6PgsZ6tYhiBzbBZyQbfHg6fMttqWMjPFIOlXIr0hkLWJVOBRKuV1k38zgk78BCDtDIL4LXQ2PykuSs0I9qPkuvnEx07laHixWARGVGbuaM0tax5mqRe1y7pcj+H4EdR0xKIuWRb0bttpD9Mo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.74 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-74.mimecast.com (us-smtp-delivery-74.mimecast.com [63.128.21.74]) by mx.zohomail.com with SMTPS id 1584552785508577.5608384903819; Wed, 18 Mar 2020 10:33:05 -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-446-XM6zjCWbMI2xTR_7RmZNFg-1; Wed, 18 Mar 2020 13:33:01 -0400 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 27FE48014DF; Wed, 18 Mar 2020 17:32:38 +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 F16275C1A0; Wed, 18 Mar 2020 17:32:37 +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 A607218089CF; Wed, 18 Mar 2020 17:32:37 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 02IHWPiP029240 for ; Wed, 18 Mar 2020 13:32:25 -0400 Received: by smtp.corp.redhat.com (Postfix) id 5A96817B91; Wed, 18 Mar 2020 17:32:25 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.192.91]) by smtp.corp.redhat.com (Postfix) with ESMTP id CCE066EF81 for ; Wed, 18 Mar 2020 17:32:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1584552784; 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=Ske6LjggHOsVS16OXeYDD4bYs3PyrjYDZNwE5sqTxXs=; b=E0EiBdX8wJDyR/38y/TP8eNladGJSTveg/8ItySCP6jzYCxa2MkUrxz3oeOPwonGh3pMjv mvhC4sNxhp877rB/hDCEpcsSFzHKjB2eoOhzWYX+JPZyke3eKGzcRxpDY7BPuVvp9g6Sop LEgMsd2HuQSI4he2GwtwtqMgt2sk9oM= X-MC-Unique: XM6zjCWbMI2xTR_7RmZNFg-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 2/6] qemuDomainBuildNamespace: Try harder to remove temp directories Date: Wed, 18 Mar 2020 18:32:12 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 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.13 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" If building namespace fails somewhere in the middle (that is some files exists under devMountsSavePath[i]), then plain rmdir() is not enough to remove dir. Umount the temp location and use virFileDeleteTree() to remove the directory. Signed-off-by: Michal Privoznik Reviewed-by: Pavel Mores --- src/qemu/qemu_domain.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 48bf5ae559..2724607311 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -15311,9 +15311,12 @@ qemuDomainBuildNamespace(virQEMUDriverConfigPtr cf= g, ret =3D 0; cleanup: for (i =3D 0; i < ndevMountsPath; i++) { +#if defined(__linux__) + umount(devMountsSavePath[i]); +#endif /* defined(__linux__) */ /* The path can be either a regular file or a dir. */ if (virFileIsDir(devMountsSavePath[i])) - rmdir(devMountsSavePath[i]); + virFileDeleteTree(devMountsSavePath[i]); else unlink(devMountsSavePath[i]); } --=20 2.24.1 From nobody Thu Mar 28 15:05:59 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.74 as permitted sender) client-ip=216.205.24.74; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-74.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.74 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=1584552777; cv=none; d=zohomail.com; s=zohoarc; b=G90jI/+NRlOAyIbtRgdsOOSDsCtwwTZQVoPFdCj01daoS6lDgvH5s1odmRSZXXv1rknaR9MxMTH6MvVEJIyk3C6BJCTDxSxru5YkyDMXdDq+sMbr10xprR78sxxWJzVsFj6HRdKg0dNoEGrnbEs0TxP8j1lIF6CbfrP3eg0/TKM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1584552777; 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=F7H2kKK0hkzNFe8p9OUgdsmoc6nU9o9LBDyUFWxc+Tk=; b=M9dC2wLjQRLzO4BcsEMOf1Bc93NRubn5sHKIfo7Rd1KDAhrTHENhh1ac4uu+nY/crlSXYWAS6eZB8tctXXHUOtIljwDjhhiu8M1X4kT3MzJIAYnXN3tnvolK+lINOhx6vNOoWCk+bN1+iYsa7t1ZHXdfqlF69rMEcCAZeN6KEaA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.74 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-74.mimecast.com (us-smtp-delivery-74.mimecast.com [216.205.24.74]) by mx.zohomail.com with SMTPS id 158455277750925.755902120053406; Wed, 18 Mar 2020 10:32:57 -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-379-XdEKFkucP0KzNZXFnQdhmA-1; Wed, 18 Mar 2020 13:32:53 -0400 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 5A390100CEA4; Wed, 18 Mar 2020 17:32:40 +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 2936219756; Wed, 18 Mar 2020 17:32:40 +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 B81CF87005; Wed, 18 Mar 2020 17:32:39 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 02IHWSJD029260 for ; Wed, 18 Mar 2020 13:32:28 -0400 Received: by smtp.corp.redhat.com (Postfix) id 245C917B91; Wed, 18 Mar 2020 17:32:28 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.192.91]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9757093509 for ; Wed, 18 Mar 2020 17:32:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1584552776; 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=F7H2kKK0hkzNFe8p9OUgdsmoc6nU9o9LBDyUFWxc+Tk=; b=gnY74Lm2CM+WETq8rBpnPl5p0zn2jsekC2Gk+w9yRxc1tLYvPr3uXlbNn/5OK+NoQgrleZ dSgHyGv6G8L5h3HM2qlFtxTwxp/VxmlMvEfEz6saXvN4F2KOPIfoM7CpRj9a5fKihKThDZ K0sCyM9sYR3M7lUZN0w6TQk/u9RWQdk= X-MC-Unique: XdEKFkucP0KzNZXFnQdhmA-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 3/6] qemuDomainBuildNamespace: Make @devPath const Date: Wed, 18 Mar 2020 18:32:13 +0100 Message-Id: <8cd07f4aadd62af55e6a23f3a121480bbc02faba.1584552044.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 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.84 on 10.5.11.23 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" The @devPath variable is not modifiable. It merely just points to string containing path where private devtmpfs is being constructed. Make it const so it doesn't look weird that it's not freed. Signed-off-by: Michal Privoznik Reviewed-by: Pavel Mores --- src/qemu/qemu_domain.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 2724607311..a4c07fffcb 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -15176,7 +15176,7 @@ qemuDomainBuildNamespace(virQEMUDriverConfigPtr cfg, virDomainObjPtr vm) { struct qemuDomainCreateDeviceData data; - char *devPath =3D NULL; + const char *devPath =3D NULL; char **devMountsPath =3D NULL, **devMountsSavePath =3D NULL; size_t ndevMountsPath =3D 0, i; int ret =3D -1; --=20 2.24.1 From nobody Thu Mar 28 15:05:59 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.74 as permitted sender) client-ip=63.128.21.74; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-74.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.74 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=1584552853; cv=none; d=zohomail.com; s=zohoarc; b=AdJ3uFtT6RUSWU9g5z0KbjdKxzkWBZDMQgwROR2Z+4KezEUQ6JXRe6YjxPhml32Muc6HJGaIKmsFP7f/OhQRoLM8TVkCE6rauq8ghX2EvsaG4RmASkic9htREHqMyFtlkTDebGxk99pw6xU/HygB6DY8MpyWgPRz8EKG++Z8E8A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1584552853; 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=PLUKT0zgI5r9KUM/vPHRjaroXbV0WQ+wkSaCKEBo2fM=; b=IObjAUK75jT23grxhQfqMJ2nCrOkiL5Hmsi/wCq8VfsKPpnUVmU5oo0bT1XWMLl5RA2BOF5GbWSg0sDthPqtmJK+57XgG1NwhzG9TzV2v7m2Fypc31YeRNZpSduGjiYQsg1XvVaFfUijG1j2qNqDgrvO/4ckRzXu3PZ/Z+70DFk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.74 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-74.mimecast.com (us-smtp-delivery-74.mimecast.com [63.128.21.74]) by mx.zohomail.com with SMTPS id 1584552853105362.7156143965882; Wed, 18 Mar 2020 10:34:13 -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-412-ZK2a74jRO_uJd-is_I_aeA-1; Wed, 18 Mar 2020 13:33:01 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 6C25D18C43CF; Wed, 18 Mar 2020 17:32:44 +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 3F5ED10027A8; Wed, 18 Mar 2020 17:32:44 +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 EBA8287011; Wed, 18 Mar 2020 17:32:43 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 02IHWTLX029267 for ; Wed, 18 Mar 2020 13:32:29 -0400 Received: by smtp.corp.redhat.com (Postfix) id 05D3F5417F; Wed, 18 Mar 2020 17:32:29 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.192.91]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7853F17B91 for ; Wed, 18 Mar 2020 17:32:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1584552851; 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=PLUKT0zgI5r9KUM/vPHRjaroXbV0WQ+wkSaCKEBo2fM=; b=BXyo2bIWwTsC53lAXr6Jm/44Y7DgeKAcLcCZEdTXvvw5X+apB0QFiRUsultbMmsMdYg89v uZWdtjQsNbSCoxY0U6AKQ0OAtlbFlQCZwOBcj0If9EP9eoOZmg1nXad5Ei1R0zQtjXOoIx t6brTShigzgypkcAeLS+Tl2UUpieDYI= X-MC-Unique: ZK2a74jRO_uJd-is_I_aeA-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 4/6] virfile: Handle directories in virFileBindMountDevice() Date: Wed, 18 Mar 2020 18:32:14 +0100 Message-Id: <7605b6895fe70aef52a031213c9606a78a15ec7b.1584552044.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 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.84 on 10.5.11.22 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" The @src is not always a file. It may also be a directory (for instance qemuDomainCreateDeviceRecursive() assumes that) - even though it doesn't happen usually. Anyway, mount() can mount only a dir onto a dir and a file onto a file. Signed-off-by: Michal Privoznik Reviewed-by: Pavel Mores --- src/util/virfile.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/util/virfile.c b/src/util/virfile.c index 0f31554323..9c175b041f 100644 --- a/src/util/virfile.c +++ b/src/util/virfile.c @@ -3743,8 +3743,17 @@ int virFileBindMountDevice(const char *src, const char *dst) { - if (virFileTouch(dst, 0666) < 0) - return -1; + if (!virFileExists(dst)) { + if (virFileIsDir(src)) { + if (virFileMakePath(dst)) { + virReportSystemError(errno, _("Unable to make dir %s"), ds= t); + return -1; + } + } else { + if (virFileTouch(dst, 0666) < 0) + return -1; + } + } =20 if (mount(src, dst, "none", MS_BIND, NULL) < 0) { virReportSystemError(errno, _("Failed to bind %s on to %s"), src, --=20 2.24.1 From nobody Thu Mar 28 15:05:59 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.74 as permitted sender) client-ip=63.128.21.74; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-74.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.74 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=1584552778; cv=none; d=zohomail.com; s=zohoarc; b=YXs8z34OW6yNXwVOIKP7a1EixFoIAuB4i+9R7Y1chTcVMgbPsH7D+KVaT7blxpsxYZPsBVU3eRSi6cxzOv2jbGS3RsqybwTf3RX+1d7YISI+G3G4bGut1ZI7CJpdSKA6xC3YwV/ctPqA8kVf5W5XYjOkcG4mf0Gn74qsDqjXaPU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1584552778; 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=QJ+xutWREE4GK3Cx8I5HO46PDMHDibUvnheH4q1IjRw=; b=LhpsOJ6yDJXMeinXJHy5Pl5BSRRU4BgxZ8V3NL4fUy/CqEoVc02GQ/9wAmGjcYwNRMCSO8uiyppE6eWco9s9hY3Zq18DYweKHa0DsKo7K9Z4uag40F9UYAian3LroEl1QfBuP/ioOqkoCaB9VP/T9/8ty/w7YUeSBIQ3ENkIOho= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.74 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-74.mimecast.com (us-smtp-delivery-74.mimecast.com [63.128.21.74]) by mx.zohomail.com with SMTPS id 1584552778529436.83710157433836; Wed, 18 Mar 2020 10:32:58 -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-176-P45OXwj8MjOJS38o3tuyVQ-1; Wed, 18 Mar 2020 13:32:54 -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 2DD226D95A; Wed, 18 Mar 2020 17:32:34 +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 031145DA82; Wed, 18 Mar 2020 17:32:34 +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 8762E18089CF; Wed, 18 Mar 2020 17:32:33 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 02IHWVj8029282 for ; Wed, 18 Mar 2020 13:32:31 -0400 Received: by smtp.corp.redhat.com (Postfix) id E267417B91; Wed, 18 Mar 2020 17:32:31 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.192.91]) by smtp.corp.redhat.com (Postfix) with ESMTP id 61BB6627D8 for ; Wed, 18 Mar 2020 17:32:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1584552777; 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=QJ+xutWREE4GK3Cx8I5HO46PDMHDibUvnheH4q1IjRw=; b=dokU0MuF/5Tix0uSJTLM1ApywvN8c3F+r0Pmn7kIM3/Az7EP8wNOr4dzo93qgmtUVh6LMo DZc6oxw4qnfkyfZJd7zYDqdJh9TVFP06nwUbSiw90s8NHt3t2PwpNRXGQS7VwWhJMYur7P U16sUAVcpIvM2CyjUCPF+1V0i0QVVfw= X-MC-Unique: P45OXwj8MjOJS38o3tuyVQ-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 5/6] virprocess: Passthru error from virProcessRunInForkHelper Date: Wed, 18 Mar 2020 18:32:15 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 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 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" When running a function in a forked child, so far the only thing we could report is exit status of the child and the error message. However, it may be beneficial to the caller to know the actual error that happened in the child. Signed-off-by: Michal Privoznik Reviewed-by: Pavel Mores --- build-aux/syntax-check.mk | 2 +- src/util/virprocess.c | 51 ++++++++++++++++++++++++++++++++++++--- tests/commandtest.c | 43 +++++++++++++++++++++++++++++++++ 3 files changed, 91 insertions(+), 5 deletions(-) diff --git a/build-aux/syntax-check.mk b/build-aux/syntax-check.mk index 3020921be8..2a38c03ba9 100644 --- a/build-aux/syntax-check.mk +++ b/build-aux/syntax-check.mk @@ -1987,7 +1987,7 @@ exclude_file_name_regexp--sc_flags_usage =3D \ exclude_file_name_regexp--sc_libvirt_unmarked_diagnostics =3D \ ^(src/rpc/gendispatch\.pl$$|tests/) =20 -exclude_file_name_regexp--sc_po_check =3D ^(docs/|src/rpc/gendispatch\.pl$= $) +exclude_file_name_regexp--sc_po_check =3D ^(docs/|src/rpc/gendispatch\.pl$= $|tests/commandtest.c$$) =20 exclude_file_name_regexp--sc_prohibit_VIR_ERR_NO_MEMORY =3D \ ^(build-aux/syntax-check\.mk|include/libvirt/virterror\.h|src/remote/rem= ote_daemon_dispatch\.c|src/util/virerror\.c|docs/internals/oomtesting\.html= \.in)$$ diff --git a/src/util/virprocess.c b/src/util/virprocess.c index 24135070b7..e8674402f9 100644 --- a/src/util/virprocess.c +++ b/src/util/virprocess.c @@ -1126,6 +1126,23 @@ virProcessRunInMountNamespace(pid_t pid G_GNUC_UNUSE= D, =20 =20 #ifndef WIN32 +typedef struct { + int code; + int domain; + char message[VIR_ERROR_MAX_LENGTH]; + virErrorLevel level; + char str1[VIR_ERROR_MAX_LENGTH]; + char str2[VIR_ERROR_MAX_LENGTH]; + /* str3 doesn't seem to be used. Ignore it. */ + int int1; + int int2; +} errorData; + +typedef union { + errorData data; + char bindata[sizeof(errorData)]; +} errorDataBin; + static int virProcessRunInForkHelper(int errfd, pid_t ppid, @@ -1134,9 +1151,19 @@ virProcessRunInForkHelper(int errfd, { if (cb(ppid, opaque) < 0) { virErrorPtr err =3D virGetLastError(); + errorDataBin bin =3D { 0 }; + if (err) { - size_t len =3D strlen(err->message) + 1; - ignore_value(safewrite(errfd, err->message, len)); + bin.data.code =3D err->code; + bin.data.domain =3D err->domain; + ignore_value(virStrcpy(bin.data.message, err->message, sizeof(= bin.data.message))); + bin.data.level =3D err->level; + ignore_value(virStrcpy(bin.data.str1, err->str1, sizeof(bin.da= ta.str1))); + ignore_value(virStrcpy(bin.data.str2, err->str2, sizeof(bin.da= ta.str2))); + bin.data.int1 =3D err->int1; + bin.data.int2 =3D err->int2; + + ignore_value(safewrite(errfd, bin.bindata, sizeof(bin))); } =20 return -1; @@ -1188,16 +1215,32 @@ virProcessRunInFork(virProcessForkCallback cb, } else { int status; g_autofree char *buf =3D NULL; + errorDataBin bin; + int nread; =20 VIR_FORCE_CLOSE(errfd[1]); - ignore_value(virFileReadHeaderFD(errfd[0], 1024, &buf)); + nread =3D virFileReadHeaderFD(errfd[0], sizeof(bin), &buf); ret =3D virProcessWait(child, &status, false); if (ret =3D=3D 0) { ret =3D status =3D=3D EXIT_CANCELED ? -1 : status; if (ret) { virReportError(VIR_ERR_INTERNAL_ERROR, _("child reported (status=3D%d): %s"), - status, NULLSTR(buf)); + status, NULLSTR(bin.data.message)); + + if (nread =3D=3D sizeof(bin)) { + memcpy(bin.bindata, buf, sizeof(bin)); + virRaiseErrorFull(__FILE__, __FUNCTION__, __LINE__, + bin.data.domain, + bin.data.code, + bin.data.level, + bin.data.str1, + bin.data.str2, + NULL, + bin.data.int1, + bin.data.int2, + "%s", bin.data.message); + } } } } diff --git a/tests/commandtest.c b/tests/commandtest.c index a64aa9ad33..f4a2c67c05 100644 --- a/tests/commandtest.c +++ b/tests/commandtest.c @@ -1257,6 +1257,48 @@ static int test27(const void *unused G_GNUC_UNUSED) } =20 =20 +static int +test28Callback(pid_t pid G_GNUC_UNUSED, + void *opaque G_GNUC_UNUSED) +{ + virReportSystemError(ENODATA, "%s", "some error message"); + return -1; +} + + +static int +test28(const void *unused G_GNUC_UNUSED) +{ + /* Not strictly a virCommand test, but this is the easiest place + * to test this lower-level interface. */ + virErrorPtr err; + + if (virProcessRunInFork(test28Callback, NULL) !=3D -1) { + fprintf(stderr, "virProcessRunInFork did not fail\n"); + return -1; + } + + if (!(err =3D virGetLastError())) { + fprintf(stderr, "Expected error but got nothing\n"); + return -1; + } + + if (!(err->code =3D=3D VIR_ERR_SYSTEM_ERROR && + err->domain =3D=3D 0 && + STREQ(err->message, "some error message: No data available") && + err->level =3D=3D VIR_ERR_ERROR && + STREQ(err->str1, "%s") && + STREQ(err->str2, "some error message: No data available") && + err->int1 =3D=3D ENODATA && + err->int2 =3D=3D -1)) { + fprintf(stderr, "Unexpected error object\n"); + return -1; + } + + return 0; +} + + static int mymain(void) { @@ -1354,6 +1396,7 @@ mymain(void) DO_TEST(test25); DO_TEST(test26); DO_TEST(test27); + DO_TEST(test28); =20 return ret =3D=3D 0 ? EXIT_SUCCESS : EXIT_FAILURE; } --=20 2.24.1 From nobody Thu Mar 28 15:05:59 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.74 as permitted sender) client-ip=63.128.21.74; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-74.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.74 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=1584552784; cv=none; d=zohomail.com; s=zohoarc; b=LVd8KI4kztFBpi9G1al8zy1HwsRgAEP4ahJNxPTPLZ8t1LwRB8rldkIiBTJaRsHf5a17C8ULguI4affzSDAQXq2yocMckQyp6xjVs6BIKVepFXuT0fr3Q508bNaxA/g+8zZP3I4ucaUPmaxVFV+ct+8aT6u29vTZdxr2i+iTHsA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1584552784; 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=Op0Pt18iBS5AoAaBCjALb2fTA6z5RSlZsbX6dgFAXSg=; b=LMw0NDnhDgAXvZEtry7P1P3cMn9EEFekCs20OKDY/puAMExgZF2rU9sPSI3YCsjHBOuBYO4uaylpybhNWGAqbveTUxfTTgv5D0GkfoKS2GTnGeBhhJAIeNuifAkouGjP2rsunLZsrg17ZEK7vmtViIQN7Qbh6P7gjd1xhH2cDQo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.74 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-74.mimecast.com (us-smtp-delivery-74.mimecast.com [63.128.21.74]) by mx.zohomail.com with SMTPS id 1584552784624298.0550716442117; Wed, 18 Mar 2020 10:33:04 -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-178-phRGeArHP9SpHIXN_f9ipw-1; Wed, 18 Mar 2020 13:33:00 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 17F95803D42; Wed, 18 Mar 2020 17:32:48 +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 E3E8B8AC39; Wed, 18 Mar 2020 17:32:47 +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 9DDDD87013; Wed, 18 Mar 2020 17:32:47 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 02IHWYUv029306 for ; Wed, 18 Mar 2020 13:32:34 -0400 Received: by smtp.corp.redhat.com (Postfix) id 783A66EF81; Wed, 18 Mar 2020 17:32:34 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.192.91]) by smtp.corp.redhat.com (Postfix) with ESMTP id EA4226EF94 for ; Wed, 18 Mar 2020 17:32:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1584552783; 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=Op0Pt18iBS5AoAaBCjALb2fTA6z5RSlZsbX6dgFAXSg=; b=H8m7xwmWXA5T4HpQZvrg1eZ2AMJ6EZCaOE+XtPachrj6Ns5zO3HRGQCZYDtAJJOzaLzIIS SqQbJ/ehJLg6GVacBCUfFHlwScyveiz0roKDwoQwx1zZdq98YFzS1lu78cuyEDxne26hcm NFgGvq3SF0BK1gMooOZb2FKcgprIt34= X-MC-Unique: phRGeArHP9SpHIXN_f9ipw-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 6/6] security: Try harder to run transactions Date: Wed, 18 Mar 2020 18:32:16 +0100 Message-Id: <5588452d987d675e107843426dee3af709f41437.1584552044.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 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.11 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" When a QEMU process dies in the middle of a hotplug, then we fail to restore the seclabels on the device. The problem is that if the thread doing hotplug locks the domain object first and thus blocks the thread that wants to do qemuProcessStop(), the seclabel cleanup code will see vm->pid still set and mount namespace used and therefore try to enter the namespace represented by the PID. But the PID is gone really and thus entering will fail and no restore is done. What we can do is to try enter the namespace (if requested to do so) but if entering fails, fall back to no NS mode. Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=3D1814481 Signed-off-by: Michal Privoznik Reviewed-by: Pavel Mores --- src/security/security_dac.c | 16 ++++++++++++---- src/security/security_selinux.c | 16 ++++++++++++---- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/src/security/security_dac.c b/src/security/security_dac.c index 9046b51004..11fff63bc7 100644 --- a/src/security/security_dac.c +++ b/src/security/security_dac.c @@ -640,15 +640,23 @@ virSecurityDACTransactionCommit(virSecurityManagerPtr= mgr G_GNUC_UNUSED, =20 list->lock =3D lock; =20 + if (pid !=3D -1) { + rc =3D virProcessRunInMountNamespace(pid, + virSecurityDACTransactionRun, + list); + if (rc < 0) { + if (virGetLastErrorCode() =3D=3D VIR_ERR_SYSTEM_ERROR) + pid =3D -1; + else + goto cleanup; + } + } + if (pid =3D=3D -1) { if (lock) rc =3D virProcessRunInFork(virSecurityDACTransactionRun, list); else rc =3D virSecurityDACTransactionRun(pid, list); - } else { - rc =3D virProcessRunInMountNamespace(pid, - virSecurityDACTransactionRun, - list); } =20 if (rc < 0) diff --git a/src/security/security_selinux.c b/src/security/security_selinu= x.c index c94f31727c..8aeb6e45a5 100644 --- a/src/security/security_selinux.c +++ b/src/security/security_selinux.c @@ -1163,15 +1163,23 @@ virSecuritySELinuxTransactionCommit(virSecurityMana= gerPtr mgr G_GNUC_UNUSED, =20 list->lock =3D lock; =20 + if (pid !=3D -1) { + rc =3D virProcessRunInMountNamespace(pid, + virSecuritySELinuxTransactionRu= n, + list); + if (rc < 0) { + if (virGetLastErrorCode() =3D=3D VIR_ERR_SYSTEM_ERROR) + pid =3D -1; + else + goto cleanup; + } + } + if (pid =3D=3D -1) { if (lock) rc =3D virProcessRunInFork(virSecuritySELinuxTransactionRun, l= ist); else rc =3D virSecuritySELinuxTransactionRun(pid, list); - } else { - rc =3D virProcessRunInMountNamespace(pid, - virSecuritySELinuxTransactionRu= n, - list); } =20 if (rc < 0) --=20 2.24.1