]> git.proxmox.com Git - mirror_edk2.git/blame - OvmfPkg/VirtioFsDxe/SimpleFsDelete.c
OvmfPkg/VirtioFsDxe: flush, sync, release and forget in Close() / Delete()
[mirror_edk2.git] / OvmfPkg / VirtioFsDxe / SimpleFsDelete.c
CommitLineData
334c13e1
LE
1/** @file\r
2 EFI_FILE_PROTOCOL.Delete() member function for the Virtio Filesystem driver.\r
3\r
4 Copyright (C) 2020, Red Hat, Inc.\r
5\r
6 SPDX-License-Identifier: BSD-2-Clause-Patent\r
7**/\r
8\r
28092a39
LE
9#include <Library/BaseLib.h> // RemoveEntryList()\r
10#include <Library/MemoryAllocationLib.h> // FreePool()\r
11\r
334c13e1
LE
12#include "VirtioFsDxe.h"\r
13\r
14EFI_STATUS\r
15EFIAPI\r
16VirtioFsSimpleFileDelete (\r
17 IN EFI_FILE_PROTOCOL *This\r
18 )\r
19{\r
28092a39
LE
20 VIRTIO_FS_FILE *VirtioFsFile;\r
21 VIRTIO_FS *VirtioFs;\r
22 EFI_STATUS Status;\r
23\r
24 VirtioFsFile = VIRTIO_FS_FILE_FROM_SIMPLE_FILE (This);\r
25 VirtioFs = VirtioFsFile->OwnerFs;\r
26\r
27 //\r
28 // All actions in this function are "best effort"; the UEFI spec requires\r
29 // EFI_FILE_PROTOCOL.Delete() to release resources unconditionally. If a step\r
30 // related to removing the file fails, it's only reflected in the return\r
31 // status (EFI_WARN_DELETE_FAILURE rather than EFI_SUCCESS).\r
32 //\r
33 // Release, remove, and (if needed) forget. We don't waste time flushing and\r
34 // syncing; if the EFI_FILE_PROTOCOL user cares enough, they should keep the\r
35 // parent directory open until after this function call returns, and then\r
36 // force a sync on *that* EFI_FILE_PROTOCOL instance, using either the\r
37 // Flush() member function, or the Close() member function.\r
38 //\r
39 // If any action fails below, we still try the others.\r
40 //\r
41 VirtioFsFuseReleaseFileOrDir (VirtioFs, VirtioFsFile->NodeId,\r
42 VirtioFsFile->FuseHandle, VirtioFsFile->IsDirectory);\r
43\r
44 //\r
45 // VirtioFsFile->FuseHandle is gone at this point, but VirtioFsFile->NodeId\r
46 // is still valid. Continue with removing the file or directory. The result\r
47 // of this operation determines the return status of the function.\r
334c13e1 48 //\r
28092a39 49 // TODO\r
334c13e1 50 //\r
28092a39
LE
51 Status = EFI_WARN_DELETE_FAILURE;\r
52\r
334c13e1 53 //\r
28092a39
LE
54 // Finally, if we've known VirtioFsFile->NodeId from a lookup, then we should\r
55 // also ask the server to forget it *once*.\r
334c13e1 56 //\r
28092a39
LE
57 if (VirtioFsFile->NodeId != VIRTIO_FS_FUSE_ROOT_DIR_NODE_ID) {\r
58 VirtioFsFuseForget (VirtioFs, VirtioFsFile->NodeId);\r
59 }\r
60\r
61 //\r
62 // One fewer file left open for the owner filesystem.\r
63 //\r
64 RemoveEntryList (&VirtioFsFile->OpenFilesEntry);\r
65\r
66 FreePool (VirtioFsFile);\r
67 return Status;\r
334c13e1 68}\r