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>
69 lines
2.1 KiB
C
69 lines
2.1 KiB
C
/** @file
|
|
EFI_FILE_PROTOCOL.Close() member function for the Virtio Filesystem driver.
|
|
|
|
Copyright (C) 2020, Red Hat, Inc.
|
|
|
|
SPDX-License-Identifier: BSD-2-Clause-Patent
|
|
**/
|
|
|
|
#include <Library/BaseLib.h> // RemoveEntryList()
|
|
#include <Library/MemoryAllocationLib.h> // FreePool()
|
|
|
|
#include "VirtioFsDxe.h"
|
|
|
|
EFI_STATUS
|
|
EFIAPI
|
|
VirtioFsSimpleFileClose (
|
|
IN EFI_FILE_PROTOCOL *This
|
|
)
|
|
{
|
|
VIRTIO_FS_FILE *VirtioFsFile;
|
|
VIRTIO_FS *VirtioFs;
|
|
|
|
VirtioFsFile = VIRTIO_FS_FILE_FROM_SIMPLE_FILE (This);
|
|
VirtioFs = VirtioFsFile->OwnerFs;
|
|
|
|
//
|
|
// 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 unconditionally,
|
|
// and to return EFI_SUCCESS 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);
|
|
|
|
//
|
|
// VirtioFsFile->FuseHandle is gone at this point, but VirtioFsFile->NodeId
|
|
// is still valid. If we've known VirtioFsFile->NodeId from a lookup, then
|
|
// now we should ask the server to forget it *once*.
|
|
//
|
|
if (VirtioFsFile->NodeId != 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->CanonicalPathname);
|
|
if (VirtioFsFile->FileInfoArray != NULL) {
|
|
FreePool (VirtioFsFile->FileInfoArray);
|
|
}
|
|
FreePool (VirtioFsFile);
|
|
return EFI_SUCCESS;
|
|
}
|