]> git.proxmox.com Git - mirror_edk2.git/commitdiff
OvmfPkg/VirtioFsDxe: implement the wrapper function for FUSE_LOOKUP
authorLaszlo Ersek <lersek@redhat.com>
Wed, 16 Dec 2020 21:10:59 +0000 (22:10 +0100)
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Mon, 21 Dec 2020 17:16:23 +0000 (17:16 +0000)
Add the VirtioFsFuseLookup() function, for sending the FUSE_LOOKUP command
to the Virtio Filesystem device.

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-23-lersek@redhat.com>
Acked-by: Ard Biesheuvel <ard.biesheuvel@arm.com>
OvmfPkg/Include/IndustryStandard/VirtioFs.h
OvmfPkg/VirtioFsDxe/FuseLookup.c [new file with mode: 0644]
OvmfPkg/VirtioFsDxe/VirtioFsDxe.h
OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf

index 5d1d990a2d839c8c9794f30d8369dad6a4a8f2e9..8a07b3d2eb9366775514979245608f072019fd13 100644 (file)
@@ -81,6 +81,11 @@ typedef struct {
 //\r
 #define VIRTIO_FS_FUSE_ROOT_DIR_NODE_ID 1\r
 \r
+//\r
+// Distinguished errno values.\r
+//\r
+#define VIRTIO_FS_FUSE_ERRNO_ENOENT (-2)\r
+\r
 //\r
 // File mode bitmasks.\r
 //\r
@@ -107,6 +112,7 @@ typedef struct {
 // FUSE operation codes.\r
 //\r
 typedef enum {\r
+  VirtioFsFuseOpLookup      =  1,\r
   VirtioFsFuseOpForget      =  2,\r
   VirtioFsFuseOpMkDir       =  9,\r
   VirtioFsFuseOpOpen        = 14,\r
diff --git a/OvmfPkg/VirtioFsDxe/FuseLookup.c b/OvmfPkg/VirtioFsDxe/FuseLookup.c
new file mode 100644 (file)
index 0000000..5c9a825
--- /dev/null
@@ -0,0 +1,148 @@
+/** @file\r
+  FUSE_LOOKUP wrapper for the Virtio Filesystem device.\r
+\r
+  Copyright (C) 2020, Red Hat, Inc.\r
+\r
+  SPDX-License-Identifier: BSD-2-Clause-Patent\r
+**/\r
+\r
+#include <Library/BaseLib.h> // AsciiStrSize()\r
+\r
+#include "VirtioFsDxe.h"\r
+\r
+/**\r
+  Send a FUSE_LOOKUP request to the Virtio Filesystem device, for resolving a\r
+  filename to an inode.\r
+\r
+  The function returns EFI_NOT_FOUND exclusively if the Virtio Filesystem\r
+  device explicitly responds with ENOENT -- "No such file or directory".\r
+\r
+  The function may only be called after VirtioFsFuseInitSession() returns\r
+  successfully and before VirtioFsUninit() is called.\r
+\r
+  @param[in,out] VirtioFs  The Virtio Filesystem device to send the FUSE_LOOKUP\r
+                           request to. On output, the FUSE request counter\r
+                           "VirtioFs->RequestId" will have been incremented.\r
+\r
+  @param[in] DirNodeId     The inode number of the directory in which Name\r
+                           should be resolved to an inode.\r
+\r
+  @param[in] Name          The single-component filename to resolve in the\r
+                           directory identified by DirNodeId.\r
+\r
+  @param[out] NodeId       The inode number which Name has been resolved to.\r
+\r
+  @param[out] FuseAttr     The VIRTIO_FS_FUSE_ATTRIBUTES_RESPONSE object\r
+                           describing the properties of the resolved inode.\r
+\r
+  @retval EFI_SUCCESS    Filename to inode resolution successful.\r
+\r
+  @retval EFI_NOT_FOUND  The Virtio Filesystem device explicitly reported\r
+                         ENOENT -- "No such file or directory".\r
+\r
+  @return                The "errno" value mapped to an EFI_STATUS code, if the\r
+                         Virtio Filesystem device explicitly reported an error\r
+                         different from ENOENT. If said mapping resulted in\r
+                         EFI_NOT_FOUND, it is remapped to EFI_DEVICE_ERROR.\r
+\r
+  @return                Error codes propagated from VirtioFsSgListsValidate(),\r
+                         VirtioFsFuseNewRequest(), VirtioFsSgListsSubmit(),\r
+                         VirtioFsFuseCheckResponse(). EFI_NOT_FOUND is remapped\r
+                         to EFI_DEVICE_ERROR.\r
+**/\r
+EFI_STATUS\r
+VirtioFsFuseLookup (\r
+  IN OUT VIRTIO_FS                          *VirtioFs,\r
+  IN     UINT64                             DirNodeId,\r
+  IN     CHAR8                              *Name,\r
+     OUT UINT64                             *NodeId,\r
+     OUT VIRTIO_FS_FUSE_ATTRIBUTES_RESPONSE *FuseAttr\r
+  )\r
+{\r
+  VIRTIO_FS_FUSE_REQUEST        CommonReq;\r
+  VIRTIO_FS_IO_VECTOR           ReqIoVec[2];\r
+  VIRTIO_FS_SCATTER_GATHER_LIST ReqSgList;\r
+  VIRTIO_FS_FUSE_RESPONSE       CommonResp;\r
+  VIRTIO_FS_FUSE_NODE_RESPONSE  NodeResp;\r
+  VIRTIO_FS_IO_VECTOR           RespIoVec[3];\r
+  VIRTIO_FS_SCATTER_GATHER_LIST RespSgList;\r
+  EFI_STATUS                    Status;\r
+\r
+  //\r
+  // Set up the scatter-gather lists.\r
+  //\r
+  ReqIoVec[0].Buffer = &CommonReq;\r
+  ReqIoVec[0].Size   = sizeof CommonReq;\r
+  ReqIoVec[1].Buffer = Name;\r
+  ReqIoVec[1].Size   = AsciiStrSize (Name);\r
+  ReqSgList.IoVec    = ReqIoVec;\r
+  ReqSgList.NumVec   = ARRAY_SIZE (ReqIoVec);\r
+\r
+  RespIoVec[0].Buffer = &CommonResp;\r
+  RespIoVec[0].Size   = sizeof CommonResp;\r
+  RespIoVec[1].Buffer = &NodeResp;\r
+  RespIoVec[1].Size   = sizeof NodeResp;\r
+  RespIoVec[2].Buffer = FuseAttr;\r
+  RespIoVec[2].Size   = sizeof *FuseAttr;\r
+  RespSgList.IoVec    = RespIoVec;\r
+  RespSgList.NumVec   = ARRAY_SIZE (RespIoVec);\r
+\r
+  //\r
+  // Validate the scatter-gather lists; calculate the total transfer sizes.\r
+  //\r
+  Status = VirtioFsSgListsValidate (VirtioFs, &ReqSgList, &RespSgList);\r
+  if (EFI_ERROR (Status)) {\r
+    goto Fail;\r
+  }\r
+\r
+  //\r
+  // Populate the common request header.\r
+  //\r
+  Status = VirtioFsFuseNewRequest (VirtioFs, &CommonReq, ReqSgList.TotalSize,\r
+             VirtioFsFuseOpLookup, DirNodeId);\r
+  if (EFI_ERROR (Status)) {\r
+    goto Fail;\r
+  }\r
+\r
+  //\r
+  // Submit the request.\r
+  //\r
+  Status = VirtioFsSgListsSubmit (VirtioFs, &ReqSgList, &RespSgList);\r
+  if (EFI_ERROR (Status)) {\r
+    goto Fail;\r
+  }\r
+\r
+  //\r
+  // Verify the response (all response buffers are fixed size).\r
+  //\r
+  Status = VirtioFsFuseCheckResponse (&RespSgList, CommonReq.Unique, NULL);\r
+  if (EFI_ERROR (Status)) {\r
+    if (Status == EFI_DEVICE_ERROR) {\r
+      DEBUG ((\r
+        ((CommonResp.Error == VIRTIO_FS_FUSE_ERRNO_ENOENT) ?\r
+         DEBUG_VERBOSE :\r
+         DEBUG_ERROR),\r
+        "%a: Label=\"%s\" DirNodeId=%Lu Name=\"%a\" Errno=%d\n",\r
+        __FUNCTION__,\r
+        VirtioFs->Label,\r
+        DirNodeId,\r
+        Name,\r
+        CommonResp.Error\r
+        ));\r
+      if (CommonResp.Error == VIRTIO_FS_FUSE_ERRNO_ENOENT) {\r
+        return EFI_NOT_FOUND;\r
+      }\r
+      Status = VirtioFsErrnoToEfiStatus (CommonResp.Error);\r
+    }\r
+    goto Fail;\r
+  }\r
+\r
+  //\r
+  // Output the NodeId to which Name has been resolved to.\r
+  //\r
+  *NodeId = NodeResp.NodeId;\r
+  return EFI_SUCCESS;\r
+\r
+Fail:\r
+  return (Status == EFI_NOT_FOUND) ? EFI_DEVICE_ERROR : Status;\r
+}\r
index 6cc5257bab40f238c091e018b4114ccfd225c09e..b2e4adce098bd06f63cf5684a9b4a04cb50c425e 100644 (file)
@@ -236,6 +236,15 @@ VirtioFsFuseAttrToEfiFileInfo (
 // Wrapper functions for FUSE commands (primitives).\r
 //\r
 \r
+EFI_STATUS\r
+VirtioFsFuseLookup (\r
+  IN OUT VIRTIO_FS                          *VirtioFs,\r
+  IN     UINT64                             DirNodeId,\r
+  IN     CHAR8                              *Name,\r
+     OUT UINT64                             *NodeId,\r
+     OUT VIRTIO_FS_FUSE_ATTRIBUTES_RESPONSE *FuseAttr\r
+  );\r
+\r
 EFI_STATUS\r
 VirtioFsFuseForget (\r
   IN OUT VIRTIO_FS *VirtioFs,\r
index 7d7272188465a892a819231994a2362cecf1ef94..3552ece6b945b7ee599ffd8dcb4c08f85531a450 100644 (file)
@@ -87,6 +87,7 @@
   FuseForget.c\r
   FuseFsync.c\r
   FuseInit.c\r
+  FuseLookup.c\r
   FuseMkDir.c\r
   FuseOpen.c\r
   FuseOpenDir.c\r