Files
system76-edk2/OvmfPkg/VirtioFsDxe/SimpleFsOpenVolume.c
Laszlo Ersek b845de89d0 OvmfPkg/VirtioFsDxe: add EFI_FILE_INFO cache fields to VIRTIO_FS_FILE
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 <ard.biesheuvel@arm.com>
Cc: Jordan Justen <jordan.l.justen@intel.com>
Cc: Philippe Mathieu-Daudé <philmd@redhat.com>
Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3097
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
Message-Id: <20201216211125.19496-36-lersek@redhat.com>
Acked-by: Ard Biesheuvel <ard.biesheuvel@arm.com>
2020-12-21 17:16:23 +00:00

99 lines
3.1 KiB
C

/** @file
EFI_SIMPLE_FILE_SYSTEM_PROTOCOL.OpenVolume() member function for the Virtio
Filesystem driver.
Copyright (C) 2020, Red Hat, Inc.
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
#include <Library/BaseLib.h> // InsertTailList()
#include <Library/MemoryAllocationLib.h> // AllocatePool()
#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
)
{
VIRTIO_FS *VirtioFs;
VIRTIO_FS_FILE *VirtioFsFile;
EFI_STATUS Status;
CHAR8 *CanonicalPathname;
UINT64 RootDirHandle;
VirtioFs = VIRTIO_FS_FROM_SIMPLE_FS (This);
VirtioFsFile = AllocatePool (sizeof *VirtioFsFile);
if (VirtioFsFile == NULL) {
return EFI_OUT_OF_RESOURCES;
}
CanonicalPathname = AllocateCopyPool (sizeof "/", "/");
if (CanonicalPathname == NULL) {
Status = EFI_OUT_OF_RESOURCES;
goto FreeVirtioFsFile;
}
//
// Open the root directory.
//
Status = VirtioFsFuseOpenDir (VirtioFs, VIRTIO_FS_FUSE_ROOT_DIR_NODE_ID,
&RootDirHandle);
if (EFI_ERROR (Status)) {
goto FreeCanonicalPathname;
}
//
// Populate the new VIRTIO_FS_FILE object.
//
VirtioFsFile->Signature = VIRTIO_FS_FILE_SIG;
VirtioFsFile->SimpleFile.Revision = EFI_FILE_PROTOCOL_REVISION;
VirtioFsFile->SimpleFile.Open = VirtioFsSimpleFileOpen;
VirtioFsFile->SimpleFile.Close = VirtioFsSimpleFileClose;
VirtioFsFile->SimpleFile.Delete = VirtioFsSimpleFileDelete;
VirtioFsFile->SimpleFile.Read = VirtioFsSimpleFileRead;
VirtioFsFile->SimpleFile.Write = VirtioFsSimpleFileWrite;
VirtioFsFile->SimpleFile.GetPosition = VirtioFsSimpleFileGetPosition;
VirtioFsFile->SimpleFile.SetPosition = VirtioFsSimpleFileSetPosition;
VirtioFsFile->SimpleFile.GetInfo = VirtioFsSimpleFileGetInfo;
VirtioFsFile->SimpleFile.SetInfo = VirtioFsSimpleFileSetInfo;
VirtioFsFile->SimpleFile.Flush = VirtioFsSimpleFileFlush;
VirtioFsFile->IsDirectory = TRUE;
VirtioFsFile->IsOpenForWriting = FALSE;
VirtioFsFile->OwnerFs = VirtioFs;
VirtioFsFile->CanonicalPathname = CanonicalPathname;
VirtioFsFile->FilePosition = 0;
VirtioFsFile->NodeId = VIRTIO_FS_FUSE_ROOT_DIR_NODE_ID;
VirtioFsFile->FuseHandle = RootDirHandle;
VirtioFsFile->FileInfoArray = NULL;
VirtioFsFile->SingleFileInfoSize = 0;
VirtioFsFile->NumFileInfo = 0;
VirtioFsFile->NextFileInfo = 0;
//
// One more file open for the filesystem.
//
InsertTailList (&VirtioFs->OpenFiles, &VirtioFsFile->OpenFilesEntry);
*Root = &VirtioFsFile->SimpleFile;
return EFI_SUCCESS;
FreeCanonicalPathname:
FreePool (CanonicalPathname);
FreeVirtioFsFile:
FreePool (VirtioFsFile);
return Status;
}