]> git.proxmox.com Git - mirror_edk2.git/commitdiff
OvmfPkg/VirtioFsDxe: implement the wrapper function for FUSE_GETATTR
authorLaszlo Ersek <lersek@redhat.com>
Wed, 16 Dec 2020 21:11:02 +0000 (22:11 +0100)
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Mon, 21 Dec 2020 17:16:23 +0000 (17:16 +0000)
Add the VirtioFsFuseGetAttr() function, for sending the FUSE_GETATTR
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-26-lersek@redhat.com>
Acked-by: Ard Biesheuvel <ard.biesheuvel@arm.com>
OvmfPkg/Include/IndustryStandard/VirtioFs.h
OvmfPkg/VirtioFsDxe/FuseGetAttr.c [new file with mode: 0644]
OvmfPkg/VirtioFsDxe/VirtioFsDxe.h
OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf

index f49452830abc190f22269885cc7c0becd84ed97f..efcf57941c5916600a872809551d2b5c1a9a71a5 100644 (file)
@@ -114,6 +114,7 @@ typedef struct {
 typedef enum {\r
   VirtioFsFuseOpLookup      =  1,\r
   VirtioFsFuseOpForget      =  2,\r
+  VirtioFsFuseOpGetAttr     =  3,\r
   VirtioFsFuseOpMkDir       =  9,\r
   VirtioFsFuseOpUnlink      = 10,\r
   VirtioFsFuseOpRmDir       = 11,\r
@@ -195,6 +196,21 @@ typedef struct {
   UINT64 NumberOfLookups;\r
 } VIRTIO_FS_FUSE_FORGET_REQUEST;\r
 \r
+//\r
+// Headers for VirtioFsFuseOpGetAttr.\r
+//\r
+typedef struct {\r
+  UINT32 GetAttrFlags;\r
+  UINT32 Dummy;\r
+  UINT64 FileHandle;\r
+} VIRTIO_FS_FUSE_GETATTR_REQUEST;\r
+\r
+typedef struct {\r
+  UINT64 AttrValid;\r
+  UINT32 AttrValidNsec;\r
+  UINT32 Dummy;\r
+} VIRTIO_FS_FUSE_GETATTR_RESPONSE;\r
+\r
 //\r
 // Header for VirtioFsFuseOpMkDir.\r
 //\r
diff --git a/OvmfPkg/VirtioFsDxe/FuseGetAttr.c b/OvmfPkg/VirtioFsDxe/FuseGetAttr.c
new file mode 100644 (file)
index 0000000..29d8ec8
--- /dev/null
@@ -0,0 +1,116 @@
+/** @file\r
+  FUSE_GETATTR 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 "VirtioFsDxe.h"\r
+\r
+/**\r
+  Send a FUSE_GETATTR request to the Virtio Filesystem device, for fetching the\r
+  attributes of an inode.\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\r
+                           FUSE_GETATTR request to. On output, the FUSE request\r
+                           counter "VirtioFs->RequestId" will have been\r
+                           incremented.\r
+\r
+  @param[in] NodeId        The inode number for which the attributes should be\r
+                           retrieved.\r
+\r
+  @param[out] FuseAttr     The VIRTIO_FS_FUSE_ATTRIBUTES_RESPONSE object\r
+                           describing the properties of the inode.\r
+\r
+  @retval EFI_SUCCESS  FuseAttr has been filled in.\r
+\r
+  @return              The "errno" value mapped to an EFI_STATUS code, if the\r
+                       Virtio Filesystem device explicitly reported an error.\r
+\r
+  @return              Error codes propagated from VirtioFsSgListsValidate(),\r
+                       VirtioFsFuseNewRequest(), VirtioFsSgListsSubmit(),\r
+                       VirtioFsFuseCheckResponse().\r
+**/\r
+EFI_STATUS\r
+VirtioFsFuseGetAttr (\r
+  IN OUT VIRTIO_FS                          *VirtioFs,\r
+  IN     UINT64                             NodeId,\r
+     OUT VIRTIO_FS_FUSE_ATTRIBUTES_RESPONSE *FuseAttr\r
+  )\r
+{\r
+  VIRTIO_FS_FUSE_REQUEST          CommonReq;\r
+  VIRTIO_FS_FUSE_GETATTR_REQUEST  GetAttrReq;\r
+  VIRTIO_FS_IO_VECTOR             ReqIoVec[2];\r
+  VIRTIO_FS_SCATTER_GATHER_LIST   ReqSgList;\r
+  VIRTIO_FS_FUSE_RESPONSE         CommonResp;\r
+  VIRTIO_FS_FUSE_GETATTR_RESPONSE GetAttrResp;\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 = &GetAttrReq;\r
+  ReqIoVec[1].Size   = sizeof GetAttrReq;\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 = &GetAttrResp;\r
+  RespIoVec[1].Size   = sizeof GetAttrResp;\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
+    return Status;\r
+  }\r
+\r
+  //\r
+  // Populate the common request header.\r
+  //\r
+  Status = VirtioFsFuseNewRequest (VirtioFs, &CommonReq, ReqSgList.TotalSize,\r
+             VirtioFsFuseOpGetAttr, NodeId);\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  //\r
+  // Populate the FUSE_GETATTR-specific fields.\r
+  //\r
+  GetAttrReq.GetAttrFlags = 0;\r
+  GetAttrReq.Dummy        = 0;\r
+  GetAttrReq.FileHandle   = 0;\r
+\r
+  //\r
+  // Submit the request.\r
+  //\r
+  Status = VirtioFsSgListsSubmit (VirtioFs, &ReqSgList, &RespSgList);\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  //\r
+  // Verify the response (all response buffers are fixed size).\r
+  //\r
+  Status = VirtioFsFuseCheckResponse (&RespSgList, CommonReq.Unique, NULL);\r
+  if (Status == EFI_DEVICE_ERROR) {\r
+    DEBUG ((DEBUG_ERROR, "%a: Label=\"%s\" NodeId=%Lu Errno=%d\n",\r
+      __FUNCTION__, VirtioFs->Label, NodeId, CommonResp.Error));\r
+    Status = VirtioFsErrnoToEfiStatus (CommonResp.Error);\r
+  }\r
+  return Status;\r
+}\r
index 0e4f2109eb0291b4c2b9005bb621832fdc99268c..3bf64c0146fae05c96ce76807dd6698387720fa8 100644 (file)
@@ -259,6 +259,13 @@ VirtioFsFuseForget (
   IN     UINT64    NodeId\r
   );\r
 \r
+EFI_STATUS\r
+VirtioFsFuseGetAttr (\r
+  IN OUT VIRTIO_FS                          *VirtioFs,\r
+  IN     UINT64                             NodeId,\r
+     OUT VIRTIO_FS_FUSE_ATTRIBUTES_RESPONSE *FuseAttr\r
+  );\r
+\r
 EFI_STATUS\r
 VirtioFsFuseMkDir (\r
   IN OUT VIRTIO_FS *VirtioFs,\r
index 2332aa3ee551e00f51d75a139aa2fd9095e254b0..233c0c5c0f9a9417e973ef3ac38dcbb46ebb3967 100644 (file)
@@ -86,6 +86,7 @@
   FuseFlush.c\r
   FuseForget.c\r
   FuseFsync.c\r
+  FuseGetAttr.c\r
   FuseInit.c\r
   FuseLookup.c\r
   FuseMkDir.c\r