OvmfPkg/VirtioFsDxe: implement EFI_SIMPLE_FILE_SYSTEM_PROTOCOL.OpenVolume()
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 <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-12-lersek@redhat.com> Acked-by: Ard Biesheuvel <ard.biesheuvel@arm.com>
This commit is contained in:
committed by
mergify[bot]
parent
72d4f133e9
commit
334c13e106
48
OvmfPkg/VirtioFsDxe/SimpleFsClose.c
Normal file
48
OvmfPkg/VirtioFsDxe/SimpleFsClose.c
Normal file
@@ -0,0 +1,48 @@
|
||||
/** @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;
|
||||
|
||||
//
|
||||
// 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 == 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;
|
||||
}
|
Reference in New Issue
Block a user