From nobody Tue May 7 07:56:31 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+69013+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+69013+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1608153225; cv=none; d=zohomail.com; s=zohoarc; b=HRyFxaurd5r6Jvb3B0STx/PLB45oR894T5IHe2LLs7d1KgdOLV7jgJ9PflAa0vOerhqxT1YbKq867e+kAcoTpFVPmKyoU9LSVd+rHWzR79GntNqdQBJbKLTAlueCV2p0IKpG1Cb25euZ7OuuDYNptQbhQ0oEvdRTIeYCgF3G7r0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608153225; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=bRPX7oONlvLEQjFhe4RrA7R1tc1NZLQtPvifN4qJSqA=; b=UFFYAD5bdjDQoGXkD8OexaKRGas+oPvs1QtiL5uhrn19gK1k5SztpG6EY3fIua342l+PuMk5HZVj30nxdQcT+azClWWPpdU3ySyUxZ1wMHkErNZQEIG4TeoecRlqkTCIE9AcFKKtOkSkQDvojZ07oumTrcfsblXVdjj4ID06Uv4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+69013+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) header.from= Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1608153225109840.2234447398832; Wed, 16 Dec 2020 13:13:45 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id 9ZjvYY1788612xIk0KOWzOc6; Wed, 16 Dec 2020 13:13:43 -0800 X-Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.groups.io with SMTP id smtpd.web12.3473.1608153221482470255 for ; Wed, 16 Dec 2020 13:13:42 -0800 X-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-260-Pc0BB8nCP5-6TRG5fI6YXg-1; Wed, 16 Dec 2020 16:13:38 -0500 X-MC-Unique: Pc0BB8nCP5-6TRG5fI6YXg-1 X-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 D150C1E7C1; Wed, 16 Dec 2020 21:13:37 +0000 (UTC) X-Received: from lacos-laptop-7.usersys.redhat.com (ovpn-114-152.ams2.redhat.com [10.36.114.152]) by smtp.corp.redhat.com (Postfix) with ESMTP id D20C75D9CD; Wed, 16 Dec 2020 21:13:32 +0000 (UTC) From: "Laszlo Ersek" To: devel@edk2.groups.io, virtio-fs@redhat.com, lersek@redhat.com Cc: Ard Biesheuvel , Jordan Justen , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [edk2-devel] [edk2 PATCH 01/48] OvmfPkg: introduce VirtioFsDxe Date: Wed, 16 Dec 2020 22:10:38 +0100 Message-Id: <20201216211125.19496-2-lersek@redhat.com> In-Reply-To: <20201216211125.19496-1-lersek@redhat.com> References: <20201216211125.19496-1-lersek@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,lersek@redhat.com X-Gm-Message-State: GKbXUp5CngjpABTK6533q70Yx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1608153223; bh=bRPX7oONlvLEQjFhe4RrA7R1tc1NZLQtPvifN4qJSqA=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=rCBmaLPzlx6Db6ltAIaP4PM9+545w00ysHh7CV2pKlokOu7GlUD5uHvIH+f/X9B52tm fOr7CtFCOm9iATgj7rrGOMvCFiYJKlCFyKUYlQxlVICEQV922ELCpPu38Sy4hL3xs8HdV aCcec2fRmCqs7b5cHy8HkcOipifUw8TUl8U= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" The purpose of the driver is to ease file exchange (file sharing) between the guest firmware and the virtualization host. The driver is supposed to interoperate with QEMU's "virtiofsd" (Virtio Filesystem Daemon). References: - https://virtio-fs.gitlab.io/ - https://libvirt.org/kbase/virtiofs.html VirtioFsDxe will bind virtio-fs devices, and produce EFI_SIMPLE_FILE_SYSTEM_PROTOCOL instances on them. In the longer term, assuming QEMU will create "bootorder" fw_cfg file entries for virtio-fs devices, booting guest OSes from host-side directories should become possible (dependent on the matching QemuBootOrderLib enhancement). Add the skeleton of the driver. Install EFI_DRIVER_BINDING_PROTOCOL with stub member functions. Install EFI_COMPONENT_NAME2_PROTOCOL with final member functions. This suffices for the DRIVERS command in the UEFI Shell to list the driver with a human-readable name. The file permission model is described immediately in the INF file as a comment block, for future reference. Cc: Ard Biesheuvel Cc: Jordan Justen Cc: Philippe Mathieu-Daud=C3=A9 Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3097 Signed-off-by: Laszlo Ersek Acked-by: Ard Biesheuvel --- OvmfPkg/OvmfPkgIa32.dsc | 1 + OvmfPkg/OvmfPkgIa32X64.dsc | 1 + OvmfPkg/OvmfPkgX64.dsc | 1 + OvmfPkg/OvmfPkgIa32.fdf | 1 + OvmfPkg/OvmfPkgIa32X64.fdf | 1 + OvmfPkg/OvmfPkgX64.fdf | 1 + OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf | 92 ++++++++++++++++ OvmfPkg/VirtioFsDxe/DriverBinding.c | 112 ++++++++++++++++++++ 8 files changed, 210 insertions(+) diff --git a/OvmfPkg/OvmfPkgIa32.dsc b/OvmfPkg/OvmfPkgIa32.dsc index 8eede796a8bd..4ff70674fb6e 100644 --- a/OvmfPkg/OvmfPkgIa32.dsc +++ b/OvmfPkg/OvmfPkgIa32.dsc @@ -807,16 +807,17 @@ [Components] } MdeModulePkg/Universal/PrintDxe/PrintDxe.inf MdeModulePkg/Universal/Disk/DiskIoDxe/DiskIoDxe.inf MdeModulePkg/Universal/Disk/PartitionDxe/PartitionDxe.inf MdeModulePkg/Universal/Disk/RamDiskDxe/RamDiskDxe.inf MdeModulePkg/Universal/Disk/UnicodeCollation/EnglishDxe/EnglishDxe.inf FatPkg/EnhancedFatDxe/Fat.inf MdeModulePkg/Universal/Disk/UdfDxe/UdfDxe.inf + OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf MdeModulePkg/Bus/Scsi/ScsiBusDxe/ScsiBusDxe.inf MdeModulePkg/Bus/Scsi/ScsiDiskDxe/ScsiDiskDxe.inf OvmfPkg/SataControllerDxe/SataControllerDxe.inf MdeModulePkg/Bus/Ata/AtaAtapiPassThru/AtaAtapiPassThru.inf MdeModulePkg/Bus/Ata/AtaBusDxe/AtaBusDxe.inf MdeModulePkg/Bus/Pci/NvmExpressDxe/NvmExpressDxe.inf MdeModulePkg/Universal/HiiDatabaseDxe/HiiDatabaseDxe.inf MdeModulePkg/Universal/SetupBrowserDxe/SetupBrowserDxe.inf diff --git a/OvmfPkg/OvmfPkgIa32X64.dsc b/OvmfPkg/OvmfPkgIa32X64.dsc index f9f82a48f4b9..d40a59183c79 100644 --- a/OvmfPkg/OvmfPkgIa32X64.dsc +++ b/OvmfPkg/OvmfPkgIa32X64.dsc @@ -821,16 +821,17 @@ [Components.X64] } MdeModulePkg/Universal/PrintDxe/PrintDxe.inf MdeModulePkg/Universal/Disk/DiskIoDxe/DiskIoDxe.inf MdeModulePkg/Universal/Disk/PartitionDxe/PartitionDxe.inf MdeModulePkg/Universal/Disk/RamDiskDxe/RamDiskDxe.inf MdeModulePkg/Universal/Disk/UnicodeCollation/EnglishDxe/EnglishDxe.inf FatPkg/EnhancedFatDxe/Fat.inf MdeModulePkg/Universal/Disk/UdfDxe/UdfDxe.inf + OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf MdeModulePkg/Bus/Scsi/ScsiBusDxe/ScsiBusDxe.inf MdeModulePkg/Bus/Scsi/ScsiDiskDxe/ScsiDiskDxe.inf OvmfPkg/SataControllerDxe/SataControllerDxe.inf MdeModulePkg/Bus/Ata/AtaAtapiPassThru/AtaAtapiPassThru.inf MdeModulePkg/Bus/Ata/AtaBusDxe/AtaBusDxe.inf MdeModulePkg/Bus/Pci/NvmExpressDxe/NvmExpressDxe.inf MdeModulePkg/Universal/HiiDatabaseDxe/HiiDatabaseDxe.inf MdeModulePkg/Universal/SetupBrowserDxe/SetupBrowserDxe.inf diff --git a/OvmfPkg/OvmfPkgX64.dsc b/OvmfPkg/OvmfPkgX64.dsc index e59ae05b73aa..ec7886235acf 100644 --- a/OvmfPkg/OvmfPkgX64.dsc +++ b/OvmfPkg/OvmfPkgX64.dsc @@ -817,16 +817,17 @@ [Components] } MdeModulePkg/Universal/PrintDxe/PrintDxe.inf MdeModulePkg/Universal/Disk/DiskIoDxe/DiskIoDxe.inf MdeModulePkg/Universal/Disk/PartitionDxe/PartitionDxe.inf MdeModulePkg/Universal/Disk/RamDiskDxe/RamDiskDxe.inf MdeModulePkg/Universal/Disk/UnicodeCollation/EnglishDxe/EnglishDxe.inf FatPkg/EnhancedFatDxe/Fat.inf MdeModulePkg/Universal/Disk/UdfDxe/UdfDxe.inf + OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf MdeModulePkg/Bus/Scsi/ScsiBusDxe/ScsiBusDxe.inf MdeModulePkg/Bus/Scsi/ScsiDiskDxe/ScsiDiskDxe.inf OvmfPkg/SataControllerDxe/SataControllerDxe.inf MdeModulePkg/Bus/Ata/AtaAtapiPassThru/AtaAtapiPassThru.inf MdeModulePkg/Bus/Ata/AtaBusDxe/AtaBusDxe.inf MdeModulePkg/Bus/Pci/NvmExpressDxe/NvmExpressDxe.inf MdeModulePkg/Universal/HiiDatabaseDxe/HiiDatabaseDxe.inf MdeModulePkg/Universal/SetupBrowserDxe/SetupBrowserDxe.inf diff --git a/OvmfPkg/OvmfPkgIa32.fdf b/OvmfPkg/OvmfPkgIa32.fdf index c07b775d0a2d..f400c845b9c9 100644 --- a/OvmfPkg/OvmfPkgIa32.fdf +++ b/OvmfPkg/OvmfPkgIa32.fdf @@ -285,16 +285,17 @@ [FV.DXEFV] INF OvmfPkg/AcpiPlatformDxe/AcpiPlatformDxe.inf INF RuleOverride=3DACPITABLE OvmfPkg/AcpiTables/AcpiTables.inf INF MdeModulePkg/Universal/Acpi/S3SaveStateDxe/S3SaveStateDxe.inf INF MdeModulePkg/Universal/Acpi/BootScriptExecutorDxe/BootScriptExecutorD= xe.inf INF MdeModulePkg/Universal/Acpi/BootGraphicsResourceTableDxe/BootGraphics= ResourceTableDxe.inf =20 INF FatPkg/EnhancedFatDxe/Fat.inf INF MdeModulePkg/Universal/Disk/UdfDxe/UdfDxe.inf +INF OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf =20 !if $(TOOL_CHAIN_TAG) !=3D "XCODE5" INF ShellPkg/DynamicCommand/TftpDynamicCommand/TftpDynamicCommand.inf INF ShellPkg/DynamicCommand/HttpDynamicCommand/HttpDynamicCommand.inf INF OvmfPkg/LinuxInitrdDynamicShellCommand/LinuxInitrdDynamicShellCommand= .inf !endif INF ShellPkg/Application/Shell/Shell.inf =20 diff --git a/OvmfPkg/OvmfPkgIa32X64.fdf b/OvmfPkg/OvmfPkgIa32X64.fdf index 9adf1525c135..d055552fd09f 100644 --- a/OvmfPkg/OvmfPkgIa32X64.fdf +++ b/OvmfPkg/OvmfPkgIa32X64.fdf @@ -286,16 +286,17 @@ [FV.DXEFV] INF OvmfPkg/AcpiPlatformDxe/AcpiPlatformDxe.inf INF RuleOverride=3DACPITABLE OvmfPkg/AcpiTables/AcpiTables.inf INF MdeModulePkg/Universal/Acpi/S3SaveStateDxe/S3SaveStateDxe.inf INF MdeModulePkg/Universal/Acpi/BootScriptExecutorDxe/BootScriptExecutorD= xe.inf INF MdeModulePkg/Universal/Acpi/BootGraphicsResourceTableDxe/BootGraphics= ResourceTableDxe.inf =20 INF FatPkg/EnhancedFatDxe/Fat.inf INF MdeModulePkg/Universal/Disk/UdfDxe/UdfDxe.inf +INF OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf =20 !if $(TOOL_CHAIN_TAG) !=3D "XCODE5" INF ShellPkg/DynamicCommand/TftpDynamicCommand/TftpDynamicCommand.inf INF ShellPkg/DynamicCommand/HttpDynamicCommand/HttpDynamicCommand.inf INF OvmfPkg/LinuxInitrdDynamicShellCommand/LinuxInitrdDynamicShellCommand= .inf !endif INF ShellPkg/Application/Shell/Shell.inf =20 diff --git a/OvmfPkg/OvmfPkgX64.fdf b/OvmfPkg/OvmfPkgX64.fdf index 17ba9e177ac3..1a2ef5bf2ae3 100644 --- a/OvmfPkg/OvmfPkgX64.fdf +++ b/OvmfPkg/OvmfPkgX64.fdf @@ -295,16 +295,17 @@ [FV.DXEFV] INF OvmfPkg/AcpiPlatformDxe/AcpiPlatformDxe.inf INF RuleOverride=3DACPITABLE OvmfPkg/AcpiTables/AcpiTables.inf INF MdeModulePkg/Universal/Acpi/S3SaveStateDxe/S3SaveStateDxe.inf INF MdeModulePkg/Universal/Acpi/BootScriptExecutorDxe/BootScriptExecutorD= xe.inf INF MdeModulePkg/Universal/Acpi/BootGraphicsResourceTableDxe/BootGraphics= ResourceTableDxe.inf =20 INF FatPkg/EnhancedFatDxe/Fat.inf INF MdeModulePkg/Universal/Disk/UdfDxe/UdfDxe.inf +INF OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf =20 !if $(TOOL_CHAIN_TAG) !=3D "XCODE5" INF ShellPkg/DynamicCommand/TftpDynamicCommand/TftpDynamicCommand.inf INF ShellPkg/DynamicCommand/HttpDynamicCommand/HttpDynamicCommand.inf INF OvmfPkg/LinuxInitrdDynamicShellCommand/LinuxInitrdDynamicShellCommand= .inf !endif INF ShellPkg/Application/Shell/Shell.inf =20 diff --git a/OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf b/OvmfPkg/VirtioFsDxe/Virt= ioFsDxe.inf new file mode 100644 index 000000000000..69cb44bc7c96 --- /dev/null +++ b/OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf @@ -0,0 +1,92 @@ +## @file +# Provide EFI_SIMPLE_FILE_SYSTEM_PROTOCOL instances on virtio-fs devices. +# +# Copyright (C) 2020, Red Hat, Inc. +# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +# +# Permission Model of this driver: +# +# Regardless of the UID and GID values this driver send in the FUSE request +# header, the daemon (that is, the Virtio Filesystem device) always acts w= ith +# root privileges on the host side. The only time the daemon considers sai= d UID +# and GID fields is when creating a new file or directory. Thus, the guest +# driver cannot rely on the host for enforcing any file mode permissions, +# regardless of the "personality" that the guest driver poses as, because +# "root" on the host side ignores all file mode bits. +# +# Therefore the guest driver has to do its own permission checking, and us= e the +# host-side file mode bits only as a kind of "metadata storage" or "remind= er" +# -- hopefully in a way that makes some sense on the host side too. +# +# The complete mapping between the EFI_FILE_PROTOCOL and the host-side file +# mode bits is described below. +# +# - The guest driver poses as UID 0, GID 0, PID 1. +# +# - If and only if all "w" bits are missing from a file on the host side, = then +# the file or directory is reported as EFI_FILE_READ_ONLY in the guest. = When +# setting EFI_FILE_READ_ONLY in the guest, all "w" bits (0222) are clear= ed on +# the host; when clearing EFI_FILE_READ_ONLY in the guest, all "w" bits = are +# set on the host. Viewed from the host side, this sort of reflects that= an +# EFI_FILE_READ_ONLY file should not be written by anyone. +# +# - The attributes EFI_FILE_HIDDEN, EFI_FILE_SYSTEM, EFI_FILE_RESERVED, and +# EFI_FILE_ARCHIVE are never reported in the guest, and they are silently +# ignored when a SetInfo() call or a file-creating Open() call requests = them. +# +# - On the host, files are created with 0666 file mode bits, directories a= re +# created with 0777 file mode bits. +# +# - In the guest, the EFI_FILE_READ_ONLY attribute only controls the permi= tted +# open mode. In particular, on directories, the EFI_FILE_READ_ONLY attri= bute +# does not prevent the creation or deletion of entries inside the direct= ory; +# EFI_FILE_READ_ONLY only prevents the renaming, deleting, flushing (syn= cing) +# and touching of the directory itself (with "touching" meaning updating= the +# timestamps). The fact that EFI_FILE_READ_ONLY being set on a directory= is +# irrelevant in the guest with regard to entry creation/deletion, is +# well-mirrored by the fact that virtiofsd -- which runs as root, regard= less +# of guest driver personality -- ignores the absence of "w" permissions = on a +# host-side directory, when creating or removing entries in it. +# +# - When an EFI_FILE_PROTOCOL is opened read-only, then the Delete(), Writ= e() +# and Flush() member functions are disabled for it. Additionally, SetInf= o() +# is restricted to flipping the EFI_FILE_READ_ONLY bit (which takes effe= ct at +# the next Open()). +# +# - As a consequence of the above, for deleting a directory, it must be +# presented in the guest as openable for writing. +# +# - We diverge from the UEFI spec, and permit Flush() on a directory that = has +# been opened read-write; otherwise the only way to invoke FUSE_FSYNCDIR= on a +# directory would be to Close() it. +# +# - OpenVolume() opens the root directory for read-only access. The Open() +# member function may open it for read-write access. While the root dire= ctory +# cannot be renamed or deleted, opening it for read-write access is usef= ul +# for calling Flush(), according to the previous paragraph, or for updat= ing +# the root directory's timestamps with SetInfo(). +## + +[Defines] + INF_VERSION =3D 1.29 + BASE_NAME =3D VirtioFsDxe + FILE_GUID =3D 7BD9DDF7-8B83-488E-AEC9-24C786= 10289C + MODULE_TYPE =3D UEFI_DRIVER + ENTRY_POINT =3D VirtioFsEntryPoint + +[Packages] + MdePkg/MdePkg.dec + +[Sources] + DriverBinding.c + +[LibraryClasses] + BaseLib + UefiBootServicesTableLib + UefiDriverEntryPoint + +[Protocols] + gEfiComponentName2ProtocolGuid ## PRODUCES + gEfiDriverBindingProtocolGuid ## PRODUCES diff --git a/OvmfPkg/VirtioFsDxe/DriverBinding.c b/OvmfPkg/VirtioFsDxe/Driv= erBinding.c new file mode 100644 index 000000000000..ac0a6330f01b --- /dev/null +++ b/OvmfPkg/VirtioFsDxe/DriverBinding.c @@ -0,0 +1,112 @@ +/** @file + Provide EFI_SIMPLE_FILE_SYSTEM_PROTOCOL instances on virtio-fs devices. + + Copyright (C) 2020, Red Hat, Inc. + + SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#include // AsciiStrCmp() +#include // gBS +#include // EFI_COMPONENT_NAME2_PROTO= COL +#include // EFI_DRIVER_BINDING_PROTOC= OL + +// +// UEFI Driver Model protocol instances. +// +STATIC EFI_DRIVER_BINDING_PROTOCOL mDriverBinding; +STATIC EFI_COMPONENT_NAME2_PROTOCOL mComponentName2; + +// +// UEFI Driver Model protocol member functions. +// +EFI_STATUS +EFIAPI +VirtioFsBindingSupported ( + IN EFI_DRIVER_BINDING_PROTOCOL *This, + IN EFI_HANDLE ControllerHandle, + IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL + ) +{ + return EFI_UNSUPPORTED; +} + +EFI_STATUS +EFIAPI +VirtioFsBindingStart ( + IN EFI_DRIVER_BINDING_PROTOCOL *This, + IN EFI_HANDLE ControllerHandle, + IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL + ) +{ + return EFI_DEVICE_ERROR; +} + +EFI_STATUS +EFIAPI +VirtioFsBindingStop ( + IN EFI_DRIVER_BINDING_PROTOCOL *This, + IN EFI_HANDLE ControllerHandle, + IN UINTN NumberOfChildren, + IN EFI_HANDLE *ChildHandleBuffer OPTIONAL + ) +{ + return EFI_DEVICE_ERROR; +} + +EFI_STATUS +EFIAPI +VirtioFsGetDriverName ( + IN EFI_COMPONENT_NAME2_PROTOCOL *This, + IN CHAR8 *Language, + OUT CHAR16 **DriverName + ) +{ + if (AsciiStrCmp (Language, "en") !=3D 0) { + return EFI_UNSUPPORTED; + } + *DriverName =3D L"Virtio Filesystem Driver"; + return EFI_SUCCESS; +} + +EFI_STATUS +EFIAPI +VirtioFsGetControllerName ( + IN EFI_COMPONENT_NAME2_PROTOCOL *This, + IN EFI_HANDLE ControllerHandle, + IN EFI_HANDLE ChildHandle OPTIONAL, + IN CHAR8 *Language, + OUT CHAR16 **ControllerName + ) +{ + return EFI_UNSUPPORTED; +} + +// +// Entry point of this driver. +// +EFI_STATUS +EFIAPI +VirtioFsEntryPoint ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + EFI_STATUS Status; + + mDriverBinding.Supported =3D VirtioFsBindingSupported; + mDriverBinding.Start =3D VirtioFsBindingStart; + mDriverBinding.Stop =3D VirtioFsBindingStop; + mDriverBinding.Version =3D 0x10; + mDriverBinding.ImageHandle =3D ImageHandle; + mDriverBinding.DriverBindingHandle =3D ImageHandle; + + mComponentName2.GetDriverName =3D VirtioFsGetDriverName; + mComponentName2.GetControllerName =3D VirtioFsGetControllerName; + mComponentName2.SupportedLanguages =3D "en"; + + Status =3D gBS->InstallMultipleProtocolInterfaces (&ImageHandle, + &gEfiDriverBindingProtocolGuid, &mDriverBinding, + &gEfiComponentName2ProtocolGuid, &mComponentName2, NULL); + return Status; +} --=20 2.19.1.3.g30247aa5d201 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#69013): https://edk2.groups.io/g/devel/message/69013 Mute This Topic: https://groups.io/mt/79022524/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Tue May 7 07:56:31 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+69014+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+69014+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1608153380; cv=none; d=zohomail.com; s=zohoarc; b=OYU7YM9NMGjV9wOsuStlU0ER1bD2G9Azd1ge3ESKE973YEoAZLBHvC71aLmBQe82db9jRACe4FPZn3hC6nzl+XQXGb3VdAONfp4nQHxh+PoIek3W+6dZeMbFLH0UZIbLmwvepedkeDwuE60s3DE0eLso1MBVvqWyxYnQ0573h7Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608153380; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=C5K1A2YbhRYsTwgBPv5l4xeAk+lqEVW8St+xm9Z5k20=; b=fhmy8E4EfkNsrXFDO2v5hoeCTmnanCM+yXuuEzqaWs10zUq40RAS2v7jR45DLN0ZGbPWwQQirTHCe5v78pOWXL1MA6Kwnr2005O9Vcx2iJP2LiH2KAIr+mq1iWHlNXdG6QSNuR3JyvBN7U7Ttl6ySo+WQOSwNQmlvm1thhMUrHA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+69014+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) header.from= Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1608153380342641.6927257339794; Wed, 16 Dec 2020 13:16:20 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id ESVXYY1788612xAZl90tzx6h; Wed, 16 Dec 2020 13:16:19 -0800 X-Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.groups.io with SMTP id smtpd.web08.3503.1608153350486886461 for ; Wed, 16 Dec 2020 13:15:50 -0800 X-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-71-0O5VHDYxP4aL1zXrq3FaiQ-1; Wed, 16 Dec 2020 16:15:45 -0500 X-MC-Unique: 0O5VHDYxP4aL1zXrq3FaiQ-1 X-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 4E33E803621; Wed, 16 Dec 2020 21:15:44 +0000 (UTC) X-Received: from lacos-laptop-7.usersys.redhat.com (ovpn-114-152.ams2.redhat.com [10.36.114.152]) by smtp.corp.redhat.com (Postfix) with ESMTP id E992662AF7; Wed, 16 Dec 2020 21:15:38 +0000 (UTC) From: "Laszlo Ersek" To: devel@edk2.groups.io, virtio-fs@redhat.com, lersek@redhat.com Cc: Ard Biesheuvel , Leif Lindholm , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [edk2-devel] [edk2 PATCH 02/48] ArmVirtPkg: include VirtioFsDxe in the ArmVirtQemu* platforms Date: Wed, 16 Dec 2020 22:10:39 +0100 Message-Id: <20201216211125.19496-3-lersek@redhat.com> In-Reply-To: <20201216211125.19496-1-lersek@redhat.com> References: <20201216211125.19496-1-lersek@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,lersek@redhat.com X-Gm-Message-State: eQvuQYVcUONt1sMOJGzkIefJx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1608153379; bh=C5K1A2YbhRYsTwgBPv5l4xeAk+lqEVW8St+xm9Z5k20=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=Ygo1Em5oYmL6Dr6iP5t6Xqq4fyBac3NwVVmirO6JNFxKCl1pvf4SgUIxEMBcZhPPZbq zU3Jzx0w+15wq1o8xJJrr4VI3L0gfqOBfre7B//ps84ob7PrZ5Zh+yI41kmGpG1x+sX06 Rn4yQVdGHh9oYPM73jolJo3Hyz4sPjIOGDQ= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" Include the VirtioFsDxe driver in the ArmVirtPkg platforms that include Virtio10Dxe. (The virtio-fs device is virtio-1.0-only.) Cc: Ard Biesheuvel Cc: Leif Lindholm Cc: Philippe Mathieu-Daud=C3=A9 Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3097 Signed-off-by: Laszlo Ersek Acked-by: Ard Biesheuvel --- ArmVirtPkg/ArmVirtQemu.dsc | 3 ++- ArmVirtPkg/ArmVirtQemuKernel.dsc | 3 ++- ArmVirtPkg/ArmVirtQemuFvMain.fdf.inc | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/ArmVirtPkg/ArmVirtQemu.dsc b/ArmVirtPkg/ArmVirtQemu.dsc index 365426bd7dfd..ef5d6dbeaddc 100644 --- a/ArmVirtPkg/ArmVirtQemu.dsc +++ b/ArmVirtPkg/ArmVirtQemu.dsc @@ -403,23 +403,24 @@ [Components.common] ArmVirtPkg/FdtClientDxe/FdtClientDxe.inf ArmVirtPkg/HighMemDxe/HighMemDxe.inf OvmfPkg/VirtioBlkDxe/VirtioBlk.inf OvmfPkg/VirtioScsiDxe/VirtioScsi.inf OvmfPkg/VirtioNetDxe/VirtioNet.inf OvmfPkg/VirtioRngDxe/VirtioRng.inf =20 # - # FAT filesystem + GPT/MBR partitioning + UDF filesystem + # FAT filesystem + GPT/MBR partitioning + UDF filesystem + virtio-fs # MdeModulePkg/Universal/Disk/DiskIoDxe/DiskIoDxe.inf MdeModulePkg/Universal/Disk/PartitionDxe/PartitionDxe.inf MdeModulePkg/Universal/Disk/UnicodeCollation/EnglishDxe/EnglishDxe.inf FatPkg/EnhancedFatDxe/Fat.inf MdeModulePkg/Universal/Disk/UdfDxe/UdfDxe.inf + OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf =20 # # Bds # MdeModulePkg/Universal/DevicePathDxe/DevicePathDxe.inf { DevicePathLib|MdePkg/Library/UefiDevicePathLib/UefiDevicePathLib.inf PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf diff --git a/ArmVirtPkg/ArmVirtQemuKernel.dsc b/ArmVirtPkg/ArmVirtQemuKerne= l.dsc index f447c62f6898..f8f5f7f4b94b 100644 --- a/ArmVirtPkg/ArmVirtQemuKernel.dsc +++ b/ArmVirtPkg/ArmVirtQemuKernel.dsc @@ -339,23 +339,24 @@ [Components.common] ArmVirtPkg/FdtClientDxe/FdtClientDxe.inf ArmVirtPkg/HighMemDxe/HighMemDxe.inf OvmfPkg/VirtioBlkDxe/VirtioBlk.inf OvmfPkg/VirtioScsiDxe/VirtioScsi.inf OvmfPkg/VirtioNetDxe/VirtioNet.inf OvmfPkg/VirtioRngDxe/VirtioRng.inf =20 # - # FAT filesystem + GPT/MBR partitioning + UDF filesystem + # FAT filesystem + GPT/MBR partitioning + UDF filesystem + virtio-fs # MdeModulePkg/Universal/Disk/DiskIoDxe/DiskIoDxe.inf MdeModulePkg/Universal/Disk/PartitionDxe/PartitionDxe.inf MdeModulePkg/Universal/Disk/UnicodeCollation/EnglishDxe/EnglishDxe.inf FatPkg/EnhancedFatDxe/Fat.inf MdeModulePkg/Universal/Disk/UdfDxe/UdfDxe.inf + OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf =20 # # Bds # MdeModulePkg/Universal/DevicePathDxe/DevicePathDxe.inf { DevicePathLib|MdePkg/Library/UefiDevicePathLib/UefiDevicePathLib.inf PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf diff --git a/ArmVirtPkg/ArmVirtQemuFvMain.fdf.inc b/ArmVirtPkg/ArmVirtQemuF= vMain.fdf.inc index 6eade7e50ff7..1752fee12b79 100644 --- a/ArmVirtPkg/ArmVirtQemuFvMain.fdf.inc +++ b/ArmVirtPkg/ArmVirtQemuFvMain.fdf.inc @@ -72,23 +72,24 @@ [FV.FvMain] INF MdeModulePkg/Universal/SerialDxe/SerialDxe.inf =20 INF ArmPkg/Drivers/ArmGic/ArmGicDxe.inf INF ArmPkg/Drivers/TimerDxe/TimerDxe.inf INF ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashDxe.inf INF MdeModulePkg/Universal/WatchdogTimerDxe/WatchdogTimer.inf =20 # - # FAT filesystem + GPT/MBR partitioning + UDF filesystem + # FAT filesystem + GPT/MBR partitioning + UDF filesystem + virtio-fs # INF MdeModulePkg/Universal/Disk/DiskIoDxe/DiskIoDxe.inf INF MdeModulePkg/Universal/Disk/PartitionDxe/PartitionDxe.inf INF FatPkg/EnhancedFatDxe/Fat.inf INF MdeModulePkg/Universal/Disk/UnicodeCollation/EnglishDxe/EnglishDxe.i= nf INF MdeModulePkg/Universal/Disk/UdfDxe/UdfDxe.inf + INF OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf =20 # # Status Code Routing # INF MdeModulePkg/Universal/ReportStatusCodeRouter/RuntimeDxe/ReportStatu= sCodeRouterRuntimeDxe.inf =20 # # Platform Driver --=20 2.19.1.3.g30247aa5d201 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#69014): https://edk2.groups.io/g/devel/message/69014 Mute This Topic: https://groups.io/mt/79022570/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Tue May 7 07:56:31 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+69015+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+69015+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1608153477; cv=none; d=zohomail.com; s=zohoarc; b=EakiDW2k5zGOKetXSnD/X3xz/se8JnHnqeXXAfxZup7ysnQzBXqyzATfC+fUZ8/KotyS80JYOd4Y2kTQ81DCpPZYvLumpyI4PRIWiQZMgsmCfTP423cHxNC3KQ4ZptSxYK2sb3ldz4ouqn5Zq/8KecXQhTR6VSgygoNYg04W9Qk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608153477; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=wBmD5XgRCX00AOXtT4fKGKPMVPwuGN6J8u+l7mbWCQ0=; b=ncNAQ6ZuJgVS9vGxm4EwKkjVP4HAHBCm5sKCzK7otpWHrxspEme2hwcm8gHepbdZ7gvoTZYIhEakiXIKiIKEjXpev9oeWEwJCd/659PSZuAhcDOMUU2Qw0c0j4qs9k59B9FOTb/0XFJ0gvGSxfdSd4/02SXs27x85OIw2aKO7o8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+69015+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) header.from= Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1608153477132437.7244076213733; Wed, 16 Dec 2020 13:17:57 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id OkSHYY1788612xOD28d56wdK; Wed, 16 Dec 2020 13:17:56 -0800 X-Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.groups.io with SMTP id smtpd.web09.3416.1608153475745491043 for ; Wed, 16 Dec 2020 13:17:56 -0800 X-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-550-K_c9JeCnNUm5sgiAIfoOCQ-1; Wed, 16 Dec 2020 16:17:51 -0500 X-MC-Unique: K_c9JeCnNUm5sgiAIfoOCQ-1 X-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 632F5190D343; Wed, 16 Dec 2020 21:17:50 +0000 (UTC) X-Received: from lacos-laptop-7.usersys.redhat.com (ovpn-114-152.ams2.redhat.com [10.36.114.152]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8EA605D9C0; Wed, 16 Dec 2020 21:17:45 +0000 (UTC) From: "Laszlo Ersek" To: devel@edk2.groups.io, virtio-fs@redhat.com, lersek@redhat.com Cc: Ard Biesheuvel , Jordan Justen , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [edk2-devel] [edk2 PATCH 03/48] OvmfPkg/VirtioFsDxe: DriverBinding: open VirtioDevice, install SimpleFs Date: Wed, 16 Dec 2020 22:10:40 +0100 Message-Id: <20201216211125.19496-4-lersek@redhat.com> In-Reply-To: <20201216211125.19496-1-lersek@redhat.com> References: <20201216211125.19496-1-lersek@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,lersek@redhat.com X-Gm-Message-State: 911yIgUloXN25N05D0S3zzQ6x1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1608153476; bh=wBmD5XgRCX00AOXtT4fKGKPMVPwuGN6J8u+l7mbWCQ0=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=HAGjpsLHkJL2vYhjuLl18mZGnAfrOhnUhXlAHQAl/0dRSJkpjBHQ5HHh7JoWLJNl7ci Bq36UEAK8L0LX6MTRywygxqIpgFdNWZ6nLXnpjceN5FJ06i9AsUF9ZFYJ8PTbr4E4thZV sxKcMFZFlO9HXqhZMbUhQReqcIRTpjSNsmI= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" Complete the Supported, Start, and Stop member functions of EFI_DRIVER_BINDING_PROTOCOL sufficiently for exercising the UEFI driver model: - bind virtio-fs devices, - produce placeholder EFI_SIMPLE_FILE_SYSTEM_PROTOCOL instances on them. On the "TO_START" (=3D Virtio) side, the VirtioFsBindingSupported() function verifies the Virtio subsystem ID for the virtio-fs device (decimal 26 -- see ). Beyond that, no actual Virtio setup is performed for now. Those bits are going to be implemented later in this series. On the "BY_START" (=3D UEFI filesystem) side, the VirtioFsOpenVolume() function -- which is the sole EFI_SIMPLE_FILE_SYSTEM_PROTOCOL member function -- is a stub; it always returns EFI_NO_MEDIA, for now. The "CONNECT", "DISCONNECT", and "MAP -R" UEFI Shell commands can be used to test this patch. Cc: Ard Biesheuvel Cc: Jordan Justen Cc: Philippe Mathieu-Daud=C3=A9 Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3097 Signed-off-by: Laszlo Ersek Acked-by: Ard Biesheuvel --- OvmfPkg/Include/IndustryStandard/Virtio10.h | 5 ++ OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf | 7 ++ OvmfPkg/VirtioFsDxe/VirtioFsDxe.h | 52 +++++++++++ OvmfPkg/VirtioFsDxe/DriverBinding.c | 94 +++++++++++++++++++- OvmfPkg/VirtioFsDxe/SimpleFsOpenVolume.c | 26 ++++++ 5 files changed, 181 insertions(+), 3 deletions(-) diff --git a/OvmfPkg/Include/IndustryStandard/Virtio10.h b/OvmfPkg/Include/= IndustryStandard/Virtio10.h index 3c1592d1fdea..2c60be2b7c0c 100644 --- a/OvmfPkg/Include/IndustryStandard/Virtio10.h +++ b/OvmfPkg/Include/IndustryStandard/Virtio10.h @@ -12,16 +12,21 @@ =20 #include #include =20 // // Subsystem Device IDs (to be) introduced in VirtIo 1.0 // #define VIRTIO_SUBSYSTEM_GPU_DEVICE 16 +// +// Subsystem Device IDs from the VirtIo spec at git commit 87fa6b5d8155; +// . +// +#define VIRTIO_SUBSYSTEM_FILESYSTEM 26 =20 // // Structures for parsing the VirtIo 1.0 specific PCI capabilities from the // config space // #pragma pack (1) typedef struct { EFI_PCI_CAPABILITY_VENDOR_HDR VendorHdr; diff --git a/OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf b/OvmfPkg/VirtioFsDxe/Virt= ioFsDxe.inf index 69cb44bc7c96..ff9b1c6178bc 100644 --- a/OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf +++ b/OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf @@ -73,20 +73,27 @@ [Defines] INF_VERSION =3D 1.29 BASE_NAME =3D VirtioFsDxe FILE_GUID =3D 7BD9DDF7-8B83-488E-AEC9-24C786= 10289C MODULE_TYPE =3D UEFI_DRIVER ENTRY_POINT =3D VirtioFsEntryPoint =20 [Packages] MdePkg/MdePkg.dec + OvmfPkg/OvmfPkg.dec =20 [Sources] DriverBinding.c + SimpleFsOpenVolume.c + VirtioFsDxe.h =20 [LibraryClasses] BaseLib + DebugLib + MemoryAllocationLib UefiBootServicesTableLib UefiDriverEntryPoint =20 [Protocols] gEfiComponentName2ProtocolGuid ## PRODUCES gEfiDriverBindingProtocolGuid ## PRODUCES + gEfiSimpleFileSystemProtocolGuid ## BY_START + gVirtioDeviceProtocolGuid ## TO_START diff --git a/OvmfPkg/VirtioFsDxe/VirtioFsDxe.h b/OvmfPkg/VirtioFsDxe/Virtio= FsDxe.h new file mode 100644 index 000000000000..287defd21f23 --- /dev/null +++ b/OvmfPkg/VirtioFsDxe/VirtioFsDxe.h @@ -0,0 +1,52 @@ +/** @file + Internal macro definitions, type definitions, and function declarations = for + the Virtio Filesystem device driver. + + Copyright (C) 2020, Red Hat, Inc. + + SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#ifndef VIRTIO_FS_DXE_H_ +#define VIRTIO_FS_DXE_H_ + +#include // SIGNATURE_64() +#include // CR() +#include // EFI_SIMPLE_FILE_SYSTEM_PROTOCOL +#include // VIRTIO_DEVICE_PROTOCOL + +#define VIRTIO_FS_SIG SIGNATURE_64 ('V', 'I', 'R', 'T', 'I', 'O', 'F', 'S') + +// +// Main context structure, expressing an EFI_SIMPLE_FILE_SYSTEM_PROTOCOL +// interface on top of the Virtio Filesystem device. +// +typedef struct { + // + // Parts of this structure are initialized / torn down in various functi= ons + // at various call depths. The table to the right should make it easier = to + // track them. + // + // field init function init d= epth + // ----------- ------------------ ------= ---- + UINT64 Signature; // DriverBindingStart 0 + VIRTIO_DEVICE_PROTOCOL *Virtio; // DriverBindingStart 0 + EFI_SIMPLE_FILE_SYSTEM_PROTOCOL SimpleFs; // DriverBindingStart 0 +} VIRTIO_FS; + +#define VIRTIO_FS_FROM_SIMPLE_FS(SimpleFsReference) \ + CR (SimpleFsReference, VIRTIO_FS, SimpleFs, VIRTIO_FS_SIG); + +// +// EFI_SIMPLE_FILE_SYSTEM_PROTOCOL member functions for the Virtio Filesys= tem +// driver. +// + +EFI_STATUS +EFIAPI +VirtioFsOpenVolume ( + IN EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *This, + OUT EFI_FILE_PROTOCOL **Root + ); + +#endif // VIRTIO_FS_DXE_H_ diff --git a/OvmfPkg/VirtioFsDxe/DriverBinding.c b/OvmfPkg/VirtioFsDxe/Driv= erBinding.c index ac0a6330f01b..65e45b5c4bf7 100644 --- a/OvmfPkg/VirtioFsDxe/DriverBinding.c +++ b/OvmfPkg/VirtioFsDxe/DriverBinding.c @@ -1,21 +1,25 @@ /** @file Provide EFI_SIMPLE_FILE_SYSTEM_PROTOCOL instances on virtio-fs devices. =20 Copyright (C) 2020, Red Hat, Inc. =20 SPDX-License-Identifier: BSD-2-Clause-Patent **/ =20 +#include // VIRTIO_SUBSYSTEM_FILESYST= EM #include // AsciiStrCmp() +#include // AllocatePool() #include // gBS #include // EFI_COMPONENT_NAME2_PROTO= COL #include // EFI_DRIVER_BINDING_PROTOC= OL =20 +#include "VirtioFsDxe.h" + // // UEFI Driver Model protocol instances. // STATIC EFI_DRIVER_BINDING_PROTOCOL mDriverBinding; STATIC EFI_COMPONENT_NAME2_PROTOCOL mComponentName2; =20 // // UEFI Driver Model protocol member functions. @@ -23,40 +27,124 @@ STATIC EFI_COMPONENT_NAME2_PROTOCOL mComponentName2; EFI_STATUS EFIAPI VirtioFsBindingSupported ( IN EFI_DRIVER_BINDING_PROTOCOL *This, IN EFI_HANDLE ControllerHandle, IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL ) { - return EFI_UNSUPPORTED; + EFI_STATUS Status; + VIRTIO_DEVICE_PROTOCOL *Virtio; + EFI_STATUS CloseStatus; + + Status =3D gBS->OpenProtocol (ControllerHandle, &gVirtioDeviceProtocolGu= id, + (VOID **)&Virtio, This->DriverBindingHandle, + ControllerHandle, EFI_OPEN_PROTOCOL_BY_DRIVER); + if (EFI_ERROR (Status)) { + return Status; + } + + if (Virtio->SubSystemDeviceId !=3D VIRTIO_SUBSYSTEM_FILESYSTEM) { + Status =3D EFI_UNSUPPORTED; + } + + CloseStatus =3D gBS->CloseProtocol (ControllerHandle, + &gVirtioDeviceProtocolGuid, This->DriverBindingHand= le, + ControllerHandle); + ASSERT_EFI_ERROR (CloseStatus); + + return Status; } =20 EFI_STATUS EFIAPI VirtioFsBindingStart ( IN EFI_DRIVER_BINDING_PROTOCOL *This, IN EFI_HANDLE ControllerHandle, IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL ) { - return EFI_DEVICE_ERROR; + VIRTIO_FS *VirtioFs; + EFI_STATUS Status; + EFI_STATUS CloseStatus; + + VirtioFs =3D AllocatePool (sizeof *VirtioFs); + if (VirtioFs =3D=3D NULL) { + return EFI_OUT_OF_RESOURCES; + } + VirtioFs->Signature =3D VIRTIO_FS_SIG; + + Status =3D gBS->OpenProtocol (ControllerHandle, &gVirtioDeviceProtocolGu= id, + (VOID **)&VirtioFs->Virtio, This->DriverBindingHandle, + ControllerHandle, EFI_OPEN_PROTOCOL_BY_DRIVER); + if (EFI_ERROR (Status)) { + goto FreeVirtioFs; + } + + VirtioFs->SimpleFs.Revision =3D EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_REVISI= ON; + VirtioFs->SimpleFs.OpenVolume =3D VirtioFsOpenVolume; + + Status =3D gBS->InstallProtocolInterface (&ControllerHandle, + &gEfiSimpleFileSystemProtocolGuid, EFI_NATIVE_INTERFACE, + &VirtioFs->SimpleFs); + if (EFI_ERROR (Status)) { + goto CloseVirtio; + } + + return EFI_SUCCESS; + +CloseVirtio: + CloseStatus =3D gBS->CloseProtocol (ControllerHandle, + &gVirtioDeviceProtocolGuid, This->DriverBindingHand= le, + ControllerHandle); + ASSERT_EFI_ERROR (CloseStatus); + +FreeVirtioFs: + FreePool (VirtioFs); + + return Status; } =20 EFI_STATUS EFIAPI VirtioFsBindingStop ( IN EFI_DRIVER_BINDING_PROTOCOL *This, IN EFI_HANDLE ControllerHandle, IN UINTN NumberOfChildren, IN EFI_HANDLE *ChildHandleBuffer OPTIONAL ) { - return EFI_DEVICE_ERROR; + EFI_STATUS Status; + EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *SimpleFs; + VIRTIO_FS *VirtioFs; + + Status =3D gBS->OpenProtocol (ControllerHandle, + &gEfiSimpleFileSystemProtocolGuid, (VOID **)&SimpleFs, + This->DriverBindingHandle, ControllerHandle, + EFI_OPEN_PROTOCOL_GET_PROTOCOL); + if (EFI_ERROR (Status)) { + return Status; + } + + VirtioFs =3D VIRTIO_FS_FROM_SIMPLE_FS (SimpleFs); + + Status =3D gBS->UninstallProtocolInterface (ControllerHandle, + &gEfiSimpleFileSystemProtocolGuid, SimpleFs); + if (EFI_ERROR (Status)) { + return Status; + } + + Status =3D gBS->CloseProtocol (ControllerHandle, &gVirtioDeviceProtocolG= uid, + This->DriverBindingHandle, ControllerHandle); + ASSERT_EFI_ERROR (Status); + + FreePool (VirtioFs); + + return EFI_SUCCESS; } =20 EFI_STATUS EFIAPI VirtioFsGetDriverName ( IN EFI_COMPONENT_NAME2_PROTOCOL *This, IN CHAR8 *Language, OUT CHAR16 **DriverName diff --git a/OvmfPkg/VirtioFsDxe/SimpleFsOpenVolume.c b/OvmfPkg/VirtioFsDxe= /SimpleFsOpenVolume.c new file mode 100644 index 000000000000..a5a66a27d84c --- /dev/null +++ b/OvmfPkg/VirtioFsDxe/SimpleFsOpenVolume.c @@ -0,0 +1,26 @@ +/** @file + EFI_SIMPLE_FILE_SYSTEM_PROTOCOL.OpenVolume() member function for the Vir= tio + Filesystem driver. + + Copyright (C) 2020, Red Hat, Inc. + + SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#include "VirtioFsDxe.h" + +/** + Open the root directory on the Virtio Filesystem. + + Refer to EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_OPEN_VOLUME for the interface + contract. +**/ +EFI_STATUS +EFIAPI +VirtioFsOpenVolume ( + IN EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *This, + OUT EFI_FILE_PROTOCOL **Root + ) +{ + return EFI_NO_MEDIA; +} --=20 2.19.1.3.g30247aa5d201 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#69015): https://edk2.groups.io/g/devel/message/69015 Mute This Topic: https://groups.io/mt/79022609/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Tue May 7 07:56:31 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+69016+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+69016+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1608153614; cv=none; d=zohomail.com; s=zohoarc; b=MqUA7YH8hrDC/+dG6mmfBj8xQJCr0Lln2n693dllP5xOsQYJ4y0Ozlfdy9i/5PWy1Er63OTPR/mKfMXi8fjtAl0Ele0WeY2e2svcJ92fO+W2NwWSXkyIYKWofqhdofXBr/lfM28Bf3kigFREfc2enidgOk0TF9MM9R9Wbfgnhy0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608153614; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=PeBn7HDNJHKXaR2YepR7E5/PSfekgYN8BfXMWsE+Ylo=; b=n+imPAskslh//M6Lwoygd23rGIy90ZYjpgS6gO9dHret9yrpvC+LWYoik0ibAoK0GMn6eZOZnbV558w+RO2AOJZ+H9i25o8faw66x+m5MpxZpLNAZP+b24vj8ZywdP6W5p0C2FX74R4kbbm6ZpYckRULJy85o/igPsrUf75QW/Q= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+69016+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) header.from= Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1608153614198754.1113131579496; Wed, 16 Dec 2020 13:20:14 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id XIXCYY1788612xN8FZyPhwy7; Wed, 16 Dec 2020 13:20:07 -0800 X-Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.groups.io with SMTP id smtpd.web12.3640.1608153601436957133 for ; Wed, 16 Dec 2020 13:20:01 -0800 X-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-339-hSteD7UxM0m-d7JfW_IzFw-1; Wed, 16 Dec 2020 16:19:57 -0500 X-MC-Unique: hSteD7UxM0m-d7JfW_IzFw-1 X-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 56C8F800D53; Wed, 16 Dec 2020 21:19:56 +0000 (UTC) X-Received: from lacos-laptop-7.usersys.redhat.com (ovpn-114-152.ams2.redhat.com [10.36.114.152]) by smtp.corp.redhat.com (Postfix) with ESMTP id 92458106D5AC; Wed, 16 Dec 2020 21:19:51 +0000 (UTC) From: "Laszlo Ersek" To: devel@edk2.groups.io, virtio-fs@redhat.com, lersek@redhat.com Cc: Ard Biesheuvel , Jordan Justen , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [edk2-devel] [edk2 PATCH 04/48] OvmfPkg/VirtioFsDxe: implement virtio device (un)initialization Date: Wed, 16 Dec 2020 22:10:41 +0100 Message-Id: <20201216211125.19496-5-lersek@redhat.com> In-Reply-To: <20201216211125.19496-1-lersek@redhat.com> References: <20201216211125.19496-1-lersek@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,lersek@redhat.com X-Gm-Message-State: 3GEAFEGLjMYg1fTRX4VHBpuTx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1608153607; bh=PeBn7HDNJHKXaR2YepR7E5/PSfekgYN8BfXMWsE+Ylo=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=qhUUtlbqFRN2R2ocwTLg5xGOkBRz8/45E9A2uyNWhCOguljJMQS8N/ppVSbJZEfSqAY vsEcwEoqkSx0Vwe52Kb4R5tDTvwFaN1orVSAH3B2lyXRCzFKkUbu/0KIO+ZBQtlaiiMSH gyL0spatSG857XTKY/tFInKSi4m98wKgCKk= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" Add the VirtioFsInit(), VirtioFsUninit(), and VirtioFsExitBoot() functions. In VirtioFsInit(): - Verify the host-side config of the virtio-fs device. - Save the filesystem label ("tag") for later, from the configuration area of the virtio-fs device. - Save the virtio queue size for later as well. - Set up the virtio ring for sending requests. In VirtioFsUninit(): - Reset the device. - Tear down the virtio ring. In VirtioFsExitBoot(): - Reset the device. With this patch, the UEFI connect / disconnect controller operations involve virtio setup / teardown; they are visible in the virtio-fs daemon's log file. The virtiofsd log also confirms the device reset in VirtioFsExitBoot(), when an OS is booted while the virtio-fs device is bound. Cc: Ard Biesheuvel Cc: Jordan Justen Cc: Philippe Mathieu-Daud=C3=A9 Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3097 Signed-off-by: Laszlo Ersek Acked-by: Ard Biesheuvel --- OvmfPkg/Include/IndustryStandard/VirtioFs.h | 52 ++++ OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf | 2 + OvmfPkg/VirtioFsDxe/VirtioFsDxe.h | 35 +++ OvmfPkg/VirtioFsDxe/DriverBinding.c | 26 +- OvmfPkg/VirtioFsDxe/Helpers.c | 299 ++++++++++++++++++++ 5 files changed, 412 insertions(+), 2 deletions(-) diff --git a/OvmfPkg/Include/IndustryStandard/VirtioFs.h b/OvmfPkg/Include/= IndustryStandard/VirtioFs.h new file mode 100644 index 000000000000..ea7d80d15d0b --- /dev/null +++ b/OvmfPkg/Include/IndustryStandard/VirtioFs.h @@ -0,0 +1,52 @@ +/** @file + Type and macro definitions specific to the Virtio Filesystem device. + + At the time of this writing, the latest released Virtio specification (v= 1.1) + does not include the virtio-fs device. The development version of the + specification defines it however; see the latest version at + . + + This header file is minimal, and only defines the types and macros that = are + necessary for the OvmfPkg implementation. + + Copyright (C) 2020, Red Hat, Inc. + + SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#ifndef VIRTIO_FS_H_ +#define VIRTIO_FS_H_ + +#include + +// +// Lowest numbered queue for sending normal priority requests. +// +#define VIRTIO_FS_REQUEST_QUEUE 1 + +// +// Number of bytes in the "VIRTIO_FS_CONFIG.Tag" field. +// +#define VIRTIO_FS_TAG_BYTES 36 + +// +// Device configuration layout. +// +#pragma pack (1) +typedef struct { + // + // The Tag field can be considered the filesystem label, or a mount point + // hint. It is UTF-8 encoded, and padded to full size with NUL bytes. If= the + // encoded bytes take up the entire Tag field, then there is no NUL + // terminator. + // + UINT8 Tag[VIRTIO_FS_TAG_BYTES]; + // + // The total number of request virtqueues exposed by the device (i.e., + // excluding the "hiprio" queue). + // + UINT32 NumReqQueues; +} VIRTIO_FS_CONFIG; +#pragma pack () + +#endif // VIRTIO_FS_H_ diff --git a/OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf b/OvmfPkg/VirtioFsDxe/Virt= ioFsDxe.inf index ff9b1c6178bc..f6eebdb6bc7c 100644 --- a/OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf +++ b/OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf @@ -77,23 +77,25 @@ [Defines] ENTRY_POINT =3D VirtioFsEntryPoint =20 [Packages] MdePkg/MdePkg.dec OvmfPkg/OvmfPkg.dec =20 [Sources] DriverBinding.c + Helpers.c SimpleFsOpenVolume.c VirtioFsDxe.h =20 [LibraryClasses] BaseLib DebugLib MemoryAllocationLib UefiBootServicesTableLib UefiDriverEntryPoint + VirtioLib =20 [Protocols] gEfiComponentName2ProtocolGuid ## PRODUCES gEfiDriverBindingProtocolGuid ## PRODUCES gEfiSimpleFileSystemProtocolGuid ## BY_START gVirtioDeviceProtocolGuid ## TO_START diff --git a/OvmfPkg/VirtioFsDxe/VirtioFsDxe.h b/OvmfPkg/VirtioFsDxe/Virtio= FsDxe.h index 287defd21f23..2aae96ecd79a 100644 --- a/OvmfPkg/VirtioFsDxe/VirtioFsDxe.h +++ b/OvmfPkg/VirtioFsDxe/VirtioFsDxe.h @@ -6,42 +6,77 @@ =20 SPDX-License-Identifier: BSD-2-Clause-Patent **/ =20 #ifndef VIRTIO_FS_DXE_H_ #define VIRTIO_FS_DXE_H_ =20 #include // SIGNATURE_64() +#include // VIRTIO_FS_TAG_BYTES #include // CR() #include // EFI_SIMPLE_FILE_SYSTEM_PROTOCOL #include // VIRTIO_DEVICE_PROTOCOL +#include // EFI_EVENT =20 #define VIRTIO_FS_SIG SIGNATURE_64 ('V', 'I', 'R', 'T', 'I', 'O', 'F', 'S') =20 +// +// Filesystem label encoded in UCS-2, transformed from the UTF-8 represent= ation +// in "VIRTIO_FS_CONFIG.Tag", and NUL-terminated. Only the printable ASCII= code +// points (U+0020 through U+007E) are supported. +// +typedef CHAR16 VIRTIO_FS_LABEL[VIRTIO_FS_TAG_BYTES + 1]; + // // Main context structure, expressing an EFI_SIMPLE_FILE_SYSTEM_PROTOCOL // interface on top of the Virtio Filesystem device. // typedef struct { // // Parts of this structure are initialized / torn down in various functi= ons // at various call depths. The table to the right should make it easier = to // track them. // // field init function init d= epth // ----------- ------------------ ------= ---- UINT64 Signature; // DriverBindingStart 0 VIRTIO_DEVICE_PROTOCOL *Virtio; // DriverBindingStart 0 + VIRTIO_FS_LABEL Label; // VirtioFsInit 1 + UINT16 QueueSize; // VirtioFsInit 1 + VRING Ring; // VirtioRingInit 2 + VOID *RingMap; // VirtioRingMap 2 + EFI_EVENT ExitBoot; // DriverBindingStart 0 EFI_SIMPLE_FILE_SYSTEM_PROTOCOL SimpleFs; // DriverBindingStart 0 } VIRTIO_FS; =20 #define VIRTIO_FS_FROM_SIMPLE_FS(SimpleFsReference) \ CR (SimpleFsReference, VIRTIO_FS, SimpleFs, VIRTIO_FS_SIG); =20 +// +// Initialization and helper routines for the Virtio Filesystem device. +// + +EFI_STATUS +VirtioFsInit ( + IN OUT VIRTIO_FS *VirtioFs + ); + +VOID +VirtioFsUninit ( + IN OUT VIRTIO_FS *VirtioFs + ); + +VOID +EFIAPI +VirtioFsExitBoot ( + IN EFI_EVENT ExitBootEvent, + IN VOID *VirtioFsAsVoid + ); + // // EFI_SIMPLE_FILE_SYSTEM_PROTOCOL member functions for the Virtio Filesys= tem // driver. // =20 EFI_STATUS EFIAPI VirtioFsOpenVolume ( diff --git a/OvmfPkg/VirtioFsDxe/DriverBinding.c b/OvmfPkg/VirtioFsDxe/Driv= erBinding.c index 65e45b5c4bf7..b888158a805d 100644 --- a/OvmfPkg/VirtioFsDxe/DriverBinding.c +++ b/OvmfPkg/VirtioFsDxe/DriverBinding.c @@ -1,17 +1,16 @@ /** @file Provide EFI_SIMPLE_FILE_SYSTEM_PROTOCOL instances on virtio-fs devices. =20 Copyright (C) 2020, Red Hat, Inc. =20 SPDX-License-Identifier: BSD-2-Clause-Patent **/ =20 -#include // VIRTIO_SUBSYSTEM_FILESYST= EM #include // AsciiStrCmp() #include // AllocatePool() #include // gBS #include // EFI_COMPONENT_NAME2_PROTO= COL #include // EFI_DRIVER_BINDING_PROTOC= OL =20 #include "VirtioFsDxe.h" =20 @@ -75,28 +74,46 @@ VirtioFsBindingStart ( =20 Status =3D gBS->OpenProtocol (ControllerHandle, &gVirtioDeviceProtocolGu= id, (VOID **)&VirtioFs->Virtio, This->DriverBindingHandle, ControllerHandle, EFI_OPEN_PROTOCOL_BY_DRIVER); if (EFI_ERROR (Status)) { goto FreeVirtioFs; } =20 + Status =3D VirtioFsInit (VirtioFs); + if (EFI_ERROR (Status)) { + goto CloseVirtio; + } + + Status =3D gBS->CreateEvent (EVT_SIGNAL_EXIT_BOOT_SERVICES, TPL_CALLBACK, + VirtioFsExitBoot, VirtioFs, &VirtioFs->ExitBoot); + if (EFI_ERROR (Status)) { + goto UninitVirtioFs; + } + VirtioFs->SimpleFs.Revision =3D EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_REVISI= ON; VirtioFs->SimpleFs.OpenVolume =3D VirtioFsOpenVolume; =20 Status =3D gBS->InstallProtocolInterface (&ControllerHandle, &gEfiSimpleFileSystemProtocolGuid, EFI_NATIVE_INTERFACE, &VirtioFs->SimpleFs); if (EFI_ERROR (Status)) { - goto CloseVirtio; + goto CloseExitBoot; } =20 return EFI_SUCCESS; =20 +CloseExitBoot: + CloseStatus =3D gBS->CloseEvent (VirtioFs->ExitBoot); + ASSERT_EFI_ERROR (CloseStatus); + +UninitVirtioFs: + VirtioFsUninit (VirtioFs); + CloseVirtio: CloseStatus =3D gBS->CloseProtocol (ControllerHandle, &gVirtioDeviceProtocolGuid, This->DriverBindingHand= le, ControllerHandle); ASSERT_EFI_ERROR (CloseStatus); =20 FreeVirtioFs: FreePool (VirtioFs); @@ -128,16 +145,21 @@ VirtioFsBindingStop ( VirtioFs =3D VIRTIO_FS_FROM_SIMPLE_FS (SimpleFs); =20 Status =3D gBS->UninstallProtocolInterface (ControllerHandle, &gEfiSimpleFileSystemProtocolGuid, SimpleFs); if (EFI_ERROR (Status)) { return Status; } =20 + Status =3D gBS->CloseEvent (VirtioFs->ExitBoot); + ASSERT_EFI_ERROR (Status); + + VirtioFsUninit (VirtioFs); + Status =3D gBS->CloseProtocol (ControllerHandle, &gVirtioDeviceProtocolG= uid, This->DriverBindingHandle, ControllerHandle); ASSERT_EFI_ERROR (Status); =20 FreePool (VirtioFs); =20 return EFI_SUCCESS; } diff --git a/OvmfPkg/VirtioFsDxe/Helpers.c b/OvmfPkg/VirtioFsDxe/Helpers.c new file mode 100644 index 000000000000..7b4906c54184 --- /dev/null +++ b/OvmfPkg/VirtioFsDxe/Helpers.c @@ -0,0 +1,299 @@ +/** @file + Initialization and helper routines for the Virtio Filesystem device. + + Copyright (C) 2020, Red Hat, Inc. + + SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#include // Virtio10WriteFeatures() + +#include "VirtioFsDxe.h" + +/** + Read the Virtio Filesystem device configuration structure in full. + + @param[in] Virtio The Virtio protocol underlying the VIRTIO_FS object. + + @param[out] Config The fully populated VIRTIO_FS_CONFIG structure. + + @retval EFI_SUCCESS Config has been filled in. + + @return Error codes propagated from Virtio->ReadDevice(). T= he + contents of Config are indeterminate. +**/ +STATIC +EFI_STATUS +VirtioFsReadConfig ( + IN VIRTIO_DEVICE_PROTOCOL *Virtio, + OUT VIRTIO_FS_CONFIG *Config + ) +{ + UINTN Idx; + EFI_STATUS Status; + + for (Idx =3D 0; Idx < VIRTIO_FS_TAG_BYTES; Idx++) { + Status =3D Virtio->ReadDevice ( + Virtio, // This + OFFSET_OF (VIRTIO_FS_CONFIG, Tag[Idx]), // FieldOff= set + sizeof Config->Tag[Idx], // FieldSize + sizeof Config->Tag[Idx], // BufferSi= ze + &Config->Tag[Idx] // Buffer + ); + if (EFI_ERROR (Status)) { + return Status; + } + } + + Status =3D Virtio->ReadDevice ( + Virtio, // This + OFFSET_OF (VIRTIO_FS_CONFIG, NumReqQueues), // FieldO= ffset + sizeof Config->NumReqQueues, // FieldS= ize + sizeof Config->NumReqQueues, // Buffer= Size + &Config->NumReqQueues // Buffer + ); + return Status; +} + +/** + Configure the Virtio Filesystem device underlying VirtioFs. + + @param[in,out] VirtioFs The VIRTIO_FS object for which Virtio communica= tion + should be set up. On input, the caller is + responsible for VirtioFs->Virtio having been + initialized. On output, synchronous Virtio + Filesystem commands (primitives) may be submitt= ed to + the device. + + @retval EFI_SUCCESS Virtio machinery has been set up. + + @retval EFI_UNSUPPORTED The host-side configuration of the Virtio Files= ystem + is not supported by this driver. + + @return Error codes from underlying functions. +**/ +EFI_STATUS +VirtioFsInit ( + IN OUT VIRTIO_FS *VirtioFs + ) +{ + UINT8 NextDevStat; + EFI_STATUS Status; + UINT64 Features; + VIRTIO_FS_CONFIG Config; + UINTN Idx; + UINT64 RingBaseShift; + + // + // Execute virtio-v1.1-cs01-87fa6b5d8155, 3.1.1 Driver Requirements: Dev= ice + // Initialization. + // + // 1. Reset the device. + // + NextDevStat =3D 0; + Status =3D VirtioFs->Virtio->SetDeviceStatus (VirtioFs->Virtio, NextDevS= tat); + if (EFI_ERROR (Status)) { + goto Failed; + } + + // + // 2. Set the ACKNOWLEDGE status bit [...] + // + NextDevStat |=3D VSTAT_ACK; + Status =3D VirtioFs->Virtio->SetDeviceStatus (VirtioFs->Virtio, NextDevS= tat); + if (EFI_ERROR (Status)) { + goto Failed; + } + + // + // 3. Set the DRIVER status bit [...] + // + NextDevStat |=3D VSTAT_DRIVER; + Status =3D VirtioFs->Virtio->SetDeviceStatus (VirtioFs->Virtio, NextDevS= tat); + if (EFI_ERROR (Status)) { + goto Failed; + } + + // + // 4. Read device feature bits... + // + Status =3D VirtioFs->Virtio->GetDeviceFeatures (VirtioFs->Virtio, &Featu= res); + if (EFI_ERROR (Status)) { + goto Failed; + } + if ((Features & VIRTIO_F_VERSION_1) =3D=3D 0) { + Status =3D EFI_UNSUPPORTED; + goto Failed; + } + // + // No device-specific feature bits have been defined in file "virtio-fs.= tex" + // of the virtio spec at ,= as + // of commit 87fa6b5d8155. + // + Features &=3D VIRTIO_F_VERSION_1 | VIRTIO_F_IOMMU_PLATFORM; + + // + // ... and write the subset of feature bits understood by the [...] driv= er to + // the device. [...] + // 5. Set the FEATURES_OK status bit. + // 6. Re-read device status to ensure the FEATURES_OK bit is still set [= ...] + // + Status =3D Virtio10WriteFeatures (VirtioFs->Virtio, Features, &NextDevSt= at); + if (EFI_ERROR (Status)) { + goto Failed; + } + + // + // 7. Perform device-specific setup, including discovery of virtqueues f= or + // the device, [...] reading [...] the device's virtio configuration spa= ce + // + Status =3D VirtioFsReadConfig (VirtioFs->Virtio, &Config); + if (EFI_ERROR (Status)) { + goto Failed; + } + + // + // 7.a. Convert the filesystem label from UTF-8 to UCS-2. Only labels wi= th + // printable ASCII code points (U+0020 through U+007E) are supported. + // NUL-terminate at either the terminator we find, or right after the + // original label. + // + for (Idx =3D 0; Idx < VIRTIO_FS_TAG_BYTES && Config.Tag[Idx] !=3D '\0'; = Idx++) { + if (Config.Tag[Idx] < 0x20 || Config.Tag[Idx] > 0x7E) { + Status =3D EFI_UNSUPPORTED; + goto Failed; + } + VirtioFs->Label[Idx] =3D Config.Tag[Idx]; + } + VirtioFs->Label[Idx] =3D L'\0'; + + // + // 7.b. We need one queue for sending normal priority requests. + // + if (Config.NumReqQueues < 1) { + Status =3D EFI_UNSUPPORTED; + goto Failed; + } + + // + // 7.c. Fetch and remember the number of descriptors we can place on the + // queue at once. We'll need two descriptors per request, as a minimum -- + // request header, response header. + // + Status =3D VirtioFs->Virtio->SetQueueSel (VirtioFs->Virtio, + VIRTIO_FS_REQUEST_QUEUE); + if (EFI_ERROR (Status)) { + goto Failed; + } + Status =3D VirtioFs->Virtio->GetQueueNumMax (VirtioFs->Virtio, + &VirtioFs->QueueSize); + if (EFI_ERROR (Status)) { + goto Failed; + } + if (VirtioFs->QueueSize < 2) { + Status =3D EFI_UNSUPPORTED; + goto Failed; + } + + // + // 7.d. [...] population of virtqueues [...] + // + Status =3D VirtioRingInit (VirtioFs->Virtio, VirtioFs->QueueSize, + &VirtioFs->Ring); + if (EFI_ERROR (Status)) { + goto Failed; + } + + Status =3D VirtioRingMap (VirtioFs->Virtio, &VirtioFs->Ring, &RingBaseSh= ift, + &VirtioFs->RingMap); + if (EFI_ERROR (Status)) { + goto ReleaseQueue; + } + + Status =3D VirtioFs->Virtio->SetQueueAddress (VirtioFs->Virtio, + &VirtioFs->Ring, RingBaseShift); + if (EFI_ERROR (Status)) { + goto UnmapQueue; + } + + // + // 8. Set the DRIVER_OK status bit. + // + NextDevStat |=3D VSTAT_DRIVER_OK; + Status =3D VirtioFs->Virtio->SetDeviceStatus (VirtioFs->Virtio, NextDevS= tat); + if (EFI_ERROR (Status)) { + goto UnmapQueue; + } + + return EFI_SUCCESS; + +UnmapQueue: + VirtioFs->Virtio->UnmapSharedBuffer (VirtioFs->Virtio, VirtioFs->RingMap= ); + +ReleaseQueue: + VirtioRingUninit (VirtioFs->Virtio, &VirtioFs->Ring); + +Failed: + // + // If any of these steps go irrecoverably wrong, the driver SHOULD set t= he + // FAILED status bit to indicate that it has given up on the device (it = can + // reset the device later to restart if desired). [...] + // + // Virtio access failure here should not mask the original error. + // + NextDevStat |=3D VSTAT_FAILED; + VirtioFs->Virtio->SetDeviceStatus (VirtioFs->Virtio, NextDevStat); + + return Status; +} + +/** + De-configure the Virtio Filesystem device underlying VirtioFs. + + @param[in] VirtioFs The VIRTIO_FS object for which Virtio communication + should be torn down. On input, the caller is respon= sible + for having called VirtioFsInit(). On output, Virtio + Filesystem commands (primitives) must no longer be + submitted to the device. +**/ +VOID +VirtioFsUninit ( + IN OUT VIRTIO_FS *VirtioFs + ) +{ + // + // Resetting the Virtio device makes it release its resources and forget= its + // configuration. + // + VirtioFs->Virtio->SetDeviceStatus (VirtioFs->Virtio, 0); + VirtioFs->Virtio->UnmapSharedBuffer (VirtioFs->Virtio, VirtioFs->RingMap= ); + VirtioRingUninit (VirtioFs->Virtio, &VirtioFs->Ring); +} + +/** + ExitBootServices event notification function for a Virtio Filesystem obj= ect. + + This function resets the VIRTIO_FS.Virtio device, causing it to release = all + references to guest-side resources. The function may only be called after + VirtioFsInit() returns successfully and before VirtioFsUninit() is calle= d. + + @param[in] ExitBootEvent The VIRTIO_FS.ExitBoot event that has been + signaled. + + @param[in] VirtioFsAsVoid Pointer to the VIRTIO_FS object, passed in as + (VOID*). +**/ +VOID +EFIAPI +VirtioFsExitBoot ( + IN EFI_EVENT ExitBootEvent, + IN VOID *VirtioFsAsVoid + ) +{ + VIRTIO_FS *VirtioFs; + + VirtioFs =3D VirtioFsAsVoid; + DEBUG ((DEBUG_VERBOSE, "%a: VirtioFs=3D0x%p Label=3D\"%s\"\n", __FUNCTIO= N__, + VirtioFsAsVoid, VirtioFs->Label)); + VirtioFs->Virtio->SetDeviceStatus (VirtioFs->Virtio, 0); +} --=20 2.19.1.3.g30247aa5d201 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#69016): https://edk2.groups.io/g/devel/message/69016 Mute This Topic: https://groups.io/mt/79022663/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Tue May 7 07:56:31 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+69017+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+69017+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1608153750; cv=none; d=zohomail.com; s=zohoarc; b=EvHzr+V784kK/UcrtSVxzjz+NrFtheI56bk3FVPtJduhKRmX7yNJ5yNeikpLq6IP7zARg/qVv+CqcL5YTxjo8LKVP/YR5ohhucK9lSJvudscSKPpU3Y32KVvozR9DSSm+dLkJqLuiH+riW7ITSsAfIwwrmW1b5ZBZcUh6Fitqbo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608153750; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=ZRzFvdbgKJYDAaqPEIBe6MX82ECv6CP+9xvQyU+nSuA=; b=Dm1nJGqNwZO4dRc3SwhKHf714ip1WkzRLUOV8y+dP7bxseHUEXsSga4s5XZGSjADi0pWRSUx8n7QrmqVsXQ1zebBsENBH+ChColCiC/qORkJdN0lXLStdVPshFEZjW4ZkN3U1hX+7eBjfxuPByZCYUSBPwfT2UqnBcinMuxjDJw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+69017+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) header.from= Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1608153750620762.587584904536; Wed, 16 Dec 2020 13:22:30 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id KcXsYY1788612xvXaXn00aVO; Wed, 16 Dec 2020 13:22:30 -0800 X-Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.groups.io with SMTP id smtpd.web12.3669.1608153726585386411 for ; Wed, 16 Dec 2020 13:22:06 -0800 X-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-283-BJZrqRp7Oom_xj7wf29ztQ-1; Wed, 16 Dec 2020 16:22:03 -0500 X-MC-Unique: BJZrqRp7Oom_xj7wf29ztQ-1 X-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 842F651087; Wed, 16 Dec 2020 21:22:02 +0000 (UTC) X-Received: from lacos-laptop-7.usersys.redhat.com (ovpn-114-152.ams2.redhat.com [10.36.114.152]) by smtp.corp.redhat.com (Postfix) with ESMTP id 862B660CCC; Wed, 16 Dec 2020 21:21:57 +0000 (UTC) From: "Laszlo Ersek" To: devel@edk2.groups.io, virtio-fs@redhat.com, lersek@redhat.com Cc: Ard Biesheuvel , Jordan Justen , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [edk2-devel] [edk2 PATCH 05/48] OvmfPkg/VirtioFsDxe: add a scatter-gather list data type Date: Wed, 16 Dec 2020 22:10:42 +0100 Message-Id: <20201216211125.19496-6-lersek@redhat.com> In-Reply-To: <20201216211125.19496-1-lersek@redhat.com> References: <20201216211125.19496-1-lersek@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,lersek@redhat.com X-Gm-Message-State: WMHQH9svfZpLImgDvjE9sYVIx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1608153750; bh=ZRzFvdbgKJYDAaqPEIBe6MX82ECv6CP+9xvQyU+nSuA=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=s7A/tzm4ElskdAWpm+Sh1hnqOlMxFRghivAvofMnff8yPX+bglaDkHqsnnuviUkIzJV n3nxnRZ7GYbwltjRLrbVQeQpYLypOIXNMcBN64EJxC2yjKFrqNhFCE0U3TM/wiPJJBjTL bomox9tbnDWeVh/nxW6mgRqppLoY5efXOoI= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" In preparation for the variously structured FUSE request/response exchanges that virtio-fs uses, introduce a scatter-gather list data type. This will let us express FUSE request-response pairs flexibly. Add a function for validating whether a (request buffer list, response buffer list) pair is well-formed, and supported by the Virtio Filesystem device's queue depth. Add another function for mapping and submitting a validated pair of scatter-gather lists to the Virtio Filesystem device. Cc: Ard Biesheuvel Cc: Jordan Justen Cc: Philippe Mathieu-Daud=C3=A9 Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3097 Signed-off-by: Laszlo Ersek Acked-by: Ard Biesheuvel --- OvmfPkg/VirtioFsDxe/VirtioFsDxe.h | 60 +++ OvmfPkg/VirtioFsDxe/Helpers.c | 401 ++++++++++++++++++++ 2 files changed, 461 insertions(+) diff --git a/OvmfPkg/VirtioFsDxe/VirtioFsDxe.h b/OvmfPkg/VirtioFsDxe/Virtio= FsDxe.h index 2aae96ecd79a..12acbd6dc359 100644 --- a/OvmfPkg/VirtioFsDxe/VirtioFsDxe.h +++ b/OvmfPkg/VirtioFsDxe/VirtioFsDxe.h @@ -46,16 +46,62 @@ typedef struct { VOID *RingMap; // VirtioRingMap 2 EFI_EVENT ExitBoot; // DriverBindingStart 0 EFI_SIMPLE_FILE_SYSTEM_PROTOCOL SimpleFs; // DriverBindingStart 0 } VIRTIO_FS; =20 #define VIRTIO_FS_FROM_SIMPLE_FS(SimpleFsReference) \ CR (SimpleFsReference, VIRTIO_FS, SimpleFs, VIRTIO_FS_SIG); =20 +// +// Structure for describing a contiguous buffer, potentially mapped for Vi= rtio +// transfer. +// +typedef struct { + // + // The following fields originate from the owner of the buffer. + // + VOID *Buffer; + UINTN Size; + // + // All of the fields below, until the end of the structure, are + // zero-initialized when the structure is initially validated. + // + // Mapped, MappedAddress and Mapping are updated when the buffer is mapp= ed + // for VirtioOperationBusMasterRead or VirtioOperationBusMasterWrite. Th= ey + // are again updated when the buffer is unmapped. + // + BOOLEAN Mapped; + EFI_PHYSICAL_ADDRESS MappedAddress; + VOID *Mapping; + // + // Transferred is updated after VirtioFlush() returns successfully: + // - for VirtioOperationBusMasterRead, Transferred is set to Size; + // - for VirtioOperationBusMasterWrite, Transferred is calculated from t= he + // UsedLen output parameter of VirtioFlush(). + // + UINTN Transferred; +} VIRTIO_FS_IO_VECTOR; + +// +// Structure for describing a list of IO Vectors. +// +typedef struct { + // + // The following fields originate from the owner of the buffers. + // + VIRTIO_FS_IO_VECTOR *IoVec; + UINTN NumVec; + // + // TotalSize is calculated when the scatter-gather list is initially + // validated. + // + UINT32 TotalSize; +} VIRTIO_FS_SCATTER_GATHER_LIST; + // // Initialization and helper routines for the Virtio Filesystem device. // =20 EFI_STATUS VirtioFsInit ( IN OUT VIRTIO_FS *VirtioFs ); @@ -67,16 +113,30 @@ VirtioFsUninit ( =20 VOID EFIAPI VirtioFsExitBoot ( IN EFI_EVENT ExitBootEvent, IN VOID *VirtioFsAsVoid ); =20 +EFI_STATUS +VirtioFsSgListsValidate ( + IN VIRTIO_FS *VirtioFs, + IN OUT VIRTIO_FS_SCATTER_GATHER_LIST *RequestSgList, + IN OUT VIRTIO_FS_SCATTER_GATHER_LIST *ResponseSgList OPTIONAL + ); + +EFI_STATUS +VirtioFsSgListsSubmit ( + IN OUT VIRTIO_FS *VirtioFs, + IN OUT VIRTIO_FS_SCATTER_GATHER_LIST *RequestSgList, + IN OUT VIRTIO_FS_SCATTER_GATHER_LIST *ResponseSgList OPTIONAL + ); + // // EFI_SIMPLE_FILE_SYSTEM_PROTOCOL member functions for the Virtio Filesys= tem // driver. // =20 EFI_STATUS EFIAPI VirtioFsOpenVolume ( diff --git a/OvmfPkg/VirtioFsDxe/Helpers.c b/OvmfPkg/VirtioFsDxe/Helpers.c index 7b4906c54184..88264d4b264c 100644 --- a/OvmfPkg/VirtioFsDxe/Helpers.c +++ b/OvmfPkg/VirtioFsDxe/Helpers.c @@ -292,8 +292,409 @@ VirtioFsExitBoot ( { VIRTIO_FS *VirtioFs; =20 VirtioFs =3D VirtioFsAsVoid; DEBUG ((DEBUG_VERBOSE, "%a: VirtioFs=3D0x%p Label=3D\"%s\"\n", __FUNCTIO= N__, VirtioFsAsVoid, VirtioFs->Label)); VirtioFs->Virtio->SetDeviceStatus (VirtioFs->Virtio, 0); } + +/** + Validate two VIRTIO_FS_SCATTER_GATHER_LIST objects -- list of request + buffers, list of response buffers -- together. + + On input, the caller is required to populate the following fields: + - VIRTIO_FS_IO_VECTOR.Buffer, + - VIRTIO_FS_IO_VECTOR.Size, + - VIRTIO_FS_SCATTER_GATHER_LIST.IoVec, + - VIRTIO_FS_SCATTER_GATHER_LIST.NumVec. + + On output (on successful return), the following fields will be + zero-initialized: + - VIRTIO_FS_IO_VECTOR.Mapped, + - VIRTIO_FS_IO_VECTOR.MappedAddress, + - VIRTIO_FS_IO_VECTOR.Mapping, + - VIRTIO_FS_IO_VECTOR.Transferred. + + On output (on successful return), the following fields will be calculate= d: + - VIRTIO_FS_SCATTER_GATHER_LIST.TotalSize. + + The function may only be called after VirtioFsInit() returns successfull= y and + before VirtioFsUninit() is called. + + @param[in] VirtioFs The Virtio Filesystem device that the + request-response exchange, expressed via + RequestSgList and ResponseSgList, will be + submitted to. + + @param[in,out] RequestSgList The scatter-gather list that describes the + request part of the exchange -- the buffe= rs + that should be sent to the Virtio Filesys= tem + device in the virtio transfer. + + @param[in,out] ResponseSgList The scatter-gather list that describes the + response part of the exchange -- the buff= ers + that the Virtio Filesystem device should + populate in the virtio transfer. May be N= ULL + if the exchange with the Virtio Filesystem + device consists of a request only, with t= he + response part omitted altogether. + + @retval EFI_SUCCESS RequestSgList and ResponseSgList have been + validated, output fields have been set. + + @retval EFI_INVALID_PARAMETER RequestSgList is NULL. + + @retval EFI_INVALID_PARAMETER On input, a + VIRTIO_FS_SCATTER_GATHER_LIST.IoVec field= is + NULL, or a + VIRTIO_FS_SCATTER_GATHER_LIST.NumVec fiel= d is + zero. + + @retval EFI_INVALID_PARAMETER On input, a VIRTIO_FS_IO_VECTOR.Buffer fi= eld + is NULL, or a VIRTIO_FS_IO_VECTOR.Size fi= eld + is zero. + + @retval EFI_UNSUPPORTED (RequestSgList->NumVec + + ResponseSgList->NumVec) exceeds + VirtioFs->QueueSize, meaning that the tot= al + list of buffers cannot be placed on the v= irtio + queue in a single descriptor chain (with = one + descriptor per buffer). + + @retval EFI_UNSUPPORTED One of the + VIRTIO_FS_SCATTER_GATHER_LIST.TotalSize f= ields + would exceed MAX_UINT32. +**/ +EFI_STATUS +VirtioFsSgListsValidate ( + IN VIRTIO_FS *VirtioFs, + IN OUT VIRTIO_FS_SCATTER_GATHER_LIST *RequestSgList, + IN OUT VIRTIO_FS_SCATTER_GATHER_LIST *ResponseSgList OPTIONAL + ) +{ + VIRTIO_FS_SCATTER_GATHER_LIST *SgListParam[2]; + UINT16 DescriptorsNeeded; + UINTN ListId; + + if (RequestSgList =3D=3D NULL) { + return EFI_INVALID_PARAMETER; + } + + SgListParam[0] =3D RequestSgList; + SgListParam[1] =3D ResponseSgList; + + DescriptorsNeeded =3D 0; + for (ListId =3D 0; ListId < ARRAY_SIZE (SgListParam); ListId++) { + VIRTIO_FS_SCATTER_GATHER_LIST *SgList; + UINT32 SgListTotalSize; + UINTN IoVecIdx; + + SgList =3D SgListParam[ListId]; + if (SgList =3D=3D NULL) { + continue; + } + // + // Sanity-check SgList -- it must provide at least one IO Vector. + // + if (SgList->IoVec =3D=3D NULL || SgList->NumVec =3D=3D 0) { + return EFI_INVALID_PARAMETER; + } + // + // Make sure that, for each IO Vector in this SgList, a virtio descrip= tor + // can be added to the virtio queue, after the other descriptors added + // previously. + // + if (SgList->NumVec > MAX_UINT16 - DescriptorsNeeded || + DescriptorsNeeded + SgList->NumVec > VirtioFs->QueueSize) { + return EFI_UNSUPPORTED; + } + DescriptorsNeeded +=3D (UINT16)SgList->NumVec; + + SgListTotalSize =3D 0; + for (IoVecIdx =3D 0; IoVecIdx < SgList->NumVec; IoVecIdx++) { + VIRTIO_FS_IO_VECTOR *IoVec; + + IoVec =3D &SgList->IoVec[IoVecIdx]; + // + // Sanity-check this IoVec -- it must describe a non-empty buffer. + // + if (IoVec->Buffer =3D=3D NULL || IoVec->Size =3D=3D 0) { + return EFI_INVALID_PARAMETER; + } + // + // Make sure the cumulative size of all IO Vectors in this SgList re= mains + // expressible as a UINT32. + // + if (IoVec->Size > MAX_UINT32 - SgListTotalSize) { + return EFI_UNSUPPORTED; + } + SgListTotalSize +=3D (UINT32)IoVec->Size; + + // + // Initialize those fields in this IO Vector that will be updated in + // relation to mapping / transfer. + // + IoVec->Mapped =3D FALSE; + IoVec->MappedAddress =3D 0; + IoVec->Mapping =3D NULL; + IoVec->Transferred =3D 0; + } + + // + // Store the cumulative size of all IO Vectors that we have calculated= in + // this SgList. + // + SgList->TotalSize =3D SgListTotalSize; + } + + return EFI_SUCCESS; +} + +/** + Submit a validated pair of (request buffer list, response buffer list) t= o the + Virtio Filesystem device. + + On input, the pair of VIRTIO_FS_SCATTER_GATHER_LIST objects must have be= en + validated together, using the VirtioFsSgListsValidate() function. + + On output (on successful return), the following fields will be re-initia= lized + to zero (after temporarily setting them to different values): + - VIRTIO_FS_IO_VECTOR.Mapped, + - VIRTIO_FS_IO_VECTOR.MappedAddress, + - VIRTIO_FS_IO_VECTOR.Mapping. + + On output (on successful return), the following fields will be calculate= d: + - VIRTIO_FS_IO_VECTOR.Transferred. + + The function may only be called after VirtioFsInit() returns successfull= y and + before VirtioFsUninit() is called. + + @param[in,out] VirtioFs The Virtio Filesystem device that the + request-response exchange, expressed via + RequestSgList and ResponseSgList, should = now + be submitted to. + + @param[in,out] RequestSgList The scatter-gather list that describes the + request part of the exchange -- the buffe= rs + that should be sent to the Virtio Filesys= tem + device in the virtio transfer. + + @param[in,out] ResponseSgList The scatter-gather list that describes the + response part of the exchange -- the buff= ers + that the Virtio Filesystem device should + populate in the virtio transfer. May be N= ULL + if and only if NULL was passed to + VirtioFsSgListsValidate() as ResponseSgLi= st. + + @retval EFI_SUCCESS Transfer complete. The caller should investiga= te + the VIRTIO_FS_IO_VECTOR.Transferred fields in + ResponseSgList, to ensure coverage of the rele= vant + response buffers. Subsequently, the caller sho= uld + investigate the contents of those buffers. + + @retval EFI_DEVICE_ERROR The Virtio Filesystem device reported populati= ng + more response bytes than ResponseSgList->Total= Size. + + @return Error codes propagated from + VirtioMapAllBytesInSharedBuffer(), VirtioFlush= (), + or VirtioFs->Virtio->UnmapSharedBuffer(). +**/ +EFI_STATUS +VirtioFsSgListsSubmit ( + IN OUT VIRTIO_FS *VirtioFs, + IN OUT VIRTIO_FS_SCATTER_GATHER_LIST *RequestSgList, + IN OUT VIRTIO_FS_SCATTER_GATHER_LIST *ResponseSgList OPTIONAL + ) +{ + VIRTIO_FS_SCATTER_GATHER_LIST *SgListParam[2]; + VIRTIO_MAP_OPERATION SgListVirtioMapOp[ARRAY_SIZE (SgListParam)= ]; + UINT16 SgListDescriptorFlag[ARRAY_SIZE (SgListPar= am)]; + UINTN ListId; + VIRTIO_FS_SCATTER_GATHER_LIST *SgList; + UINTN IoVecIdx; + VIRTIO_FS_IO_VECTOR *IoVec; + EFI_STATUS Status; + DESC_INDICES Indices; + UINT32 TotalBytesWrittenByDevice; + UINT32 BytesPermittedForWrite; + + SgListParam[0] =3D RequestSgList; + SgListVirtioMapOp[0] =3D VirtioOperationBusMasterRead; + SgListDescriptorFlag[0] =3D 0; + + SgListParam[1] =3D ResponseSgList; + SgListVirtioMapOp[1] =3D VirtioOperationBusMasterWrite; + SgListDescriptorFlag[1] =3D VRING_DESC_F_WRITE; + + // + // Map all IO Vectors. + // + for (ListId =3D 0; ListId < ARRAY_SIZE (SgListParam); ListId++) { + SgList =3D SgListParam[ListId]; + if (SgList =3D=3D NULL) { + continue; + } + for (IoVecIdx =3D 0; IoVecIdx < SgList->NumVec; IoVecIdx++) { + IoVec =3D &SgList->IoVec[IoVecIdx]; + // + // Map this IO Vector. + // + Status =3D VirtioMapAllBytesInSharedBuffer ( + VirtioFs->Virtio, + SgListVirtioMapOp[ListId], + IoVec->Buffer, + IoVec->Size, + &IoVec->MappedAddress, + &IoVec->Mapping + ); + if (EFI_ERROR (Status)) { + goto Unmap; + } + IoVec->Mapped =3D TRUE; + } + } + + // + // Compose the descriptor chain. + // + VirtioPrepare (&VirtioFs->Ring, &Indices); + for (ListId =3D 0; ListId < ARRAY_SIZE (SgListParam); ListId++) { + SgList =3D SgListParam[ListId]; + if (SgList =3D=3D NULL) { + continue; + } + for (IoVecIdx =3D 0; IoVecIdx < SgList->NumVec; IoVecIdx++) { + UINT16 NextFlag; + + IoVec =3D &SgList->IoVec[IoVecIdx]; + // + // Set VRING_DESC_F_NEXT on all except the very last descriptor. + // + NextFlag =3D VRING_DESC_F_NEXT; + if (ListId =3D=3D ARRAY_SIZE (SgListParam) - 1 && + IoVecIdx =3D=3D SgList->NumVec - 1) { + NextFlag =3D 0; + } + VirtioAppendDesc ( + &VirtioFs->Ring, + IoVec->MappedAddress, + (UINT32)IoVec->Size, + SgListDescriptorFlag[ListId] | NextFlag, + &Indices + ); + } + } + + // + // Submit the descriptor chain. + // + Status =3D VirtioFlush (VirtioFs->Virtio, VIRTIO_FS_REQUEST_QUEUE, + &VirtioFs->Ring, &Indices, &TotalBytesWrittenByDevice); + if (EFI_ERROR (Status)) { + goto Unmap; + } + + // + // Sanity-check: the Virtio Filesystem device should not have written mo= re + // bytes than what we offered buffers for. + // + if (ResponseSgList =3D=3D NULL) { + BytesPermittedForWrite =3D 0; + } else { + BytesPermittedForWrite =3D ResponseSgList->TotalSize; + } + if (TotalBytesWrittenByDevice > BytesPermittedForWrite) { + Status =3D EFI_DEVICE_ERROR; + goto Unmap; + } + + // + // Update the transfer sizes in the IO Vectors. + // + for (ListId =3D 0; ListId < ARRAY_SIZE (SgListParam); ListId++) { + SgList =3D SgListParam[ListId]; + if (SgList =3D=3D NULL) { + continue; + } + for (IoVecIdx =3D 0; IoVecIdx < SgList->NumVec; IoVecIdx++) { + IoVec =3D &SgList->IoVec[IoVecIdx]; + if (SgListVirtioMapOp[ListId] =3D=3D VirtioOperationBusMasterRead) { + // + // We report that the Virtio Filesystem device has read all buffer= s in + // the request. + // + IoVec->Transferred =3D IoVec->Size; + } else { + // + // Regarding the response, calculate how much of the current IO Ve= ctor + // has been populated by the Virtio Filesystem device. In + // "TotalBytesWrittenByDevice", VirtioFlush() reported the total c= ount + // across all device-writeable descriptors, in the order they were + // chained on the ring. + // + IoVec->Transferred =3D MIN ((UINTN)TotalBytesWrittenByDevice, + IoVec->Size); + TotalBytesWrittenByDevice -=3D (UINT32)IoVec->Transferred; + } + } + } + + // + // By now, "TotalBytesWrittenByDevice" has been exhausted. + // + ASSERT (TotalBytesWrittenByDevice =3D=3D 0); + + // + // We've succeeded; fall through. + // +Unmap: + // + // Unmap all mapped IO Vectors on both the success and the error paths. = The + // unmapping occurs in reverse order of mapping, in an attempt to avoid + // memory fragmentation. + // + ListId =3D ARRAY_SIZE (SgListParam); + while (ListId > 0) { + --ListId; + SgList =3D SgListParam[ListId]; + if (SgList =3D=3D NULL) { + continue; + } + IoVecIdx =3D SgList->NumVec; + while (IoVecIdx > 0) { + EFI_STATUS UnmapStatus; + + --IoVecIdx; + IoVec =3D &SgList->IoVec[IoVecIdx]; + // + // Unmap this IO Vector, if it has been mapped. + // + if (!IoVec->Mapped) { + continue; + } + UnmapStatus =3D VirtioFs->Virtio->UnmapSharedBuffer (VirtioFs->Virti= o, + IoVec->Mapping); + // + // Re-set the following fields to the values they initially got from + // VirtioFsSgListsValidate() -- the above unmapping attempt is consi= dered + // final, even if it fails. + // + IoVec->Mapped =3D FALSE; + IoVec->MappedAddress =3D 0; + IoVec->Mapping =3D NULL; + + // + // If we are on the success path, but the unmapping failed, we need = to + // transparently flip to the failure path -- the caller must learn t= hey + // should not consult the response buffers. + // + // The branch below can be taken at most once. + // + if (!EFI_ERROR (Status) && EFI_ERROR (UnmapStatus)) { + Status =3D UnmapStatus; + } + } + } + + return Status; +} --=20 2.19.1.3.g30247aa5d201 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#69017): https://edk2.groups.io/g/devel/message/69017 Mute This Topic: https://groups.io/mt/79022703/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Tue May 7 07:56:31 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+69018+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+69018+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1608153856; cv=none; d=zohomail.com; s=zohoarc; b=UK3Yel52201LAu5dLkttZyBGOQolbMXV66oA0TJFnS3lc10wQqD01pBetJmTLz604s50Ngoh8QehyNJusdFMXaB7xZv9OkRPaiWoFsw1Uqk//39eVc39KdT7ez8ComFGBXIQ1noEzZInynIojFUOIwr83NOTJDZMDLeursk6u28= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608153856; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=kdZQTJyDWBZfJ2q1WLmC7COMYyXy4dUBCFcfLbXkKOo=; b=REvFjG31pGxkRUukY3Tjx0jd8lbLNOYiR/KJrQTXc6afrbh6Bsg9EYFlIo/Vlq4N2PaMzwetp4C4NDaDIvEAAGgL2pYXNM+ZAAANqrxuBOvsKhgt6Zh63Wv2Pfu22b3FDlBSiv1X5vRxADSw+dDEzpNjV+Bngr/+me0ODtSdFTg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+69018+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) header.from= Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1608153856174828.2606745102536; Wed, 16 Dec 2020 13:24:16 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id Ms99YY1788612xrQ2BZMWt3H; Wed, 16 Dec 2020 13:24:15 -0800 X-Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.groups.io with SMTP id smtpd.web08.3697.1608153855121705399 for ; Wed, 16 Dec 2020 13:24:15 -0800 X-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-286-kePgENsbOpehwtsgKUbhAg-1; Wed, 16 Dec 2020 16:24:09 -0500 X-MC-Unique: kePgENsbOpehwtsgKUbhAg-1 X-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 AA7BB800D62; Wed, 16 Dec 2020 21:24:08 +0000 (UTC) X-Received: from lacos-laptop-7.usersys.redhat.com (ovpn-114-152.ams2.redhat.com [10.36.114.152]) by smtp.corp.redhat.com (Postfix) with ESMTP id BAB9A10021B3; Wed, 16 Dec 2020 21:24:03 +0000 (UTC) From: "Laszlo Ersek" To: devel@edk2.groups.io, virtio-fs@redhat.com, lersek@redhat.com Cc: Ard Biesheuvel , Jordan Justen , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [edk2-devel] [edk2 PATCH 06/48] OvmfPkg/VirtioFsDxe: introduce the basic FUSE request/response headers Date: Wed, 16 Dec 2020 22:10:43 +0100 Message-Id: <20201216211125.19496-7-lersek@redhat.com> In-Reply-To: <20201216211125.19496-1-lersek@redhat.com> References: <20201216211125.19496-1-lersek@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,lersek@redhat.com X-Gm-Message-State: L5DCmxsDEIyfZQfsxjMO7qXSx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1608153855; bh=kdZQTJyDWBZfJ2q1WLmC7COMYyXy4dUBCFcfLbXkKOo=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=uMFTqMIOYFlndQUH6qK+ZlwY52AIDMwtRWRcU4zui1lBgP11M6yRmL7HmeCm2wqHBm8 yWUL03K3MAN7hru4SaGm+kFaG1OR7MGC0imfiBqZ1P5MiB2lnVyBf3phpoyB0T1iMtRev O+6Ty4QJsJbOPLw710RSSHvzLiTf9wWJldM= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" Introduce the VIRTIO_FS_FUSE_REQUEST and VIRTIO_FS_FUSE_RESPONSE structures, which are the common headers for the various FUSE request/response structures. Introduce the VirtioFsFuseNewRequest() helper function for populating VIRTIO_FS_FUSE_REQUEST, from parameters and from a VIRTIO_FS-level request counter. Introduce the VirtioFsFuseCheckResponse() helper function for verifying most FUSE response types that begin with the VIRTIO_FS_FUSE_RESPONSE header. Cc: Ard Biesheuvel Cc: Jordan Justen Cc: Philippe Mathieu-Daud=C3=A9 Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3097 Signed-off-by: Laszlo Ersek Acked-by: Ard Biesheuvel --- OvmfPkg/Include/IndustryStandard/VirtioFs.h | 49 +++++ OvmfPkg/VirtioFsDxe/VirtioFsDxe.h | 17 ++ OvmfPkg/VirtioFsDxe/DriverBinding.c | 5 + OvmfPkg/VirtioFsDxe/Helpers.c | 216 ++++++++++++++++++++ 4 files changed, 287 insertions(+) diff --git a/OvmfPkg/Include/IndustryStandard/VirtioFs.h b/OvmfPkg/Include/= IndustryStandard/VirtioFs.h index ea7d80d15d0b..521288b03f1c 100644 --- a/OvmfPkg/Include/IndustryStandard/VirtioFs.h +++ b/OvmfPkg/Include/IndustryStandard/VirtioFs.h @@ -44,9 +44,58 @@ typedef struct { // // The total number of request virtqueues exposed by the device (i.e., // excluding the "hiprio" queue). // UINT32 NumReqQueues; } VIRTIO_FS_CONFIG; #pragma pack () =20 +// +// FUSE-related definitions follow. +// +// From virtio-v1.1-cs01-87fa6b5d8155, 5.11 File System Device: "[...] The +// driver acts as the FUSE client mounting the file system. The virtio file +// system device provides the mechanism for transporting FUSE requests [..= .]" +// +// Unfortunately, the documentation of the FUSE wire protocol is lacking. = The +// Virtio spec (as of this writing) simply defers to +// "include/uapi/linux/fuse.h" in the Linux kernel source -- see the refer= ence +// in virtio spec file "introduction.tex", at commit 87fa6b5d8155. +// +// Of course, "include/uapi/linux/fuse.h" is a moving target (the virtio s= pec +// does not specify a particular FUSE interface version). The OvmfPkg code +// targets version 7.31, because that's the lowest version that the QEMU +// virtio-fs daemon supports at this time -- see QEMU commit 72c42e2d6551 +// ("virtiofsd: Trim out compatibility code", 2020-01-23). +// +// Correspondingly, Linux's "include/uapi/linux/fuse.h" is consulted as ch= ecked +// out at commit (c6ff213fe5b8^) =3D d78092e4937d ("fuse: fix page derefer= ence +// after free", 2020-09-18); that is, right before commit c6ff213fe5b8 ("f= use: +// add submount support to ", 2020-09-18) introduces FU= SE +// interface version 7.32. +// +#define VIRTIO_FS_FUSE_MAJOR 7 +#define VIRTIO_FS_FUSE_MINOR 31 + +#pragma pack (1) +// +// Request-response headers common to all request types. +// +typedef struct { + UINT32 Len; + UINT32 Opcode; + UINT64 Unique; + UINT64 NodeId; + UINT32 Uid; + UINT32 Gid; + UINT32 Pid; + UINT32 Padding; +} VIRTIO_FS_FUSE_REQUEST; + +typedef struct { + UINT32 Len; + INT32 Error; + UINT64 Unique; +} VIRTIO_FS_FUSE_RESPONSE; +#pragma pack () + #endif // VIRTIO_FS_H_ diff --git a/OvmfPkg/VirtioFsDxe/VirtioFsDxe.h b/OvmfPkg/VirtioFsDxe/Virtio= FsDxe.h index 12acbd6dc359..f7eae9a4b71a 100644 --- a/OvmfPkg/VirtioFsDxe/VirtioFsDxe.h +++ b/OvmfPkg/VirtioFsDxe/VirtioFsDxe.h @@ -39,16 +39,17 @@ typedef struct { // field init function init d= epth // ----------- ------------------ ------= ---- UINT64 Signature; // DriverBindingStart 0 VIRTIO_DEVICE_PROTOCOL *Virtio; // DriverBindingStart 0 VIRTIO_FS_LABEL Label; // VirtioFsInit 1 UINT16 QueueSize; // VirtioFsInit 1 VRING Ring; // VirtioRingInit 2 VOID *RingMap; // VirtioRingMap 2 + UINT64 RequestId; // DriverBindingStart 0 EFI_EVENT ExitBoot; // DriverBindingStart 0 EFI_SIMPLE_FILE_SYSTEM_PROTOCOL SimpleFs; // DriverBindingStart 0 } VIRTIO_FS; =20 #define VIRTIO_FS_FROM_SIMPLE_FS(SimpleFsReference) \ CR (SimpleFsReference, VIRTIO_FS, SimpleFs, VIRTIO_FS_SIG); =20 // @@ -127,16 +128,32 @@ VirtioFsSgListsValidate ( =20 EFI_STATUS VirtioFsSgListsSubmit ( IN OUT VIRTIO_FS *VirtioFs, IN OUT VIRTIO_FS_SCATTER_GATHER_LIST *RequestSgList, IN OUT VIRTIO_FS_SCATTER_GATHER_LIST *ResponseSgList OPTIONAL ); =20 +EFI_STATUS +VirtioFsFuseNewRequest ( + IN OUT VIRTIO_FS *VirtioFs, + OUT VIRTIO_FS_FUSE_REQUEST *Request, + IN UINT32 RequestSize, + IN UINT32 Opcode, + IN UINT64 NodeId + ); + +EFI_STATUS +VirtioFsFuseCheckResponse ( + IN VIRTIO_FS_SCATTER_GATHER_LIST *ResponseSgList, + IN UINT64 RequestId, + OUT UINTN *TailBufferFill + ); + // // EFI_SIMPLE_FILE_SYSTEM_PROTOCOL member functions for the Virtio Filesys= tem // driver. // =20 EFI_STATUS EFIAPI VirtioFsOpenVolume ( diff --git a/OvmfPkg/VirtioFsDxe/DriverBinding.c b/OvmfPkg/VirtioFsDxe/Driv= erBinding.c index b888158a805d..4a2787a50a6e 100644 --- a/OvmfPkg/VirtioFsDxe/DriverBinding.c +++ b/OvmfPkg/VirtioFsDxe/DriverBinding.c @@ -79,16 +79,21 @@ VirtioFsBindingStart ( goto FreeVirtioFs; } =20 Status =3D VirtioFsInit (VirtioFs); if (EFI_ERROR (Status)) { goto CloseVirtio; } =20 + // + // Initialize the FUSE request counter. + // + VirtioFs->RequestId =3D 1; + Status =3D gBS->CreateEvent (EVT_SIGNAL_EXIT_BOOT_SERVICES, TPL_CALLBACK, VirtioFsExitBoot, VirtioFs, &VirtioFs->ExitBoot); if (EFI_ERROR (Status)) { goto UninitVirtioFs; } =20 VirtioFs->SimpleFs.Revision =3D EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_REVISI= ON; VirtioFs->SimpleFs.OpenVolume =3D VirtioFsOpenVolume; diff --git a/OvmfPkg/VirtioFsDxe/Helpers.c b/OvmfPkg/VirtioFsDxe/Helpers.c index 88264d4b264c..5bd2dc641f6d 100644 --- a/OvmfPkg/VirtioFsDxe/Helpers.c +++ b/OvmfPkg/VirtioFsDxe/Helpers.c @@ -693,8 +693,224 @@ VirtioFsSgListsSubmit ( if (!EFI_ERROR (Status) && EFI_ERROR (UnmapStatus)) { Status =3D UnmapStatus; } } } =20 return Status; } + +/** + Set up the fields of a new VIRTIO_FS_FUSE_REQUEST object. + + The function may only be called after VirtioFsInit() returns successfull= y and + before VirtioFsUninit() is called. + + @param[in,out] VirtioFs The Virtio Filesystem device that the request is + being prepared for. The "VirtioFs->RequestId" fi= eld + will be copied into "Request->Unique". On output= (on + successful return), "VirtioFs->RequestId" will be + incremented. + + @param[out] Request The VIRTIO_FS_FUSE_REQUEST object whose fields a= re to + be set. + + @param[in] RequestSize The total size of the request, including + sizeof(VIRTIO_FS_FUSE_REQUEST). + + @param[in] Opcode The VIRTIO_FS_FUSE_OPCODE that identifies the co= mmand + to send. + + @param[in] NodeId The inode number of the file that the request re= fers + to. + + @retval EFI_INVALID_PARAMETER RequestSize is smaller than + sizeof(VIRTIO_FS_FUSE_REQUEST). + + @retval EFI_OUT_OF_RESOURCES "VirtioFs->RequestId" is MAX_UINT64, and = can + be incremented no more. + + @retval EFI_SUCCESS Request has been populated, + "VirtioFs->RequestId" has been incremente= d. +**/ +EFI_STATUS +VirtioFsFuseNewRequest ( + IN OUT VIRTIO_FS *VirtioFs, + OUT VIRTIO_FS_FUSE_REQUEST *Request, + IN UINT32 RequestSize, + IN UINT32 Opcode, + IN UINT64 NodeId + ) +{ + if (RequestSize < sizeof *Request) { + return EFI_INVALID_PARAMETER; + } + + if (VirtioFs->RequestId =3D=3D MAX_UINT64) { + return EFI_OUT_OF_RESOURCES; + } + + Request->Len =3D RequestSize; + Request->Opcode =3D Opcode; + Request->Unique =3D VirtioFs->RequestId++; + Request->NodeId =3D NodeId; + Request->Uid =3D 0; + Request->Gid =3D 0; + Request->Pid =3D 1; + Request->Padding =3D 0; + + return EFI_SUCCESS; +} + +/** + Check the common FUSE response format. + + The first buffer in the response scatter-gather list is assumed a + VIRTIO_FS_FUSE_RESPONSE structure. Subsequent response buffers, if any, = up to + and excluding the last one, are assumed fixed size. The last response bu= ffer + may or may not be fixed size, as specified by the caller. + + This function may only be called after VirtioFsSgListsSubmit() returns + successfully. + + @param[in] ResponseSgList The scatter-gather list that describes the + response part of the exchange -- the buffers= that + the Virtio Filesystem device filled in durin= g the + virtio transfer. + + @param[in] RequestId The request identifier to which the response= is + expected to belong. + + @param[out] TailBufferFill If NULL, then the last buffer in ResponseSgL= ist + is considered fixed size. Otherwise, the last + buffer is considered variable size, and on + successful return, TailBufferFill reports the + number of bytes in the last buffer. + + @retval EFI_INVALID_PARAMETER TailBufferFill is not NULL (i.e., the last + buffer is considered variable size), and + ResponseSgList->NumVec is 1. + + @retval EFI_INVALID_PARAMETER The allocated size of the first buffer do= es + not match sizeof(VIRTIO_FS_FUSE_RESPONSE). + + @retval EFI_PROTOCOL_ERROR The VIRTIO_FS_FUSE_RESPONSE structure in = the + first buffer has not been fully populated. + + @retval EFI_PROTOCOL_ERROR "VIRTIO_FS_FUSE_RESPONSE.Len" in the first + buffer does not equal the sum of the + individual buffer sizes (as populated). + + @retval EFI_PROTOCOL_ERROR "VIRTIO_FS_FUSE_RESPONSE.Unique" in the f= irst + buffer does not equal RequestId. + + @retval EFI_PROTOCOL_ERROR "VIRTIO_FS_FUSE_RESPONSE.Error" in the fi= rst + buffer is zero, but a subsequent fixed si= ze + buffer has not been fully populated. + + @retval EFI_DEVICE_ERROR "VIRTIO_FS_FUSE_RESPONSE.Error" in the fi= rst + buffer is nonzero. The caller may investi= gate + "VIRTIO_FS_FUSE_RESPONSE.Error". Note tha= t the + completeness of the subsequent fixed size + buffers is not verified in this case. + + @retval EFI_SUCCESS Verification successful. +**/ +EFI_STATUS +VirtioFsFuseCheckResponse ( + IN VIRTIO_FS_SCATTER_GATHER_LIST *ResponseSgList, + IN UINT64 RequestId, + OUT UINTN *TailBufferFill + ) +{ + UINTN NumFixedSizeVec; + VIRTIO_FS_FUSE_RESPONSE *CommonResp; + UINT32 TotalTransferred; + UINTN Idx; + + // + // Ensured by VirtioFsSgListsValidate(). + // + ASSERT (ResponseSgList->NumVec > 0); + + if (TailBufferFill =3D=3D NULL) { + // + // All buffers are considered fixed size. + // + NumFixedSizeVec =3D ResponseSgList->NumVec; + } else { + // + // If the last buffer is variable size, then we need that buffer to be + // different from the first buffer, which is considered a + // VIRTIO_FS_FUSE_RESPONSE (fixed size) structure. + // + if (ResponseSgList->NumVec =3D=3D 1) { + return EFI_INVALID_PARAMETER; + } + NumFixedSizeVec =3D ResponseSgList->NumVec - 1; + } + + // + // The first buffer is supposed to carry a (fully populated) + // VIRTIO_FS_FUSE_RESPONSE structure. + // + if (ResponseSgList->IoVec[0].Size !=3D sizeof *CommonResp) { + return EFI_INVALID_PARAMETER; + } + if (ResponseSgList->IoVec[0].Transferred !=3D ResponseSgList->IoVec[0].S= ize) { + return EFI_PROTOCOL_ERROR; + } + + // + // FUSE must report the same number of bytes, written by the Virtio + // Filesystem device, as the virtio transport does. + // + CommonResp =3D ResponseSgList->IoVec[0].Buffer; + TotalTransferred =3D 0; + for (Idx =3D 0; Idx < ResponseSgList->NumVec; Idx++) { + // + // Integer overflow and truncation are not possible, based on + // VirtioFsSgListsValidate() and VirtioFsSgListsSubmit(). + // + TotalTransferred +=3D (UINT32)ResponseSgList->IoVec[Idx].Transferred; + } + if (CommonResp->Len !=3D TotalTransferred) { + return EFI_PROTOCOL_ERROR; + } + + // + // Enforce that FUSE match our request ID in the response. + // + if (CommonResp->Unique !=3D RequestId) { + return EFI_PROTOCOL_ERROR; + } + + // + // If there is an explicit error report, skip checking the transfer + // counts for the rest of the fixed size buffers. + // + if (CommonResp->Error !=3D 0) { + return EFI_DEVICE_ERROR; + } + + // + // There was no error reported, so we require that the Virtio Filesystem + // device populate all fixed size buffers. We checked this for the very = first + // buffer above; let's check the rest (if any). + // + ASSERT (NumFixedSizeVec >=3D 1); + for (Idx =3D 1; Idx < NumFixedSizeVec; Idx++) { + if (ResponseSgList->IoVec[Idx].Transferred !=3D + ResponseSgList->IoVec[Idx].Size) { + return EFI_PROTOCOL_ERROR; + } + } + + // + // If the last buffer is considered variable size, report its filled siz= e. + // + if (TailBufferFill !=3D NULL) { + *TailBufferFill =3D ResponseSgList->IoVec[NumFixedSizeVec].Transferred; + } + + return EFI_SUCCESS; +} --=20 2.19.1.3.g30247aa5d201 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#69018): https://edk2.groups.io/g/devel/message/69018 Mute This Topic: https://groups.io/mt/79022728/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Tue May 7 07:56:31 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+69019+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+69019+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1608153984; cv=none; d=zohomail.com; s=zohoarc; b=DUsvu6LmmxWptydDIfd8rXKdctUX+CS1zo2lEs5LbQjXTbe6hZakxYx43ADh0LT2iSACE4gzvN5eXqwqwWDUQTvS1D8tJhpycLyStoFoteI0jUF6oMkOKT/rd5AE0S+nSRFyYrB+1FQeK1sJShIF3cAvYCTfefMgJO65pey1XHc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608153984; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=t6UB8pF8AV5kwy8JZoer3laull7aj4O8SPsm1A/OX5g=; b=n604OYCHD7FnDcHGo13wIinqJac6d92cKzBUIWgqyojruYqtshVn+CCakHZxg062KMB2ZGyAPHHgP1pj8ewFIvZs+UIqb5ILPm7z6UWrI07TX4vXjCUODSh4LDoBpbtf4V3LhpbUiNpZ34ykdgj8yaEEh1kJCEtqDFfE0xpI0D0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+69019+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) header.from= Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1608153984765904.7187385592833; Wed, 16 Dec 2020 13:26:24 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id DHqpYY1788612xufhA0cx09S; Wed, 16 Dec 2020 13:26:24 -0800 X-Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.groups.io with SMTP id smtpd.web09.3582.1608153978771164849 for ; Wed, 16 Dec 2020 13:26:19 -0800 X-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-121-8o13ub_EPp6joSARBhpqYQ-1; Wed, 16 Dec 2020 16:26:16 -0500 X-MC-Unique: 8o13ub_EPp6joSARBhpqYQ-1 X-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 ECABF801A9D; Wed, 16 Dec 2020 21:26:14 +0000 (UTC) X-Received: from lacos-laptop-7.usersys.redhat.com (ovpn-114-152.ams2.redhat.com [10.36.114.152]) by smtp.corp.redhat.com (Postfix) with ESMTP id 078D11E5; Wed, 16 Dec 2020 21:26:09 +0000 (UTC) From: "Laszlo Ersek" To: devel@edk2.groups.io, virtio-fs@redhat.com, lersek@redhat.com Cc: Ard Biesheuvel , Jordan Justen , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [edk2-devel] [edk2 PATCH 07/48] OvmfPkg/VirtioFsDxe: map "errno" values to EFI_STATUS Date: Wed, 16 Dec 2020 22:10:44 +0100 Message-Id: <20201216211125.19496-8-lersek@redhat.com> In-Reply-To: <20201216211125.19496-1-lersek@redhat.com> References: <20201216211125.19496-1-lersek@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,lersek@redhat.com X-Gm-Message-State: m4Yg908GHrAcst2ZahN79vUqx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1608153984; bh=t6UB8pF8AV5kwy8JZoer3laull7aj4O8SPsm1A/OX5g=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=a+WaAn7fwgyN9I7glNT4rtnWjaoWzHFm8j/hP6pmTktbKsTP8jVyv9FRaISpEI2t9K5 IU7J0dwZPivKxarh2CzbNpXnBMi61PatAbx7EGfxVLCTjuJ0cqV24aoBjVd21fi4jjMkh 55F/vIMN9ul17jrV9kkk0B6dMjDzhPRPsPo= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" The VirtioFsFuseCheckResponse() function dedicates the EFI_DEVICE_ERROR status code to the case when the Virtio Filesystem device explicitly returns an error via the "VIRTIO_FS_FUSE_RESPONSE.Error" field. Said field effectively carries a Linux "errno" value. Introduce a helper function for mapping "errno" values to (hopefully) reasonable EFI_STATUS codes. This way we'll be able to propagate "errno" values as EFI_STATUS return codes along the UEFI call stack -- in some detail anyway. Cc: Ard Biesheuvel Cc: Jordan Justen Cc: Philippe Mathieu-Daud=C3=A9 Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3097 Signed-off-by: Laszlo Ersek Acked-by: Ard Biesheuvel --- OvmfPkg/VirtioFsDxe/VirtioFsDxe.h | 5 + OvmfPkg/VirtioFsDxe/Helpers.c | 200 ++++++++++++++++++++ 2 files changed, 205 insertions(+) diff --git a/OvmfPkg/VirtioFsDxe/VirtioFsDxe.h b/OvmfPkg/VirtioFsDxe/Virtio= FsDxe.h index f7eae9a4b71a..772ab743cc8e 100644 --- a/OvmfPkg/VirtioFsDxe/VirtioFsDxe.h +++ b/OvmfPkg/VirtioFsDxe/VirtioFsDxe.h @@ -144,16 +144,21 @@ VirtioFsFuseNewRequest ( =20 EFI_STATUS VirtioFsFuseCheckResponse ( IN VIRTIO_FS_SCATTER_GATHER_LIST *ResponseSgList, IN UINT64 RequestId, OUT UINTN *TailBufferFill ); =20 +EFI_STATUS +VirtioFsErrnoToEfiStatus ( + IN INT32 Errno + ); + // // EFI_SIMPLE_FILE_SYSTEM_PROTOCOL member functions for the Virtio Filesys= tem // driver. // =20 EFI_STATUS EFIAPI VirtioFsOpenVolume ( diff --git a/OvmfPkg/VirtioFsDxe/Helpers.c b/OvmfPkg/VirtioFsDxe/Helpers.c index 5bd2dc641f6d..334fa6c7dd26 100644 --- a/OvmfPkg/VirtioFsDxe/Helpers.c +++ b/OvmfPkg/VirtioFsDxe/Helpers.c @@ -909,8 +909,208 @@ VirtioFsFuseCheckResponse ( // If the last buffer is considered variable size, report its filled siz= e. // if (TailBufferFill !=3D NULL) { *TailBufferFill =3D ResponseSgList->IoVec[NumFixedSizeVec].Transferred; } =20 return EFI_SUCCESS; } + +/** + An ad-hoc function for mapping FUSE (well, Linux) "errno" values to + EFI_STATUS. + + @param[in] Errno The "VIRTIO_FS_FUSE_RESPONSE.Error" value, returned by= the + Virtio Filesystem device. The value is expected to be + negative. + + @return An EFI_STATUS error code that's deemed a passa= ble + mapping for the Errno value. + + @retval EFI_DEVICE_ERROR Fallback EFI_STATUS code for unrecognized Errno + values. +**/ +EFI_STATUS +VirtioFsErrnoToEfiStatus ( + IN INT32 Errno + ) +{ + switch (Errno) { + case -1: // EPERM Operation not permitted + return EFI_SECURITY_VIOLATION; + + case -2: // ENOENT No such file or directory + case -3: // ESRCH No such process + case -6: // ENXIO No such device or address + case -10: // ECHILD No child processes + case -19: // ENODEV No such device + case -49: // EUNATCH Protocol driver not attached + case -65: // ENOPKG Package not installed + case -79: // ELIBACC Can not access a needed shared library + case -126: // ENOKEY Required key not available + return EFI_NOT_FOUND; + + case -4: // EINTR Interrupted system call + case -11: // EAGAIN, EWOULDBLOCK Resource temporarily unavailable + case -16: // EBUSY Device or resource busy + case -26: // ETXTBSY Text file busy + case -35: // EDEADLK, EDEADLOCK Resource deadlock avoided + case -39: // ENOTEMPTY Directory not empty + case -42: // ENOMSG No message of desired type + case -61: // ENODATA No data available + case -85: // ERESTART Interrupted system call should be rest= arted + return EFI_NOT_READY; + + case -5: // EIO Input/output error + case -45: // EL2NSYNC Level 2 not synchronized + case -46: // EL3HLT Level 3 halted + case -47: // EL3RST Level 3 reset + case -51: // EL2HLT Level 2 halted + case -121: // EREMOTEIO Remote I/O error + case -133: // EHWPOISON Memory page has hardware error + return EFI_DEVICE_ERROR; + + case -7: // E2BIG Argument list too long + case -36: // ENAMETOOLONG File name too long + case -90: // EMSGSIZE Message too long + return EFI_BAD_BUFFER_SIZE; + + case -8: // ENOEXEC Exec format error + case -15: // ENOTBLK Block device required + case -18: // EXDEV Invalid cross-device link + case -20: // ENOTDIR Not a directory + case -21: // EISDIR Is a directory + case -25: // ENOTTY Inappropriate ioctl for device + case -27: // EFBIG File too large + case -29: // ESPIPE Illegal seek + case -38: // ENOSYS Function not implemented + case -59: // EBFONT Bad font file format + case -60: // ENOSTR Device not a stream + case -83: // ELIBEXEC Cannot exec a shared library directly + case -88: // ENOTSOCK Socket operation on non-socket + case -91: // EPROTOTYPE Protocol wrong type for socket + case -92: // ENOPROTOOPT Protocol not available + case -93: // EPROTONOSUPPORT Protocol not supported + case -94: // ESOCKTNOSUPPORT Socket type not supported + case -95: // ENOTSUP, EOPNOTSUPP Operation not supported + case -96: // EPFNOSUPPORT Protocol family not supported + case -97: // EAFNOSUPPORT Address family not supported by protoc= ol + case -99: // EADDRNOTAVAIL Cannot assign requested address + case -118: // ENOTNAM Not a XENIX named type file + case -120: // EISNAM Is a named type file + case -124: // EMEDIUMTYPE Wrong medium type + return EFI_UNSUPPORTED; + + case -9: // EBADF Bad file descriptor + case -14: // EFAULT Bad address + case -44: // ECHRNG Channel number out of range + case -48: // ELNRNG Link number out of range + case -53: // EBADR Invalid request descriptor + case -56: // EBADRQC Invalid request code + case -57: // EBADSLT Invalid slot + case -76: // ENOTUNIQ Name not unique on network + case -84: // EILSEQ Invalid or incomplete multibyte or wide char= acter + return EFI_NO_MAPPING; + + case -12: // ENOMEM Cannot allocate memory + case -23: // ENFILE Too many open files in system + case -24: // EMFILE Too many open files + case -31: // EMLINK Too many links + case -37: // ENOLCK No locks available + case -40: // ELOOP Too many levels of symbolic links + case -50: // ENOCSI No CSI structure available + case -55: // ENOANO No anode + case -63: // ENOSR Out of streams resources + case -82: // ELIBMAX Attempting to link in too many shared libr= aries + case -87: // EUSERS Too many users + case -105: // ENOBUFS No buffer space available + case -109: // ETOOMANYREFS Too many references: cannot splice + case -119: // ENAVAIL No XENIX semaphores available + case -122: // EDQUOT Disk quota exceeded + return EFI_OUT_OF_RESOURCES; + + case -13: // EACCES Permission denied + return EFI_ACCESS_DENIED; + + case -17: // EEXIST File exists + case -98: // EADDRINUSE Address already in use + case -106: // EISCONN Transport endpoint is already connected + case -114: // EALREADY Operation already in progress + case -115: // EINPROGRESS Operation now in progress + return EFI_ALREADY_STARTED; + + case -22: // EINVAL Invalid argument + case -33: // EDOM Numerical argument out of domain + return EFI_INVALID_PARAMETER; + + case -28: // ENOSPC No space left on device + case -54: // EXFULL Exchange full + return EFI_VOLUME_FULL; + + case -30: // EROFS Read-only file system + return EFI_WRITE_PROTECTED; + + case -32: // EPIPE Broken pipe + case -43: // EIDRM Identifier removed + case -67: // ENOLINK Link has been severed + case -68: // EADV Advertise error + case -69: // ESRMNT Srmount error + case -70: // ECOMM Communication error on send + case -73: // EDOTDOT RFS specific error + case -78: // EREMCHG Remote address changed + case -86: // ESTRPIPE Streams pipe error + case -102: // ENETRESET Network dropped connection on reset + case -103: // ECONNABORTED Software caused connection abort + case -104: // ECONNRESET Connection reset by peer + case -116: // ESTALE Stale file handle + case -125: // ECANCELED Operation canceled + case -128: // EKEYREVOKED Key has been revoked + case -129: // EKEYREJECTED Key was rejected by service + case -130: // EOWNERDEAD Owner died + case -131: // ENOTRECOVERABLE State not recoverable + return EFI_ABORTED; + + case -34: // ERANGE Numerical result out of range + case -75: // EOVERFLOW Value too large for defined data type + return EFI_BUFFER_TOO_SMALL; + + case -52: // EBADE Invalid exchange + case -108: // ESHUTDOWN Cannot send after transport endpoint shu= tdown + case -111: // ECONNREFUSED Connection refused + return EFI_END_OF_FILE; + + case -62: // ETIME Timer expired + case -110: // ETIMEDOUT Connection timed out + case -127: // EKEYEXPIRED Key has expired + return EFI_TIMEOUT; + + case -64: // ENONET Machine is not on the network + case -66: // EREMOTE Object is remote + case -72: // EMULTIHOP Multihop attempted + case -100: // ENETDOWN Network is down + case -101: // ENETUNREACH Network is unreachable + case -112: // EHOSTDOWN Host is down + case -113: // EHOSTUNREACH No route to host + case -123: // ENOMEDIUM No medium found + case -132: // ERFKILL Operation not possible due to RF-kill + return EFI_NO_MEDIA; + + case -71: // EPROTO Protocol error + return EFI_PROTOCOL_ERROR; + + case -74: // EBADMSG Bad message + case -77: // EBADFD File descriptor in bad state + case -80: // ELIBBAD Accessing a corrupted shared library + case -81: // ELIBSCN .lib section in a.out corrupted + case -117: // EUCLEAN Structure needs cleaning + return EFI_VOLUME_CORRUPTED; + + case -89: // EDESTADDRREQ Destination address required + case -107: // ENOTCONN Transport endpoint is not connected + return EFI_NOT_STARTED; + + default: + break; + } + + return EFI_DEVICE_ERROR; +} --=20 2.19.1.3.g30247aa5d201 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#69019): https://edk2.groups.io/g/devel/message/69019 Mute This Topic: https://groups.io/mt/79022783/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Tue May 7 07:56:31 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+69021+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+69021+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1608154112; cv=none; d=zohomail.com; s=zohoarc; b=V3u87V33YfVn8JLlfheZPk1b2hcDHxQj1wwBQ6nblpJBt5Syd2T6KvIGFUc8KLMQGgjJkk0LEXbUSLIQe4HZWK75LPMUljCTKmQcsjY6lnUlLclpyrhX4xD7RO+tg2fp+6wL1i28WpBhBiqDJ3AQnbwjRqUXV8iirVnbdrVnj1A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608154112; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=Gjf3mlMLfIAkmjun5kLL4joP4Pcwco6wmluSvN0mzcQ=; b=n5DbE6flilcrasACBHdGECoCa8t7mH5kC3HIVuTvZr7JuPbvBCLAZ6EwoHugeJcrYrbqXX+QJ237VF7CwYYqSfTCdwOVtqxlRvJoqUY765pDMWKnEpZSB9zHPTcQwa8c+cRMWwUY2rIdHE9Ibn97mo4w7geVG0A56amIS8mH1FQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+69021+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) header.from= Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1608154112493688.0382810606887; Wed, 16 Dec 2020 13:28:32 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id jIFbYY1788612xJdChevP7Qd; Wed, 16 Dec 2020 13:28:32 -0800 X-Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.groups.io with SMTP id smtpd.web09.3619.1608154106438060780 for ; Wed, 16 Dec 2020 13:28:26 -0800 X-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-202--ARxxNsbPy-XsozAXwhnwA-1; Wed, 16 Dec 2020 16:28:21 -0500 X-MC-Unique: -ARxxNsbPy-XsozAXwhnwA-1 X-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 B6B6251080; Wed, 16 Dec 2020 21:28:20 +0000 (UTC) X-Received: from lacos-laptop-7.usersys.redhat.com (ovpn-114-152.ams2.redhat.com [10.36.114.152]) by smtp.corp.redhat.com (Postfix) with ESMTP id 30D09369A; Wed, 16 Dec 2020 21:28:16 +0000 (UTC) From: "Laszlo Ersek" To: devel@edk2.groups.io, virtio-fs@redhat.com, lersek@redhat.com Cc: Ard Biesheuvel , Jordan Justen , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [edk2-devel] [edk2 PATCH 08/48] OvmfPkg/VirtioFsDxe: submit the FUSE_INIT request to the device Date: Wed, 16 Dec 2020 22:10:45 +0100 Message-Id: <20201216211125.19496-9-lersek@redhat.com> In-Reply-To: <20201216211125.19496-1-lersek@redhat.com> References: <20201216211125.19496-1-lersek@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,lersek@redhat.com X-Gm-Message-State: OJnikd7ngt3bTsNWSnGIuwT0x1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1608154112; bh=Gjf3mlMLfIAkmjun5kLL4joP4Pcwco6wmluSvN0mzcQ=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=BBdBv41iy9SoAuAoxxK6O3wl5Qx7rapExJlof1pWnINqQBf1ZiHK/QRkALFZ2XroDg4 3jA1UNJded4RvSeD4oY9Km4plewI05qW/3xJSByNUykErfYXMfVgl3qhyiWDaWFDCldkY gmF3PAUZ090PxxRABOjPuf0A9xroM2g84G0= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" Submit the FUSE_INIT request to the Virtio Filesystem device, for starting the FUSE session. The FUSE_INIT request is logged by the virtio-fs daemon, with this patch applied, when (for example) using the "CONNECT" UEFI shell command. Cc: Ard Biesheuvel Cc: Jordan Justen Cc: Philippe Mathieu-Daud=C3=A9 Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3097 Signed-off-by: Laszlo Ersek Acked-by: Ard Biesheuvel --- OvmfPkg/Include/IndustryStandard/VirtioFs.h | 31 +++++ OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf | 1 + OvmfPkg/VirtioFsDxe/VirtioFsDxe.h | 13 +- OvmfPkg/VirtioFsDxe/DriverBinding.c | 8 +- OvmfPkg/VirtioFsDxe/FuseInit.c | 132 ++++++++++++++++++++ OvmfPkg/VirtioFsDxe/Helpers.c | 5 +- 6 files changed, 182 insertions(+), 8 deletions(-) diff --git a/OvmfPkg/Include/IndustryStandard/VirtioFs.h b/OvmfPkg/Include/= IndustryStandard/VirtioFs.h index 521288b03f1c..006e0f5debcb 100644 --- a/OvmfPkg/Include/IndustryStandard/VirtioFs.h +++ b/OvmfPkg/Include/IndustryStandard/VirtioFs.h @@ -71,16 +71,23 @@ typedef struct { // out at commit (c6ff213fe5b8^) =3D d78092e4937d ("fuse: fix page derefer= ence // after free", 2020-09-18); that is, right before commit c6ff213fe5b8 ("f= use: // add submount support to ", 2020-09-18) introduces FU= SE // interface version 7.32. // #define VIRTIO_FS_FUSE_MAJOR 7 #define VIRTIO_FS_FUSE_MINOR 31 =20 +// +// FUSE operation codes. +// +typedef enum { + VirtioFsFuseOpInit =3D 26, +} VIRTIO_FS_FUSE_OPCODE; + #pragma pack (1) // // Request-response headers common to all request types. // typedef struct { UINT32 Len; UINT32 Opcode; UINT64 Unique; @@ -91,11 +98,35 @@ typedef struct { UINT32 Padding; } VIRTIO_FS_FUSE_REQUEST; =20 typedef struct { UINT32 Len; INT32 Error; UINT64 Unique; } VIRTIO_FS_FUSE_RESPONSE; + +// +// Headers for VirtioFsFuseOpInit. +// +typedef struct { + UINT32 Major; + UINT32 Minor; + UINT32 MaxReadahead; + UINT32 Flags; +} VIRTIO_FS_FUSE_INIT_REQUEST; + +typedef struct { + UINT32 Major; + UINT32 Minor; + UINT32 MaxReadahead; + UINT32 Flags; + UINT16 MaxBackground; + UINT16 CongestionThreshold; + UINT32 MaxWrite; + UINT32 TimeGran; + UINT16 MaxPages; + UINT16 MapAlignment; + UINT32 Unused[8]; +} VIRTIO_FS_FUSE_INIT_RESPONSE; #pragma pack () =20 #endif // VIRTIO_FS_H_ diff --git a/OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf b/OvmfPkg/VirtioFsDxe/Virt= ioFsDxe.inf index f6eebdb6bc7c..8fddc50318f1 100644 --- a/OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf +++ b/OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf @@ -77,16 +77,17 @@ [Defines] ENTRY_POINT =3D VirtioFsEntryPoint =20 [Packages] MdePkg/MdePkg.dec OvmfPkg/OvmfPkg.dec =20 [Sources] DriverBinding.c + FuseInit.c Helpers.c SimpleFsOpenVolume.c VirtioFsDxe.h =20 [LibraryClasses] BaseLib DebugLib MemoryAllocationLib diff --git a/OvmfPkg/VirtioFsDxe/VirtioFsDxe.h b/OvmfPkg/VirtioFsDxe/Virtio= FsDxe.h index 772ab743cc8e..b8d464011843 100644 --- a/OvmfPkg/VirtioFsDxe/VirtioFsDxe.h +++ b/OvmfPkg/VirtioFsDxe/VirtioFsDxe.h @@ -39,17 +39,17 @@ typedef struct { // field init function init d= epth // ----------- ------------------ ------= ---- UINT64 Signature; // DriverBindingStart 0 VIRTIO_DEVICE_PROTOCOL *Virtio; // DriverBindingStart 0 VIRTIO_FS_LABEL Label; // VirtioFsInit 1 UINT16 QueueSize; // VirtioFsInit 1 VRING Ring; // VirtioRingInit 2 VOID *RingMap; // VirtioRingMap 2 - UINT64 RequestId; // DriverBindingStart 0 + UINT64 RequestId; // FuseInitSession 1 EFI_EVENT ExitBoot; // DriverBindingStart 0 EFI_SIMPLE_FILE_SYSTEM_PROTOCOL SimpleFs; // DriverBindingStart 0 } VIRTIO_FS; =20 #define VIRTIO_FS_FROM_SIMPLE_FS(SimpleFsReference) \ CR (SimpleFsReference, VIRTIO_FS, SimpleFs, VIRTIO_FS_SIG); =20 // @@ -133,32 +133,41 @@ VirtioFsSgListsSubmit ( IN OUT VIRTIO_FS_SCATTER_GATHER_LIST *ResponseSgList OPTIONAL ); =20 EFI_STATUS VirtioFsFuseNewRequest ( IN OUT VIRTIO_FS *VirtioFs, OUT VIRTIO_FS_FUSE_REQUEST *Request, IN UINT32 RequestSize, - IN UINT32 Opcode, + IN VIRTIO_FS_FUSE_OPCODE Opcode, IN UINT64 NodeId ); =20 EFI_STATUS VirtioFsFuseCheckResponse ( IN VIRTIO_FS_SCATTER_GATHER_LIST *ResponseSgList, IN UINT64 RequestId, OUT UINTN *TailBufferFill ); =20 EFI_STATUS VirtioFsErrnoToEfiStatus ( IN INT32 Errno ); =20 +// +// Wrapper functions for FUSE commands (primitives). +// + +EFI_STATUS +VirtioFsFuseInitSession ( + IN OUT VIRTIO_FS *VirtioFs + ); + // // EFI_SIMPLE_FILE_SYSTEM_PROTOCOL member functions for the Virtio Filesys= tem // driver. // =20 EFI_STATUS EFIAPI VirtioFsOpenVolume ( diff --git a/OvmfPkg/VirtioFsDxe/DriverBinding.c b/OvmfPkg/VirtioFsDxe/Driv= erBinding.c index 4a2787a50a6e..4f77ffaa9953 100644 --- a/OvmfPkg/VirtioFsDxe/DriverBinding.c +++ b/OvmfPkg/VirtioFsDxe/DriverBinding.c @@ -79,20 +79,20 @@ VirtioFsBindingStart ( goto FreeVirtioFs; } =20 Status =3D VirtioFsInit (VirtioFs); if (EFI_ERROR (Status)) { goto CloseVirtio; } =20 - // - // Initialize the FUSE request counter. - // - VirtioFs->RequestId =3D 1; + Status =3D VirtioFsFuseInitSession (VirtioFs); + if (EFI_ERROR (Status)) { + goto UninitVirtioFs; + } =20 Status =3D gBS->CreateEvent (EVT_SIGNAL_EXIT_BOOT_SERVICES, TPL_CALLBACK, VirtioFsExitBoot, VirtioFs, &VirtioFs->ExitBoot); if (EFI_ERROR (Status)) { goto UninitVirtioFs; } =20 VirtioFs->SimpleFs.Revision =3D EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_REVISI= ON; diff --git a/OvmfPkg/VirtioFsDxe/FuseInit.c b/OvmfPkg/VirtioFsDxe/FuseInit.c new file mode 100644 index 000000000000..aa19dbdc05cb --- /dev/null +++ b/OvmfPkg/VirtioFsDxe/FuseInit.c @@ -0,0 +1,132 @@ +/** @file + FUSE_INIT wrapper for the Virtio Filesystem device. + + Copyright (C) 2020, Red Hat, Inc. + + SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#include "VirtioFsDxe.h" + +/** + Send a FUSE_INIT request to the Virtio Filesystem device, for starting t= he + FUSE session. + + From virtio-v1.1-cs01-87fa6b5d8155, 5.11.5 Device Initialization: "On + initialization the driver first discovers the device's virtqueues. The F= USE + session is started by sending a FUSE_INIT request as defined by the FUSE + protocol on one request virtqueue." + + The function may only be called after VirtioFsInit() returns successfull= y and + before VirtioFsUninit() is called. + + @param[in,out] VirtioFs The Virtio Filesystem device to send the FUSE_I= NIT + request to. The FUSE request counter + "VirtioFs->RequestId" is set to 1 on output. + + @retval EFI_SUCCESS The FUSE session has been started. + + @retval EFI_UNSUPPORTED FUSE interface version negotiation failed. + + @return The "errno" value mapped to an EFI_STATUS code,= if + the Virtio Filesystem device explicitly reporte= d an + error. + + @return Error codes propagated from + VirtioFsSgListsValidate(), VirtioFsFuseNewReque= st(), + VirtioFsSgListsSubmit(), + VirtioFsFuseCheckResponse(). +**/ +EFI_STATUS +VirtioFsFuseInitSession ( + IN OUT VIRTIO_FS *VirtioFs + ) +{ + VIRTIO_FS_FUSE_REQUEST CommonReq; + VIRTIO_FS_FUSE_INIT_REQUEST InitReq; + VIRTIO_FS_IO_VECTOR ReqIoVec[2]; + VIRTIO_FS_SCATTER_GATHER_LIST ReqSgList; + VIRTIO_FS_FUSE_RESPONSE CommonResp; + VIRTIO_FS_FUSE_INIT_RESPONSE InitResp; + VIRTIO_FS_IO_VECTOR RespIoVec[2]; + VIRTIO_FS_SCATTER_GATHER_LIST RespSgList; + EFI_STATUS Status; + + // + // Initialize the FUSE request counter. + // + VirtioFs->RequestId =3D 1; + + // + // Set up the scatter-gather lists. + // + ReqIoVec[0].Buffer =3D &CommonReq; + ReqIoVec[0].Size =3D sizeof CommonReq; + ReqIoVec[1].Buffer =3D &InitReq; + ReqIoVec[1].Size =3D sizeof InitReq; + ReqSgList.IoVec =3D ReqIoVec; + ReqSgList.NumVec =3D ARRAY_SIZE (ReqIoVec); + + RespIoVec[0].Buffer =3D &CommonResp; + RespIoVec[0].Size =3D sizeof CommonResp; + RespIoVec[1].Buffer =3D &InitResp; + RespIoVec[1].Size =3D sizeof InitResp; + RespSgList.IoVec =3D RespIoVec; + RespSgList.NumVec =3D ARRAY_SIZE (RespIoVec); + + // + // Validate the scatter-gather lists; calculate the total transfer sizes. + // + Status =3D VirtioFsSgListsValidate (VirtioFs, &ReqSgList, &RespSgList); + if (EFI_ERROR (Status)) { + return Status; + } + + // + // Populate the common request header. + // + Status =3D VirtioFsFuseNewRequest (VirtioFs, &CommonReq, ReqSgList.Total= Size, + VirtioFsFuseOpInit, 0); + if (EFI_ERROR (Status)) { + return Status; + } + + // + // Populate the FUSE_INIT-specific fields. + // + InitReq.Major =3D VIRTIO_FS_FUSE_MAJOR; + InitReq.Minor =3D VIRTIO_FS_FUSE_MINOR; + InitReq.MaxReadahead =3D 0; + InitReq.Flags =3D 0; + + // + // Submit the request. + // + Status =3D VirtioFsSgListsSubmit (VirtioFs, &ReqSgList, &RespSgList); + if (EFI_ERROR (Status)) { + return Status; + } + + // + // Verify the response (all response buffers are fixed size). + // + Status =3D VirtioFsFuseCheckResponse (&RespSgList, CommonReq.Unique, NUL= L); + if (EFI_ERROR (Status)) { + if (Status =3D=3D EFI_DEVICE_ERROR) { + DEBUG ((DEBUG_ERROR, "%a: Label=3D\"%s\" Errno=3D%d\n", __FUNCTION__, + VirtioFs->Label, CommonResp.Error)); + Status =3D VirtioFsErrnoToEfiStatus (CommonResp.Error); + } + return Status; + } + + // + // Check FUSE interface version compatibility. + // + if (InitResp.Major < InitReq.Major || + (InitResp.Major =3D=3D InitReq.Major && InitResp.Minor < InitReq.Min= or)) { + return EFI_UNSUPPORTED; + } + + return EFI_SUCCESS; +} diff --git a/OvmfPkg/VirtioFsDxe/Helpers.c b/OvmfPkg/VirtioFsDxe/Helpers.c index 334fa6c7dd26..00f762142746 100644 --- a/OvmfPkg/VirtioFsDxe/Helpers.c +++ b/OvmfPkg/VirtioFsDxe/Helpers.c @@ -716,33 +716,34 @@ VirtioFsSgListsSubmit ( =20 @param[in] RequestSize The total size of the request, including sizeof(VIRTIO_FS_FUSE_REQUEST). =20 @param[in] Opcode The VIRTIO_FS_FUSE_OPCODE that identifies the co= mmand to send. =20 @param[in] NodeId The inode number of the file that the request re= fers - to. + to. When Opcode is VirtioFsFuseOpInit, NodeId is + ignored by the Virtio Filesystem device. =20 @retval EFI_INVALID_PARAMETER RequestSize is smaller than sizeof(VIRTIO_FS_FUSE_REQUEST). =20 @retval EFI_OUT_OF_RESOURCES "VirtioFs->RequestId" is MAX_UINT64, and = can be incremented no more. =20 @retval EFI_SUCCESS Request has been populated, "VirtioFs->RequestId" has been incremente= d. **/ EFI_STATUS VirtioFsFuseNewRequest ( IN OUT VIRTIO_FS *VirtioFs, OUT VIRTIO_FS_FUSE_REQUEST *Request, IN UINT32 RequestSize, - IN UINT32 Opcode, + IN VIRTIO_FS_FUSE_OPCODE Opcode, IN UINT64 NodeId ) { if (RequestSize < sizeof *Request) { return EFI_INVALID_PARAMETER; } =20 if (VirtioFs->RequestId =3D=3D MAX_UINT64) { --=20 2.19.1.3.g30247aa5d201 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#69021): https://edk2.groups.io/g/devel/message/69021 Mute This Topic: https://groups.io/mt/79022827/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Tue May 7 07:56:31 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+69023+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+69023+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1608154244; cv=none; d=zohomail.com; s=zohoarc; b=fVb8VtP5fKYH3bsi0jwf067rFbiPYYdaQmbcfVb9uLZe6pNTlcAWTJpPZiCWC04MbNmoRVQpn3xcATaOBtsTlX/gZm0Bve2SD9PGfhMJiAPZvhqSo8f9iszhbI819xuVDoXOdSdh5Pq9EtRtU7TSZFr82lKNvCPnFXNn7U0PUc8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608154244; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=ACiQOWhIaXWmQQZObwXySswZ4XTK4epDEEzNaZRzMJQ=; b=i4xOGw4vgvZOWft29SZ5bPppfWSyZ3vnca91wZ2bL4uYn9WRvbDH936Yi2/fCgAUny+prKS8zTt3LMaLjGq/hsh1JvqrWUY08qDO96FMIwXg6wziH7SIMmmnLGcaH7/lqUKa9qcj9ESAVdvSeAhfgCDyb0dUi8LDGS205PgtQrA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+69023+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) header.from= Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 160815424444472.86419874884496; Wed, 16 Dec 2020 13:30:44 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id kgTGYY1788612xHX6Kt6IFyI; Wed, 16 Dec 2020 13:30:43 -0800 X-Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.groups.io with SMTP id smtpd.web12.3828.1608154233007949136 for ; Wed, 16 Dec 2020 13:30:33 -0800 X-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-85-uabSQidGMeKpjSFUzRy6mg-1; Wed, 16 Dec 2020 16:30:28 -0500 X-MC-Unique: uabSQidGMeKpjSFUzRy6mg-1 X-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 3C07D1926DA1; Wed, 16 Dec 2020 21:30:27 +0000 (UTC) X-Received: from lacos-laptop-7.usersys.redhat.com (ovpn-114-152.ams2.redhat.com [10.36.114.152]) by smtp.corp.redhat.com (Postfix) with ESMTP id DB15E1971D; Wed, 16 Dec 2020 21:30:21 +0000 (UTC) From: "Laszlo Ersek" To: devel@edk2.groups.io, virtio-fs@redhat.com, lersek@redhat.com Cc: Ard Biesheuvel , Jordan Justen , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [edk2-devel] [edk2 PATCH 09/48] OvmfPkg/VirtioFsDxe: implement the wrapper function for FUSE_OPENDIR Date: Wed, 16 Dec 2020 22:10:46 +0100 Message-Id: <20201216211125.19496-10-lersek@redhat.com> In-Reply-To: <20201216211125.19496-1-lersek@redhat.com> References: <20201216211125.19496-1-lersek@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,lersek@redhat.com X-Gm-Message-State: MtAhfldUQAmA6QqrP0rxQYukx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1608154243; bh=ACiQOWhIaXWmQQZObwXySswZ4XTK4epDEEzNaZRzMJQ=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=JkU8KPr1OBJRmzwltLgKmjyz/jIK3ULU2IAzW2C4DbOG3O2YESPvS9SKFDnQFhQ8hJq kkDYl/CUXf3waPnlsH47xceJMkzUp69DDmqb3VlYkPjCP7E6o36didpl0v44gSNi0/0O9 Zr8nL61Ss0jwjcnT2J6UTH43KR5//324+Hk= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" Add the VirtioFsFuseOpenDir() function, for sending the FUSE_OPENDIR command to the Virtio Filesystem device. Cc: Ard Biesheuvel Cc: Jordan Justen Cc: Philippe Mathieu-Daud=C3=A9 Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3097 Signed-off-by: Laszlo Ersek Acked-by: Ard Biesheuvel --- OvmfPkg/Include/IndustryStandard/VirtioFs.h | 15 +++ OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf | 1 + OvmfPkg/VirtioFsDxe/VirtioFsDxe.h | 7 ++ OvmfPkg/VirtioFsDxe/FuseOpenDir.c | 120 ++++++++++++++++++++ 4 files changed, 143 insertions(+) diff --git a/OvmfPkg/Include/IndustryStandard/VirtioFs.h b/OvmfPkg/Include/= IndustryStandard/VirtioFs.h index 006e0f5debcb..c48105325515 100644 --- a/OvmfPkg/Include/IndustryStandard/VirtioFs.h +++ b/OvmfPkg/Include/IndustryStandard/VirtioFs.h @@ -76,16 +76,17 @@ typedef struct { #define VIRTIO_FS_FUSE_MAJOR 7 #define VIRTIO_FS_FUSE_MINOR 31 =20 // // FUSE operation codes. // typedef enum { VirtioFsFuseOpInit =3D 26, + VirtioFsFuseOpOpenDir =3D 27, } VIRTIO_FS_FUSE_OPCODE; =20 #pragma pack (1) // // Request-response headers common to all request types. // typedef struct { UINT32 Len; @@ -122,11 +123,25 @@ typedef struct { UINT16 MaxBackground; UINT16 CongestionThreshold; UINT32 MaxWrite; UINT32 TimeGran; UINT16 MaxPages; UINT16 MapAlignment; UINT32 Unused[8]; } VIRTIO_FS_FUSE_INIT_RESPONSE; + +// +// Headers for VirtioFsFuseOpOpenDir. +// +typedef struct { + UINT32 Flags; + UINT32 Unused; +} VIRTIO_FS_FUSE_OPEN_REQUEST; + +typedef struct { + UINT64 FileHandle; + UINT32 OpenFlags; + UINT32 Padding; +} VIRTIO_FS_FUSE_OPEN_RESPONSE; #pragma pack () =20 #endif // VIRTIO_FS_H_ diff --git a/OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf b/OvmfPkg/VirtioFsDxe/Virt= ioFsDxe.inf index 8fddc50318f1..051acbdd7199 100644 --- a/OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf +++ b/OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf @@ -78,16 +78,17 @@ [Defines] =20 [Packages] MdePkg/MdePkg.dec OvmfPkg/OvmfPkg.dec =20 [Sources] DriverBinding.c FuseInit.c + FuseOpenDir.c Helpers.c SimpleFsOpenVolume.c VirtioFsDxe.h =20 [LibraryClasses] BaseLib DebugLib MemoryAllocationLib diff --git a/OvmfPkg/VirtioFsDxe/VirtioFsDxe.h b/OvmfPkg/VirtioFsDxe/Virtio= FsDxe.h index b8d464011843..9c47454435ae 100644 --- a/OvmfPkg/VirtioFsDxe/VirtioFsDxe.h +++ b/OvmfPkg/VirtioFsDxe/VirtioFsDxe.h @@ -158,16 +158,23 @@ VirtioFsErrnoToEfiStatus ( // Wrapper functions for FUSE commands (primitives). // =20 EFI_STATUS VirtioFsFuseInitSession ( IN OUT VIRTIO_FS *VirtioFs ); =20 +EFI_STATUS +VirtioFsFuseOpenDir ( + IN OUT VIRTIO_FS *VirtioFs, + IN UINT64 NodeId, + OUT UINT64 *FuseHandle + ); + // // EFI_SIMPLE_FILE_SYSTEM_PROTOCOL member functions for the Virtio Filesys= tem // driver. // =20 EFI_STATUS EFIAPI VirtioFsOpenVolume ( diff --git a/OvmfPkg/VirtioFsDxe/FuseOpenDir.c b/OvmfPkg/VirtioFsDxe/FuseOp= enDir.c new file mode 100644 index 000000000000..eef522693c3f --- /dev/null +++ b/OvmfPkg/VirtioFsDxe/FuseOpenDir.c @@ -0,0 +1,120 @@ +/** @file + FUSE_OPENDIR wrapper for the Virtio Filesystem device. + + Copyright (C) 2020, Red Hat, Inc. + + SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#include "VirtioFsDxe.h" + +/** + Send a FUSE_OPENDIR request to the Virtio Filesystem device, for opening= a + directory. + + The function may only be called after VirtioFsFuseInitSession() returns + successfully and before VirtioFsUninit() is called. + + @param[in,out] VirtioFs The Virtio Filesystem device to send the + FUSE_OPENDIR request to. On output, the FUSE re= quest + counter "VirtioFs->RequestId" will have been + incremented. + + @param[in] NodeId The inode number of the directory to open. + + @param[out] FuseHandle The open file handle returned by the Virtio + Filesystem device. + + @retval EFI_SUCCESS The directory has been opened. + + @return The "errno" value mapped to an EFI_STATUS code, if = the + Virtio Filesystem device explicitly reported an err= or. + + @return Error codes propagated from VirtioFsSgListsValidate= (), + VirtioFsFuseNewRequest(), VirtioFsSgListsSubmit(), + VirtioFsFuseCheckResponse(). +**/ +EFI_STATUS +VirtioFsFuseOpenDir ( + IN OUT VIRTIO_FS *VirtioFs, + IN UINT64 NodeId, + OUT UINT64 *FuseHandle + ) +{ + VIRTIO_FS_FUSE_REQUEST CommonReq; + VIRTIO_FS_FUSE_OPEN_REQUEST OpenReq; + VIRTIO_FS_IO_VECTOR ReqIoVec[2]; + VIRTIO_FS_SCATTER_GATHER_LIST ReqSgList; + VIRTIO_FS_FUSE_RESPONSE CommonResp; + VIRTIO_FS_FUSE_OPEN_RESPONSE OpenResp; + VIRTIO_FS_IO_VECTOR RespIoVec[2]; + VIRTIO_FS_SCATTER_GATHER_LIST RespSgList; + EFI_STATUS Status; + + // + // Set up the scatter-gather lists. + // + ReqIoVec[0].Buffer =3D &CommonReq; + ReqIoVec[0].Size =3D sizeof CommonReq; + ReqIoVec[1].Buffer =3D &OpenReq; + ReqIoVec[1].Size =3D sizeof OpenReq; + ReqSgList.IoVec =3D ReqIoVec; + ReqSgList.NumVec =3D ARRAY_SIZE (ReqIoVec); + + RespIoVec[0].Buffer =3D &CommonResp; + RespIoVec[0].Size =3D sizeof CommonResp; + RespIoVec[1].Buffer =3D &OpenResp; + RespIoVec[1].Size =3D sizeof OpenResp; + RespSgList.IoVec =3D RespIoVec; + RespSgList.NumVec =3D ARRAY_SIZE (RespIoVec); + + // + // Validate the scatter-gather lists; calculate the total transfer sizes. + // + Status =3D VirtioFsSgListsValidate (VirtioFs, &ReqSgList, &RespSgList); + if (EFI_ERROR (Status)) { + return Status; + } + + // + // Populate the common request header. + // + Status =3D VirtioFsFuseNewRequest (VirtioFs, &CommonReq, ReqSgList.Total= Size, + VirtioFsFuseOpOpenDir, NodeId); + if (EFI_ERROR (Status)) { + return Status; + } + + // + // Populate the FUSE_OPENDIR-specific fields. + // + OpenReq.Flags =3D 0; + OpenReq.Unused =3D 0; + + // + // Submit the request. + // + Status =3D VirtioFsSgListsSubmit (VirtioFs, &ReqSgList, &RespSgList); + if (EFI_ERROR (Status)) { + return Status; + } + + // + // Verify the response (all response buffers are fixed size). + // + Status =3D VirtioFsFuseCheckResponse (&RespSgList, CommonReq.Unique, NUL= L); + if (EFI_ERROR (Status)) { + if (Status =3D=3D EFI_DEVICE_ERROR) { + DEBUG ((DEBUG_ERROR, "%a: Label=3D\"%s\" NodeId=3D%Lu Errno=3D%d\n", + __FUNCTION__, VirtioFs->Label, NodeId, CommonResp.Error)); + Status =3D VirtioFsErrnoToEfiStatus (CommonResp.Error); + } + return Status; + } + + // + // Output the open file handle. + // + *FuseHandle =3D OpenResp.FileHandle; + return EFI_SUCCESS; +} --=20 2.19.1.3.g30247aa5d201 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#69023): https://edk2.groups.io/g/devel/message/69023 Mute This Topic: https://groups.io/mt/79022879/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Tue May 7 07:56:31 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+69024+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+69024+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1608154360; cv=none; d=zohomail.com; s=zohoarc; b=Vkug68h7mM9/YZ9kMOlt/jTxP0TEerMJOQZyWqor3vDCFQD6o0Hosvp/XAwzxnyMUJtEHW7cT2XNGfXlfM5Dx0ecab4uLynNBUhSV5mAV8w+3KEVypmlkjgKRcgkrxixuniRBgHot4fDASlg2BK6+yT0SUtkBl2qrGU3cDqQJKs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608154360; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=YhddnC2ayftX733qFE3xnNkI+H57PAVlKj9Zpa9tNK4=; b=Jph+XYsadFw7TDSVi3699gJyGGeTZ44ANuMVdz6ED5j/UMyIZ7SZFR+xifGTB2AoShaZRbRB09YGw4MWZZCcVsgngEsuxnldyJ9O1LMK1uxF+5mrrNOBn268tl553fAzMPvHXxsJFCjH7WD+lI0xUSH+RR99cXwUeXC9oKVA4Zk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+69024+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) header.from= Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1608154360507362.22200937887897; Wed, 16 Dec 2020 13:32:40 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id X03hYY1788612xvwQ0Sk91Te; Wed, 16 Dec 2020 13:32:40 -0800 X-Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.groups.io with SMTP id smtpd.web09.3685.1608154359536031779 for ; Wed, 16 Dec 2020 13:32:39 -0800 X-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-462-qwsZ_4XdPpOCUb3RRBPX2A-1; Wed, 16 Dec 2020 16:32:34 -0500 X-MC-Unique: qwsZ_4XdPpOCUb3RRBPX2A-1 X-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 7748E801B12; Wed, 16 Dec 2020 21:32:33 +0000 (UTC) X-Received: from lacos-laptop-7.usersys.redhat.com (ovpn-114-152.ams2.redhat.com [10.36.114.152]) by smtp.corp.redhat.com (Postfix) with ESMTP id 68AA219CBD; Wed, 16 Dec 2020 21:32:28 +0000 (UTC) From: "Laszlo Ersek" To: devel@edk2.groups.io, virtio-fs@redhat.com, lersek@redhat.com Cc: Ard Biesheuvel , Jordan Justen , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [edk2-devel] [edk2 PATCH 10/48] OvmfPkg/VirtioFsDxe: add shared wrapper for FUSE_RELEASE / FUSE_RELEASEDIR Date: Wed, 16 Dec 2020 22:10:47 +0100 Message-Id: <20201216211125.19496-11-lersek@redhat.com> In-Reply-To: <20201216211125.19496-1-lersek@redhat.com> References: <20201216211125.19496-1-lersek@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,lersek@redhat.com X-Gm-Message-State: ngiEDe29klcoKgUnXgCdkRfJx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1608154360; bh=YhddnC2ayftX733qFE3xnNkI+H57PAVlKj9Zpa9tNK4=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=bEvmZtU/zFb8McNsYaRnLsNRn6dQOWBvnWaLHUzOH6ot6J3mYCFvoTQ1MkP6NqhKpZp p87CgxIbt/V4ZFdUjsqkfvqpor7TttrlLtqhZNWk7D+FqqulqfZhgWETxTIp13ydtuGSF isfYPbRGf1JWBi9x7oGPjB6xsN3p3JFhUos= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" The FUSE_RELEASE and FUSE_RELEASEDIR commands only differ in the opcode. Add a common function called VirtioFsFuseReleaseFileOrDir() for sending either command. Cc: Ard Biesheuvel Cc: Jordan Justen Cc: Philippe Mathieu-Daud=C3=A9 Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3097 Signed-off-by: Laszlo Ersek Acked-by: Ard Biesheuvel --- OvmfPkg/Include/IndustryStandard/VirtioFs.h | 12 ++ OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf | 1 + OvmfPkg/VirtioFsDxe/VirtioFsDxe.h | 8 ++ OvmfPkg/VirtioFsDxe/FuseRelease.c | 121 ++++++++++++++++++++ 4 files changed, 142 insertions(+) diff --git a/OvmfPkg/Include/IndustryStandard/VirtioFs.h b/OvmfPkg/Include/= IndustryStandard/VirtioFs.h index c48105325515..c17a43c160e3 100644 --- a/OvmfPkg/Include/IndustryStandard/VirtioFs.h +++ b/OvmfPkg/Include/IndustryStandard/VirtioFs.h @@ -75,18 +75,20 @@ typedef struct { // #define VIRTIO_FS_FUSE_MAJOR 7 #define VIRTIO_FS_FUSE_MINOR 31 =20 // // FUSE operation codes. // typedef enum { + VirtioFsFuseOpRelease =3D 18, VirtioFsFuseOpInit =3D 26, VirtioFsFuseOpOpenDir =3D 27, + VirtioFsFuseOpReleaseDir =3D 29, } VIRTIO_FS_FUSE_OPCODE; =20 #pragma pack (1) // // Request-response headers common to all request types. // typedef struct { UINT32 Len; @@ -100,16 +102,26 @@ typedef struct { } VIRTIO_FS_FUSE_REQUEST; =20 typedef struct { UINT32 Len; INT32 Error; UINT64 Unique; } VIRTIO_FS_FUSE_RESPONSE; =20 +// +// Header for VirtioFsFuseOpRelease and VirtioFsFuseOpReleaseDir. +// +typedef struct { + UINT64 FileHandle; + UINT32 Flags; + UINT32 ReleaseFlags; + UINT64 LockOwner; +} VIRTIO_FS_FUSE_RELEASE_REQUEST; + // // Headers for VirtioFsFuseOpInit. // typedef struct { UINT32 Major; UINT32 Minor; UINT32 MaxReadahead; UINT32 Flags; diff --git a/OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf b/OvmfPkg/VirtioFsDxe/Virt= ioFsDxe.inf index 051acbdd7199..95b1a5a8f60a 100644 --- a/OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf +++ b/OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf @@ -79,16 +79,17 @@ [Defines] [Packages] MdePkg/MdePkg.dec OvmfPkg/OvmfPkg.dec =20 [Sources] DriverBinding.c FuseInit.c FuseOpenDir.c + FuseRelease.c Helpers.c SimpleFsOpenVolume.c VirtioFsDxe.h =20 [LibraryClasses] BaseLib DebugLib MemoryAllocationLib diff --git a/OvmfPkg/VirtioFsDxe/VirtioFsDxe.h b/OvmfPkg/VirtioFsDxe/Virtio= FsDxe.h index 9c47454435ae..a99625d0473a 100644 --- a/OvmfPkg/VirtioFsDxe/VirtioFsDxe.h +++ b/OvmfPkg/VirtioFsDxe/VirtioFsDxe.h @@ -153,16 +153,24 @@ EFI_STATUS VirtioFsErrnoToEfiStatus ( IN INT32 Errno ); =20 // // Wrapper functions for FUSE commands (primitives). // =20 +EFI_STATUS +VirtioFsFuseReleaseFileOrDir ( + IN OUT VIRTIO_FS *VirtioFs, + IN UINT64 NodeId, + IN UINT64 FuseHandle, + IN BOOLEAN IsDir + ); + EFI_STATUS VirtioFsFuseInitSession ( IN OUT VIRTIO_FS *VirtioFs ); =20 EFI_STATUS VirtioFsFuseOpenDir ( IN OUT VIRTIO_FS *VirtioFs, diff --git a/OvmfPkg/VirtioFsDxe/FuseRelease.c b/OvmfPkg/VirtioFsDxe/FuseRe= lease.c new file mode 100644 index 000000000000..dd45c7864fc8 --- /dev/null +++ b/OvmfPkg/VirtioFsDxe/FuseRelease.c @@ -0,0 +1,121 @@ +/** @file + FUSE_RELEASE / FUSE_RELEASEDIR wrapper for the Virtio Filesystem device. + + Copyright (C) 2020, Red Hat, Inc. + + SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#include "VirtioFsDxe.h" + +/** + Close a regular file or a directory that is open, by sending the FUSE_RE= LEASE + or FUSE_RELEASEDIR request to the Virtio Filesystem device. + + The function may only be called after VirtioFsFuseInitSession() returns + successfully and before VirtioFsUninit() is called. + + @param[in,out] VirtioFs The Virtio Filesystem device to send the + FUSE_RELEASE / FUSE_RELEASEDIR request to. On + output, the FUSE request counter + "VirtioFs->RequestId" will have been incremente= d. + + @param[in] NodeId The inode number of the file or directory to cl= ose. + + @param[in] FuseHandle The open handle to the file or directory to clo= se. + + @param[in] IsDir TRUE if NodeId and FuseHandle refer to a direct= ory, + FALSE if NodeId and FuseHandle refer to a regul= ar + file. + + @retval EFI_SUCCESS The file or directory has been closed. + + @return The "errno" value mapped to an EFI_STATUS code, if = the + Virtio Filesystem device explicitly reported an err= or. + + @return Error codes propagated from VirtioFsSgListsValidate= (), + VirtioFsFuseNewRequest(), VirtioFsSgListsSubmit(), + VirtioFsFuseCheckResponse(). +**/ +EFI_STATUS +VirtioFsFuseReleaseFileOrDir ( + IN OUT VIRTIO_FS *VirtioFs, + IN UINT64 NodeId, + IN UINT64 FuseHandle, + IN BOOLEAN IsDir + ) +{ + VIRTIO_FS_FUSE_REQUEST CommonReq; + VIRTIO_FS_FUSE_RELEASE_REQUEST ReleaseReq; + VIRTIO_FS_IO_VECTOR ReqIoVec[2]; + VIRTIO_FS_SCATTER_GATHER_LIST ReqSgList; + VIRTIO_FS_FUSE_RESPONSE CommonResp; + VIRTIO_FS_IO_VECTOR RespIoVec[1]; + VIRTIO_FS_SCATTER_GATHER_LIST RespSgList; + EFI_STATUS Status; + + // + // Set up the scatter-gather lists. + // + ReqIoVec[0].Buffer =3D &CommonReq; + ReqIoVec[0].Size =3D sizeof CommonReq; + ReqIoVec[1].Buffer =3D &ReleaseReq; + ReqIoVec[1].Size =3D sizeof ReleaseReq; + ReqSgList.IoVec =3D ReqIoVec; + ReqSgList.NumVec =3D ARRAY_SIZE (ReqIoVec); + + RespIoVec[0].Buffer =3D &CommonResp; + RespIoVec[0].Size =3D sizeof CommonResp; + RespSgList.IoVec =3D RespIoVec; + RespSgList.NumVec =3D ARRAY_SIZE (RespIoVec); + + // + // Validate the scatter-gather lists; calculate the total transfer sizes. + // + Status =3D VirtioFsSgListsValidate (VirtioFs, &ReqSgList, &RespSgList); + if (EFI_ERROR (Status)) { + return Status; + } + + // + // Populate the common request header. + // + Status =3D VirtioFsFuseNewRequest ( + VirtioFs, + &CommonReq, + ReqSgList.TotalSize, + IsDir ? VirtioFsFuseOpReleaseDir : VirtioFsFuseOpRelease, + NodeId + ); + if (EFI_ERROR (Status)) { + return Status; + } + + // + // Populate the FUSE_RELEASE- / FUSE_RELEASEDIR-specific fields. + // + ReleaseReq.FileHandle =3D FuseHandle; + ReleaseReq.Flags =3D 0; + ReleaseReq.ReleaseFlags =3D 0; + ReleaseReq.LockOwner =3D 0; + + // + // Submit the request. + // + Status =3D VirtioFsSgListsSubmit (VirtioFs, &ReqSgList, &RespSgList); + if (EFI_ERROR (Status)) { + return Status; + } + + // + // Verify the response (all response buffers are fixed size). + // + Status =3D VirtioFsFuseCheckResponse (&RespSgList, CommonReq.Unique, NUL= L); + if (Status =3D=3D EFI_DEVICE_ERROR) { + DEBUG ((DEBUG_ERROR, "%a: Label=3D\"%s\" NodeId=3D%Lu FuseHandle=3D%Lu= " + "IsDir=3D%d Errno=3D%d\n", __FUNCTION__, VirtioFs->Label, NodeId, Fu= seHandle, + IsDir, CommonResp.Error)); + Status =3D VirtioFsErrnoToEfiStatus (CommonResp.Error); + } + return Status; +} --=20 2.19.1.3.g30247aa5d201 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#69024): https://edk2.groups.io/g/devel/message/69024 Mute This Topic: https://groups.io/mt/79022927/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Tue May 7 07:56:31 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+69025+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+69025+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1608154491; cv=none; d=zohomail.com; s=zohoarc; b=Cv9sMZvbFr6DDzDrSHEmHalyKdQdfkqfHDeM/zs8aj9h83LTd5c2Gi0cKdF6Bu02VBgVVZVbsznFkWxFI4VP+EF4+L9j/MFz1hSdpfwI81V8MlZYrvyybSKAnSOaXn1vffv0EHMCxykk0x017L1+1R/GTESH9pObSlapfyv0XhI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608154491; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=1bXBT5KqgiK5xrY6A8+f4CJNvrkPHsFCj39AKceOsak=; b=LkJLpNgCMcFLsYLZeK91mL0Fn4TmBq4QxVgq3phEyNI8akn33fCOQkbEjVgzx1+Hgms06QaJPylHtTR2gy056mGCnV4/Kzst5KqgroAcDIHMQyfo2EwMwN45GH81LOttOj24k3ucRWKCMo+VQFPwZNTf37OACdSvasL532Udmd8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+69025+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) header.from= Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1608154491595882.3816324608936; Wed, 16 Dec 2020 13:34:51 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id 5k5QYY1788612x7WmH2Cc5Hy; Wed, 16 Dec 2020 13:34:50 -0800 X-Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.groups.io with SMTP id smtpd.web12.3899.1608154485034633403 for ; Wed, 16 Dec 2020 13:34:45 -0800 X-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-397-Hm_DG1HaNv6t5phAjwv-Pg-1; Wed, 16 Dec 2020 16:34:41 -0500 X-MC-Unique: Hm_DG1HaNv6t5phAjwv-Pg-1 X-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 5D771801817; Wed, 16 Dec 2020 21:34:40 +0000 (UTC) X-Received: from lacos-laptop-7.usersys.redhat.com (ovpn-114-152.ams2.redhat.com [10.36.114.152]) by smtp.corp.redhat.com (Postfix) with ESMTP id AE04E106D5A4; Wed, 16 Dec 2020 21:34:34 +0000 (UTC) From: "Laszlo Ersek" To: devel@edk2.groups.io, virtio-fs@redhat.com, lersek@redhat.com Cc: Ard Biesheuvel , Jordan Justen , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [edk2-devel] [edk2 PATCH 11/48] OvmfPkg/VirtioFsDxe: implement EFI_SIMPLE_FILE_SYSTEM_PROTOCOL.OpenVolume() Date: Wed, 16 Dec 2020 22:10:48 +0100 Message-Id: <20201216211125.19496-12-lersek@redhat.com> In-Reply-To: <20201216211125.19496-1-lersek@redhat.com> References: <20201216211125.19496-1-lersek@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,lersek@redhat.com X-Gm-Message-State: AvXHdODNoFTrNNYNpVGWSJmlx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1608154490; bh=1bXBT5KqgiK5xrY6A8+f4CJNvrkPHsFCj39AKceOsak=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=xKaFyUb8xo+DtE5GB/pbo3+06M0bCYG075v4E+t8w2QepqpdThL3WkjWjskpGj8JnVU MIwZ75QXnx/+19P92pSkzyH6HstA++39GyOB0X0m8ScKsembSzFSs06pNXc1iRZX/vwRR gvbCFv2OwT6Wb1YN7AJuhBirVDRxdpUizAI= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" With the help of the VirtioFsFuseOpenDir() and VirtioFsFuseReleaseFileOrDir() functions introduced previously, we can now open and close the root directory. So let's implement EFI_SIMPLE_FILE_SYSTEM_PROTOCOL.OpenVolume(). OpenVolume() creates a new EFI_FILE_PROTOCOL object -- a reference to the root directory of the filesystem. Thus, we have to start tracking references to EFI_SIMPLE_FILE_SYSTEM_PROTOCOL, lest we unbind the virtio-fs device while files are open. There are two methods that release an EFI_FILE_PROTOCOL object: the Close() and the Delete() member functions. In particular, they are not allowed to fail with regard to resource management -- they must release resources unconditionally. Thus, for rolling back the resource accounting that we do in EFI_SIMPLE_FILE_SYSTEM_PROTOCOL.OpenVolume(), we have to implement the first versions of EFI_FILE_PROTOCOL.Close() and EFI_FILE_PROTOCOL.Delete() in this patch as well. With this patch applied, the UEFI shell can enter the root directory of the Virtio Filesystem (such as with the "FS3:" shell command), and the "DIR" shell command exercises FUSE_OPENDIR and FUSE_RELEASEDIR, according to the virtiofsd log. The "DIR" command reports the root directory as if it were empty; probably because at this time, we only allow the shell to open and to close the root directory, but not to read it. Cc: Ard Biesheuvel Cc: Jordan Justen Cc: Philippe Mathieu-Daud=C3=A9 Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3097 Signed-off-by: Laszlo Ersek Acked-by: Ard Biesheuvel --- OvmfPkg/Include/IndustryStandard/VirtioFs.h | 5 + OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf | 10 ++ OvmfPkg/VirtioFsDxe/VirtioFsDxe.h | 117 ++++++++++++++++++++ OvmfPkg/VirtioFsDxe/DriverBinding.c | 5 + OvmfPkg/VirtioFsDxe/SimpleFsClose.c | 48 ++++++++ OvmfPkg/VirtioFsDxe/SimpleFsDelete.c | 29 +++++ OvmfPkg/VirtioFsDxe/SimpleFsFlush.c | 18 +++ OvmfPkg/VirtioFsDxe/SimpleFsGetInfo.c | 21 ++++ OvmfPkg/VirtioFsDxe/SimpleFsGetPosition.c | 20 ++++ OvmfPkg/VirtioFsDxe/SimpleFsOpen.c | 22 ++++ OvmfPkg/VirtioFsDxe/SimpleFsOpenVolume.c | 57 +++++++++- OvmfPkg/VirtioFsDxe/SimpleFsRead.c | 20 ++++ OvmfPkg/VirtioFsDxe/SimpleFsSetInfo.c | 21 ++++ OvmfPkg/VirtioFsDxe/SimpleFsSetPosition.c | 20 ++++ OvmfPkg/VirtioFsDxe/SimpleFsWrite.c | 20 ++++ 15 files changed, 432 insertions(+), 1 deletion(-) diff --git a/OvmfPkg/Include/IndustryStandard/VirtioFs.h b/OvmfPkg/Include/= IndustryStandard/VirtioFs.h index c17a43c160e3..67fcf975e8b2 100644 --- a/OvmfPkg/Include/IndustryStandard/VirtioFs.h +++ b/OvmfPkg/Include/IndustryStandard/VirtioFs.h @@ -71,16 +71,21 @@ typedef struct { // out at commit (c6ff213fe5b8^) =3D d78092e4937d ("fuse: fix page derefer= ence // after free", 2020-09-18); that is, right before commit c6ff213fe5b8 ("f= use: // add submount support to ", 2020-09-18) introduces FU= SE // interface version 7.32. // #define VIRTIO_FS_FUSE_MAJOR 7 #define VIRTIO_FS_FUSE_MINOR 31 =20 +// +// The inode number of the root directory. +// +#define VIRTIO_FS_FUSE_ROOT_DIR_NODE_ID 1 + // // FUSE operation codes. // typedef enum { VirtioFsFuseOpRelease =3D 18, VirtioFsFuseOpInit =3D 26, VirtioFsFuseOpOpenDir =3D 27, VirtioFsFuseOpReleaseDir =3D 29, diff --git a/OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf b/OvmfPkg/VirtioFsDxe/Virt= ioFsDxe.inf index 95b1a5a8f60a..28e66082ecfe 100644 --- a/OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf +++ b/OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf @@ -81,17 +81,27 @@ [Packages] OvmfPkg/OvmfPkg.dec =20 [Sources] DriverBinding.c FuseInit.c FuseOpenDir.c FuseRelease.c Helpers.c + SimpleFsClose.c + SimpleFsDelete.c + SimpleFsFlush.c + SimpleFsGetInfo.c + SimpleFsGetPosition.c + SimpleFsOpen.c SimpleFsOpenVolume.c + SimpleFsRead.c + SimpleFsSetInfo.c + SimpleFsSetPosition.c + SimpleFsWrite.c VirtioFsDxe.h =20 [LibraryClasses] BaseLib DebugLib MemoryAllocationLib UefiBootServicesTableLib UefiDriverEntryPoint diff --git a/OvmfPkg/VirtioFsDxe/VirtioFsDxe.h b/OvmfPkg/VirtioFsDxe/Virtio= FsDxe.h index a99625d0473a..34574d0596fc 100644 --- a/OvmfPkg/VirtioFsDxe/VirtioFsDxe.h +++ b/OvmfPkg/VirtioFsDxe/VirtioFsDxe.h @@ -14,16 +14,19 @@ #include // VIRTIO_FS_TAG_BYTES #include // CR() #include // EFI_SIMPLE_FILE_SYSTEM_PROTOCOL #include // VIRTIO_DEVICE_PROTOCOL #include // EFI_EVENT =20 #define VIRTIO_FS_SIG SIGNATURE_64 ('V', 'I', 'R', 'T', 'I', 'O', 'F', 'S') =20 +#define VIRTIO_FS_FILE_SIG \ + SIGNATURE_64 ('V', 'I', 'O', 'F', 'S', 'F', 'I', 'L') + // // Filesystem label encoded in UCS-2, transformed from the UTF-8 represent= ation // in "VIRTIO_FS_CONFIG.Tag", and NUL-terminated. Only the printable ASCII= code // points (U+0020 through U+007E) are supported. // typedef CHAR16 VIRTIO_FS_LABEL[VIRTIO_FS_TAG_BYTES + 1]; =20 // @@ -41,16 +44,17 @@ typedef struct { UINT64 Signature; // DriverBindingStart 0 VIRTIO_DEVICE_PROTOCOL *Virtio; // DriverBindingStart 0 VIRTIO_FS_LABEL Label; // VirtioFsInit 1 UINT16 QueueSize; // VirtioFsInit 1 VRING Ring; // VirtioRingInit 2 VOID *RingMap; // VirtioRingMap 2 UINT64 RequestId; // FuseInitSession 1 EFI_EVENT ExitBoot; // DriverBindingStart 0 + LIST_ENTRY OpenFiles; // DriverBindingStart 0 EFI_SIMPLE_FILE_SYSTEM_PROTOCOL SimpleFs; // DriverBindingStart 0 } VIRTIO_FS; =20 #define VIRTIO_FS_FROM_SIMPLE_FS(SimpleFsReference) \ CR (SimpleFsReference, VIRTIO_FS, SimpleFs, VIRTIO_FS_SIG); =20 // // Structure for describing a contiguous buffer, potentially mapped for Vi= rtio @@ -93,16 +97,49 @@ typedef struct { UINTN NumVec; // // TotalSize is calculated when the scatter-gather list is initially // validated. // UINT32 TotalSize; } VIRTIO_FS_SCATTER_GATHER_LIST; =20 +// +// Private context structure that exposes EFI_FILE_PROTOCOL on top of an o= pen +// FUSE file reference. +// +typedef struct { + UINT64 Signature; + EFI_FILE_PROTOCOL SimpleFile; + BOOLEAN IsDirectory; + VIRTIO_FS *OwnerFs; + LIST_ENTRY OpenFilesEntry; + // + // In the FUSE wire protocol, every request except FUSE_INIT refers to a + // file, namely by the "VIRTIO_FS_FUSE_REQUEST.NodeId" field; that is, b= y the + // inode number of the file. However, some of the FUSE requests that we = need + // for some of the EFI_FILE_PROTOCOL member functions require an open fi= le + // handle *in addition* to the inode number. For simplicity, whenever a + // VIRTIO_FS_FILE object is created, primarily defined by its NodeId fie= ld, + // we also *open* the referenced file at once, and save the returned file + // handle in the FuseHandle field. This way, when an EFI_FILE_PROTOCOL m= ember + // function must send a FUSE request that needs the file handle *in addi= tion* + // to the inode number, FuseHandle will be at our disposal at once. + // + UINT64 NodeId; + UINT64 FuseHandle; +} VIRTIO_FS_FILE; + +#define VIRTIO_FS_FILE_FROM_SIMPLE_FILE(SimpleFileReference) \ + CR (SimpleFileReference, VIRTIO_FS_FILE, SimpleFile, VIRTIO_FS_FILE_SIG); + +#define VIRTIO_FS_FILE_FROM_OPEN_FILES_ENTRY(OpenFilesEntryReference) \ + CR (OpenFilesEntryReference, VIRTIO_FS_FILE, OpenFilesEntry, \ + VIRTIO_FS_FILE_SIG); + // // Initialization and helper routines for the Virtio Filesystem device. // =20 EFI_STATUS VirtioFsInit ( IN OUT VIRTIO_FS *VirtioFs ); @@ -185,9 +222,89 @@ VirtioFsFuseOpenDir ( =20 EFI_STATUS EFIAPI VirtioFsOpenVolume ( IN EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *This, OUT EFI_FILE_PROTOCOL **Root ); =20 +// +// EFI_FILE_PROTOCOL member functions for the Virtio Filesystem driver. +// + +EFI_STATUS +EFIAPI +VirtioFsSimpleFileClose ( + IN EFI_FILE_PROTOCOL *This + ); + +EFI_STATUS +EFIAPI +VirtioFsSimpleFileDelete ( + IN EFI_FILE_PROTOCOL *This + ); + +EFI_STATUS +EFIAPI +VirtioFsSimpleFileFlush ( + IN EFI_FILE_PROTOCOL *This + ); + +EFI_STATUS +EFIAPI +VirtioFsSimpleFileGetInfo ( + IN EFI_FILE_PROTOCOL *This, + IN EFI_GUID *InformationType, + IN OUT UINTN *BufferSize, + OUT VOID *Buffer + ); + +EFI_STATUS +EFIAPI +VirtioFsSimpleFileGetPosition ( + IN EFI_FILE_PROTOCOL *This, + OUT UINT64 *Position + ); + +EFI_STATUS +EFIAPI +VirtioFsSimpleFileOpen ( + IN EFI_FILE_PROTOCOL *This, + OUT EFI_FILE_PROTOCOL **NewHandle, + IN CHAR16 *FileName, + IN UINT64 OpenMode, + IN UINT64 Attributes + ); + +EFI_STATUS +EFIAPI +VirtioFsSimpleFileRead ( + IN EFI_FILE_PROTOCOL *This, + IN OUT UINTN *BufferSize, + OUT VOID *Buffer + ); + +EFI_STATUS +EFIAPI +VirtioFsSimpleFileSetInfo ( + IN EFI_FILE_PROTOCOL *This, + IN EFI_GUID *InformationType, + IN UINTN BufferSize, + IN VOID *Buffer + ); + +EFI_STATUS +EFIAPI +VirtioFsSimpleFileSetPosition ( + IN EFI_FILE_PROTOCOL *This, + IN UINT64 Position + ); + +EFI_STATUS +EFIAPI +VirtioFsSimpleFileWrite ( + IN EFI_FILE_PROTOCOL *This, + IN OUT UINTN *BufferSize, + IN VOID *Buffer + ); + #endif // VIRTIO_FS_DXE_H_ diff --git a/OvmfPkg/VirtioFsDxe/DriverBinding.c b/OvmfPkg/VirtioFsDxe/Driv= erBinding.c index 4f77ffaa9953..e273c9f362eb 100644 --- a/OvmfPkg/VirtioFsDxe/DriverBinding.c +++ b/OvmfPkg/VirtioFsDxe/DriverBinding.c @@ -90,16 +90,17 @@ VirtioFsBindingStart ( } =20 Status =3D gBS->CreateEvent (EVT_SIGNAL_EXIT_BOOT_SERVICES, TPL_CALLBACK, VirtioFsExitBoot, VirtioFs, &VirtioFs->ExitBoot); if (EFI_ERROR (Status)) { goto UninitVirtioFs; } =20 + InitializeListHead (&VirtioFs->OpenFiles); VirtioFs->SimpleFs.Revision =3D EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_REVISI= ON; VirtioFs->SimpleFs.OpenVolume =3D VirtioFsOpenVolume; =20 Status =3D gBS->InstallProtocolInterface (&ControllerHandle, &gEfiSimpleFileSystemProtocolGuid, EFI_NATIVE_INTERFACE, &VirtioFs->SimpleFs); if (EFI_ERROR (Status)) { goto CloseExitBoot; @@ -144,16 +145,20 @@ VirtioFsBindingStop ( This->DriverBindingHandle, ControllerHandle, EFI_OPEN_PROTOCOL_GET_PROTOCOL); if (EFI_ERROR (Status)) { return Status; } =20 VirtioFs =3D VIRTIO_FS_FROM_SIMPLE_FS (SimpleFs); =20 + if (!IsListEmpty (&VirtioFs->OpenFiles)) { + return EFI_ACCESS_DENIED; + } + Status =3D gBS->UninstallProtocolInterface (ControllerHandle, &gEfiSimpleFileSystemProtocolGuid, SimpleFs); if (EFI_ERROR (Status)) { return Status; } =20 Status =3D gBS->CloseEvent (VirtioFs->ExitBoot); ASSERT_EFI_ERROR (Status); diff --git a/OvmfPkg/VirtioFsDxe/SimpleFsClose.c b/OvmfPkg/VirtioFsDxe/Simp= leFsClose.c new file mode 100644 index 000000000000..01bbeae21473 --- /dev/null +++ b/OvmfPkg/VirtioFsDxe/SimpleFsClose.c @@ -0,0 +1,48 @@ +/** @file + EFI_FILE_PROTOCOL.Close() member function for the Virtio Filesystem driv= er. + + Copyright (C) 2020, Red Hat, Inc. + + SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#include // RemoveEntryList() +#include // FreePool() + +#include "VirtioFsDxe.h" + +EFI_STATUS +EFIAPI +VirtioFsSimpleFileClose ( + IN EFI_FILE_PROTOCOL *This + ) +{ + VIRTIO_FS_FILE *VirtioFsFile; + VIRTIO_FS *VirtioFs; + + VirtioFsFile =3D VIRTIO_FS_FILE_FROM_SIMPLE_FILE (This); + VirtioFs =3D VirtioFsFile->OwnerFs; + + // + // At this point, the implementation is only suitable for closing the + // VIRTIO_FS_FILE that was created by VirtioFsOpenVolume(). + // + ASSERT (VirtioFsFile->IsDirectory); + ASSERT (VirtioFsFile->NodeId =3D=3D VIRTIO_FS_FUSE_ROOT_DIR_NODE_ID); + // + // Close the root directory. + // + // Ignore any errors, because EFI_FILE_PROTOCOL.Close() is required to + // release the EFI_FILE_PROTOCOL object unconditionally. + // + VirtioFsFuseReleaseFileOrDir (VirtioFs, VirtioFsFile->NodeId, + VirtioFsFile->FuseHandle, VirtioFsFile->IsDirectory); + + // + // One fewer file left open for the owner filesystem. + // + RemoveEntryList (&VirtioFsFile->OpenFilesEntry); + + FreePool (VirtioFsFile); + return EFI_SUCCESS; +} diff --git a/OvmfPkg/VirtioFsDxe/SimpleFsDelete.c b/OvmfPkg/VirtioFsDxe/Sim= pleFsDelete.c new file mode 100644 index 000000000000..3209923d1e49 --- /dev/null +++ b/OvmfPkg/VirtioFsDxe/SimpleFsDelete.c @@ -0,0 +1,29 @@ +/** @file + EFI_FILE_PROTOCOL.Delete() member function for the Virtio Filesystem dri= ver. + + Copyright (C) 2020, Red Hat, Inc. + + SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#include "VirtioFsDxe.h" + +EFI_STATUS +EFIAPI +VirtioFsSimpleFileDelete ( + IN EFI_FILE_PROTOCOL *This + ) +{ + // + // At this point, the implementation is only suitable for closing the + // VIRTIO_FS_FILE that was created by VirtioFsOpenVolume(). + // + // Actually deleting the root directory is not possible, so we're only g= oing + // to release resources, and return EFI_WARN_DELETE_FAILURE. + // + // In order to release resources, VirtioFsSimpleFileClose() is just right + // here. + // + VirtioFsSimpleFileClose (This); + return EFI_WARN_DELETE_FAILURE; +} diff --git a/OvmfPkg/VirtioFsDxe/SimpleFsFlush.c b/OvmfPkg/VirtioFsDxe/Simp= leFsFlush.c new file mode 100644 index 000000000000..e48d92140f64 --- /dev/null +++ b/OvmfPkg/VirtioFsDxe/SimpleFsFlush.c @@ -0,0 +1,18 @@ +/** @file + EFI_FILE_PROTOCOL.Flush() member function for the Virtio Filesystem driv= er. + + Copyright (C) 2020, Red Hat, Inc. + + SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#include "VirtioFsDxe.h" + +EFI_STATUS +EFIAPI +VirtioFsSimpleFileFlush ( + IN EFI_FILE_PROTOCOL *This + ) +{ + return EFI_NO_MEDIA; +} diff --git a/OvmfPkg/VirtioFsDxe/SimpleFsGetInfo.c b/OvmfPkg/VirtioFsDxe/Si= mpleFsGetInfo.c new file mode 100644 index 000000000000..6e870460c014 --- /dev/null +++ b/OvmfPkg/VirtioFsDxe/SimpleFsGetInfo.c @@ -0,0 +1,21 @@ +/** @file + EFI_FILE_PROTOCOL.GetInfo() member function for the Virtio Filesystem dr= iver. + + Copyright (C) 2020, Red Hat, Inc. + + SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#include "VirtioFsDxe.h" + +EFI_STATUS +EFIAPI +VirtioFsSimpleFileGetInfo ( + IN EFI_FILE_PROTOCOL *This, + IN EFI_GUID *InformationType, + IN OUT UINTN *BufferSize, + OUT VOID *Buffer + ) +{ + return EFI_NO_MEDIA; +} diff --git a/OvmfPkg/VirtioFsDxe/SimpleFsGetPosition.c b/OvmfPkg/VirtioFsDx= e/SimpleFsGetPosition.c new file mode 100644 index 000000000000..2f40d2be2693 --- /dev/null +++ b/OvmfPkg/VirtioFsDxe/SimpleFsGetPosition.c @@ -0,0 +1,20 @@ +/** @file + EFI_FILE_PROTOCOL.GetPosition() member function for the Virtio Filesystem + driver. + + Copyright (C) 2020, Red Hat, Inc. + + SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#include "VirtioFsDxe.h" + +EFI_STATUS +EFIAPI +VirtioFsSimpleFileGetPosition ( + IN EFI_FILE_PROTOCOL *This, + OUT UINT64 *Position + ) +{ + return EFI_DEVICE_ERROR; +} diff --git a/OvmfPkg/VirtioFsDxe/SimpleFsOpen.c b/OvmfPkg/VirtioFsDxe/Simpl= eFsOpen.c new file mode 100644 index 000000000000..f0e249184079 --- /dev/null +++ b/OvmfPkg/VirtioFsDxe/SimpleFsOpen.c @@ -0,0 +1,22 @@ +/** @file + EFI_FILE_PROTOCOL.Open() member function for the Virtio Filesystem drive= r. + + Copyright (C) 2020, Red Hat, Inc. + + SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#include "VirtioFsDxe.h" + +EFI_STATUS +EFIAPI +VirtioFsSimpleFileOpen ( + IN EFI_FILE_PROTOCOL *This, + OUT EFI_FILE_PROTOCOL **NewHandle, + IN CHAR16 *FileName, + IN UINT64 OpenMode, + IN UINT64 Attributes + ) +{ + return EFI_NO_MEDIA; +} diff --git a/OvmfPkg/VirtioFsDxe/SimpleFsOpenVolume.c b/OvmfPkg/VirtioFsDxe= /SimpleFsOpenVolume.c index a5a66a27d84c..8c1457a68aad 100644 --- a/OvmfPkg/VirtioFsDxe/SimpleFsOpenVolume.c +++ b/OvmfPkg/VirtioFsDxe/SimpleFsOpenVolume.c @@ -2,25 +2,80 @@ EFI_SIMPLE_FILE_SYSTEM_PROTOCOL.OpenVolume() member function for the Vir= tio Filesystem driver. =20 Copyright (C) 2020, Red Hat, Inc. =20 SPDX-License-Identifier: BSD-2-Clause-Patent **/ =20 +#include // InsertTailList() +#include // AllocatePool() + #include "VirtioFsDxe.h" =20 /** Open the root directory on the Virtio Filesystem. =20 Refer to EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_OPEN_VOLUME for the interface contract. **/ EFI_STATUS EFIAPI VirtioFsOpenVolume ( IN EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *This, OUT EFI_FILE_PROTOCOL **Root ) { - return EFI_NO_MEDIA; + VIRTIO_FS *VirtioFs; + VIRTIO_FS_FILE *VirtioFsFile; + EFI_STATUS Status; + UINT64 RootDirHandle; + + VirtioFs =3D VIRTIO_FS_FROM_SIMPLE_FS (This); + + VirtioFsFile =3D AllocatePool (sizeof *VirtioFsFile); + if (VirtioFsFile =3D=3D NULL) { + return EFI_OUT_OF_RESOURCES; + } + + // + // Open the root directory. + // + Status =3D VirtioFsFuseOpenDir (VirtioFs, VIRTIO_FS_FUSE_ROOT_DIR_NODE_I= D, + &RootDirHandle); + if (EFI_ERROR (Status)) { + goto FreeVirtioFsFile; + } + + // + // Populate the new VIRTIO_FS_FILE object. + // + VirtioFsFile->Signature =3D VIRTIO_FS_FILE_SIG; + VirtioFsFile->SimpleFile.Revision =3D EFI_FILE_PROTOCOL_REVISION; + VirtioFsFile->SimpleFile.Open =3D VirtioFsSimpleFileOpen; + VirtioFsFile->SimpleFile.Close =3D VirtioFsSimpleFileClose; + VirtioFsFile->SimpleFile.Delete =3D VirtioFsSimpleFileDelete; + VirtioFsFile->SimpleFile.Read =3D VirtioFsSimpleFileRead; + VirtioFsFile->SimpleFile.Write =3D VirtioFsSimpleFileWrite; + VirtioFsFile->SimpleFile.GetPosition =3D VirtioFsSimpleFileGetPosition; + VirtioFsFile->SimpleFile.SetPosition =3D VirtioFsSimpleFileSetPosition; + VirtioFsFile->SimpleFile.GetInfo =3D VirtioFsSimpleFileGetInfo; + VirtioFsFile->SimpleFile.SetInfo =3D VirtioFsSimpleFileSetInfo; + VirtioFsFile->SimpleFile.Flush =3D VirtioFsSimpleFileFlush; + VirtioFsFile->IsDirectory =3D TRUE; + VirtioFsFile->OwnerFs =3D VirtioFs; + VirtioFsFile->NodeId =3D VIRTIO_FS_FUSE_ROOT_DIR_NODE_ID; + VirtioFsFile->FuseHandle =3D RootDirHandle; + + // + // One more file open for the filesystem. + // + InsertTailList (&VirtioFs->OpenFiles, &VirtioFsFile->OpenFilesEntry); + + *Root =3D &VirtioFsFile->SimpleFile; + return EFI_SUCCESS; + +FreeVirtioFsFile: + FreePool (VirtioFsFile); + + return Status; } diff --git a/OvmfPkg/VirtioFsDxe/SimpleFsRead.c b/OvmfPkg/VirtioFsDxe/Simpl= eFsRead.c new file mode 100644 index 000000000000..e737d5e33204 --- /dev/null +++ b/OvmfPkg/VirtioFsDxe/SimpleFsRead.c @@ -0,0 +1,20 @@ +/** @file + EFI_FILE_PROTOCOL.Read() member function for the Virtio Filesystem drive= r. + + Copyright (C) 2020, Red Hat, Inc. + + SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#include "VirtioFsDxe.h" + +EFI_STATUS +EFIAPI +VirtioFsSimpleFileRead ( + IN EFI_FILE_PROTOCOL *This, + IN OUT UINTN *BufferSize, + OUT VOID *Buffer + ) +{ + return EFI_NO_MEDIA; +} diff --git a/OvmfPkg/VirtioFsDxe/SimpleFsSetInfo.c b/OvmfPkg/VirtioFsDxe/Si= mpleFsSetInfo.c new file mode 100644 index 000000000000..200b7a1bcd20 --- /dev/null +++ b/OvmfPkg/VirtioFsDxe/SimpleFsSetInfo.c @@ -0,0 +1,21 @@ +/** @file + EFI_FILE_PROTOCOL.SetInfo() member function for the Virtio Filesystem dr= iver. + + Copyright (C) 2020, Red Hat, Inc. + + SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#include "VirtioFsDxe.h" + +EFI_STATUS +EFIAPI +VirtioFsSimpleFileSetInfo ( + IN EFI_FILE_PROTOCOL *This, + IN EFI_GUID *InformationType, + IN UINTN BufferSize, + IN VOID *Buffer + ) +{ + return EFI_NO_MEDIA; +} diff --git a/OvmfPkg/VirtioFsDxe/SimpleFsSetPosition.c b/OvmfPkg/VirtioFsDx= e/SimpleFsSetPosition.c new file mode 100644 index 000000000000..ee8cb1f4e465 --- /dev/null +++ b/OvmfPkg/VirtioFsDxe/SimpleFsSetPosition.c @@ -0,0 +1,20 @@ +/** @file + EFI_FILE_PROTOCOL.SetPosition() member function for the Virtio Filesystem + driver. + + Copyright (C) 2020, Red Hat, Inc. + + SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#include "VirtioFsDxe.h" + +EFI_STATUS +EFIAPI +VirtioFsSimpleFileSetPosition ( + IN EFI_FILE_PROTOCOL *This, + IN UINT64 Position + ) +{ + return EFI_DEVICE_ERROR; +} diff --git a/OvmfPkg/VirtioFsDxe/SimpleFsWrite.c b/OvmfPkg/VirtioFsDxe/Simp= leFsWrite.c new file mode 100644 index 000000000000..90d82bd722b1 --- /dev/null +++ b/OvmfPkg/VirtioFsDxe/SimpleFsWrite.c @@ -0,0 +1,20 @@ +/** @file + EFI_FILE_PROTOCOL.Write() member function for the Virtio Filesystem driv= er. + + Copyright (C) 2020, Red Hat, Inc. + + SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#include "VirtioFsDxe.h" + +EFI_STATUS +EFIAPI +VirtioFsSimpleFileWrite ( + IN EFI_FILE_PROTOCOL *This, + IN OUT UINTN *BufferSize, + IN VOID *Buffer + ) +{ + return EFI_NO_MEDIA; +} --=20 2.19.1.3.g30247aa5d201 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#69025): https://edk2.groups.io/g/devel/message/69025 Mute This Topic: https://groups.io/mt/79022983/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Tue May 7 07:56:31 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+69026+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+69026+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1608154617; cv=none; d=zohomail.com; s=zohoarc; b=N8WWDpTxkneKQw1qlO4aXc7o5rUzUySrNFuSYryPgD7GmyF94ceu3L2hNx1tlpZzAuc0x3iyNLHgOOGVOcD4E7sshPOOFkj+GxHNHBRwMyGH2C43F3SJCTvX8dMjmsrguy864gcJQVL4szHDgwUdnHS+TD0IXjDp7Iq+vOmJ1Jk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608154617; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=E/AA5E2VqVDJBTKamLVBas1L900Lsd/zVLO+imNkx0U=; b=U1xAdUR/w0xsK2okvyKzs1tsXCrBl25WUtnfnk0AS0D+jR1RqMPNbaYuuO7WXofg9ld5XTIY4gUIpU5VDKRx054Tip70yCIIFoGUB9sz/a0/N02TcKhi88glM7seN6KkV/BV1U6Lsmm9joUXMlC7sf1TN1jESjdg+HA9MvU4eN8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+69026+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) header.from= Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1608154617958569.709956656422; Wed, 16 Dec 2020 13:36:57 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id PFYoYY1788612xDGcKEDtYfU; Wed, 16 Dec 2020 13:36:57 -0800 X-Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.groups.io with SMTP id smtpd.web09.3759.1608154611875723771 for ; Wed, 16 Dec 2020 13:36:52 -0800 X-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-87-_o6owpZPOzOSHNpMZ6F0pg-1; Wed, 16 Dec 2020 16:36:47 -0500 X-MC-Unique: _o6owpZPOzOSHNpMZ6F0pg-1 X-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 06C1C1015C80; Wed, 16 Dec 2020 21:36:46 +0000 (UTC) X-Received: from lacos-laptop-7.usersys.redhat.com (ovpn-114-152.ams2.redhat.com [10.36.114.152]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7F8FC10021B3; Wed, 16 Dec 2020 21:36:41 +0000 (UTC) From: "Laszlo Ersek" To: devel@edk2.groups.io, virtio-fs@redhat.com, lersek@redhat.com Cc: Ard Biesheuvel , Jordan Justen , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [edk2-devel] [edk2 PATCH 12/48] OvmfPkg/VirtioFsDxe: implement the wrapper function for FUSE_FORGET Date: Wed, 16 Dec 2020 22:10:49 +0100 Message-Id: <20201216211125.19496-13-lersek@redhat.com> In-Reply-To: <20201216211125.19496-1-lersek@redhat.com> References: <20201216211125.19496-1-lersek@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,lersek@redhat.com X-Gm-Message-State: OBAgInMDy42FnKlj9axOhX8Bx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1608154617; bh=E/AA5E2VqVDJBTKamLVBas1L900Lsd/zVLO+imNkx0U=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=RRJMVyNDuM5SqkBJgg1puTPCmIeA8XFQIzSb8EWGtggK3VhWqTctyNuhphpn6oWf05L Pv25nzeXZqYH2nqi5uJVbXQ41XBXTUWMz2RoCiA7GGDpS4+mgPfNGh7J8gCcfv5hAQFE3 BjSmqhe9Dcqg2QNSH+wE7Jk4pcB4Fw2b0CU= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" Add the VirtioFsFuseForget() function, for sending the FUSE_FORGET command to the Virtio Filesystem device. This is an unusual command in that it doesn't generate any response from the FUSE server. Cc: Ard Biesheuvel Cc: Jordan Justen Cc: Philippe Mathieu-Daud=C3=A9 Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3097 Signed-off-by: Laszlo Ersek Acked-by: Ard Biesheuvel --- OvmfPkg/Include/IndustryStandard/VirtioFs.h | 8 ++ OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf | 1 + OvmfPkg/VirtioFsDxe/VirtioFsDxe.h | 6 ++ OvmfPkg/VirtioFsDxe/FuseForget.c | 85 ++++++++++++++++++++ 4 files changed, 100 insertions(+) diff --git a/OvmfPkg/Include/IndustryStandard/VirtioFs.h b/OvmfPkg/Include/= IndustryStandard/VirtioFs.h index 67fcf975e8b2..0241daf1e8d6 100644 --- a/OvmfPkg/Include/IndustryStandard/VirtioFs.h +++ b/OvmfPkg/Include/IndustryStandard/VirtioFs.h @@ -80,16 +80,17 @@ typedef struct { // The inode number of the root directory. // #define VIRTIO_FS_FUSE_ROOT_DIR_NODE_ID 1 =20 // // FUSE operation codes. // typedef enum { + VirtioFsFuseOpForget =3D 2, VirtioFsFuseOpRelease =3D 18, VirtioFsFuseOpInit =3D 26, VirtioFsFuseOpOpenDir =3D 27, VirtioFsFuseOpReleaseDir =3D 29, } VIRTIO_FS_FUSE_OPCODE; =20 #pragma pack (1) // @@ -107,16 +108,23 @@ typedef struct { } VIRTIO_FS_FUSE_REQUEST; =20 typedef struct { UINT32 Len; INT32 Error; UINT64 Unique; } VIRTIO_FS_FUSE_RESPONSE; =20 +// +// Header for VirtioFsFuseOpForget. +// +typedef struct { + UINT64 NumberOfLookups; +} VIRTIO_FS_FUSE_FORGET_REQUEST; + // // Header for VirtioFsFuseOpRelease and VirtioFsFuseOpReleaseDir. // typedef struct { UINT64 FileHandle; UINT32 Flags; UINT32 ReleaseFlags; UINT64 LockOwner; diff --git a/OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf b/OvmfPkg/VirtioFsDxe/Virt= ioFsDxe.inf index 28e66082ecfe..baeb741be18f 100644 --- a/OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf +++ b/OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf @@ -77,16 +77,17 @@ [Defines] ENTRY_POINT =3D VirtioFsEntryPoint =20 [Packages] MdePkg/MdePkg.dec OvmfPkg/OvmfPkg.dec =20 [Sources] DriverBinding.c + FuseForget.c FuseInit.c FuseOpenDir.c FuseRelease.c Helpers.c SimpleFsClose.c SimpleFsDelete.c SimpleFsFlush.c SimpleFsGetInfo.c diff --git a/OvmfPkg/VirtioFsDxe/VirtioFsDxe.h b/OvmfPkg/VirtioFsDxe/Virtio= FsDxe.h index 34574d0596fc..68ed6cd7e6a1 100644 --- a/OvmfPkg/VirtioFsDxe/VirtioFsDxe.h +++ b/OvmfPkg/VirtioFsDxe/VirtioFsDxe.h @@ -190,16 +190,22 @@ EFI_STATUS VirtioFsErrnoToEfiStatus ( IN INT32 Errno ); =20 // // Wrapper functions for FUSE commands (primitives). // =20 +EFI_STATUS +VirtioFsFuseForget ( + IN OUT VIRTIO_FS *VirtioFs, + IN UINT64 NodeId + ); + EFI_STATUS VirtioFsFuseReleaseFileOrDir ( IN OUT VIRTIO_FS *VirtioFs, IN UINT64 NodeId, IN UINT64 FuseHandle, IN BOOLEAN IsDir ); =20 diff --git a/OvmfPkg/VirtioFsDxe/FuseForget.c b/OvmfPkg/VirtioFsDxe/FuseFor= get.c new file mode 100644 index 000000000000..fdee42cffbff --- /dev/null +++ b/OvmfPkg/VirtioFsDxe/FuseForget.c @@ -0,0 +1,85 @@ +/** @file + FUSE_FORGET wrapper for the Virtio Filesystem device. + + Copyright (C) 2020, Red Hat, Inc. + + SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#include "VirtioFsDxe.h" + +/** + Make the Virtio Filesysem device drop one reference count from a NodeId = that + the driver looked up by filename. + + Send the FUSE_FORGET request to the Virtio Filesysem device for this. Un= like + most other FUSE requests, FUSE_FORGET doesn't elicit a response, not eve= n the + common VIRTIO_FS_FUSE_RESPONSE header. + + The function may only be called after VirtioFsFuseInitSession() returns + successfully and before VirtioFsUninit() is called. + + @param[in,out] VirtioFs The Virtio Filesystem device to send the FUSE_F= ORGET + request to. On output, the FUSE request counter + "VirtioFs->RequestId" will have been incremente= d. + + @param[in] NodeId The inode number that the client learned by way= of + lookup, and that the server should now un-refer= ence + exactly once. + + @retval EFI_SUCCESS The FUSE_FORGET request has been submitted. + + @return Error codes propagated from VirtioFsSgListsValidate= (), + VirtioFsFuseNewRequest(), VirtioFsSgListsSubmit(). +**/ +EFI_STATUS +VirtioFsFuseForget ( + IN OUT VIRTIO_FS *VirtioFs, + IN UINT64 NodeId + ) +{ + VIRTIO_FS_FUSE_REQUEST CommonReq; + VIRTIO_FS_FUSE_FORGET_REQUEST ForgetReq; + VIRTIO_FS_IO_VECTOR ReqIoVec[2]; + VIRTIO_FS_SCATTER_GATHER_LIST ReqSgList; + EFI_STATUS Status; + + // + // Set up the scatter-gather list (note: only request). + // + ReqIoVec[0].Buffer =3D &CommonReq; + ReqIoVec[0].Size =3D sizeof CommonReq; + ReqIoVec[1].Buffer =3D &ForgetReq; + ReqIoVec[1].Size =3D sizeof ForgetReq; + ReqSgList.IoVec =3D ReqIoVec; + ReqSgList.NumVec =3D ARRAY_SIZE (ReqIoVec); + + // + // Validate the scatter-gather list (request only); calculate the total + // transfer size. + // + Status =3D VirtioFsSgListsValidate (VirtioFs, &ReqSgList, NULL); + if (EFI_ERROR (Status)) { + return Status; + } + + // + // Populate the common request header. + // + Status =3D VirtioFsFuseNewRequest (VirtioFs, &CommonReq, ReqSgList.Total= Size, + VirtioFsFuseOpForget, NodeId); + if (EFI_ERROR (Status)) { + return Status; + } + + // + // Populate the FUSE_FORGET-specific fields. + // + ForgetReq.NumberOfLookups =3D 1; + + // + // Submit the request. There's not going to be a response. + // + Status =3D VirtioFsSgListsSubmit (VirtioFs, &ReqSgList, NULL); + return Status; +} --=20 2.19.1.3.g30247aa5d201 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#69026): https://edk2.groups.io/g/devel/message/69026 Mute This Topic: https://groups.io/mt/79023011/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Tue May 7 07:56:31 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+69027+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+69027+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1608154739; cv=none; d=zohomail.com; s=zohoarc; b=jnzNfgDSa300eRWttm+sj9vssgp9JJOuDvPwzKs4Bdsk+CupYLv4kVMDhJdkNExa1us6pB5xkdGJuTldVOHY4m6irtoWqTU0GXO/eY1HxkpUuyUEpY5TmsfPFVvg5aUppHxQONzmM+Fk6n4p+uFyZHfgHjUA+MNDe2wf+jhZiGU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608154739; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=cCvsPd5UAXdEUbk8RLnxJppe2O0OanczctWK8RXoTzU=; b=gIaKrapqpRQajXx1kezvOgRxdspKLXp6Ls3f+OzMOXFNyJwUiP195ChHIldUbeOB1ktA5b26NydCQPMx0gliRPyMgHNl5w5jyCM24CcNgH8lD/p9XZ+wn5099AEXOia38a9nxbxmR7Y5m79KU44ItPdDRxpeAZn5xeLxsVuCIAU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+69027+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) header.from= Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1608154739017582.529942879904; Wed, 16 Dec 2020 13:38:59 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id N3iFYY1788612xreJgAn82rA; Wed, 16 Dec 2020 13:38:58 -0800 X-Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.groups.io with SMTP id smtpd.web08.3936.1608154737860626420 for ; Wed, 16 Dec 2020 13:38:58 -0800 X-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-321-9T45EBEAMRCPUmoD4cq_Lg-1; Wed, 16 Dec 2020 16:38:53 -0500 X-MC-Unique: 9T45EBEAMRCPUmoD4cq_Lg-1 X-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 DE0D4180A087; Wed, 16 Dec 2020 21:38:51 +0000 (UTC) X-Received: from lacos-laptop-7.usersys.redhat.com (ovpn-114-152.ams2.redhat.com [10.36.114.152]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3566460C9C; Wed, 16 Dec 2020 21:38:47 +0000 (UTC) From: "Laszlo Ersek" To: devel@edk2.groups.io, virtio-fs@redhat.com, lersek@redhat.com Cc: Ard Biesheuvel , Jordan Justen , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [edk2-devel] [edk2 PATCH 13/48] OvmfPkg/VirtioFsDxe: add a shared wrapper for FUSE_FSYNC / FUSE_FSYNCDIR Date: Wed, 16 Dec 2020 22:10:50 +0100 Message-Id: <20201216211125.19496-14-lersek@redhat.com> In-Reply-To: <20201216211125.19496-1-lersek@redhat.com> References: <20201216211125.19496-1-lersek@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,lersek@redhat.com X-Gm-Message-State: UUQXtf4aGERJMt7HEx0DVhzJx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1608154738; bh=cCvsPd5UAXdEUbk8RLnxJppe2O0OanczctWK8RXoTzU=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=oXNq755jz1J3NFxNLEMI2Y+IGpWUprKnyENYPJxi1kqZUyNhQjLVrGXNKNv6PjAKGMF wmsWFbK8k0W+313M7P4d2hmhhR1fwzWUXVj4sMm2SyeK7Z9wtLqT2sTYZY/4rEhD8zYT7 F2RUenRCtiW4jUFNppCym9qpv9r2N0xTe6k= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" The FUSE_FSYNC and FUSE_FSYNCDIR commands only differ in the opcode. Add a common function for wrapping both. Cc: Ard Biesheuvel Cc: Jordan Justen Cc: Philippe Mathieu-Daud=C3=A9 Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3097 Signed-off-by: Laszlo Ersek Acked-by: Ard Biesheuvel --- OvmfPkg/Include/IndustryStandard/VirtioFs.h | 11 ++ OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf | 1 + OvmfPkg/VirtioFsDxe/VirtioFsDxe.h | 8 ++ OvmfPkg/VirtioFsDxe/FuseFsync.c | 121 ++++++++++++++++++++ 4 files changed, 141 insertions(+) diff --git a/OvmfPkg/Include/IndustryStandard/VirtioFs.h b/OvmfPkg/Include/= IndustryStandard/VirtioFs.h index 0241daf1e8d6..797d94a39a39 100644 --- a/OvmfPkg/Include/IndustryStandard/VirtioFs.h +++ b/OvmfPkg/Include/IndustryStandard/VirtioFs.h @@ -82,19 +82,21 @@ typedef struct { #define VIRTIO_FS_FUSE_ROOT_DIR_NODE_ID 1 =20 // // FUSE operation codes. // typedef enum { VirtioFsFuseOpForget =3D 2, VirtioFsFuseOpRelease =3D 18, + VirtioFsFuseOpFsync =3D 20, VirtioFsFuseOpInit =3D 26, VirtioFsFuseOpOpenDir =3D 27, VirtioFsFuseOpReleaseDir =3D 29, + VirtioFsFuseOpFsyncDir =3D 30, } VIRTIO_FS_FUSE_OPCODE; =20 #pragma pack (1) // // Request-response headers common to all request types. // typedef struct { UINT32 Len; @@ -125,16 +127,25 @@ typedef struct { // typedef struct { UINT64 FileHandle; UINT32 Flags; UINT32 ReleaseFlags; UINT64 LockOwner; } VIRTIO_FS_FUSE_RELEASE_REQUEST; =20 +// +// Header for VirtioFsFuseOpFsync and VirtioFsFuseOpFsyncDir. +// +typedef struct { + UINT64 FileHandle; + UINT32 FsyncFlags; + UINT32 Padding; +} VIRTIO_FS_FUSE_FSYNC_REQUEST; + // // Headers for VirtioFsFuseOpInit. // typedef struct { UINT32 Major; UINT32 Minor; UINT32 MaxReadahead; UINT32 Flags; diff --git a/OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf b/OvmfPkg/VirtioFsDxe/Virt= ioFsDxe.inf index baeb741be18f..839660a0f904 100644 --- a/OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf +++ b/OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf @@ -78,16 +78,17 @@ [Defines] =20 [Packages] MdePkg/MdePkg.dec OvmfPkg/OvmfPkg.dec =20 [Sources] DriverBinding.c FuseForget.c + FuseFsync.c FuseInit.c FuseOpenDir.c FuseRelease.c Helpers.c SimpleFsClose.c SimpleFsDelete.c SimpleFsFlush.c SimpleFsGetInfo.c diff --git a/OvmfPkg/VirtioFsDxe/VirtioFsDxe.h b/OvmfPkg/VirtioFsDxe/Virtio= FsDxe.h index 68ed6cd7e6a1..ac1fb8965472 100644 --- a/OvmfPkg/VirtioFsDxe/VirtioFsDxe.h +++ b/OvmfPkg/VirtioFsDxe/VirtioFsDxe.h @@ -204,16 +204,24 @@ VirtioFsFuseForget ( EFI_STATUS VirtioFsFuseReleaseFileOrDir ( IN OUT VIRTIO_FS *VirtioFs, IN UINT64 NodeId, IN UINT64 FuseHandle, IN BOOLEAN IsDir ); =20 +EFI_STATUS +VirtioFsFuseFsyncFileOrDir ( + IN OUT VIRTIO_FS *VirtioFs, + IN UINT64 NodeId, + IN UINT64 FuseHandle, + IN BOOLEAN IsDir + ); + EFI_STATUS VirtioFsFuseInitSession ( IN OUT VIRTIO_FS *VirtioFs ); =20 EFI_STATUS VirtioFsFuseOpenDir ( IN OUT VIRTIO_FS *VirtioFs, diff --git a/OvmfPkg/VirtioFsDxe/FuseFsync.c b/OvmfPkg/VirtioFsDxe/FuseFsyn= c.c new file mode 100644 index 000000000000..ea1463cd8073 --- /dev/null +++ b/OvmfPkg/VirtioFsDxe/FuseFsync.c @@ -0,0 +1,121 @@ +/** @file + FUSE_FSYNC / FUSE_FSYNCDIR wrapper for the Virtio Filesystem device. + + Copyright (C) 2020, Red Hat, Inc. + + SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#include "VirtioFsDxe.h" + +/** + Synchronize the in-core state of a regular file or a directory with the + storage device on the host, by sending the FUSE_FSYNC or FUSE_FSYNCDIR + request to the Virtio Filesystem device. + + The function may only be called after VirtioFsFuseInitSession() returns + successfully and before VirtioFsUninit() is called. + + @param[in,out] VirtioFs The Virtio Filesystem device to send the FUSE_F= SYNC + / FUSE_FSYNCDIR request to. On output, the FUSE + request counter "VirtioFs->RequestId" will have= been + incremented. + + @param[in] NodeId The inode number of the file or directory to sy= nc. + + @param[in] FuseHandle The open handle to the file or directory to syn= c. + + @param[in] IsDir TRUE if NodeId and FuseHandle refer to a direct= ory, + FALSE if NodeId and FuseHandle refer to a regul= ar + file. + + @retval EFI_SUCCESS The file or directory has been synchronized. + + @return The "errno" value mapped to an EFI_STATUS code, if = the + Virtio Filesystem device explicitly reported an err= or. + + @return Error codes propagated from VirtioFsSgListsValidate= (), + VirtioFsFuseNewRequest(), VirtioFsSgListsSubmit(), + VirtioFsFuseCheckResponse(). +**/ +EFI_STATUS +VirtioFsFuseFsyncFileOrDir ( + IN OUT VIRTIO_FS *VirtioFs, + IN UINT64 NodeId, + IN UINT64 FuseHandle, + IN BOOLEAN IsDir + ) +{ + VIRTIO_FS_FUSE_REQUEST CommonReq; + VIRTIO_FS_FUSE_FSYNC_REQUEST FsyncReq; + VIRTIO_FS_IO_VECTOR ReqIoVec[2]; + VIRTIO_FS_SCATTER_GATHER_LIST ReqSgList; + VIRTIO_FS_FUSE_RESPONSE CommonResp; + VIRTIO_FS_IO_VECTOR RespIoVec[1]; + VIRTIO_FS_SCATTER_GATHER_LIST RespSgList; + EFI_STATUS Status; + + // + // Set up the scatter-gather lists. + // + ReqIoVec[0].Buffer =3D &CommonReq; + ReqIoVec[0].Size =3D sizeof CommonReq; + ReqIoVec[1].Buffer =3D &FsyncReq; + ReqIoVec[1].Size =3D sizeof FsyncReq; + ReqSgList.IoVec =3D ReqIoVec; + ReqSgList.NumVec =3D ARRAY_SIZE (ReqIoVec); + + RespIoVec[0].Buffer =3D &CommonResp; + RespIoVec[0].Size =3D sizeof CommonResp; + RespSgList.IoVec =3D RespIoVec; + RespSgList.NumVec =3D ARRAY_SIZE (RespIoVec); + + // + // Validate the scatter-gather lists; calculate the total transfer sizes. + // + Status =3D VirtioFsSgListsValidate (VirtioFs, &ReqSgList, &RespSgList); + if (EFI_ERROR (Status)) { + return Status; + } + + // + // Populate the common request header. + // + Status =3D VirtioFsFuseNewRequest ( + VirtioFs, + &CommonReq, + ReqSgList.TotalSize, + IsDir ? VirtioFsFuseOpFsyncDir : VirtioFsFuseOpFsync, + NodeId + ); + if (EFI_ERROR (Status)) { + return Status; + } + + // + // Populate the FUSE_FSYNC- / FUSE_FSYNCDIR-specific fields. + // + FsyncReq.FileHandle =3D FuseHandle; + FsyncReq.FsyncFlags =3D 0; + FsyncReq.Padding =3D 0; + + // + // Submit the request. + // + Status =3D VirtioFsSgListsSubmit (VirtioFs, &ReqSgList, &RespSgList); + if (EFI_ERROR (Status)) { + return Status; + } + + // + // Verify the response (all response buffers are fixed size). + // + Status =3D VirtioFsFuseCheckResponse (&RespSgList, CommonReq.Unique, NUL= L); + if (Status =3D=3D EFI_DEVICE_ERROR) { + DEBUG ((DEBUG_ERROR, "%a: Label=3D\"%s\" NodeId=3D%Lu FuseHandle=3D%Lu= " + "IsDir=3D%d Errno=3D%d\n", __FUNCTION__, VirtioFs->Label, NodeId, Fu= seHandle, + IsDir, CommonResp.Error)); + Status =3D VirtioFsErrnoToEfiStatus (CommonResp.Error); + } + return Status; +} --=20 2.19.1.3.g30247aa5d201 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#69027): https://edk2.groups.io/g/devel/message/69027 Mute This Topic: https://groups.io/mt/79023053/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Tue May 7 07:56:31 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+69028+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+69028+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1608154862; cv=none; d=zohomail.com; s=zohoarc; b=hKh5mtWPfRp/ns8iAY5mnVqK0R0ODHNzSw/hr1AAamRdQ8YXHY3Bc+4tmVe75muwo6KidGUI0Y1enAXKlCJ3vXj+w3HzEFgHbcDyUUSkPmfWPLVgJwU5pTFFuA494O3VoZuGggLSzZJfeCx9O8fLGmLX7YN84PgifJgqzZNMws0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608154862; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=cwpLGJdjf5wqNXuzK2b3VaDexFu7G8AaOaL0OfXbcLQ=; b=k2GSp5vbP/r5DENi0l5YZv8dXjRRVOLHoDXBfP6+QmF53Lc4aO0RpTWYjZbDs1JBPFdijS2ckSp3OygQfq8wX9vJ4nvULs0ahEbuDbNFY4YBDTvHA+UOJPTNAvYKx5PMCaEQDKPMtnKfPD2lmHjzvYwTvMIi2qcrKwR461ASoaQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+69028+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) header.from= Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1608154862690221.0259389123762; Wed, 16 Dec 2020 13:41:02 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id WqM4YY1788612x3SntdHVjjT; Wed, 16 Dec 2020 13:41:02 -0800 X-Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.groups.io with SMTP id smtpd.web10.4042.1608154861697625893 for ; Wed, 16 Dec 2020 13:41:01 -0800 X-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-253-wYJBj1R0OKO-wB5Y1oKVjg-1; Wed, 16 Dec 2020 16:40:59 -0500 X-MC-Unique: wYJBj1R0OKO-wB5Y1oKVjg-1 X-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 E58A61005504; Wed, 16 Dec 2020 21:40:57 +0000 (UTC) X-Received: from lacos-laptop-7.usersys.redhat.com (ovpn-114-152.ams2.redhat.com [10.36.114.152]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1A8145D9C0; Wed, 16 Dec 2020 21:40:52 +0000 (UTC) From: "Laszlo Ersek" To: devel@edk2.groups.io, virtio-fs@redhat.com, lersek@redhat.com Cc: Ard Biesheuvel , Jordan Justen , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [edk2-devel] [edk2 PATCH 14/48] OvmfPkg/VirtioFsDxe: implement the wrapper function for FUSE_FLUSH Date: Wed, 16 Dec 2020 22:10:51 +0100 Message-Id: <20201216211125.19496-15-lersek@redhat.com> In-Reply-To: <20201216211125.19496-1-lersek@redhat.com> References: <20201216211125.19496-1-lersek@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,lersek@redhat.com X-Gm-Message-State: bG9Up2G6rsGU2fLOmKl4NfXjx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1608154862; bh=cwpLGJdjf5wqNXuzK2b3VaDexFu7G8AaOaL0OfXbcLQ=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=ae0CPCbsdjVojUqZrOSRERMLh3kXF/08ZJ/fv2nsguiU9rLZ7qfTMxa68yRghBFItKd xGKM4lWN81eMYq7l55FO9fz27xErbg33vNlU8oOkfWbIUPDbcrfRN8sT3Llbwn2p4k0IY cblu4PTjN39lZPoBbqGC+/LFHdhK+S5ih6E= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" Add the VirtioFsFuseFlush() function, for sending the FUSE_FLUSH command to the Virtio Filesystem device. Cc: Ard Biesheuvel Cc: Jordan Justen Cc: Philippe Mathieu-Daud=C3=A9 Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3097 Signed-off-by: Laszlo Ersek Acked-by: Ard Biesheuvel --- OvmfPkg/Include/IndustryStandard/VirtioFs.h | 11 ++ OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf | 1 + OvmfPkg/VirtioFsDxe/VirtioFsDxe.h | 7 ++ OvmfPkg/VirtioFsDxe/FuseFlush.c | 111 ++++++++++++++++++++ 4 files changed, 130 insertions(+) diff --git a/OvmfPkg/Include/IndustryStandard/VirtioFs.h b/OvmfPkg/Include/= IndustryStandard/VirtioFs.h index 797d94a39a39..fec2f4be531f 100644 --- a/OvmfPkg/Include/IndustryStandard/VirtioFs.h +++ b/OvmfPkg/Include/IndustryStandard/VirtioFs.h @@ -83,16 +83,17 @@ typedef struct { =20 // // FUSE operation codes. // typedef enum { VirtioFsFuseOpForget =3D 2, VirtioFsFuseOpRelease =3D 18, VirtioFsFuseOpFsync =3D 20, + VirtioFsFuseOpFlush =3D 25, VirtioFsFuseOpInit =3D 26, VirtioFsFuseOpOpenDir =3D 27, VirtioFsFuseOpReleaseDir =3D 29, VirtioFsFuseOpFsyncDir =3D 30, } VIRTIO_FS_FUSE_OPCODE; =20 #pragma pack (1) // @@ -136,16 +137,26 @@ typedef struct { // Header for VirtioFsFuseOpFsync and VirtioFsFuseOpFsyncDir. // typedef struct { UINT64 FileHandle; UINT32 FsyncFlags; UINT32 Padding; } VIRTIO_FS_FUSE_FSYNC_REQUEST; =20 +// +// Header for VirtioFsFuseOpFlush. +// +typedef struct { + UINT64 FileHandle; + UINT32 Unused; + UINT32 Padding; + UINT64 LockOwner; +} VIRTIO_FS_FUSE_FLUSH_REQUEST; + // // Headers for VirtioFsFuseOpInit. // typedef struct { UINT32 Major; UINT32 Minor; UINT32 MaxReadahead; UINT32 Flags; diff --git a/OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf b/OvmfPkg/VirtioFsDxe/Virt= ioFsDxe.inf index 839660a0f904..15e21772c8ac 100644 --- a/OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf +++ b/OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf @@ -77,16 +77,17 @@ [Defines] ENTRY_POINT =3D VirtioFsEntryPoint =20 [Packages] MdePkg/MdePkg.dec OvmfPkg/OvmfPkg.dec =20 [Sources] DriverBinding.c + FuseFlush.c FuseForget.c FuseFsync.c FuseInit.c FuseOpenDir.c FuseRelease.c Helpers.c SimpleFsClose.c SimpleFsDelete.c diff --git a/OvmfPkg/VirtioFsDxe/VirtioFsDxe.h b/OvmfPkg/VirtioFsDxe/Virtio= FsDxe.h index ac1fb8965472..7151a62bb42b 100644 --- a/OvmfPkg/VirtioFsDxe/VirtioFsDxe.h +++ b/OvmfPkg/VirtioFsDxe/VirtioFsDxe.h @@ -212,16 +212,23 @@ VirtioFsFuseReleaseFileOrDir ( EFI_STATUS VirtioFsFuseFsyncFileOrDir ( IN OUT VIRTIO_FS *VirtioFs, IN UINT64 NodeId, IN UINT64 FuseHandle, IN BOOLEAN IsDir ); =20 +EFI_STATUS +VirtioFsFuseFlush ( + IN OUT VIRTIO_FS *VirtioFs, + IN UINT64 NodeId, + IN UINT64 FuseHandle + ); + EFI_STATUS VirtioFsFuseInitSession ( IN OUT VIRTIO_FS *VirtioFs ); =20 EFI_STATUS VirtioFsFuseOpenDir ( IN OUT VIRTIO_FS *VirtioFs, diff --git a/OvmfPkg/VirtioFsDxe/FuseFlush.c b/OvmfPkg/VirtioFsDxe/FuseFlus= h.c new file mode 100644 index 000000000000..b689ad32910a --- /dev/null +++ b/OvmfPkg/VirtioFsDxe/FuseFlush.c @@ -0,0 +1,111 @@ +/** @file + FUSE_FLUSH wrapper for the Virtio Filesystem device. + + Copyright (C) 2020, Red Hat, Inc. + + SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#include "VirtioFsDxe.h" + +/** + Flush changes queued on the local virtualization host to the remote stor= age + server's memory (not storage device), over the network, by sending the + FUSE_FLUSH request to the Virtio Filesystem device. + + The function may only be called after VirtioFsFuseInitSession() returns + successfully and before VirtioFsUninit() is called. + + @param[in,out] VirtioFs The Virtio Filesystem device to send the FUSE_F= LUSH + request to. On output, the FUSE request counter + "VirtioFs->RequestId" will have been incremente= d. + + @param[in] NodeId The inode number of the regular file to flush. + + @param[in] FuseHandle The open handle to the regular file to flush. + + @retval EFI_SUCCESS The regular file has been flushed. + + @return The "errno" value mapped to an EFI_STATUS code, if = the + Virtio Filesystem device explicitly reported an err= or. + + @return Error codes propagated from VirtioFsSgListsValidate= (), + VirtioFsFuseNewRequest(), VirtioFsSgListsSubmit(), + VirtioFsFuseCheckResponse(). +**/ +EFI_STATUS +VirtioFsFuseFlush ( + IN OUT VIRTIO_FS *VirtioFs, + IN UINT64 NodeId, + IN UINT64 FuseHandle + ) +{ + VIRTIO_FS_FUSE_REQUEST CommonReq; + VIRTIO_FS_FUSE_FLUSH_REQUEST FlushReq; + VIRTIO_FS_IO_VECTOR ReqIoVec[2]; + VIRTIO_FS_SCATTER_GATHER_LIST ReqSgList; + VIRTIO_FS_FUSE_RESPONSE CommonResp; + VIRTIO_FS_IO_VECTOR RespIoVec[1]; + VIRTIO_FS_SCATTER_GATHER_LIST RespSgList; + EFI_STATUS Status; + + // + // Set up the scatter-gather lists. + // + ReqIoVec[0].Buffer =3D &CommonReq; + ReqIoVec[0].Size =3D sizeof CommonReq; + ReqIoVec[1].Buffer =3D &FlushReq; + ReqIoVec[1].Size =3D sizeof FlushReq; + ReqSgList.IoVec =3D ReqIoVec; + ReqSgList.NumVec =3D ARRAY_SIZE (ReqIoVec); + + RespIoVec[0].Buffer =3D &CommonResp; + RespIoVec[0].Size =3D sizeof CommonResp; + RespSgList.IoVec =3D RespIoVec; + RespSgList.NumVec =3D ARRAY_SIZE (RespIoVec); + + // + // Validate the scatter-gather lists; calculate the total transfer sizes. + // + Status =3D VirtioFsSgListsValidate (VirtioFs, &ReqSgList, &RespSgList); + if (EFI_ERROR (Status)) { + return Status; + } + + // + // Populate the common request header. + // + Status =3D VirtioFsFuseNewRequest (VirtioFs, &CommonReq, ReqSgList.Total= Size, + VirtioFsFuseOpFlush, NodeId); + if (EFI_ERROR (Status)) { + return Status; + } + + // + // Populate the FUSE_FLUSH-specific fields. + // + FlushReq.FileHandle =3D FuseHandle; + FlushReq.Unused =3D 0; + FlushReq.Padding =3D 0; + FlushReq.LockOwner =3D 0; + + // + // Submit the request. + // + Status =3D VirtioFsSgListsSubmit (VirtioFs, &ReqSgList, &RespSgList); + if (EFI_ERROR (Status)) { + return Status; + } + + // + // Verify the response (all response buffers are fixed size). + // + Status =3D VirtioFsFuseCheckResponse (&RespSgList, CommonReq.Unique, NUL= L); + if (Status =3D=3D EFI_DEVICE_ERROR) { + DEBUG ((DEBUG_ERROR, "%a: Label=3D\"%s\" NodeId=3D%Lu FuseHandle=3D%Lu= " + "Errno=3D%d\n", __FUNCTION__, VirtioFs->Label, NodeId, FuseHandle, + CommonResp.Error)); + Status =3D VirtioFsErrnoToEfiStatus (CommonResp.Error); + } + return Status; +} --=20 2.19.1.3.g30247aa5d201 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#69028): https://edk2.groups.io/g/devel/message/69028 Mute This Topic: https://groups.io/mt/79023105/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Tue May 7 07:56:31 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+69029+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+69029+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1608154995; cv=none; d=zohomail.com; s=zohoarc; b=Y7T7D7/0ITj9eBeT+f3EieaINOtO6euqBg7eTF8jtHVfDVqFffuWy2fZbELoAHEgkeau9DvuySM+P6/P722uECUl4AqDrykC7KnQrR5tABFPDaZWa+g/qa7C30mBB8/Vwg4PWKut2UZaoWiohV/6Hv634H4lpquiXeIaAo5YR3M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608154995; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=SUouXpIEa9hfJ2V35njxyKU/mCto7glsOSX0e8E+qyk=; b=XHEI4ApVrGB3ozh+eRQW+nBNOYYFdvMQ/G1ESjUPKWTUjobyiuTtULt6kPc6maKPtWhWgtNRFiPSxTtRHbcJ4pGrkPZQ6gvIB7RBDClO6uS2PEHecXJoVUIlwxYlBg8VWIaXOvwRd9S/gRh+pvupM+myw42xov8ca6zHA97RqbY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+69029+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) header.from= Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1608154995148393.4398791829932; Wed, 16 Dec 2020 13:43:15 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id ohLbYY1788612xdc2bLLrz0G; Wed, 16 Dec 2020 13:43:14 -0800 X-Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.groups.io with SMTP id smtpd.web10.4075.1608154992662794590 for ; Wed, 16 Dec 2020 13:43:12 -0800 X-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-312-IKvaRMSgO4Gm1u0IXq1lLg-1; Wed, 16 Dec 2020 16:43:04 -0500 X-MC-Unique: IKvaRMSgO4Gm1u0IXq1lLg-1 X-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 CB6B8800D55; Wed, 16 Dec 2020 21:43:03 +0000 (UTC) X-Received: from lacos-laptop-7.usersys.redhat.com (ovpn-114-152.ams2.redhat.com [10.36.114.152]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3690860C15; Wed, 16 Dec 2020 21:42:58 +0000 (UTC) From: "Laszlo Ersek" To: devel@edk2.groups.io, virtio-fs@redhat.com, lersek@redhat.com Cc: Ard Biesheuvel , Jordan Justen , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [edk2-devel] [edk2 PATCH 15/48] OvmfPkg/VirtioFsDxe: flush, sync, release and forget in Close() / Delete() Date: Wed, 16 Dec 2020 22:10:52 +0100 Message-Id: <20201216211125.19496-16-lersek@redhat.com> In-Reply-To: <20201216211125.19496-1-lersek@redhat.com> References: <20201216211125.19496-1-lersek@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,lersek@redhat.com X-Gm-Message-State: AEPOf1T4BGQBH5jUbM5reZfwx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1608154994; bh=SUouXpIEa9hfJ2V35njxyKU/mCto7glsOSX0e8E+qyk=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=AvJRClskvYpn7L6ks4CGcYidzEMZdtt3ZC243muiWiVTbEkP7VEWnUCHycTx6h4WFcr j0b1mNAYm4IG4iCzuNeXigi3vb8fp/YQqnirW6XEXF3AxTZ7tLV8W+VbHo2CtNDpn0LD7 EYseWMuOkcTNlHVcNb2wqVKDI3YM4qnNe6U= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" The two member functions that free the EFI_FILE_PROTOCOL object are Close() and Delete(). Before we create VIRTIO_FS_FILE objects with EFI_FILE_PROTOCOL.Open() later in this patch series, extend each of these "destructor" functions to get rid of the FuseHandle and NodeId resources properly -- in a way that matches each function's own purpose. For the time being, VirtioFsSimpleFileDelete() only gets a reminder about its core task (namely, removing the file), as the needed machinery will become only later. But we can already outline the "task list", and deal with the FuseHandle and NodeId resources. The "task list" of VirtioFsSimpleFileDelete() is different from that of VirtioFsSimpleFileClose(), thus both destructors diverge at this point. Cc: Ard Biesheuvel Cc: Jordan Justen Cc: Philippe Mathieu-Daud=C3=A9 Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3097 Signed-off-by: Laszlo Ersek Acked-by: Ard Biesheuvel --- OvmfPkg/VirtioFsDxe/VirtioFsDxe.h | 1 + OvmfPkg/VirtioFsDxe/SimpleFsClose.c | 34 ++++++++---- OvmfPkg/VirtioFsDxe/SimpleFsDelete.c | 55 +++++++++++++++++--- OvmfPkg/VirtioFsDxe/SimpleFsOpenVolume.c | 1 + 4 files changed, 74 insertions(+), 17 deletions(-) diff --git a/OvmfPkg/VirtioFsDxe/VirtioFsDxe.h b/OvmfPkg/VirtioFsDxe/Virtio= FsDxe.h index 7151a62bb42b..1cbd27d8fb52 100644 --- a/OvmfPkg/VirtioFsDxe/VirtioFsDxe.h +++ b/OvmfPkg/VirtioFsDxe/VirtioFsDxe.h @@ -105,16 +105,17 @@ typedef struct { // // Private context structure that exposes EFI_FILE_PROTOCOL on top of an o= pen // FUSE file reference. // typedef struct { UINT64 Signature; EFI_FILE_PROTOCOL SimpleFile; BOOLEAN IsDirectory; + BOOLEAN IsOpenForWriting; VIRTIO_FS *OwnerFs; LIST_ENTRY OpenFilesEntry; // // In the FUSE wire protocol, every request except FUSE_INIT refers to a // file, namely by the "VIRTIO_FS_FUSE_REQUEST.NodeId" field; that is, b= y the // inode number of the file. However, some of the FUSE requests that we = need // for some of the EFI_FILE_PROTOCOL member functions require an open fi= le // handle *in addition* to the inode number. For simplicity, whenever a diff --git a/OvmfPkg/VirtioFsDxe/SimpleFsClose.c b/OvmfPkg/VirtioFsDxe/Simp= leFsClose.c index 01bbeae21473..bc91ad726b2c 100644 --- a/OvmfPkg/VirtioFsDxe/SimpleFsClose.c +++ b/OvmfPkg/VirtioFsDxe/SimpleFsClose.c @@ -19,30 +19,46 @@ VirtioFsSimpleFileClose ( { VIRTIO_FS_FILE *VirtioFsFile; VIRTIO_FS *VirtioFs; =20 VirtioFsFile =3D VIRTIO_FS_FILE_FROM_SIMPLE_FILE (This); VirtioFs =3D VirtioFsFile->OwnerFs; =20 // - // At this point, the implementation is only suitable for closing the - // VIRTIO_FS_FILE that was created by VirtioFsOpenVolume(). + // All actions in this function are "best effort"; the UEFI spec requires + // EFI_FILE_PROTOCOL.Close() to sync all data to the device, but it also + // requires EFI_FILE_PROTOCOL.Close() to release resources unconditional= ly, + // and to return EFI_SUCCESS unconditionally. // - ASSERT (VirtioFsFile->IsDirectory); - ASSERT (VirtioFsFile->NodeId =3D=3D VIRTIO_FS_FUSE_ROOT_DIR_NODE_ID); - // - // Close the root directory. - // - // Ignore any errors, because EFI_FILE_PROTOCOL.Close() is required to - // release the EFI_FILE_PROTOCOL object unconditionally. + // Flush, sync, release, and (if needed) forget. If any action fails, we + // still try the others. // + if (VirtioFsFile->IsOpenForWriting) { + if (!VirtioFsFile->IsDirectory) { + VirtioFsFuseFlush (VirtioFs, VirtioFsFile->NodeId, + VirtioFsFile->FuseHandle); + } + + VirtioFsFuseFsyncFileOrDir (VirtioFs, VirtioFsFile->NodeId, + VirtioFsFile->FuseHandle, VirtioFsFile->IsDirectory); + } + VirtioFsFuseReleaseFileOrDir (VirtioFs, VirtioFsFile->NodeId, VirtioFsFile->FuseHandle, VirtioFsFile->IsDirectory); =20 + // + // VirtioFsFile->FuseHandle is gone at this point, but VirtioFsFile->Nod= eId + // is still valid. If we've known VirtioFsFile->NodeId from a lookup, th= en + // now we should ask the server to forget it *once*. + // + if (VirtioFsFile->NodeId !=3D VIRTIO_FS_FUSE_ROOT_DIR_NODE_ID) { + VirtioFsFuseForget (VirtioFs, VirtioFsFile->NodeId); + } + // // One fewer file left open for the owner filesystem. // RemoveEntryList (&VirtioFsFile->OpenFilesEntry); =20 FreePool (VirtioFsFile); return EFI_SUCCESS; } diff --git a/OvmfPkg/VirtioFsDxe/SimpleFsDelete.c b/OvmfPkg/VirtioFsDxe/Sim= pleFsDelete.c index 3209923d1e49..bbad64bf7886 100644 --- a/OvmfPkg/VirtioFsDxe/SimpleFsDelete.c +++ b/OvmfPkg/VirtioFsDxe/SimpleFsDelete.c @@ -1,29 +1,68 @@ /** @file EFI_FILE_PROTOCOL.Delete() member function for the Virtio Filesystem dri= ver. =20 Copyright (C) 2020, Red Hat, Inc. =20 SPDX-License-Identifier: BSD-2-Clause-Patent **/ =20 +#include // RemoveEntryList() +#include // FreePool() + #include "VirtioFsDxe.h" =20 EFI_STATUS EFIAPI VirtioFsSimpleFileDelete ( IN EFI_FILE_PROTOCOL *This ) { + VIRTIO_FS_FILE *VirtioFsFile; + VIRTIO_FS *VirtioFs; + EFI_STATUS Status; + + VirtioFsFile =3D VIRTIO_FS_FILE_FROM_SIMPLE_FILE (This); + VirtioFs =3D VirtioFsFile->OwnerFs; + // - // At this point, the implementation is only suitable for closing the - // VIRTIO_FS_FILE that was created by VirtioFsOpenVolume(). + // All actions in this function are "best effort"; the UEFI spec requires + // EFI_FILE_PROTOCOL.Delete() to release resources unconditionally. If a= step + // related to removing the file fails, it's only reflected in the return + // status (EFI_WARN_DELETE_FAILURE rather than EFI_SUCCESS). // - // Actually deleting the root directory is not possible, so we're only g= oing - // to release resources, and return EFI_WARN_DELETE_FAILURE. + // Release, remove, and (if needed) forget. We don't waste time flushing= and + // syncing; if the EFI_FILE_PROTOCOL user cares enough, they should keep= the + // parent directory open until after this function call returns, and then + // force a sync on *that* EFI_FILE_PROTOCOL instance, using either the + // Flush() member function, or the Close() member function. // - // In order to release resources, VirtioFsSimpleFileClose() is just right - // here. + // If any action fails below, we still try the others. // - VirtioFsSimpleFileClose (This); - return EFI_WARN_DELETE_FAILURE; + VirtioFsFuseReleaseFileOrDir (VirtioFs, VirtioFsFile->NodeId, + VirtioFsFile->FuseHandle, VirtioFsFile->IsDirectory); + + // + // VirtioFsFile->FuseHandle is gone at this point, but VirtioFsFile->Nod= eId + // is still valid. Continue with removing the file or directory. The res= ult + // of this operation determines the return status of the function. + // + // TODO + // + Status =3D EFI_WARN_DELETE_FAILURE; + + // + // Finally, if we've known VirtioFsFile->NodeId from a lookup, then we s= hould + // also ask the server to forget it *once*. + // + if (VirtioFsFile->NodeId !=3D VIRTIO_FS_FUSE_ROOT_DIR_NODE_ID) { + VirtioFsFuseForget (VirtioFs, VirtioFsFile->NodeId); + } + + // + // One fewer file left open for the owner filesystem. + // + RemoveEntryList (&VirtioFsFile->OpenFilesEntry); + + FreePool (VirtioFsFile); + return Status; } diff --git a/OvmfPkg/VirtioFsDxe/SimpleFsOpenVolume.c b/OvmfPkg/VirtioFsDxe= /SimpleFsOpenVolume.c index 8c1457a68aad..67d2deb6bdf2 100644 --- a/OvmfPkg/VirtioFsDxe/SimpleFsOpenVolume.c +++ b/OvmfPkg/VirtioFsDxe/SimpleFsOpenVolume.c @@ -57,16 +57,17 @@ VirtioFsOpenVolume ( VirtioFsFile->SimpleFile.Read =3D VirtioFsSimpleFileRead; VirtioFsFile->SimpleFile.Write =3D VirtioFsSimpleFileWrite; VirtioFsFile->SimpleFile.GetPosition =3D VirtioFsSimpleFileGetPosition; VirtioFsFile->SimpleFile.SetPosition =3D VirtioFsSimpleFileSetPosition; VirtioFsFile->SimpleFile.GetInfo =3D VirtioFsSimpleFileGetInfo; VirtioFsFile->SimpleFile.SetInfo =3D VirtioFsSimpleFileSetInfo; VirtioFsFile->SimpleFile.Flush =3D VirtioFsSimpleFileFlush; VirtioFsFile->IsDirectory =3D TRUE; + VirtioFsFile->IsOpenForWriting =3D FALSE; VirtioFsFile->OwnerFs =3D VirtioFs; VirtioFsFile->NodeId =3D VIRTIO_FS_FUSE_ROOT_DIR_NODE_ID; VirtioFsFile->FuseHandle =3D RootDirHandle; =20 // // One more file open for the filesystem. // InsertTailList (&VirtioFs->OpenFiles, &VirtioFsFile->OpenFilesEntry); --=20 2.19.1.3.g30247aa5d201 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#69029): https://edk2.groups.io/g/devel/message/69029 Mute This Topic: https://groups.io/mt/79023154/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Tue May 7 07:56:31 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+69030+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+69030+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1608155121; cv=none; d=zohomail.com; s=zohoarc; b=m0S+PTAQuEgqErlr62eZVgW4D6IKScoO7Rvw4QUV6p6yeXkS7TxlWNQJWXFuGNi58XYLXPZ16F7CaeBFhHTDzG/aRU+7J1ajE+sKvFPFPVj1w1zUFek4z6jHDWGMs0sRduZM3NwWG7AI83ZElq8k5P7ktrcCsYoNF/K0KM9Uagk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608155121; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=iOi9RKotYtjfX2GxfPSl16RRnOgiB6P5mAIsMF5qNTY=; b=BgJTfFfAdSl0DCa9/nlEFnNricwyP3CAEn94kKcYDl0kySNz3U60bFxRB9dtzSymSpxPRgvQKyQwGkwyIbqfXmIsC97i3zuDYBlj7o9qWty4DuV1gKt4nMHgJDEIiQYvkc0+jjWf97IjtmNyuW1LYG9kByAgygk+NujI+qWl2+Y= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+69030+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) header.from= Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1608155121838614.8213185620731; Wed, 16 Dec 2020 13:45:21 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id CXN6YY1788612xFg0QGcc6Wp; Wed, 16 Dec 2020 13:45:21 -0800 X-Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.groups.io with SMTP id smtpd.web09.3871.1608155115346989409 for ; Wed, 16 Dec 2020 13:45:15 -0800 X-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-QL2vaVxWO-usxFQy8A3QnA-1; Wed, 16 Dec 2020 16:45:12 -0500 X-MC-Unique: QL2vaVxWO-usxFQy8A3QnA-1 X-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 76127180E475; Wed, 16 Dec 2020 21:45:11 +0000 (UTC) X-Received: from lacos-laptop-7.usersys.redhat.com (ovpn-114-152.ams2.redhat.com [10.36.114.152]) by smtp.corp.redhat.com (Postfix) with ESMTP id 10458271A4; Wed, 16 Dec 2020 21:45:04 +0000 (UTC) From: "Laszlo Ersek" To: devel@edk2.groups.io, virtio-fs@redhat.com, lersek@redhat.com Cc: Ard Biesheuvel , Jordan Justen , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [edk2-devel] [edk2 PATCH 16/48] OvmfPkg/VirtioFsDxe: add helper for appending and sanitizing paths Date: Wed, 16 Dec 2020 22:10:53 +0100 Message-Id: <20201216211125.19496-17-lersek@redhat.com> In-Reply-To: <20201216211125.19496-1-lersek@redhat.com> References: <20201216211125.19496-1-lersek@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,lersek@redhat.com X-Gm-Message-State: df8ZV2THbKxjqbVizMjg5HMDx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1608155121; bh=iOi9RKotYtjfX2GxfPSl16RRnOgiB6P5mAIsMF5qNTY=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=UFEvMHl7XFvRdaZASZCodEa1EFCZxIMn+Mz/JLa5ZperdNz/eZL0dnF/pGQCKxJoEwH 6WelXJ9NHXX2s/L6D20V1xEMvzZxiVhpn00XM7WXzU384aTRM8yfCCfFEuTVwIsJFn1dJ bM5YAmMlaagSkbmaI4XNIw4FT/dEmW1dKj0= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" EFI_FILE_PROTOCOL.Open() -- for opening files -- and EFI_FILE_PROTOCOL.SetInfo() -- for renaming files -- will require us to append a relative UEFI pathname to an absolute base pathname. In turn, components of the resultant pathnames will have to be sent to virtiofsd, which does not consume UEFI-style pathnames. We're going to maintain the base pathnames in canonical POSIX format: - absolute (starts with "/"), - dot (.) and dot-dot (..) components resolved/removed, - uses forward slashes, - sequences of slashes collapsed, - printable ASCII character set, - CHAR8 encoding, - no trailing slash except for the root directory itself, - length at most VIRTIO_FS_MAX_PATHNAME_LENGTH. Add a helper function that can append a UEFI pathname to such a base pathname, and produce the result in conformance with the same invariants. Cc: Ard Biesheuvel Cc: Jordan Justen Cc: Philippe Mathieu-Daud=C3=A9 Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3097 Signed-off-by: Laszlo Ersek Acked-by: Ard Biesheuvel --- OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf | 1 + OvmfPkg/VirtioFsDxe/VirtioFsDxe.h | 32 ++ OvmfPkg/VirtioFsDxe/Helpers.c | 474 ++++++++++++++++++++ 3 files changed, 507 insertions(+) diff --git a/OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf b/OvmfPkg/VirtioFsDxe/Virt= ioFsDxe.inf index 15e21772c8ac..0c92bccdac86 100644 --- a/OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf +++ b/OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf @@ -99,16 +99,17 @@ [Sources] SimpleFsRead.c SimpleFsSetInfo.c SimpleFsSetPosition.c SimpleFsWrite.c VirtioFsDxe.h =20 [LibraryClasses] BaseLib + BaseMemoryLib DebugLib MemoryAllocationLib UefiBootServicesTableLib UefiDriverEntryPoint VirtioLib =20 [Protocols] gEfiComponentName2ProtocolGuid ## PRODUCES diff --git a/OvmfPkg/VirtioFsDxe/VirtioFsDxe.h b/OvmfPkg/VirtioFsDxe/Virtio= FsDxe.h index 1cbd27d8fb52..f4fed64c7217 100644 --- a/OvmfPkg/VirtioFsDxe/VirtioFsDxe.h +++ b/OvmfPkg/VirtioFsDxe/VirtioFsDxe.h @@ -17,16 +17,40 @@ #include // VIRTIO_DEVICE_PROTOCOL #include // EFI_EVENT =20 #define VIRTIO_FS_SIG SIGNATURE_64 ('V', 'I', 'R', 'T', 'I', 'O', 'F', 'S') =20 #define VIRTIO_FS_FILE_SIG \ SIGNATURE_64 ('V', 'I', 'O', 'F', 'S', 'F', 'I', 'L') =20 +// +// The following limit applies to two kinds of pathnames. +// +// - The length of a POSIX-style, canonical pathname *at rest* never excee= ds +// VIRTIO_FS_MAX_PATHNAME_LENGTH. (Length is defined as the number of CH= AR8 +// elements in the canonical pathname, excluding the terminating '\0'.) = This +// is an invariant that is ensured for canonical pathnames created, and = that +// is assumed about canonical pathname inputs (which all originate +// internally). +// +// - If the length of a UEFI-style pathname *argument*, originating direct= ly or +// indirectly from the EFI_FILE_PROTOCOL caller, exceeds +// VIRTIO_FS_MAX_PATHNAME_LENGTH, then the argument is rejected. (Length= is +// defined as the number of CHAR16 elements in the UEFI-style pathname, +// excluding the terminating L'\0'.) This is a restriction that's checke= d on +// external UEFI-style pathname inputs. +// +// The limit is not expected to be a practical limitation; it's only suppo= sed +// to prevent attempts at overflowing size calculations. For both kinds of +// pathnames, separate limits could be used; a common limit is used purely= for +// simplicity. +// +#define VIRTIO_FS_MAX_PATHNAME_LENGTH ((UINTN)65535) + // // Filesystem label encoded in UCS-2, transformed from the UTF-8 represent= ation // in "VIRTIO_FS_CONFIG.Tag", and NUL-terminated. Only the printable ASCII= code // points (U+0020 through U+007E) are supported. // typedef CHAR16 VIRTIO_FS_LABEL[VIRTIO_FS_TAG_BYTES + 1]; =20 // @@ -187,16 +211,24 @@ VirtioFsFuseCheckResponse ( OUT UINTN *TailBufferFill ); =20 EFI_STATUS VirtioFsErrnoToEfiStatus ( IN INT32 Errno ); =20 +EFI_STATUS +VirtioFsAppendPath ( + IN CHAR8 *LhsPath8, + IN CHAR16 *RhsPath16, + OUT CHAR8 **ResultPath8, + OUT BOOLEAN *RootEscape + ); + // // Wrapper functions for FUSE commands (primitives). // =20 EFI_STATUS VirtioFsFuseForget ( IN OUT VIRTIO_FS *VirtioFs, IN UINT64 NodeId diff --git a/OvmfPkg/VirtioFsDxe/Helpers.c b/OvmfPkg/VirtioFsDxe/Helpers.c index 00f762142746..4a7b59332ca9 100644 --- a/OvmfPkg/VirtioFsDxe/Helpers.c +++ b/OvmfPkg/VirtioFsDxe/Helpers.c @@ -1,16 +1,19 @@ /** @file Initialization and helper routines for the Virtio Filesystem device. =20 Copyright (C) 2020, Red Hat, Inc. =20 SPDX-License-Identifier: BSD-2-Clause-Patent **/ =20 +#include // StrLen() +#include // CopyMem() +#include // AllocatePool() #include // Virtio10WriteFeatures() =20 #include "VirtioFsDxe.h" =20 /** Read the Virtio Filesystem device configuration structure in full. =20 @param[in] Virtio The Virtio protocol underlying the VIRTIO_FS object. @@ -1110,8 +1113,479 @@ VirtioFsErrnoToEfiStatus ( return EFI_NOT_STARTED; =20 default: break; } =20 return EFI_DEVICE_ERROR; } + +// +// Parser states for canonicalizing a POSIX pathname. +// +typedef enum { + ParserInit, // just starting + ParserEnd, // finished + ParserSlash, // slash(es) seen + ParserDot, // one dot seen since last slash + ParserDotDot, // two dots seen since last slash + ParserNormal, // a different sequence seen +} PARSER_STATE; + +/** + Strip the trailing slash from the parser's output buffer, unless the tra= iling + slash stands for the root directory. + + @param[in] Buffer The parser's output buffer. Only used for + sanity-checking. + + @param[in,out] Position On entry, points at the next character to produ= ce + (i.e., right past the end of the output written= by + the parser thus far). The last character in the + parser's output buffer is a slash. On return, t= he + slash is stripped, by decrementing Position by = one. + If this action would remove the slash character + standing for the root directory, then the funct= ion + has no effect. +**/ +STATIC +VOID +ParserStripSlash ( + IN CHAR8 *Buffer, + IN OUT UINTN *Position + ) +{ + ASSERT (*Position >=3D 1); + ASSERT (Buffer[*Position - 1] =3D=3D '/'); + if (*Position =3D=3D 1) { + return; + } + (*Position)--; +} + +/** + Produce one character in the parser's output buffer. + + @param[out] Buffer The parser's output buffer. On return, Char8 wi= ll + have been written. + + @param[in,out] Position On entry, points at the next character to produ= ce + (i.e., right past the end of the output written= by + the parser thus far). On return, Position is + incremented by one. + + @param[in] Size Total allocated size of the parser's output buf= fer. + Used for sanity-checking. + + @param[in] Char8 The character to place in the output buffer. +**/ +STATIC +VOID +ParserCopy ( + OUT CHAR8 *Buffer, + IN OUT UINTN *Position, + IN UINTN Size, + IN CHAR8 Char8 + ) +{ + ASSERT (*Position < Size); + Buffer[(*Position)++] =3D Char8; +} + +/** + Rewind the last single-dot in the parser's output buffer. + + @param[in] Buffer The parser's output buffer. Only used for + sanity-checking. + + @param[in,out] Position On entry, points at the next character to produ= ce + (i.e., right past the end of the output written= by + the parser thus far); the parser's output buffer + ends with the characters ('/', '.'). On return,= the + dot is rewound by decrementing Position by one;= a + slash character will reside at the new end of t= he + parser's output buffer. +**/ +STATIC +VOID +ParserRewindDot ( + IN CHAR8 *Buffer, + IN OUT UINTN *Position + ) +{ + ASSERT (*Position >=3D 2); + ASSERT (Buffer[*Position - 1] =3D=3D '.'); + ASSERT (Buffer[*Position - 2] =3D=3D '/'); + (*Position)--; +} + +/** + Rewind the last dot-dot in the parser's output buffer. + + @param[in] Buffer The parser's output buffer. Only used for + sanity-checking. + + @param[in,out] Position On entry, points at the next character to produ= ce + (i.e., right past the end of the output written= by + the parser thus far); the parser's output buffer + ends with the characters ('/', '.', '.'). On re= turn, + the ('.', '.') pair is rewound unconditionally,= by + decrementing Position by two; a slash character + resides at the new end of the parser's output + buffer. + + If this slash character stands for the root + directory, then RootEscape is set to TRUE. + + Otherwise (i.e., if this slash character is not= the + one standing for the root directory), then the = slash + character, and the pathname component preceding= it, + are removed by decrementing Position further. In + this case, the slash character preceding the re= moved + pathname component will reside at the new end o= f the + parser's output buffer. + + @param[out] RootEscape Set to TRUE on output if the dot-dot component = tries + to escape the root directory, as described abov= e. + Otherwise, RootEscape is not modified. +**/ +STATIC +VOID +ParserRewindDotDot ( + IN CHAR8 *Buffer, + IN OUT UINTN *Position, + OUT BOOLEAN *RootEscape + + ) +{ + ASSERT (*Position >=3D 3); + ASSERT (Buffer[*Position - 1] =3D=3D '.'); + ASSERT (Buffer[*Position - 2] =3D=3D '.'); + ASSERT (Buffer[*Position - 3] =3D=3D '/'); + (*Position) -=3D 2; + + if (*Position =3D=3D 1) { + // + // Root directory slash reached; don't try to climb higher. + // + *RootEscape =3D TRUE; + return; + } + + // + // Skip slash. + // + (*Position)--; + // + // Scan until next slash to the left. + // + do { + ASSERT (*Position > 0); + (*Position)--; + } while (Buffer[*Position] !=3D '/'); + (*Position)++; +} + +/** + Append the UEFI-style RhsPath16 to the POSIX-style, canonical format + LhsPath8. Output the POSIX-style, canonical format result in ResultPath,= as a + dynamically allocated string. + + Canonicalization (aka sanitization) establishes the following properties: + - ResultPath is absolute (starts with "/"), + - dot (.) and dot-dot (..) components are resolved/eliminated in ResultP= ath, + with the usual semantics, + - ResultPath uses forward slashes, + - sequences of slashes are squashed in ResultPath, + - the printable ASCII character set covers ResultPath, + - CHAR8 encoding is used in ResultPath, + - no trailing slash present in ResultPath except for the standalone root + directory, + - the length of ResultPath is at most VIRTIO_FS_MAX_PATHNAME_LENGTH. + + Any dot-dot in RhsPath16 that would remove the root directory is dropped= , and + reported through RootEscape, without failing the function call. + + @param[in] LhsPath8 Identifies the base directory. The caller is + responsible for ensuring that LhsPath8 conform = to + the above canonical pathname format on entry. + + @param[in] RhsPath16 Identifies the desired file with a UEFI-style C= HAR16 + pathname. If RhsPath16 starts with a backslash,= then + RhsPath16 is considered absolute, and LhsPath8 = is + ignored; RhsPath16 is sanitized in isolation, f= or + producing ResultPath8. Otherwise (i.e., if RhsP= ath16 + is relative), RhsPath16 is transliterated to CH= AR8, + and naively appended to LhsPath8. The resultant + fused pathname is then sanitized, to produce + ResultPath8. + + @param[out] ResultPath8 The POSIX-style, canonical format pathname that + leads to the file desired by the caller. After = use, + the caller is responsible for freeing ResultPat= h8. + + @param[out] RootEscape Set to TRUE if at least one dot-dot component in + RhsPath16 attempted to escape the root director= y; + set to FALSE otherwise. + + @retval EFI_SUCCESS ResultPath8 has been produced. RootEscape= has + been output. + + @retval EFI_INVALID_PARAMETER RhsPath16 is zero-length. + + @retval EFI_INVALID_PARAMETER RhsPath16 failed the + VIRTIO_FS_MAX_PATHNAME_LENGTH check. + + @retval EFI_OUT_OF_RESOURCES Memory allocation failed. + + @retval EFI_OUT_OF_RESOURCES ResultPath8 would have failed the + VIRTIO_FS_MAX_PATHNAME_LENGTH check. + + @retval EFI_UNSUPPORTED RhsPath16 contains a character that either + falls outside of the printable ASCII set,= or + is a forward slash. +**/ +EFI_STATUS +VirtioFsAppendPath ( + IN CHAR8 *LhsPath8, + IN CHAR16 *RhsPath16, + OUT CHAR8 **ResultPath8, + OUT BOOLEAN *RootEscape + ) +{ + UINTN RhsLen; + CHAR8 *RhsPath8; + UINTN Idx; + EFI_STATUS Status; + UINTN SizeToSanitize; + CHAR8 *BufferToSanitize; + CHAR8 *SanitizedBuffer; + PARSER_STATE State; + UINTN SanitizedPosition; + + // + // Appending an empty pathname is not allowed. + // + RhsLen =3D StrLen (RhsPath16); + if (RhsLen =3D=3D 0) { + return EFI_INVALID_PARAMETER; + } + // + // Enforce length restriction on RhsPath16. + // + if (RhsLen > VIRTIO_FS_MAX_PATHNAME_LENGTH) { + return EFI_INVALID_PARAMETER; + } + + // + // Transliterate RhsPath16 to RhsPath8 by: + // - rejecting RhsPath16 if a character outside of printable ASCII is se= en, + // - rejecting RhsPath16 if a forward slash is seen, + // - replacing backslashes with forward slashes, + // - casting the characters from CHAR16 to CHAR8. + // + RhsPath8 =3D AllocatePool (RhsLen + 1); + if (RhsPath8 =3D=3D NULL) { + return EFI_OUT_OF_RESOURCES; + } + for (Idx =3D 0; RhsPath16[Idx] !=3D L'\0'; Idx++) { + if (RhsPath16[Idx] < 0x20 || RhsPath16[Idx] > 0x7E || + RhsPath16[Idx] =3D=3D L'/') { + Status =3D EFI_UNSUPPORTED; + goto FreeRhsPath8; + } + RhsPath8[Idx] =3D (CHAR8)((RhsPath16[Idx] =3D=3D L'\\') ? L'/' : RhsPa= th16[Idx]); + } + RhsPath8[Idx++] =3D '\0'; + + // + // Now prepare the input for the canonicalization (squashing of sequence= s of + // forward slashes, and eliminating . (dot) and .. (dot-dot) pathname + // components). + // + // The sanitized path can never be longer than the naive concatenation o= f the + // left hand side and right hand side paths, so we'll use the catenated = size + // for allocating the sanitized output too. + // + if (RhsPath8[0] =3D=3D '/') { + // + // If the right hand side path is absolute, then it is not appended to= the + // left hand side path -- it *replaces* the left hand side path. + // + SizeToSanitize =3D RhsLen + 1; + BufferToSanitize =3D RhsPath8; + } else { + // + // If the right hand side path is relative, then it is appended (naive= ly) + // to the left hand side. + // + UINTN LhsLen; + + LhsLen =3D AsciiStrLen (LhsPath8); + SizeToSanitize =3D LhsLen + 1 + RhsLen + 1; + BufferToSanitize =3D AllocatePool (SizeToSanitize); + if (BufferToSanitize =3D=3D NULL) { + Status =3D EFI_OUT_OF_RESOURCES; + goto FreeRhsPath8; + } + CopyMem (BufferToSanitize, LhsPath8, LhsLen); + BufferToSanitize[LhsLen] =3D '/'; + CopyMem (BufferToSanitize + LhsLen + 1, RhsPath8, RhsLen + 1); + } + + // + // Allocate the output buffer. + // + SanitizedBuffer =3D AllocatePool (SizeToSanitize); + if (SanitizedBuffer =3D=3D NULL) { + Status =3D EFI_OUT_OF_RESOURCES; + goto FreeBufferToSanitize; + } + + // + // State machine for parsing the input and producing the canonical output + // follows. + // + *RootEscape =3D FALSE; + Idx =3D 0; + State =3D ParserInit; + SanitizedPosition =3D 0; + do { + CHAR8 Chr8; + + ASSERT (Idx < SizeToSanitize); + Chr8 =3D BufferToSanitize[Idx++]; + + switch (State) { + case ParserInit: // just starting + ASSERT (Chr8 =3D=3D '/'); + ParserCopy (SanitizedBuffer, &SanitizedPosition, SizeToSanitize, Chr= 8); + State =3D ParserSlash; + break; + + case ParserSlash: // slash(es) seen + switch (Chr8) { + case '\0': + ParserStripSlash (SanitizedBuffer, &SanitizedPosition); + ParserCopy (SanitizedBuffer, &SanitizedPosition, SizeToSanitize, C= hr8); + State =3D ParserEnd; + break; + case '/': + // + // skip & stay in same state + // + break; + case '.': + ParserCopy (SanitizedBuffer, &SanitizedPosition, SizeToSanitize, C= hr8); + State =3D ParserDot; + break; + default: + ParserCopy (SanitizedBuffer, &SanitizedPosition, SizeToSanitize, C= hr8); + State =3D ParserNormal; + break; + } + break; + + case ParserDot: // one dot seen since last slash + switch (Chr8) { + case '\0': + ParserRewindDot (SanitizedBuffer, &SanitizedPosition); + ParserStripSlash (SanitizedBuffer, &SanitizedPosition); + ParserCopy (SanitizedBuffer, &SanitizedPosition, SizeToSanitize, C= hr8); + State =3D ParserEnd; + break; + case '/': + ParserRewindDot (SanitizedBuffer, &SanitizedPosition); + State =3D ParserSlash; + break; + case '.': + ParserCopy (SanitizedBuffer, &SanitizedPosition, SizeToSanitize, C= hr8); + State =3D ParserDotDot; + break; + default: + ParserCopy (SanitizedBuffer, &SanitizedPosition, SizeToSanitize, C= hr8); + State =3D ParserNormal; + break; + } + break; + + case ParserDotDot: // two dots seen since last slash + switch (Chr8) { + case '\0': + ParserRewindDotDot (SanitizedBuffer, &SanitizedPosition, RootEscap= e); + ParserStripSlash (SanitizedBuffer, &SanitizedPosition); + ParserCopy (SanitizedBuffer, &SanitizedPosition, SizeToSanitize, C= hr8); + State =3D ParserEnd; + break; + case '/': + ParserRewindDotDot (SanitizedBuffer, &SanitizedPosition, RootEscap= e); + State =3D ParserSlash; + break; + case '.': + // + // fall through + // + default: + ParserCopy (SanitizedBuffer, &SanitizedPosition, SizeToSanitize, C= hr8); + State =3D ParserNormal; + break; + } + break; + + case ParserNormal: // a different sequence seen + switch (Chr8) { + case '\0': + ParserCopy (SanitizedBuffer, &SanitizedPosition, SizeToSanitize, C= hr8); + State =3D ParserEnd; + break; + case '/': + ParserCopy (SanitizedBuffer, &SanitizedPosition, SizeToSanitize, C= hr8); + State =3D ParserSlash; + break; + case '.': + // + // fall through + // + default: + // + // copy and stay in same state + // + ParserCopy (SanitizedBuffer, &SanitizedPosition, SizeToSanitize, C= hr8); + break; + } + break; + + default: + ASSERT (FALSE); + break; + } + } while (State !=3D ParserEnd); + + // + // Ensure length invariant on ResultPath8. + // + ASSERT (SanitizedPosition >=3D 2); + if (SanitizedPosition - 1 > VIRTIO_FS_MAX_PATHNAME_LENGTH) { + Status =3D EFI_OUT_OF_RESOURCES; + goto FreeSanitizedBuffer; + } + + *ResultPath8 =3D SanitizedBuffer; + SanitizedBuffer =3D NULL; + Status =3D EFI_SUCCESS; + // + // Fall through. + // +FreeSanitizedBuffer: + if (SanitizedBuffer !=3D NULL) { + FreePool (SanitizedBuffer); + } + +FreeBufferToSanitize: + if (RhsPath8[0] !=3D '/') { + FreePool (BufferToSanitize); + } + +FreeRhsPath8: + FreePool (RhsPath8); + return Status; +} --=20 2.19.1.3.g30247aa5d201 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#69030): https://edk2.groups.io/g/devel/message/69030 Mute This Topic: https://groups.io/mt/79023203/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Tue May 7 07:56:31 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+69031+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+69031+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1608155241; cv=none; d=zohomail.com; s=zohoarc; b=WnKT3XyTzlioTy56OPRzQ6JMJgOJCnuzsyaryWekwHC7kn5c2WOC8TTMe/l6WH/hlNVZopt9f96Tfd7CEYpLhHQab/5s3klh4tbfUuDObWrNAzptqsi2r4bD3KWkTYZI6Y3yNx/lklWKDOf+rGwA6yT3JRUzodk0mnivMLaLT5A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608155241; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=AWwXhdGlLc16v2ea+8NY0GwSwbcQxNkj7DG7vFjo9m8=; b=a4WDQYo3IOmZpW0AMlMArq29uRk9Hjxw8ggqcqvgLYhmCVTZelR8lMh0jaNywkIK7pTLdEwlybMX8I7nWzCymOJ795idfv2E3Hh/mcq3Q61PK/3i5adimc3d0cdE69WculrmYKW6O8ssTLHt8dcnWPE4cvQJCbvKE4Zzwl/+3JU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+69031+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) header.from= Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1608155241895575.4568751611164; Wed, 16 Dec 2020 13:47:21 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id NeDCYY1788612xjzDqUhNCIX; Wed, 16 Dec 2020 13:47:21 -0800 X-Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.groups.io with SMTP id smtpd.web09.3896.1608155240927863680 for ; Wed, 16 Dec 2020 13:47:21 -0800 X-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-584-AuVTaftFO2qRTuoaTwa_pg-1; Wed, 16 Dec 2020 16:47:18 -0500 X-MC-Unique: AuVTaftFO2qRTuoaTwa_pg-1 X-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 5D3AC180E46D; Wed, 16 Dec 2020 21:47:17 +0000 (UTC) X-Received: from lacos-laptop-7.usersys.redhat.com (ovpn-114-152.ams2.redhat.com [10.36.114.152]) by smtp.corp.redhat.com (Postfix) with ESMTP id A5DAE1754A; Wed, 16 Dec 2020 21:47:12 +0000 (UTC) From: "Laszlo Ersek" To: devel@edk2.groups.io, virtio-fs@redhat.com, lersek@redhat.com Cc: Ard Biesheuvel , Jordan Justen , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [edk2-devel] [edk2 PATCH 17/48] OvmfPkg/VirtioFsDxe: manage path lifecycle in OpenVolume, Close, Delete Date: Wed, 16 Dec 2020 22:10:54 +0100 Message-Id: <20201216211125.19496-18-lersek@redhat.com> In-Reply-To: <20201216211125.19496-1-lersek@redhat.com> References: <20201216211125.19496-1-lersek@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,lersek@redhat.com X-Gm-Message-State: eUOCnjI1wuJUW1SEmQHQ0z6Sx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1608155241; bh=AWwXhdGlLc16v2ea+8NY0GwSwbcQxNkj7DG7vFjo9m8=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=XnblBTMFUiQUhs2kQmtQ860f3izBCljtgRHO4yM0dwUp1ObK/0LcSquqfYl/x0v1Mc2 zuJcfeQwWsZB82WAPX/VX5vvYSoInLXVtA2ViJLM4J/cCOcrogB84U5eidoKWOJxipvmq s/KY4Uvhf4TvLpFeFfnpw6ZdwDxeiWAOrC4= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" Add a canonical pathname field to VIRTIO_FS_FILE. Initialize the new field in EFI_SIMPLE_FILE_SYSTEM_PROTOCOL.OpenVolume(). Release the new field in EFI_FILE_PROTOCOL.Close() and EFI_FILE_PROTOCOL.Delete(). Cc: Ard Biesheuvel Cc: Jordan Justen Cc: Philippe Mathieu-Daud=C3=A9 Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3097 Signed-off-by: Laszlo Ersek Acked-by: Ard Biesheuvel --- OvmfPkg/VirtioFsDxe/VirtioFsDxe.h | 1 + OvmfPkg/VirtioFsDxe/SimpleFsClose.c | 1 + OvmfPkg/VirtioFsDxe/SimpleFsDelete.c | 1 + OvmfPkg/VirtioFsDxe/SimpleFsOpenVolume.c | 13 ++++++++++++- 4 files changed, 15 insertions(+), 1 deletion(-) diff --git a/OvmfPkg/VirtioFsDxe/VirtioFsDxe.h b/OvmfPkg/VirtioFsDxe/Virtio= FsDxe.h index f4fed64c7217..487d215c7f38 100644 --- a/OvmfPkg/VirtioFsDxe/VirtioFsDxe.h +++ b/OvmfPkg/VirtioFsDxe/VirtioFsDxe.h @@ -132,16 +132,17 @@ typedef struct { // typedef struct { UINT64 Signature; EFI_FILE_PROTOCOL SimpleFile; BOOLEAN IsDirectory; BOOLEAN IsOpenForWriting; VIRTIO_FS *OwnerFs; LIST_ENTRY OpenFilesEntry; + CHAR8 *CanonicalPathname; // // In the FUSE wire protocol, every request except FUSE_INIT refers to a // file, namely by the "VIRTIO_FS_FUSE_REQUEST.NodeId" field; that is, b= y the // inode number of the file. However, some of the FUSE requests that we = need // for some of the EFI_FILE_PROTOCOL member functions require an open fi= le // handle *in addition* to the inode number. For simplicity, whenever a // VIRTIO_FS_FILE object is created, primarily defined by its NodeId fie= ld, // we also *open* the referenced file at once, and save the returned file diff --git a/OvmfPkg/VirtioFsDxe/SimpleFsClose.c b/OvmfPkg/VirtioFsDxe/Simp= leFsClose.c index bc91ad726b2c..04b4f2c382d7 100644 --- a/OvmfPkg/VirtioFsDxe/SimpleFsClose.c +++ b/OvmfPkg/VirtioFsDxe/SimpleFsClose.c @@ -54,11 +54,12 @@ VirtioFsSimpleFileClose ( VirtioFsFuseForget (VirtioFs, VirtioFsFile->NodeId); } =20 // // One fewer file left open for the owner filesystem. // RemoveEntryList (&VirtioFsFile->OpenFilesEntry); =20 + FreePool (VirtioFsFile->CanonicalPathname); FreePool (VirtioFsFile); return EFI_SUCCESS; } diff --git a/OvmfPkg/VirtioFsDxe/SimpleFsDelete.c b/OvmfPkg/VirtioFsDxe/Sim= pleFsDelete.c index bbad64bf7886..e2fc2d72dfeb 100644 --- a/OvmfPkg/VirtioFsDxe/SimpleFsDelete.c +++ b/OvmfPkg/VirtioFsDxe/SimpleFsDelete.c @@ -58,11 +58,12 @@ VirtioFsSimpleFileDelete ( VirtioFsFuseForget (VirtioFs, VirtioFsFile->NodeId); } =20 // // One fewer file left open for the owner filesystem. // RemoveEntryList (&VirtioFsFile->OpenFilesEntry); =20 + FreePool (VirtioFsFile->CanonicalPathname); FreePool (VirtioFsFile); return Status; } diff --git a/OvmfPkg/VirtioFsDxe/SimpleFsOpenVolume.c b/OvmfPkg/VirtioFsDxe= /SimpleFsOpenVolume.c index 67d2deb6bdf2..9c0ab434c186 100644 --- a/OvmfPkg/VirtioFsDxe/SimpleFsOpenVolume.c +++ b/OvmfPkg/VirtioFsDxe/SimpleFsOpenVolume.c @@ -23,32 +23,39 @@ EFIAPI VirtioFsOpenVolume ( IN EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *This, OUT EFI_FILE_PROTOCOL **Root ) { VIRTIO_FS *VirtioFs; VIRTIO_FS_FILE *VirtioFsFile; EFI_STATUS Status; + CHAR8 *CanonicalPathname; UINT64 RootDirHandle; =20 VirtioFs =3D VIRTIO_FS_FROM_SIMPLE_FS (This); =20 VirtioFsFile =3D AllocatePool (sizeof *VirtioFsFile); if (VirtioFsFile =3D=3D NULL) { return EFI_OUT_OF_RESOURCES; } =20 + CanonicalPathname =3D AllocateCopyPool (sizeof "/", "/"); + if (CanonicalPathname =3D=3D NULL) { + Status =3D EFI_OUT_OF_RESOURCES; + goto FreeVirtioFsFile; + } + // // Open the root directory. // Status =3D VirtioFsFuseOpenDir (VirtioFs, VIRTIO_FS_FUSE_ROOT_DIR_NODE_I= D, &RootDirHandle); if (EFI_ERROR (Status)) { - goto FreeVirtioFsFile; + goto FreeCanonicalPathname; } =20 // // Populate the new VIRTIO_FS_FILE object. // VirtioFsFile->Signature =3D VIRTIO_FS_FILE_SIG; VirtioFsFile->SimpleFile.Revision =3D EFI_FILE_PROTOCOL_REVISION; VirtioFsFile->SimpleFile.Open =3D VirtioFsSimpleFileOpen; @@ -59,24 +66,28 @@ VirtioFsOpenVolume ( VirtioFsFile->SimpleFile.GetPosition =3D VirtioFsSimpleFileGetPosition; VirtioFsFile->SimpleFile.SetPosition =3D VirtioFsSimpleFileSetPosition; VirtioFsFile->SimpleFile.GetInfo =3D VirtioFsSimpleFileGetInfo; VirtioFsFile->SimpleFile.SetInfo =3D VirtioFsSimpleFileSetInfo; VirtioFsFile->SimpleFile.Flush =3D VirtioFsSimpleFileFlush; VirtioFsFile->IsDirectory =3D TRUE; VirtioFsFile->IsOpenForWriting =3D FALSE; VirtioFsFile->OwnerFs =3D VirtioFs; + VirtioFsFile->CanonicalPathname =3D CanonicalPathname; VirtioFsFile->NodeId =3D VIRTIO_FS_FUSE_ROOT_DIR_NODE_ID; VirtioFsFile->FuseHandle =3D RootDirHandle; =20 // // One more file open for the filesystem. // InsertTailList (&VirtioFs->OpenFiles, &VirtioFsFile->OpenFilesEntry); =20 *Root =3D &VirtioFsFile->SimpleFile; return EFI_SUCCESS; =20 +FreeCanonicalPathname: + FreePool (CanonicalPathname); + FreeVirtioFsFile: FreePool (VirtioFsFile); =20 return Status; } --=20 2.19.1.3.g30247aa5d201 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#69031): https://edk2.groups.io/g/devel/message/69031 Mute This Topic: https://groups.io/mt/79023248/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Tue May 7 07:56:31 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+69032+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+69032+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1608155375; cv=none; d=zohomail.com; s=zohoarc; b=D9OuQVWzpqRGkNh/2LhYlMLacDjGouuwUdKJqIi6FCGxpOrM9BDb43VF7VRZ7gFLi5Yez6+JpKWStRsAHiTech9eXfaYazK6EHal+J9LB2C1Q4hEDu4yUHuYSfHQFT3o0aUjWj4LXgtdUUOgEp6Q0K/2GD0eao3QWos4sOnIYWs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608155375; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=pDErOue0oNYxc75Zul7c5IlfwumznqeZudbruxIJX8I=; b=KZ5hmZebEWfjGCm1NN3AcwIelmvZl0mwxmf4b7AaSIUucOJbzJvzzIVdJhAob4209SxWYEXxmXaE4I2wgjTexE108YnFACn509knpFy3AVINjJcZjqDEb8BppY8LvgYfLWqz26R20sXDPbi1c+5c4MrB/GUOKZ8DHO+Pu6g0Azs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+69032+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) header.from= Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1608155375845830.8174089531832; Wed, 16 Dec 2020 13:49:35 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id jXl3YY1788612xv2kloAg2sP; Wed, 16 Dec 2020 13:49:35 -0800 X-Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.groups.io with SMTP id smtpd.web09.3941.1608155369949877993 for ; Wed, 16 Dec 2020 13:49:30 -0800 X-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-105-87Hy5rmqOA6y4dMuUuJS6A-1; Wed, 16 Dec 2020 16:49:27 -0500 X-MC-Unique: 87Hy5rmqOA6y4dMuUuJS6A-1 X-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 498F81842141; Wed, 16 Dec 2020 21:49:26 +0000 (UTC) X-Received: from lacos-laptop-7.usersys.redhat.com (ovpn-114-152.ams2.redhat.com [10.36.114.152]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9536F1754A; Wed, 16 Dec 2020 21:49:18 +0000 (UTC) From: "Laszlo Ersek" To: devel@edk2.groups.io, virtio-fs@redhat.com, lersek@redhat.com Cc: Ard Biesheuvel , Jordan Justen , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [edk2-devel] [edk2 PATCH 18/48] OvmfPkg/VirtioFsDxe: implement the wrapper function for FUSE_OPEN Date: Wed, 16 Dec 2020 22:10:55 +0100 Message-Id: <20201216211125.19496-19-lersek@redhat.com> In-Reply-To: <20201216211125.19496-1-lersek@redhat.com> References: <20201216211125.19496-1-lersek@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,lersek@redhat.com X-Gm-Message-State: oWiTvCMqGvc5M66o5Kf3UvrFx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1608155375; bh=pDErOue0oNYxc75Zul7c5IlfwumznqeZudbruxIJX8I=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=XqxrIB7z+HuhlzmIusFKOFVthaJ4T+H2IAWW4fMUTFiYC6V23QAjddeNOf1lanssrYa eM+fcs01uXNrAv7NMjrzhr/gwCvwYUUgOItAot5j10Pb0m68+m6uf++8vwGB38YRrZqcc HGq47CSbZYNAx2kGWlMtHoV3sZfMUykzNSI= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" Add the VirtioFsFuseOpen() function, for sending the FUSE_OPEN command to the Virtio Filesystem device. Cc: Ard Biesheuvel Cc: Jordan Justen Cc: Philippe Mathieu-Daud=C3=A9 Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3097 Signed-off-by: Laszlo Ersek Acked-by: Ard Biesheuvel --- OvmfPkg/Include/IndustryStandard/VirtioFs.h | 35 +++--- OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf | 1 + OvmfPkg/VirtioFsDxe/VirtioFsDxe.h | 8 ++ OvmfPkg/VirtioFsDxe/FuseOpen.c | 126 ++++++++++++++++++++ 4 files changed, 156 insertions(+), 14 deletions(-) diff --git a/OvmfPkg/Include/IndustryStandard/VirtioFs.h b/OvmfPkg/Include/= IndustryStandard/VirtioFs.h index fec2f4be531f..7b6f30335577 100644 --- a/OvmfPkg/Include/IndustryStandard/VirtioFs.h +++ b/OvmfPkg/Include/IndustryStandard/VirtioFs.h @@ -76,21 +76,28 @@ typedef struct { #define VIRTIO_FS_FUSE_MAJOR 7 #define VIRTIO_FS_FUSE_MINOR 31 =20 // // The inode number of the root directory. // #define VIRTIO_FS_FUSE_ROOT_DIR_NODE_ID 1 =20 +// +// Flags for VirtioFsFuseOpOpen. +// +#define VIRTIO_FS_FUSE_OPEN_REQ_F_RDONLY 0 +#define VIRTIO_FS_FUSE_OPEN_REQ_F_RDWR 2 + // // FUSE operation codes. // typedef enum { VirtioFsFuseOpForget =3D 2, + VirtioFsFuseOpOpen =3D 14, VirtioFsFuseOpRelease =3D 18, VirtioFsFuseOpFsync =3D 20, VirtioFsFuseOpFlush =3D 25, VirtioFsFuseOpInit =3D 26, VirtioFsFuseOpOpenDir =3D 27, VirtioFsFuseOpReleaseDir =3D 29, VirtioFsFuseOpFsyncDir =3D 30, } VIRTIO_FS_FUSE_OPCODE; @@ -118,16 +125,30 @@ typedef struct { =20 // // Header for VirtioFsFuseOpForget. // typedef struct { UINT64 NumberOfLookups; } VIRTIO_FS_FUSE_FORGET_REQUEST; =20 +// +// Headers for VirtioFsFuseOpOpen and VirtioFsFuseOpOpenDir. +// +typedef struct { + UINT32 Flags; + UINT32 Unused; +} VIRTIO_FS_FUSE_OPEN_REQUEST; + +typedef struct { + UINT64 FileHandle; + UINT32 OpenFlags; + UINT32 Padding; +} VIRTIO_FS_FUSE_OPEN_RESPONSE; + // // Header for VirtioFsFuseOpRelease and VirtioFsFuseOpReleaseDir. // typedef struct { UINT64 FileHandle; UINT32 Flags; UINT32 ReleaseFlags; UINT64 LockOwner; @@ -170,25 +191,11 @@ typedef struct { UINT16 MaxBackground; UINT16 CongestionThreshold; UINT32 MaxWrite; UINT32 TimeGran; UINT16 MaxPages; UINT16 MapAlignment; UINT32 Unused[8]; } VIRTIO_FS_FUSE_INIT_RESPONSE; - -// -// Headers for VirtioFsFuseOpOpenDir. -// -typedef struct { - UINT32 Flags; - UINT32 Unused; -} VIRTIO_FS_FUSE_OPEN_REQUEST; - -typedef struct { - UINT64 FileHandle; - UINT32 OpenFlags; - UINT32 Padding; -} VIRTIO_FS_FUSE_OPEN_RESPONSE; #pragma pack () =20 #endif // VIRTIO_FS_H_ diff --git a/OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf b/OvmfPkg/VirtioFsDxe/Virt= ioFsDxe.inf index 0c92bccdac86..dc9a12820f3d 100644 --- a/OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf +++ b/OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf @@ -81,16 +81,17 @@ [Packages] OvmfPkg/OvmfPkg.dec =20 [Sources] DriverBinding.c FuseFlush.c FuseForget.c FuseFsync.c FuseInit.c + FuseOpen.c FuseOpenDir.c FuseRelease.c Helpers.c SimpleFsClose.c SimpleFsDelete.c SimpleFsFlush.c SimpleFsGetInfo.c SimpleFsGetPosition.c diff --git a/OvmfPkg/VirtioFsDxe/VirtioFsDxe.h b/OvmfPkg/VirtioFsDxe/Virtio= FsDxe.h index 487d215c7f38..c13258a2e08f 100644 --- a/OvmfPkg/VirtioFsDxe/VirtioFsDxe.h +++ b/OvmfPkg/VirtioFsDxe/VirtioFsDxe.h @@ -230,16 +230,24 @@ VirtioFsAppendPath ( // =20 EFI_STATUS VirtioFsFuseForget ( IN OUT VIRTIO_FS *VirtioFs, IN UINT64 NodeId ); =20 +EFI_STATUS +VirtioFsFuseOpen ( + IN OUT VIRTIO_FS *VirtioFs, + IN UINT64 NodeId, + IN BOOLEAN ReadWrite, + OUT UINT64 *FuseHandle + ); + EFI_STATUS VirtioFsFuseReleaseFileOrDir ( IN OUT VIRTIO_FS *VirtioFs, IN UINT64 NodeId, IN UINT64 FuseHandle, IN BOOLEAN IsDir ); =20 diff --git a/OvmfPkg/VirtioFsDxe/FuseOpen.c b/OvmfPkg/VirtioFsDxe/FuseOpen.c new file mode 100644 index 000000000000..b731580729b6 --- /dev/null +++ b/OvmfPkg/VirtioFsDxe/FuseOpen.c @@ -0,0 +1,126 @@ +/** @file + FUSE_OPEN wrapper for the Virtio Filesystem device. + + Copyright (C) 2020, Red Hat, Inc. + + SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#include "VirtioFsDxe.h" + +/** + Send a FUSE_OPEN request to the Virtio Filesystem device, for opening a + regular file. + + The function may only be called after VirtioFsFuseInitSession() returns + successfully and before VirtioFsUninit() is called. + + @param[in,out] VirtioFs The Virtio Filesystem device to send the FUSE_O= PEN + request to. On output, the FUSE request counter + "VirtioFs->RequestId" will have been incremente= d. + + @param[in] NodeId The inode number of the regular file to open. + + @param[in] ReadWrite If TRUE, open the regular file in read-write mo= de. + If FALSE, open the regular file in read-only mo= de. + + @param[out] FuseHandle The open handle to the regular file, returned b= y the + Virtio Filesystem device. + + @retval EFI_SUCCESS The regular file has been opened. + + @return The "errno" value mapped to an EFI_STATUS code, if = the + Virtio Filesystem device explicitly reported an err= or. + + @return Error codes propagated from VirtioFsSgListsValidate= (), + VirtioFsFuseNewRequest(), VirtioFsSgListsSubmit(), + VirtioFsFuseCheckResponse(). +**/ +EFI_STATUS +VirtioFsFuseOpen ( + IN OUT VIRTIO_FS *VirtioFs, + IN UINT64 NodeId, + IN BOOLEAN ReadWrite, + OUT UINT64 *FuseHandle + ) +{ + VIRTIO_FS_FUSE_REQUEST CommonReq; + VIRTIO_FS_FUSE_OPEN_REQUEST OpenReq; + VIRTIO_FS_IO_VECTOR ReqIoVec[2]; + VIRTIO_FS_SCATTER_GATHER_LIST ReqSgList; + VIRTIO_FS_FUSE_RESPONSE CommonResp; + VIRTIO_FS_FUSE_OPEN_RESPONSE OpenResp; + VIRTIO_FS_IO_VECTOR RespIoVec[2]; + VIRTIO_FS_SCATTER_GATHER_LIST RespSgList; + EFI_STATUS Status; + + // + // Set up the scatter-gather lists. + // + ReqIoVec[0].Buffer =3D &CommonReq; + ReqIoVec[0].Size =3D sizeof CommonReq; + ReqIoVec[1].Buffer =3D &OpenReq; + ReqIoVec[1].Size =3D sizeof OpenReq; + ReqSgList.IoVec =3D ReqIoVec; + ReqSgList.NumVec =3D ARRAY_SIZE (ReqIoVec); + + RespIoVec[0].Buffer =3D &CommonResp; + RespIoVec[0].Size =3D sizeof CommonResp; + RespIoVec[1].Buffer =3D &OpenResp; + RespIoVec[1].Size =3D sizeof OpenResp; + RespSgList.IoVec =3D RespIoVec; + RespSgList.NumVec =3D ARRAY_SIZE (RespIoVec); + + // + // Validate the scatter-gather lists; calculate the total transfer sizes. + // + Status =3D VirtioFsSgListsValidate (VirtioFs, &ReqSgList, &RespSgList); + if (EFI_ERROR (Status)) { + return Status; + } + + // + // Populate the common request header. + // + Status =3D VirtioFsFuseNewRequest (VirtioFs, &CommonReq, ReqSgList.Total= Size, + VirtioFsFuseOpOpen, NodeId); + if (EFI_ERROR (Status)) { + return Status; + } + + // + // Populate the FUSE_OPEN-specific fields. + // + OpenReq.Flags =3D (ReadWrite ? + VIRTIO_FS_FUSE_OPEN_REQ_F_RDWR : + VIRTIO_FS_FUSE_OPEN_REQ_F_RDONLY); + OpenReq.Unused =3D 0; + + // + // Submit the request. + // + Status =3D VirtioFsSgListsSubmit (VirtioFs, &ReqSgList, &RespSgList); + if (EFI_ERROR (Status)) { + return Status; + } + + // + // Verify the response (all response buffers are fixed size). + // + Status =3D VirtioFsFuseCheckResponse (&RespSgList, CommonReq.Unique, NUL= L); + if (EFI_ERROR (Status)) { + if (Status =3D=3D EFI_DEVICE_ERROR) { + DEBUG ((DEBUG_ERROR, "%a: Label=3D\"%s\" NodeId=3D%Lu ReadWrite=3D%d= " + "Errno=3D%d\n", __FUNCTION__, VirtioFs->Label, NodeId, ReadWrite, + CommonResp.Error)); + Status =3D VirtioFsErrnoToEfiStatus (CommonResp.Error); + } + return Status; + } + + // + // Output the open handle. + // + *FuseHandle =3D OpenResp.FileHandle; + return EFI_SUCCESS; +} --=20 2.19.1.3.g30247aa5d201 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#69032): https://edk2.groups.io/g/devel/message/69032 Mute This Topic: https://groups.io/mt/79023292/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Tue May 7 07:56:31 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+69033+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+69033+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1608155499; cv=none; d=zohomail.com; s=zohoarc; b=OxaaOtShXqZl7NByJp1EFJeM730agftFkSVlMPyrUIr9LOUV8sUlN0nRU9NyGTdvYSKu4kV+0CAuO8gD+T1MZhn4qQRUrwFRUg5n/Y9Rm13Y/9vSbGOrnLAESPbTzqM9lXPE3Sa1I0RTOxJXBzbwZ7Hv3CLvEiO38cy4r69Mhss= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608155499; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=eiE09NSSdP3cthsHcReNcrVJ8Sh2YF4QFJZLnakFKBg=; b=Ha/leVlUdaX6TBkMflRV5nSsz6rjjdaHJkbKx6SgdhtkxQXSt8PwRffdyRnaeTxONfm3mV6aZGkTXr7q0S/JTE7WfHbmZeaJMjrdB4eRvv/rAGaCoWqlBwoZ/HDhbdtnpybZoYSda+mLU4M7Ng7JzTtF52o7JIC2PYh3EPCT9y8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+69033+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) header.from= Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1608155499237789.7209239092789; Wed, 16 Dec 2020 13:51:39 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id ZoDAYY1788612xwh6ZIv0O4C; Wed, 16 Dec 2020 13:51:38 -0800 X-Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.groups.io with SMTP id smtpd.web11.4066.1608155498253760753 for ; Wed, 16 Dec 2020 13:51:38 -0800 X-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-369-cprC8zIQPRy2FcxgsXtsGw-1; Wed, 16 Dec 2020 16:51:33 -0500 X-MC-Unique: cprC8zIQPRy2FcxgsXtsGw-1 X-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 5E85959; Wed, 16 Dec 2020 21:51:32 +0000 (UTC) X-Received: from lacos-laptop-7.usersys.redhat.com (ovpn-114-152.ams2.redhat.com [10.36.114.152]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8363227C3D; Wed, 16 Dec 2020 21:51:27 +0000 (UTC) From: "Laszlo Ersek" To: devel@edk2.groups.io, virtio-fs@redhat.com, lersek@redhat.com Cc: Ard Biesheuvel , Jordan Justen , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [edk2-devel] [edk2 PATCH 19/48] OvmfPkg/VirtioFsDxe: implement the wrapper function for FUSE_MKDIR Date: Wed, 16 Dec 2020 22:10:56 +0100 Message-Id: <20201216211125.19496-20-lersek@redhat.com> In-Reply-To: <20201216211125.19496-1-lersek@redhat.com> References: <20201216211125.19496-1-lersek@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,lersek@redhat.com X-Gm-Message-State: HwrecNSpwWnt2vK1o8tnkVobx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1608155498; bh=eiE09NSSdP3cthsHcReNcrVJ8Sh2YF4QFJZLnakFKBg=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=gtgwazjGk7Sa746FISpuZGKpxqlBXvY/sQRJzZgkTMS/er2JfQd1pR+2phoERpIsr36 v4HNMmk2Ui2niKWyoXWqIdGgB8wLyc88cajKzJyctrlBVxLQJavPcUe44BCYxfd9Ii1tI fPOMgmU+VFEpd7ib9x1XFnHNAA/cskZuwr0= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" Add the VirtioFsFuseMkDir() function, for sending the FUSE_MKDIR command to the Virtio Filesystem device. Cc: Ard Biesheuvel Cc: Jordan Justen Cc: Philippe Mathieu-Daud=C3=A9 Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3097 Signed-off-by: Laszlo Ersek Acked-by: Ard Biesheuvel --- OvmfPkg/Include/IndustryStandard/VirtioFs.h | 55 ++++++++ OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf | 1 + OvmfPkg/VirtioFsDxe/VirtioFsDxe.h | 8 ++ OvmfPkg/VirtioFsDxe/FuseMkDir.c | 134 ++++++++++++++++++++ 4 files changed, 198 insertions(+) diff --git a/OvmfPkg/Include/IndustryStandard/VirtioFs.h b/OvmfPkg/Include/= IndustryStandard/VirtioFs.h index 7b6f30335577..9ffeb9c8c954 100644 --- a/OvmfPkg/Include/IndustryStandard/VirtioFs.h +++ b/OvmfPkg/Include/IndustryStandard/VirtioFs.h @@ -76,27 +76,35 @@ typedef struct { #define VIRTIO_FS_FUSE_MAJOR 7 #define VIRTIO_FS_FUSE_MINOR 31 =20 // // The inode number of the root directory. // #define VIRTIO_FS_FUSE_ROOT_DIR_NODE_ID 1 =20 +// +// File mode bitmasks. +// +#define VIRTIO_FS_FUSE_MODE_PERM_RWXU 0000700u +#define VIRTIO_FS_FUSE_MODE_PERM_RWXG 0000070u +#define VIRTIO_FS_FUSE_MODE_PERM_RWXO 0000007u + // // Flags for VirtioFsFuseOpOpen. // #define VIRTIO_FS_FUSE_OPEN_REQ_F_RDONLY 0 #define VIRTIO_FS_FUSE_OPEN_REQ_F_RDWR 2 =20 // // FUSE operation codes. // typedef enum { VirtioFsFuseOpForget =3D 2, + VirtioFsFuseOpMkDir =3D 9, VirtioFsFuseOpOpen =3D 14, VirtioFsFuseOpRelease =3D 18, VirtioFsFuseOpFsync =3D 20, VirtioFsFuseOpFlush =3D 25, VirtioFsFuseOpInit =3D 26, VirtioFsFuseOpOpenDir =3D 27, VirtioFsFuseOpReleaseDir =3D 29, VirtioFsFuseOpFsyncDir =3D 30, @@ -118,23 +126,70 @@ typedef struct { } VIRTIO_FS_FUSE_REQUEST; =20 typedef struct { UINT32 Len; INT32 Error; UINT64 Unique; } VIRTIO_FS_FUSE_RESPONSE; =20 +// +// Structure with which the Virtio Filesystem device reports a NodeId to t= he +// FUSE client (i.e., to the Virtio Filesystem driver). This structure is a +// part of the response headers for operations that inform the FUSE client= of +// an inode. +// +typedef struct { + UINT64 NodeId; + UINT64 Generation; + UINT64 EntryValid; + UINT64 AttrValid; + UINT32 EntryValidNsec; + UINT32 AttrValidNsec; +} VIRTIO_FS_FUSE_NODE_RESPONSE; + +// +// Structure describing the host-side attributes of an inode. This structu= re is +// a part of the response headers for operations that inform the FUSE clie= nt of +// an inode. +// +typedef struct { + UINT64 Ino; + UINT64 Size; + UINT64 Blocks; + UINT64 Atime; + UINT64 Mtime; + UINT64 Ctime; + UINT32 AtimeNsec; + UINT32 MtimeNsec; + UINT32 CtimeNsec; + UINT32 Mode; + UINT32 Nlink; + UINT32 Uid; + UINT32 Gid; + UINT32 Rdev; + UINT32 Blksize; + UINT32 Padding; +} VIRTIO_FS_FUSE_ATTRIBUTES_RESPONSE; + // // Header for VirtioFsFuseOpForget. // typedef struct { UINT64 NumberOfLookups; } VIRTIO_FS_FUSE_FORGET_REQUEST; =20 +// +// Header for VirtioFsFuseOpMkDir. +// +typedef struct { + UINT32 Mode; + UINT32 Umask; +} VIRTIO_FS_FUSE_MKDIR_REQUEST; + // // Headers for VirtioFsFuseOpOpen and VirtioFsFuseOpOpenDir. // typedef struct { UINT32 Flags; UINT32 Unused; } VIRTIO_FS_FUSE_OPEN_REQUEST; =20 diff --git a/OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf b/OvmfPkg/VirtioFsDxe/Virt= ioFsDxe.inf index dc9a12820f3d..eebb86f7c275 100644 --- a/OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf +++ b/OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf @@ -81,16 +81,17 @@ [Packages] OvmfPkg/OvmfPkg.dec =20 [Sources] DriverBinding.c FuseFlush.c FuseForget.c FuseFsync.c FuseInit.c + FuseMkDir.c FuseOpen.c FuseOpenDir.c FuseRelease.c Helpers.c SimpleFsClose.c SimpleFsDelete.c SimpleFsFlush.c SimpleFsGetInfo.c diff --git a/OvmfPkg/VirtioFsDxe/VirtioFsDxe.h b/OvmfPkg/VirtioFsDxe/Virtio= FsDxe.h index c13258a2e08f..8fd56bdbf6e1 100644 --- a/OvmfPkg/VirtioFsDxe/VirtioFsDxe.h +++ b/OvmfPkg/VirtioFsDxe/VirtioFsDxe.h @@ -230,16 +230,24 @@ VirtioFsAppendPath ( // =20 EFI_STATUS VirtioFsFuseForget ( IN OUT VIRTIO_FS *VirtioFs, IN UINT64 NodeId ); =20 +EFI_STATUS +VirtioFsFuseMkDir ( + IN OUT VIRTIO_FS *VirtioFs, + IN UINT64 ParentNodeId, + IN CHAR8 *Name, + OUT UINT64 *NodeId + ); + EFI_STATUS VirtioFsFuseOpen ( IN OUT VIRTIO_FS *VirtioFs, IN UINT64 NodeId, IN BOOLEAN ReadWrite, OUT UINT64 *FuseHandle ); =20 diff --git a/OvmfPkg/VirtioFsDxe/FuseMkDir.c b/OvmfPkg/VirtioFsDxe/FuseMkDi= r.c new file mode 100644 index 000000000000..541ff330cd1e --- /dev/null +++ b/OvmfPkg/VirtioFsDxe/FuseMkDir.c @@ -0,0 +1,134 @@ +/** @file + FUSE_MKDIR wrapper for the Virtio Filesystem device. + + Copyright (C) 2020, Red Hat, Inc. + + SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#include // AsciiStrSize() + +#include "VirtioFsDxe.h" + +/** + Send a FUSE_MKDIR request to the Virtio Filesystem device, for creating a + directory. + + The function may only be called after VirtioFsFuseInitSession() returns + successfully and before VirtioFsUninit() is called. + + @param[in,out] VirtioFs The Virtio Filesystem device to send the FUSE_M= KDIR + request to. On output, the FUSE request counter + "VirtioFs->RequestId" will have been incremente= d. + + @param[in] ParentNodeId The inode number of the direct parent directory= of + the directory to create. + + @param[in] Name The single-component filename of the directory = to + create, under the parent directory identified by + ParentNodeId. + + @param[out] NodeId The inode number of the new directory. + + @retval EFI_SUCCESS The directory has been created. + + @return The "errno" value mapped to an EFI_STATUS code, if = the + Virtio Filesystem device explicitly reported an err= or. + + @return Error codes propagated from VirtioFsSgListsValidate= (), + VirtioFsFuseNewRequest(), VirtioFsSgListsSubmit(), + VirtioFsFuseCheckResponse(). +**/ +EFI_STATUS +VirtioFsFuseMkDir ( + IN OUT VIRTIO_FS *VirtioFs, + IN UINT64 ParentNodeId, + IN CHAR8 *Name, + OUT UINT64 *NodeId + ) +{ + VIRTIO_FS_FUSE_REQUEST CommonReq; + VIRTIO_FS_FUSE_MKDIR_REQUEST MkDirReq; + VIRTIO_FS_IO_VECTOR ReqIoVec[3]; + VIRTIO_FS_SCATTER_GATHER_LIST ReqSgList; + VIRTIO_FS_FUSE_RESPONSE CommonResp; + VIRTIO_FS_FUSE_NODE_RESPONSE NodeResp; + VIRTIO_FS_FUSE_ATTRIBUTES_RESPONSE AttrResp; + VIRTIO_FS_IO_VECTOR RespIoVec[3]; + VIRTIO_FS_SCATTER_GATHER_LIST RespSgList; + EFI_STATUS Status; + + // + // Set up the scatter-gather lists. + // + ReqIoVec[0].Buffer =3D &CommonReq; + ReqIoVec[0].Size =3D sizeof CommonReq; + ReqIoVec[1].Buffer =3D &MkDirReq; + ReqIoVec[1].Size =3D sizeof MkDirReq; + ReqIoVec[2].Buffer =3D Name; + ReqIoVec[2].Size =3D AsciiStrSize (Name); + ReqSgList.IoVec =3D ReqIoVec; + ReqSgList.NumVec =3D ARRAY_SIZE (ReqIoVec); + + RespIoVec[0].Buffer =3D &CommonResp; + RespIoVec[0].Size =3D sizeof CommonResp; + RespIoVec[1].Buffer =3D &NodeResp; + RespIoVec[1].Size =3D sizeof NodeResp; + RespIoVec[2].Buffer =3D &AttrResp; + RespIoVec[2].Size =3D sizeof AttrResp; + RespSgList.IoVec =3D RespIoVec; + RespSgList.NumVec =3D ARRAY_SIZE (RespIoVec); + + // + // Validate the scatter-gather lists; calculate the total transfer sizes. + // + Status =3D VirtioFsSgListsValidate (VirtioFs, &ReqSgList, &RespSgList); + if (EFI_ERROR (Status)) { + return Status; + } + + // + // Populate the common request header. + // + Status =3D VirtioFsFuseNewRequest (VirtioFs, &CommonReq, ReqSgList.Total= Size, + VirtioFsFuseOpMkDir, ParentNodeId); + if (EFI_ERROR (Status)) { + return Status; + } + + // + // Populate the FUSE_MKDIR-specific fields. + // + MkDirReq.Mode =3D (VIRTIO_FS_FUSE_MODE_PERM_RWXU | + VIRTIO_FS_FUSE_MODE_PERM_RWXG | + VIRTIO_FS_FUSE_MODE_PERM_RWXO); + MkDirReq.Umask =3D 0; + + // + // Submit the request. + // + Status =3D VirtioFsSgListsSubmit (VirtioFs, &ReqSgList, &RespSgList); + if (EFI_ERROR (Status)) { + return Status; + } + + // + // Verify the response (all response buffers are fixed size). + // + Status =3D VirtioFsFuseCheckResponse (&RespSgList, CommonReq.Unique, NUL= L); + if (EFI_ERROR (Status)) { + if (Status =3D=3D EFI_DEVICE_ERROR) { + DEBUG ((DEBUG_ERROR, "%a: Label=3D\"%s\" ParentNodeId=3D%Lu Name=3D\= "%a\" " + "Errno=3D%d\n", __FUNCTION__, VirtioFs->Label, ParentNodeId, Name, + CommonResp.Error)); + Status =3D VirtioFsErrnoToEfiStatus (CommonResp.Error); + } + return Status; + } + + // + // Output the NodeId of the new directory. + // + *NodeId =3D NodeResp.NodeId; + return EFI_SUCCESS; +} --=20 2.19.1.3.g30247aa5d201 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#69033): https://edk2.groups.io/g/devel/message/69033 Mute This Topic: https://groups.io/mt/79023350/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Tue May 7 07:56:31 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+69034+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+69034+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1608155630; cv=none; d=zohomail.com; s=zohoarc; b=RjRqFOr5LpXhpkm7DQlJg69hZq5nkGFAhEWUJdqDXgjW8AHPlsWp/qKzO7xn0H+J9XdUcvQU7elHSF7KzPBvxQ6HREGcA6B2sFyTtdH1puxEgMQFEWefGQgUwt68IzkXPW0KsVQUmzimg/QiHyFaC3/qiiBjIKn49H+jHkRK08o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608155630; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=SPiyeWRUxzVmpbFzxk8/pG6/krjJybkKWm45k3YPsJ4=; b=HVibbFxBYE7HOdGyMXurwQ9QC4n/odZ7ViCoCJmylLxce7Qw1gcpmJmACG04LB15rDr+No3naRl1rzFjPFjYqE4xLh3N/iRucIwKH0uU1DNRePVTCo495VmZg6aZ9lLNNruGcy/p/nhB77bxiCAV4zJvgb3/sfhioEiJ86hzIj4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+69034+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) header.from= Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1608155630299980.8521597267653; Wed, 16 Dec 2020 13:53:50 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id o7w6YY1788612xrQka10qniP; Wed, 16 Dec 2020 13:53:49 -0800 X-Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.groups.io with SMTP id smtpd.web09.4017.1608155624147552000 for ; Wed, 16 Dec 2020 13:53:44 -0800 X-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-470-f8goCZPdOL6hhzyxTkNEAA-1; Wed, 16 Dec 2020 16:53:39 -0500 X-MC-Unique: f8goCZPdOL6hhzyxTkNEAA-1 X-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 5D561107ACE6; Wed, 16 Dec 2020 21:53:38 +0000 (UTC) X-Received: from lacos-laptop-7.usersys.redhat.com (ovpn-114-152.ams2.redhat.com [10.36.114.152]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8F00A5D9C0; Wed, 16 Dec 2020 21:53:33 +0000 (UTC) From: "Laszlo Ersek" To: devel@edk2.groups.io, virtio-fs@redhat.com, lersek@redhat.com Cc: Ard Biesheuvel , Jordan Justen , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [edk2-devel] [edk2 PATCH 20/48] OvmfPkg/VirtioFsDxe: implement the wrapper function for FUSE_CREATE Date: Wed, 16 Dec 2020 22:10:57 +0100 Message-Id: <20201216211125.19496-21-lersek@redhat.com> In-Reply-To: <20201216211125.19496-1-lersek@redhat.com> References: <20201216211125.19496-1-lersek@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,lersek@redhat.com X-Gm-Message-State: vGheoPozePXtUAaEgHTk71Jsx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1608155629; bh=SPiyeWRUxzVmpbFzxk8/pG6/krjJybkKWm45k3YPsJ4=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=C+4ifVdcuF0aSEY3N5haaEwO/txkFw70LR0SjPnO67kbWewtJ0hUcX5qvG4QvRiDztK 1BKZVyy0bM7tYW6VnVpgO8+qGL16fzpBuDdJLZhwB44YAAS1gYlcOHtZx9s4P5UoevIDw we2glThvM7tWMQYH9EOty/njVdRikvPZ5oQ= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" Add the VirtioFsFuseOpenOrCreate() function, for sending the FUSE_CREATE command to the Virtio Filesystem device. Cc: Ard Biesheuvel Cc: Jordan Justen Cc: Philippe Mathieu-Daud=C3=A9 Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3097 Signed-off-by: Laszlo Ersek Acked-by: Ard Biesheuvel --- OvmfPkg/Include/IndustryStandard/VirtioFs.h | 17 +++ OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf | 1 + OvmfPkg/VirtioFsDxe/VirtioFsDxe.h | 9 ++ OvmfPkg/VirtioFsDxe/FuseOpenOrCreate.c | 155 ++++++++++++++++++++ 4 files changed, 182 insertions(+) diff --git a/OvmfPkg/Include/IndustryStandard/VirtioFs.h b/OvmfPkg/Include/= IndustryStandard/VirtioFs.h index 9ffeb9c8c954..63aced229e9b 100644 --- a/OvmfPkg/Include/IndustryStandard/VirtioFs.h +++ b/OvmfPkg/Include/IndustryStandard/VirtioFs.h @@ -80,18 +80,24 @@ typedef struct { // The inode number of the root directory. // #define VIRTIO_FS_FUSE_ROOT_DIR_NODE_ID 1 =20 // // File mode bitmasks. // #define VIRTIO_FS_FUSE_MODE_PERM_RWXU 0000700u +#define VIRTIO_FS_FUSE_MODE_PERM_RUSR 0000400u +#define VIRTIO_FS_FUSE_MODE_PERM_WUSR 0000200u #define VIRTIO_FS_FUSE_MODE_PERM_RWXG 0000070u +#define VIRTIO_FS_FUSE_MODE_PERM_RGRP 0000040u +#define VIRTIO_FS_FUSE_MODE_PERM_WGRP 0000020u #define VIRTIO_FS_FUSE_MODE_PERM_RWXO 0000007u +#define VIRTIO_FS_FUSE_MODE_PERM_ROTH 0000004u +#define VIRTIO_FS_FUSE_MODE_PERM_WOTH 0000002u =20 // // Flags for VirtioFsFuseOpOpen. // #define VIRTIO_FS_FUSE_OPEN_REQ_F_RDONLY 0 #define VIRTIO_FS_FUSE_OPEN_REQ_F_RDWR 2 =20 // @@ -103,16 +109,17 @@ typedef enum { VirtioFsFuseOpOpen =3D 14, VirtioFsFuseOpRelease =3D 18, VirtioFsFuseOpFsync =3D 20, VirtioFsFuseOpFlush =3D 25, VirtioFsFuseOpInit =3D 26, VirtioFsFuseOpOpenDir =3D 27, VirtioFsFuseOpReleaseDir =3D 29, VirtioFsFuseOpFsyncDir =3D 30, + VirtioFsFuseOpCreate =3D 35, } VIRTIO_FS_FUSE_OPCODE; =20 #pragma pack (1) // // Request-response headers common to all request types. // typedef struct { UINT32 Len; @@ -246,11 +253,21 @@ typedef struct { UINT16 MaxBackground; UINT16 CongestionThreshold; UINT32 MaxWrite; UINT32 TimeGran; UINT16 MaxPages; UINT16 MapAlignment; UINT32 Unused[8]; } VIRTIO_FS_FUSE_INIT_RESPONSE; + +// +// Header for VirtioFsFuseOpCreate. +// +typedef struct { + UINT32 Flags; + UINT32 Mode; + UINT32 Umask; + UINT32 Padding; +} VIRTIO_FS_FUSE_CREATE_REQUEST; #pragma pack () =20 #endif // VIRTIO_FS_H_ diff --git a/OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf b/OvmfPkg/VirtioFsDxe/Virt= ioFsDxe.inf index eebb86f7c275..b942baa4a772 100644 --- a/OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf +++ b/OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf @@ -84,16 +84,17 @@ [Sources] DriverBinding.c FuseFlush.c FuseForget.c FuseFsync.c FuseInit.c FuseMkDir.c FuseOpen.c FuseOpenDir.c + FuseOpenOrCreate.c FuseRelease.c Helpers.c SimpleFsClose.c SimpleFsDelete.c SimpleFsFlush.c SimpleFsGetInfo.c SimpleFsGetPosition.c SimpleFsOpen.c diff --git a/OvmfPkg/VirtioFsDxe/VirtioFsDxe.h b/OvmfPkg/VirtioFsDxe/Virtio= FsDxe.h index 8fd56bdbf6e1..795cf4ee5d7d 100644 --- a/OvmfPkg/VirtioFsDxe/VirtioFsDxe.h +++ b/OvmfPkg/VirtioFsDxe/VirtioFsDxe.h @@ -281,16 +281,25 @@ VirtioFsFuseInitSession ( =20 EFI_STATUS VirtioFsFuseOpenDir ( IN OUT VIRTIO_FS *VirtioFs, IN UINT64 NodeId, OUT UINT64 *FuseHandle ); =20 +EFI_STATUS +VirtioFsFuseOpenOrCreate ( + IN OUT VIRTIO_FS *VirtioFs, + IN UINT64 ParentNodeId, + IN CHAR8 *Name, + OUT UINT64 *NodeId, + OUT UINT64 *FuseHandle + ); + // // EFI_SIMPLE_FILE_SYSTEM_PROTOCOL member functions for the Virtio Filesys= tem // driver. // =20 EFI_STATUS EFIAPI VirtioFsOpenVolume ( diff --git a/OvmfPkg/VirtioFsDxe/FuseOpenOrCreate.c b/OvmfPkg/VirtioFsDxe/F= useOpenOrCreate.c new file mode 100644 index 000000000000..60ab002bcd99 --- /dev/null +++ b/OvmfPkg/VirtioFsDxe/FuseOpenOrCreate.c @@ -0,0 +1,155 @@ +/** @file + FUSE_CREATE wrapper for the Virtio Filesystem device. + + Copyright (C) 2020, Red Hat, Inc. + + SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#include // AsciiStrSize() + +#include "VirtioFsDxe.h" + +/** + Send a FUSE_CREATE request to the Virtio Filesystem device, for opening a + regular file with (O_RDWR | O_CREAT) semantics. + + The function may only be called after VirtioFsFuseInitSession() returns + successfully and before VirtioFsUninit() is called. + + @param[in,out] VirtioFs The Virtio Filesystem device to send the FUSE_C= REATE + request to. On output, the FUSE request counter + "VirtioFs->RequestId" will have been incremente= d. + + @param[in] ParentNodeId The inode number of the direct parent directory= of + the regular file to open or create. + + @param[in] Name The single-component filename of the regular fi= le to + open or create, under the parent directory + identified by ParentNodeId. + + @param[out] NodeId The inode number of the regular file, returned = by + the Virtio Filesystem device. + + @param[out] FuseHandle The open file handle returned by the Virtio + Filesystem device. + + @retval EFI_SUCCESS The regular file has been opened, and (if necessary) + created. + + @return The "errno" value mapped to an EFI_STATUS code, if = the + Virtio Filesystem device explicitly reported an err= or. + + @return Error codes propagated from VirtioFsSgListsValidate= (), + VirtioFsFuseNewRequest(), VirtioFsSgListsSubmit(), + VirtioFsFuseCheckResponse(). +**/ +EFI_STATUS +VirtioFsFuseOpenOrCreate ( + IN OUT VIRTIO_FS *VirtioFs, + IN UINT64 ParentNodeId, + IN CHAR8 *Name, + OUT UINT64 *NodeId, + OUT UINT64 *FuseHandle + ) +{ + VIRTIO_FS_FUSE_REQUEST CommonReq; + VIRTIO_FS_FUSE_CREATE_REQUEST CreateReq; + VIRTIO_FS_IO_VECTOR ReqIoVec[3]; + VIRTIO_FS_SCATTER_GATHER_LIST ReqSgList; + VIRTIO_FS_FUSE_RESPONSE CommonResp; + VIRTIO_FS_FUSE_NODE_RESPONSE NodeResp; + VIRTIO_FS_FUSE_ATTRIBUTES_RESPONSE AttrResp; + VIRTIO_FS_FUSE_OPEN_RESPONSE OpenResp; + VIRTIO_FS_IO_VECTOR RespIoVec[4]; + VIRTIO_FS_SCATTER_GATHER_LIST RespSgList; + EFI_STATUS Status; + + // + // Set up the scatter-gather lists. + // + ReqIoVec[0].Buffer =3D &CommonReq; + ReqIoVec[0].Size =3D sizeof CommonReq; + ReqIoVec[1].Buffer =3D &CreateReq; + ReqIoVec[1].Size =3D sizeof CreateReq; + ReqIoVec[2].Buffer =3D Name; + ReqIoVec[2].Size =3D AsciiStrSize (Name); + ReqSgList.IoVec =3D ReqIoVec; + ReqSgList.NumVec =3D ARRAY_SIZE (ReqIoVec); + + RespIoVec[0].Buffer =3D &CommonResp; + RespIoVec[0].Size =3D sizeof CommonResp; + RespIoVec[1].Buffer =3D &NodeResp; + RespIoVec[1].Size =3D sizeof NodeResp; + RespIoVec[2].Buffer =3D &AttrResp; + RespIoVec[2].Size =3D sizeof AttrResp; + RespIoVec[3].Buffer =3D &OpenResp; + RespIoVec[3].Size =3D sizeof OpenResp; + RespSgList.IoVec =3D RespIoVec; + RespSgList.NumVec =3D ARRAY_SIZE (RespIoVec); + + // + // Validate the scatter-gather lists; calculate the total transfer sizes. + // + Status =3D VirtioFsSgListsValidate (VirtioFs, &ReqSgList, &RespSgList); + if (EFI_ERROR (Status)) { + return Status; + } + + // + // Populate the common request header. + // + Status =3D VirtioFsFuseNewRequest (VirtioFs, &CommonReq, ReqSgList.Total= Size, + VirtioFsFuseOpCreate, ParentNodeId); + if (EFI_ERROR (Status)) { + return Status; + } + + // + // Populate the FUSE_CREATE-specific fields. + // + // VIRTIO_FS_FUSE_OPEN_REQ_F_RDWR is why this request can never open a + // directory (EISDIR). And VIRTIO_FS_FUSE_OPEN_REQ_F_RDWR is consistent = with + // the only OpenMode of EFI_FILE_PROTOCOL.Open() that enables filesystem + // object creation -- that is, Create/Read/Write. + // + CreateReq.Flags =3D VIRTIO_FS_FUSE_OPEN_REQ_F_RDWR; + CreateReq.Mode =3D (VIRTIO_FS_FUSE_MODE_PERM_RUSR | + VIRTIO_FS_FUSE_MODE_PERM_WUSR | + VIRTIO_FS_FUSE_MODE_PERM_RGRP | + VIRTIO_FS_FUSE_MODE_PERM_WGRP | + VIRTIO_FS_FUSE_MODE_PERM_ROTH | + VIRTIO_FS_FUSE_MODE_PERM_WOTH); + CreateReq.Umask =3D 0; + CreateReq.Padding =3D 0; + + // + // Submit the request. + // + Status =3D VirtioFsSgListsSubmit (VirtioFs, &ReqSgList, &RespSgList); + if (EFI_ERROR (Status)) { + return Status; + } + + // + // Verify the response (all response buffers are fixed size). + // + Status =3D VirtioFsFuseCheckResponse (&RespSgList, CommonReq.Unique, NUL= L); + if (EFI_ERROR (Status)) { + if (Status =3D=3D EFI_DEVICE_ERROR) { + DEBUG ((DEBUG_ERROR, "%a: Label=3D\"%s\" ParentNodeId=3D%Lu Name=3D\= "%a\" " + "Errno=3D%d\n", __FUNCTION__, VirtioFs->Label, ParentNodeId, Name, + CommonResp.Error)); + Status =3D VirtioFsErrnoToEfiStatus (CommonResp.Error); + } + return Status; + } + + // + // Output the NodeId of the (possibly new) regular file. Also output the= open + // file handle. + // + *NodeId =3D NodeResp.NodeId; + *FuseHandle =3D OpenResp.FileHandle; + return EFI_SUCCESS; +} --=20 2.19.1.3.g30247aa5d201 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#69034): https://edk2.groups.io/g/devel/message/69034 Mute This Topic: https://groups.io/mt/79023402/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Tue May 7 07:56:31 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+69035+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+69035+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1608155755; cv=none; d=zohomail.com; s=zohoarc; b=IWjlsZBVoLnzDGqGxo7kZ+3YNz9mA11hFh1cPsafRQWJ/FER1VRw6FmafJNlC3Wl3PMqybDGXvah3hAioYVbTcCJiUPZDELhW+OShyNXYrN9o7u3/iOiV80AFBMTszXUjQ12oY/SqPg0MT2oiHAeBWj2VWqYj6w6H1owe4hOEfY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608155755; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=QaELhLK2gl77uQEagTwcQMUf60n20oJ/tPRROTU1H+0=; b=ADp/wH4cXEQG7uX9sUcgY8oqZ9Mf8+KdzY9dZ3AV9FS/AKDTX8fWuSMnsdI3iWiZwCJi9NIEvY5bSsyB/2EyQ0jdaISnYDZycGuffBa6GCUxKRUSO2DdGq92ndSSio7mOlD1ueuiAux/LmptHz4f5/4vIrtbc0/z3RrncjkXWPU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+69035+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) header.from= Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1608155755809407.5251216177777; Wed, 16 Dec 2020 13:55:55 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id H2ELYY1788612xKKNtKCaymv; Wed, 16 Dec 2020 13:55:55 -0800 X-Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.groups.io with SMTP id smtpd.web10.4272.1608155749890947673 for ; Wed, 16 Dec 2020 13:55:50 -0800 X-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-258-qRFhBgrsMvus0oSNKbSkNQ-1; Wed, 16 Dec 2020 16:55:45 -0500 X-MC-Unique: qRFhBgrsMvus0oSNKbSkNQ-1 X-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 32FDBE758; Wed, 16 Dec 2020 21:55:44 +0000 (UTC) X-Received: from lacos-laptop-7.usersys.redhat.com (ovpn-114-152.ams2.redhat.com [10.36.114.152]) by smtp.corp.redhat.com (Postfix) with ESMTP id 990781A49B; Wed, 16 Dec 2020 21:55:39 +0000 (UTC) From: "Laszlo Ersek" To: devel@edk2.groups.io, virtio-fs@redhat.com, lersek@redhat.com Cc: Ard Biesheuvel , Jordan Justen , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [edk2-devel] [edk2 PATCH 21/48] OvmfPkg/VirtioFsDxe: convert FUSE inode attributes to EFI_FILE_INFO Date: Wed, 16 Dec 2020 22:10:58 +0100 Message-Id: <20201216211125.19496-22-lersek@redhat.com> In-Reply-To: <20201216211125.19496-1-lersek@redhat.com> References: <20201216211125.19496-1-lersek@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,lersek@redhat.com X-Gm-Message-State: tpjqn9ItQ0NjgsYr5aaTmhfCx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1608155755; bh=QaELhLK2gl77uQEagTwcQMUf60n20oJ/tPRROTU1H+0=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=fAJkCJzfeYdot7PrOVfhOJU3QTOMmmxNl2MjHLEcq7sXoyGb11Zfy6TTz5gMANRvGUi fI+6z6BF0go9A8KEpGlA6Ou1KNL9LSFDh/4lbmPxtoHD9ywjMjFpoHsPyaZ5KFGPlt4A1 SUZ7vWZcy9nNzem8exZgWj0+TCMkrIT1fHs= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" Introduce the VirtioFsFuseAttrToEfiFileInfo() function, for converting FUSE inode attributes to EFI_FILE_INFO. The EpochToEfiTime() function from EmbeddedPkg's TimeBaseLib proves invaluable for converting the file access times. This is the first time we consume TimeBaseLib in OvmfPkg, so add the necessary lib class resolution. We need not modify any ArmVirtPkg DSC files: see commit af5fed90bfbf ("ArmPlatformPkg,ArmVirtPkg: delete redundant PL031 functions", 2017-05-10). Cc: Ard Biesheuvel Cc: Jordan Justen Cc: Philippe Mathieu-Daud=C3=A9 Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3097 Signed-off-by: Laszlo Ersek Acked-by: Ard Biesheuvel --- OvmfPkg/OvmfPkgIa32.dsc | 1 + OvmfPkg/OvmfPkgIa32X64.dsc | 1 + OvmfPkg/OvmfPkgX64.dsc | 1 + OvmfPkg/Include/IndustryStandard/VirtioFs.h | 3 + OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf | 2 + OvmfPkg/VirtioFsDxe/VirtioFsDxe.h | 7 ++ OvmfPkg/VirtioFsDxe/Helpers.c | 119 ++++++++++++++++++++ 7 files changed, 134 insertions(+) diff --git a/OvmfPkg/OvmfPkgIa32.dsc b/OvmfPkg/OvmfPkgIa32.dsc index 4ff70674fb6e..26a013ec353e 100644 --- a/OvmfPkg/OvmfPkgIa32.dsc +++ b/OvmfPkg/OvmfPkgIa32.dsc @@ -120,16 +120,17 @@ [SkuIds] [LibraryClasses] PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf TimerLib|OvmfPkg/Library/AcpiTimerLib/BaseAcpiTimerLib.inf ResetSystemLib|OvmfPkg/Library/ResetSystemLib/BaseResetSystemLib.inf PrintLib|MdePkg/Library/BasePrintLib/BasePrintLib.inf BaseMemoryLib|MdePkg/Library/BaseMemoryLibRepStr/BaseMemoryLibRepStr.inf BaseLib|MdePkg/Library/BaseLib/BaseLib.inf SafeIntLib|MdePkg/Library/BaseSafeIntLib/BaseSafeIntLib.inf + TimeBaseLib|EmbeddedPkg/Library/TimeBaseLib/TimeBaseLib.inf BmpSupportLib|MdeModulePkg/Library/BaseBmpSupportLib/BaseBmpSupportLib.i= nf SynchronizationLib|MdePkg/Library/BaseSynchronizationLib/BaseSynchroniza= tionLib.inf CpuLib|MdePkg/Library/BaseCpuLib/BaseCpuLib.inf PerformanceLib|MdePkg/Library/BasePerformanceLibNull/BasePerformanceLibN= ull.inf PeCoffLib|MdePkg/Library/BasePeCoffLib/BasePeCoffLib.inf CacheMaintenanceLib|MdePkg/Library/BaseCacheMaintenanceLib/BaseCacheMain= tenanceLib.inf UefiDecompressLib|MdePkg/Library/BaseUefiDecompressLib/BaseUefiDecompres= sLib.inf UefiHiiServicesLib|MdeModulePkg/Library/UefiHiiServicesLib/UefiHiiServic= esLib.inf diff --git a/OvmfPkg/OvmfPkgIa32X64.dsc b/OvmfPkg/OvmfPkgIa32X64.dsc index d40a59183c79..10579fe46c5b 100644 --- a/OvmfPkg/OvmfPkgIa32X64.dsc +++ b/OvmfPkg/OvmfPkgIa32X64.dsc @@ -124,16 +124,17 @@ [SkuIds] [LibraryClasses] PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf TimerLib|OvmfPkg/Library/AcpiTimerLib/BaseAcpiTimerLib.inf ResetSystemLib|OvmfPkg/Library/ResetSystemLib/BaseResetSystemLib.inf PrintLib|MdePkg/Library/BasePrintLib/BasePrintLib.inf BaseMemoryLib|MdePkg/Library/BaseMemoryLibRepStr/BaseMemoryLibRepStr.inf BaseLib|MdePkg/Library/BaseLib/BaseLib.inf SafeIntLib|MdePkg/Library/BaseSafeIntLib/BaseSafeIntLib.inf + TimeBaseLib|EmbeddedPkg/Library/TimeBaseLib/TimeBaseLib.inf BmpSupportLib|MdeModulePkg/Library/BaseBmpSupportLib/BaseBmpSupportLib.i= nf SynchronizationLib|MdePkg/Library/BaseSynchronizationLib/BaseSynchroniza= tionLib.inf CpuLib|MdePkg/Library/BaseCpuLib/BaseCpuLib.inf PerformanceLib|MdePkg/Library/BasePerformanceLibNull/BasePerformanceLibN= ull.inf PeCoffLib|MdePkg/Library/BasePeCoffLib/BasePeCoffLib.inf CacheMaintenanceLib|MdePkg/Library/BaseCacheMaintenanceLib/BaseCacheMain= tenanceLib.inf UefiDecompressLib|MdePkg/Library/BaseUefiDecompressLib/BaseUefiDecompres= sLib.inf UefiHiiServicesLib|MdeModulePkg/Library/UefiHiiServicesLib/UefiHiiServic= esLib.inf diff --git a/OvmfPkg/OvmfPkgX64.dsc b/OvmfPkg/OvmfPkgX64.dsc index ec7886235acf..c9235e48ad62 100644 --- a/OvmfPkg/OvmfPkgX64.dsc +++ b/OvmfPkg/OvmfPkgX64.dsc @@ -124,16 +124,17 @@ [SkuIds] [LibraryClasses] PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf TimerLib|OvmfPkg/Library/AcpiTimerLib/BaseAcpiTimerLib.inf ResetSystemLib|OvmfPkg/Library/ResetSystemLib/BaseResetSystemLib.inf PrintLib|MdePkg/Library/BasePrintLib/BasePrintLib.inf BaseMemoryLib|MdePkg/Library/BaseMemoryLibRepStr/BaseMemoryLibRepStr.inf BaseLib|MdePkg/Library/BaseLib/BaseLib.inf SafeIntLib|MdePkg/Library/BaseSafeIntLib/BaseSafeIntLib.inf + TimeBaseLib|EmbeddedPkg/Library/TimeBaseLib/TimeBaseLib.inf BmpSupportLib|MdeModulePkg/Library/BaseBmpSupportLib/BaseBmpSupportLib.i= nf SynchronizationLib|MdePkg/Library/BaseSynchronizationLib/BaseSynchroniza= tionLib.inf CpuLib|MdePkg/Library/BaseCpuLib/BaseCpuLib.inf PerformanceLib|MdePkg/Library/BasePerformanceLibNull/BasePerformanceLibN= ull.inf PeCoffLib|MdePkg/Library/BasePeCoffLib/BasePeCoffLib.inf CacheMaintenanceLib|MdePkg/Library/BaseCacheMaintenanceLib/BaseCacheMain= tenanceLib.inf UefiDecompressLib|MdePkg/Library/BaseUefiDecompressLib/BaseUefiDecompres= sLib.inf UefiHiiServicesLib|MdeModulePkg/Library/UefiHiiServicesLib/UefiHiiServic= esLib.inf diff --git a/OvmfPkg/Include/IndustryStandard/VirtioFs.h b/OvmfPkg/Include/= IndustryStandard/VirtioFs.h index 63aced229e9b..5d1d990a2d83 100644 --- a/OvmfPkg/Include/IndustryStandard/VirtioFs.h +++ b/OvmfPkg/Include/IndustryStandard/VirtioFs.h @@ -79,16 +79,19 @@ typedef struct { // // The inode number of the root directory. // #define VIRTIO_FS_FUSE_ROOT_DIR_NODE_ID 1 =20 // // File mode bitmasks. // +#define VIRTIO_FS_FUSE_MODE_TYPE_MASK 0170000u +#define VIRTIO_FS_FUSE_MODE_TYPE_REG 0100000u +#define VIRTIO_FS_FUSE_MODE_TYPE_DIR 0040000u #define VIRTIO_FS_FUSE_MODE_PERM_RWXU 0000700u #define VIRTIO_FS_FUSE_MODE_PERM_RUSR 0000400u #define VIRTIO_FS_FUSE_MODE_PERM_WUSR 0000200u #define VIRTIO_FS_FUSE_MODE_PERM_RWXG 0000070u #define VIRTIO_FS_FUSE_MODE_PERM_RGRP 0000040u #define VIRTIO_FS_FUSE_MODE_PERM_WGRP 0000020u #define VIRTIO_FS_FUSE_MODE_PERM_RWXO 0000007u #define VIRTIO_FS_FUSE_MODE_PERM_ROTH 0000004u diff --git a/OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf b/OvmfPkg/VirtioFsDxe/Virt= ioFsDxe.inf index b942baa4a772..7d7272188465 100644 --- a/OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf +++ b/OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf @@ -72,16 +72,17 @@ [Defines] INF_VERSION =3D 1.29 BASE_NAME =3D VirtioFsDxe FILE_GUID =3D 7BD9DDF7-8B83-488E-AEC9-24C786= 10289C MODULE_TYPE =3D UEFI_DRIVER ENTRY_POINT =3D VirtioFsEntryPoint =20 [Packages] + EmbeddedPkg/EmbeddedPkg.dec MdePkg/MdePkg.dec OvmfPkg/OvmfPkg.dec =20 [Sources] DriverBinding.c FuseFlush.c FuseForget.c FuseFsync.c @@ -105,16 +106,17 @@ [Sources] SimpleFsWrite.c VirtioFsDxe.h =20 [LibraryClasses] BaseLib BaseMemoryLib DebugLib MemoryAllocationLib + TimeBaseLib UefiBootServicesTableLib UefiDriverEntryPoint VirtioLib =20 [Protocols] gEfiComponentName2ProtocolGuid ## PRODUCES gEfiDriverBindingProtocolGuid ## PRODUCES gEfiSimpleFileSystemProtocolGuid ## BY_START diff --git a/OvmfPkg/VirtioFsDxe/VirtioFsDxe.h b/OvmfPkg/VirtioFsDxe/Virtio= FsDxe.h index 795cf4ee5d7d..6cc5257bab40 100644 --- a/OvmfPkg/VirtioFsDxe/VirtioFsDxe.h +++ b/OvmfPkg/VirtioFsDxe/VirtioFsDxe.h @@ -6,16 +6,17 @@ =20 SPDX-License-Identifier: BSD-2-Clause-Patent **/ =20 #ifndef VIRTIO_FS_DXE_H_ #define VIRTIO_FS_DXE_H_ =20 #include // SIGNATURE_64() +#include // EFI_FILE_INFO #include // VIRTIO_FS_TAG_BYTES #include // CR() #include // EFI_SIMPLE_FILE_SYSTEM_PROTOCOL #include // VIRTIO_DEVICE_PROTOCOL #include // EFI_EVENT =20 #define VIRTIO_FS_SIG SIGNATURE_64 ('V', 'I', 'R', 'T', 'I', 'O', 'F', 'S') =20 @@ -220,16 +221,22 @@ VirtioFsErrnoToEfiStatus ( EFI_STATUS VirtioFsAppendPath ( IN CHAR8 *LhsPath8, IN CHAR16 *RhsPath16, OUT CHAR8 **ResultPath8, OUT BOOLEAN *RootEscape ); =20 +EFI_STATUS +VirtioFsFuseAttrToEfiFileInfo ( + IN VIRTIO_FS_FUSE_ATTRIBUTES_RESPONSE *FuseAttr, + OUT EFI_FILE_INFO *FileInfo + ); + // // Wrapper functions for FUSE commands (primitives). // =20 EFI_STATUS VirtioFsFuseForget ( IN OUT VIRTIO_FS *VirtioFs, IN UINT64 NodeId diff --git a/OvmfPkg/VirtioFsDxe/Helpers.c b/OvmfPkg/VirtioFsDxe/Helpers.c index 4a7b59332ca9..fa656bb535b8 100644 --- a/OvmfPkg/VirtioFsDxe/Helpers.c +++ b/OvmfPkg/VirtioFsDxe/Helpers.c @@ -4,16 +4,17 @@ Copyright (C) 2020, Red Hat, Inc. =20 SPDX-License-Identifier: BSD-2-Clause-Patent **/ =20 #include // StrLen() #include // CopyMem() #include // AllocatePool() +#include // EpochToEfiTime() #include // Virtio10WriteFeatures() =20 #include "VirtioFsDxe.h" =20 /** Read the Virtio Filesystem device configuration structure in full. =20 @param[in] Virtio The Virtio protocol underlying the VIRTIO_FS object. @@ -1584,8 +1585,126 @@ VirtioFsAppendPath ( if (RhsPath8[0] !=3D '/') { FreePool (BufferToSanitize); } =20 FreeRhsPath8: FreePool (RhsPath8); return Status; } + +/** + Convert select fields of a VIRTIO_FS_FUSE_ATTRIBUTES_RESPONSE object to + corresponding fields in EFI_FILE_INFO. + + @param[in] FuseAttr The VIRTIO_FS_FUSE_ATTRIBUTES_RESPONSE object to + convert the relevant fields from. + + @param[out] FileInfo The EFI_FILE_INFO structure to modify. Importantly= , the + FileInfo->Size and FileInfo->FileName fields are n= ot + overwritten. + + @retval EFI_SUCCESS Conversion successful. + + @retval EFI_UNSUPPORTED The allocated size of the file is inexpressible= in + EFI_FILE_INFO. + + @retval EFI_UNSUPPORTED One of the file access times is inexpressible in + EFI_FILE_INFO. + + @retval EFI_UNSUPPORTED The file type is inexpressible in EFI_FILE_INFO. + + @retval EFI_UNSUPPORTED The file is a regular file that has multiple na= mes + on the host side (i.e., its hard link count is + greater than one). +**/ +EFI_STATUS +VirtioFsFuseAttrToEfiFileInfo ( + IN VIRTIO_FS_FUSE_ATTRIBUTES_RESPONSE *FuseAttr, + OUT EFI_FILE_INFO *FileInfo + ) +{ + UINT64 EpochTime[3]; + EFI_TIME *ConvertedTime[ARRAY_SIZE (EpochTime)]; + UINTN Idx; + + FileInfo->FileSize =3D FuseAttr->Size; + + // + // The unit for FuseAttr->Blocks is 512B. + // + if (FuseAttr->Blocks >=3D BIT55) { + return EFI_UNSUPPORTED; + } + FileInfo->PhysicalSize =3D LShiftU64 (FuseAttr->Blocks, 9); + + // + // Convert the timestamps. File creation time is not tracked by the Virt= io + // Filesystem device, so set FileInfo->CreateTime from FuseAttr->Mtime as + // well. + // + EpochTime[0] =3D FuseAttr->Mtime; + EpochTime[1] =3D FuseAttr->Atime; + EpochTime[2] =3D FuseAttr->Mtime; + ConvertedTime[0] =3D &FileInfo->CreateTime; + ConvertedTime[1] =3D &FileInfo->LastAccessTime; + ConvertedTime[2] =3D &FileInfo->ModificationTime; + + for (Idx =3D 0; Idx < ARRAY_SIZE (EpochTime); Idx++) { + // + // EpochToEfiTime() takes a UINTN for seconds. + // + if (EpochTime[Idx] > MAX_UINTN) { + return EFI_UNSUPPORTED; + } + // + // Set the following fields in the converted time: Year, Month, Day, H= our, + // Minute, Second, Nanosecond. + // + EpochToEfiTime ((UINTN)EpochTime[Idx], ConvertedTime[Idx]); + // + // The times are all expressed in UTC. Consequently, they are not affe= cted + // by daylight saving. + // + ConvertedTime[Idx]->TimeZone =3D 0; + ConvertedTime[Idx]->Daylight =3D 0; + // + // Clear the padding fields. + // + ConvertedTime[Idx]->Pad1 =3D 0; + ConvertedTime[Idx]->Pad2 =3D 0; + } + + // + // Set the attributes. + // + switch (FuseAttr->Mode & VIRTIO_FS_FUSE_MODE_TYPE_MASK) { + case VIRTIO_FS_FUSE_MODE_TYPE_DIR: + FileInfo->Attribute =3D EFI_FILE_DIRECTORY; + break; + case VIRTIO_FS_FUSE_MODE_TYPE_REG: + FileInfo->Attribute =3D 0; + break; + default: + // + // Other file types are not supported. + // + return EFI_UNSUPPORTED; + } + // + // Report the regular file or directory as read-only if all classes lack + // write permission. + // + if ((FuseAttr->Mode & (VIRTIO_FS_FUSE_MODE_PERM_WUSR | + VIRTIO_FS_FUSE_MODE_PERM_WGRP | + VIRTIO_FS_FUSE_MODE_PERM_WOTH)) =3D=3D 0) { + FileInfo->Attribute |=3D EFI_FILE_READ_ONLY; + } + + // + // A hard link count greater than 1 is not supported for regular files. + // + if ((FileInfo->Attribute & EFI_FILE_DIRECTORY) =3D=3D 0 && FuseAttr->Nli= nk > 1) { + return EFI_UNSUPPORTED; + } + + return EFI_SUCCESS; +} --=20 2.19.1.3.g30247aa5d201 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#69035): https://edk2.groups.io/g/devel/message/69035 Mute This Topic: https://groups.io/mt/79023450/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Tue May 7 07:56:31 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+69036+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+69036+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1608155880; cv=none; d=zohomail.com; s=zohoarc; b=JvKctEM6kHcjv3qFtaMC2eOmN0Hu/hLgQo2c6/5l1c1/s9Iwyd+6mGKyqVbSo3htIRoLwK0LpFTkDetV7I3+VMuIc9EfQ6RY+grWUSbtvADmPIUZol5gB0tyfKeTT7mWW6/4S97tCWm8vcTut1GpiLHAcps5kRHjKaIbQCfkYAk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608155880; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=BlqVyv9B3/y7a5COFm0U6yIbugh34QGLPy2xY6hc2qM=; b=jdyKaEenU2wmWvf7KMf2YLoLcDUAbjZgMoUGUGc8GikgTain4oM9QdN7gZDh7CY/2WSxEYoGLy+61EQV5wwvvOI+BAFPm6c3gg21OKwqgnfwEn1Yjk6ZgZQ/IDuAnaND2UOHPY1AEF+4ucuX0ozlJW7nSCajGB/IU6P90QdaPZM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+69036+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) header.from= Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1608155880651348.7244550714687; Wed, 16 Dec 2020 13:58:00 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id LktIYY1788612x9wHZq63ev1; Wed, 16 Dec 2020 13:58:00 -0800 X-Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.groups.io with SMTP id smtpd.web11.4163.1608155874754002091 for ; Wed, 16 Dec 2020 13:57:54 -0800 X-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-565-XP4Iw0RqOtiCkFJ1J10QLw-1; Wed, 16 Dec 2020 16:57:52 -0500 X-MC-Unique: XP4Iw0RqOtiCkFJ1J10QLw-1 X-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 87594801817; Wed, 16 Dec 2020 21:57:50 +0000 (UTC) X-Received: from lacos-laptop-7.usersys.redhat.com (ovpn-114-152.ams2.redhat.com [10.36.114.152]) by smtp.corp.redhat.com (Postfix) with ESMTP id 69F2E5D9C0; Wed, 16 Dec 2020 21:57:45 +0000 (UTC) From: "Laszlo Ersek" To: devel@edk2.groups.io, virtio-fs@redhat.com, lersek@redhat.com Cc: Ard Biesheuvel , Jordan Justen , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [edk2-devel] [edk2 PATCH 22/48] OvmfPkg/VirtioFsDxe: implement the wrapper function for FUSE_LOOKUP Date: Wed, 16 Dec 2020 22:10:59 +0100 Message-Id: <20201216211125.19496-23-lersek@redhat.com> In-Reply-To: <20201216211125.19496-1-lersek@redhat.com> References: <20201216211125.19496-1-lersek@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,lersek@redhat.com X-Gm-Message-State: K8adOoj9VglRCSCIxzC9oC97x1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1608155880; bh=BlqVyv9B3/y7a5COFm0U6yIbugh34QGLPy2xY6hc2qM=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=MAa/g0atn9RBW3s0rM/tTXuUaAoBwUVhTNDUFsHfC1dYg5j7Voli83CMgJ/wXQ9Wd5N CkfUn39qMJNpRFjE7Nz170XsLvopWQZir2hPAqVaGWh7j5vuY9KInsvdMUPkfXLp3KgGs 57zN6gQWbQgVevLdG5YcOoA5vz5QHVvFqQE= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" Add the VirtioFsFuseLookup() function, for sending the FUSE_LOOKUP command to the Virtio Filesystem device. Cc: Ard Biesheuvel Cc: Jordan Justen Cc: Philippe Mathieu-Daud=C3=A9 Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3097 Signed-off-by: Laszlo Ersek Acked-by: Ard Biesheuvel --- OvmfPkg/Include/IndustryStandard/VirtioFs.h | 6 + OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf | 1 + OvmfPkg/VirtioFsDxe/VirtioFsDxe.h | 9 ++ OvmfPkg/VirtioFsDxe/FuseLookup.c | 148 ++++++++++++++++++++ 4 files changed, 164 insertions(+) diff --git a/OvmfPkg/Include/IndustryStandard/VirtioFs.h b/OvmfPkg/Include/= IndustryStandard/VirtioFs.h index 5d1d990a2d83..8a07b3d2eb93 100644 --- a/OvmfPkg/Include/IndustryStandard/VirtioFs.h +++ b/OvmfPkg/Include/IndustryStandard/VirtioFs.h @@ -76,16 +76,21 @@ typedef struct { #define VIRTIO_FS_FUSE_MAJOR 7 #define VIRTIO_FS_FUSE_MINOR 31 =20 // // The inode number of the root directory. // #define VIRTIO_FS_FUSE_ROOT_DIR_NODE_ID 1 =20 +// +// Distinguished errno values. +// +#define VIRTIO_FS_FUSE_ERRNO_ENOENT (-2) + // // File mode bitmasks. // #define VIRTIO_FS_FUSE_MODE_TYPE_MASK 0170000u #define VIRTIO_FS_FUSE_MODE_TYPE_REG 0100000u #define VIRTIO_FS_FUSE_MODE_TYPE_DIR 0040000u #define VIRTIO_FS_FUSE_MODE_PERM_RWXU 0000700u #define VIRTIO_FS_FUSE_MODE_PERM_RUSR 0000400u @@ -102,16 +107,17 @@ typedef struct { // #define VIRTIO_FS_FUSE_OPEN_REQ_F_RDONLY 0 #define VIRTIO_FS_FUSE_OPEN_REQ_F_RDWR 2 =20 // // FUSE operation codes. // typedef enum { + VirtioFsFuseOpLookup =3D 1, VirtioFsFuseOpForget =3D 2, VirtioFsFuseOpMkDir =3D 9, VirtioFsFuseOpOpen =3D 14, VirtioFsFuseOpRelease =3D 18, VirtioFsFuseOpFsync =3D 20, VirtioFsFuseOpFlush =3D 25, VirtioFsFuseOpInit =3D 26, VirtioFsFuseOpOpenDir =3D 27, diff --git a/OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf b/OvmfPkg/VirtioFsDxe/Virt= ioFsDxe.inf index 7d7272188465..3552ece6b945 100644 --- a/OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf +++ b/OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf @@ -82,16 +82,17 @@ [Packages] OvmfPkg/OvmfPkg.dec =20 [Sources] DriverBinding.c FuseFlush.c FuseForget.c FuseFsync.c FuseInit.c + FuseLookup.c FuseMkDir.c FuseOpen.c FuseOpenDir.c FuseOpenOrCreate.c FuseRelease.c Helpers.c SimpleFsClose.c SimpleFsDelete.c diff --git a/OvmfPkg/VirtioFsDxe/VirtioFsDxe.h b/OvmfPkg/VirtioFsDxe/Virtio= FsDxe.h index 6cc5257bab40..b2e4adce098b 100644 --- a/OvmfPkg/VirtioFsDxe/VirtioFsDxe.h +++ b/OvmfPkg/VirtioFsDxe/VirtioFsDxe.h @@ -231,16 +231,25 @@ VirtioFsFuseAttrToEfiFileInfo ( IN VIRTIO_FS_FUSE_ATTRIBUTES_RESPONSE *FuseAttr, OUT EFI_FILE_INFO *FileInfo ); =20 // // Wrapper functions for FUSE commands (primitives). // =20 +EFI_STATUS +VirtioFsFuseLookup ( + IN OUT VIRTIO_FS *VirtioFs, + IN UINT64 DirNodeId, + IN CHAR8 *Name, + OUT UINT64 *NodeId, + OUT VIRTIO_FS_FUSE_ATTRIBUTES_RESPONSE *FuseAttr + ); + EFI_STATUS VirtioFsFuseForget ( IN OUT VIRTIO_FS *VirtioFs, IN UINT64 NodeId ); =20 EFI_STATUS VirtioFsFuseMkDir ( diff --git a/OvmfPkg/VirtioFsDxe/FuseLookup.c b/OvmfPkg/VirtioFsDxe/FuseLoo= kup.c new file mode 100644 index 000000000000..5c9a825e1725 --- /dev/null +++ b/OvmfPkg/VirtioFsDxe/FuseLookup.c @@ -0,0 +1,148 @@ +/** @file + FUSE_LOOKUP wrapper for the Virtio Filesystem device. + + Copyright (C) 2020, Red Hat, Inc. + + SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#include // AsciiStrSize() + +#include "VirtioFsDxe.h" + +/** + Send a FUSE_LOOKUP request to the Virtio Filesystem device, for resolvin= g a + filename to an inode. + + The function returns EFI_NOT_FOUND exclusively if the Virtio Filesystem + device explicitly responds with ENOENT -- "No such file or directory". + + The function may only be called after VirtioFsFuseInitSession() returns + successfully and before VirtioFsUninit() is called. + + @param[in,out] VirtioFs The Virtio Filesystem device to send the FUSE_L= OOKUP + request to. On output, the FUSE request counter + "VirtioFs->RequestId" will have been incremente= d. + + @param[in] DirNodeId The inode number of the directory in which Name + should be resolved to an inode. + + @param[in] Name The single-component filename to resolve in the + directory identified by DirNodeId. + + @param[out] NodeId The inode number which Name has been resolved t= o. + + @param[out] FuseAttr The VIRTIO_FS_FUSE_ATTRIBUTES_RESPONSE object + describing the properties of the resolved inode. + + @retval EFI_SUCCESS Filename to inode resolution successful. + + @retval EFI_NOT_FOUND The Virtio Filesystem device explicitly reported + ENOENT -- "No such file or directory". + + @return The "errno" value mapped to an EFI_STATUS code, i= f the + Virtio Filesystem device explicitly reported an e= rror + different from ENOENT. If said mapping resulted in + EFI_NOT_FOUND, it is remapped to EFI_DEVICE_ERROR. + + @return Error codes propagated from VirtioFsSgListsValida= te(), + VirtioFsFuseNewRequest(), VirtioFsSgListsSubmit(), + VirtioFsFuseCheckResponse(). EFI_NOT_FOUND is rem= apped + to EFI_DEVICE_ERROR. +**/ +EFI_STATUS +VirtioFsFuseLookup ( + IN OUT VIRTIO_FS *VirtioFs, + IN UINT64 DirNodeId, + IN CHAR8 *Name, + OUT UINT64 *NodeId, + OUT VIRTIO_FS_FUSE_ATTRIBUTES_RESPONSE *FuseAttr + ) +{ + VIRTIO_FS_FUSE_REQUEST CommonReq; + VIRTIO_FS_IO_VECTOR ReqIoVec[2]; + VIRTIO_FS_SCATTER_GATHER_LIST ReqSgList; + VIRTIO_FS_FUSE_RESPONSE CommonResp; + VIRTIO_FS_FUSE_NODE_RESPONSE NodeResp; + VIRTIO_FS_IO_VECTOR RespIoVec[3]; + VIRTIO_FS_SCATTER_GATHER_LIST RespSgList; + EFI_STATUS Status; + + // + // Set up the scatter-gather lists. + // + ReqIoVec[0].Buffer =3D &CommonReq; + ReqIoVec[0].Size =3D sizeof CommonReq; + ReqIoVec[1].Buffer =3D Name; + ReqIoVec[1].Size =3D AsciiStrSize (Name); + ReqSgList.IoVec =3D ReqIoVec; + ReqSgList.NumVec =3D ARRAY_SIZE (ReqIoVec); + + RespIoVec[0].Buffer =3D &CommonResp; + RespIoVec[0].Size =3D sizeof CommonResp; + RespIoVec[1].Buffer =3D &NodeResp; + RespIoVec[1].Size =3D sizeof NodeResp; + RespIoVec[2].Buffer =3D FuseAttr; + RespIoVec[2].Size =3D sizeof *FuseAttr; + RespSgList.IoVec =3D RespIoVec; + RespSgList.NumVec =3D ARRAY_SIZE (RespIoVec); + + // + // Validate the scatter-gather lists; calculate the total transfer sizes. + // + Status =3D VirtioFsSgListsValidate (VirtioFs, &ReqSgList, &RespSgList); + if (EFI_ERROR (Status)) { + goto Fail; + } + + // + // Populate the common request header. + // + Status =3D VirtioFsFuseNewRequest (VirtioFs, &CommonReq, ReqSgList.Total= Size, + VirtioFsFuseOpLookup, DirNodeId); + if (EFI_ERROR (Status)) { + goto Fail; + } + + // + // Submit the request. + // + Status =3D VirtioFsSgListsSubmit (VirtioFs, &ReqSgList, &RespSgList); + if (EFI_ERROR (Status)) { + goto Fail; + } + + // + // Verify the response (all response buffers are fixed size). + // + Status =3D VirtioFsFuseCheckResponse (&RespSgList, CommonReq.Unique, NUL= L); + if (EFI_ERROR (Status)) { + if (Status =3D=3D EFI_DEVICE_ERROR) { + DEBUG (( + ((CommonResp.Error =3D=3D VIRTIO_FS_FUSE_ERRNO_ENOENT) ? + DEBUG_VERBOSE : + DEBUG_ERROR), + "%a: Label=3D\"%s\" DirNodeId=3D%Lu Name=3D\"%a\" Errno=3D%d\n", + __FUNCTION__, + VirtioFs->Label, + DirNodeId, + Name, + CommonResp.Error + )); + if (CommonResp.Error =3D=3D VIRTIO_FS_FUSE_ERRNO_ENOENT) { + return EFI_NOT_FOUND; + } + Status =3D VirtioFsErrnoToEfiStatus (CommonResp.Error); + } + goto Fail; + } + + // + // Output the NodeId to which Name has been resolved to. + // + *NodeId =3D NodeResp.NodeId; + return EFI_SUCCESS; + +Fail: + return (Status =3D=3D EFI_NOT_FOUND) ? EFI_DEVICE_ERROR : Status; +} --=20 2.19.1.3.g30247aa5d201 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#69036): https://edk2.groups.io/g/devel/message/69036 Mute This Topic: https://groups.io/mt/79023490/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Tue May 7 07:56:31 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+69037+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+69037+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1608156007; cv=none; d=zohomail.com; s=zohoarc; b=QQki4l6j6faMlod0a0YWEnLAK8RntG3BblVN65C4rxwmSPflPaSwi4ucP7QWrc7Y3FAhwc8bYzo9EOKdc57uIHPDeLyPlD4vby1bPb7lyv0W9MC8NwWqypVFAM89OGDEBASvdJWYREflVU80vIZJ8EINE4pM46SPiOgZJMg+EeM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608156007; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=4dMJgdzUPG3C79dVeYeWxJnrJyg7uTS6o5dWLhwXv0c=; b=IWpdGpn31ANL2VJU9k/zIkn2nRTRkWiXKNPo8bVtQqjO45Yc/8IddcCbPr5XBucvPc+hxAphDT5xzqH3bYg3h/DN4iZHzxUwlpD8mV3gKWdFtL/fveWEKCSmD29q1vc9sP8f9bkwNP30ccuT6a/RjTNKPefSKnUzjYXONUP/R9E= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+69037+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) header.from= Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1608156007632190.2422454824458; Wed, 16 Dec 2020 14:00:07 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id ZCf9YY1788612xtWeDqV4mgA; Wed, 16 Dec 2020 14:00:06 -0800 X-Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.groups.io with SMTP id smtpd.web12.4308.1608156000834250013 for ; Wed, 16 Dec 2020 14:00:01 -0800 X-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-445-BXBfViN_MsCuPNZ9B4h-tA-1; Wed, 16 Dec 2020 16:59:57 -0500 X-MC-Unique: BXBfViN_MsCuPNZ9B4h-tA-1 X-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 80CFC801817; Wed, 16 Dec 2020 21:59:56 +0000 (UTC) X-Received: from lacos-laptop-7.usersys.redhat.com (ovpn-114-152.ams2.redhat.com [10.36.114.152]) by smtp.corp.redhat.com (Postfix) with ESMTP id EBB8C60C15; Wed, 16 Dec 2020 21:59:51 +0000 (UTC) From: "Laszlo Ersek" To: devel@edk2.groups.io, virtio-fs@redhat.com, lersek@redhat.com Cc: Ard Biesheuvel , Jordan Justen , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [edk2-devel] [edk2 PATCH 23/48] OvmfPkg/VirtioFsDxe: split canon. path into last parent + last component Date: Wed, 16 Dec 2020 22:11:00 +0100 Message-Id: <20201216211125.19496-24-lersek@redhat.com> In-Reply-To: <20201216211125.19496-1-lersek@redhat.com> References: <20201216211125.19496-1-lersek@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,lersek@redhat.com X-Gm-Message-State: 8tLr8O9HQegQE6ZBTz1rsQdhx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1608156006; bh=4dMJgdzUPG3C79dVeYeWxJnrJyg7uTS6o5dWLhwXv0c=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=dA0/eV2OhhMLaTTr5Nh1NmaQtqtVTo095Zarj4mlILOC5lXKs6jGP4ShuLoOSVe/xk6 syRQ1jZU4D/kR4kjOatFf0RBMs2W54Ri39J3EbUhAVx9gf7emEVFOFnpxBu/sflkH721B kSsVdOixApo9nmRm1TTf8VSLzdtwLQN3ijE= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" Given a canonical pathname (as defined by VirtioFsAppendPath()), different from "/", introduce a helper function for: - looking up the NodeId of the most specific parent directory, and - exposing the last component stand-alone (which is therefore a direct child of said parent directory). This splitting operation will be necessary in multiple subsequent patches. Cc: Ard Biesheuvel Cc: Jordan Justen Cc: Philippe Mathieu-Daud=C3=A9 Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3097 Signed-off-by: Laszlo Ersek Acked-by: Ard Biesheuvel --- OvmfPkg/VirtioFsDxe/VirtioFsDxe.h | 8 ++ OvmfPkg/VirtioFsDxe/Helpers.c | 131 ++++++++++++++++++++ 2 files changed, 139 insertions(+) diff --git a/OvmfPkg/VirtioFsDxe/VirtioFsDxe.h b/OvmfPkg/VirtioFsDxe/Virtio= FsDxe.h index b2e4adce098b..6ae5c36f7fd5 100644 --- a/OvmfPkg/VirtioFsDxe/VirtioFsDxe.h +++ b/OvmfPkg/VirtioFsDxe/VirtioFsDxe.h @@ -221,16 +221,24 @@ VirtioFsErrnoToEfiStatus ( EFI_STATUS VirtioFsAppendPath ( IN CHAR8 *LhsPath8, IN CHAR16 *RhsPath16, OUT CHAR8 **ResultPath8, OUT BOOLEAN *RootEscape ); =20 +EFI_STATUS +VirtioFsLookupMostSpecificParentDir ( + IN OUT VIRTIO_FS *VirtioFs, + IN OUT CHAR8 *Path, + OUT UINT64 *DirNodeId, + OUT CHAR8 **LastComponent + ); + EFI_STATUS VirtioFsFuseAttrToEfiFileInfo ( IN VIRTIO_FS_FUSE_ATTRIBUTES_RESPONSE *FuseAttr, OUT EFI_FILE_INFO *FileInfo ); =20 // // Wrapper functions for FUSE commands (primitives). diff --git a/OvmfPkg/VirtioFsDxe/Helpers.c b/OvmfPkg/VirtioFsDxe/Helpers.c index fa656bb535b8..6adc0341dee6 100644 --- a/OvmfPkg/VirtioFsDxe/Helpers.c +++ b/OvmfPkg/VirtioFsDxe/Helpers.c @@ -1586,16 +1586,147 @@ VirtioFsAppendPath ( FreePool (BufferToSanitize); } =20 FreeRhsPath8: FreePool (RhsPath8); return Status; } =20 +/** + For a given canonical pathname (as defined at VirtioFsAppendPath()), loo= k up + the NodeId of the most specific parent directory, plus output a pointer = to + the last pathname component (which is therefore a direct child of said p= arent + directory). + + The function may only be called after VirtioFsFuseInitSession() returns + successfully and before VirtioFsUninit() is called. + + @param[in,out] VirtioFs The Virtio Filesystem device to send FUSE_LOO= KUP + and FUSE_FORGET requests to. On output, the F= USE + request counter "VirtioFs->RequestId" will ha= ve + been incremented several times. + + @param[in,out] Path The canonical pathname (as defined in the + description of VirtioFsAppendPath()) to split. + Path is modified in-place temporarily; howeve= r, on + return (successful or otherwise), Path reassu= mes + its original contents. + + @param[out] DirNodeId The NodeId of the most specific parent direct= ory + identified by Path. The caller is responsible= for + sending a FUSE_FORGET request to the Virtio + Filesystem device for DirNodeId -- unless + DirNodeId equals VIRTIO_FS_FUSE_ROOT_DIR_NODE= _ID + --, when DirNodeId's use ends. + + @param[out] LastComponent A pointer into Path, pointing at the start of= the + last pathname component. + + @retval EFI_SUCCESS Splitting successful. + + @retval EFI_INVALID_PARAMETER Path is "/". + + @retval EFI_ACCESS_DENIED One of the components on Path before the = last + is not a directory. + + @return Error codes propagated from + VirtioFsFuseLookup() and + VirtioFsFuseAttrToEfiFileInfo(). +**/ +EFI_STATUS +VirtioFsLookupMostSpecificParentDir ( + IN OUT VIRTIO_FS *VirtioFs, + IN OUT CHAR8 *Path, + OUT UINT64 *DirNodeId, + OUT CHAR8 **LastComponent + ) +{ + UINT64 ParentDirNodeId; + CHAR8 *Slash; + EFI_STATUS Status; + UINT64 NextDirNodeId; + + if (AsciiStrCmp (Path, "/") =3D=3D 0) { + return EFI_INVALID_PARAMETER; + } + + ParentDirNodeId =3D VIRTIO_FS_FUSE_ROOT_DIR_NODE_ID; + Slash =3D Path; + for (;;) { + CHAR8 *NextSlash; + VIRTIO_FS_FUSE_ATTRIBUTES_RESPONSE FuseAttr; + EFI_FILE_INFO FileInfo; + + // + // Find the slash (if any) that terminates the next pathname component. + // + NextSlash =3D AsciiStrStr (Slash + 1, "/"); + if (NextSlash =3D=3D NULL) { + break; + } + + // + // Temporarily replace the found slash character with a NUL in-place, = for + // easy construction of the single-component filename that we need to = look + // up. + // + *NextSlash =3D '\0'; + Status =3D VirtioFsFuseLookup (VirtioFs, ParentDirNodeId, Slash + 1, + &NextDirNodeId, &FuseAttr); + *NextSlash =3D '/'; + + // + // We're done with the directory inode that was the basis for the look= up. + // + if (ParentDirNodeId !=3D VIRTIO_FS_FUSE_ROOT_DIR_NODE_ID) { + VirtioFsFuseForget (VirtioFs, ParentDirNodeId); + } + + // + // If we couldn't look up the next *non-final* pathname component, bai= l. + // + if (EFI_ERROR (Status)) { + return Status; + } + + // + // Lookup successful; now check if the next (non-final) component is a + // directory. If not, bail. + // + Status =3D VirtioFsFuseAttrToEfiFileInfo (&FuseAttr, &FileInfo); + if (EFI_ERROR (Status)) { + goto ForgetNextDirNodeId; + } + if ((FileInfo.Attribute & EFI_FILE_DIRECTORY) =3D=3D 0) { + Status =3D EFI_ACCESS_DENIED; + goto ForgetNextDirNodeId; + } + + // + // Advance. + // + ParentDirNodeId =3D NextDirNodeId; + Slash =3D NextSlash; + } + + // + // ParentDirNodeId corresponds to the last containing directory. The + // remaining single-component filename represents a direct child under t= hat + // directory. Said filename starts at (Slash + 1). + // + *DirNodeId =3D ParentDirNodeId; + *LastComponent =3D Slash + 1; + return EFI_SUCCESS; + +ForgetNextDirNodeId: + VirtioFsFuseForget (VirtioFs, NextDirNodeId); + return Status; +} + /** Convert select fields of a VIRTIO_FS_FUSE_ATTRIBUTES_RESPONSE object to corresponding fields in EFI_FILE_INFO. =20 @param[in] FuseAttr The VIRTIO_FS_FUSE_ATTRIBUTES_RESPONSE object to convert the relevant fields from. =20 @param[out] FileInfo The EFI_FILE_INFO structure to modify. Importantly= , the --=20 2.19.1.3.g30247aa5d201 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#69037): https://edk2.groups.io/g/devel/message/69037 Mute This Topic: https://groups.io/mt/79023525/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Tue May 7 07:56:31 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+69038+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+69038+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1608156133; cv=none; d=zohomail.com; s=zohoarc; b=bCRT1DtJ3ZzwLMi82sC+VX+WICHMlB+6KZ1SdzaM2DDDvc0U5OhqdRl/J/glDK4kemeFNd6EJDIMmMef5VrUxju1U87ni6W6fTqHQOPpJIYNTHWhbTHuvIsEbOHFP5Cw0tGTTwamt/hJh7ne1zM2x7BNR5JXzFbVbu0gHOQhJKQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608156133; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=9a7h+DHu20naklPbhZj1K4+V0Xn5vHn5wfezVKYg2kA=; b=ULSZRgvZGLe+7OnmzG/Eh+Y5wEMQMwd7+58ML3T2lVkc6cYfkuWwCDfz5dSha496/QI2QMVIrusUii0l3pnZkY1Z3wOrhp3S+pgefLfLqqfHzQApvvNTTB3GOcVLQCgtkTZ0yEwm8adBt7yAqKD4xGu95ZqH2Qz3gvMRplLeQCw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+69038+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) header.from= Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1608156133350510.94920925281383; Wed, 16 Dec 2020 14:02:13 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id 93S1YY1788612x0MSOoV764l; Wed, 16 Dec 2020 14:02:11 -0800 X-Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.groups.io with SMTP id smtpd.web09.4154.1608156126305328871 for ; Wed, 16 Dec 2020 14:02:06 -0800 X-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-549-jb_JhaGkMUWli4Cv6CVgJQ-1; Wed, 16 Dec 2020 17:02:03 -0500 X-MC-Unique: jb_JhaGkMUWli4Cv6CVgJQ-1 X-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 96E571005504; Wed, 16 Dec 2020 22:02:02 +0000 (UTC) X-Received: from lacos-laptop-7.usersys.redhat.com (ovpn-114-152.ams2.redhat.com [10.36.114.152]) by smtp.corp.redhat.com (Postfix) with ESMTP id C127B5D71B; Wed, 16 Dec 2020 22:01:57 +0000 (UTC) From: "Laszlo Ersek" To: devel@edk2.groups.io, virtio-fs@redhat.com, lersek@redhat.com Cc: Ard Biesheuvel , Jordan Justen , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [edk2-devel] [edk2 PATCH 24/48] OvmfPkg/VirtioFsDxe: add a shared wrapper for FUSE_UNLINK / FUSE_RMDIR Date: Wed, 16 Dec 2020 22:11:01 +0100 Message-Id: <20201216211125.19496-25-lersek@redhat.com> In-Reply-To: <20201216211125.19496-1-lersek@redhat.com> References: <20201216211125.19496-1-lersek@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,lersek@redhat.com X-Gm-Message-State: TyTSJwvEVl3QyWoSJYpYBCMzx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1608156131; bh=9a7h+DHu20naklPbhZj1K4+V0Xn5vHn5wfezVKYg2kA=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=HYgrYJeP0Mzk+znqso7dKWI6MuDdZZEMNqkumGevG4XKLAKTd9tUxDHNOm9vgA8/a47 43/k4ldCEk8BVRfTtg2ov4ZPndnIvdy6U1Lap0e63IQkZVU0UGjvm1dy+G3Xw+g0HsXr+ K7mQeWashzNA1Pl7tqTDaWJAMYoV9/i1EvM= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" The FUSE_UNLINK and FUSE_RMDIR commands only differ in the opcode. Add a common function for wrapping both. Cc: Ard Biesheuvel Cc: Jordan Justen Cc: Philippe Mathieu-Daud=C3=A9 Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3097 Signed-off-by: Laszlo Ersek Acked-by: Ard Biesheuvel --- OvmfPkg/Include/IndustryStandard/VirtioFs.h | 2 + OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf | 1 + OvmfPkg/VirtioFsDxe/VirtioFsDxe.h | 8 ++ OvmfPkg/VirtioFsDxe/FuseUnlink.c | 114 ++++++++++++++++++++ 4 files changed, 125 insertions(+) diff --git a/OvmfPkg/Include/IndustryStandard/VirtioFs.h b/OvmfPkg/Include/= IndustryStandard/VirtioFs.h index 8a07b3d2eb93..f49452830abc 100644 --- a/OvmfPkg/Include/IndustryStandard/VirtioFs.h +++ b/OvmfPkg/Include/IndustryStandard/VirtioFs.h @@ -110,16 +110,18 @@ typedef struct { =20 // // FUSE operation codes. // typedef enum { VirtioFsFuseOpLookup =3D 1, VirtioFsFuseOpForget =3D 2, VirtioFsFuseOpMkDir =3D 9, + VirtioFsFuseOpUnlink =3D 10, + VirtioFsFuseOpRmDir =3D 11, VirtioFsFuseOpOpen =3D 14, VirtioFsFuseOpRelease =3D 18, VirtioFsFuseOpFsync =3D 20, VirtioFsFuseOpFlush =3D 25, VirtioFsFuseOpInit =3D 26, VirtioFsFuseOpOpenDir =3D 27, VirtioFsFuseOpReleaseDir =3D 29, VirtioFsFuseOpFsyncDir =3D 30, diff --git a/OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf b/OvmfPkg/VirtioFsDxe/Virt= ioFsDxe.inf index 3552ece6b945..2332aa3ee551 100644 --- a/OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf +++ b/OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf @@ -88,16 +88,17 @@ [Sources] FuseFsync.c FuseInit.c FuseLookup.c FuseMkDir.c FuseOpen.c FuseOpenDir.c FuseOpenOrCreate.c FuseRelease.c + FuseUnlink.c Helpers.c SimpleFsClose.c SimpleFsDelete.c SimpleFsFlush.c SimpleFsGetInfo.c SimpleFsGetPosition.c SimpleFsOpen.c SimpleFsOpenVolume.c diff --git a/OvmfPkg/VirtioFsDxe/VirtioFsDxe.h b/OvmfPkg/VirtioFsDxe/Virtio= FsDxe.h index 6ae5c36f7fd5..0e4f2109eb02 100644 --- a/OvmfPkg/VirtioFsDxe/VirtioFsDxe.h +++ b/OvmfPkg/VirtioFsDxe/VirtioFsDxe.h @@ -262,16 +262,24 @@ VirtioFsFuseForget ( EFI_STATUS VirtioFsFuseMkDir ( IN OUT VIRTIO_FS *VirtioFs, IN UINT64 ParentNodeId, IN CHAR8 *Name, OUT UINT64 *NodeId ); =20 +EFI_STATUS +VirtioFsFuseRemoveFileOrDir ( + IN OUT VIRTIO_FS *VirtioFs, + IN UINT64 ParentNodeId, + IN CHAR8 *Name, + IN BOOLEAN IsDir + ); + EFI_STATUS VirtioFsFuseOpen ( IN OUT VIRTIO_FS *VirtioFs, IN UINT64 NodeId, IN BOOLEAN ReadWrite, OUT UINT64 *FuseHandle ); =20 diff --git a/OvmfPkg/VirtioFsDxe/FuseUnlink.c b/OvmfPkg/VirtioFsDxe/FuseUnl= ink.c new file mode 100644 index 000000000000..8f84edbe9431 --- /dev/null +++ b/OvmfPkg/VirtioFsDxe/FuseUnlink.c @@ -0,0 +1,114 @@ +/** @file + FUSE_UNLINK / FUSE_RMDIR wrapper for the Virtio Filesystem device. + + Copyright (C) 2020, Red Hat, Inc. + + SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#include // AsciiStrSize() + +#include "VirtioFsDxe.h" + +/** + Remove a regular file or a directory, by sending the FUSE_UNLINK or + FUSE_RMDIR request to the Virtio Filesystem device. + + The function may only be called after VirtioFsFuseInitSession() returns + successfully and before VirtioFsUninit() is called. + + @param[in,out] VirtioFs The Virtio Filesystem device to send the FUSE_U= NLINK + / FUSE_RMDIR request to. On output, the FUSE re= quest + counter "VirtioFs->RequestId" will have been + incremented. + + @param[in] ParentNodeId The inode number of the directory in which Name + should be removed. + + @param[in] Name The single-component filename to remove in the + directory identified by ParentNodeId. + + @param[in] IsDir TRUE if Name refers to a directory, FALSE other= wise. + + @retval EFI_SUCCESS The file or directory has been removed. + + @return The "errno" value mapped to an EFI_STATUS code, if = the + Virtio Filesystem device explicitly reported an err= or. + + @return Error codes propagated from VirtioFsSgListsValidate= (), + VirtioFsFuseNewRequest(), VirtioFsSgListsSubmit(), + VirtioFsFuseCheckResponse(). +**/ +EFI_STATUS +VirtioFsFuseRemoveFileOrDir ( + IN OUT VIRTIO_FS *VirtioFs, + IN UINT64 ParentNodeId, + IN CHAR8 *Name, + IN BOOLEAN IsDir + ) +{ + VIRTIO_FS_FUSE_REQUEST CommonReq; + VIRTIO_FS_IO_VECTOR ReqIoVec[2]; + VIRTIO_FS_SCATTER_GATHER_LIST ReqSgList; + VIRTIO_FS_FUSE_RESPONSE CommonResp; + VIRTIO_FS_IO_VECTOR RespIoVec[1]; + VIRTIO_FS_SCATTER_GATHER_LIST RespSgList; + EFI_STATUS Status; + + // + // Set up the scatter-gather lists. + // + ReqIoVec[0].Buffer =3D &CommonReq; + ReqIoVec[0].Size =3D sizeof CommonReq; + ReqIoVec[1].Buffer =3D Name; + ReqIoVec[1].Size =3D AsciiStrSize (Name); + ReqSgList.IoVec =3D ReqIoVec; + ReqSgList.NumVec =3D ARRAY_SIZE (ReqIoVec); + + RespIoVec[0].Buffer =3D &CommonResp; + RespIoVec[0].Size =3D sizeof CommonResp; + RespSgList.IoVec =3D RespIoVec; + RespSgList.NumVec =3D ARRAY_SIZE (RespIoVec); + + // + // Validate the scatter-gather lists; calculate the total transfer sizes. + // + Status =3D VirtioFsSgListsValidate (VirtioFs, &ReqSgList, &RespSgList); + if (EFI_ERROR (Status)) { + return Status; + } + + // + // Populate the common request header. + // + Status =3D VirtioFsFuseNewRequest ( + VirtioFs, + &CommonReq, + ReqSgList.TotalSize, + IsDir ? VirtioFsFuseOpRmDir : VirtioFsFuseOpUnlink, + ParentNodeId + ); + if (EFI_ERROR (Status)) { + return Status; + } + + // + // Submit the request. + // + Status =3D VirtioFsSgListsSubmit (VirtioFs, &ReqSgList, &RespSgList); + if (EFI_ERROR (Status)) { + return Status; + } + + // + // Verify the response (all response buffers are fixed size). + // + Status =3D VirtioFsFuseCheckResponse (&RespSgList, CommonReq.Unique, NUL= L); + if (Status =3D=3D EFI_DEVICE_ERROR) { + DEBUG ((DEBUG_ERROR, "%a: Label=3D\"%s\" ParentNodeId=3D%Lu Name=3D\"%= a\" " + "IsDir=3D%d Errno=3D%d\n", __FUNCTION__, VirtioFs->Label, ParentNode= Id, Name, + IsDir, CommonResp.Error)); + Status =3D VirtioFsErrnoToEfiStatus (CommonResp.Error); + } + return Status; +} --=20 2.19.1.3.g30247aa5d201 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#69038): https://edk2.groups.io/g/devel/message/69038 Mute This Topic: https://groups.io/mt/79023582/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Tue May 7 07:56:31 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+69039+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+69039+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1608156262; cv=none; d=zohomail.com; s=zohoarc; b=APehprYTzxuCUP9Har3UV6QMSXEoQkdGFueZECD3vR8djIDYtyRiIU6W1Sln5oX63Gcp/sGJD9AJOU+WN+iuPCXBfGIYeoTAPhuejD3H0jtQYl4Wo3Z+LQPLDgxeMwCNs+dTf0P4FVEtLyfYI15BV+QTS6fLFe/yrEDbMp0Z1xk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608156262; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=dFnYQEODUUEmXrtPmXpiRQQ1HgHQ/4alxycrcJVPG6I=; b=OwcrLJpAUAnGbFTVLjwnfx20qkZV25Xgrw7Y9F2oSeUlUoi6Zenb3xl3rODm1JjU9ljZPv03JJjVC43i4FLiyIi//qCshnL8MbTYthNbnWzXJSc46d0j7+pWiZ+0YNok+9siFw+Nivv46FuXF19d0DkXnNzDcP1ATsCtIM34MbE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+69039+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) header.from= Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 160815626241510.456129784611107; Wed, 16 Dec 2020 14:04:22 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id kd0rYY1788612x5GtAQ9MQSW; Wed, 16 Dec 2020 14:04:21 -0800 X-Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.groups.io with SMTP id smtpd.web09.4181.1608156255632202800 for ; Wed, 16 Dec 2020 14:04:15 -0800 X-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-532-GAuqssMqOoihV3Gh8yUUBQ-1; Wed, 16 Dec 2020 17:04:09 -0500 X-MC-Unique: GAuqssMqOoihV3Gh8yUUBQ-1 X-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 A134C107ACE8; Wed, 16 Dec 2020 22:04:08 +0000 (UTC) X-Received: from lacos-laptop-7.usersys.redhat.com (ovpn-114-152.ams2.redhat.com [10.36.114.152]) by smtp.corp.redhat.com (Postfix) with ESMTP id C663819CAC; Wed, 16 Dec 2020 22:04:03 +0000 (UTC) From: "Laszlo Ersek" To: devel@edk2.groups.io, virtio-fs@redhat.com, lersek@redhat.com Cc: Ard Biesheuvel , Jordan Justen , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [edk2-devel] [edk2 PATCH 25/48] OvmfPkg/VirtioFsDxe: implement the wrapper function for FUSE_GETATTR Date: Wed, 16 Dec 2020 22:11:02 +0100 Message-Id: <20201216211125.19496-26-lersek@redhat.com> In-Reply-To: <20201216211125.19496-1-lersek@redhat.com> References: <20201216211125.19496-1-lersek@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,lersek@redhat.com X-Gm-Message-State: efGnEoaDw1pL9j9nD1IgMmvfx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1608156261; bh=dFnYQEODUUEmXrtPmXpiRQQ1HgHQ/4alxycrcJVPG6I=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=kGgbPEEZIpZLDn3aF5SMyX63x84liCO3lCDj3j2UP0Z5WXOUOSJXNFbJ87X7iPsjaZR qb7oHd92J3pXbmgbhcU3tCvSfQK5R9VoAlqqeLYReYtCHXp/g9sXU7GAxO14IgpTVUmfz mlVCCNcmQWz0I3HGraptNwu0+ndXo+kuA7Y= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" Add the VirtioFsFuseGetAttr() function, for sending the FUSE_GETATTR command to the Virtio Filesystem device. Cc: Ard Biesheuvel Cc: Jordan Justen Cc: Philippe Mathieu-Daud=C3=A9 Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3097 Signed-off-by: Laszlo Ersek Acked-by: Ard Biesheuvel --- OvmfPkg/Include/IndustryStandard/VirtioFs.h | 16 +++ OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf | 1 + OvmfPkg/VirtioFsDxe/VirtioFsDxe.h | 7 ++ OvmfPkg/VirtioFsDxe/FuseGetAttr.c | 116 ++++++++++++++++++++ 4 files changed, 140 insertions(+) diff --git a/OvmfPkg/Include/IndustryStandard/VirtioFs.h b/OvmfPkg/Include/= IndustryStandard/VirtioFs.h index f49452830abc..efcf57941c59 100644 --- a/OvmfPkg/Include/IndustryStandard/VirtioFs.h +++ b/OvmfPkg/Include/IndustryStandard/VirtioFs.h @@ -109,16 +109,17 @@ typedef struct { #define VIRTIO_FS_FUSE_OPEN_REQ_F_RDWR 2 =20 // // FUSE operation codes. // typedef enum { VirtioFsFuseOpLookup =3D 1, VirtioFsFuseOpForget =3D 2, + VirtioFsFuseOpGetAttr =3D 3, VirtioFsFuseOpMkDir =3D 9, VirtioFsFuseOpUnlink =3D 10, VirtioFsFuseOpRmDir =3D 11, VirtioFsFuseOpOpen =3D 14, VirtioFsFuseOpRelease =3D 18, VirtioFsFuseOpFsync =3D 20, VirtioFsFuseOpFlush =3D 25, VirtioFsFuseOpInit =3D 26, @@ -190,16 +191,31 @@ typedef struct { =20 // // Header for VirtioFsFuseOpForget. // typedef struct { UINT64 NumberOfLookups; } VIRTIO_FS_FUSE_FORGET_REQUEST; =20 +// +// Headers for VirtioFsFuseOpGetAttr. +// +typedef struct { + UINT32 GetAttrFlags; + UINT32 Dummy; + UINT64 FileHandle; +} VIRTIO_FS_FUSE_GETATTR_REQUEST; + +typedef struct { + UINT64 AttrValid; + UINT32 AttrValidNsec; + UINT32 Dummy; +} VIRTIO_FS_FUSE_GETATTR_RESPONSE; + // // Header for VirtioFsFuseOpMkDir. // typedef struct { UINT32 Mode; UINT32 Umask; } VIRTIO_FS_FUSE_MKDIR_REQUEST; =20 diff --git a/OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf b/OvmfPkg/VirtioFsDxe/Virt= ioFsDxe.inf index 2332aa3ee551..233c0c5c0f9a 100644 --- a/OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf +++ b/OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf @@ -81,16 +81,17 @@ [Packages] MdePkg/MdePkg.dec OvmfPkg/OvmfPkg.dec =20 [Sources] DriverBinding.c FuseFlush.c FuseForget.c FuseFsync.c + FuseGetAttr.c FuseInit.c FuseLookup.c FuseMkDir.c FuseOpen.c FuseOpenDir.c FuseOpenOrCreate.c FuseRelease.c FuseUnlink.c diff --git a/OvmfPkg/VirtioFsDxe/VirtioFsDxe.h b/OvmfPkg/VirtioFsDxe/Virtio= FsDxe.h index 0e4f2109eb02..3bf64c0146fa 100644 --- a/OvmfPkg/VirtioFsDxe/VirtioFsDxe.h +++ b/OvmfPkg/VirtioFsDxe/VirtioFsDxe.h @@ -254,16 +254,23 @@ VirtioFsFuseLookup ( ); =20 EFI_STATUS VirtioFsFuseForget ( IN OUT VIRTIO_FS *VirtioFs, IN UINT64 NodeId ); =20 +EFI_STATUS +VirtioFsFuseGetAttr ( + IN OUT VIRTIO_FS *VirtioFs, + IN UINT64 NodeId, + OUT VIRTIO_FS_FUSE_ATTRIBUTES_RESPONSE *FuseAttr + ); + EFI_STATUS VirtioFsFuseMkDir ( IN OUT VIRTIO_FS *VirtioFs, IN UINT64 ParentNodeId, IN CHAR8 *Name, OUT UINT64 *NodeId ); =20 diff --git a/OvmfPkg/VirtioFsDxe/FuseGetAttr.c b/OvmfPkg/VirtioFsDxe/FuseGe= tAttr.c new file mode 100644 index 000000000000..29d8ec8190e1 --- /dev/null +++ b/OvmfPkg/VirtioFsDxe/FuseGetAttr.c @@ -0,0 +1,116 @@ +/** @file + FUSE_GETATTR wrapper for the Virtio Filesystem device. + + Copyright (C) 2020, Red Hat, Inc. + + SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#include "VirtioFsDxe.h" + +/** + Send a FUSE_GETATTR request to the Virtio Filesystem device, for fetchin= g the + attributes of an inode. + + The function may only be called after VirtioFsFuseInitSession() returns + successfully and before VirtioFsUninit() is called. + + @param[in,out] VirtioFs The Virtio Filesystem device to send the + FUSE_GETATTR request to. On output, the FUSE re= quest + counter "VirtioFs->RequestId" will have been + incremented. + + @param[in] NodeId The inode number for which the attributes shoul= d be + retrieved. + + @param[out] FuseAttr The VIRTIO_FS_FUSE_ATTRIBUTES_RESPONSE object + describing the properties of the inode. + + @retval EFI_SUCCESS FuseAttr has been filled in. + + @return The "errno" value mapped to an EFI_STATUS code, if = the + Virtio Filesystem device explicitly reported an err= or. + + @return Error codes propagated from VirtioFsSgListsValidate= (), + VirtioFsFuseNewRequest(), VirtioFsSgListsSubmit(), + VirtioFsFuseCheckResponse(). +**/ +EFI_STATUS +VirtioFsFuseGetAttr ( + IN OUT VIRTIO_FS *VirtioFs, + IN UINT64 NodeId, + OUT VIRTIO_FS_FUSE_ATTRIBUTES_RESPONSE *FuseAttr + ) +{ + VIRTIO_FS_FUSE_REQUEST CommonReq; + VIRTIO_FS_FUSE_GETATTR_REQUEST GetAttrReq; + VIRTIO_FS_IO_VECTOR ReqIoVec[2]; + VIRTIO_FS_SCATTER_GATHER_LIST ReqSgList; + VIRTIO_FS_FUSE_RESPONSE CommonResp; + VIRTIO_FS_FUSE_GETATTR_RESPONSE GetAttrResp; + VIRTIO_FS_IO_VECTOR RespIoVec[3]; + VIRTIO_FS_SCATTER_GATHER_LIST RespSgList; + EFI_STATUS Status; + + // + // Set up the scatter-gather lists. + // + ReqIoVec[0].Buffer =3D &CommonReq; + ReqIoVec[0].Size =3D sizeof CommonReq; + ReqIoVec[1].Buffer =3D &GetAttrReq; + ReqIoVec[1].Size =3D sizeof GetAttrReq; + ReqSgList.IoVec =3D ReqIoVec; + ReqSgList.NumVec =3D ARRAY_SIZE (ReqIoVec); + + RespIoVec[0].Buffer =3D &CommonResp; + RespIoVec[0].Size =3D sizeof CommonResp; + RespIoVec[1].Buffer =3D &GetAttrResp; + RespIoVec[1].Size =3D sizeof GetAttrResp; + RespIoVec[2].Buffer =3D FuseAttr; + RespIoVec[2].Size =3D sizeof *FuseAttr; + RespSgList.IoVec =3D RespIoVec; + RespSgList.NumVec =3D ARRAY_SIZE (RespIoVec); + + // + // Validate the scatter-gather lists; calculate the total transfer sizes. + // + Status =3D VirtioFsSgListsValidate (VirtioFs, &ReqSgList, &RespSgList); + if (EFI_ERROR (Status)) { + return Status; + } + + // + // Populate the common request header. + // + Status =3D VirtioFsFuseNewRequest (VirtioFs, &CommonReq, ReqSgList.Total= Size, + VirtioFsFuseOpGetAttr, NodeId); + if (EFI_ERROR (Status)) { + return Status; + } + + // + // Populate the FUSE_GETATTR-specific fields. + // + GetAttrReq.GetAttrFlags =3D 0; + GetAttrReq.Dummy =3D 0; + GetAttrReq.FileHandle =3D 0; + + // + // Submit the request. + // + Status =3D VirtioFsSgListsSubmit (VirtioFs, &ReqSgList, &RespSgList); + if (EFI_ERROR (Status)) { + return Status; + } + + // + // Verify the response (all response buffers are fixed size). + // + Status =3D VirtioFsFuseCheckResponse (&RespSgList, CommonReq.Unique, NUL= L); + if (Status =3D=3D EFI_DEVICE_ERROR) { + DEBUG ((DEBUG_ERROR, "%a: Label=3D\"%s\" NodeId=3D%Lu Errno=3D%d\n", + __FUNCTION__, VirtioFs->Label, NodeId, CommonResp.Error)); + Status =3D VirtioFsErrnoToEfiStatus (CommonResp.Error); + } + return Status; +} --=20 2.19.1.3.g30247aa5d201 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#69039): https://edk2.groups.io/g/devel/message/69039 Mute This Topic: https://groups.io/mt/79023626/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Tue May 7 07:56:31 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+69040+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+69040+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1608156385; cv=none; d=zohomail.com; s=zohoarc; b=fYFtKtz9irCjfQiGdNknrzIVJc2Rb1g0pIOgtJZXHhIie2xN2axu95Ztv0MwGBkF7PdMSFsJJ0ve0SV9t1rWS7DQgwuaoOX/FXHgqexvU+HcGIOSQ7eIRtD1fQpBuG3mYzWkKu6wX+Lbk8VyIZVz1upslfZYi4JwNqq0PEWxtbQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608156385; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=GLCtgAi1YuOWdfd3zDmd+uryd1zokjRDdDO2Stf3yUo=; b=CqcNu5GBw4k/T5Gxm997kl/zciMBlEVugO8kcCI7XyGO/JAZYpnnv87yJa1mO6uk90x4ZmRpDPEjkSDiw0SBdwAA4wHXatOZiKN1Fg6EKIWWr+o/J+11MT56kZ79D1RyTIRuiovM7j73V1hR1hcJLEoDOzJMSqAot7h07hHM7lU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+69040+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) header.from= Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1608156385155514.219983245091; Wed, 16 Dec 2020 14:06:25 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id g6SZYY1788612xpJSSxaDz2l; Wed, 16 Dec 2020 14:06:24 -0800 X-Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.groups.io with SMTP id smtpd.web08.4374.1608156383810038864 for ; Wed, 16 Dec 2020 14:06:24 -0800 X-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-299-5Wt_bqQ1OOuHdFqxa_rHsQ-1; Wed, 16 Dec 2020 17:06:16 -0500 X-MC-Unique: 5Wt_bqQ1OOuHdFqxa_rHsQ-1 X-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 00E9C800D53; Wed, 16 Dec 2020 22:06:15 +0000 (UTC) X-Received: from lacos-laptop-7.usersys.redhat.com (ovpn-114-152.ams2.redhat.com [10.36.114.152]) by smtp.corp.redhat.com (Postfix) with ESMTP id 100AB5D9C0; Wed, 16 Dec 2020 22:06:09 +0000 (UTC) From: "Laszlo Ersek" To: devel@edk2.groups.io, virtio-fs@redhat.com, lersek@redhat.com Cc: Ard Biesheuvel , Jordan Justen , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [edk2-devel] [edk2 PATCH 26/48] OvmfPkg/VirtioFsDxe: implement EFI_FILE_PROTOCOL.Open() Date: Wed, 16 Dec 2020 22:11:03 +0100 Message-Id: <20201216211125.19496-27-lersek@redhat.com> In-Reply-To: <20201216211125.19496-1-lersek@redhat.com> References: <20201216211125.19496-1-lersek@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,lersek@redhat.com X-Gm-Message-State: 1wc0nvl3M2A6fYkM7kUBZXA8x1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1608156384; bh=GLCtgAi1YuOWdfd3zDmd+uryd1zokjRDdDO2Stf3yUo=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=QFGfq0TUNQnwHj+LQky4wIpNq6IBx50ozLOsH/EzcbM5ZTc8Q5oB14Xj5/kzvet/Zgr S/6GtuMtArTr8QbnoxzC2k1HLkqcpmYdMbCAgcbJ6Nf7HtVmVlAKPbxqEENLmOz2NgTJ8 aX1QngrkHIM7g+vb30p7PenAPOmrUcZxVbk= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" Using the functions introduced previously, we can now implement VirtioFsSimpleFileOpen(). This lets the "MKDIR" command to work in the UEFI shell, for example. Cc: Ard Biesheuvel Cc: Jordan Justen Cc: Philippe Mathieu-Daud=C3=A9 Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3097 Signed-off-by: Laszlo Ersek Acked-by: Ard Biesheuvel --- OvmfPkg/VirtioFsDxe/SimpleFsOpen.c | 480 +++++++++++++++++++- 1 file changed, 479 insertions(+), 1 deletion(-) diff --git a/OvmfPkg/VirtioFsDxe/SimpleFsOpen.c b/OvmfPkg/VirtioFsDxe/Simpl= eFsOpen.c index f0e249184079..2649c796ac97 100644 --- a/OvmfPkg/VirtioFsDxe/SimpleFsOpen.c +++ b/OvmfPkg/VirtioFsDxe/SimpleFsOpen.c @@ -1,22 +1,500 @@ /** @file EFI_FILE_PROTOCOL.Open() member function for the Virtio Filesystem drive= r. =20 Copyright (C) 2020, Red Hat, Inc. =20 SPDX-License-Identifier: BSD-2-Clause-Patent **/ =20 +#include // AsciiStrCmp() +#include // AllocatePool() + #include "VirtioFsDxe.h" =20 +/** + Open the root directory, possibly for writing. + + @param[in,out] VirtioFs The Virtio Filesystem device whose root direc= tory + should be opened. + + @param[out] NewHandle The new EFI_FILE_PROTOCOL instance through wh= ich + the root directory can be accessed. + + @param[in] OpenForWriting TRUE if the root directory should be opened f= or + read-write access. FALSE if the root directory + should be opened for read-only access. Openin= g the + root directory for read-write access is usefu= l for + calling EFI_FILE_PROTOCOL.Flush() or + EFI_FILE_PROTOCOL.SetInfo() later, for syncin= g or + touching the root directory, respectively. + + @retval EFI_SUCCESS The root directory has been opened successful= ly. + + @retval EFI_ACCESS_DENIED OpenForWriting is TRUE, but the root director= y is + marked as read-only. + + @return Error codes propagated from underlying functi= ons. +**/ +STATIC +EFI_STATUS +OpenRootDirectory ( + IN OUT VIRTIO_FS *VirtioFs, + OUT EFI_FILE_PROTOCOL **NewHandle, + IN BOOLEAN OpenForWriting + ) +{ + EFI_STATUS Status; + VIRTIO_FS_FILE *NewVirtioFsFile; + + // + // VirtioFsOpenVolume() opens the root directory for read-only access. I= f the + // current request is to open the root directory for read-write access, = so + // that EFI_FILE_PROTOCOL.Flush() or EFI_FILE_PROTOCOL.SetInfo()+timesta= mps + // can be used on the root directory later, then we have to check for wr= ite + // permission first. + // + if (OpenForWriting) { + VIRTIO_FS_FUSE_ATTRIBUTES_RESPONSE FuseAttr; + EFI_FILE_INFO FileInfo; + + Status =3D VirtioFsFuseGetAttr (VirtioFs, VIRTIO_FS_FUSE_ROOT_DIR_NODE= _ID, + &FuseAttr); + if (EFI_ERROR (Status)) { + return Status; + } + Status =3D VirtioFsFuseAttrToEfiFileInfo (&FuseAttr, &FileInfo); + if (EFI_ERROR (Status)) { + return Status; + } + if ((FileInfo.Attribute & EFI_FILE_READ_ONLY) !=3D 0) { + return EFI_ACCESS_DENIED; + } + } + + Status =3D VirtioFsOpenVolume (&VirtioFs->SimpleFs, NewHandle); + if (EFI_ERROR (Status)) { + return Status; + } + + NewVirtioFsFile =3D VIRTIO_FS_FILE_FROM_SIMPLE_FILE (*NewHandle); + NewVirtioFsFile->IsOpenForWriting =3D OpenForWriting; + return EFI_SUCCESS; +} + +/** + Open an existent regular file or non-root directory. + + @param[in,out] VirtioFs The Virtio Filesystem device on which the + regular file or directory should be opened. + + @param[in] DirNodeId The inode number of the immediate parent + directory of the regular file or directory = to + open. + + @param[in] Name The single-component filename of the regular + file or directory to open, under the immedi= ate + parent directory identified by DirNodeId. + + @param[in] OpenForWriting TRUE if the regular file or directory shoul= d be + opened for read-write access. FALSE if the + regular file or directory should be opened = for + read-only access. Opening a directory for + read-write access is useful for deleting, + renaming, syncing or touching the directory + later. + + @param[out] NodeId The inode number of the regular file or + directory, returned by the Virtio Filesystem + device. + + @param[out] FuseHandle The open handle to the regular file or + directory, returned by the Virtio Filesystem + device. + + @param[out] NodeIsDirectory Set to TRUE on output if Name was found to = refer + to a directory. Set to FALSE if Name was fo= und + to refer to a regular file. + + @retval EFI_SUCCESS The regular file or directory has been looked= up + and opened successfully. + + @retval EFI_ACCESS_DENIED OpenForWriting is TRUE, but the regular file = or + directory is marked read-only. + + @retval EFI_NOT_FOUND A directory entry called Name was not found i= n the + directory identified by DirNodeId. (EFI_NOT_F= OUND + is not returned for any other condition.) + + @return Errors propagated from underlying functions. = If + the error code to propagate were EFI_NOT_FOUN= D, it + is remapped to EFI_DEVICE_ERROR. +**/ +STATIC +EFI_STATUS +OpenExistentFileOrDirectory ( + IN OUT VIRTIO_FS *VirtioFs, + IN UINT64 DirNodeId, + IN CHAR8 *Name, + IN BOOLEAN OpenForWriting, + OUT UINT64 *NodeId, + OUT UINT64 *FuseHandle, + OUT BOOLEAN *NodeIsDirectory + ) +{ + EFI_STATUS Status; + UINT64 ResolvedNodeId; + VIRTIO_FS_FUSE_ATTRIBUTES_RESPONSE FuseAttr; + EFI_FILE_INFO FileInfo; + BOOLEAN IsDirectory; + UINT64 NewFuseHandle; + + Status =3D VirtioFsFuseLookup (VirtioFs, DirNodeId, Name, &ResolvedNodeI= d, + &FuseAttr); + if (EFI_ERROR (Status)) { + return Status; + } + Status =3D VirtioFsFuseAttrToEfiFileInfo (&FuseAttr, &FileInfo); + if (EFI_ERROR (Status)) { + goto ForgetResolvedNodeId; + } + + if (OpenForWriting && (FileInfo.Attribute & EFI_FILE_READ_ONLY) !=3D 0) { + Status =3D EFI_ACCESS_DENIED; + goto ForgetResolvedNodeId; + } + + IsDirectory =3D (BOOLEAN)((FileInfo.Attribute & EFI_FILE_DIRECTORY) !=3D= 0); + if (IsDirectory) { + // + // If OpenForWriting is TRUE here, that's not passed to + // VirtioFsFuseOpenDir(); it does not affect the FUSE_OPENDIR request = we + // send. OpenForWriting=3DTRUE will only permit attempts to delete, re= name, + // flush (sync), and touch the directory. + // + Status =3D VirtioFsFuseOpenDir (VirtioFs, ResolvedNodeId, &NewFuseHand= le); + } else { + Status =3D VirtioFsFuseOpen (VirtioFs, ResolvedNodeId, OpenForWriting, + &NewFuseHandle); + } + if (EFI_ERROR (Status)) { + goto ForgetResolvedNodeId; + } + + *NodeId =3D ResolvedNodeId; + *FuseHandle =3D NewFuseHandle; + *NodeIsDirectory =3D IsDirectory; + return EFI_SUCCESS; + +ForgetResolvedNodeId: + VirtioFsFuseForget (VirtioFs, ResolvedNodeId); + return (Status =3D=3D EFI_NOT_FOUND) ? EFI_DEVICE_ERROR : Status; +} + +/** + Create a directory. + + @param[in,out] VirtioFs The Virtio Filesystem device on which the direc= tory + should be created. + + @param[in] DirNodeId The inode number of the immediate parent direct= ory + of the directory to create. + + @param[in] Name The single-component filename of the directory = to + create, under the immediate parent directory + identified by DirNodeId. + + @param[out] NodeId The inode number of the directory created, retu= rned + by the Virtio Filesystem device. + + @param[out] FuseHandle The open handle to the directory created, retur= ned + by the Virtio Filesystem device. + + @retval EFI_SUCCESS The directory has been created successfully. + + @return Errors propagated from underlying functions. +**/ +STATIC +EFI_STATUS +CreateDirectory ( + IN OUT VIRTIO_FS *VirtioFs, + IN UINT64 DirNodeId, + IN CHAR8 *Name, + OUT UINT64 *NodeId, + OUT UINT64 *FuseHandle + ) +{ + EFI_STATUS Status; + UINT64 NewChildDirNodeId; + UINT64 NewFuseHandle; + + Status =3D VirtioFsFuseMkDir (VirtioFs, DirNodeId, Name, &NewChildDirNod= eId); + if (EFI_ERROR (Status)) { + return Status; + } + + Status =3D VirtioFsFuseOpenDir (VirtioFs, NewChildDirNodeId, &NewFuseHan= dle); + if (EFI_ERROR (Status)) { + goto RemoveNewChildDir; + } + + *NodeId =3D NewChildDirNodeId; + *FuseHandle =3D NewFuseHandle; + return EFI_SUCCESS; + +RemoveNewChildDir: + VirtioFsFuseRemoveFileOrDir (VirtioFs, DirNodeId, Name, TRUE /* IsDir */= ); + VirtioFsFuseForget (VirtioFs, NewChildDirNodeId); + return Status; +} + +/** + Create a regular file. + + @param[in,out] VirtioFs The Virtio Filesystem device on which the regul= ar + file should be created. + + @param[in] DirNodeId The inode number of the immediate parent direct= ory + of the regular file to create. + + @param[in] Name The single-component filename of the regular fi= le to + create, under the immediate parent directory + identified by DirNodeId. + + @param[out] NodeId The inode number of the regular file created, + returned by the Virtio Filesystem device. + + @param[out] FuseHandle The open handle to the regular file created, + returned by the Virtio Filesystem device. + + @retval EFI_SUCCESS The regular file has been created successfully. + + @return Errors propagated from underlying functions. +**/ +STATIC +EFI_STATUS +CreateRegularFile ( + IN OUT VIRTIO_FS *VirtioFs, + IN UINT64 DirNodeId, + IN CHAR8 *Name, + OUT UINT64 *NodeId, + OUT UINT64 *FuseHandle + ) +{ + return VirtioFsFuseOpenOrCreate (VirtioFs, DirNodeId, Name, NodeId, + FuseHandle); +} + EFI_STATUS EFIAPI VirtioFsSimpleFileOpen ( IN EFI_FILE_PROTOCOL *This, OUT EFI_FILE_PROTOCOL **NewHandle, IN CHAR16 *FileName, IN UINT64 OpenMode, IN UINT64 Attributes ) { - return EFI_NO_MEDIA; + VIRTIO_FS_FILE *VirtioFsFile; + VIRTIO_FS *VirtioFs; + BOOLEAN OpenForWriting; + BOOLEAN PermitCreation; + BOOLEAN CreateDirectoryIfCreating; + VIRTIO_FS_FILE *NewVirtioFsFile; + EFI_STATUS Status; + CHAR8 *NewCanonicalPath; + BOOLEAN RootEscape; + UINT64 DirNodeId; + CHAR8 *LastComponent; + UINT64 NewNodeId; + UINT64 NewFuseHandle; + BOOLEAN NewNodeIsDirectory; + + VirtioFsFile =3D VIRTIO_FS_FILE_FROM_SIMPLE_FILE (This); + VirtioFs =3D VirtioFsFile->OwnerFs; + + // + // Validate OpenMode. + // + switch (OpenMode) { + case EFI_FILE_MODE_READ: + OpenForWriting =3D FALSE; + PermitCreation =3D FALSE; + break; + case EFI_FILE_MODE_READ | EFI_FILE_MODE_WRITE: + OpenForWriting =3D TRUE; + PermitCreation =3D FALSE; + break; + case EFI_FILE_MODE_READ | EFI_FILE_MODE_WRITE | EFI_FILE_MODE_CREATE: + OpenForWriting =3D TRUE; + PermitCreation =3D TRUE; + break; + default: + return EFI_INVALID_PARAMETER; + } + + // + // Validate the Attributes requested for the case when the file ends up = being + // created, provided creation is permitted. + // + if (PermitCreation) { + if ((Attributes & ~EFI_FILE_VALID_ATTR) !=3D 0) { + // + // Unknown attribute requested. + // + return EFI_INVALID_PARAMETER; + } + + ASSERT (OpenForWriting); + if ((Attributes & EFI_FILE_READ_ONLY) !=3D 0) { + DEBUG (( + DEBUG_ERROR, + ("%a: Label=3D\"%s\" CanonicalPathname=3D\"%a\" FileName=3D\"%s\" " + "OpenMode=3D0x%Lx Attributes=3D0x%Lx: nonsensical request to poss= ibly " + "create a file marked read-only, for read-write access\n"), + __FUNCTION__, + VirtioFs->Label, + VirtioFsFile->CanonicalPathname, + FileName, + OpenMode, + Attributes + )); + return EFI_INVALID_PARAMETER; + } + CreateDirectoryIfCreating =3D (BOOLEAN)((Attributes & + EFI_FILE_DIRECTORY) !=3D 0); + } + + // + // Referring to a file relative to a regular file makes no sense (or at = least + // it cannot be implemented consistently with how a file is referred to + // relative to a directory). + // + if (!VirtioFsFile->IsDirectory) { + DEBUG (( + DEBUG_ERROR, + ("%a: Label=3D\"%s\" CanonicalPathname=3D\"%a\" FileName=3D\"%s\": " + "nonsensical request to open a file or directory relative to a regu= lar " + "file\n"), + __FUNCTION__, + VirtioFs->Label, + VirtioFsFile->CanonicalPathname, + FileName + )); + return EFI_INVALID_PARAMETER; + } + + // + // Allocate the new VIRTIO_FS_FILE object. + // + NewVirtioFsFile =3D AllocatePool (sizeof *NewVirtioFsFile); + if (NewVirtioFsFile =3D=3D NULL) { + return EFI_OUT_OF_RESOURCES; + } + + // + // Create the canonical pathname at which the desired file is expected to + // exist. + // + Status =3D VirtioFsAppendPath (VirtioFsFile->CanonicalPathname, FileName, + &NewCanonicalPath, &RootEscape); + if (EFI_ERROR (Status)) { + goto FreeNewVirtioFsFile; + } + if (RootEscape) { + Status =3D EFI_ACCESS_DENIED; + goto FreeNewCanonicalPath; + } + + // + // If the desired file is the root directory, just open the volume one m= ore + // time, without looking up anything. + // + if (AsciiStrCmp (NewCanonicalPath, "/") =3D=3D 0) { + FreePool (NewCanonicalPath); + FreePool (NewVirtioFsFile); + return OpenRootDirectory (VirtioFs, NewHandle, OpenForWriting); + } + + // + // Split the new canonical pathname into most specific parent directory + // (given by DirNodeId) and last pathname component (i.e., immediate chi= ld + // within that parent directory). + // + Status =3D VirtioFsLookupMostSpecificParentDir (VirtioFs, NewCanonicalPa= th, + &DirNodeId, &LastComponent); + if (EFI_ERROR (Status)) { + goto FreeNewCanonicalPath; + } + + // + // Try to open LastComponent directly under DirNodeId, as an existent re= gular + // file or directory. + // + Status =3D OpenExistentFileOrDirectory (VirtioFs, DirNodeId, LastCompone= nt, + OpenForWriting, &NewNodeId, &NewFuseHandle, &NewNodeIsDirecto= ry); + // + // If LastComponent could not be found under DirNodeId, but the request + // allows us to create a new entry, attempt creating the requested regul= ar + // file or directory. + // + if (Status =3D=3D EFI_NOT_FOUND && PermitCreation) { + ASSERT (OpenForWriting); + if (CreateDirectoryIfCreating) { + Status =3D CreateDirectory (VirtioFs, DirNodeId, LastComponent, &New= NodeId, + &NewFuseHandle); + } else { + Status =3D CreateRegularFile (VirtioFs, DirNodeId, LastComponent, + &NewNodeId, &NewFuseHandle); + } + NewNodeIsDirectory =3D CreateDirectoryIfCreating; + } + + // + // Regardless of the branch taken, we're done with DirNodeId. + // + if (DirNodeId !=3D VIRTIO_FS_FUSE_ROOT_DIR_NODE_ID) { + VirtioFsFuseForget (VirtioFs, DirNodeId); + } + + if (EFI_ERROR (Status)) { + goto FreeNewCanonicalPath; + } + + // + // Populate the new VIRTIO_FS_FILE object. + // + NewVirtioFsFile->Signature =3D VIRTIO_FS_FILE_SIG; + NewVirtioFsFile->SimpleFile.Revision =3D EFI_FILE_PROTOCOL_REVISION; + NewVirtioFsFile->SimpleFile.Open =3D VirtioFsSimpleFileOpen; + NewVirtioFsFile->SimpleFile.Close =3D VirtioFsSimpleFileClose; + NewVirtioFsFile->SimpleFile.Delete =3D VirtioFsSimpleFileDelete; + NewVirtioFsFile->SimpleFile.Read =3D VirtioFsSimpleFileRead; + NewVirtioFsFile->SimpleFile.Write =3D VirtioFsSimpleFileWrite; + NewVirtioFsFile->SimpleFile.GetPosition =3D VirtioFsSimpleFileGetPositio= n; + NewVirtioFsFile->SimpleFile.SetPosition =3D VirtioFsSimpleFileSetPositio= n; + NewVirtioFsFile->SimpleFile.GetInfo =3D VirtioFsSimpleFileGetInfo; + NewVirtioFsFile->SimpleFile.SetInfo =3D VirtioFsSimpleFileSetInfo; + NewVirtioFsFile->SimpleFile.Flush =3D VirtioFsSimpleFileFlush; + NewVirtioFsFile->IsDirectory =3D NewNodeIsDirectory; + NewVirtioFsFile->IsOpenForWriting =3D OpenForWriting; + NewVirtioFsFile->OwnerFs =3D VirtioFs; + NewVirtioFsFile->CanonicalPathname =3D NewCanonicalPath; + NewVirtioFsFile->NodeId =3D NewNodeId; + NewVirtioFsFile->FuseHandle =3D NewFuseHandle; + + // + // One more file is now open for the filesystem. + // + InsertTailList (&VirtioFs->OpenFiles, &NewVirtioFsFile->OpenFilesEntry); + + *NewHandle =3D &NewVirtioFsFile->SimpleFile; + return EFI_SUCCESS; + +FreeNewCanonicalPath: + FreePool (NewCanonicalPath); + +FreeNewVirtioFsFile: + FreePool (NewVirtioFsFile); + + return Status; } --=20 2.19.1.3.g30247aa5d201 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#69040): https://edk2.groups.io/g/devel/message/69040 Mute This Topic: https://groups.io/mt/79023669/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Tue May 7 07:56:31 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+69041+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+69041+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1608156508; cv=none; d=zohomail.com; s=zohoarc; b=aox3Rc0o+1VQ3hubBTRxszXjP4SirWHSFH00oAwaG3C93eOdw8WMlPZHyTUGZu/Ic/hPJfRz+o68BEGlhXwmc7IZgpp3xpWKbmu9N1SZ+eVAU8+phMacsLFCk8t5nkCW0X+xX/fMuj805rs/H/smDAT7rQkaIYkm3VXGEv/YyLo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608156508; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=k/Gwdfk6qw29aaPCchw9Oxwp7FNyIqbJXhP0fm79DpI=; b=fTL1zTeRV9efGnZUs2gFH5cJgeze9XPXPj3MLtlslQrPa70d6dgaE9SDmW/pIptkWz/K2SwqKFeqjj7KmOh2DOzp9yaUF+oEHxODaw7ZOy5bo/DHE2AJKn1QEInS3M2YN5TZ/sHQWO9htb24tJbV33qLuvg0il+u52hf3vN+OO0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+69041+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) header.from= Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1608156508171304.6006100138052; Wed, 16 Dec 2020 14:08:28 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id ndKxYY1788612xe2PJL5BarD; Wed, 16 Dec 2020 14:08:27 -0800 X-Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.groups.io with SMTP id smtpd.web10.4480.1608156507213690620 for ; Wed, 16 Dec 2020 14:08:27 -0800 X-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-192-ufGrjuhQNPS226jPZmfBdA-1; Wed, 16 Dec 2020 17:08:24 -0500 X-MC-Unique: ufGrjuhQNPS226jPZmfBdA-1 X-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 325AC10051A8; Wed, 16 Dec 2020 22:08:23 +0000 (UTC) X-Received: from lacos-laptop-7.usersys.redhat.com (ovpn-114-152.ams2.redhat.com [10.36.114.152]) by smtp.corp.redhat.com (Postfix) with ESMTP id 44AD56F926; Wed, 16 Dec 2020 22:08:15 +0000 (UTC) From: "Laszlo Ersek" To: devel@edk2.groups.io, virtio-fs@redhat.com, lersek@redhat.com Cc: Ard Biesheuvel , Jordan Justen , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [edk2-devel] [edk2 PATCH 27/48] OvmfPkg/VirtioFsDxe: erase the dir. entry in EFI_FILE_PROTOCOL.Delete() Date: Wed, 16 Dec 2020 22:11:04 +0100 Message-Id: <20201216211125.19496-28-lersek@redhat.com> In-Reply-To: <20201216211125.19496-1-lersek@redhat.com> References: <20201216211125.19496-1-lersek@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,lersek@redhat.com X-Gm-Message-State: KXY8VJCjFAOp54etxyxMy5BVx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1608156507; bh=k/Gwdfk6qw29aaPCchw9Oxwp7FNyIqbJXhP0fm79DpI=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=GtlZeAlAnZlmbKtAynLk6XpqhTINAc6Xy0bRRhRNDaSdI3Bjd6AlJtaNzVng1gRLvr4 jZOcBpraqjk+wyPpzD/4uo70zRJsh8gAOaXwp88PjE9Gvs4minFGUKbaP0PovNfxORS49 /AVpo3CP4Jkj40N0YLrE31xg813bGmy2mhI= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" At this point, the infrastructure is available for looking up the directly containing directory of the file in EFI_FILE_PROTOCOL.Delete(), and to remove the file in that directory by last pathname component. Do so. The "RM" UEFI shell command will start working only later in the series; the shell needs more EFI_FILE_PROTOCOL members to function before it calls Delete(). Cc: Ard Biesheuvel Cc: Jordan Justen Cc: Philippe Mathieu-Daud=C3=A9 Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3097 Signed-off-by: Laszlo Ersek Acked-by: Ard Biesheuvel --- OvmfPkg/VirtioFsDxe/SimpleFsDelete.c | 44 ++++++++++++++++++-- 1 file changed, 41 insertions(+), 3 deletions(-) diff --git a/OvmfPkg/VirtioFsDxe/SimpleFsDelete.c b/OvmfPkg/VirtioFsDxe/Sim= pleFsDelete.c index e2fc2d72dfeb..76cfee5bceb1 100644 --- a/OvmfPkg/VirtioFsDxe/SimpleFsDelete.c +++ b/OvmfPkg/VirtioFsDxe/SimpleFsDelete.c @@ -41,19 +41,57 @@ VirtioFsSimpleFileDelete ( VirtioFsFuseReleaseFileOrDir (VirtioFs, VirtioFsFile->NodeId, VirtioFsFile->FuseHandle, VirtioFsFile->IsDirectory); =20 // // VirtioFsFile->FuseHandle is gone at this point, but VirtioFsFile->Nod= eId // is still valid. Continue with removing the file or directory. The res= ult // of this operation determines the return status of the function. // - // TODO - // - Status =3D EFI_WARN_DELETE_FAILURE; + if (VirtioFsFile->IsOpenForWriting) { + UINT64 ParentNodeId; + CHAR8 *LastComponent; + + // + // Split our canonical pathname into most specific parent directory + // (identified by NodeId), and single-component filename within that + // directory. If This stands for the root directory "/", then the foll= owing + // function call will gracefully fail. + // + Status =3D VirtioFsLookupMostSpecificParentDir ( + VirtioFs, + VirtioFsFile->CanonicalPathname, + &ParentNodeId, + &LastComponent + ); + if (!EFI_ERROR (Status)) { + // + // Attempt the actual removal. Regardless of the outcome, ParentNode= Id + // must be forgotten right after (unless it stands for the root + // directory). + // + Status =3D VirtioFsFuseRemoveFileOrDir ( + VirtioFs, + ParentNodeId, + LastComponent, + VirtioFsFile->IsDirectory + ); + if (ParentNodeId !=3D VIRTIO_FS_FUSE_ROOT_DIR_NODE_ID) { + VirtioFsFuseForget (VirtioFs, ParentNodeId); + } + } + if (EFI_ERROR (Status)) { + // + // Map any failure to the spec-mandated warning code. + // + Status =3D EFI_WARN_DELETE_FAILURE; + } + } else { + Status =3D EFI_WARN_DELETE_FAILURE; + } =20 // // Finally, if we've known VirtioFsFile->NodeId from a lookup, then we s= hould // also ask the server to forget it *once*. // if (VirtioFsFile->NodeId !=3D VIRTIO_FS_FUSE_ROOT_DIR_NODE_ID) { VirtioFsFuseForget (VirtioFs, VirtioFsFile->NodeId); } --=20 2.19.1.3.g30247aa5d201 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#69041): https://edk2.groups.io/g/devel/message/69041 Mute This Topic: https://groups.io/mt/79023705/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Tue May 7 07:56:31 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+69042+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+69042+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1608156640; cv=none; d=zohomail.com; s=zohoarc; b=S7xo/HIufDJwwb4XU0Zda9I6R6Kvxqh+rrXxDPItywYHtnVlwJbjP7O3ZmrKdnfuxS3TJtPtbM1rpKmAFvuJOWFdeCCvoMvRZ9sIJDOoIoqZmoUe0mBhK9djmGb0LSpQQttIKzAraoZB+pTu7M3yVS/0gL6MS6Sr6IKYZk2zuWo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608156640; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=4F6WPmO6Q+h3yfYBdD21O8Hs6KqvSKYllUJXWph37u0=; b=hAL94u8B8G7GKHN6GPNlTPm0UndQl9aZcwd59URZTmUbPK3a8RiS+CvYYOGx7YSGw4eHuOf7dN5SW7UU1bVOvSwAj5zIU5Ad9Vb1STxFdsjKV5nHDpyIl2xPDpFWnzykrcUqBg77itR4sdKuOos6R6U2L3OGC6kcOONq8PJ8Q4k= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+69042+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) header.from= Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1608156640119454.8362571632754; Wed, 16 Dec 2020 14:10:40 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id 8NSeYY1788612xTH7CGrFAk0; Wed, 16 Dec 2020 14:10:39 -0800 X-Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.groups.io with SMTP id smtpd.web10.4509.1608156634069821965 for ; Wed, 16 Dec 2020 14:10:34 -0800 X-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-420-ZCxL6Zi5Mty-CuhO2eid7Q-1; Wed, 16 Dec 2020 17:10:31 -0500 X-MC-Unique: ZCxL6Zi5Mty-CuhO2eid7Q-1 X-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 0481C800D55; Wed, 16 Dec 2020 22:10:29 +0000 (UTC) X-Received: from lacos-laptop-7.usersys.redhat.com (ovpn-114-152.ams2.redhat.com [10.36.114.152]) by smtp.corp.redhat.com (Postfix) with ESMTP id 490CF1A49B; Wed, 16 Dec 2020 22:10:24 +0000 (UTC) From: "Laszlo Ersek" To: devel@edk2.groups.io, virtio-fs@redhat.com, lersek@redhat.com Cc: Ard Biesheuvel , Jordan Justen , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [edk2-devel] [edk2 PATCH 28/48] OvmfPkg/VirtioFsDxe: implement the wrapper function for FUSE_STATFS Date: Wed, 16 Dec 2020 22:11:05 +0100 Message-Id: <20201216211125.19496-29-lersek@redhat.com> In-Reply-To: <20201216211125.19496-1-lersek@redhat.com> References: <20201216211125.19496-1-lersek@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,lersek@redhat.com X-Gm-Message-State: Ye4883rdeGX0Y4k23dW73EAhx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1608156639; bh=4F6WPmO6Q+h3yfYBdD21O8Hs6KqvSKYllUJXWph37u0=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=LPLhDnrrFoWvm6zBHMSmhfDmiVOE+keAA/Z/BItxNvmaT/E9C7xpTGDM1AdjbrzLqJu X8DRCENvq+EeOdw1hxiUe6Hv1umQgKwZcfyvQuk6Dxd19PdM68AdeSnNem4UTQhKlKvJ7 SaXCtMqrk6hcuU+p01P70dNxteMZEQWehKI= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" Add the VirtioFsFuseStatFs() function, for sending the FUSE_STATFS command to the Virtio Filesystem device. Cc: Ard Biesheuvel Cc: Jordan Justen Cc: Philippe Mathieu-Daud=C3=A9 Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3097 Signed-off-by: Laszlo Ersek Acked-by: Ard Biesheuvel --- OvmfPkg/Include/IndustryStandard/VirtioFs.h | 17 ++++ OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf | 1 + OvmfPkg/VirtioFsDxe/VirtioFsDxe.h | 7 ++ OvmfPkg/VirtioFsDxe/FuseStatFs.c | 102 ++++++++++++++++++++ 4 files changed, 127 insertions(+) diff --git a/OvmfPkg/Include/IndustryStandard/VirtioFs.h b/OvmfPkg/Include/= IndustryStandard/VirtioFs.h index efcf57941c59..800d3651e12b 100644 --- a/OvmfPkg/Include/IndustryStandard/VirtioFs.h +++ b/OvmfPkg/Include/IndustryStandard/VirtioFs.h @@ -114,16 +114,17 @@ typedef struct { typedef enum { VirtioFsFuseOpLookup =3D 1, VirtioFsFuseOpForget =3D 2, VirtioFsFuseOpGetAttr =3D 3, VirtioFsFuseOpMkDir =3D 9, VirtioFsFuseOpUnlink =3D 10, VirtioFsFuseOpRmDir =3D 11, VirtioFsFuseOpOpen =3D 14, + VirtioFsFuseOpStatFs =3D 17, VirtioFsFuseOpRelease =3D 18, VirtioFsFuseOpFsync =3D 20, VirtioFsFuseOpFlush =3D 25, VirtioFsFuseOpInit =3D 26, VirtioFsFuseOpOpenDir =3D 27, VirtioFsFuseOpReleaseDir =3D 29, VirtioFsFuseOpFsyncDir =3D 30, VirtioFsFuseOpCreate =3D 35, @@ -228,16 +229,32 @@ typedef struct { } VIRTIO_FS_FUSE_OPEN_REQUEST; =20 typedef struct { UINT64 FileHandle; UINT32 OpenFlags; UINT32 Padding; } VIRTIO_FS_FUSE_OPEN_RESPONSE; =20 +// +// Header for VirtioFsFuseOpStatFs. +// +typedef struct { + UINT64 Blocks; + UINT64 Bfree; + UINT64 Bavail; + UINT64 Files; + UINT64 Ffree; + UINT32 Bsize; + UINT32 Namelen; + UINT32 Frsize; + UINT32 Padding; + UINT32 Spare[6]; +} VIRTIO_FS_FUSE_STATFS_RESPONSE; + // // Header for VirtioFsFuseOpRelease and VirtioFsFuseOpReleaseDir. // typedef struct { UINT64 FileHandle; UINT32 Flags; UINT32 ReleaseFlags; UINT64 LockOwner; diff --git a/OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf b/OvmfPkg/VirtioFsDxe/Virt= ioFsDxe.inf index 233c0c5c0f9a..318449db3e63 100644 --- a/OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf +++ b/OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf @@ -89,16 +89,17 @@ [Sources] FuseGetAttr.c FuseInit.c FuseLookup.c FuseMkDir.c FuseOpen.c FuseOpenDir.c FuseOpenOrCreate.c FuseRelease.c + FuseStatFs.c FuseUnlink.c Helpers.c SimpleFsClose.c SimpleFsDelete.c SimpleFsFlush.c SimpleFsGetInfo.c SimpleFsGetPosition.c SimpleFsOpen.c diff --git a/OvmfPkg/VirtioFsDxe/VirtioFsDxe.h b/OvmfPkg/VirtioFsDxe/Virtio= FsDxe.h index 3bf64c0146fa..029c568b39c7 100644 --- a/OvmfPkg/VirtioFsDxe/VirtioFsDxe.h +++ b/OvmfPkg/VirtioFsDxe/VirtioFsDxe.h @@ -285,16 +285,23 @@ VirtioFsFuseRemoveFileOrDir ( EFI_STATUS VirtioFsFuseOpen ( IN OUT VIRTIO_FS *VirtioFs, IN UINT64 NodeId, IN BOOLEAN ReadWrite, OUT UINT64 *FuseHandle ); =20 +EFI_STATUS +VirtioFsFuseStatFs ( + IN OUT VIRTIO_FS *VirtioFs, + IN UINT64 NodeId, + OUT VIRTIO_FS_FUSE_STATFS_RESPONSE *FilesysAttr + ); + EFI_STATUS VirtioFsFuseReleaseFileOrDir ( IN OUT VIRTIO_FS *VirtioFs, IN UINT64 NodeId, IN UINT64 FuseHandle, IN BOOLEAN IsDir ); =20 diff --git a/OvmfPkg/VirtioFsDxe/FuseStatFs.c b/OvmfPkg/VirtioFsDxe/FuseSta= tFs.c new file mode 100644 index 000000000000..e794f8977a48 --- /dev/null +++ b/OvmfPkg/VirtioFsDxe/FuseStatFs.c @@ -0,0 +1,102 @@ +/** @file + FUSE_STATFS wrapper for the Virtio Filesystem device. + + Copyright (C) 2020, Red Hat, Inc. + + SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#include "VirtioFsDxe.h" + +/** + Send the FUSE_STATFS request to the Virtio Filesysem device, for retriev= ing + the attributes of the host-side filesystem that contains NodeId. + + The function may only be called after VirtioFsFuseInitSession() returns + successfully and before VirtioFsUninit() is called. + + @param[in,out] VirtioFs The Virtio Filesystem device to send the FUSE_S= TATFS + request to. On output, the FUSE request counter + "VirtioFs->RequestId" will have been incremente= d. + + @param[in] NodeId The inode whose containing filesystem is to be + queried for its attributes. + + @param[out] FilesysAttr The VIRTIO_FS_FUSE_STATFS_RESPONSE object descr= ibing + the filesystem that underlies NodeId. + + @retval EFI_SUCCESS FilesysAttr has been filled in. + + @return The "errno" value mapped to an EFI_STATUS code, if = the + Virtio Filesystem device explicitly reported an err= or. + + @return Error codes propagated from VirtioFsSgListsValidate= (), + VirtioFsFuseNewRequest(), VirtioFsSgListsSubmit(), + VirtioFsFuseCheckResponse(). +**/ +EFI_STATUS +VirtioFsFuseStatFs ( + IN OUT VIRTIO_FS *VirtioFs, + IN UINT64 NodeId, + OUT VIRTIO_FS_FUSE_STATFS_RESPONSE *FilesysAttr + ) +{ + VIRTIO_FS_FUSE_REQUEST CommonReq; + VIRTIO_FS_IO_VECTOR ReqIoVec[1]; + VIRTIO_FS_SCATTER_GATHER_LIST ReqSgList; + VIRTIO_FS_FUSE_RESPONSE CommonResp; + VIRTIO_FS_IO_VECTOR RespIoVec[2]; + VIRTIO_FS_SCATTER_GATHER_LIST RespSgList; + EFI_STATUS Status; + + // + // Set up the scatter-gather lists. + // + ReqIoVec[0].Buffer =3D &CommonReq; + ReqIoVec[0].Size =3D sizeof CommonReq; + ReqSgList.IoVec =3D ReqIoVec; + ReqSgList.NumVec =3D ARRAY_SIZE (ReqIoVec); + + RespIoVec[0].Buffer =3D &CommonResp; + RespIoVec[0].Size =3D sizeof CommonResp; + RespIoVec[1].Buffer =3D FilesysAttr; + RespIoVec[1].Size =3D sizeof *FilesysAttr; + RespSgList.IoVec =3D RespIoVec; + RespSgList.NumVec =3D ARRAY_SIZE (RespIoVec); + + // + // Validate the scatter-gather lists; calculate the total transfer sizes. + // + Status =3D VirtioFsSgListsValidate (VirtioFs, &ReqSgList, &RespSgList); + if (EFI_ERROR (Status)) { + return Status; + } + + // + // Populate the common request header. + // + Status =3D VirtioFsFuseNewRequest (VirtioFs, &CommonReq, ReqSgList.Total= Size, + VirtioFsFuseOpStatFs, NodeId); + if (EFI_ERROR (Status)) { + return Status; + } + + // + // Submit the request. + // + Status =3D VirtioFsSgListsSubmit (VirtioFs, &ReqSgList, &RespSgList); + if (EFI_ERROR (Status)) { + return Status; + } + + // + // Verify the response (all response buffers are fixed size). + // + Status =3D VirtioFsFuseCheckResponse (&RespSgList, CommonReq.Unique, NUL= L); + if (Status =3D=3D EFI_DEVICE_ERROR) { + DEBUG ((DEBUG_ERROR, "%a: Label=3D\"%s\" NodeId=3D%Lu Errno=3D%d\n", + __FUNCTION__, VirtioFs->Label, NodeId, CommonResp.Error)); + Status =3D VirtioFsErrnoToEfiStatus (CommonResp.Error); + } + return Status; +} --=20 2.19.1.3.g30247aa5d201 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#69042): https://edk2.groups.io/g/devel/message/69042 Mute This Topic: https://groups.io/mt/79023749/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Tue May 7 07:56:31 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+69043+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+69043+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1608156765; cv=none; d=zohomail.com; s=zohoarc; b=Y7qWzDTkBNYACxKYirFw0vxhdrjJVM3BhplvRBoIbKTR6SpuPo48k2b00FWstfBscB7KkHOjgJ2pxTQejwhfQ/9UjmsUk4Ub7V39t0omrph2odEscF7f7b5aj4fr66O10KRuEdjxRFAPOSFQYdiDukyzTxNqzkO6U0r96C/HMqc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608156765; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=enQzXzCaqmzwyG5oh6iFPwEVtmQZ5r2qscSFYalG+HI=; b=MkiKGjlzgUm9sst/jOkmO8Z3gixUoJQtH946TN4Rej30YJgPjwtKlxRG5tFbXcodX8zdCyOoE90Fioox0D8Ld+3ynouykzStjabwBf8rNOoRvNO+KQy631KXuqsp/5cjxikAwpSTpZkaA3VwGoikxDmcInBr4h0u1IPvBJxO+ZA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+69043+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) header.from= Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1608156765109361.70763583702546; Wed, 16 Dec 2020 14:12:45 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id a5vQYY1788612x2VZZ5l72Ml; Wed, 16 Dec 2020 14:12:44 -0800 X-Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.groups.io with SMTP id smtpd.web10.4536.1608156758850008660 for ; Wed, 16 Dec 2020 14:12:39 -0800 X-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-341-GAb2xRw6POuine2qmgedDw-1; Wed, 16 Dec 2020 17:12:36 -0500 X-MC-Unique: GAb2xRw6POuine2qmgedDw-1 X-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 BA08A8144F4; Wed, 16 Dec 2020 22:12:34 +0000 (UTC) X-Received: from lacos-laptop-7.usersys.redhat.com (ovpn-114-152.ams2.redhat.com [10.36.114.152]) by smtp.corp.redhat.com (Postfix) with ESMTP id 39BAB60CCD; Wed, 16 Dec 2020 22:12:30 +0000 (UTC) From: "Laszlo Ersek" To: devel@edk2.groups.io, virtio-fs@redhat.com, lersek@redhat.com Cc: Ard Biesheuvel , Jordan Justen , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [edk2-devel] [edk2 PATCH 29/48] OvmfPkg/VirtioFsDxe: add helper for formatting UEFI basenames Date: Wed, 16 Dec 2020 22:11:06 +0100 Message-Id: <20201216211125.19496-30-lersek@redhat.com> In-Reply-To: <20201216211125.19496-1-lersek@redhat.com> References: <20201216211125.19496-1-lersek@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,lersek@redhat.com X-Gm-Message-State: UmLWUGiVmVUFZEJ2MOSmVraMx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1608156764; bh=enQzXzCaqmzwyG5oh6iFPwEVtmQZ5r2qscSFYalG+HI=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=L8m/nwA2Bt2Dy/fzBqnDUdxzZd+9jAGn78RFTFiC7iejmdv5scdlcySrzJZ4BsKe7P/ LlptPWF+TG+aGRvFGHZ/0dvYZWKDlwyI/2Qb95cpAMwkOeVq0//YS/NnmvMWSJK/DGLcE YeUTJjFZLLBy2eGQOOFM7sEgaL7nPuURFeA= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" The EFI_FILE_INFO structure, which is output by EFI_FILE_PROTOCOL.GetInfo(), ends with a flexible CHAR16 array called "FileName". Add the VirtioFsGetBasename() function, for determining the required array size, and for filling the array as well. Cc: Ard Biesheuvel Cc: Jordan Justen Cc: Philippe Mathieu-Daud=C3=A9 Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3097 Signed-off-by: Laszlo Ersek Acked-by: Ard Biesheuvel --- OvmfPkg/VirtioFsDxe/VirtioFsDxe.h | 7 +++ OvmfPkg/VirtioFsDxe/Helpers.c | 61 ++++++++++++++++++++ 2 files changed, 68 insertions(+) diff --git a/OvmfPkg/VirtioFsDxe/VirtioFsDxe.h b/OvmfPkg/VirtioFsDxe/Virtio= FsDxe.h index 029c568b39c7..d1b746c0d8cf 100644 --- a/OvmfPkg/VirtioFsDxe/VirtioFsDxe.h +++ b/OvmfPkg/VirtioFsDxe/VirtioFsDxe.h @@ -229,16 +229,23 @@ VirtioFsAppendPath ( EFI_STATUS VirtioFsLookupMostSpecificParentDir ( IN OUT VIRTIO_FS *VirtioFs, IN OUT CHAR8 *Path, OUT UINT64 *DirNodeId, OUT CHAR8 **LastComponent ); =20 +EFI_STATUS +VirtioFsGetBasename ( + IN CHAR8 *Path, + OUT CHAR16 *Basename OPTIONAL, + IN OUT UINTN *BasenameSize + ); + EFI_STATUS VirtioFsFuseAttrToEfiFileInfo ( IN VIRTIO_FS_FUSE_ATTRIBUTES_RESPONSE *FuseAttr, OUT EFI_FILE_INFO *FileInfo ); =20 // // Wrapper functions for FUSE commands (primitives). diff --git a/OvmfPkg/VirtioFsDxe/Helpers.c b/OvmfPkg/VirtioFsDxe/Helpers.c index 6adc0341dee6..77f718e91233 100644 --- a/OvmfPkg/VirtioFsDxe/Helpers.c +++ b/OvmfPkg/VirtioFsDxe/Helpers.c @@ -1717,16 +1717,77 @@ VirtioFsLookupMostSpecificParentDir ( *LastComponent =3D Slash + 1; return EFI_SUCCESS; =20 ForgetNextDirNodeId: VirtioFsFuseForget (VirtioFs, NextDirNodeId); return Status; } =20 +/** + Format the last component of a canonical pathname into a caller-provided + CHAR16 array. + + @param[in] Path The canonical pathname (as defined in the + description of VirtioFsAppendPath()) to for= mat + the last component of. + + @param[out] Basename If BasenameSize is zero on input, Basename = may + be NULL. Otherwise, Basename is allocated b= y the + caller. On successful return, Basename cont= ains + the last component of Path, formatted as a + NUL-terminated CHAR16 string. When Path is = "/" + on input, Basename is L"" on output. + + @param[in,out] BasenameSize On input, the number of bytes the caller + provides in Basename. On output, regardless= of + return value, the number of bytes required = for + formatting Basename, including the terminat= ing + L'\0'. + + @retval EFI_SUCCESS Basename has been filled in. + + @retval EFI_BUFFER_TOO_SMALL BasenameSize was too small on input; Basen= ame + has not been modified. +**/ +EFI_STATUS +VirtioFsGetBasename ( + IN CHAR8 *Path, + OUT CHAR16 *Basename OPTIONAL, + IN OUT UINTN *BasenameSize + ) +{ + UINTN AllocSize; + UINTN LastComponent; + UINTN Idx; + UINTN PathSize; + + AllocSize =3D *BasenameSize; + + LastComponent =3D MAX_UINTN; + for (Idx =3D 0; Path[Idx] !=3D '\0'; Idx++) { + if (Path[Idx] =3D=3D '/') { + LastComponent =3D Idx; + } + } + PathSize =3D Idx + 1; + ASSERT (LastComponent < MAX_UINTN); + LastComponent++; + *BasenameSize =3D (PathSize - LastComponent) * sizeof Basename[0]; + + if (*BasenameSize > AllocSize) { + return EFI_BUFFER_TOO_SMALL; + } + + for (Idx =3D LastComponent; Idx < PathSize; Idx++) { + Basename[Idx - LastComponent] =3D Path[Idx]; + } + return EFI_SUCCESS; +} + /** Convert select fields of a VIRTIO_FS_FUSE_ATTRIBUTES_RESPONSE object to corresponding fields in EFI_FILE_INFO. =20 @param[in] FuseAttr The VIRTIO_FS_FUSE_ATTRIBUTES_RESPONSE object to convert the relevant fields from. =20 @param[out] FileInfo The EFI_FILE_INFO structure to modify. Importantly= , the --=20 2.19.1.3.g30247aa5d201 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#69043): https://edk2.groups.io/g/devel/message/69043 Mute This Topic: https://groups.io/mt/79023796/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Tue May 7 07:56:31 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+69044+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+69044+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1608156893; cv=none; d=zohomail.com; s=zohoarc; b=icoSQdqbo6YhCmfxDrqLXoVZYxvnQvBcmsCBFOAAuP9NHKHurNNldyFV2tqr9bl7YAH+h0ciXHTVJnrjNfdT/x1rIfi1LVgoPHaDzfZyiRkw2jo5lwcw92FxMWo88ellW/igyx6SlcpV/lrYxdGufQxDA6/EmFdpFL+YX/gHNlA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608156893; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=UEDeamCVbrafyh/g7qlBA1kygJcRZCVvDTRevjwkQT8=; b=bDo17HVOoYW4a+DEaMEZNtuGOP2b5DGU0eb1llWqccmlaH2psgHHcOJIVax465hkS2tfTLAv1xrY+HGcagDyIZ18HYup7mZ70W3aGoW5SVsQlRd7xP/8F7xH4TW/YM63IibHqQCyWGlBGHfeUEA5jC6JThDzFi/JZyg2e4F2ozw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+69044+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) header.from= Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1608156893180393.33065140436634; Wed, 16 Dec 2020 14:14:53 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id PdimYY1788612x3Ic216ggJP; Wed, 16 Dec 2020 14:14:52 -0800 X-Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.groups.io with SMTP id smtpd.web10.4573.1608156892123446554 for ; Wed, 16 Dec 2020 14:14:52 -0800 X-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-112-x76iCGCKMcGeVWFIlIuHOg-1; Wed, 16 Dec 2020 17:14:46 -0500 X-MC-Unique: x76iCGCKMcGeVWFIlIuHOg-1 X-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 BDC9B107ACE4; Wed, 16 Dec 2020 22:14:45 +0000 (UTC) X-Received: from lacos-laptop-7.usersys.redhat.com (ovpn-114-152.ams2.redhat.com [10.36.114.152]) by smtp.corp.redhat.com (Postfix) with ESMTP id F2D2819C9B; Wed, 16 Dec 2020 22:14:35 +0000 (UTC) From: "Laszlo Ersek" To: devel@edk2.groups.io, virtio-fs@redhat.com, lersek@redhat.com Cc: Ard Biesheuvel , Jordan Justen , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [edk2-devel] [edk2 PATCH 30/48] OvmfPkg/VirtioFsDxe: implement EFI_FILE_PROTOCOL.GetInfo() Date: Wed, 16 Dec 2020 22:11:07 +0100 Message-Id: <20201216211125.19496-31-lersek@redhat.com> In-Reply-To: <20201216211125.19496-1-lersek@redhat.com> References: <20201216211125.19496-1-lersek@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,lersek@redhat.com X-Gm-Message-State: AzNqoNNJG69BDlUrlLJmy6EHx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1608156892; bh=UEDeamCVbrafyh/g7qlBA1kygJcRZCVvDTRevjwkQT8=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=JqoYiRM9E4pEcPZhX3VsC8DX8qKltWT41EMr6lsgtgeXGyQ4ROWreYQrs8nrkryHHfu na9Vqp8mEUN61j/5E8T8agCu9odXe5bdk4UsjSIHJKFQSdXL2UFkYX+P2ppjLYVU0WkUR Rj83zivfW3pPmqs+Uq4Hs7VzdpunwpDkRxc= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" Using the functions introduced previously, we can now implement VirtioFsSimpleFileGetInfo(). This allows the "VOL" command to work in the UEFI shell. Cc: Ard Biesheuvel Cc: Jordan Justen Cc: Philippe Mathieu-Daud=C3=A9 Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3097 Signed-off-by: Laszlo Ersek Acked-by: Ard Biesheuvel --- OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf | 5 + OvmfPkg/VirtioFsDxe/SimpleFsGetInfo.c | 190 +++++++++++++++++++- 2 files changed, 194 insertions(+), 1 deletion(-) diff --git a/OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf b/OvmfPkg/VirtioFsDxe/Virt= ioFsDxe.inf index 318449db3e63..3cb5c101c3a6 100644 --- a/OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf +++ b/OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf @@ -120,8 +120,13 @@ [LibraryClasses] UefiDriverEntryPoint VirtioLib =20 [Protocols] gEfiComponentName2ProtocolGuid ## PRODUCES gEfiDriverBindingProtocolGuid ## PRODUCES gEfiSimpleFileSystemProtocolGuid ## BY_START gVirtioDeviceProtocolGuid ## TO_START + +[Guids] + gEfiFileInfoGuid + gEfiFileSystemInfoGuid + gEfiFileSystemVolumeLabelInfoIdGuid diff --git a/OvmfPkg/VirtioFsDxe/SimpleFsGetInfo.c b/OvmfPkg/VirtioFsDxe/Si= mpleFsGetInfo.c index 6e870460c014..c8be1d502202 100644 --- a/OvmfPkg/VirtioFsDxe/SimpleFsGetInfo.c +++ b/OvmfPkg/VirtioFsDxe/SimpleFsGetInfo.c @@ -1,21 +1,209 @@ /** @file EFI_FILE_PROTOCOL.GetInfo() member function for the Virtio Filesystem dr= iver. =20 Copyright (C) 2020, Red Hat, Inc. =20 SPDX-License-Identifier: BSD-2-Clause-Patent **/ =20 +#include // gEfiFileSystemInfoGuid +#include // gEfiFileSystemVolumeLabelIn= fo... +#include // StrSize() +#include // CompareGuid() + #include "VirtioFsDxe.h" =20 +/** + Provide EFI_FILE_INFO about this particular file. +**/ +STATIC +EFI_STATUS +GetFileInfo ( + IN EFI_FILE_PROTOCOL *This, + IN OUT UINTN *BufferSize, + OUT VOID *Buffer + ) +{ + VIRTIO_FS_FILE *VirtioFsFile; + VIRTIO_FS *VirtioFs; + UINTN AllocSize; + UINTN BasenameSize; + EFI_STATUS Status; + EFI_FILE_INFO *FileInfo; + VIRTIO_FS_FUSE_ATTRIBUTES_RESPONSE FuseAttr; + + VirtioFsFile =3D VIRTIO_FS_FILE_FROM_SIMPLE_FILE (This); + VirtioFs =3D VirtioFsFile->OwnerFs; + + AllocSize =3D *BufferSize; + + // + // Calculate the needed size. + // + BasenameSize =3D 0; + Status =3D VirtioFsGetBasename (VirtioFsFile->CanonicalPathname, NULL, + &BasenameSize); + ASSERT (Status =3D=3D EFI_BUFFER_TOO_SMALL); + *BufferSize =3D OFFSET_OF (EFI_FILE_INFO, FileName) + BasenameSize; + + if (*BufferSize > AllocSize) { + return EFI_BUFFER_TOO_SMALL; + } + + // + // Set the structure size, and store the basename. + // + FileInfo =3D Buffer; + FileInfo->Size =3D *BufferSize; + Status =3D VirtioFsGetBasename (VirtioFsFile->CanonicalPathname, + FileInfo->FileName, &BasenameSize); + ASSERT_EFI_ERROR (Status); + + // + // Fetch the file attributes, and convert them into the caller's buffer. + // + Status =3D VirtioFsFuseGetAttr (VirtioFs, VirtioFsFile->NodeId, &FuseAtt= r); + if (!EFI_ERROR (Status)) { + Status =3D VirtioFsFuseAttrToEfiFileInfo (&FuseAttr, FileInfo); + } + return (Status =3D=3D EFI_BUFFER_TOO_SMALL) ? EFI_DEVICE_ERROR : Status; +} + +/** + Provide EFI_FILE_SYSTEM_INFO about the filesystem this file lives on. +**/ +STATIC +EFI_STATUS +GetFileSystemInfo ( + IN EFI_FILE_PROTOCOL *This, + IN OUT UINTN *BufferSize, + OUT VOID *Buffer + ) +{ + VIRTIO_FS_FILE *VirtioFsFile; + VIRTIO_FS *VirtioFs; + UINTN AllocSize; + UINTN LabelSize; + EFI_STATUS Status; + VIRTIO_FS_FUSE_STATFS_RESPONSE FilesysAttr; + UINT64 MaxBlocks; + EFI_FILE_SYSTEM_INFO *FilesysInfo; + + VirtioFsFile =3D VIRTIO_FS_FILE_FROM_SIMPLE_FILE (This); + VirtioFs =3D VirtioFsFile->OwnerFs; + + AllocSize =3D *BufferSize; + + // + // Calculate the needed size. + // + LabelSize =3D StrSize (VirtioFs->Label); + *BufferSize =3D OFFSET_OF (EFI_FILE_SYSTEM_INFO, VolumeLabel) + LabelSiz= e; + + if (*BufferSize > AllocSize) { + return EFI_BUFFER_TOO_SMALL; + } + + // + // Fetch the filesystem attributes. + // + Status =3D VirtioFsFuseStatFs (VirtioFs, VirtioFsFile->NodeId, &FilesysA= ttr); + if (EFI_ERROR (Status)) { + return (Status =3D=3D EFI_BUFFER_TOO_SMALL) ? EFI_DEVICE_ERROR : Statu= s; + } + // + // Sanity checks... + // + if (FilesysAttr.Frsize !=3D FilesysAttr.Bsize) { + return EFI_UNSUPPORTED; + } + if (FilesysAttr.Frsize =3D=3D 0 || FilesysAttr.Blocks =3D=3D 0 || + FilesysAttr.Bavail > FilesysAttr.Blocks) { + return EFI_DEVICE_ERROR; + } + MaxBlocks =3D DivU64x32 (MAX_UINT64, FilesysAttr.Frsize); + if (FilesysAttr.Blocks > MaxBlocks || FilesysAttr.Bavail > MaxBlocks) { + return EFI_DEVICE_ERROR; + } + + // + // Fill in EFI_FILE_SYSTEM_INFO. + // + FilesysInfo =3D Buffer; + FilesysInfo->Size =3D *BufferSize; + FilesysInfo->ReadOnly =3D FALSE; + FilesysInfo->VolumeSize =3D MultU64x32 (FilesysAttr.Blocks, + FilesysAttr.Frsize); + FilesysInfo->FreeSpace =3D MultU64x32 (FilesysAttr.Bavail, + FilesysAttr.Frsize); + FilesysInfo->BlockSize =3D FilesysAttr.Frsize; + CopyMem (FilesysInfo->VolumeLabel, VirtioFs->Label, LabelSize); + + return EFI_SUCCESS; +} + +/** + Return the filesystem label as EFI_FILE_SYSTEM_VOLUME_LABEL. +**/ +STATIC +EFI_STATUS +GetFileSystemVolumeLabelInfo ( + IN EFI_FILE_PROTOCOL *This, + IN OUT UINTN *BufferSize, + OUT VOID *Buffer + ) +{ + VIRTIO_FS_FILE *VirtioFsFile; + VIRTIO_FS *VirtioFs; + UINTN AllocSize; + UINTN LabelSize; + EFI_FILE_SYSTEM_VOLUME_LABEL *FilesysVolumeLabel; + + VirtioFsFile =3D VIRTIO_FS_FILE_FROM_SIMPLE_FILE (This); + VirtioFs =3D VirtioFsFile->OwnerFs; + + AllocSize =3D *BufferSize; + + // + // Calculate the needed size. + // + LabelSize =3D StrSize (VirtioFs->Label); + *BufferSize =3D (OFFSET_OF (EFI_FILE_SYSTEM_VOLUME_LABEL, VolumeLabel) + + LabelSize); + + if (*BufferSize > AllocSize) { + return EFI_BUFFER_TOO_SMALL; + } + + // + // Store the label. + // + FilesysVolumeLabel =3D Buffer; + CopyMem (FilesysVolumeLabel->VolumeLabel, VirtioFs->Label, LabelSize); + + return EFI_SUCCESS; +} + EFI_STATUS EFIAPI VirtioFsSimpleFileGetInfo ( IN EFI_FILE_PROTOCOL *This, IN EFI_GUID *InformationType, IN OUT UINTN *BufferSize, OUT VOID *Buffer ) { - return EFI_NO_MEDIA; + if (CompareGuid (InformationType, &gEfiFileInfoGuid)) { + return GetFileInfo (This, BufferSize, Buffer); + } + + if (CompareGuid (InformationType, &gEfiFileSystemInfoGuid)) { + return GetFileSystemInfo (This, BufferSize, Buffer); + } + + if (CompareGuid (InformationType, &gEfiFileSystemVolumeLabelInfoIdGuid))= { + return GetFileSystemVolumeLabelInfo (This, BufferSize, Buffer); + } + + return EFI_UNSUPPORTED; } --=20 2.19.1.3.g30247aa5d201 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#69044): https://edk2.groups.io/g/devel/message/69044 Mute This Topic: https://groups.io/mt/79023862/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Tue May 7 07:56:31 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+69045+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+69045+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1608157016; cv=none; d=zohomail.com; s=zohoarc; b=dBi27yd2XcyFhMLgHa5ej+75BQztfghDHTL8tn8YY4jHqiVtCCe+DbwgTYsd+YH6hq5+WXGIspKf33A+PNjQ9AoqVqLyHEBS9lQEvM0AO8ndPbiY0iwLZHsTR4DxuTWQjaEUJXYjygXC0KfDUU34K+uLqpBJ8s7xkO5Oidwtqng= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608157016; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=j69Z7L6ICM9Ik0OyL9MonG1crujlG5HIeyE7bQFe70g=; b=IkLqQWG7d5pNMgW6CFrwdWmNDnBQsYdcNtOANVVL9+MGvgZQf5iBrSA9gADQpLXTpX47avlcnAUTbnuQpEej84t9bJWFa/aEq51Yp8zkhvw008fivzSwVziNeofk+ymxwS6DJ4IHunlBPNcpz8e9JB79VJZ4my8WK22U+hC0vww= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+69045+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) header.from= Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1608157016673236.10870161846958; Wed, 16 Dec 2020 14:16:56 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id 8m1cYY1788612xSn1dT002EY; Wed, 16 Dec 2020 14:16:56 -0800 X-Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.groups.io with SMTP id smtpd.web10.4609.1608157015614290733 for ; Wed, 16 Dec 2020 14:16:55 -0800 X-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-483-wSsW0N-qPOSr8RMfOUg9ug-1; Wed, 16 Dec 2020 17:16:53 -0500 X-MC-Unique: wSsW0N-qPOSr8RMfOUg9ug-1 X-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 C753A801B13; Wed, 16 Dec 2020 22:16:51 +0000 (UTC) X-Received: from lacos-laptop-7.usersys.redhat.com (ovpn-114-152.ams2.redhat.com [10.36.114.152]) by smtp.corp.redhat.com (Postfix) with ESMTP id ED63619D9F; Wed, 16 Dec 2020 22:16:46 +0000 (UTC) From: "Laszlo Ersek" To: devel@edk2.groups.io, virtio-fs@redhat.com, lersek@redhat.com Cc: Ard Biesheuvel , Jordan Justen , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [edk2-devel] [edk2 PATCH 31/48] OvmfPkg/VirtioFsDxe: implement EFI_FILE_PROTOCOL.GetPosition, .SetPosition Date: Wed, 16 Dec 2020 22:11:08 +0100 Message-Id: <20201216211125.19496-32-lersek@redhat.com> In-Reply-To: <20201216211125.19496-1-lersek@redhat.com> References: <20201216211125.19496-1-lersek@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,lersek@redhat.com X-Gm-Message-State: EHXddXMaEgbFCIjcKVCAgfu8x1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1608157016; bh=j69Z7L6ICM9Ik0OyL9MonG1crujlG5HIeyE7bQFe70g=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=byLUcpRWybmFJygcez2vE+/pxN2dRb+0Bdw7hwZzSHJPZzsCvS4jbrt4fL40EPbUdlq jXMxQySY7GGK9IlO25IMAuM/xpJfWkzhZ+jOAqkYpuNk5OTBQt553xTk9EeL/oMgmIlnx 1adaD4bN5CClhDZM833gDhF3cma/V7Giga0= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" Using the functions introduced previously, we can now implement VirtioFsSimpleFileGetPosition() and VirtioFsSimpleFileSetPosition(). Cc: Ard Biesheuvel Cc: Jordan Justen Cc: Philippe Mathieu-Daud=C3=A9 Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3097 Signed-off-by: Laszlo Ersek Acked-by: Ard Biesheuvel --- OvmfPkg/VirtioFsDxe/VirtioFsDxe.h | 1 + OvmfPkg/VirtioFsDxe/SimpleFsGetPosition.c | 9 ++++- OvmfPkg/VirtioFsDxe/SimpleFsOpen.c | 1 + OvmfPkg/VirtioFsDxe/SimpleFsOpenVolume.c | 1 + OvmfPkg/VirtioFsDxe/SimpleFsSetPosition.c | 40 +++++++++++++++++++- 5 files changed, 50 insertions(+), 2 deletions(-) diff --git a/OvmfPkg/VirtioFsDxe/VirtioFsDxe.h b/OvmfPkg/VirtioFsDxe/Virtio= FsDxe.h index d1b746c0d8cf..948fcfb6b6f3 100644 --- a/OvmfPkg/VirtioFsDxe/VirtioFsDxe.h +++ b/OvmfPkg/VirtioFsDxe/VirtioFsDxe.h @@ -134,16 +134,17 @@ typedef struct { typedef struct { UINT64 Signature; EFI_FILE_PROTOCOL SimpleFile; BOOLEAN IsDirectory; BOOLEAN IsOpenForWriting; VIRTIO_FS *OwnerFs; LIST_ENTRY OpenFilesEntry; CHAR8 *CanonicalPathname; + UINT64 FilePosition; // // In the FUSE wire protocol, every request except FUSE_INIT refers to a // file, namely by the "VIRTIO_FS_FUSE_REQUEST.NodeId" field; that is, b= y the // inode number of the file. However, some of the FUSE requests that we = need // for some of the EFI_FILE_PROTOCOL member functions require an open fi= le // handle *in addition* to the inode number. For simplicity, whenever a // VIRTIO_FS_FILE object is created, primarily defined by its NodeId fie= ld, // we also *open* the referenced file at once, and save the returned file diff --git a/OvmfPkg/VirtioFsDxe/SimpleFsGetPosition.c b/OvmfPkg/VirtioFsDx= e/SimpleFsGetPosition.c index 2f40d2be2693..53212621e970 100644 --- a/OvmfPkg/VirtioFsDxe/SimpleFsGetPosition.c +++ b/OvmfPkg/VirtioFsDxe/SimpleFsGetPosition.c @@ -11,10 +11,17 @@ =20 EFI_STATUS EFIAPI VirtioFsSimpleFileGetPosition ( IN EFI_FILE_PROTOCOL *This, OUT UINT64 *Position ) { - return EFI_DEVICE_ERROR; + VIRTIO_FS_FILE *VirtioFsFile; + + VirtioFsFile =3D VIRTIO_FS_FILE_FROM_SIMPLE_FILE (This); + if (VirtioFsFile->IsDirectory) { + return EFI_UNSUPPORTED; + } + *Position =3D VirtioFsFile->FilePosition; + return EFI_SUCCESS; } diff --git a/OvmfPkg/VirtioFsDxe/SimpleFsOpen.c b/OvmfPkg/VirtioFsDxe/Simpl= eFsOpen.c index 2649c796ac97..7c50ce9c0e76 100644 --- a/OvmfPkg/VirtioFsDxe/SimpleFsOpen.c +++ b/OvmfPkg/VirtioFsDxe/SimpleFsOpen.c @@ -474,16 +474,17 @@ VirtioFsSimpleFileOpen ( NewVirtioFsFile->SimpleFile.SetPosition =3D VirtioFsSimpleFileSetPositio= n; NewVirtioFsFile->SimpleFile.GetInfo =3D VirtioFsSimpleFileGetInfo; NewVirtioFsFile->SimpleFile.SetInfo =3D VirtioFsSimpleFileSetInfo; NewVirtioFsFile->SimpleFile.Flush =3D VirtioFsSimpleFileFlush; NewVirtioFsFile->IsDirectory =3D NewNodeIsDirectory; NewVirtioFsFile->IsOpenForWriting =3D OpenForWriting; NewVirtioFsFile->OwnerFs =3D VirtioFs; NewVirtioFsFile->CanonicalPathname =3D NewCanonicalPath; + NewVirtioFsFile->FilePosition =3D 0; NewVirtioFsFile->NodeId =3D NewNodeId; NewVirtioFsFile->FuseHandle =3D NewFuseHandle; =20 // // One more file is now open for the filesystem. // InsertTailList (&VirtioFs->OpenFiles, &NewVirtioFsFile->OpenFilesEntry); =20 diff --git a/OvmfPkg/VirtioFsDxe/SimpleFsOpenVolume.c b/OvmfPkg/VirtioFsDxe= /SimpleFsOpenVolume.c index 9c0ab434c186..1181191d271b 100644 --- a/OvmfPkg/VirtioFsDxe/SimpleFsOpenVolume.c +++ b/OvmfPkg/VirtioFsDxe/SimpleFsOpenVolume.c @@ -67,16 +67,17 @@ VirtioFsOpenVolume ( VirtioFsFile->SimpleFile.SetPosition =3D VirtioFsSimpleFileSetPosition; VirtioFsFile->SimpleFile.GetInfo =3D VirtioFsSimpleFileGetInfo; VirtioFsFile->SimpleFile.SetInfo =3D VirtioFsSimpleFileSetInfo; VirtioFsFile->SimpleFile.Flush =3D VirtioFsSimpleFileFlush; VirtioFsFile->IsDirectory =3D TRUE; VirtioFsFile->IsOpenForWriting =3D FALSE; VirtioFsFile->OwnerFs =3D VirtioFs; VirtioFsFile->CanonicalPathname =3D CanonicalPathname; + VirtioFsFile->FilePosition =3D 0; VirtioFsFile->NodeId =3D VIRTIO_FS_FUSE_ROOT_DIR_NODE_ID; VirtioFsFile->FuseHandle =3D RootDirHandle; =20 // // One more file open for the filesystem. // InsertTailList (&VirtioFs->OpenFiles, &VirtioFsFile->OpenFilesEntry); =20 diff --git a/OvmfPkg/VirtioFsDxe/SimpleFsSetPosition.c b/OvmfPkg/VirtioFsDx= e/SimpleFsSetPosition.c index ee8cb1f4e465..ac6285302652 100644 --- a/OvmfPkg/VirtioFsDxe/SimpleFsSetPosition.c +++ b/OvmfPkg/VirtioFsDxe/SimpleFsSetPosition.c @@ -11,10 +11,48 @@ =20 EFI_STATUS EFIAPI VirtioFsSimpleFileSetPosition ( IN EFI_FILE_PROTOCOL *This, IN UINT64 Position ) { - return EFI_DEVICE_ERROR; + VIRTIO_FS_FILE *VirtioFsFile; + VIRTIO_FS *VirtioFs; + EFI_STATUS Status; + VIRTIO_FS_FUSE_ATTRIBUTES_RESPONSE FuseAttr; + + VirtioFsFile =3D VIRTIO_FS_FILE_FROM_SIMPLE_FILE (This); + + // + // Directories can only be rewound, per spec. + // + if (VirtioFsFile->IsDirectory) { + if (Position !=3D 0) { + return EFI_UNSUPPORTED; + } + VirtioFsFile->FilePosition =3D 0; + return EFI_SUCCESS; + } + + // + // Regular file. + // + if (Position < MAX_UINT64) { + // + // Caller is requesting absolute file position. + // + VirtioFsFile->FilePosition =3D Position; + return EFI_SUCCESS; + } + + // + // Caller is requesting a seek to EOF. + // + VirtioFs =3D VirtioFsFile->OwnerFs; + Status =3D VirtioFsFuseGetAttr (VirtioFs, VirtioFsFile->NodeId, &FuseAtt= r); + if (EFI_ERROR (Status)) { + return Status; + } + VirtioFsFile->FilePosition =3D FuseAttr.Size; + return EFI_SUCCESS; } --=20 2.19.1.3.g30247aa5d201 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#69045): https://edk2.groups.io/g/devel/message/69045 Mute This Topic: https://groups.io/mt/79023920/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Tue May 7 07:56:31 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+69046+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+69046+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1608157143; cv=none; d=zohomail.com; s=zohoarc; b=SGhvU1zwlfYiHNU12YGry9TKa9t79Yrh/DuELnEHI4y3zhneFF433Xz+GotZLyrwdBWUnlw530xjuK0l/FU0WN0KFccM3EED6C7PygLIHnm3ZAxtOx96E+WA7ufXwDUYfd5FfClaTSzfgC+GcI2ZuzWyWpLjxh2cbhLv3DcYbYM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608157143; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=evIC5vHnEFnqJzJpsBRIJ7ioYCqNPUxUKqtAB82pYHc=; b=LPxG0vK+6+OZm9dJ+Y7esk3nCsY0z88hqVzBJUePHhoohWpbkrJ0DfeFAGZeWtNiLwZV1qwiZhvieJe2VZwrM1iL+lFtcZipzJ7cqYMKPlRrc0+j2tyzE287UNNwz4qgVBixQFLALZj1Ie7mD/rTlTLiKm9/dykDFOfv0CLOeqk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+69046+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) header.from= Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1608157143338341.90711887809425; Wed, 16 Dec 2020 14:19:03 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id mtcAYY1788612x3NXnogb7vT; Wed, 16 Dec 2020 14:19:02 -0800 X-Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.groups.io with SMTP id smtpd.web10.4640.1608157141987051410 for ; Wed, 16 Dec 2020 14:19:02 -0800 X-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-80-RWkKTyQ1NtWMYSoGfgGVCg-1; Wed, 16 Dec 2020 17:18:59 -0500 X-MC-Unique: RWkKTyQ1NtWMYSoGfgGVCg-1 X-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 461D819251A1; Wed, 16 Dec 2020 22:18:58 +0000 (UTC) X-Received: from lacos-laptop-7.usersys.redhat.com (ovpn-114-152.ams2.redhat.com [10.36.114.152]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0B0CF1971D; Wed, 16 Dec 2020 22:18:52 +0000 (UTC) From: "Laszlo Ersek" To: devel@edk2.groups.io, virtio-fs@redhat.com, lersek@redhat.com Cc: Ard Biesheuvel , Jordan Justen , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [edk2-devel] [edk2 PATCH 32/48] OvmfPkg/VirtioFsDxe: add a shared wrapper for FUSE_READ / FUSE_READDIRPLUS Date: Wed, 16 Dec 2020 22:11:09 +0100 Message-Id: <20201216211125.19496-33-lersek@redhat.com> In-Reply-To: <20201216211125.19496-1-lersek@redhat.com> References: <20201216211125.19496-1-lersek@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,lersek@redhat.com X-Gm-Message-State: 1556nyanwMoLDAHLTBiisg7zx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1608157142; bh=evIC5vHnEFnqJzJpsBRIJ7ioYCqNPUxUKqtAB82pYHc=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=Fi8aeYbrZyvpq3yH0ojM5ECr9WupUsAKdk0b7lVAzuB0GjJjFA3eqZSHhGMR5CSw5Ct NvMCD77SwRXvySPjLjGNW0wpMBTK63BXEQ6rQkceu6E6eU1hMAqOpS/avsR7u7NwxWRvl SE21n5xqC1/sMHlkQl/vGNK+nM118GVY+jU= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" Add the VirtioFsFuseReadFileOrDir() function, for sending the FUSE_READ or FUSE_READDIRPLUS command to the Virtio Filesystem device. Parsing the structured FUSE_READDIRPLUS output is complex, and cannot be integrated into the wrapper function. Given that fact, FUSE_READ and FUSE_READDIRPLUS turn out to need identical low-level handling, except for the opcode. Hence the shared wrapper function. (It's prudent to verify whether the FUSE server supports FUSE_READDIRPLUS, so update the session init code accordingly.) This is the first FUSE request wrapper function that deals with a variable size tail buffer. Cc: Ard Biesheuvel Cc: Jordan Justen Cc: Philippe Mathieu-Daud=C3=A9 Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3097 Signed-off-by: Laszlo Ersek Acked-by: Ard Biesheuvel --- OvmfPkg/Include/IndustryStandard/VirtioFs.h | 67 +++++++ OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf | 1 + OvmfPkg/VirtioFsDxe/VirtioFsDxe.h | 11 ++ OvmfPkg/VirtioFsDxe/FuseInit.c | 10 +- OvmfPkg/VirtioFsDxe/FuseRead.c | 191 ++++++++++++++++++++ 5 files changed, 276 insertions(+), 4 deletions(-) diff --git a/OvmfPkg/Include/IndustryStandard/VirtioFs.h b/OvmfPkg/Include/= IndustryStandard/VirtioFs.h index 800d3651e12b..fa8c40019f4e 100644 --- a/OvmfPkg/Include/IndustryStandard/VirtioFs.h +++ b/OvmfPkg/Include/IndustryStandard/VirtioFs.h @@ -103,36 +103,71 @@ typedef struct { #define VIRTIO_FS_FUSE_MODE_PERM_WOTH 0000002u =20 // // Flags for VirtioFsFuseOpOpen. // #define VIRTIO_FS_FUSE_OPEN_REQ_F_RDONLY 0 #define VIRTIO_FS_FUSE_OPEN_REQ_F_RDWR 2 =20 +// +// Flags for VirtioFsFuseOpInit. +// +#define VIRTIO_FS_FUSE_INIT_REQ_F_DO_READDIRPLUS BIT13 + +/** + Macro for calculating the size of a directory stream entry. + + The macro may evaluate Namelen multiple times. + + The macro evaluates to a UINTN value that is safe to cast to UINT32. + + @param[in] Namelen The size of the filename byte array that follows + VIRTIO_FS_FUSE_DIRENTPLUS_RESPONSE in the directory + stream, as reported by + VIRTIO_FS_FUSE_STATFS_RESPONSE.Namelen or + VIRTIO_FS_FUSE_DIRENTPLUS_RESPONSE.Namelen. The file= name + byte array is not NUL-terminated. + + @retval 0 Namelen was zero or greater than SIZE_4KB. + + @return The number of bytes in the directory entry, including the + VIRTIO_FS_FUSE_DIRENTPLUS_RESPONSE header. +**/ +#define VIRTIO_FS_FUSE_DIRENTPLUS_RESPONSE_SIZE(Namelen) \ + ((Namelen) =3D=3D 0 || (Namelen) > SIZE_4KB ? \ + (UINTN)0 : \ + ALIGN_VALUE ( \ + sizeof (VIRTIO_FS_FUSE_DIRENTPLUS_RESPONSE) + (UINTN)(Namelen), \ + sizeof (UINT64) \ + ) \ + ) + // // FUSE operation codes. // typedef enum { VirtioFsFuseOpLookup =3D 1, VirtioFsFuseOpForget =3D 2, VirtioFsFuseOpGetAttr =3D 3, VirtioFsFuseOpMkDir =3D 9, VirtioFsFuseOpUnlink =3D 10, VirtioFsFuseOpRmDir =3D 11, VirtioFsFuseOpOpen =3D 14, + VirtioFsFuseOpRead =3D 15, VirtioFsFuseOpStatFs =3D 17, VirtioFsFuseOpRelease =3D 18, VirtioFsFuseOpFsync =3D 20, VirtioFsFuseOpFlush =3D 25, VirtioFsFuseOpInit =3D 26, VirtioFsFuseOpOpenDir =3D 27, VirtioFsFuseOpReleaseDir =3D 29, VirtioFsFuseOpFsyncDir =3D 30, VirtioFsFuseOpCreate =3D 35, + VirtioFsFuseOpReadDirPlus =3D 44, } VIRTIO_FS_FUSE_OPCODE; =20 #pragma pack (1) // // Request-response headers common to all request types. // typedef struct { UINT32 Len; @@ -229,16 +264,29 @@ typedef struct { } VIRTIO_FS_FUSE_OPEN_REQUEST; =20 typedef struct { UINT64 FileHandle; UINT32 OpenFlags; UINT32 Padding; } VIRTIO_FS_FUSE_OPEN_RESPONSE; =20 +// +// Header for VirtioFsFuseOpRead and VirtioFsFuseOpReadDirPlus. +// +typedef struct { + UINT64 FileHandle; + UINT64 Offset; + UINT32 Size; + UINT32 ReadFlags; + UINT64 LockOwner; + UINT32 Flags; + UINT32 Padding; +} VIRTIO_FS_FUSE_READ_REQUEST; + // // Header for VirtioFsFuseOpStatFs. // typedef struct { UINT64 Blocks; UINT64 Bfree; UINT64 Bavail; UINT64 Files; @@ -307,11 +355,30 @@ typedef struct { // Header for VirtioFsFuseOpCreate. // typedef struct { UINT32 Flags; UINT32 Mode; UINT32 Umask; UINT32 Padding; } VIRTIO_FS_FUSE_CREATE_REQUEST; + +// +// Header for VirtioFsFuseOpReadDirPlus. +// +// Diverging from the rest of the headers, this structure embeds other +// structures. The reason is that a scatter list cannot be used to receive +// NodeResp and AttrResp separately; the record below is followed by a var= iable +// size filename byte array, and then such pairs are repeated a number of +// times. Thus, later header start offsets depend on earlier filename array +// sizes. +// +typedef struct { + VIRTIO_FS_FUSE_NODE_RESPONSE NodeResp; + VIRTIO_FS_FUSE_ATTRIBUTES_RESPONSE AttrResp; + UINT64 NodeId; + UINT64 CookieForNextEntry; + UINT32 Namelen; + UINT32 Type; +} VIRTIO_FS_FUSE_DIRENTPLUS_RESPONSE; #pragma pack () =20 #endif // VIRTIO_FS_H_ diff --git a/OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf b/OvmfPkg/VirtioFsDxe/Virt= ioFsDxe.inf index 3cb5c101c3a6..39c77c7c4ee9 100644 --- a/OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf +++ b/OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf @@ -88,16 +88,17 @@ [Sources] FuseFsync.c FuseGetAttr.c FuseInit.c FuseLookup.c FuseMkDir.c FuseOpen.c FuseOpenDir.c FuseOpenOrCreate.c + FuseRead.c FuseRelease.c FuseStatFs.c FuseUnlink.c Helpers.c SimpleFsClose.c SimpleFsDelete.c SimpleFsFlush.c SimpleFsGetInfo.c diff --git a/OvmfPkg/VirtioFsDxe/VirtioFsDxe.h b/OvmfPkg/VirtioFsDxe/Virtio= FsDxe.h index 948fcfb6b6f3..f5501af7d0a4 100644 --- a/OvmfPkg/VirtioFsDxe/VirtioFsDxe.h +++ b/OvmfPkg/VirtioFsDxe/VirtioFsDxe.h @@ -293,16 +293,27 @@ VirtioFsFuseRemoveFileOrDir ( EFI_STATUS VirtioFsFuseOpen ( IN OUT VIRTIO_FS *VirtioFs, IN UINT64 NodeId, IN BOOLEAN ReadWrite, OUT UINT64 *FuseHandle ); =20 +EFI_STATUS +VirtioFsFuseReadFileOrDir ( + IN OUT VIRTIO_FS *VirtioFs, + IN UINT64 NodeId, + IN UINT64 FuseHandle, + IN BOOLEAN IsDir, + IN UINT64 Offset, + IN OUT UINT32 *Size, + OUT VOID *Data + ); + EFI_STATUS VirtioFsFuseStatFs ( IN OUT VIRTIO_FS *VirtioFs, IN UINT64 NodeId, OUT VIRTIO_FS_FUSE_STATFS_RESPONSE *FilesysAttr ); =20 EFI_STATUS diff --git a/OvmfPkg/VirtioFsDxe/FuseInit.c b/OvmfPkg/VirtioFsDxe/FuseInit.c index aa19dbdc05cb..7aa6ee75caf6 100644 --- a/OvmfPkg/VirtioFsDxe/FuseInit.c +++ b/OvmfPkg/VirtioFsDxe/FuseInit.c @@ -21,17 +21,18 @@ before VirtioFsUninit() is called. =20 @param[in,out] VirtioFs The Virtio Filesystem device to send the FUSE_I= NIT request to. The FUSE request counter "VirtioFs->RequestId" is set to 1 on output. =20 @retval EFI_SUCCESS The FUSE session has been started. =20 - @retval EFI_UNSUPPORTED FUSE interface version negotiation failed. + @retval EFI_UNSUPPORTED FUSE interface version or feature negotiation + failed. =20 @return The "errno" value mapped to an EFI_STATUS code,= if the Virtio Filesystem device explicitly reporte= d an error. =20 @return Error codes propagated from VirtioFsSgListsValidate(), VirtioFsFuseNewReque= st(), VirtioFsSgListsSubmit(), @@ -92,17 +93,17 @@ VirtioFsFuseInitSession ( } =20 // // Populate the FUSE_INIT-specific fields. // InitReq.Major =3D VIRTIO_FS_FUSE_MAJOR; InitReq.Minor =3D VIRTIO_FS_FUSE_MINOR; InitReq.MaxReadahead =3D 0; - InitReq.Flags =3D 0; + InitReq.Flags =3D VIRTIO_FS_FUSE_INIT_REQ_F_DO_READDIRPLUS; =20 // // Submit the request. // Status =3D VirtioFsSgListsSubmit (VirtioFs, &ReqSgList, &RespSgList); if (EFI_ERROR (Status)) { return Status; } @@ -116,17 +117,18 @@ VirtioFsFuseInitSession ( DEBUG ((DEBUG_ERROR, "%a: Label=3D\"%s\" Errno=3D%d\n", __FUNCTION__, VirtioFs->Label, CommonResp.Error)); Status =3D VirtioFsErrnoToEfiStatus (CommonResp.Error); } return Status; } =20 // - // Check FUSE interface version compatibility. + // Check FUSE interface version / feature compatibility. // if (InitResp.Major < InitReq.Major || - (InitResp.Major =3D=3D InitReq.Major && InitResp.Minor < InitReq.Min= or)) { + (InitResp.Major =3D=3D InitReq.Major && InitResp.Minor < InitReq.Min= or) || + (InitResp.Flags & VIRTIO_FS_FUSE_INIT_REQ_F_DO_READDIRPLUS) =3D=3D 0= ) { return EFI_UNSUPPORTED; } =20 return EFI_SUCCESS; } diff --git a/OvmfPkg/VirtioFsDxe/FuseRead.c b/OvmfPkg/VirtioFsDxe/FuseRead.c new file mode 100644 index 000000000000..1611e298b90d --- /dev/null +++ b/OvmfPkg/VirtioFsDxe/FuseRead.c @@ -0,0 +1,191 @@ +/** @file + FUSE_READ / FUSE_READDIRPLUS wrapper for the Virtio Filesystem device. + + Copyright (C) 2020, Red Hat, Inc. + + SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#include "VirtioFsDxe.h" + +/** + Read a chunk from a regular file or a directory stream, by sending the + FUSE_READ / FUSE_READDIRPLUS request to the Virtio Filesystem device. + + The function may only be called after VirtioFsFuseInitSession() returns + successfully and before VirtioFsUninit() is called. + + @param[in,out] VirtioFs The Virtio Filesystem device to send the FUSE_R= EAD + or FUSE_READDIRPLUS request to. On output, the = FUSE + request counter "VirtioFs->RequestId" will have= been + incremented. + + @param[in] NodeId The inode number of the regular file or directo= ry + stream to read from. + + @param[in] FuseHandle The open handle to the regular file or directory + stream to read from. + + @param[in] IsDir TRUE if NodeId and FuseHandle refer to a direct= ory, + FALSE if NodeId and FuseHandle refer to a regul= ar + file. + + @param[in] Offset If IsDir is FALSE: the absolute file position at + which to start reading. + + If IsDir is TRUE: the directory stream cookie at + which to start or continue reading. The zero-va= lued + cookie identifies the start of the directory st= ream. + Further positions in the directory stream can be + passed in from the CookieForNextEntry field of + VIRTIO_FS_FUSE_DIRENTPLUS_RESPONSE. + + @param[in,out] Size On input, the number of bytes to read. On succe= ssful + return, the number of bytes actually read, whic= h may + be smaller than the value on input. + + When reading a regular file (i.e., when IsDir is + FALSE), EOF can be detected by passing in a non= zero + Size, and finding a zero Size on output. + + When reading a directory stream (i.e., when IsD= ir is + TRUE), Data consists of a sequence of variably-= sized + records (directory entries). A read operation + returns the maximal sequence of records that fi= ts in + Size, without having to truncate a record. In o= rder + to guarantee progress, call + + VirtioFsFuseStatFs (VirtioFs, NodeId, + &FilesysAttr) + + first, to learn the maximum Namelen for the + directory stream. Then assign Size at least + + VIRTIO_FS_FUSE_DIRENTPLUS_RESPONSE_SIZE ( + FilesysAttr.Namelen) + + on input. (Remember that + VIRTIO_FS_FUSE_DIRENTPLUS_RESPONSE_SIZE() may r= eturn + 0 if its Namelen argument is invalid.) EOF can = be + detected if Size is set on input like described + above, and Size is zero on output. + + @param[out] Data Buffer to read the bytes from the regular file = or + the directory stream into. The caller is respon= sible + for providing room for (at least) as many bytes= in + Data as Size is on input. + + @retval EFI_SUCCESS Read successful. The caller is responsible for chec= king + Size to learn the actual byte count transferred. + + @return The "errno" value mapped to an EFI_STATUS code, if = the + Virtio Filesystem device explicitly reported an err= or. + + @return Error codes propagated from VirtioFsSgListsValidate= (), + VirtioFsFuseNewRequest(), VirtioFsSgListsSubmit(), + VirtioFsFuseCheckResponse(). +**/ +EFI_STATUS +VirtioFsFuseReadFileOrDir ( + IN OUT VIRTIO_FS *VirtioFs, + IN UINT64 NodeId, + IN UINT64 FuseHandle, + IN BOOLEAN IsDir, + IN UINT64 Offset, + IN OUT UINT32 *Size, + OUT VOID *Data + ) +{ + VIRTIO_FS_FUSE_REQUEST CommonReq; + VIRTIO_FS_FUSE_READ_REQUEST ReadReq; + VIRTIO_FS_IO_VECTOR ReqIoVec[2]; + VIRTIO_FS_SCATTER_GATHER_LIST ReqSgList; + VIRTIO_FS_FUSE_RESPONSE CommonResp; + VIRTIO_FS_IO_VECTOR RespIoVec[2]; + VIRTIO_FS_SCATTER_GATHER_LIST RespSgList; + EFI_STATUS Status; + UINTN TailBufferFill; + + // + // Set up the scatter-gather lists. + // + ReqIoVec[0].Buffer =3D &CommonReq; + ReqIoVec[0].Size =3D sizeof CommonReq; + ReqIoVec[1].Buffer =3D &ReadReq; + ReqIoVec[1].Size =3D sizeof ReadReq; + ReqSgList.IoVec =3D ReqIoVec; + ReqSgList.NumVec =3D ARRAY_SIZE (ReqIoVec); + + RespIoVec[0].Buffer =3D &CommonResp; + RespIoVec[0].Size =3D sizeof CommonResp; + RespIoVec[1].Buffer =3D Data; + RespIoVec[1].Size =3D *Size; + RespSgList.IoVec =3D RespIoVec; + RespSgList.NumVec =3D ARRAY_SIZE (RespIoVec); + + // + // Validate the scatter-gather lists; calculate the total transfer sizes. + // + Status =3D VirtioFsSgListsValidate (VirtioFs, &ReqSgList, &RespSgList); + if (EFI_ERROR (Status)) { + return Status; + } + + // + // Populate the common request header. + // + Status =3D VirtioFsFuseNewRequest ( + VirtioFs, + &CommonReq, + ReqSgList.TotalSize, + IsDir ? VirtioFsFuseOpReadDirPlus : VirtioFsFuseOpRead, + NodeId + ); + if (EFI_ERROR (Status)) { + return Status; + } + + // + // Populate the FUSE_READ- / FUSE_READDIRPLUS-specific fields. + // + ReadReq.FileHandle =3D FuseHandle; + ReadReq.Offset =3D Offset; + ReadReq.Size =3D *Size; + ReadReq.ReadFlags =3D 0; + ReadReq.LockOwner =3D 0; + ReadReq.Flags =3D 0; + ReadReq.Padding =3D 0; + + // + // Submit the request. + // + Status =3D VirtioFsSgListsSubmit (VirtioFs, &ReqSgList, &RespSgList); + if (EFI_ERROR (Status)) { + return Status; + } + + // + // Verify the response. Note that TailBufferFill is variable. + // + Status =3D VirtioFsFuseCheckResponse (&RespSgList, CommonReq.Unique, + &TailBufferFill); + if (EFI_ERROR (Status)) { + if (Status =3D=3D EFI_DEVICE_ERROR) { + DEBUG ((DEBUG_ERROR, "%a: Label=3D\"%s\" NodeId=3D%Lu FuseHandle=3D%= Lu " + "IsDir=3D%d Offset=3D0x%Lx Size=3D0x%x Data@%p Errno=3D%d\n", __FU= NCTION__, + VirtioFs->Label, NodeId, FuseHandle, IsDir, Offset, *Size, Data, + CommonResp.Error)); + Status =3D VirtioFsErrnoToEfiStatus (CommonResp.Error); + } + return Status; + } + + // + // Report the actual transfer size. + // + // Integer overflow in the (UINT32) cast below is not possible; the + // VIRTIO_FS_SCATTER_GATHER_LIST functions would have caught that. + // + *Size =3D (UINT32)TailBufferFill; + return EFI_SUCCESS; +} --=20 2.19.1.3.g30247aa5d201 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#69046): https://edk2.groups.io/g/devel/message/69046 Mute This Topic: https://groups.io/mt/79023967/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Tue May 7 07:56:31 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+69047+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+69047+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1608157268; cv=none; d=zohomail.com; s=zohoarc; b=Or/Kp2hJZUHCSNnlgcpeLbK7fwkH2bRETH96KaYa4mT5usJV6YBwOnz5hNmmhSg9+1TiQy/V+Xvwb4jYnfUjbEnH6H29G/K7DiW3lFMcIEtWeXG50Omli3yF/WTk89OOiCq1wYeFx7AADE4LHAFQXNCTl4tqyn1MfzEogT6gw3E= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608157268; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=MHAK8POlNjkxVLImCuJSmCR8GyZKDsd5UtGprm5208o=; b=f/Ifi8bQdRf1nFW5wft9GgwqOj7JjosNc0VOpzfdtzSaNqzVxTprQEVEtsEiYVj286uZ7CpQz8leBvUdNyedXWBANhT+jKGkpUPPlMBTej0yzGmugzFFeNbfiURY9e+Qa5BNwdDfWLhB5DtzaflQpD3U4l9tmIZVEybwCTDZkFE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+69047+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) header.from= Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1608157268620114.26571760075592; Wed, 16 Dec 2020 14:21:08 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id wi5sYY1788612xRM0utNeNnf; Wed, 16 Dec 2020 14:21:08 -0800 X-Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.groups.io with SMTP id smtpd.web12.4700.1608157267638574032 for ; Wed, 16 Dec 2020 14:21:07 -0800 X-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-173-qY4bri3EP2Otk8DzLTqHFg-1; Wed, 16 Dec 2020 17:21:05 -0500 X-MC-Unique: qY4bri3EP2Otk8DzLTqHFg-1 X-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 0EBC48145EE; Wed, 16 Dec 2020 22:21:04 +0000 (UTC) X-Received: from lacos-laptop-7.usersys.redhat.com (ovpn-114-152.ams2.redhat.com [10.36.114.152]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7618260843; Wed, 16 Dec 2020 22:20:59 +0000 (UTC) From: "Laszlo Ersek" To: devel@edk2.groups.io, virtio-fs@redhat.com, lersek@redhat.com Cc: Ard Biesheuvel , Jordan Justen , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [edk2-devel] [edk2 PATCH 33/48] OvmfPkg/VirtioFsDxe: implement EFI_FILE_PROTOCOL.Read() for regular files Date: Wed, 16 Dec 2020 22:11:10 +0100 Message-Id: <20201216211125.19496-34-lersek@redhat.com> In-Reply-To: <20201216211125.19496-1-lersek@redhat.com> References: <20201216211125.19496-1-lersek@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,lersek@redhat.com X-Gm-Message-State: ELiRqNG58eMkgyksHLhNPXNnx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1608157268; bh=MHAK8POlNjkxVLImCuJSmCR8GyZKDsd5UtGprm5208o=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=lX5rME1ZQ1NzPzHT1u+vVX5fwikIIIK9JyIvD3G+kunE3XBBCL4KPbcaMumAFIi9Axc IrPDmzCQX3wRasfaNPFInzRKmW4L7zIMx24KzTU0CbKKlndU/YRPGZK7R0bB/jDtHGJlr qFPDUqizYiQsu9MtGiG8Dc26sgpWKWPSdv0= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" Using the functions introduced previously, we can now implement VirtioFsSimpleFileRead(); for regular files at first. Cc: Ard Biesheuvel Cc: Jordan Justen Cc: Philippe Mathieu-Daud=C3=A9 Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3097 Signed-off-by: Laszlo Ersek Acked-by: Ard Biesheuvel --- OvmfPkg/VirtioFsDxe/SimpleFsRead.c | 75 +++++++++++++++++++- 1 file changed, 74 insertions(+), 1 deletion(-) diff --git a/OvmfPkg/VirtioFsDxe/SimpleFsRead.c b/OvmfPkg/VirtioFsDxe/Simpl= eFsRead.c index e737d5e33204..c4ad07c9aec4 100644 --- a/OvmfPkg/VirtioFsDxe/SimpleFsRead.c +++ b/OvmfPkg/VirtioFsDxe/SimpleFsRead.c @@ -3,18 +3,91 @@ =20 Copyright (C) 2020, Red Hat, Inc. =20 SPDX-License-Identifier: BSD-2-Clause-Patent **/ =20 #include "VirtioFsDxe.h" =20 +/** + Read from a regular file. +**/ +STATIC +EFI_STATUS +ReadRegularFile ( + IN OUT VIRTIO_FS_FILE *VirtioFsFile, + IN OUT UINTN *BufferSize, + OUT VOID *Buffer + ) +{ + VIRTIO_FS *VirtioFs; + EFI_STATUS Status; + VIRTIO_FS_FUSE_ATTRIBUTES_RESPONSE FuseAttr; + UINTN Transferred; + UINTN Left; + + VirtioFs =3D VirtioFsFile->OwnerFs; + // + // The UEFI spec forbids reads that start beyond the end of the file. + // + Status =3D VirtioFsFuseGetAttr (VirtioFs, VirtioFsFile->NodeId, &FuseAtt= r); + if (EFI_ERROR (Status) || VirtioFsFile->FilePosition > FuseAttr.Size) { + return EFI_DEVICE_ERROR; + } + + Status =3D EFI_SUCCESS; + Transferred =3D 0; + Left =3D *BufferSize; + while (Left > 0) { + UINT32 ReadSize; + + // + // FUSE_READ cannot express a >=3D4GB buffer size. + // + ReadSize =3D (UINT32)MIN ((UINTN)MAX_UINT32, Left); + Status =3D VirtioFsFuseReadFileOrDir ( + VirtioFs, + VirtioFsFile->NodeId, + VirtioFsFile->FuseHandle, + FALSE, // IsDir + VirtioFsFile->FilePosition + Transferred, + &ReadSize, + (UINT8 *)Buffer + Transferred + ); + if (EFI_ERROR (Status) || ReadSize =3D=3D 0) { + break; + } + Transferred +=3D ReadSize; + Left -=3D ReadSize; + } + + *BufferSize =3D Transferred; + VirtioFsFile->FilePosition +=3D Transferred; + // + // If we managed to read some data, return success. If zero bytes were + // transferred due to zero-sized buffer on input or due to EOF on first = read, + // return SUCCESS. Otherwise, return the error due to which zero bytes w= ere + // transferred. + // + return (Transferred > 0) ? EFI_SUCCESS : Status; +} + EFI_STATUS EFIAPI VirtioFsSimpleFileRead ( IN EFI_FILE_PROTOCOL *This, IN OUT UINTN *BufferSize, OUT VOID *Buffer ) { - return EFI_NO_MEDIA; + VIRTIO_FS_FILE *VirtioFsFile; + EFI_STATUS Status; + + VirtioFsFile =3D VIRTIO_FS_FILE_FROM_SIMPLE_FILE (This); + + if (VirtioFsFile->IsDirectory) { + Status =3D EFI_NO_MEDIA; + } else { + Status =3D ReadRegularFile (VirtioFsFile, BufferSize, Buffer); + } + return Status; } --=20 2.19.1.3.g30247aa5d201 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#69047): https://edk2.groups.io/g/devel/message/69047 Mute This Topic: https://groups.io/mt/79024007/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Tue May 7 07:56:31 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+69048+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+69048+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1608157399; cv=none; d=zohomail.com; s=zohoarc; b=X1gkW1+1iw70l877rssmXq466sSwX20QaOhs4bws9PBFD847lz5yiLuMG1w1Wk47wfDBbNveT9jOYanGUg9Tgulba8ezp0V6OzCnr/iArr3XrAo5cEXCAbyxVsphz19KsKmUFd3OWQA0sB/PywvUjy4aVtU7ZBVGWvD+1YyZngM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608157399; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=ngu3uj+2q/6ZwnvVfVEx/doysl+i5ZL+9ebEEiDc7Mc=; b=E1QP+LwLbiTSxAJZfOIMpFHVk52gWxTv5iJyuAvlIUnwKTWvM5O4I2a8dupxOvQIKR+LNPDXwefLJfAtswAmuvds4nq/rsPUdwMqRyJ3GNCHWXsLJBwOFzqmgh4lPtN/BEKHdOddtzJAzP75ieCC3FgqkJUi2WNchLBYby2DbqM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+69048+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) header.from= Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1608157399650209.90723486476963; Wed, 16 Dec 2020 14:23:19 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id V0yuYY1788612xPPnn9coSLk; Wed, 16 Dec 2020 14:23:19 -0800 X-Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.groups.io with SMTP id smtpd.web12.4736.1608157393751484524 for ; Wed, 16 Dec 2020 14:23:13 -0800 X-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-16-Glt2OX7WMQSDiIo9kQ7bzQ-1; Wed, 16 Dec 2020 17:23:10 -0500 X-MC-Unique: Glt2OX7WMQSDiIo9kQ7bzQ-1 X-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 CCB43107ACE6; Wed, 16 Dec 2020 22:23:09 +0000 (UTC) X-Received: from lacos-laptop-7.usersys.redhat.com (ovpn-114-152.ams2.redhat.com [10.36.114.152]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2666A5D9C0; Wed, 16 Dec 2020 22:23:04 +0000 (UTC) From: "Laszlo Ersek" To: devel@edk2.groups.io, virtio-fs@redhat.com, lersek@redhat.com Cc: Ard Biesheuvel , Jordan Justen , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [edk2-devel] [edk2 PATCH 34/48] OvmfPkg/VirtioFsDxe: convert FUSE dirent filename to EFI_FILE_INFO Date: Wed, 16 Dec 2020 22:11:11 +0100 Message-Id: <20201216211125.19496-35-lersek@redhat.com> In-Reply-To: <20201216211125.19496-1-lersek@redhat.com> References: <20201216211125.19496-1-lersek@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,lersek@redhat.com X-Gm-Message-State: i1nkRZsh4lAHqXayzgcx4uIex1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1608157399; bh=ngu3uj+2q/6ZwnvVfVEx/doysl+i5ZL+9ebEEiDc7Mc=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=Ai/KkUTfFlPXwrIfpvqy9Jyz7vxu4+Jqr+Q5X/os/rAXmvPjCREQ06YL2RKH0J16bRp 7ZcOgSqfuCaj6zQbNfhv082aN+xZoWhbwKf4tO9ZSCU515AyEmUzZAo6T6QM4dY7ohddw Gqp7zgYyvCvp7UyHJyKJ8orhv75e7BynpDo= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" Introduce the VirtioFsFuseDirentPlusToEfiFileInfo() function, for converting the VIRTIO_FS_FUSE_DIRENTPLUS_RESPONSE filename byte array to EFI_FILE_INFO. This new function updates those EFI_FILE_INFO fields (Size, FileName) that the earlier helper function VirtioFsFuseAttrToEfiFileInfo() does not set. Both functions together will be able to fill in EFI_FILE_INFO completely, from FUSE_READDIRPLUS. Cc: Ard Biesheuvel Cc: Jordan Justen Cc: Philippe Mathieu-Daud=C3=A9 Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3097 Signed-off-by: Laszlo Ersek Acked-by: Ard Biesheuvel --- OvmfPkg/VirtioFsDxe/VirtioFsDxe.h | 6 ++ OvmfPkg/VirtioFsDxe/Helpers.c | 79 ++++++++++++++++++++ 2 files changed, 85 insertions(+) diff --git a/OvmfPkg/VirtioFsDxe/VirtioFsDxe.h b/OvmfPkg/VirtioFsDxe/Virtio= FsDxe.h index f5501af7d0a4..2b419048c232 100644 --- a/OvmfPkg/VirtioFsDxe/VirtioFsDxe.h +++ b/OvmfPkg/VirtioFsDxe/VirtioFsDxe.h @@ -243,16 +243,22 @@ VirtioFsGetBasename ( ); =20 EFI_STATUS VirtioFsFuseAttrToEfiFileInfo ( IN VIRTIO_FS_FUSE_ATTRIBUTES_RESPONSE *FuseAttr, OUT EFI_FILE_INFO *FileInfo ); =20 +EFI_STATUS +VirtioFsFuseDirentPlusToEfiFileInfo ( + IN VIRTIO_FS_FUSE_DIRENTPLUS_RESPONSE *FuseDirent, + IN OUT EFI_FILE_INFO *FileInfo + ); + // // Wrapper functions for FUSE commands (primitives). // =20 EFI_STATUS VirtioFsFuseLookup ( IN OUT VIRTIO_FS *VirtioFs, IN UINT64 DirNodeId, diff --git a/OvmfPkg/VirtioFsDxe/Helpers.c b/OvmfPkg/VirtioFsDxe/Helpers.c index 77f718e91233..cdaa8557a17b 100644 --- a/OvmfPkg/VirtioFsDxe/Helpers.c +++ b/OvmfPkg/VirtioFsDxe/Helpers.c @@ -1895,8 +1895,87 @@ VirtioFsFuseAttrToEfiFileInfo ( // A hard link count greater than 1 is not supported for regular files. // if ((FileInfo->Attribute & EFI_FILE_DIRECTORY) =3D=3D 0 && FuseAttr->Nli= nk > 1) { return EFI_UNSUPPORTED; } =20 return EFI_SUCCESS; } + +/** + Convert a VIRTIO_FS_FUSE_DIRENTPLUS_RESPONSE filename to an EFI_FILE_INFO + filename. + + @param[in] FuseDirent The VIRTIO_FS_FUSE_DIRENTPLUS_RESPONSE object to + convert the filename byte array from. The calle= r is + responsible for ensuring that FuseDirent->Namel= en + describe valid storage. + + @param[in,out] FileInfo The EFI_FILE_INFO structure to modify. On input= , the + caller is responsible for setting FileInfo->Size + according to the allocated size. On successful + return, FileInfo->Size is reduced to reflect the + filename converted into FileInfo->FileName. + FileInfo->FileName is set from the filename byte + array that directly follows the FuseDirent head= er + object. Fields other than FileInfo->Size and + FileInfo->FileName are not modified. + + @retval EFI_SUCCESS Conversion successful. + + @retval EFI_INVALID_PARAMETER VIRTIO_FS_FUSE_DIRENTPLUS_RESPONSE_SIZE() + returns zero for FuseDirent->Namelen. + + @retval EFI_BUFFER_TOO_SMALL On input, FileInfo->Size does not provide + enough room for converting the filename b= yte + array from FuseDirent. + + @retval EFI_UNSUPPORTED The FuseDirent filename byte array contai= ns a + byte that falls outside of the printable = ASCII + range, or is a forward slash or a backsla= sh. +**/ +EFI_STATUS +VirtioFsFuseDirentPlusToEfiFileInfo ( + IN VIRTIO_FS_FUSE_DIRENTPLUS_RESPONSE *FuseDirent, + IN OUT EFI_FILE_INFO *FileInfo + ) +{ + UINTN DirentSize; + UINTN FileInfoSize; + UINT8 *DirentName; + UINT32 Idx; + + DirentSize =3D VIRTIO_FS_FUSE_DIRENTPLUS_RESPONSE_SIZE (FuseDirent->Name= len); + if (DirentSize =3D=3D 0) { + return EFI_INVALID_PARAMETER; + } + // + // We're now safe from overflow in the calculation below. + // + FileInfoSize =3D (OFFSET_OF (EFI_FILE_INFO, FileName) + + ((UINTN)FuseDirent->Namelen + 1) * sizeof (CHAR16)); + if (FileInfoSize > FileInfo->Size) { + return EFI_BUFFER_TOO_SMALL; + } + + // + // Convert the name. + // + DirentName =3D (UINT8 *)(FuseDirent + 1); + for (Idx =3D 0; Idx < FuseDirent->Namelen; Idx++) { + UINT8 NameByte; + + NameByte =3D DirentName[Idx]; + if (NameByte < 0x20 || NameByte > 0x7E || + NameByte =3D=3D '/' || NameByte =3D=3D '\\') { + return EFI_UNSUPPORTED; + } + FileInfo->FileName[Idx] =3D (CHAR16)NameByte; + } + FileInfo->FileName[Idx++] =3D L'\0'; + // + // Set the (possibly reduced) size. + // + FileInfo->Size =3D FileInfoSize; + + return EFI_SUCCESS; +} --=20 2.19.1.3.g30247aa5d201 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#69048): https://edk2.groups.io/g/devel/message/69048 Mute This Topic: https://groups.io/mt/79024054/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Tue May 7 07:56:31 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+69049+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+69049+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1608157522; cv=none; d=zohomail.com; s=zohoarc; b=Bct1NGhpGzGWy/5B9ajik2nimFp37HDramhFI78Qf4on5WDqubnPnQV3bTpTL3K5tGCbVAzXljEx5IfEyqOJX5lWvgpUFz9ZTEGJZXroQl0VbU3+eaDxkCHlhhrnerMFKNUtgxHibvW8rkEAVdUoiofSrOLmTuAPk9nft5I3i6c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608157522; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=NZ8ckHFh6VcTKUOA6ufQwF++LVrh3HGeqkBUtI5eV4c=; b=QcEG8tbM2fBapt2JPDXEemgLAU9OLjXYsvRe5VhLqeuyfKgZ7amiRA0ZeqCiw5ujsExbwGUu2EqGHsqKVDruknDp5uWF0Ubki1DBQERy0KcGGuL40TFCo7vRrAZy4zXb45JUW+Hquvars/aEsiy56VuwGe9bBZ6fXYZ/AjejjwA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+69049+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) header.from= Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1608157522861295.23488843111033; Wed, 16 Dec 2020 14:25:22 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id 0y4AYY1788612xEsWF0z7yXk; Wed, 16 Dec 2020 14:25:22 -0800 X-Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.groups.io with SMTP id smtpd.web11.4630.1608157521461124037 for ; Wed, 16 Dec 2020 14:25:21 -0800 X-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-98-fz5Pf_FWP8izqGsOFadn1A-1; Wed, 16 Dec 2020 17:25:16 -0500 X-MC-Unique: fz5Pf_FWP8izqGsOFadn1A-1 X-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 BAFD459; Wed, 16 Dec 2020 22:25:15 +0000 (UTC) X-Received: from lacos-laptop-7.usersys.redhat.com (ovpn-114-152.ams2.redhat.com [10.36.114.152]) by smtp.corp.redhat.com (Postfix) with ESMTP id F17D360CD2; Wed, 16 Dec 2020 22:25:10 +0000 (UTC) From: "Laszlo Ersek" To: devel@edk2.groups.io, virtio-fs@redhat.com, lersek@redhat.com Cc: Ard Biesheuvel , Jordan Justen , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [edk2-devel] [edk2 PATCH 35/48] OvmfPkg/VirtioFsDxe: add EFI_FILE_INFO cache fields to VIRTIO_FS_FILE Date: Wed, 16 Dec 2020 22:11:12 +0100 Message-Id: <20201216211125.19496-36-lersek@redhat.com> In-Reply-To: <20201216211125.19496-1-lersek@redhat.com> References: <20201216211125.19496-1-lersek@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,lersek@redhat.com X-Gm-Message-State: a0O9ZURHiiTXRu0E2KlQE1rwx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1608157522; bh=NZ8ckHFh6VcTKUOA6ufQwF++LVrh3HGeqkBUtI5eV4c=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=gEjNuxU1UW15R/fLy9KO8LyRyTzA9L6x86YEXHNhx65GS7Say2TNchTZKudDOlz8+dv 2Oo2Bubqij/Sa5wYQ4Tqdj9nTRqIfSwip89F4XpWXWslhKeRAHXUb0HmRrf0zOdQytDoV mPIP77zqhS0iKb/HQKOyJffOREROHgD1h5o= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" For reading through a directory stream with tolerable performance, we'll have to call FUSE_READDIRPLUS each time with such a buffer that can deliver a good number of variable size records (VIRTIO_FS_FUSE_DIRENTPLUS_RESPONSE elements). Every time we'll do that, we'll turn the whole bunch into an array of EFI_FILE_INFOs immediately. EFI_FILE_PROTOCOL.Read() invocations (on directories) will be served from this EFI_FILE_INFO cache. Add the fields for the EFI_FILE_INFO cache to VIRTIO_FS_FILE: - initialize them in Open() and OpenVolume(), - release the cache in Close() and Delete(), - also release the cache when the directory is rewound, in SetPosition(). Cc: Ard Biesheuvel Cc: Jordan Justen Cc: Philippe Mathieu-Daud=C3=A9 Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3097 Signed-off-by: Laszlo Ersek Acked-by: Ard Biesheuvel --- OvmfPkg/VirtioFsDxe/VirtioFsDxe.h | 19 +++++++++++++++++++ OvmfPkg/VirtioFsDxe/SimpleFsClose.c | 3 +++ OvmfPkg/VirtioFsDxe/SimpleFsDelete.c | 3 +++ OvmfPkg/VirtioFsDxe/SimpleFsOpen.c | 4 ++++ OvmfPkg/VirtioFsDxe/SimpleFsOpenVolume.c | 4 ++++ OvmfPkg/VirtioFsDxe/SimpleFsSetPosition.c | 9 +++++++++ 6 files changed, 42 insertions(+) diff --git a/OvmfPkg/VirtioFsDxe/VirtioFsDxe.h b/OvmfPkg/VirtioFsDxe/Virtio= FsDxe.h index 2b419048c232..a704acdd520e 100644 --- a/OvmfPkg/VirtioFsDxe/VirtioFsDxe.h +++ b/OvmfPkg/VirtioFsDxe/VirtioFsDxe.h @@ -42,16 +42,21 @@ // // The limit is not expected to be a practical limitation; it's only suppo= sed // to prevent attempts at overflowing size calculations. For both kinds of // pathnames, separate limits could be used; a common limit is used purely= for // simplicity. // #define VIRTIO_FS_MAX_PATHNAME_LENGTH ((UINTN)65535) =20 +// +// Maximum value for VIRTIO_FS_FILE.NumFileInfo. +// +#define VIRTIO_FS_FILE_MAX_FILE_INFO 256 + // // Filesystem label encoded in UCS-2, transformed from the UTF-8 represent= ation // in "VIRTIO_FS_CONFIG.Tag", and NUL-terminated. Only the printable ASCII= code // points (U+0020 through U+007E) are supported. // typedef CHAR16 VIRTIO_FS_LABEL[VIRTIO_FS_TAG_BYTES + 1]; =20 // @@ -149,16 +154,30 @@ typedef struct { // VIRTIO_FS_FILE object is created, primarily defined by its NodeId fie= ld, // we also *open* the referenced file at once, and save the returned file // handle in the FuseHandle field. This way, when an EFI_FILE_PROTOCOL m= ember // function must send a FUSE request that needs the file handle *in addi= tion* // to the inode number, FuseHandle will be at our disposal at once. // UINT64 NodeId; UINT64 FuseHandle; + // + // EFI_FILE_INFO objects cached for an in-flight directory read. + // + // For reading through a directory stream with tolerable performance, we= have + // to call FUSE_READDIRPLUS each time with such a buffer that can delive= r a + // good number of variable size records (VIRTIO_FS_FUSE_DIRENTPLUS_RESPO= NSE + // elements). Every time we do that, we turn the whole bunch into an arr= ay of + // EFI_FILE_INFOs immediately. EFI_FILE_PROTOCOL.Read() invocations (on + // directories) will be served from this EFI_FILE_INFO cache. + // + UINT8 *FileInfoArray; + UINTN SingleFileInfoSize; + UINTN NumFileInfo; + UINTN NextFileInfo; } VIRTIO_FS_FILE; =20 #define VIRTIO_FS_FILE_FROM_SIMPLE_FILE(SimpleFileReference) \ CR (SimpleFileReference, VIRTIO_FS_FILE, SimpleFile, VIRTIO_FS_FILE_SIG); =20 #define VIRTIO_FS_FILE_FROM_OPEN_FILES_ENTRY(OpenFilesEntryReference) \ CR (OpenFilesEntryReference, VIRTIO_FS_FILE, OpenFilesEntry, \ VIRTIO_FS_FILE_SIG); diff --git a/OvmfPkg/VirtioFsDxe/SimpleFsClose.c b/OvmfPkg/VirtioFsDxe/Simp= leFsClose.c index 04b4f2c382d7..4c1cf52112ce 100644 --- a/OvmfPkg/VirtioFsDxe/SimpleFsClose.c +++ b/OvmfPkg/VirtioFsDxe/SimpleFsClose.c @@ -55,11 +55,14 @@ VirtioFsSimpleFileClose ( } =20 // // One fewer file left open for the owner filesystem. // RemoveEntryList (&VirtioFsFile->OpenFilesEntry); =20 FreePool (VirtioFsFile->CanonicalPathname); + if (VirtioFsFile->FileInfoArray !=3D NULL) { + FreePool (VirtioFsFile->FileInfoArray); + } FreePool (VirtioFsFile); return EFI_SUCCESS; } diff --git a/OvmfPkg/VirtioFsDxe/SimpleFsDelete.c b/OvmfPkg/VirtioFsDxe/Sim= pleFsDelete.c index 76cfee5bceb1..76a868b3c24d 100644 --- a/OvmfPkg/VirtioFsDxe/SimpleFsDelete.c +++ b/OvmfPkg/VirtioFsDxe/SimpleFsDelete.c @@ -97,11 +97,14 @@ VirtioFsSimpleFileDelete ( } =20 // // One fewer file left open for the owner filesystem. // RemoveEntryList (&VirtioFsFile->OpenFilesEntry); =20 FreePool (VirtioFsFile->CanonicalPathname); + if (VirtioFsFile->FileInfoArray !=3D NULL) { + FreePool (VirtioFsFile->FileInfoArray); + } FreePool (VirtioFsFile); return Status; } diff --git a/OvmfPkg/VirtioFsDxe/SimpleFsOpen.c b/OvmfPkg/VirtioFsDxe/Simpl= eFsOpen.c index 7c50ce9c0e76..d73d23fe8665 100644 --- a/OvmfPkg/VirtioFsDxe/SimpleFsOpen.c +++ b/OvmfPkg/VirtioFsDxe/SimpleFsOpen.c @@ -477,16 +477,20 @@ VirtioFsSimpleFileOpen ( NewVirtioFsFile->SimpleFile.Flush =3D VirtioFsSimpleFileFlush; NewVirtioFsFile->IsDirectory =3D NewNodeIsDirectory; NewVirtioFsFile->IsOpenForWriting =3D OpenForWriting; NewVirtioFsFile->OwnerFs =3D VirtioFs; NewVirtioFsFile->CanonicalPathname =3D NewCanonicalPath; NewVirtioFsFile->FilePosition =3D 0; NewVirtioFsFile->NodeId =3D NewNodeId; NewVirtioFsFile->FuseHandle =3D NewFuseHandle; + NewVirtioFsFile->FileInfoArray =3D NULL; + NewVirtioFsFile->SingleFileInfoSize =3D 0; + NewVirtioFsFile->NumFileInfo =3D 0; + NewVirtioFsFile->NextFileInfo =3D 0; =20 // // One more file is now open for the filesystem. // InsertTailList (&VirtioFs->OpenFiles, &NewVirtioFsFile->OpenFilesEntry); =20 *NewHandle =3D &NewVirtioFsFile->SimpleFile; return EFI_SUCCESS; diff --git a/OvmfPkg/VirtioFsDxe/SimpleFsOpenVolume.c b/OvmfPkg/VirtioFsDxe= /SimpleFsOpenVolume.c index 1181191d271b..058e7a41ab03 100644 --- a/OvmfPkg/VirtioFsDxe/SimpleFsOpenVolume.c +++ b/OvmfPkg/VirtioFsDxe/SimpleFsOpenVolume.c @@ -70,16 +70,20 @@ VirtioFsOpenVolume ( VirtioFsFile->SimpleFile.Flush =3D VirtioFsSimpleFileFlush; VirtioFsFile->IsDirectory =3D TRUE; VirtioFsFile->IsOpenForWriting =3D FALSE; VirtioFsFile->OwnerFs =3D VirtioFs; VirtioFsFile->CanonicalPathname =3D CanonicalPathname; VirtioFsFile->FilePosition =3D 0; VirtioFsFile->NodeId =3D VIRTIO_FS_FUSE_ROOT_DIR_NODE_ID; VirtioFsFile->FuseHandle =3D RootDirHandle; + VirtioFsFile->FileInfoArray =3D NULL; + VirtioFsFile->SingleFileInfoSize =3D 0; + VirtioFsFile->NumFileInfo =3D 0; + VirtioFsFile->NextFileInfo =3D 0; =20 // // One more file open for the filesystem. // InsertTailList (&VirtioFs->OpenFiles, &VirtioFsFile->OpenFilesEntry); =20 *Root =3D &VirtioFsFile->SimpleFile; return EFI_SUCCESS; diff --git a/OvmfPkg/VirtioFsDxe/SimpleFsSetPosition.c b/OvmfPkg/VirtioFsDx= e/SimpleFsSetPosition.c index ac6285302652..a548012d9c09 100644 --- a/OvmfPkg/VirtioFsDxe/SimpleFsSetPosition.c +++ b/OvmfPkg/VirtioFsDxe/SimpleFsSetPosition.c @@ -2,16 +2,18 @@ EFI_FILE_PROTOCOL.SetPosition() member function for the Virtio Filesystem driver. =20 Copyright (C) 2020, Red Hat, Inc. =20 SPDX-License-Identifier: BSD-2-Clause-Patent **/ =20 +#include // FreePool() + #include "VirtioFsDxe.h" =20 EFI_STATUS EFIAPI VirtioFsSimpleFileSetPosition ( IN EFI_FILE_PROTOCOL *This, IN UINT64 Position ) @@ -26,16 +28,23 @@ VirtioFsSimpleFileSetPosition ( // // Directories can only be rewound, per spec. // if (VirtioFsFile->IsDirectory) { if (Position !=3D 0) { return EFI_UNSUPPORTED; } VirtioFsFile->FilePosition =3D 0; + if (VirtioFsFile->FileInfoArray !=3D NULL) { + FreePool (VirtioFsFile->FileInfoArray); + VirtioFsFile->FileInfoArray =3D NULL; + } + VirtioFsFile->SingleFileInfoSize =3D 0; + VirtioFsFile->NumFileInfo =3D 0; + VirtioFsFile->NextFileInfo =3D 0; return EFI_SUCCESS; } =20 // // Regular file. // if (Position < MAX_UINT64) { // --=20 2.19.1.3.g30247aa5d201 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#69049): https://edk2.groups.io/g/devel/message/69049 Mute This Topic: https://groups.io/mt/79024111/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Tue May 7 07:56:31 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+69050+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+69050+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1608157646; cv=none; d=zohomail.com; s=zohoarc; b=KPcLSVpffMPgvSFb9306uD50XUqbbLpwOCeGYWv8zGJAhcy96LxU8ErAgwTYXwxqoLbWeG0I0U4HkN5km0rrzvD6h25OYSMb+B/bm1Kx6fnfTsEcBEP64BnSB4VjXSVKey27XR4UkDpifWo0XEMo000dXYYGACPL3RpDCA++CuY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608157646; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=G3YnKevy7aWVDSx1a6rVftvkVB4K75p1vmuntXmW8qE=; b=j9WNyJuAyQwIsovYZiMKPwFHPyrXFbvn9++4m6lS4iqpC8ficNNpGaLN/1WwEBL9QPbrhsz/a9sSc7Gz2+iNRljfgx8u+nPG7sLRlU+8T6IyE6/od3OVeLO+2ukU/kSF2JtwYxLzRPBYkxok9ymlkmO2OYr3Z+66/d9Fk7LI7U4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+69050+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) header.from= Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1608157646579964.0066777104219; Wed, 16 Dec 2020 14:27:26 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id cXRdYY1788612xH1nSfTrLX3; Wed, 16 Dec 2020 14:27:26 -0800 X-Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.groups.io with SMTP id smtpd.web12.4796.1608157645451111499 for ; Wed, 16 Dec 2020 14:27:25 -0800 X-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-391-3cwK6gj8Pn6GMxIjzNij9Q-1; Wed, 16 Dec 2020 17:27:22 -0500 X-MC-Unique: 3cwK6gj8Pn6GMxIjzNij9Q-1 X-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 A7343801817; Wed, 16 Dec 2020 22:27:21 +0000 (UTC) X-Received: from lacos-laptop-7.usersys.redhat.com (ovpn-114-152.ams2.redhat.com [10.36.114.152]) by smtp.corp.redhat.com (Postfix) with ESMTP id D23AE60CC4; Wed, 16 Dec 2020 22:27:16 +0000 (UTC) From: "Laszlo Ersek" To: devel@edk2.groups.io, virtio-fs@redhat.com, lersek@redhat.com Cc: Ard Biesheuvel , Jordan Justen , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [edk2-devel] [edk2 PATCH 36/48] OvmfPkg/VirtioFsDxe: implement EFI_FILE_PROTOCOL.Read() for directories Date: Wed, 16 Dec 2020 22:11:13 +0100 Message-Id: <20201216211125.19496-37-lersek@redhat.com> In-Reply-To: <20201216211125.19496-1-lersek@redhat.com> References: <20201216211125.19496-1-lersek@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,lersek@redhat.com X-Gm-Message-State: T8Jm6ffM8QvZazL3h3oxdFZ0x1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1608157646; bh=G3YnKevy7aWVDSx1a6rVftvkVB4K75p1vmuntXmW8qE=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=bTmWJ0h+WcC6uLBPUfjW0dqwbCSOqmoysjzk20j/CmHO/HmGK0SDKuoWfhRsYdu9KlY xLr8gEE5XDesid0OpJV+soOONvGbZ2Vel+SGgpLNI5JBywa6vwNADzpsOepCExtRYTUZs ehXyKWCMvxDUhptT9DVW3cODWwnwnYPkOFk= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" Using the functions introduced previously, we can now implement VirtioFsSimpleFileRead() for directories as well. This patch completes the read-only support for virtio-fs. Commands like "TYPE" and "DIR" work in the UEFI shell. Cc: Ard Biesheuvel Cc: Jordan Justen Cc: Philippe Mathieu-Daud=C3=A9 Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3097 Signed-off-by: Laszlo Ersek Acked-by: Ard Biesheuvel --- OvmfPkg/VirtioFsDxe/SimpleFsRead.c | 343 +++++++++++++++++++- 1 file changed, 342 insertions(+), 1 deletion(-) diff --git a/OvmfPkg/VirtioFsDxe/SimpleFsRead.c b/OvmfPkg/VirtioFsDxe/Simpl= eFsRead.c index c4ad07c9aec4..d6368342a139 100644 --- a/OvmfPkg/VirtioFsDxe/SimpleFsRead.c +++ b/OvmfPkg/VirtioFsDxe/SimpleFsRead.c @@ -1,18 +1,359 @@ /** @file EFI_FILE_PROTOCOL.Read() member function for the Virtio Filesystem drive= r. =20 Copyright (C) 2020, Red Hat, Inc. =20 SPDX-License-Identifier: BSD-2-Clause-Patent **/ =20 +#include // CopyMem() +#include // AllocatePool() + #include "VirtioFsDxe.h" =20 +/** + Populate a caller-allocated EFI_FILE_INFO object from + VIRTIO_FS_FUSE_DIRENTPLUS_RESPONSE. + + @param[in] Dirent The entry read from the directory stream.= The + caller is responsible for ensuring that + Dirent->Namelen describe valid storage. + + @param[in] SingleFileInfoSize The allocated size of FileInfo. + + @param[out] FileInfo The EFI_FILE_INFO object to populate. On + success, all fields in FileInfo will be + updated, setting FileInfo->Size to the + actually used size (which will not exceed + SingleFileInfoSize). + + @retval EFI_SUCCESS FileInfo has been filled in. + + @return Error codes propagated from + VirtioFsFuseDirentPlusToEfiFileInfo() and + VirtioFsFuseAttrToEfiFileInfo(). The contents of + FileInfo are indeterminate. +**/ +STATIC +EFI_STATUS +PopulateFileInfo ( + IN VIRTIO_FS_FUSE_DIRENTPLUS_RESPONSE *Dirent, + IN UINTN SingleFileInfoSize, + OUT EFI_FILE_INFO *FileInfo + ) +{ + EFI_STATUS Status; + + // + // Convert the name, set the actual size. + // + FileInfo->Size =3D SingleFileInfoSize; + Status =3D VirtioFsFuseDirentPlusToEfiFileInfo (Dirent, FileInfo); + if (EFI_ERROR (Status)) { + return Status; + } + // + // Populate the scalar fields. + // + Status =3D VirtioFsFuseAttrToEfiFileInfo (&Dirent->AttrResp, FileInfo); + return Status; +} + +/** + Refill the EFI_FILE_INFO cache from the directory stream. +**/ +STATIC +EFI_STATUS +RefillFileInfoCache ( + IN OUT VIRTIO_FS_FILE *VirtioFsFile + ) +{ + VIRTIO_FS *VirtioFs; + EFI_STATUS Status; + VIRTIO_FS_FUSE_STATFS_RESPONSE FilesysAttr; + UINT32 DirentBufSize; + UINT8 *DirentBuf; + UINTN SingleFileInfoSize; + UINT8 *FileInfoArray; + UINT64 DirStreamCookie; + UINT64 CacheEndsAtCookie; + UINTN NumFileInfo; + + // + // Allocate a DirentBuf that can receive at least + // VIRTIO_FS_FILE_MAX_FILE_INFO directory entries, based on the maximum + // filename length supported by the filesystem. Note that the multiplica= tion + // is safe from overflow due to the VIRTIO_FS_FUSE_DIRENTPLUS_RESPONSE_S= IZE() + // check. + // + VirtioFs =3D VirtioFsFile->OwnerFs; + Status =3D VirtioFsFuseStatFs (VirtioFs, VirtioFsFile->NodeId, &FilesysA= ttr); + if (EFI_ERROR (Status)) { + return Status; + } + DirentBufSize =3D (UINT32)VIRTIO_FS_FUSE_DIRENTPLUS_RESPONSE_SIZE ( + FilesysAttr.Namelen); + if (DirentBufSize =3D=3D 0) { + return EFI_UNSUPPORTED; + } + DirentBufSize *=3D VIRTIO_FS_FILE_MAX_FILE_INFO; + DirentBuf =3D AllocatePool (DirentBufSize); + if (DirentBuf =3D=3D NULL) { + return EFI_OUT_OF_RESOURCES; + } + + // + // Allocate the EFI_FILE_INFO cache. A single EFI_FILE_INFO element is s= ized + // accordingly to the maximum filename length supported by the filesyste= m. + // + // Note that the calculation below cannot overflow, due to the filename = limit + // imposed by the VIRTIO_FS_FUSE_DIRENTPLUS_RESPONSE_SIZE() check above.= The + // calculation takes the L'\0' character that we'll need to append into + // account. + // + SingleFileInfoSize =3D (OFFSET_OF (EFI_FILE_INFO, FileName) + + ((UINTN)FilesysAttr.Namelen + 1) * sizeof (CHAR16)= ); + FileInfoArray =3D AllocatePool ( + VIRTIO_FS_FILE_MAX_FILE_INFO * SingleFileInfoSize + ); + if (FileInfoArray =3D=3D NULL) { + Status =3D EFI_OUT_OF_RESOURCES; + goto FreeDirentBuf; + } + + // + // Pick up reading the directory stream where the previous cache ended. + // + DirStreamCookie =3D VirtioFsFile->FilePosition; + CacheEndsAtCookie =3D VirtioFsFile->FilePosition; + NumFileInfo =3D 0; + do { + UINT32 Remaining; + UINT32 Consumed; + + // + // Fetch a chunk of the directory stream. The chunk may hold more entr= ies + // than what we can fit in the cache. The chunk may also not entirely = fill + // the cache, especially after filtering out entries that cannot be + // supported under UEFI (sockets, FIFOs, filenames with backslashes, e= tc). + // + Remaining =3D DirentBufSize; + Status =3D VirtioFsFuseReadFileOrDir ( + VirtioFs, + VirtioFsFile->NodeId, + VirtioFsFile->FuseHandle, + TRUE, // IsDir + DirStreamCookie, // Offset + &Remaining, // Size + DirentBuf // Data + ); + if (EFI_ERROR (Status)) { + goto FreeFileInfoArray; + } + + if (Remaining =3D=3D 0) { + // + // The directory stream ends. + // + break; + } + + // + // Iterate over all records in DirentBuf. Primarily, forget them all. + // Secondarily, if a record proves transformable to EFI_FILE_INFO, add= it + // to the EFI_FILE_INFO cache (unless the cache is full). + // + Consumed =3D 0; + while (Remaining >=3D sizeof (VIRTIO_FS_FUSE_DIRENTPLUS_RESPONSE)) { + VIRTIO_FS_FUSE_DIRENTPLUS_RESPONSE *Dirent; + UINT32 DirentSize; + + Dirent =3D (VIRTIO_FS_FUSE_DIRENTPLUS_RESPONSE *)(DirentBuf + Consum= ed); + DirentSize =3D (UINT32)VIRTIO_FS_FUSE_DIRENTPLUS_RESPONSE_SIZE ( + Dirent->Namelen); + if (DirentSize =3D=3D 0) { + // + // This means one of two things: (a) Dirent->Namelen is zero, or (= b) + // (b) Dirent->Namelen is unsupportably large. (a) is just invalid= for + // the Virtio Filesystem device to send, while (b) shouldn't happen + // because "FilesysAttr.Namelen" -- the maximum filename length + // supported by the filesystem -- proved acceptable above. + // + Status =3D EFI_PROTOCOL_ERROR; + goto FreeFileInfoArray; + } + if (DirentSize > Remaining) { + // + // Dirent->Namelen suggests that the filename byte array (plus any + // padding) are truncated. This should never happen; the Virtio + // Filesystem device is supposed to send complete entries only. + // + Status =3D EFI_PROTOCOL_ERROR; + goto FreeFileInfoArray; + } + if (Dirent->Namelen > FilesysAttr.Namelen) { + // + // This is possible without tripping the truncation check above, d= ue to + // how entries are padded. The condition means that Dirent->Namele= n is + // reportedly larger than the filesystem limit, without spilling i= nto + // the next alignment bucket. Should never happen. + // + Status =3D EFI_PROTOCOL_ERROR; + goto FreeFileInfoArray; + } + + // + // If we haven't filled the EFI_FILE_INFO cache yet, attempt transfo= rming + // Dirent to EFI_FILE_INFO. + // + if (NumFileInfo < VIRTIO_FS_FILE_MAX_FILE_INFO) { + EFI_FILE_INFO *FileInfo; + + FileInfo =3D (EFI_FILE_INFO *)(FileInfoArray + + (NumFileInfo * SingleFileInfoSize)); + Status =3D PopulateFileInfo (Dirent, SingleFileInfoSize, FileInfo); + if (!EFI_ERROR (Status)) { + // + // Dirent has been transformed and cached successfully. + // + NumFileInfo++; + // + // The next time we refill the cache, restart reading the direct= ory + // stream right after the entry that we've just transformed and + // cached. + // + CacheEndsAtCookie =3D Dirent->CookieForNextEntry; + } + // + // If Dirent wasn't transformable to an EFI_FILE_INFO, we'll just = skip + // it. + // + } + + // + // Make the Virtio Filesystem device forget the NodeId in this direc= tory + // entry, as we'll need it no more. (The "." and ".." entries need no + // FUSE_FORGET requests, when returned by FUSE_READDIRPLUS -- and so= the + // Virtio Filesystem device reports their NodeId fields as zero.) + // + if (Dirent->NodeResp.NodeId !=3D 0) { + VirtioFsFuseForget (VirtioFs, Dirent->NodeResp.NodeId); + } + + // + // Advance to the next entry in DirentBuf. + // + DirStreamCookie =3D Dirent->CookieForNextEntry; + Consumed +=3D DirentSize; + Remaining -=3D DirentSize; + } + + if (Remaining > 0) { + // + // This suggests that a VIRTIO_FS_FUSE_DIRENTPLUS_RESPONSE header was + // truncated. This should never happen; the Virtio Filesystem device= is + // supposed to send complete entries only. + // + Status =3D EFI_PROTOCOL_ERROR; + goto FreeFileInfoArray; + } + // + // Fetch another DirentBuf from the directory stream, unless we've fil= led + // the EFI_FILE_INFO cache. + // + } while (NumFileInfo < VIRTIO_FS_FILE_MAX_FILE_INFO); + + // + // Commit the results. (Note that the result may be an empty cache.) + // + if (VirtioFsFile->FileInfoArray !=3D NULL) { + FreePool (VirtioFsFile->FileInfoArray); + } + VirtioFsFile->FileInfoArray =3D FileInfoArray; + VirtioFsFile->SingleFileInfoSize =3D SingleFileInfoSize; + VirtioFsFile->NumFileInfo =3D NumFileInfo; + VirtioFsFile->NextFileInfo =3D 0; + VirtioFsFile->FilePosition =3D CacheEndsAtCookie; + + FreePool (DirentBuf); + return EFI_SUCCESS; + +FreeFileInfoArray: + FreePool (FileInfoArray); + +FreeDirentBuf: + FreePool (DirentBuf); + + return Status; +} + +/** + Read an entry from the EFI_FILE_INFO cache. +**/ +STATIC +EFI_STATUS +ReadFileInfoCache ( + IN OUT VIRTIO_FS_FILE *VirtioFsFile, + IN OUT UINTN *BufferSize, + OUT VOID *Buffer + ) +{ + EFI_FILE_INFO *FileInfo; + UINTN CallerAllocated; + + // + // Refill the cache if needed. If the refill doesn't produce any new + // EFI_FILE_INFO, report End of Directory, by setting (*BufferSize) to 0. + // + if (VirtioFsFile->NextFileInfo =3D=3D VirtioFsFile->NumFileInfo) { + EFI_STATUS Status; + + Status =3D RefillFileInfoCache (VirtioFsFile); + if (EFI_ERROR (Status)) { + return (Status =3D=3D EFI_BUFFER_TOO_SMALL) ? EFI_DEVICE_ERROR : Sta= tus; + } + if (VirtioFsFile->NumFileInfo =3D=3D 0) { + *BufferSize =3D 0; + return EFI_SUCCESS; + } + } + FileInfo =3D (EFI_FILE_INFO *)(VirtioFsFile->FileInfoArray + + (VirtioFsFile->NextFileInfo * + VirtioFsFile->SingleFileInfoSize)); + + // + // Check if the caller is ready to accept FileInfo. If not, we'll just + // present the required size for now. + // + // (The (UINTN) cast below is safe because FileInfo->Size has been reduc= ed + // from VirtioFsFile->SingleFileInfoSize, in + // + // RefillFileInfoCache() + // PopulateFileInfo() + // VirtioFsFuseDirentPlusToEfiFileInfo() + // + // and VirtioFsFile->SingleFileInfoSize was computed from + // FilesysAttr.Namelen, which had been accepted by + // VIRTIO_FS_FUSE_DIRENTPLUS_RESPONSE_SIZE().) + // + CallerAllocated =3D *BufferSize; + *BufferSize =3D (UINTN)FileInfo->Size; + if (CallerAllocated < *BufferSize) { + return EFI_BUFFER_TOO_SMALL; + } + // + // Output FileInfo, and remove it from the cache. + // + CopyMem (Buffer, FileInfo, *BufferSize); + VirtioFsFile->NextFileInfo++; + return EFI_SUCCESS; +} + /** Read from a regular file. **/ STATIC EFI_STATUS ReadRegularFile ( IN OUT VIRTIO_FS_FILE *VirtioFsFile, IN OUT UINTN *BufferSize, @@ -80,14 +421,14 @@ VirtioFsSimpleFileRead ( ) { VIRTIO_FS_FILE *VirtioFsFile; EFI_STATUS Status; =20 VirtioFsFile =3D VIRTIO_FS_FILE_FROM_SIMPLE_FILE (This); =20 if (VirtioFsFile->IsDirectory) { - Status =3D EFI_NO_MEDIA; + Status =3D ReadFileInfoCache (VirtioFsFile, BufferSize, Buffer); } else { Status =3D ReadRegularFile (VirtioFsFile, BufferSize, Buffer); } return Status; } --=20 2.19.1.3.g30247aa5d201 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#69050): https://edk2.groups.io/g/devel/message/69050 Mute This Topic: https://groups.io/mt/79024159/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Tue May 7 07:56:31 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+69051+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+69051+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1608157774; cv=none; d=zohomail.com; s=zohoarc; b=MVQNTkZkjJZv4cyPVOPUlj9XKtW0muhXidOSlUgCKPVm2uXmA9J5FykpA1gp10Q3G6P10gDzjH1nhgcZJoFVAb6D+FNt0ZGtL8Ea9XZH7bvJxlmWq20MgwBP/gK+hS6uYYnu0KaKdqLMimbd+dN/1vOD5QZIbJoqZmj708d+RJg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608157774; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=WBMDL6NDhm+GTU+tGE4G0Bhp0KLhUzmlNTZRRtTsTjA=; b=ONAVxpyaW3p4vSEkU3kqu6uQ65xr1YecCUGDSTlYq6N1DUOY6fYYB6GPE4+iJ/dnCcVvyl9qfqrv08RZuoDicfLWNjgleSX9sbgaOqRQDkX8aOuUj07I98SMYhsBKadMojfWzPHmhhajThm4y4Cn2WOhG1E8nOGkIefl7u7/wn8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+69051+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) header.from= Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1608157774721277.2193651924108; Wed, 16 Dec 2020 14:29:34 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id 7S3zYY1788612xooWIjLQQAg; Wed, 16 Dec 2020 14:29:34 -0800 X-Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.groups.io with SMTP id smtpd.web12.4846.1608157773734583822 for ; Wed, 16 Dec 2020 14:29:33 -0800 X-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-169-l0FHSdIFOACwD3g8UzBbEw-1; Wed, 16 Dec 2020 17:29:29 -0500 X-MC-Unique: l0FHSdIFOACwD3g8UzBbEw-1 X-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 E26F710054FF; Wed, 16 Dec 2020 22:29:27 +0000 (UTC) X-Received: from lacos-laptop-7.usersys.redhat.com (ovpn-114-152.ams2.redhat.com [10.36.114.152]) by smtp.corp.redhat.com (Postfix) with ESMTP id C09415D71B; Wed, 16 Dec 2020 22:29:22 +0000 (UTC) From: "Laszlo Ersek" To: devel@edk2.groups.io, virtio-fs@redhat.com, lersek@redhat.com Cc: Ard Biesheuvel , Jordan Justen , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [edk2-devel] [edk2 PATCH 37/48] OvmfPkg/VirtioFsDxe: implement EFI_FILE_PROTOCOL.Flush() Date: Wed, 16 Dec 2020 22:11:14 +0100 Message-Id: <20201216211125.19496-38-lersek@redhat.com> In-Reply-To: <20201216211125.19496-1-lersek@redhat.com> References: <20201216211125.19496-1-lersek@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,lersek@redhat.com X-Gm-Message-State: BMfiSPm4KDarFWW0a1AcAIp4x1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1608157774; bh=WBMDL6NDhm+GTU+tGE4G0Bhp0KLhUzmlNTZRRtTsTjA=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=EB62bmcdlUPx9rL7JxvKadmwHWpQwK8vRcqM53bpVGGbM1oysRhMPfMs66OVT9TbyCM 8EkEiKaDGsdbQmg5cDDeoioajuHNBlv/8CEpr1aGBEy3fqzENv0aDe/+zfaQDbORZW2D0 /C7d6m2foXMv3Xh+Iy6kXcczO+TsWq2xNqA= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" For directories, implement EFI_FILE_PROTOCOL.Flush() by sending the FUSE_FSYNCDIR command to the Virtio Filesystem device. For regular files, send FUSE_FLUSH, followed by FUSE_FSYNC. Cc: Ard Biesheuvel Cc: Jordan Justen Cc: Philippe Mathieu-Daud=C3=A9 Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3097 Signed-off-by: Laszlo Ersek Acked-by: Ard Biesheuvel --- OvmfPkg/VirtioFsDxe/SimpleFsFlush.c | 26 +++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/OvmfPkg/VirtioFsDxe/SimpleFsFlush.c b/OvmfPkg/VirtioFsDxe/Simp= leFsFlush.c index e48d92140f64..ba4a611e5a21 100644 --- a/OvmfPkg/VirtioFsDxe/SimpleFsFlush.c +++ b/OvmfPkg/VirtioFsDxe/SimpleFsFlush.c @@ -9,10 +9,34 @@ #include "VirtioFsDxe.h" =20 EFI_STATUS EFIAPI VirtioFsSimpleFileFlush ( IN EFI_FILE_PROTOCOL *This ) { - return EFI_NO_MEDIA; + VIRTIO_FS_FILE *VirtioFsFile; + VIRTIO_FS *VirtioFs; + EFI_STATUS Status; + + VirtioFsFile =3D VIRTIO_FS_FILE_FROM_SIMPLE_FILE (This); + VirtioFs =3D VirtioFsFile->OwnerFs; + + if (!VirtioFsFile->IsOpenForWriting) { + return EFI_ACCESS_DENIED; + } + + // + // FUSE_FLUSH is for regular files only. + // + if (!VirtioFsFile->IsDirectory) { + Status =3D VirtioFsFuseFlush (VirtioFs, VirtioFsFile->NodeId, + VirtioFsFile->FuseHandle); + if (EFI_ERROR (Status)) { + return Status; + } + } + + Status =3D VirtioFsFuseFsyncFileOrDir (VirtioFs, VirtioFsFile->NodeId, + VirtioFsFile->FuseHandle, VirtioFsFile->IsDirectory); + return Status; } --=20 2.19.1.3.g30247aa5d201 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#69051): https://edk2.groups.io/g/devel/message/69051 Mute This Topic: https://groups.io/mt/79024215/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Tue May 7 07:56:31 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+69052+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+69052+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1608157901; cv=none; d=zohomail.com; s=zohoarc; b=MTCRoxM/v1VzV/QE1OzvoXOs2hom7FevqX6XBQAjCmG1G3kJUzRCkGbe/D5sYRLPbf6My/LJekISHqukXlURQo5LW/q7TCZlrqJ8cL0GNi+C/yL35f7kNzOe5zDZbflENoZztNMFfik4KDCRQf9I/F6O1F8P1LvBwZKqB9Orn7A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608157901; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=ejEI88Iw8D4VgI/a4h+Q5wGjbYrgbL22p0p0JfEe8rQ=; b=lo2BjyMSGPVKL4/jxL/aYhp2i1ke9blDG3FpG3ORpCYiT/0uo1hR+dWL/WVUys67YE5cKF9cXph4t6Cj+ulst70oNiYTSviphp5LepJaJn9N/ANAu2qPbcOKne3hfD74cD/pAima3WHHtyAHMc+fUI/wG9GR2Dtqda8IBlt3wOE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+69052+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) header.from= Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1608157901671647.2699616418305; Wed, 16 Dec 2020 14:31:41 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id 1zqqYY1788612x9br6wEqeDW; Wed, 16 Dec 2020 14:31:41 -0800 X-Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.groups.io with SMTP id smtpd.web12.4883.1608157899824662842 for ; Wed, 16 Dec 2020 14:31:40 -0800 X-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-520-uOoMrRvrMPC2yu5bpKVxNg-1; Wed, 16 Dec 2020 17:31:35 -0500 X-MC-Unique: uOoMrRvrMPC2yu5bpKVxNg-1 X-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 CFD52800D62; Wed, 16 Dec 2020 22:31:33 +0000 (UTC) X-Received: from lacos-laptop-7.usersys.redhat.com (ovpn-114-152.ams2.redhat.com [10.36.114.152]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2B7C960C15; Wed, 16 Dec 2020 22:31:28 +0000 (UTC) From: "Laszlo Ersek" To: devel@edk2.groups.io, virtio-fs@redhat.com, lersek@redhat.com Cc: Ard Biesheuvel , Jordan Justen , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [edk2-devel] [edk2 PATCH 38/48] OvmfPkg/VirtioFsDxe: implement the wrapper function for FUSE_WRITE Date: Wed, 16 Dec 2020 22:11:15 +0100 Message-Id: <20201216211125.19496-39-lersek@redhat.com> In-Reply-To: <20201216211125.19496-1-lersek@redhat.com> References: <20201216211125.19496-1-lersek@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,lersek@redhat.com X-Gm-Message-State: Nvdj9Eu3hI7xxzYSmJ6Opg0Ax1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1608157901; bh=ejEI88Iw8D4VgI/a4h+Q5wGjbYrgbL22p0p0JfEe8rQ=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=LrKxIxwvtQ7Z0O4kKy+MgsqjacwV/SNhqum4JZWaccMAoBlcUNIa1o+GsmXgo01YDDW PbMnaHIkUINQ631cQQeyLzu0ZN+cibZK7PuJhwhN8gjTu/Oue2/8TQTtAsIdc4EVho8l/ 2VBZBEmJupmOpzXYXZyE6prW7LGHlgUPJ50= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" Add the VirtioFsFuseWrite() function, for sending the FUSE_WRITE command to the Virtio Filesystem device. (For avoiding oversized FUSE_WRITE commands, save the maximum write buffer size that is advertized by the FUSE server, in the session init code.) Cc: Ard Biesheuvel Cc: Jordan Justen Cc: Philippe Mathieu-Daud=C3=A9 Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3097 Signed-off-by: Laszlo Ersek Acked-by: Ard Biesheuvel --- OvmfPkg/Include/IndustryStandard/VirtioFs.h | 19 +++ OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf | 1 + OvmfPkg/VirtioFsDxe/VirtioFsDxe.h | 11 ++ OvmfPkg/VirtioFsDxe/FuseInit.c | 12 +- OvmfPkg/VirtioFsDxe/FuseWrite.c | 155 ++++++++++++++++++++ 5 files changed, 196 insertions(+), 2 deletions(-) diff --git a/OvmfPkg/Include/IndustryStandard/VirtioFs.h b/OvmfPkg/Include/= IndustryStandard/VirtioFs.h index fa8c40019f4e..0b7b3ff80edd 100644 --- a/OvmfPkg/Include/IndustryStandard/VirtioFs.h +++ b/OvmfPkg/Include/IndustryStandard/VirtioFs.h @@ -148,16 +148,17 @@ typedef enum { VirtioFsFuseOpLookup =3D 1, VirtioFsFuseOpForget =3D 2, VirtioFsFuseOpGetAttr =3D 3, VirtioFsFuseOpMkDir =3D 9, VirtioFsFuseOpUnlink =3D 10, VirtioFsFuseOpRmDir =3D 11, VirtioFsFuseOpOpen =3D 14, VirtioFsFuseOpRead =3D 15, + VirtioFsFuseOpWrite =3D 16, VirtioFsFuseOpStatFs =3D 17, VirtioFsFuseOpRelease =3D 18, VirtioFsFuseOpFsync =3D 20, VirtioFsFuseOpFlush =3D 25, VirtioFsFuseOpInit =3D 26, VirtioFsFuseOpOpenDir =3D 27, VirtioFsFuseOpReleaseDir =3D 29, VirtioFsFuseOpFsyncDir =3D 30, @@ -277,16 +278,34 @@ typedef struct { UINT64 Offset; UINT32 Size; UINT32 ReadFlags; UINT64 LockOwner; UINT32 Flags; UINT32 Padding; } VIRTIO_FS_FUSE_READ_REQUEST; =20 +// +// Headers for VirtioFsFuseOpWrite. +// +typedef struct { + UINT64 FileHandle; + UINT64 Offset; + UINT32 Size; + UINT32 WriteFlags; + UINT64 LockOwner; + UINT32 Flags; + UINT32 Padding; +} VIRTIO_FS_FUSE_WRITE_REQUEST; + +typedef struct { + UINT32 Size; + UINT32 Padding; +} VIRTIO_FS_FUSE_WRITE_RESPONSE; + // // Header for VirtioFsFuseOpStatFs. // typedef struct { UINT64 Blocks; UINT64 Bfree; UINT64 Bavail; UINT64 Files; diff --git a/OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf b/OvmfPkg/VirtioFsDxe/Virt= ioFsDxe.inf index 39c77c7c4ee9..2c145da5f5ae 100644 --- a/OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf +++ b/OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf @@ -92,16 +92,17 @@ [Sources] FuseMkDir.c FuseOpen.c FuseOpenDir.c FuseOpenOrCreate.c FuseRead.c FuseRelease.c FuseStatFs.c FuseUnlink.c + FuseWrite.c Helpers.c SimpleFsClose.c SimpleFsDelete.c SimpleFsFlush.c SimpleFsGetInfo.c SimpleFsGetPosition.c SimpleFsOpen.c SimpleFsOpenVolume.c diff --git a/OvmfPkg/VirtioFsDxe/VirtioFsDxe.h b/OvmfPkg/VirtioFsDxe/Virtio= FsDxe.h index a704acdd520e..132a63400527 100644 --- a/OvmfPkg/VirtioFsDxe/VirtioFsDxe.h +++ b/OvmfPkg/VirtioFsDxe/VirtioFsDxe.h @@ -73,16 +73,17 @@ typedef struct { // ----------- ------------------ ------= ---- UINT64 Signature; // DriverBindingStart 0 VIRTIO_DEVICE_PROTOCOL *Virtio; // DriverBindingStart 0 VIRTIO_FS_LABEL Label; // VirtioFsInit 1 UINT16 QueueSize; // VirtioFsInit 1 VRING Ring; // VirtioRingInit 2 VOID *RingMap; // VirtioRingMap 2 UINT64 RequestId; // FuseInitSession 1 + UINT32 MaxWrite; // FuseInitSession 1 EFI_EVENT ExitBoot; // DriverBindingStart 0 LIST_ENTRY OpenFiles; // DriverBindingStart 0 EFI_SIMPLE_FILE_SYSTEM_PROTOCOL SimpleFs; // DriverBindingStart 0 } VIRTIO_FS; =20 #define VIRTIO_FS_FROM_SIMPLE_FS(SimpleFsReference) \ CR (SimpleFsReference, VIRTIO_FS, SimpleFs, VIRTIO_FS_SIG); =20 @@ -329,16 +330,26 @@ VirtioFsFuseReadFileOrDir ( IN UINT64 NodeId, IN UINT64 FuseHandle, IN BOOLEAN IsDir, IN UINT64 Offset, IN OUT UINT32 *Size, OUT VOID *Data ); =20 +EFI_STATUS +VirtioFsFuseWrite ( + IN OUT VIRTIO_FS *VirtioFs, + IN UINT64 NodeId, + IN UINT64 FuseHandle, + IN UINT64 Offset, + IN OUT UINT32 *Size, + IN VOID *Data + ); + EFI_STATUS VirtioFsFuseStatFs ( IN OUT VIRTIO_FS *VirtioFs, IN UINT64 NodeId, OUT VIRTIO_FS_FUSE_STATFS_RESPONSE *FilesysAttr ); =20 EFI_STATUS diff --git a/OvmfPkg/VirtioFsDxe/FuseInit.c b/OvmfPkg/VirtioFsDxe/FuseInit.c index 7aa6ee75caf6..431842804912 100644 --- a/OvmfPkg/VirtioFsDxe/FuseInit.c +++ b/OvmfPkg/VirtioFsDxe/FuseInit.c @@ -17,17 +17,20 @@ session is started by sending a FUSE_INIT request as defined by the FUSE protocol on one request virtqueue." =20 The function may only be called after VirtioFsInit() returns successfull= y and before VirtioFsUninit() is called. =20 @param[in,out] VirtioFs The Virtio Filesystem device to send the FUSE_I= NIT request to. The FUSE request counter - "VirtioFs->RequestId" is set to 1 on output. + "VirtioFs->RequestId" is set to 1 on output. The + maximum write buffer size exposed in the FUSE_I= NIT + response is saved in "VirtioFs->MaxWrite", on + output. =20 @retval EFI_SUCCESS The FUSE session has been started. =20 @retval EFI_UNSUPPORTED FUSE interface version or feature negotiation failed. =20 @return The "errno" value mapped to an EFI_STATUS code,= if the Virtio Filesystem device explicitly reporte= d an @@ -121,14 +124,19 @@ VirtioFsFuseInitSession ( return Status; } =20 // // Check FUSE interface version / feature compatibility. // if (InitResp.Major < InitReq.Major || (InitResp.Major =3D=3D InitReq.Major && InitResp.Minor < InitReq.Min= or) || - (InitResp.Flags & VIRTIO_FS_FUSE_INIT_REQ_F_DO_READDIRPLUS) =3D=3D 0= ) { + (InitResp.Flags & VIRTIO_FS_FUSE_INIT_REQ_F_DO_READDIRPLUS) =3D=3D 0= || + InitResp.MaxWrite < SIZE_4KB) { return EFI_UNSUPPORTED; } =20 + // + // Save the maximum write buffer size for FUSE_WRITE requests. + // + VirtioFs->MaxWrite =3D InitResp.MaxWrite; return EFI_SUCCESS; } diff --git a/OvmfPkg/VirtioFsDxe/FuseWrite.c b/OvmfPkg/VirtioFsDxe/FuseWrit= e.c new file mode 100644 index 000000000000..cc552bd667ba --- /dev/null +++ b/OvmfPkg/VirtioFsDxe/FuseWrite.c @@ -0,0 +1,155 @@ +/** @file + FUSE_WRITE wrapper for the Virtio Filesystem device. + + Copyright (C) 2020, Red Hat, Inc. + + SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#include "VirtioFsDxe.h" + +/** + Write a chunk to a regular file, by sending the FUSE_WRITE request to the + Virtio Filesystem device. + + The function may only be called after VirtioFsFuseInitSession() returns + successfully and before VirtioFsUninit() is called. + + @param[in,out] VirtioFs The Virtio Filesystem device to send the FUSE_W= RITE + request to. On output, the FUSE request counter + "VirtioFs->RequestId" will have been incremente= d. + + @param[in] NodeId The inode number of the regular file to write t= o. + + @param[in] FuseHandle The open handle to the regular file to write to. + + @param[in] Offset The absolute file position at which to start + writing. + + @param[in,out] Size On input, the number of bytes to write. On + successful return, the number of bytes actually + written, which may be smaller than the value on + input. + + @param[in] Data The buffer to write to the regular file. + + @retval EFI_SUCCESS Write successful. The caller is responsible= for + checking Size to learn the actual byte count + transferred. + + @retval EFI_BAD_BUFFER_SIZE On input, Size is larger than + "VirtioFs->MaxWrite". + + @return The "errno" value mapped to an EFI_STATUS c= ode, + if the Virtio Filesystem device explicitly + reported an error. + + @return Error codes propagated from + VirtioFsSgListsValidate(), + VirtioFsFuseNewRequest(), + VirtioFsSgListsSubmit(), + VirtioFsFuseCheckResponse(). +**/ +EFI_STATUS +VirtioFsFuseWrite ( + IN OUT VIRTIO_FS *VirtioFs, + IN UINT64 NodeId, + IN UINT64 FuseHandle, + IN UINT64 Offset, + IN OUT UINT32 *Size, + IN VOID *Data + ) +{ + VIRTIO_FS_FUSE_REQUEST CommonReq; + VIRTIO_FS_FUSE_WRITE_REQUEST WriteReq; + VIRTIO_FS_IO_VECTOR ReqIoVec[3]; + VIRTIO_FS_SCATTER_GATHER_LIST ReqSgList; + VIRTIO_FS_FUSE_RESPONSE CommonResp; + VIRTIO_FS_FUSE_WRITE_RESPONSE WriteResp; + VIRTIO_FS_IO_VECTOR RespIoVec[2]; + VIRTIO_FS_SCATTER_GATHER_LIST RespSgList; + EFI_STATUS Status; + + // + // Honor the write buffer size limit of the Virtio Filesystem device. + // + if (*Size > VirtioFs->MaxWrite) { + return EFI_BAD_BUFFER_SIZE; + } + + // + // Set up the scatter-gather lists. + // + ReqIoVec[0].Buffer =3D &CommonReq; + ReqIoVec[0].Size =3D sizeof CommonReq; + ReqIoVec[1].Buffer =3D &WriteReq; + ReqIoVec[1].Size =3D sizeof WriteReq; + ReqIoVec[2].Buffer =3D Data; + ReqIoVec[2].Size =3D *Size; + ReqSgList.IoVec =3D ReqIoVec; + ReqSgList.NumVec =3D ARRAY_SIZE (ReqIoVec); + + RespIoVec[0].Buffer =3D &CommonResp; + RespIoVec[0].Size =3D sizeof CommonResp; + RespIoVec[1].Buffer =3D &WriteResp; + RespIoVec[1].Size =3D sizeof WriteResp; + RespSgList.IoVec =3D RespIoVec; + RespSgList.NumVec =3D ARRAY_SIZE (RespIoVec); + + // + // Validate the scatter-gather lists; calculate the total transfer sizes. + // + Status =3D VirtioFsSgListsValidate (VirtioFs, &ReqSgList, &RespSgList); + if (EFI_ERROR (Status)) { + return Status; + } + + // + // Populate the common request header. + // + Status =3D VirtioFsFuseNewRequest (VirtioFs, &CommonReq, ReqSgList.Total= Size, + VirtioFsFuseOpWrite, NodeId); + if (EFI_ERROR (Status)) { + return Status; + } + + // + // Populate the FUSE_WRITE-specific fields. + // + WriteReq.FileHandle =3D FuseHandle; + WriteReq.Offset =3D Offset; + WriteReq.Size =3D *Size; + WriteReq.WriteFlags =3D 0; + WriteReq.LockOwner =3D 0; + WriteReq.Flags =3D 0; + WriteReq.Padding =3D 0; + + // + // Submit the request. + // + Status =3D VirtioFsSgListsSubmit (VirtioFs, &ReqSgList, &RespSgList); + if (EFI_ERROR (Status)) { + return Status; + } + + // + // Verify the response (all response buffers are fixed size). + // + Status =3D VirtioFsFuseCheckResponse (&RespSgList, CommonReq.Unique, NUL= L); + if (EFI_ERROR (Status)) { + if (Status =3D=3D EFI_DEVICE_ERROR) { + DEBUG ((DEBUG_ERROR, "%a: Label=3D\"%s\" NodeId=3D%Lu FuseHandle=3D%= Lu " + "Offset=3D0x%Lx Size=3D0x%x Data@%p Errno=3D%d\n", __FUNCTION__, + VirtioFs->Label, NodeId, FuseHandle, Offset, *Size, Data, + CommonResp.Error)); + Status =3D VirtioFsErrnoToEfiStatus (CommonResp.Error); + } + return Status; + } + + // + // Report the actual transfer size. + // + *Size =3D WriteResp.Size; + return EFI_SUCCESS; +} --=20 2.19.1.3.g30247aa5d201 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#69052): https://edk2.groups.io/g/devel/message/69052 Mute This Topic: https://groups.io/mt/79024273/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Tue May 7 07:56:31 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+69053+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+69053+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1608158024; cv=none; d=zohomail.com; s=zohoarc; b=dpJ3DNwH+YFMbKE+mP534uLq7xYHnGKAIbS8kCcdnl+KE9B3KV/9q96f3Ase2x72X5CG0j5aHnk8XeRdYAbA4QizpDppHciPQdgQAuJwKNCQlahO7gdM/0IrfgA2iU8uyIqjamkybmNl1yQ+9eTD8N+VkI9PT2TV/a62brlxL74= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608158024; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=AI5mG4ekEptycAFdFrbdhZ8j4hUt/4uP6E2++6Eb/kw=; b=eoj0lZbgFyFMHwjzYiEE+8JpiBwCr5fO+uHmSII+fdAYc1Y7maoqtckU3WTji+60GKTgJzpGSUFw8M+IyDABzkTNISJhbZIXtYTCkMDSypwJnfhd+dDMbCnBbq7VLIVRc4OJQ8uN0HWJ581OmSKVk+P+/WX619taxldBvQcRxqU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+69053+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) header.from= Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 16081580245261021.1812205272477; Wed, 16 Dec 2020 14:33:44 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id bqmUYY1788612xPcvaLf93vA; Wed, 16 Dec 2020 14:33:44 -0800 X-Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.groups.io with SMTP id smtpd.web10.4908.1608158023521573541 for ; Wed, 16 Dec 2020 14:33:43 -0800 X-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-103-ESZiJYpiP1mz_RiB57YpwA-1; Wed, 16 Dec 2020 17:33:40 -0500 X-MC-Unique: ESZiJYpiP1mz_RiB57YpwA-1 X-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 731B2107ACE4; Wed, 16 Dec 2020 22:33:39 +0000 (UTC) X-Received: from lacos-laptop-7.usersys.redhat.com (ovpn-114-152.ams2.redhat.com [10.36.114.152]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0E6FA60C15; Wed, 16 Dec 2020 22:33:34 +0000 (UTC) From: "Laszlo Ersek" To: devel@edk2.groups.io, virtio-fs@redhat.com, lersek@redhat.com Cc: Ard Biesheuvel , Jordan Justen , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [edk2-devel] [edk2 PATCH 39/48] OvmfPkg/VirtioFsDxe: implement EFI_FILE_PROTOCOL.Write() Date: Wed, 16 Dec 2020 22:11:16 +0100 Message-Id: <20201216211125.19496-40-lersek@redhat.com> In-Reply-To: <20201216211125.19496-1-lersek@redhat.com> References: <20201216211125.19496-1-lersek@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,lersek@redhat.com X-Gm-Message-State: UB01EPi8wnDZxLguPFvRvi9Qx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1608158024; bh=AI5mG4ekEptycAFdFrbdhZ8j4hUt/4uP6E2++6Eb/kw=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=H7JL/+iMw1IoSS4bz9AEEWs3BxIIg2y7kwhsjuhxOigW7KHI/esNZBpETSzZZBGbU4d J5l171q9M8sSCycNwWhBNd8C5hWqqX7y6j83UEzpMTRCxBQiScl7DydDETdXgJWy8lXl5 KF3kGUe4wUN5tYOWW7+68B0QLji8LV7By/E= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" Using the functions introduced previously, we can now implement VirtioFsSimpleFileWrite(). Cc: Ard Biesheuvel Cc: Jordan Justen Cc: Philippe Mathieu-Daud=C3=A9 Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3097 Signed-off-by: Laszlo Ersek Acked-by: Ard Biesheuvel --- OvmfPkg/VirtioFsDxe/SimpleFsWrite.c | 63 +++++++++++++++++++- 1 file changed, 62 insertions(+), 1 deletion(-) diff --git a/OvmfPkg/VirtioFsDxe/SimpleFsWrite.c b/OvmfPkg/VirtioFsDxe/Simp= leFsWrite.c index 90d82bd722b1..8ae317c88e43 100644 --- a/OvmfPkg/VirtioFsDxe/SimpleFsWrite.c +++ b/OvmfPkg/VirtioFsDxe/SimpleFsWrite.c @@ -11,10 +11,71 @@ EFI_STATUS EFIAPI VirtioFsSimpleFileWrite ( IN EFI_FILE_PROTOCOL *This, IN OUT UINTN *BufferSize, IN VOID *Buffer ) { - return EFI_NO_MEDIA; + VIRTIO_FS_FILE *VirtioFsFile; + VIRTIO_FS *VirtioFs; + EFI_STATUS Status; + UINTN Transferred; + UINTN Left; + + VirtioFsFile =3D VIRTIO_FS_FILE_FROM_SIMPLE_FILE (This); + VirtioFs =3D VirtioFsFile->OwnerFs; + + if (VirtioFsFile->IsDirectory) { + return EFI_UNSUPPORTED; + } + if (!VirtioFsFile->IsOpenForWriting) { + return EFI_ACCESS_DENIED; + } + + Status =3D EFI_SUCCESS; + Transferred =3D 0; + Left =3D *BufferSize; + while (Left > 0) { + UINT32 WriteSize; + + // + // Honor the write buffer size limit. + // + WriteSize =3D (UINT32)MIN ((UINTN)VirtioFs->MaxWrite, Left); + Status =3D VirtioFsFuseWrite ( + VirtioFs, + VirtioFsFile->NodeId, + VirtioFsFile->FuseHandle, + VirtioFsFile->FilePosition + Transferred, + &WriteSize, + (UINT8 *)Buffer + Transferred + ); + if (!EFI_ERROR (Status) && WriteSize =3D=3D 0) { + // + // Progress should have been made. + // + Status =3D EFI_DEVICE_ERROR; + } + if (EFI_ERROR (Status)) { + break; + } + Transferred +=3D WriteSize; + Left -=3D WriteSize; + } + + *BufferSize =3D Transferred; + VirtioFsFile->FilePosition +=3D Transferred; + // + // According to the UEFI spec, + // + // - 'Partial writes only occur when there has been a data error during = the + // write attempt (such as "file space full")', and + // + // - (as an example) EFI_VOLUME_FULL is returned when 'The volume is ful= l'. + // + // These together imply that after a partial write, we have to return an + // error. In other words, (Transferred > 0) is inconsequential for the r= eturn + // value. + // + return Status; } --=20 2.19.1.3.g30247aa5d201 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#69053): https://edk2.groups.io/g/devel/message/69053 Mute This Topic: https://groups.io/mt/79024319/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Tue May 7 07:56:31 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+69054+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+69054+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1608158150; cv=none; d=zohomail.com; s=zohoarc; b=RZn+waBRf1lcRMQQThNm2TSYGM3TEmXPDTxEeCbs+/tjI/sXybgLcw/MkzSZoKn40lnkbfXvlDbZDGQBHwmNAWOXt2UWvqjY4T/TZWxK7G9CeUj1Wx5YtaCxjCviDVVYT68Er2U1v0/YL93XJ7/pLFZpuQIio4K5S4Y4d1rLFXY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608158150; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=+8KhcU0EuX/bzNAYhvQ2vjM98jYZKgHGi2mLDqcUm2A=; b=DqjZFULSSBxQbyo7MZf++okuEp4XvjDWQXxJEil8X7f7JTWxiEcFPCwvQyrZINpBItQau/iOdOebDmP2fAnGm3v/mpxE9BOSIyHYt2q24n4MfrRKmqan8bciTVhapgXpR+NuTsMf1zLK0rA6JdWvMTt9hMP9ipvL9b5kfNo4vYE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+69054+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) header.from= Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1608158150139411.4333254084489; Wed, 16 Dec 2020 14:35:50 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id eXHWYY1788612xsKpxmOLYGQ; Wed, 16 Dec 2020 14:35:49 -0800 X-Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.groups.io with SMTP id smtpd.web10.4936.1608158149011425336 for ; Wed, 16 Dec 2020 14:35:49 -0800 X-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-578-lJ2RemhuO5uKJ4Ee4wDADA-1; Wed, 16 Dec 2020 17:35:46 -0500 X-MC-Unique: lJ2RemhuO5uKJ4Ee4wDADA-1 X-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 60BD010054FF; Wed, 16 Dec 2020 22:35:45 +0000 (UTC) X-Received: from lacos-laptop-7.usersys.redhat.com (ovpn-114-152.ams2.redhat.com [10.36.114.152]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9295617577; Wed, 16 Dec 2020 22:35:40 +0000 (UTC) From: "Laszlo Ersek" To: devel@edk2.groups.io, virtio-fs@redhat.com, lersek@redhat.com Cc: Ard Biesheuvel , Jordan Justen , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [edk2-devel] [edk2 PATCH 40/48] OvmfPkg/VirtioFsDxe: handle the volume label in EFI_FILE_PROTOCOL.SetInfo Date: Wed, 16 Dec 2020 22:11:17 +0100 Message-Id: <20201216211125.19496-41-lersek@redhat.com> In-Reply-To: <20201216211125.19496-1-lersek@redhat.com> References: <20201216211125.19496-1-lersek@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,lersek@redhat.com X-Gm-Message-State: yslOagcRMcInD7uDcgWzQ04kx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1608158149; bh=+8KhcU0EuX/bzNAYhvQ2vjM98jYZKgHGi2mLDqcUm2A=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=YJd5khBHjYAzQRU3Gx39EAsn6kdb++fOnPo1qp2XAJSefvqbxRotvmClj8jBDbzas9J pgXst6x4j6WtK3/ve+6nrryO7qtKPJy0lKTVYoSFGDwzsO1GRi4omnk2CLmPd/j7DsH1r vANbHEJPEkQgyBIrRlipXoiDMaHius2VBkY= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" The least complicated third of EFI_FILE_PROTOCOL.SetInfo() is to handle the EFI_FILE_SYSTEM_INFO and EFI_FILE_SYSTEM_VOLUME_LABEL setting requests. Both of those can only change the volume label -- which the Virtio Filesystem device does not support. Verify the input for well-formedness, and report success only if the volume label is being set to its current value. Cc: Ard Biesheuvel Cc: Jordan Justen Cc: Philippe Mathieu-Daud=C3=A9 Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3097 Signed-off-by: Laszlo Ersek Acked-by: Ard Biesheuvel --- OvmfPkg/VirtioFsDxe/SimpleFsSetInfo.c | 226 +++++++++++++++++++- 1 file changed, 225 insertions(+), 1 deletion(-) diff --git a/OvmfPkg/VirtioFsDxe/SimpleFsSetInfo.c b/OvmfPkg/VirtioFsDxe/Si= mpleFsSetInfo.c index 200b7a1bcd20..895b5c029a9e 100644 --- a/OvmfPkg/VirtioFsDxe/SimpleFsSetInfo.c +++ b/OvmfPkg/VirtioFsDxe/SimpleFsSetInfo.c @@ -1,21 +1,245 @@ /** @file EFI_FILE_PROTOCOL.SetInfo() member function for the Virtio Filesystem dr= iver. =20 Copyright (C) 2020, Red Hat, Inc. =20 SPDX-License-Identifier: BSD-2-Clause-Patent **/ =20 +#include // gEfiFileSystemInfoGuid +#include // gEfiFileSystemVolumeLabelIn= fo... +#include // StrCmp() +#include // CompareGuid() + #include "VirtioFsDxe.h" =20 +/** + Validate a buffer that the EFI_FILE_PROTOCOL.SetInfo() caller passes in = for a + particular InformationType GUID. + + The structure to be validated is supposed to end with a variable-length, + NUL-terminated CHAR16 Name string. + + @param[in] SizeByProtocolCaller The BufferSize parameter as provided by= the + EFI_FILE_PROTOCOL.SetInfo() caller. + + @param[in] MinimumStructSize The minimum structure size that is requ= ired + for the given InformationType GUID, + including a single CHAR16 element from = the + trailing Name field. + + @param[in] IsSizeByInfoPresent TRUE if and only if the expected struct= ure + starts with a UINT64 Size field that re= ports + the actual structure size. + + @param[in] Buffer The Buffer parameter as provided by the + EFI_FILE_PROTOCOL.SetInfo() caller. + + @retval EFI_SUCCESS Validation successful, Buffer is well-for= med. + + @retval EFI_BAD_BUFFER_SIZE The EFI_FILE_PROTOCOL.SetInfo() + caller provided a BufferSize that is smal= ler + than the minimum structure size required = for + the given InformationType GUID. + + @retval EFI_INVALID_PARAMETER IsSizeByInfoPresent is TRUE, and the lead= ing + UINT64 Size field does not match the + EFI_FILE_PROTOCOL.SetInfo() caller-provid= ed + BufferSize. + + @retval EFI_INVALID_PARAMETER The trailing Name field does not consist = of a + whole multiple of CHAR16 elements. + + @retval EFI_INVALID_PARAMETER The trailing Name field is not NUL-termin= ated. +**/ +STATIC +EFI_STATUS +ValidateInfoStructure ( + IN UINTN SizeByProtocolCaller, + IN UINTN MinimumStructSize, + IN BOOLEAN IsSizeByInfoPresent, + IN VOID *Buffer + ) +{ + UINTN NameFieldByteOffset; + UINTN NameFieldBytes; + UINTN NameFieldChar16s; + CHAR16 *NameField; + + // + // Make sure the internal function asking for validation passes in sane + // values. + // + ASSERT (MinimumStructSize >=3D sizeof (CHAR16)); + NameFieldByteOffset =3D MinimumStructSize - sizeof (CHAR16); + + if (IsSizeByInfoPresent) { + ASSERT (MinimumStructSize >=3D sizeof (UINT64) + sizeof (CHAR16)); + ASSERT (NameFieldByteOffset >=3D sizeof (UINT64)); + } + + // + // Check whether the protocol caller provided enough bytes for the minim= um + // size of this info structure. + // + if (SizeByProtocolCaller < MinimumStructSize) { + return EFI_BAD_BUFFER_SIZE; + } + + // + // If the info structure starts with a UINT64 Size field, check if that + // agrees with the protocol caller-provided size. + // + if (IsSizeByInfoPresent) { + UINT64 *SizeByInfo; + + SizeByInfo =3D Buffer; + if (*SizeByInfo !=3D SizeByProtocolCaller) { + return EFI_INVALID_PARAMETER; + } + } + + // + // The CHAR16 Name field at the end of the structure must have an even n= umber + // of bytes. + // + // The subtraction below cannot underflow, and yields at least + // sizeof(CHAR16). + // + ASSERT (SizeByProtocolCaller >=3D NameFieldByteOffset); + NameFieldBytes =3D SizeByProtocolCaller - NameFieldByteOffset; + ASSERT (NameFieldBytes >=3D sizeof (CHAR16)); + if (NameFieldBytes % sizeof (CHAR16) !=3D 0) { + return EFI_INVALID_PARAMETER; + } + + // + // The CHAR16 Name field at the end of the structure must be NUL-termina= ted. + // + NameFieldChar16s =3D NameFieldBytes / sizeof (CHAR16); + ASSERT (NameFieldChar16s >=3D 1); + + NameField =3D (CHAR16 *)((UINT8 *)Buffer + NameFieldByteOffset); + if (NameField[NameFieldChar16s - 1] !=3D L'\0') { + return EFI_INVALID_PARAMETER; + } + + return EFI_SUCCESS; +} + +/** + Process an EFI_FILE_SYSTEM_INFO setting request. +**/ +STATIC +EFI_STATUS +SetFileSystemInfo ( + IN EFI_FILE_PROTOCOL *This, + IN UINTN BufferSize, + IN VOID *Buffer + ) +{ + VIRTIO_FS_FILE *VirtioFsFile; + VIRTIO_FS *VirtioFs; + EFI_STATUS Status; + EFI_FILE_SYSTEM_INFO *FileSystemInfo; + + VirtioFsFile =3D VIRTIO_FS_FILE_FROM_SIMPLE_FILE (This); + VirtioFs =3D VirtioFsFile->OwnerFs; + + // + // Validate if Buffer passes as EFI_FILE_SYSTEM_INFO. + // + Status =3D ValidateInfoStructure ( + BufferSize, // SizeByProtocolCaller + OFFSET_OF (EFI_FILE_SYSTEM_INFO, + VolumeLabel) + sizeof (CHAR16), // MinimumStructSize + TRUE, // IsSizeByInfoPresent + Buffer + ); + if (EFI_ERROR (Status)) { + return Status; + } + FileSystemInfo =3D Buffer; + + // + // EFI_FILE_SYSTEM_INFO fields other than VolumeLabel cannot be changed,= per + // spec. + // + // If the label is being changed to its current value, report success; + // otherwise, reject the request, as the Virtio Filesystem device does n= ot + // support changing the label. + // + if (StrCmp (FileSystemInfo->VolumeLabel, VirtioFs->Label) =3D=3D 0) { + return EFI_SUCCESS; + } + return EFI_WRITE_PROTECTED; +} + +/** + Process an EFI_FILE_SYSTEM_VOLUME_LABEL setting request. +**/ +STATIC +EFI_STATUS +SetFileSystemVolumeLabelInfo ( + IN EFI_FILE_PROTOCOL *This, + IN UINTN BufferSize, + IN VOID *Buffer + ) +{ + VIRTIO_FS_FILE *VirtioFsFile; + VIRTIO_FS *VirtioFs; + EFI_STATUS Status; + EFI_FILE_SYSTEM_VOLUME_LABEL *FileSystemVolumeLabel; + + VirtioFsFile =3D VIRTIO_FS_FILE_FROM_SIMPLE_FILE (This); + VirtioFs =3D VirtioFsFile->OwnerFs; + + // + // Validate if Buffer passes as EFI_FILE_SYSTEM_VOLUME_LABEL. + // + Status =3D ValidateInfoStructure ( + BufferSize, // SizeByProtocolCal= ler + OFFSET_OF (EFI_FILE_SYSTEM_VOLUME_LABEL, + VolumeLabel) + sizeof (CHAR16), // MinimumStructSize + FALSE, // IsSizeByInfoPrese= nt + Buffer + ); + if (EFI_ERROR (Status)) { + return Status; + } + FileSystemVolumeLabel =3D Buffer; + + // + // If the label is being changed to its current value, report success; + // otherwise, reject the request, as the Virtio Filesystem device does n= ot + // support changing the label. + // + if (StrCmp (FileSystemVolumeLabel->VolumeLabel, VirtioFs->Label) =3D=3D = 0) { + return EFI_SUCCESS; + } + return EFI_WRITE_PROTECTED; +} + EFI_STATUS EFIAPI VirtioFsSimpleFileSetInfo ( IN EFI_FILE_PROTOCOL *This, IN EFI_GUID *InformationType, IN UINTN BufferSize, IN VOID *Buffer ) { - return EFI_NO_MEDIA; + if (CompareGuid (InformationType, &gEfiFileInfoGuid)) { + return EFI_UNSUPPORTED; + } + + if (CompareGuid (InformationType, &gEfiFileSystemInfoGuid)) { + return SetFileSystemInfo (This, BufferSize, Buffer); + } + + if (CompareGuid (InformationType, &gEfiFileSystemVolumeLabelInfoIdGuid))= { + return SetFileSystemVolumeLabelInfo (This, BufferSize, Buffer); + } + + return EFI_UNSUPPORTED; } --=20 2.19.1.3.g30247aa5d201 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#69054): https://edk2.groups.io/g/devel/message/69054 Mute This Topic: https://groups.io/mt/79024347/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Tue May 7 07:56:31 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+69055+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+69055+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1608158277; cv=none; d=zohomail.com; s=zohoarc; b=U0IHDG7is8n0+mkGNi+p9WqjwsIAi8x4n2N2ITsrp0FWUT6BOtusWKf5DRFN/AKCg9d1Cvv84ZCYBM8JdM0esK3wIQXMDAnLwQZ/uvym6MZEkUGOccjXfrsIh9kj7esqGopF4EgG1M/DegNW+6Wh2SNW3sMyzzQubZDwdmff/J0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608158277; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=wTSZhfOUJ0kv68+r2N7BlyPi1A6E4DfwkmMLmijkr6c=; b=CJ+tkOZYDw4sF8/Rx/Br4hLRP1mntJFncukFGRa7T6F+e11bNUJplVrk3ETFZL9iIUig/QNstJ6kNuiq5Zl3HgW/MeI9CEM5QPQY4qUlHijlDNAhSwQ0bAHvPn3Oykjj5A5dN+RLN+OJa9RQbzY8k8UyLjH/shkeDmdVrvWqjs4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+69055+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) header.from= Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1608158277199950.4625629060907; Wed, 16 Dec 2020 14:37:57 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id dDioYY1788612xi0BiItjEZw; Wed, 16 Dec 2020 14:37:55 -0800 X-Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.groups.io with SMTP id smtpd.web11.4895.1608158275094077627 for ; Wed, 16 Dec 2020 14:37:55 -0800 X-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-27-E697Va0fMD-38jPQTgV5Vw-1; Wed, 16 Dec 2020 17:37:52 -0500 X-MC-Unique: E697Va0fMD-38jPQTgV5Vw-1 X-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 308A259; Wed, 16 Dec 2020 22:37:51 +0000 (UTC) X-Received: from lacos-laptop-7.usersys.redhat.com (ovpn-114-152.ams2.redhat.com [10.36.114.152]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9169660C9C; Wed, 16 Dec 2020 22:37:46 +0000 (UTC) From: "Laszlo Ersek" To: devel@edk2.groups.io, virtio-fs@redhat.com, lersek@redhat.com Cc: Ard Biesheuvel , Jordan Justen , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [edk2-devel] [edk2 PATCH 41/48] OvmfPkg/VirtioFsDxe: implement the wrapper function for FUSE_RENAME2 Date: Wed, 16 Dec 2020 22:11:18 +0100 Message-Id: <20201216211125.19496-42-lersek@redhat.com> In-Reply-To: <20201216211125.19496-1-lersek@redhat.com> References: <20201216211125.19496-1-lersek@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,lersek@redhat.com X-Gm-Message-State: 3lbIJ0dumUpXoovhSu0ZwInSx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1608158275; bh=wTSZhfOUJ0kv68+r2N7BlyPi1A6E4DfwkmMLmijkr6c=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=aW68QWH7+8dGJasURp4rL/CCT2L3YFICM/Esxjl7a60zUCnCv/oTBAuFwFlycrjyMvz LN+wOD1o7sWJ738bZcnIlBYCRh8qgxgzv+vxNk5QZpHl+UbIMmd7NarrZy5BGoLQGT8LC pT9WKPsOyhvCW7H90CtkDSP/Jqu2FK+hP5I= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" Add the VirtioFsFuseRename() function, for sending the FUSE_RENAME2 command to the Virtio Filesystem device. Cc: Ard Biesheuvel Cc: Jordan Justen Cc: Philippe Mathieu-Daud=C3=A9 Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3097 Signed-off-by: Laszlo Ersek Acked-by: Ard Biesheuvel --- OvmfPkg/Include/IndustryStandard/VirtioFs.h | 15 +++ OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf | 1 + OvmfPkg/VirtioFsDxe/VirtioFsDxe.h | 9 ++ OvmfPkg/VirtioFsDxe/FuseRename.c | 131 ++++++++++++++++++++ 4 files changed, 156 insertions(+) diff --git a/OvmfPkg/Include/IndustryStandard/VirtioFs.h b/OvmfPkg/Include/= IndustryStandard/VirtioFs.h index 0b7b3ff80edd..0b2ed7010046 100644 --- a/OvmfPkg/Include/IndustryStandard/VirtioFs.h +++ b/OvmfPkg/Include/IndustryStandard/VirtioFs.h @@ -136,16 +136,21 @@ typedef struct { ((Namelen) =3D=3D 0 || (Namelen) > SIZE_4KB ? \ (UINTN)0 : \ ALIGN_VALUE ( \ sizeof (VIRTIO_FS_FUSE_DIRENTPLUS_RESPONSE) + (UINTN)(Namelen), \ sizeof (UINT64) \ ) \ ) =20 +// +// Flags for VirtioFsFuseOpRename2. +// +#define VIRTIO_FS_FUSE_RENAME2_REQ_F_NOREPLACE BIT0 + // // FUSE operation codes. // typedef enum { VirtioFsFuseOpLookup =3D 1, VirtioFsFuseOpForget =3D 2, VirtioFsFuseOpGetAttr =3D 3, VirtioFsFuseOpMkDir =3D 9, @@ -159,16 +164,17 @@ typedef enum { VirtioFsFuseOpFsync =3D 20, VirtioFsFuseOpFlush =3D 25, VirtioFsFuseOpInit =3D 26, VirtioFsFuseOpOpenDir =3D 27, VirtioFsFuseOpReleaseDir =3D 29, VirtioFsFuseOpFsyncDir =3D 30, VirtioFsFuseOpCreate =3D 35, VirtioFsFuseOpReadDirPlus =3D 44, + VirtioFsFuseOpRename2 =3D 45, } VIRTIO_FS_FUSE_OPCODE; =20 #pragma pack (1) // // Request-response headers common to all request types. // typedef struct { UINT32 Len; @@ -393,11 +399,20 @@ typedef struct { typedef struct { VIRTIO_FS_FUSE_NODE_RESPONSE NodeResp; VIRTIO_FS_FUSE_ATTRIBUTES_RESPONSE AttrResp; UINT64 NodeId; UINT64 CookieForNextEntry; UINT32 Namelen; UINT32 Type; } VIRTIO_FS_FUSE_DIRENTPLUS_RESPONSE; + +// +// Header for VirtioFsFuseOpRename2. +// +typedef struct { + UINT64 NewDir; + UINT32 Flags; + UINT32 Padding; +} VIRTIO_FS_FUSE_RENAME2_REQUEST; #pragma pack () =20 #endif // VIRTIO_FS_H_ diff --git a/OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf b/OvmfPkg/VirtioFsDxe/Virt= ioFsDxe.inf index 2c145da5f5ae..9dccd7d6a9ef 100644 --- a/OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf +++ b/OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf @@ -90,16 +90,17 @@ [Sources] FuseInit.c FuseLookup.c FuseMkDir.c FuseOpen.c FuseOpenDir.c FuseOpenOrCreate.c FuseRead.c FuseRelease.c + FuseRename.c FuseStatFs.c FuseUnlink.c FuseWrite.c Helpers.c SimpleFsClose.c SimpleFsDelete.c SimpleFsFlush.c SimpleFsGetInfo.c diff --git a/OvmfPkg/VirtioFsDxe/VirtioFsDxe.h b/OvmfPkg/VirtioFsDxe/Virtio= FsDxe.h index 132a63400527..9334e5434c51 100644 --- a/OvmfPkg/VirtioFsDxe/VirtioFsDxe.h +++ b/OvmfPkg/VirtioFsDxe/VirtioFsDxe.h @@ -391,16 +391,25 @@ EFI_STATUS VirtioFsFuseOpenOrCreate ( IN OUT VIRTIO_FS *VirtioFs, IN UINT64 ParentNodeId, IN CHAR8 *Name, OUT UINT64 *NodeId, OUT UINT64 *FuseHandle ); =20 +EFI_STATUS +VirtioFsFuseRename ( + IN OUT VIRTIO_FS *VirtioFs, + IN UINT64 OldParentNodeId, + IN CHAR8 *OldName, + IN UINT64 NewParentNodeId, + IN CHAR8 *NewName + ); + // // EFI_SIMPLE_FILE_SYSTEM_PROTOCOL member functions for the Virtio Filesys= tem // driver. // =20 EFI_STATUS EFIAPI VirtioFsOpenVolume ( diff --git a/OvmfPkg/VirtioFsDxe/FuseRename.c b/OvmfPkg/VirtioFsDxe/FuseRen= ame.c new file mode 100644 index 000000000000..fc9b27ccf6d4 --- /dev/null +++ b/OvmfPkg/VirtioFsDxe/FuseRename.c @@ -0,0 +1,131 @@ +/** @file + FUSE_RENAME2 wrapper for the Virtio Filesystem device. + + Copyright (C) 2020, Red Hat, Inc. + + SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#include // AsciiStrSize() + +#include "VirtioFsDxe.h" + +/** + Rename a regular file or a directory, by sending the FUSE_RENAME2 reques= t to + the Virtio Filesystem device. If the new filename exists, the request wi= ll + fail. + + The function may only be called after VirtioFsFuseInitSession() returns + successfully and before VirtioFsUninit() is called. + + @param[in,out] VirtioFs The Virtio Filesystem device to send the + FUSE_RENAME2 request to. On output, the FUSE + request counter "VirtioFs->RequestId" will h= ave + been incremented. + + @param[in] OldParentNodeId The inode number of the directory in which + OldName should be removed. + + @param[in] OldName The single-component filename to remove in t= he + directory identified by OldParentNodeId. + + @param[in] NewParentNodeId The inode number of the directory in which + NewName should be created, such that on + successful return, (NewParentNodeId, NewName) + refer to the same inode as (OldParentNodeId, + OldName) did on entry. + + @param[in] NewName The single-component filename to create in t= he + directory identified by NewParentNodeId. + + @retval EFI_SUCCESS The file or directory has been renamed. + + @return The "errno" value mapped to an EFI_STATUS code, if = the + Virtio Filesystem device explicitly reported an err= or. + + @return Error codes propagated from VirtioFsSgListsValidate= (), + VirtioFsFuseNewRequest(), VirtioFsSgListsSubmit(), + VirtioFsFuseCheckResponse(). +**/ +EFI_STATUS +VirtioFsFuseRename ( + IN OUT VIRTIO_FS *VirtioFs, + IN UINT64 OldParentNodeId, + IN CHAR8 *OldName, + IN UINT64 NewParentNodeId, + IN CHAR8 *NewName + ) +{ + VIRTIO_FS_FUSE_REQUEST CommonReq; + VIRTIO_FS_FUSE_RENAME2_REQUEST Rename2Req; + VIRTIO_FS_IO_VECTOR ReqIoVec[4]; + VIRTIO_FS_SCATTER_GATHER_LIST ReqSgList; + VIRTIO_FS_FUSE_RESPONSE CommonResp; + VIRTIO_FS_IO_VECTOR RespIoVec[1]; + VIRTIO_FS_SCATTER_GATHER_LIST RespSgList; + EFI_STATUS Status; + + // + // Set up the scatter-gather lists. + // + ReqIoVec[0].Buffer =3D &CommonReq; + ReqIoVec[0].Size =3D sizeof CommonReq; + ReqIoVec[1].Buffer =3D &Rename2Req; + ReqIoVec[1].Size =3D sizeof Rename2Req; + ReqIoVec[2].Buffer =3D OldName; + ReqIoVec[2].Size =3D AsciiStrSize (OldName); + ReqIoVec[3].Buffer =3D NewName; + ReqIoVec[3].Size =3D AsciiStrSize (NewName); + ReqSgList.IoVec =3D ReqIoVec; + ReqSgList.NumVec =3D ARRAY_SIZE (ReqIoVec); + + RespIoVec[0].Buffer =3D &CommonResp; + RespIoVec[0].Size =3D sizeof CommonResp; + RespSgList.IoVec =3D RespIoVec; + RespSgList.NumVec =3D ARRAY_SIZE (RespIoVec); + + // + // Validate the scatter-gather lists; calculate the total transfer sizes. + // + Status =3D VirtioFsSgListsValidate (VirtioFs, &ReqSgList, &RespSgList); + if (EFI_ERROR (Status)) { + return Status; + } + + // + // Populate the common request header. + // + Status =3D VirtioFsFuseNewRequest (VirtioFs, &CommonReq, ReqSgList.Total= Size, + VirtioFsFuseOpRename2, OldParentNodeId); + if (EFI_ERROR (Status)) { + return Status; + } + + // + // Populate the FUSE_RENAME2-specific fields. + // + Rename2Req.NewDir =3D NewParentNodeId; + Rename2Req.Flags =3D VIRTIO_FS_FUSE_RENAME2_REQ_F_NOREPLACE; + Rename2Req.Padding =3D 0; + + // + // Submit the request. + // + Status =3D VirtioFsSgListsSubmit (VirtioFs, &ReqSgList, &RespSgList); + if (EFI_ERROR (Status)) { + return Status; + } + + // + // Verify the response (all response buffers are fixed size). + // + Status =3D VirtioFsFuseCheckResponse (&RespSgList, CommonReq.Unique, NUL= L); + if (Status =3D=3D EFI_DEVICE_ERROR) { + DEBUG ((DEBUG_ERROR, "%a: Label=3D\"%s\" OldParentNodeId=3D%Lu OldName= =3D\"%a\" " + "NewParentNodeId=3D%Lu NewName=3D\"%a\" Errno=3D%d\n", __FUNCTION__, + VirtioFs->Label, OldParentNodeId, OldName, NewParentNodeId, NewName, + CommonResp.Error)); + Status =3D VirtioFsErrnoToEfiStatus (CommonResp.Error); + } + return Status; +} --=20 2.19.1.3.g30247aa5d201 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#69055): https://edk2.groups.io/g/devel/message/69055 Mute This Topic: https://groups.io/mt/79024401/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Tue May 7 07:56:31 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+69056+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+69056+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1608158408; cv=none; d=zohomail.com; s=zohoarc; b=UAV2/ePlSQdfnZjHGgKCx9LvtcCnRKD7Y1L4EwZqHmnRtwYqP0W6hoDi+vLSXlZTnGVGzWfujEYTQiviat/9Hp9zTM8iFSZZAU79FKt/aqf/LcV7N5UxJJRLDWyJAPlWUEpZnNQLAWzCD5t8n15DoGY4LxM1Ve8rM6L+iMA7X+I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608158408; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=7KsP6/78c+6UI7/m3lxNQ1W4mlHlPkxaVu4fiNFetK8=; b=TjEmTSlyV6QMJuOOyr6GmV/6u1Xq5Uwlyw2vONTuP9c96onU1XXES+0OLoyiYP7YBKvzUFOzaMbb/aFKsCd2caHdMTIdPa7nXfWWZ6HsXFdbky41ZAMyUQNQ5n81OnrvXV30BYR30qZH1qJJP/Lmzh4i7Ci8Ch8yCf5+eCSkzmI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+69056+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) header.from= Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 160815840866351.72386462816269; Wed, 16 Dec 2020 14:40:08 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id stVXYY1788612x2awBD1vGoC; Wed, 16 Dec 2020 14:40:08 -0800 X-Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.groups.io with SMTP id smtpd.web09.4862.1608158402654984048 for ; Wed, 16 Dec 2020 14:40:02 -0800 X-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-332-x-UbvzVlOCu972sdkrg86Q-1; Wed, 16 Dec 2020 17:39:59 -0500 X-MC-Unique: x-UbvzVlOCu972sdkrg86Q-1 X-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 2CF4181441E; Wed, 16 Dec 2020 22:39:54 +0000 (UTC) X-Received: from lacos-laptop-7.usersys.redhat.com (ovpn-114-152.ams2.redhat.com [10.36.114.152]) by smtp.corp.redhat.com (Postfix) with ESMTP id 72DEF62953; Wed, 16 Dec 2020 22:39:52 +0000 (UTC) From: "Laszlo Ersek" To: devel@edk2.groups.io, virtio-fs@redhat.com, lersek@redhat.com Cc: Ard Biesheuvel , Jordan Justen , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [edk2-devel] [edk2 PATCH 42/48] OvmfPkg/VirtioFsDxe: add helper for composing rename/move destination path Date: Wed, 16 Dec 2020 22:11:19 +0100 Message-Id: <20201216211125.19496-43-lersek@redhat.com> In-Reply-To: <20201216211125.19496-1-lersek@redhat.com> References: <20201216211125.19496-1-lersek@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,lersek@redhat.com X-Gm-Message-State: tcg5ZG9P9T6W65kAcbX4XuGhx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1608158408; bh=7KsP6/78c+6UI7/m3lxNQ1W4mlHlPkxaVu4fiNFetK8=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=e5VeJC77/XJg9spAvTqkyfXF/t9Qll3muNIKjm84kzvMp+/0lTBH/VoiY+vcp+tFN+k hah7LT+P+I6a5msaGUP1jSRnfBSjZQxjHfqpH4aVpA3d0WqFuDhCGnVxATrFdp+8YFMCd xeNA3Mo7ZO8Djnk0KJhrDXz+fW7F6hMORhA= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" The EFI_FILE_PROTOCOL.SetInfo() member is somewhat under-specified; one of its modes of operation is renaming/moving the file. In order to create the destination pathname in canonical format, 2*2=3D4 cases have to be considered. For the sake of discussion, assume the current canonical pathname of a VIRTIO_FS_FILE is "/home/user/f1.txt". Then, consider the following rename/move requests from EFI_FILE_PROTOCOL.SetInfo(): Destination requested Destination Move into Destination in by SetInfo() relative? directory? canonical format --------------------- ----------- ---------- ----------------------- L"\\dir\\f2.txt" no no "/dir/f2.txt" L"\\dir\\" no yes "/dir/f1.txt" L"dir\\f2.txt" yes no "/home/user/dir/f2.txt" L"dir\\" yes yes "/home/user/dir/f1.txt" Add the VirtioFsComposeRenameDestination() function, for composing the last column from the current canonical pathname and the SetInfo() input. The function works on the following principles: - The prefix of the destination path is "/", if the SetInfo() rename request is absolute. Otherwise, the dest prefix is the "current directory" (the most specific parent directory) of the original pathname (in the above example, "/home/user"). - The suffix of the destination path is precisely the SetInfo() request string, if the "move into directory" convenience format -- the trailing backslash -- is not used. (In the above example, L"\\dir\\f2.txt" and L"dir\\f2.txt".) Otherwise, the suffix is the SetInfo() request, plus the original basename (in the above example, L"\\dir\\f1.txt" and L"dir\\f1.txt"). - The complete destination is created by fusing the dest prefix and the dest suffix, using the VirtioFsAppendPath() function. Cc: Ard Biesheuvel Cc: Jordan Justen Cc: Philippe Mathieu-Daud=C3=A9 Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3097 Signed-off-by: Laszlo Ersek Acked-by: Ard Biesheuvel --- OvmfPkg/VirtioFsDxe/VirtioFsDxe.h | 8 + OvmfPkg/VirtioFsDxe/Helpers.c | 194 ++++++++++++++++++++ 2 files changed, 202 insertions(+) diff --git a/OvmfPkg/VirtioFsDxe/VirtioFsDxe.h b/OvmfPkg/VirtioFsDxe/Virtio= FsDxe.h index 9334e5434c51..a6dfac71f4a7 100644 --- a/OvmfPkg/VirtioFsDxe/VirtioFsDxe.h +++ b/OvmfPkg/VirtioFsDxe/VirtioFsDxe.h @@ -257,16 +257,24 @@ VirtioFsLookupMostSpecificParentDir ( =20 EFI_STATUS VirtioFsGetBasename ( IN CHAR8 *Path, OUT CHAR16 *Basename OPTIONAL, IN OUT UINTN *BasenameSize ); =20 +EFI_STATUS +VirtioFsComposeRenameDestination ( + IN CHAR8 *LhsPath8, + IN CHAR16 *RhsPath16, + OUT CHAR8 **ResultPath8, + OUT BOOLEAN *RootEscape + ); + EFI_STATUS VirtioFsFuseAttrToEfiFileInfo ( IN VIRTIO_FS_FUSE_ATTRIBUTES_RESPONSE *FuseAttr, OUT EFI_FILE_INFO *FileInfo ); =20 EFI_STATUS VirtioFsFuseDirentPlusToEfiFileInfo ( diff --git a/OvmfPkg/VirtioFsDxe/Helpers.c b/OvmfPkg/VirtioFsDxe/Helpers.c index cdaa8557a17b..b741cf753495 100644 --- a/OvmfPkg/VirtioFsDxe/Helpers.c +++ b/OvmfPkg/VirtioFsDxe/Helpers.c @@ -1778,16 +1778,210 @@ VirtioFsGetBasename ( } =20 for (Idx =3D LastComponent; Idx < PathSize; Idx++) { Basename[Idx - LastComponent] =3D Path[Idx]; } return EFI_SUCCESS; } =20 +/** + Format the destination of a rename/move operation as a dynamically alloc= ated + canonical pathname. + + Any dot-dot in RhsPath16 that would remove the root directory is dropped= , and + reported through RootEscape, without failing the function call. + + @param[in] LhsPath8 The source pathname operand of the rename/move + operation, expressed as a canonical pathname (as + defined in the description of VirtioFsAppendPath= ()). + The root directory "/" cannot be renamed/moved, = and + will be rejected. + + @param[in] RhsPath16 The destination pathname operand expressed as a + UEFI-style CHAR16 pathname. + + If RhsPath16 starts with a backslash, then RhsPa= th16 + is considered absolute. Otherwise, RhsPath16 is + interpreted relative to the most specific parent + directory found in LhsPath8. + + Independently, if RhsPath16 ends with a backslash + (i.e., RhsPath16 is given in the "move into + directory" convenience form), then RhsPath16 is + interpreted with the basename of LhsPath8 append= ed. + Otherwise, the last pathname component of RhsPat= h16 + is taken as the last pathname component of the + rename/move destination. + + An empty RhsPath16 is rejected. + + @param[out] ResultPath8 The POSIX-style, canonical format pathname that + leads to the renamed/moved file. After use, the + caller is responsible for freeing ResultPath8. + + @param[out] RootEscape Set to TRUE if at least one dot-dot component in + RhsPath16 attempted to escape the root director= y; + set to FALSE otherwise. + + @retval EFI_SUCCESS ResultPath8 has been produced. RootEscape= has + been output. + + @retval EFI_INVALID_PARAMETER LhsPath8 is "/". + + @retval EFI_INVALID_PARAMETER RhsPath16 is zero-length. + + @retval EFI_INVALID_PARAMETER RhsPath16 failed the + VIRTIO_FS_MAX_PATHNAME_LENGTH check. + + @retval EFI_OUT_OF_RESOURCES Memory allocation failed. + + @retval EFI_OUT_OF_RESOURCES ResultPath8 would have failed the + VIRTIO_FS_MAX_PATHNAME_LENGTH check. + + @retval EFI_UNSUPPORTED RhsPath16 contains a character that either + falls outside of the printable ASCII set,= or + is a forward slash. +**/ +EFI_STATUS +VirtioFsComposeRenameDestination ( + IN CHAR8 *LhsPath8, + IN CHAR16 *RhsPath16, + OUT CHAR8 **ResultPath8, + OUT BOOLEAN *RootEscape + ) +{ + // + // Lengths are expressed as numbers of characters (CHAR8 or CHAR16), + // excluding terminating NULs. Sizes are expressed as byte counts, inclu= ding + // the bytes taken up by terminating NULs. + // + UINTN RhsLen; + UINTN LhsBasename16Size; + EFI_STATUS Status; + UINTN LhsBasenameLen; + UINTN DestSuffix16Size; + CHAR16 *DestSuffix16; + CHAR8 *DestPrefix8; + + // + // An empty destination operand for the rename/move operation is not all= owed. + // + RhsLen =3D StrLen (RhsPath16); + if (RhsLen =3D=3D 0) { + return EFI_INVALID_PARAMETER; + } + // + // Enforce length restriction on RhsPath16. + // + if (RhsLen > VIRTIO_FS_MAX_PATHNAME_LENGTH) { + return EFI_INVALID_PARAMETER; + } + + // + // Determine the length of the basename of LhsPath8. + // + LhsBasename16Size =3D 0; + Status =3D VirtioFsGetBasename (LhsPath8, NULL, &LhsBasename16Size); + ASSERT (Status =3D=3D EFI_BUFFER_TOO_SMALL); + ASSERT (LhsBasename16Size >=3D sizeof (CHAR16)); + ASSERT (LhsBasename16Size % sizeof (CHAR16) =3D=3D 0); + LhsBasenameLen =3D LhsBasename16Size / sizeof (CHAR16) - 1; + if (LhsBasenameLen =3D=3D 0) { + // + // The root directory cannot be renamed/moved. + // + return EFI_INVALID_PARAMETER; + } + + // + // Resolve the "move into directory" convenience form in RhsPath16. + // + if (RhsPath16[RhsLen - 1] =3D=3D L'\\') { + // + // Append the basename of LhsPath8 as a CHAR16 string to RhsPath16. + // + DestSuffix16Size =3D RhsLen * sizeof (CHAR16) + LhsBasename16Size; + DestSuffix16 =3D AllocatePool (DestSuffix16Size); + if (DestSuffix16 =3D=3D NULL) { + return EFI_OUT_OF_RESOURCES; + } + CopyMem (DestSuffix16, RhsPath16, RhsLen * sizeof (CHAR16)); + Status =3D VirtioFsGetBasename (LhsPath8, DestSuffix16 + RhsLen, + &LhsBasename16Size); + ASSERT_EFI_ERROR (Status); + } else { + // + // Just create a copy of RhsPath16. + // + DestSuffix16Size =3D (RhsLen + 1) * sizeof (CHAR16); + DestSuffix16 =3D AllocateCopyPool (DestSuffix16Size, RhsPath16); + if (DestSuffix16 =3D=3D NULL) { + return EFI_OUT_OF_RESOURCES; + } + } + + // + // If the destination operand is absolute, it will be interpreted relati= ve to + // the root directory. + // + // Otherwise (i.e., if the destination operand is relative), then create= the + // canonical pathname that the destination operand is interpreted relati= vely + // to; that is, the canonical pathname of the most specific parent direc= tory + // found in LhsPath8. + // + if (DestSuffix16[0] =3D=3D L'\\') { + DestPrefix8 =3D AllocateCopyPool (sizeof "/", "/"); + if (DestPrefix8 =3D=3D NULL) { + Status =3D EFI_OUT_OF_RESOURCES; + goto FreeDestSuffix16; + } + } else { + UINTN LhsLen; + UINTN DestPrefixLen; + + // + // Strip the basename of LhsPath8. + // + LhsLen =3D AsciiStrLen (LhsPath8); + ASSERT (LhsBasenameLen < LhsLen); + DestPrefixLen =3D LhsLen - LhsBasenameLen; + ASSERT (LhsPath8[DestPrefixLen - 1] =3D=3D '/'); + // + // If we're not at the root directory, strip the slash too. + // + if (DestPrefixLen > 1) { + DestPrefixLen--; + } + DestPrefix8 =3D AllocatePool (DestPrefixLen + 1); + if (DestPrefix8 =3D=3D NULL) { + Status =3D EFI_OUT_OF_RESOURCES; + goto FreeDestSuffix16; + } + CopyMem (DestPrefix8, LhsPath8, DestPrefixLen); + DestPrefix8[DestPrefixLen] =3D '\0'; + } + + // + // Now combine DestPrefix8 and DestSuffix16 into the final canonical + // pathname. + // + Status =3D VirtioFsAppendPath (DestPrefix8, DestSuffix16, ResultPath8, + RootEscape); + + FreePool (DestPrefix8); + // + // Fall through. + // +FreeDestSuffix16: + FreePool (DestSuffix16); + + return Status; +} + /** Convert select fields of a VIRTIO_FS_FUSE_ATTRIBUTES_RESPONSE object to corresponding fields in EFI_FILE_INFO. =20 @param[in] FuseAttr The VIRTIO_FS_FUSE_ATTRIBUTES_RESPONSE object to convert the relevant fields from. =20 @param[out] FileInfo The EFI_FILE_INFO structure to modify. Importantly= , the --=20 2.19.1.3.g30247aa5d201 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#69056): https://edk2.groups.io/g/devel/message/69056 Mute This Topic: https://groups.io/mt/79024445/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Tue May 7 07:56:31 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+69057+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+69057+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1608158524; cv=none; d=zohomail.com; s=zohoarc; b=ThfeS48/xXf8oaf83fZb8/7YY+pvA9uGJionVYkV9uAg65ec0ZZvJuMnqLllnlIC+mIQ4u08E7dB+Pumknay3/BRVO4XjqaUlZ7KozvfIK6mXdQO1vsZjHeUDUp4/wF213ILtHGPufnd06Kz61Xa0TKeBCyA+w4hEbRr3xTybB4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608158524; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=ELV9cx4rWAkc/Y2TNsgL6MPBQUqJMlPiJcs0+JcOp74=; b=C+y1NJhIhnTvi9FUUCu8WDractdXjhZ87jvW/DzrDOlDw3BU9Klvi2P0CXaJ5JaMURdjVDmgAdQvc+LRhzeaxMRkNR7b8c2Oudsym9ZU7XGH5ZqB+tR5ra10QH1C346m9Dd6vE+agLJbaiqwOQWzWRZPyH54bQXbXXA6NgLnkbQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+69057+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) header.from= Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1608158524744731.5570134142256; Wed, 16 Dec 2020 14:42:04 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id rCONYY1788612xXIg4GnFDml; Wed, 16 Dec 2020 14:42:04 -0800 X-Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.groups.io with SMTP id smtpd.web09.4892.1608158523714886860 for ; Wed, 16 Dec 2020 14:42:04 -0800 X-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-464-CO5xvLpBP6mzLnhumGaN6g-1; Wed, 16 Dec 2020 17:42:01 -0500 X-MC-Unique: CO5xvLpBP6mzLnhumGaN6g-1 X-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 D6CBE801A9E; Wed, 16 Dec 2020 22:41:59 +0000 (UTC) X-Received: from lacos-laptop-7.usersys.redhat.com (ovpn-114-152.ams2.redhat.com [10.36.114.152]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4C7991971D; Wed, 16 Dec 2020 22:41:55 +0000 (UTC) From: "Laszlo Ersek" To: devel@edk2.groups.io, virtio-fs@redhat.com, lersek@redhat.com Cc: Ard Biesheuvel , Jordan Justen , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [edk2-devel] [edk2 PATCH 43/48] OvmfPkg/VirtioFsDxe: handle file rename/move in EFI_FILE_PROTOCOL.SetInfo Date: Wed, 16 Dec 2020 22:11:20 +0100 Message-Id: <20201216211125.19496-44-lersek@redhat.com> In-Reply-To: <20201216211125.19496-1-lersek@redhat.com> References: <20201216211125.19496-1-lersek@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,lersek@redhat.com X-Gm-Message-State: OIHC7LBB2ELJgfCXYQNjkHNbx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1608158524; bh=ELV9cx4rWAkc/Y2TNsgL6MPBQUqJMlPiJcs0+JcOp74=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=bHPjmNA9Wht7Fwx48U0q7k5pVfJJqs/ZO9h6DdbVefYCdCqsw/fOBnjH6ra+kZVFUZS Sd9Mnb8meJYZDZj07sLGp/0Wlk0LVBfKXX7TUWsgPyeIRrczL+oBfoNb8DHaDfSevNJti Sg/54VNBVQf2BavV4Qfod8ok7SusUj2mQA8= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" Using the functions introduced previously, we can now implement the rename operation in VirtioFsSimpleFileSetInfo(). Attribute updates come later. Cc: Ard Biesheuvel Cc: Jordan Justen Cc: Philippe Mathieu-Daud=C3=A9 Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3097 Signed-off-by: Laszlo Ersek Acked-by: Ard Biesheuvel --- OvmfPkg/VirtioFsDxe/SimpleFsSetInfo.c | 234 +++++++++++++++++++- 1 file changed, 233 insertions(+), 1 deletion(-) diff --git a/OvmfPkg/VirtioFsDxe/SimpleFsSetInfo.c b/OvmfPkg/VirtioFsDxe/Si= mpleFsSetInfo.c index 895b5c029a9e..55169dde78b7 100644 --- a/OvmfPkg/VirtioFsDxe/SimpleFsSetInfo.c +++ b/OvmfPkg/VirtioFsDxe/SimpleFsSetInfo.c @@ -5,16 +5,17 @@ =20 SPDX-License-Identifier: BSD-2-Clause-Patent **/ =20 #include // gEfiFileSystemInfoGuid #include // gEfiFileSystemVolumeLabelIn= fo... #include // StrCmp() #include // CompareGuid() +#include // FreePool() =20 #include "VirtioFsDxe.h" =20 /** Validate a buffer that the EFI_FILE_PROTOCOL.SetInfo() caller passes in = for a particular InformationType GUID. =20 The structure to be validated is supposed to end with a variable-length, @@ -122,16 +123,247 @@ ValidateInfoStructure ( NameField =3D (CHAR16 *)((UINT8 *)Buffer + NameFieldByteOffset); if (NameField[NameFieldChar16s - 1] !=3D L'\0') { return EFI_INVALID_PARAMETER; } =20 return EFI_SUCCESS; } =20 +/** + Rename a VIRTIO_FS_FILE as requested in EFI_FILE_INFO.FileName. + + @param[in,out] VirtioFsFile The VIRTIO_FS_FILE to rename. + + @param[in] NewFileName The new file name requested by + EFI_FILE_PROTOCOL.SetInfo(). + + @retval EFI_SUCCESS The canonical format destination path that is + determined from the input value of + VirtioFsFile->CanonicalPathname and from + NewFileName is identical to the input value of + VirtioFsFile->CanonicalPathname. This means t= hat + EFI_FILE_INFO does not constitute a rename + request. VirtioFsFile has not been changed. + + @retval EFI_SUCCESS VirtioFsFile has been renamed. + VirtioFsFile->CanonicalPathname has assumed t= he + destination pathname in canonical format. + + @retval EFI_ACCESS_DENIED VirtioFsFile refers to the root directory, and + NewFileName expresses an actual rename/move + request. + + @retval EFI_ACCESS_DENIED VirtioFsFile is the (possibly indirect) parent + directory of at least one other VIRTIO_FS_FILE + that is open for the same Virtio Filesystem + (identified by VirtioFsFile->OwnerFs). Renami= ng + VirtioFsFile would invalidate the canonical + pathnames of those VIRTIO_FS_FILE instances; + therefore the request has been rejected. + + @retval EFI_ACCESS_DENIED VirtioFsFile is not open for writing, but + NewFileName expresses an actual rename/move + request. + + @retval EFI_NOT_FOUND At least one dot-dot component in NewFileName + attempted to escape the root directory. + + @return Error codes propagated from underlying functi= ons. +**/ +STATIC +EFI_STATUS +Rename ( + IN OUT VIRTIO_FS_FILE *VirtioFsFile, + IN CHAR16 *NewFileName + ) +{ + + VIRTIO_FS *VirtioFs; + EFI_STATUS Status; + CHAR8 *Destination; + BOOLEAN RootEscape; + UINT64 OldParentDirNodeId; + CHAR8 *OldLastComponent; + UINT64 NewParentDirNodeId; + CHAR8 *NewLastComponent; + + VirtioFs =3D VirtioFsFile->OwnerFs; + + // + // The root directory cannot be renamed. + // + if (AsciiStrCmp (VirtioFsFile->CanonicalPathname, "/") =3D=3D 0) { + if (StrCmp (NewFileName, L"") =3D=3D 0) { + // + // Not a rename request anyway. + // + return EFI_SUCCESS; + } + return EFI_ACCESS_DENIED; + } + + // + // Compose the canonical pathname for the destination. + // + Status =3D VirtioFsComposeRenameDestination (VirtioFsFile->CanonicalPath= name, + NewFileName, &Destination, &RootEscape); + if (EFI_ERROR (Status)) { + return Status; + } + if (RootEscape) { + Status =3D EFI_NOT_FOUND; + goto FreeDestination; + } + // + // If the rename would leave VirtioFsFile->CanonicalPathname unchanged, = then + // EFI_FILE_PROTOCOL.SetInfo() isn't asking for a rename actually. + // + if (AsciiStrCmp (VirtioFsFile->CanonicalPathname, Destination) =3D=3D 0)= { + Status =3D EFI_SUCCESS; + goto FreeDestination; + } + // + // Check if the rename would break the canonical pathnames of other + // VIRTIO_FS_FILE instances of the same VIRTIO_FS. + // + if (VirtioFsFile->IsDirectory) { + UINTN PathLen; + LIST_ENTRY *OpenFilesEntry; + + PathLen =3D AsciiStrLen (VirtioFsFile->CanonicalPathname); + BASE_LIST_FOR_EACH (OpenFilesEntry, &VirtioFs->OpenFiles) { + VIRTIO_FS_FILE *OtherFile; + + OtherFile =3D VIRTIO_FS_FILE_FROM_OPEN_FILES_ENTRY (OpenFilesEntry); + if (OtherFile !=3D VirtioFsFile && + AsciiStrnCmp (VirtioFsFile->CanonicalPathname, + OtherFile->CanonicalPathname, PathLen) =3D=3D 0 && + (OtherFile->CanonicalPathname[PathLen] =3D=3D '\0' || + OtherFile->CanonicalPathname[PathLen] =3D=3D '/')) { + // + // OtherFile refers to the same directory as VirtioFsFile, or is a + // (possibly indirect) child of the directory referred to by + // VirtioFsFile. + // + Status =3D EFI_ACCESS_DENIED; + goto FreeDestination; + } + } + } + // + // From this point on, the file needs to be open for writing. + // + if (!VirtioFsFile->IsOpenForWriting) { + Status =3D EFI_ACCESS_DENIED; + goto FreeDestination; + } + // + // Split both source and destination canonical pathnames into (most spec= ific + // parent directory, last component) pairs. + // + Status =3D VirtioFsLookupMostSpecificParentDir (VirtioFs, + VirtioFsFile->CanonicalPathname, &OldParentDirNodeId, + &OldLastComponent); + if (EFI_ERROR (Status)) { + goto FreeDestination; + } + Status =3D VirtioFsLookupMostSpecificParentDir (VirtioFs, Destination, + &NewParentDirNodeId, &NewLastComponent); + if (EFI_ERROR (Status)) { + goto ForgetOldParentDirNodeId; + } + // + // Perform the rename. If the destination path exists, the rename will f= ail. + // + Status =3D VirtioFsFuseRename (VirtioFs, OldParentDirNodeId, OldLastComp= onent, + NewParentDirNodeId, NewLastComponent); + if (EFI_ERROR (Status)) { + goto ForgetNewParentDirNodeId; + } + + // + // Swap in the new canonical pathname. + // + FreePool (VirtioFsFile->CanonicalPathname); + VirtioFsFile->CanonicalPathname =3D Destination; + Destination =3D NULL; + Status =3D EFI_SUCCESS; + + // + // Fall through. + // +ForgetNewParentDirNodeId: + if (NewParentDirNodeId !=3D VIRTIO_FS_FUSE_ROOT_DIR_NODE_ID) { + VirtioFsFuseForget (VirtioFs, NewParentDirNodeId); + } + +ForgetOldParentDirNodeId: + if (OldParentDirNodeId !=3D VIRTIO_FS_FUSE_ROOT_DIR_NODE_ID) { + VirtioFsFuseForget (VirtioFs, OldParentDirNodeId); + } + +FreeDestination: + if (Destination !=3D NULL) { + FreePool (Destination); + } + return Status; +} + +/** + Process an EFI_FILE_INFO setting request. +**/ +STATIC +EFI_STATUS +SetFileInfo ( + IN EFI_FILE_PROTOCOL *This, + IN UINTN BufferSize, + IN VOID *Buffer + ) +{ + VIRTIO_FS_FILE *VirtioFsFile; + EFI_STATUS Status; + EFI_FILE_INFO *FileInfo; + + VirtioFsFile =3D VIRTIO_FS_FILE_FROM_SIMPLE_FILE (This); + + // + // Validate if Buffer passes as EFI_FILE_INFO. + // + Status =3D ValidateInfoStructure ( + BufferSize, // SizeByProtocolCaller + OFFSET_OF (EFI_FILE_INFO, + FileName) + sizeof (CHAR16), // MinimumStructSize + TRUE, // IsSizeByInfoPresent + Buffer + ); + if (EFI_ERROR (Status)) { + return Status; + } + FileInfo =3D Buffer; + + // + // Perform the rename/move request, if any. + // + Status =3D Rename (VirtioFsFile, FileInfo->FileName); + if (EFI_ERROR (Status)) { + return Status; + } + // + // Update any attributes requested. + // + Status =3D EFI_UNSUPPORTED; + // + // The UEFI spec does not speak about partial failure in + // EFI_FILE_PROTOCOL.SetInfo(); we won't try to roll back the rename (if + // there was one) in case the attribute updates fail. + // + return Status; +} + /** Process an EFI_FILE_SYSTEM_INFO setting request. **/ STATIC EFI_STATUS SetFileSystemInfo ( IN EFI_FILE_PROTOCOL *This, IN UINTN BufferSize, @@ -225,17 +457,17 @@ EFIAPI VirtioFsSimpleFileSetInfo ( IN EFI_FILE_PROTOCOL *This, IN EFI_GUID *InformationType, IN UINTN BufferSize, IN VOID *Buffer ) { if (CompareGuid (InformationType, &gEfiFileInfoGuid)) { - return EFI_UNSUPPORTED; + return SetFileInfo (This, BufferSize, Buffer); } =20 if (CompareGuid (InformationType, &gEfiFileSystemInfoGuid)) { return SetFileSystemInfo (This, BufferSize, Buffer); } =20 if (CompareGuid (InformationType, &gEfiFileSystemVolumeLabelInfoIdGuid))= { return SetFileSystemVolumeLabelInfo (This, BufferSize, Buffer); --=20 2.19.1.3.g30247aa5d201 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#69057): https://edk2.groups.io/g/devel/message/69057 Mute This Topic: https://groups.io/mt/79024496/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Tue May 7 07:56:31 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+69058+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+69058+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1608158653; cv=none; d=zohomail.com; s=zohoarc; b=XWdjg/FagUgscdL0R7GTCPdJV68ecbX22jIdcrS7PhFQPlXGYrh/QEsPe6SNKqx1PfMYPcC5K7n7N6FF8ErF2omdEwBJek99iFwr4yitXOuR7iC43gHr2zs0bG681uLd1/zmjdGZOw6fnuokcE9JIhAXyd+B3umls5wVrRODCAU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608158653; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=GDKgXsLLfEpksZmu4mx6QXbPFlFmETY5bHM+hlGtZSE=; b=mTpbH+Y2FPlr7038cew+Jw2BazWH0ozy1UAdbXLnhNrxlOX/zxtU9X3eD1ISNvfE03bB8yF1/ggl5GwaIZMyWcLAax7n294KvZf9jMutEjbqOQTDLaURF/erWxgY7cb9phNyaJVALgQOmyA6iDJGj4Yq9UlDTo1/tzZ67M1wzq8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+69058+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) header.from= Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1608158653596116.24269579735142; Wed, 16 Dec 2020 14:44:13 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id 5pHrYY1788612xNd4YJDISVv; Wed, 16 Dec 2020 14:44:13 -0800 X-Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.groups.io with SMTP id smtpd.web12.5082.1608158652539132251 for ; Wed, 16 Dec 2020 14:44:12 -0800 X-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-261-s4poW6tuPAqI_9iaqKkCHQ-1; Wed, 16 Dec 2020 17:44:10 -0500 X-MC-Unique: s4poW6tuPAqI_9iaqKkCHQ-1 X-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 A983410054FF; Wed, 16 Dec 2020 22:44:08 +0000 (UTC) X-Received: from lacos-laptop-7.usersys.redhat.com (ovpn-114-152.ams2.redhat.com [10.36.114.152]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1D7A85D9C0; Wed, 16 Dec 2020 22:44:00 +0000 (UTC) From: "Laszlo Ersek" To: devel@edk2.groups.io, virtio-fs@redhat.com, lersek@redhat.com Cc: Ard Biesheuvel , Jordan Justen , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [edk2-devel] [edk2 PATCH 44/48] OvmfPkg/VirtioFsDxe: implement the wrapper function for FUSE_SETATTR Date: Wed, 16 Dec 2020 22:11:21 +0100 Message-Id: <20201216211125.19496-45-lersek@redhat.com> In-Reply-To: <20201216211125.19496-1-lersek@redhat.com> References: <20201216211125.19496-1-lersek@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,lersek@redhat.com X-Gm-Message-State: iEoQNjVQn5OBntvz0thoaJ7Kx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1608158653; bh=GDKgXsLLfEpksZmu4mx6QXbPFlFmETY5bHM+hlGtZSE=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=sphupKZbSsjVE/vpmkNofMXKpDF1RuzjWgjJ7Rw/jwOjLskmYPb3+utIXpLJeshkkHO X3wtWlPoJsLu+9dGJWWbx5Iu0hFkdYLLBxyaxbw33xrpnvasQk3iTj1MNW7OSJNBeqTey JyizphRY1ZbtRc75wjUIe9U9H4X8T7TmnT4= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" Add the VirtioFsFuseSetAttr() function, for sending the FUSE_SETATTR command to the Virtio Filesystem device. Cc: Ard Biesheuvel Cc: Jordan Justen Cc: Philippe Mathieu-Daud=C3=A9 Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3097 Signed-off-by: Laszlo Ersek Acked-by: Ard Biesheuvel --- OvmfPkg/Include/IndustryStandard/VirtioFs.h | 35 +++- OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf | 1 + OvmfPkg/VirtioFsDxe/VirtioFsDxe.h | 10 ++ OvmfPkg/VirtioFsDxe/FuseSetAttr.c | 174 ++++++++++++++++++++ 4 files changed, 219 insertions(+), 1 deletion(-) diff --git a/OvmfPkg/Include/IndustryStandard/VirtioFs.h b/OvmfPkg/Include/= IndustryStandard/VirtioFs.h index 0b2ed7010046..15fb28f95a28 100644 --- a/OvmfPkg/Include/IndustryStandard/VirtioFs.h +++ b/OvmfPkg/Include/IndustryStandard/VirtioFs.h @@ -97,16 +97,25 @@ typedef struct { #define VIRTIO_FS_FUSE_MODE_PERM_WUSR 0000200u #define VIRTIO_FS_FUSE_MODE_PERM_RWXG 0000070u #define VIRTIO_FS_FUSE_MODE_PERM_RGRP 0000040u #define VIRTIO_FS_FUSE_MODE_PERM_WGRP 0000020u #define VIRTIO_FS_FUSE_MODE_PERM_RWXO 0000007u #define VIRTIO_FS_FUSE_MODE_PERM_ROTH 0000004u #define VIRTIO_FS_FUSE_MODE_PERM_WOTH 0000002u =20 +// +// Flags for VirtioFsFuseOpSetAttr, in the VIRTIO_FS_FUSE_SETATTR_REQUEST.= Valid +// field. +// +#define VIRTIO_FS_FUSE_SETATTR_REQ_F_MODE BIT0 +#define VIRTIO_FS_FUSE_SETATTR_REQ_F_SIZE BIT3 +#define VIRTIO_FS_FUSE_SETATTR_REQ_F_ATIME BIT4 +#define VIRTIO_FS_FUSE_SETATTR_REQ_F_MTIME BIT5 + // // Flags for VirtioFsFuseOpOpen. // #define VIRTIO_FS_FUSE_OPEN_REQ_F_RDONLY 0 #define VIRTIO_FS_FUSE_OPEN_REQ_F_RDWR 2 =20 // // Flags for VirtioFsFuseOpInit. @@ -148,16 +157,17 @@ typedef struct { =20 // // FUSE operation codes. // typedef enum { VirtioFsFuseOpLookup =3D 1, VirtioFsFuseOpForget =3D 2, VirtioFsFuseOpGetAttr =3D 3, + VirtioFsFuseOpSetAttr =3D 4, VirtioFsFuseOpMkDir =3D 9, VirtioFsFuseOpUnlink =3D 10, VirtioFsFuseOpRmDir =3D 11, VirtioFsFuseOpOpen =3D 14, VirtioFsFuseOpRead =3D 15, VirtioFsFuseOpWrite =3D 16, VirtioFsFuseOpStatFs =3D 17, VirtioFsFuseOpRelease =3D 18, @@ -235,30 +245,53 @@ typedef struct { // // Header for VirtioFsFuseOpForget. // typedef struct { UINT64 NumberOfLookups; } VIRTIO_FS_FUSE_FORGET_REQUEST; =20 // -// Headers for VirtioFsFuseOpGetAttr. +// Headers for VirtioFsFuseOpGetAttr (VIRTIO_FS_FUSE_GETATTR_RESPONSE is a= lso +// for VirtioFsFuseOpSetAttr). // typedef struct { UINT32 GetAttrFlags; UINT32 Dummy; UINT64 FileHandle; } VIRTIO_FS_FUSE_GETATTR_REQUEST; =20 typedef struct { UINT64 AttrValid; UINT32 AttrValidNsec; UINT32 Dummy; } VIRTIO_FS_FUSE_GETATTR_RESPONSE; =20 +// +// Header for VirtioFsFuseOpSetAttr. +// +typedef struct { + UINT32 Valid; + UINT32 Padding; + UINT64 FileHandle; + UINT64 Size; + UINT64 LockOwner; + UINT64 Atime; + UINT64 Mtime; + UINT64 Ctime; + UINT32 AtimeNsec; + UINT32 MtimeNsec; + UINT32 CtimeNsec; + UINT32 Mode; + UINT32 Unused4; + UINT32 Uid; + UINT32 Gid; + UINT32 Unused5; +} VIRTIO_FS_FUSE_SETATTR_REQUEST; + // // Header for VirtioFsFuseOpMkDir. // typedef struct { UINT32 Mode; UINT32 Umask; } VIRTIO_FS_FUSE_MKDIR_REQUEST; =20 diff --git a/OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf b/OvmfPkg/VirtioFsDxe/Virt= ioFsDxe.inf index 9dccd7d6a9ef..8d962bcdc18c 100644 --- a/OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf +++ b/OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf @@ -91,16 +91,17 @@ [Sources] FuseLookup.c FuseMkDir.c FuseOpen.c FuseOpenDir.c FuseOpenOrCreate.c FuseRead.c FuseRelease.c FuseRename.c + FuseSetAttr.c FuseStatFs.c FuseUnlink.c FuseWrite.c Helpers.c SimpleFsClose.c SimpleFsDelete.c SimpleFsFlush.c SimpleFsGetInfo.c diff --git a/OvmfPkg/VirtioFsDxe/VirtioFsDxe.h b/OvmfPkg/VirtioFsDxe/Virtio= FsDxe.h index a6dfac71f4a7..9e6348f9386e 100644 --- a/OvmfPkg/VirtioFsDxe/VirtioFsDxe.h +++ b/OvmfPkg/VirtioFsDxe/VirtioFsDxe.h @@ -303,16 +303,26 @@ VirtioFsFuseForget ( =20 EFI_STATUS VirtioFsFuseGetAttr ( IN OUT VIRTIO_FS *VirtioFs, IN UINT64 NodeId, OUT VIRTIO_FS_FUSE_ATTRIBUTES_RESPONSE *FuseAttr ); =20 +EFI_STATUS +VirtioFsFuseSetAttr ( + IN OUT VIRTIO_FS *VirtioFs, + IN UINT64 NodeId, + IN UINT64 *Size OPTIONAL, + IN UINT64 *Atime OPTIONAL, + IN UINT64 *Mtime OPTIONAL, + IN UINT32 *Mode OPTIONAL + ); + EFI_STATUS VirtioFsFuseMkDir ( IN OUT VIRTIO_FS *VirtioFs, IN UINT64 ParentNodeId, IN CHAR8 *Name, OUT UINT64 *NodeId ); =20 diff --git a/OvmfPkg/VirtioFsDxe/FuseSetAttr.c b/OvmfPkg/VirtioFsDxe/FuseSe= tAttr.c new file mode 100644 index 000000000000..dcd014172022 --- /dev/null +++ b/OvmfPkg/VirtioFsDxe/FuseSetAttr.c @@ -0,0 +1,174 @@ +/** @file + FUSE_SETATTR wrapper for the Virtio Filesystem device. + + Copyright (C) 2020, Red Hat, Inc. + + SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#include "VirtioFsDxe.h" + +/** + Send the FUSE_SETATTR request to the Virtio Filesystem device, for chang= ing + the attributes of an inode. + + The function may only be called after VirtioFsFuseInitSession() returns + successfully and before VirtioFsUninit() is called. + + @param[in,out] VirtioFs The Virtio Filesystem device to send the + FUSE_SETATTR request to. On output, the FUSE re= quest + counter "VirtioFs->RequestId" will have been + incremented. + + @param[in] NodeId The inode number representing the regular file = or + directory whose attributes should be changed. + + @param[in] Size The new size to set for the regular file. If NU= LL, + then the file size will not be changed. If Node= Id + refers to a directory, then the caller is + responsible for passing NULL as Size. + + @param[in] Atime The new last access time to set for the regular= file + or directory (seconds since the Epoch). If NULL, + then the last access time is not changed. + + @param[in] Mtime The new last modification time to set for the + regular file or directory (seconds since the Ep= och). + If NULL, then the last modification time is not + changed. + + @param[in] Mode The new file mode bits to set for the regular f= ile + or directory. If NULL, then the file mode bits = are + not changed. + + @retval EFI_SUCCESS The attributes have been updated. + + @return The "errno" value mapped to an EFI_STATUS code, if = the + Virtio Filesystem device explicitly reported an err= or. + + @return Error codes propagated from VirtioFsSgListsValidate= (), + VirtioFsFuseNewRequest(), VirtioFsSgListsSubmit(), + VirtioFsFuseCheckResponse(). +**/ +EFI_STATUS +VirtioFsFuseSetAttr ( + IN OUT VIRTIO_FS *VirtioFs, + IN UINT64 NodeId, + IN UINT64 *Size OPTIONAL, + IN UINT64 *Atime OPTIONAL, + IN UINT64 *Mtime OPTIONAL, + IN UINT32 *Mode OPTIONAL + ) +{ + VIRTIO_FS_FUSE_REQUEST CommonReq; + VIRTIO_FS_FUSE_SETATTR_REQUEST AttrReq; + VIRTIO_FS_IO_VECTOR ReqIoVec[2]; + VIRTIO_FS_SCATTER_GATHER_LIST ReqSgList; + VIRTIO_FS_FUSE_RESPONSE CommonResp; + VIRTIO_FS_FUSE_GETATTR_RESPONSE GetAttrResp; + VIRTIO_FS_FUSE_ATTRIBUTES_RESPONSE AttrResp; + VIRTIO_FS_IO_VECTOR RespIoVec[3]; + VIRTIO_FS_SCATTER_GATHER_LIST RespSgList; + EFI_STATUS Status; + + // + // Set up the scatter-gather lists. + // + ReqIoVec[0].Buffer =3D &CommonReq; + ReqIoVec[0].Size =3D sizeof CommonReq; + ReqIoVec[1].Buffer =3D &AttrReq; + ReqIoVec[1].Size =3D sizeof AttrReq; + ReqSgList.IoVec =3D ReqIoVec; + ReqSgList.NumVec =3D ARRAY_SIZE (ReqIoVec); + + RespIoVec[0].Buffer =3D &CommonResp; + RespIoVec[0].Size =3D sizeof CommonResp; + RespIoVec[1].Buffer =3D &GetAttrResp; + RespIoVec[1].Size =3D sizeof GetAttrResp; + RespIoVec[2].Buffer =3D &AttrResp; + RespIoVec[2].Size =3D sizeof AttrResp; + RespSgList.IoVec =3D RespIoVec; + RespSgList.NumVec =3D ARRAY_SIZE (RespIoVec); + + // + // Validate the scatter-gather lists; calculate the total transfer sizes. + // + Status =3D VirtioFsSgListsValidate (VirtioFs, &ReqSgList, &RespSgList); + if (EFI_ERROR (Status)) { + return Status; + } + + // + // Populate the common request header. + // + Status =3D VirtioFsFuseNewRequest (VirtioFs, &CommonReq, ReqSgList.Total= Size, + VirtioFsFuseOpSetAttr, NodeId); + if (EFI_ERROR (Status)) { + return Status; + } + + // + // Populate the FUSE_SETATTR-specific fields. + // + AttrReq.Valid =3D 0; + AttrReq.Padding =3D 0; + AttrReq.FileHandle =3D 0; + AttrReq.Size =3D (Size =3D=3D NULL) ? 0 : *Size; + AttrReq.LockOwner =3D 0; + AttrReq.Atime =3D (Atime =3D=3D NULL) ? 0 : *Atime; + AttrReq.Mtime =3D (Mtime =3D=3D NULL) ? 0 : *Mtime; + AttrReq.Ctime =3D 0; + AttrReq.AtimeNsec =3D 0; + AttrReq.MtimeNsec =3D 0; + AttrReq.CtimeNsec =3D 0; + AttrReq.Mode =3D (Mode =3D=3D NULL) ? 0 : *Mode; + AttrReq.Unused4 =3D 0; + AttrReq.Uid =3D 0; + AttrReq.Gid =3D 0; + AttrReq.Unused5 =3D 0; + + if (Size !=3D NULL) { + AttrReq.Valid |=3D VIRTIO_FS_FUSE_SETATTR_REQ_F_SIZE; + } + if (Atime !=3D NULL) { + AttrReq.Valid |=3D VIRTIO_FS_FUSE_SETATTR_REQ_F_ATIME; + } + if (Mtime !=3D NULL) { + AttrReq.Valid |=3D VIRTIO_FS_FUSE_SETATTR_REQ_F_MTIME; + } + if (Mode !=3D NULL) { + AttrReq.Valid |=3D VIRTIO_FS_FUSE_SETATTR_REQ_F_MODE; + } + + // + // Submit the request. + // + Status =3D VirtioFsSgListsSubmit (VirtioFs, &ReqSgList, &RespSgList); + if (EFI_ERROR (Status)) { + return Status; + } + + // + // Verify the response (all response buffers are fixed size). + // + Status =3D VirtioFsFuseCheckResponse (&RespSgList, CommonReq.Unique, NUL= L); + if (Status =3D=3D EFI_DEVICE_ERROR) { + DEBUG ((DEBUG_ERROR, "%a: Label=3D\"%s\" NodeId=3D%Lu", __FUNCTION__, + VirtioFs->Label, NodeId)); + if (Size !=3D NULL) { + DEBUG ((DEBUG_ERROR, " Size=3D0x%Lx", *Size)); + } + if (Atime !=3D NULL) { + DEBUG ((DEBUG_ERROR, " Atime=3D%Lu", *Atime)); + } + if (Mtime !=3D NULL) { + DEBUG ((DEBUG_ERROR, " Mtime=3D%Lu", *Mtime)); + } + if (Mode !=3D NULL) { + DEBUG ((DEBUG_ERROR, " Mode=3D0x%x", *Mode)); // no support for octa= l :/ + } + DEBUG ((DEBUG_ERROR, " Errno=3D%d\n", CommonResp.Error)); + Status =3D VirtioFsErrnoToEfiStatus (CommonResp.Error); + } + return Status; +} --=20 2.19.1.3.g30247aa5d201 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#69058): https://edk2.groups.io/g/devel/message/69058 Mute This Topic: https://groups.io/mt/79024549/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Tue May 7 07:56:31 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+69059+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+69059+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1608158788; cv=none; d=zohomail.com; s=zohoarc; b=Nzv8muxdY1kgQa0NjHINEqSrkmfaG5G7GwYCdWWGM20+eRsRRd9Mr4k6m5SUEseocFd1cQXhnMd45VHHLLsIRH3jr3WnRiKitc0j4ecFjpnBP5NEBiaVkTCf1Lge1BdwnpFWNWAFnjD99xTBwLxMuV9at+coTEb0c8TB6d/D0As= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608158788; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=RK25An1gXQj0oUGc2YcNVkSknje9hBVzmSELWpno7Qc=; b=RsYwT3oD8LFZs3q/Mdj00iZ7WrpxG7t1cbDIgf/uHD9X3EQnyR8UGnUJL52JgqTZddND7t2pDXmHgYq9aq1JVBX9gst1x7WQXiJ5OC9vx6ojedV0aT3G7ByNmbmSmUMatlnXWJpqBUc1VLIxHzEi7GWGa6/psZTNiDrDJNLL4bU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+69059+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) header.from= Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1608158788071533.2618647479569; Wed, 16 Dec 2020 14:46:28 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id HVqAYY1788612xfyBaLaXoY0; Wed, 16 Dec 2020 14:46:26 -0800 X-Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.groups.io with SMTP id smtpd.web09.4993.1608158781209237643 for ; Wed, 16 Dec 2020 14:46:21 -0800 X-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-1-ghPLVSt8Nh28W0J2m9nyuw-1; Wed, 16 Dec 2020 17:46:15 -0500 X-MC-Unique: ghPLVSt8Nh28W0J2m9nyuw-1 X-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 9BC1710054FF; Wed, 16 Dec 2020 22:46:14 +0000 (UTC) X-Received: from lacos-laptop-7.usersys.redhat.com (ovpn-114-152.ams2.redhat.com [10.36.114.152]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0C62110013C0; Wed, 16 Dec 2020 22:46:09 +0000 (UTC) From: "Laszlo Ersek" To: devel@edk2.groups.io, virtio-fs@redhat.com, lersek@redhat.com Cc: Ard Biesheuvel , Jordan Justen , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [edk2-devel] [edk2 PATCH 45/48] OvmfPkg/VirtioFsDxe: add helper for determining file size update Date: Wed, 16 Dec 2020 22:11:22 +0100 Message-Id: <20201216211125.19496-46-lersek@redhat.com> In-Reply-To: <20201216211125.19496-1-lersek@redhat.com> References: <20201216211125.19496-1-lersek@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,lersek@redhat.com X-Gm-Message-State: hZnE3mvtGdKz85OAlnvWOqWCx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1608158786; bh=RK25An1gXQj0oUGc2YcNVkSknje9hBVzmSELWpno7Qc=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=XT9MQrj9EbkMEIkRMEcqn+ftpjeVydEH4CVRYNu1K3ZsExMv4eGhd5odj41jTICDrxF suZMlyD8quDlzRrA35q8P0MM8lRZjENwB7xLZD5OSlZxwONTSsj0QiI0uYObB3DvbOvBb H77aivDfOWB+8fnlyunZofDggvSnRJ/w6JU= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" Add the VirtioFsGetFuseSizeUpdate() function, for determining whether an EFI_FILE_PROTOCOL.SetInfo() invocation requests a file size update. Cc: Ard Biesheuvel Cc: Jordan Justen Cc: Philippe Mathieu-Daud=C3=A9 Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3097 Signed-off-by: Laszlo Ersek Acked-by: Ard Biesheuvel --- OvmfPkg/VirtioFsDxe/VirtioFsDxe.h | 8 ++++ OvmfPkg/VirtioFsDxe/Helpers.c | 40 ++++++++++++++++++++ 2 files changed, 48 insertions(+) diff --git a/OvmfPkg/VirtioFsDxe/VirtioFsDxe.h b/OvmfPkg/VirtioFsDxe/Virtio= FsDxe.h index 9e6348f9386e..096756302942 100644 --- a/OvmfPkg/VirtioFsDxe/VirtioFsDxe.h +++ b/OvmfPkg/VirtioFsDxe/VirtioFsDxe.h @@ -277,16 +277,24 @@ VirtioFsFuseAttrToEfiFileInfo ( ); =20 EFI_STATUS VirtioFsFuseDirentPlusToEfiFileInfo ( IN VIRTIO_FS_FUSE_DIRENTPLUS_RESPONSE *FuseDirent, IN OUT EFI_FILE_INFO *FileInfo ); =20 +VOID +VirtioFsGetFuseSizeUpdate ( + IN EFI_FILE_INFO *Info, + IN EFI_FILE_INFO *NewInfo, + OUT BOOLEAN *Update, + OUT UINT64 *Size + ); + // // Wrapper functions for FUSE commands (primitives). // =20 EFI_STATUS VirtioFsFuseLookup ( IN OUT VIRTIO_FS *VirtioFs, IN UINT64 DirNodeId, diff --git a/OvmfPkg/VirtioFsDxe/Helpers.c b/OvmfPkg/VirtioFsDxe/Helpers.c index b741cf753495..838971bd2c85 100644 --- a/OvmfPkg/VirtioFsDxe/Helpers.c +++ b/OvmfPkg/VirtioFsDxe/Helpers.c @@ -2168,8 +2168,48 @@ VirtioFsFuseDirentPlusToEfiFileInfo ( FileInfo->FileName[Idx++] =3D L'\0'; // // Set the (possibly reduced) size. // FileInfo->Size =3D FileInfoSize; =20 return EFI_SUCCESS; } + +/** + Given an EFI_FILE_INFO object received in an EFI_FILE_PROTOCOL.SetInfo() + call, determine whether updating the size of the file is necessary, rela= tive + to an EFI_FILE_INFO object describing the current state of the file. + + @param[in] Info The EFI_FILE_INFO describing the current state of the + file. The caller is responsible for populating Info = on + input with VirtioFsFuseAttrToEfiFileInfo(), from the + current FUSE attributes of the file. The Info->Size = and + Info->FileName members are ignored. + + @param[in] NewInfo The EFI_FILE_INFO object received in the + EFI_FILE_PROTOCOL.SetInfo() call. + + @param[out] Update Set to TRUE on output if the file size needs to be + updated. Set to FALSE otherwise. + + @param[out] Size If Update is set to TRUE, then Size provides the new= file + size to set. Otherwise, Size is not written to. +**/ +VOID +VirtioFsGetFuseSizeUpdate ( + IN EFI_FILE_INFO *Info, + IN EFI_FILE_INFO *NewInfo, + OUT BOOLEAN *Update, + OUT UINT64 *Size + ) +{ + BOOLEAN IsDirectory; + + IsDirectory =3D (BOOLEAN)((Info->Attribute & EFI_FILE_DIRECTORY) !=3D 0); + + if (IsDirectory || Info->FileSize =3D=3D NewInfo->FileSize) { + *Update =3D FALSE; + return; + } + *Update =3D TRUE; + *Size =3D NewInfo->FileSize; +} --=20 2.19.1.3.g30247aa5d201 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#69059): https://edk2.groups.io/g/devel/message/69059 Mute This Topic: https://groups.io/mt/79024600/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Tue May 7 07:56:31 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+69060+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+69060+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1608158911; cv=none; d=zohomail.com; s=zohoarc; b=OFzyWrT69a0SbsVK/rQzb13Ne/le7bwYNYeNdosymh2gjbQD5S0b6Q/T9uh2OvXPFC+kclCegAh+GK/fr9wG+/XRsiC9lWRmH6XWED/ki4mvhHoIVeDncL3bRigb7ESwBrHklCw18M9nf/+TDA1o2wgLuNxoXPMq9pSRV57b4Ss= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608158911; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=22grC6BvJhUDaMjR2jh/V9JXx3Go90oI1JlIDRoDW9c=; b=Uk7TKOtShySsc6ox3iHbuFDSt6ec3hDaiSnXvk4/l7V6xkLcB4N9vG5mulWmnRdSphX2I2J5eF6D7hrI400IJ9d4gbLICSI61BYVfbJ2D20l/d+74mjaONaUJRfUXQ3ngijwVD4Ik84FRC+1KZL328lHF3xPO4jZp3FQ3TDlYU4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+69060+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) header.from= Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1608158911243193.81438064427368; Wed, 16 Dec 2020 14:48:31 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id ej5VYY1788612xo4RxlCUlLt; Wed, 16 Dec 2020 14:48:29 -0800 X-Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.groups.io with SMTP id smtpd.web09.5037.1608158904335987723 for ; Wed, 16 Dec 2020 14:48:24 -0800 X-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-525-Fc5hQJCdM-qk9WAdGxvtUg-1; Wed, 16 Dec 2020 17:48:21 -0500 X-MC-Unique: Fc5hQJCdM-qk9WAdGxvtUg-1 X-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 8FF55800D55; Wed, 16 Dec 2020 22:48:20 +0000 (UTC) X-Received: from lacos-laptop-7.usersys.redhat.com (ovpn-114-152.ams2.redhat.com [10.36.114.152]) by smtp.corp.redhat.com (Postfix) with ESMTP id BAAEC17577; Wed, 16 Dec 2020 22:48:15 +0000 (UTC) From: "Laszlo Ersek" To: devel@edk2.groups.io, virtio-fs@redhat.com, lersek@redhat.com Cc: Ard Biesheuvel , Jordan Justen , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [edk2-devel] [edk2 PATCH 46/48] OvmfPkg/VirtioFsDxe: add helper for determining access time updates Date: Wed, 16 Dec 2020 22:11:23 +0100 Message-Id: <20201216211125.19496-47-lersek@redhat.com> In-Reply-To: <20201216211125.19496-1-lersek@redhat.com> References: <20201216211125.19496-1-lersek@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,lersek@redhat.com X-Gm-Message-State: Jknvyb0R2XZbaWLE6ddUzLl4x1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1608158909; bh=22grC6BvJhUDaMjR2jh/V9JXx3Go90oI1JlIDRoDW9c=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=UbR9cMzxVBls/HccpYJeNrHUgcMdnbGBh8M06o6foKvsYq9n8Qn/DjoxlQgTYE8waur /BDLlA7IUExgFW6NPaIbmsNFhf+6XgVXmenLP6KkOtvd2RFYN2oSi8o21r8N4vj3TyMQy Y9rLve15PK5e4ZzF/8+AUtUc5j704Oh4ZyY= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" Add the VirtioFsGetFuseTimeUpdates() function, for determining whether an EFI_FILE_PROTOCOL.SetInfo() invocation requests access time updates. Cc: Ard Biesheuvel Cc: Jordan Justen Cc: Philippe Mathieu-Daud=C3=A9 Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3097 Signed-off-by: Laszlo Ersek Acked-by: Ard Biesheuvel --- OvmfPkg/VirtioFsDxe/VirtioFsDxe.h | 10 ++ OvmfPkg/VirtioFsDxe/Helpers.c | 106 ++++++++++++++++++++ 2 files changed, 116 insertions(+) diff --git a/OvmfPkg/VirtioFsDxe/VirtioFsDxe.h b/OvmfPkg/VirtioFsDxe/Virtio= FsDxe.h index 096756302942..4331cabbd40e 100644 --- a/OvmfPkg/VirtioFsDxe/VirtioFsDxe.h +++ b/OvmfPkg/VirtioFsDxe/VirtioFsDxe.h @@ -285,16 +285,26 @@ VirtioFsFuseDirentPlusToEfiFileInfo ( VOID VirtioFsGetFuseSizeUpdate ( IN EFI_FILE_INFO *Info, IN EFI_FILE_INFO *NewInfo, OUT BOOLEAN *Update, OUT UINT64 *Size ); =20 +EFI_STATUS +VirtioFsGetFuseTimeUpdates ( + IN EFI_FILE_INFO *Info, + IN EFI_FILE_INFO *NewInfo, + OUT BOOLEAN *UpdateAtime, + OUT BOOLEAN *UpdateMtime, + OUT UINT64 *Atime, + OUT UINT64 *Mtime + ); + // // Wrapper functions for FUSE commands (primitives). // =20 EFI_STATUS VirtioFsFuseLookup ( IN OUT VIRTIO_FS *VirtioFs, IN UINT64 DirNodeId, diff --git a/OvmfPkg/VirtioFsDxe/Helpers.c b/OvmfPkg/VirtioFsDxe/Helpers.c index 838971bd2c85..c85c7400f2be 100644 --- a/OvmfPkg/VirtioFsDxe/Helpers.c +++ b/OvmfPkg/VirtioFsDxe/Helpers.c @@ -2208,8 +2208,114 @@ VirtioFsGetFuseSizeUpdate ( =20 if (IsDirectory || Info->FileSize =3D=3D NewInfo->FileSize) { *Update =3D FALSE; return; } *Update =3D TRUE; *Size =3D NewInfo->FileSize; } + +/** + Given an EFI_FILE_INFO object received in an EFI_FILE_PROTOCOL.SetInfo() + call, determine whether updating the last access time and/or the last + modification time of the file is necessary, relative to an EFI_FILE_INFO + object describing the current state of the file. + + @param[in] Info The EFI_FILE_INFO describing the current state = of + the file. The caller is responsible for populat= ing + Info on input with VirtioFsFuseAttrToEfiFileInf= o(), + from the current FUSE attributes of the file. T= he + Info->Size and Info->FileName members are ignor= ed. + + @param[in] NewInfo The EFI_FILE_INFO object received in the + EFI_FILE_PROTOCOL.SetInfo() call. + + @param[out] UpdateAtime Set to TRUE on output if the last access time n= eeds + to be updated. Set to FALSE otherwise. + + @param[out] UpdateMtime Set to TRUE on output if the last modification = time + needs to be updated. Set to FALSE otherwise. + + @param[out] Atime If UpdateAtime is set to TRUE, then Atime provi= des + the last access timestamp to set (as seconds si= nce + the Epoch). Otherwise, Atime is not written to. + + @param[out] Mtime If UpdateMtime is set to TRUE, then Mtime provi= des + the last modification timestamp to set (as seco= nds + since the Epoch). Otherwise, Mtime is not writt= en + to. + + @retval EFI_SUCCESS Output parameters have been set successfully. + + @retval EFI_ACCESS_DENIED NewInfo requests changing both CreateTime and + ModificationTime, but to values that differ f= rom + each other. The Virtio Filesystem device does= not + support this. +**/ +EFI_STATUS +VirtioFsGetFuseTimeUpdates ( + IN EFI_FILE_INFO *Info, + IN EFI_FILE_INFO *NewInfo, + OUT BOOLEAN *UpdateAtime, + OUT BOOLEAN *UpdateMtime, + OUT UINT64 *Atime, + OUT UINT64 *Mtime + ) +{ + EFI_TIME *Time[3]; + EFI_TIME *NewTime[ARRAY_SIZE (Time)]; + UINTN Idx; + STATIC CONST EFI_TIME ZeroTime; + BOOLEAN Change[ARRAY_SIZE (Time)]; + UINT64 Seconds[ARRAY_SIZE (Time)]; + + Time[0] =3D &Info->CreateTime; + Time[1] =3D &Info->LastAccessTime; + Time[2] =3D &Info->ModificationTime; + NewTime[0] =3D &NewInfo->CreateTime; + NewTime[1] =3D &NewInfo->LastAccessTime; + NewTime[2] =3D &NewInfo->ModificationTime; + + // + // Determine which timestamps differ from the current state. (A zero time + // means "don't update", per UEFI spec.) For each timestamp that's being + // changed, calculate the seconds since the Epoch. + // + for (Idx =3D 0; Idx < ARRAY_SIZE (Time); Idx++) { + if (CompareMem (NewTime[Idx], &ZeroTime, sizeof (EFI_TIME)) =3D=3D 0 || + CompareMem (NewTime[Idx], Time[Idx], sizeof (EFI_TIME)) =3D=3D 0) { + Change[Idx] =3D FALSE; + } else { + Change[Idx] =3D TRUE; + Seconds[Idx] =3D EfiTimeToEpoch (NewTime[Idx]); + } + } + + // + // If a change is requested for exactly one of CreateTime and + // ModificationTime, we'll change the last modification time. If changes= are + // requested for both, and to the same timestamp, we'll similarly update= the + // last modification time. If changes are requested for both, but to + // different timestamps, we reject the request. + // + if (Change[0] && Change[2] && Seconds[0] !=3D Seconds[2]) { + return EFI_ACCESS_DENIED; + } + + *UpdateAtime =3D FALSE; + *UpdateMtime =3D FALSE; + + if (Change[0]) { + *UpdateMtime =3D TRUE; + *Mtime =3D Seconds[0]; + } + if (Change[1]) { + *UpdateAtime =3D TRUE; + *Atime =3D Seconds[1]; + } + if (Change[2]) { + *UpdateMtime =3D TRUE; + *Mtime =3D Seconds[2]; + } + + return EFI_SUCCESS; +} --=20 2.19.1.3.g30247aa5d201 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#69060): https://edk2.groups.io/g/devel/message/69060 Mute This Topic: https://groups.io/mt/79024659/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Tue May 7 07:56:31 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+69061+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+69061+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1608159032; cv=none; d=zohomail.com; s=zohoarc; b=erTU3924dQ5LEze+E3MgRvVhCd2MEz28g4E1whShQK+62hjHjQ+NTU0fzWyK7Gu+CadBVZuOg7mw8iSC6TaYkTyVMt8JVRTYSOlqm0QV3L9gRizXN6SZ27CnHrhP8gdOSHBoPRbLpVg60HqjbZxOlZwT9D+R1jGhC0406jr54l0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608159032; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=Y3bSK6tbI2VITZt7kfSzKCwK33AZc+IU/5x9VFPlEBk=; b=k3dP+Hc3Cf8jhYT7VouhBM+uK0iNT2JfNJci/3rNOz3Zc1YvEjy4kU7rZnB1vtE4iDaLjAkxgHBogdSyQGYaq5kKbqVg4c/x3yn2SyQH/hXClJvCJOwmuRoXOIddnFMEEhAklwYR7X03AC70YYJ9lULB0fYfPsh1M/UhaMWOqSI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+69061+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) header.from= Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1608159032207324.0574268246196; Wed, 16 Dec 2020 14:50:32 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id hD1kYY1788612xVO4J5JIjX7; Wed, 16 Dec 2020 14:50:31 -0800 X-Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.groups.io with SMTP id smtpd.web10.5210.1608159030877360735 for ; Wed, 16 Dec 2020 14:50:31 -0800 X-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-504-NOVOlD7zN2qY9sXxjMWpgA-1; Wed, 16 Dec 2020 17:50:28 -0500 X-MC-Unique: NOVOlD7zN2qY9sXxjMWpgA-1 X-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 2B7C51842143; Wed, 16 Dec 2020 22:50:27 +0000 (UTC) X-Received: from lacos-laptop-7.usersys.redhat.com (ovpn-114-152.ams2.redhat.com [10.36.114.152]) by smtp.corp.redhat.com (Postfix) with ESMTP id C142018017; Wed, 16 Dec 2020 22:50:21 +0000 (UTC) From: "Laszlo Ersek" To: devel@edk2.groups.io, virtio-fs@redhat.com, lersek@redhat.com Cc: Ard Biesheuvel , Jordan Justen , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [edk2-devel] [edk2 PATCH 47/48] OvmfPkg/VirtioFsDxe: add helper for determining file mode bits update Date: Wed, 16 Dec 2020 22:11:24 +0100 Message-Id: <20201216211125.19496-48-lersek@redhat.com> In-Reply-To: <20201216211125.19496-1-lersek@redhat.com> References: <20201216211125.19496-1-lersek@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,lersek@redhat.com X-Gm-Message-State: hEgjvDLCZTH7rNPWUTwGuFILx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1608159031; bh=Y3bSK6tbI2VITZt7kfSzKCwK33AZc+IU/5x9VFPlEBk=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=cBaxHuxhJSdLvYkG94R4ZOsug/5GoTdCUMcCXef8mr5rSOrVJoGDnp6xYLlR0kaZk+N q0nWlJ8Ujvkv4QGAQqdmPCTHNWGJROpcCGczcK7KtoAl8TkFQD+h2XxkbzrHhpJI86+9d 0Ol/SN7GbvXURHyYv8fBOlO6yBu6uhhKY/Y= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" Add the VirtioFsGetFuseModeUpdate() function, for determining whether an EFI_FILE_PROTOCOL.SetInfo() invocation requests an update to the file mode bits. Cc: Ard Biesheuvel Cc: Jordan Justen Cc: Philippe Mathieu-Daud=C3=A9 Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3097 Signed-off-by: Laszlo Ersek Acked-by: Ard Biesheuvel --- OvmfPkg/Include/IndustryStandard/VirtioFs.h | 3 + OvmfPkg/VirtioFsDxe/VirtioFsDxe.h | 8 ++ OvmfPkg/VirtioFsDxe/Helpers.c | 95 ++++++++++++++++++++ 3 files changed, 106 insertions(+) diff --git a/OvmfPkg/Include/IndustryStandard/VirtioFs.h b/OvmfPkg/Include/= IndustryStandard/VirtioFs.h index 15fb28f95a28..dee437ec0d39 100644 --- a/OvmfPkg/Include/IndustryStandard/VirtioFs.h +++ b/OvmfPkg/Include/IndustryStandard/VirtioFs.h @@ -90,22 +90,25 @@ typedef struct { // File mode bitmasks. // #define VIRTIO_FS_FUSE_MODE_TYPE_MASK 0170000u #define VIRTIO_FS_FUSE_MODE_TYPE_REG 0100000u #define VIRTIO_FS_FUSE_MODE_TYPE_DIR 0040000u #define VIRTIO_FS_FUSE_MODE_PERM_RWXU 0000700u #define VIRTIO_FS_FUSE_MODE_PERM_RUSR 0000400u #define VIRTIO_FS_FUSE_MODE_PERM_WUSR 0000200u +#define VIRTIO_FS_FUSE_MODE_PERM_XUSR 0000100u #define VIRTIO_FS_FUSE_MODE_PERM_RWXG 0000070u #define VIRTIO_FS_FUSE_MODE_PERM_RGRP 0000040u #define VIRTIO_FS_FUSE_MODE_PERM_WGRP 0000020u +#define VIRTIO_FS_FUSE_MODE_PERM_XGRP 0000010u #define VIRTIO_FS_FUSE_MODE_PERM_RWXO 0000007u #define VIRTIO_FS_FUSE_MODE_PERM_ROTH 0000004u #define VIRTIO_FS_FUSE_MODE_PERM_WOTH 0000002u +#define VIRTIO_FS_FUSE_MODE_PERM_XOTH 0000001u =20 // // Flags for VirtioFsFuseOpSetAttr, in the VIRTIO_FS_FUSE_SETATTR_REQUEST.= Valid // field. // #define VIRTIO_FS_FUSE_SETATTR_REQ_F_MODE BIT0 #define VIRTIO_FS_FUSE_SETATTR_REQ_F_SIZE BIT3 #define VIRTIO_FS_FUSE_SETATTR_REQ_F_ATIME BIT4 diff --git a/OvmfPkg/VirtioFsDxe/VirtioFsDxe.h b/OvmfPkg/VirtioFsDxe/Virtio= FsDxe.h index 4331cabbd40e..3c3eb1ac9338 100644 --- a/OvmfPkg/VirtioFsDxe/VirtioFsDxe.h +++ b/OvmfPkg/VirtioFsDxe/VirtioFsDxe.h @@ -295,16 +295,24 @@ VirtioFsGetFuseTimeUpdates ( IN EFI_FILE_INFO *Info, IN EFI_FILE_INFO *NewInfo, OUT BOOLEAN *UpdateAtime, OUT BOOLEAN *UpdateMtime, OUT UINT64 *Atime, OUT UINT64 *Mtime ); =20 +EFI_STATUS +VirtioFsGetFuseModeUpdate ( + IN EFI_FILE_INFO *Info, + IN EFI_FILE_INFO *NewInfo, + OUT BOOLEAN *Update, + OUT UINT32 *Mode + ); + // // Wrapper functions for FUSE commands (primitives). // =20 EFI_STATUS VirtioFsFuseLookup ( IN OUT VIRTIO_FS *VirtioFs, IN UINT64 DirNodeId, diff --git a/OvmfPkg/VirtioFsDxe/Helpers.c b/OvmfPkg/VirtioFsDxe/Helpers.c index c85c7400f2be..b669842a23bd 100644 --- a/OvmfPkg/VirtioFsDxe/Helpers.c +++ b/OvmfPkg/VirtioFsDxe/Helpers.c @@ -2314,8 +2314,103 @@ VirtioFsGetFuseTimeUpdates ( } if (Change[2]) { *UpdateMtime =3D TRUE; *Mtime =3D Seconds[2]; } =20 return EFI_SUCCESS; } + +/** + Given an EFI_FILE_INFO object received in an EFI_FILE_PROTOCOL.SetInfo() + call, determine whether updating the file mode bits of the file is neces= sary, + relative to an EFI_FILE_INFO object describing the current state of the = file. + + @param[in] Info The EFI_FILE_INFO describing the current state of the + file. The caller is responsible for populating Info = on + input with VirtioFsFuseAttrToEfiFileInfo(), from the + current FUSE attributes of the file. The Info->Size = and + Info->FileName members are ignored. + + @param[in] NewInfo The EFI_FILE_INFO object received in the + EFI_FILE_PROTOCOL.SetInfo() call. + + @param[out] Update Set to TRUE on output if the file mode bits need to = be + updated. Set to FALSE otherwise. + + @param[out] Mode If Update is set to TRUE, then Mode provides the file + mode bits to set. Otherwise, Mode is not written to. + + @retval EFI_SUCCESS Output parameters have been set successfully. + + @retval EFI_ACCESS_DENIED NewInfo requests toggling an unknown bit in t= he + Attribute bitmask. + + @retval EFI_ACCESS_DENIED NewInfo requests toggling EFI_FILE_DIRECTORY = in + the Attribute bitmask. +**/ +EFI_STATUS +VirtioFsGetFuseModeUpdate ( + IN EFI_FILE_INFO *Info, + IN EFI_FILE_INFO *NewInfo, + OUT BOOLEAN *Update, + OUT UINT32 *Mode + ) +{ + UINT64 Toggle; + BOOLEAN IsDirectory; + BOOLEAN IsWriteable; + BOOLEAN WillBeWriteable; + + Toggle =3D Info->Attribute ^ NewInfo->Attribute; + if ((Toggle & ~EFI_FILE_VALID_ATTR) !=3D 0) { + // + // Unknown attribute requested. + // + return EFI_ACCESS_DENIED; + } + if ((Toggle & EFI_FILE_DIRECTORY) !=3D 0) { + // + // EFI_FILE_DIRECTORY cannot be toggled. + // + return EFI_ACCESS_DENIED; + } + + IsDirectory =3D (BOOLEAN)((Info->Attribute & EFI_FILE_DIRECTORY) = !=3D 0); + IsWriteable =3D (BOOLEAN)((Info->Attribute & EFI_FILE_READ_ONLY) = =3D=3D 0); + WillBeWriteable =3D (BOOLEAN)((NewInfo->Attribute & EFI_FILE_READ_ONLY) = =3D=3D 0); + + if (IsWriteable =3D=3D WillBeWriteable) { + *Update =3D FALSE; + return EFI_SUCCESS; + } + + if (IsDirectory) { + if (WillBeWriteable) { + *Mode =3D (VIRTIO_FS_FUSE_MODE_PERM_RWXU | + VIRTIO_FS_FUSE_MODE_PERM_RWXG | + VIRTIO_FS_FUSE_MODE_PERM_RWXO); + } else { + *Mode =3D (VIRTIO_FS_FUSE_MODE_PERM_RUSR | + VIRTIO_FS_FUSE_MODE_PERM_XUSR | + VIRTIO_FS_FUSE_MODE_PERM_RGRP | + VIRTIO_FS_FUSE_MODE_PERM_XGRP | + VIRTIO_FS_FUSE_MODE_PERM_ROTH | + VIRTIO_FS_FUSE_MODE_PERM_XOTH); + } + } else { + if (WillBeWriteable) { + *Mode =3D (VIRTIO_FS_FUSE_MODE_PERM_RUSR | + VIRTIO_FS_FUSE_MODE_PERM_WUSR | + VIRTIO_FS_FUSE_MODE_PERM_RGRP | + VIRTIO_FS_FUSE_MODE_PERM_WGRP | + VIRTIO_FS_FUSE_MODE_PERM_ROTH | + VIRTIO_FS_FUSE_MODE_PERM_WOTH); + } else { + *Mode =3D (VIRTIO_FS_FUSE_MODE_PERM_RUSR | + VIRTIO_FS_FUSE_MODE_PERM_RGRP | + VIRTIO_FS_FUSE_MODE_PERM_ROTH); + } + } + *Update =3D TRUE; + return EFI_SUCCESS; +} --=20 2.19.1.3.g30247aa5d201 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#69061): https://edk2.groups.io/g/devel/message/69061 Mute This Topic: https://groups.io/mt/79024729/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Tue May 7 07:56:31 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+69062+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+69062+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1608159164; cv=none; d=zohomail.com; s=zohoarc; b=Ik14TqT+zeui44XK+xv9UpPPeSm+Q3WO08vN/YQAAtBazBQwTgiOJU1cdYmT/xEkFMXrrdhhei3wFsV3Ai9Y0i9Kg/RYd1dO83oQSEsJgz3nOir8u01VieQ1CpfdavarTuAX3VCOofAHVQvLdKsQ35Ykqntjrpz3/6k+X/fBdcw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608159164; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=DN+EicQ4UnBuyCCaCYTkXWFvaK+vrMcB7QkCeV1zWSk=; b=GJJEX6RD22bnTISpI66R//I6YGM+9y6r7XPO79FUs5qI6tbv7lqo9kdesxe+1Mw7yaTAwzH6UYkL0wycoPE9NzUIiCJTDdFpnzokR7rsu2oki0+bUYtq/2HpNbWamQDYwGs6DqFKVnuEGKG0yKmqzihpXZBkjSDqB78YELnIZbg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+69062+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) header.from= Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1608159164754454.67284188451424; Wed, 16 Dec 2020 14:52:44 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id uOwxYY1788612xQfsF8GKELn; Wed, 16 Dec 2020 14:52:44 -0800 X-Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.groups.io with SMTP id smtpd.web11.5217.1608159158748979519 for ; Wed, 16 Dec 2020 14:52:38 -0800 X-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-507-gaaCmfP_OZaP6ab-p8ixZA-1; Wed, 16 Dec 2020 17:52:34 -0500 X-MC-Unique: gaaCmfP_OZaP6ab-p8ixZA-1 X-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 193AB107ACE4; Wed, 16 Dec 2020 22:52:33 +0000 (UTC) X-Received: from lacos-laptop-7.usersys.redhat.com (ovpn-114-152.ams2.redhat.com [10.36.114.152]) by smtp.corp.redhat.com (Postfix) with ESMTP id 433AD10013C0; Wed, 16 Dec 2020 22:52:28 +0000 (UTC) From: "Laszlo Ersek" To: devel@edk2.groups.io, virtio-fs@redhat.com, lersek@redhat.com Cc: Ard Biesheuvel , Jordan Justen , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [edk2-devel] [edk2 PATCH 48/48] OvmfPkg/VirtioFsDxe: handle attribute updates in EFI_FILE_PROTOCOL.SetInfo Date: Wed, 16 Dec 2020 22:11:25 +0100 Message-Id: <20201216211125.19496-49-lersek@redhat.com> In-Reply-To: <20201216211125.19496-1-lersek@redhat.com> References: <20201216211125.19496-1-lersek@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,lersek@redhat.com X-Gm-Message-State: jBVzfzsYhxw6PdnE91ZiTXqex1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1608159164; bh=DN+EicQ4UnBuyCCaCYTkXWFvaK+vrMcB7QkCeV1zWSk=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=dxX9y4pPaKZNQea7WjVj92bks7vbYX0sGnmCADWdeihN09NMGlvsg1kdtsGRrjkFEMX C7LmmrK/h8SrRT+tpfFotLR4eGXZRSXRF6oXfoFENT9082f8S5LH22LlexDp2UqOH9IKD h2/GzuzVWBC8OsTd6NCyWu7W+tkVRsxAb+w= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" Using the functions introduced previously, we can now update file attributes in VirtioFsSimpleFileSetInfo(). Cc: Ard Biesheuvel Cc: Jordan Justen Cc: Philippe Mathieu-Daud=C3=A9 Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3097 Signed-off-by: Laszlo Ersek Acked-by: Ard Biesheuvel --- OvmfPkg/VirtioFsDxe/SimpleFsSetInfo.c | 107 +++++++++++++++++++- 1 file changed, 106 insertions(+), 1 deletion(-) diff --git a/OvmfPkg/VirtioFsDxe/SimpleFsSetInfo.c b/OvmfPkg/VirtioFsDxe/Si= mpleFsSetInfo.c index 55169dde78b7..e7cc3d5dc399 100644 --- a/OvmfPkg/VirtioFsDxe/SimpleFsSetInfo.c +++ b/OvmfPkg/VirtioFsDxe/SimpleFsSetInfo.c @@ -303,16 +303,121 @@ Rename ( =20 FreeDestination: if (Destination !=3D NULL) { FreePool (Destination); } return Status; } =20 +/** + Update the attributes of a VIRTIO_FS_FILE as requested in EFI_FILE_INFO. + + @param[in,out] VirtioFsFile The VIRTIO_FS_FILE to update the attributes= of. + + @param[in] NewFileInfo The new attributes requested by + EFI_FILE_PROTOCOL.SetInfo(). NewFileInfo->S= ize + and NewFileInfo->FileName are ignored. + + @retval EFI_SUCCESS No attributes had to be updated. + + @retval EFI_SUCCESS The required set of attribute updates has been + determined and performed successfully. + + @retval EFI_ACCESS_DENIED NewFileInfo requests an update to a property + different from the EFI_FILE_READ_ONLY bit in = the + Attribute field, but VirtioFsFile is not open= for + writing. + + @return Error codes propagated from underlying functi= ons. +**/ +STATIC +EFI_STATUS +UpdateAttributes ( + IN OUT VIRTIO_FS_FILE *VirtioFsFile, + IN EFI_FILE_INFO *NewFileInfo + ) +{ + VIRTIO_FS *VirtioFs; + EFI_STATUS Status; + VIRTIO_FS_FUSE_ATTRIBUTES_RESPONSE FuseAttr; + EFI_FILE_INFO FileInfo; + BOOLEAN UpdateFileSize; + UINT64 FileSize; + BOOLEAN UpdateAtime; + BOOLEAN UpdateMtime; + UINT64 Atime; + UINT64 Mtime; + BOOLEAN UpdateMode; + UINT32 Mode; + + VirtioFs =3D VirtioFsFile->OwnerFs; + + // + // Fetch the current attributes first, so we can build the difference be= tween + // them and NewFileInfo. + // + Status =3D VirtioFsFuseGetAttr (VirtioFs, VirtioFsFile->NodeId, &FuseAtt= r); + if (EFI_ERROR (Status)) { + return Status; + } + Status =3D VirtioFsFuseAttrToEfiFileInfo (&FuseAttr, &FileInfo); + if (EFI_ERROR (Status)) { + return Status; + } + // + // Collect the updates. + // + if (VirtioFsFile->IsDirectory) { + UpdateFileSize =3D FALSE; + } else { + VirtioFsGetFuseSizeUpdate (&FileInfo, NewFileInfo, &UpdateFileSize, + &FileSize); + } + + Status =3D VirtioFsGetFuseTimeUpdates (&FileInfo, NewFileInfo, &UpdateAt= ime, + &UpdateMtime, &Atime, &Mtime); + if (EFI_ERROR (Status)) { + return Status; + } + + Status =3D VirtioFsGetFuseModeUpdate (&FileInfo, NewFileInfo, &UpdateMod= e, + &Mode); + if (EFI_ERROR (Status)) { + return Status; + } + + // + // If no attribute updates are necessary, we're done. + // + if (!UpdateFileSize && !UpdateAtime && !UpdateMtime && !UpdateMode) { + return EFI_SUCCESS; + } + // + // If the file is not open for writing, then only Mode may be updated (f= or + // toggling EFI_FILE_READ_ONLY). + // + if (!VirtioFsFile->IsOpenForWriting && + (UpdateFileSize || UpdateAtime || UpdateMtime)) { + return EFI_ACCESS_DENIED; + } + // + // Send the FUSE_SETATTR request now. + // + Status =3D VirtioFsFuseSetAttr ( + VirtioFs, + VirtioFsFile->NodeId, + UpdateFileSize ? &FileSize : NULL, + UpdateAtime ? &Atime : NULL, + UpdateMtime ? &Mtime : NULL, + UpdateMode ? &Mode : NULL + ); + return Status; +} + /** Process an EFI_FILE_INFO setting request. **/ STATIC EFI_STATUS SetFileInfo ( IN EFI_FILE_PROTOCOL *This, IN UINTN BufferSize, @@ -345,17 +450,17 @@ SetFileInfo ( // Status =3D Rename (VirtioFsFile, FileInfo->FileName); if (EFI_ERROR (Status)) { return Status; } // // Update any attributes requested. // - Status =3D EFI_UNSUPPORTED; + Status =3D UpdateAttributes (VirtioFsFile, FileInfo); // // The UEFI spec does not speak about partial failure in // EFI_FILE_PROTOCOL.SetInfo(); we won't try to roll back the rename (if // there was one) in case the attribute updates fail. // return Status; } =20 --=20 2.19.1.3.g30247aa5d201 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#69062): https://edk2.groups.io/g/devel/message/69062 Mute This Topic: https://groups.io/mt/79024765/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-