From nobody Mon Feb 9 03:46:39 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 205.139.110.120 as permitted sender) client-ip=205.139.110.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.120 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=1596707756; cv=none; d=zohomail.com; s=zohoarc; b=TJvo2/yswCt2d2eZLGa68FGkHUDDKpL7NupO1Z+F4grbEDIa+CHEPVaclKJ0Z1p+uEHW8QCGyty2I6iI8AxoGYLWYlEpUekNouh+P0kW/uZr0feVdxCDnbw/8RG8k++B1JRTrcjLfPbAq7eHSw2USiGIVRPuurQHXXcZh/5D7IE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1596707756; 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=L0/kM5lpUpeML5hTvMMJZOuZ1gUu3HypwuYM8fiit38=; b=a4YbIqV96JUEArJv1Vp96IxIAc4l0ejBlgPzsoD91eofMarl38ucaBvXtnpvhTQNtuIjHe88lmaFVxMFXbJX6ESofvrPgzne6JCfIdxv6tgMSVaD/ilEn7EXJqtxze/Y83u67EWK8zYHVQerjkTnkCr4gGP5yyrzX5MfwKLAZVI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.120 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-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) by mx.zohomail.com with SMTPS id 1596707756866129.1446278628265; Thu, 6 Aug 2020 02:55:56 -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-102-KWLQPRJ7ONCl1w671U8hgA-1; Thu, 06 Aug 2020 05:55:53 -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 C802B100CCC0; Thu, 6 Aug 2020 09:55:47 +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 A64631001B2C; Thu, 6 Aug 2020 09:55: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 731B6180530B; Thu, 6 Aug 2020 09:55:47 +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 0769tNO9024675 for ; Thu, 6 Aug 2020 05:55:23 -0400 Received: by smtp.corp.redhat.com (Postfix) id EC37A60E1C; Thu, 6 Aug 2020 09:55:23 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.40.208.38]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4E2DE60BF3 for ; Thu, 6 Aug 2020 09:55:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1596707755; 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=L0/kM5lpUpeML5hTvMMJZOuZ1gUu3HypwuYM8fiit38=; b=eNQpYkjjGL0lXGnjEZtEqdoDDiSbvW1qPcpuaa+tkDLhBK4k8fXlSeSOqo3CJEGHhlOqj9 iHdVrnWSagZVkgaQ5d/EqCenYvmaV1wSDGfDK5z9FRgCeBs/m0SNAXfhNsHl0M7Aqu65O0 58EeohP3DiBxAbl05yogqFX8+2tgf9M= X-MC-Unique: KWLQPRJ7ONCl1w671U8hgA-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 2/5] qemuOpenFile: Move to qemu_domain.c Date: Thu, 6 Aug 2020 11:55:13 +0200 Message-Id: <3e8edade52db373f1b8cb192dcf8d1a3a6a2983d.1596707671.git.pkrempa@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.84 on 10.5.11.22 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) Content-Type: text/plain; charset="utf-8" Move the code to qemu_domain.c so that it can be reused in other parts of the qemu driver. 'qemu_domain' was chosen as the permissions are based on the domain configuration. Signed-off-by: Peter Krempa --- src/qemu/qemu_domain.c | 42 +++++++++++++++++++++++++++++++++++ src/qemu/qemu_domain.h | 7 ++++++ src/qemu/qemu_driver.c | 50 +++++------------------------------------- 3 files changed, 54 insertions(+), 45 deletions(-) diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index c440c79e1d..670db6ebfb 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -64,6 +64,7 @@ #include "virdomaincheckpointobjlist.h" #include "backup_conf.h" #include "virutil.h" +#include "virqemu.h" #include #include @@ -10679,3 +10680,44 @@ qemuDomainDiskBlockJobIsSupported(virDomainObjPtr = vm, return true; } + + +/** + * qemuDomainOpenFile: + * @driver: driver object + * @vm: domain object + * @path: path to file to open + * @oflags: flags for opening/creation of the file + * @needUnlink: set to true if file was created by this function + * + * Internal function to properly create or open existing files, with + * ownership affected by qemu driver setup and domain DAC label. + * + * Returns the file descriptor on success and negative errno on failure. + * + * This function should not be used on storage sources. Use + * qemuDomainStorageFileInit and storage driver APIs if possible. + **/ +int +qemuDomainOpenFile(virQEMUDriverPtr driver, + virDomainObjPtr vm, + const char *path, + int oflags, + bool *needUnlink) +{ + g_autoptr(virQEMUDriverConfig) cfg =3D virQEMUDriverGetConfig(driver); + uid_t user =3D cfg->user; + gid_t group =3D cfg->group; + bool dynamicOwnership =3D cfg->dynamicOwnership; + virSecurityLabelDefPtr seclabel; + + /* TODO: Take imagelabel into account? */ + if (vm && + (seclabel =3D virDomainDefGetSecurityLabelDef(vm->def, "dac")) != =3D NULL && + seclabel->label !=3D NULL && + (virParseOwnershipIds(seclabel->label, &user, &group) < 0)) + return -1; + + return virQEMUFileOpenAs(user, group, dynamicOwnership, + path, oflags, needUnlink); +} diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h index 3a1bcbbfa3..ef03702fa1 100644 --- a/src/qemu/qemu_domain.h +++ b/src/qemu/qemu_domain.h @@ -1017,3 +1017,10 @@ qemuDomainDiskBlockJobIsSupported(virDomainObjPtr vm, int qemuDomainDefNumaCPUsRectify(virDomainDefPtr def, virQEMUCapsPtr qemuCaps); + +int +qemuDomainOpenFile(virQEMUDriverPtr driver, + virDomainObjPtr vm, + const char *path, + int oflags, + bool *needUnlink); diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index a667eb21bf..0bc7eebe9a 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -3021,46 +3021,6 @@ qemuCompressGetCommand(virQEMUSaveFormat compression) return ret; } -/** - * qemuOpenFile: - * @driver: driver object - * @vm: domain object - * @path: path to file to open - * @oflags: flags for opening/creation of the file - * @needUnlink: set to true if file was created by this function - * - * Internal function to properly create or open existing files, with - * ownership affected by qemu driver setup and domain DAC label. - * - * Returns the file descriptor on success and negative errno on failure. - * - * This function should not be used on storage sources. Use - * qemuDomainStorageFileInit and storage driver APIs if possible. - **/ -static int -qemuOpenFile(virQEMUDriverPtr driver, - virDomainObjPtr vm, - const char *path, - int oflags, - bool *needUnlink) -{ - g_autoptr(virQEMUDriverConfig) cfg =3D virQEMUDriverGetConfig(driver); - uid_t user =3D cfg->user; - gid_t group =3D cfg->group; - bool dynamicOwnership =3D cfg->dynamicOwnership; - virSecurityLabelDefPtr seclabel; - - /* TODO: Take imagelabel into account? */ - if (vm && - (seclabel =3D virDomainDefGetSecurityLabelDef(vm->def, "dac")) != =3D NULL && - seclabel->label !=3D NULL && - (virParseOwnershipIds(seclabel->label, &user, &group) < 0)) - return -1; - - return virQEMUFileOpenAs(user, group, dynamicOwnership, - path, oflags, needUnlink); -} - static int qemuFileWrapperFDClose(virDomainObjPtr vm, @@ -3154,7 +3114,7 @@ qemuDomainSaveMemory(virQEMUDriverPtr driver, if (qemuFileWrapperFDClose(vm, wrapperFd) < 0) goto cleanup; - if ((fd =3D qemuOpenFile(driver, vm, path, O_WRONLY, NULL)) < 0 || + if ((fd =3D qemuDomainOpenFile(driver, vm, path, O_WRONLY, NULL)) < 0 = || virQEMUSaveDataFinish(data, &fd, path) < 0) goto cleanup; @@ -6593,7 +6553,7 @@ qemuDomainSaveImageOpen(virQEMUDriverPtr driver, oflags |=3D directFlag; } - if ((fd =3D qemuOpenFile(driver, NULL, path, oflags, NULL)) < 0) + if ((fd =3D qemuDomainOpenFile(driver, NULL, path, oflags, NULL)) < 0) return -1; if (bypass_cache && @@ -11593,7 +11553,7 @@ qemuDomainMemoryPeek(virDomainPtr dom, * @ret_sb: pointer to return stat buffer (local or remote) * @skipInaccessible: Don't report error if files are not accessible * - * For local storage, open the file using qemuOpenFile and then use + * For local storage, open the file using qemuDomainOpenFile and then use * fstat() to grab the stat struct data for the caller. * * For remote storage, attempt to access the file and grab the stat @@ -11616,8 +11576,8 @@ qemuDomainStorageOpenStat(virQEMUDriverPtr driver, if (skipInaccessible && !virFileExists(src->path)) return 0; - if ((*ret_fd =3D qemuOpenFile(driver, vm, src->path, O_RDONLY, - NULL)) < 0) + if ((*ret_fd =3D qemuDomainOpenFile(driver, vm, src->path, O_RDONL= Y, + NULL)) < 0) return -1; if (fstat(*ret_fd, ret_sb) < 0) { --=20 2.26.2