From nobody Thu May 9 00:59:58 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