]> git.proxmox.com Git - mirror_edk2.git/commitdiff
OvmfPkg/VirtioFsDxe: implement the wrapper function for FUSE_STATFS
authorLaszlo Ersek <lersek@redhat.com>
Wed, 16 Dec 2020 21:11:05 +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 VirtioFsFuseStatFs() function, for sending the FUSE_STATFS 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-29-lersek@redhat.com>
Acked-by: Ard Biesheuvel <ard.biesheuvel@arm.com>
OvmfPkg/Include/IndustryStandard/VirtioFs.h
OvmfPkg/VirtioFsDxe/FuseStatFs.c [new file with mode: 0644]
OvmfPkg/VirtioFsDxe/VirtioFsDxe.h
OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf

index efcf57941c5916600a872809551d2b5c1a9a71a5..800d3651e12bea7b3057995ed77a131b27b0619c 100644 (file)
@@ -119,6 +119,7 @@ typedef enum {
   VirtioFsFuseOpUnlink      = 10,\r
   VirtioFsFuseOpRmDir       = 11,\r
   VirtioFsFuseOpOpen        = 14,\r
+  VirtioFsFuseOpStatFs      = 17,\r
   VirtioFsFuseOpRelease     = 18,\r
   VirtioFsFuseOpFsync       = 20,\r
   VirtioFsFuseOpFlush       = 25,\r
@@ -233,6 +234,22 @@ typedef struct {
   UINT32 Padding;\r
 } VIRTIO_FS_FUSE_OPEN_RESPONSE;\r
 \r
+//\r
+// Header for VirtioFsFuseOpStatFs.\r
+//\r
+typedef struct {\r
+  UINT64 Blocks;\r
+  UINT64 Bfree;\r
+  UINT64 Bavail;\r
+  UINT64 Files;\r
+  UINT64 Ffree;\r
+  UINT32 Bsize;\r
+  UINT32 Namelen;\r
+  UINT32 Frsize;\r
+  UINT32 Padding;\r
+  UINT32 Spare[6];\r
+} VIRTIO_FS_FUSE_STATFS_RESPONSE;\r
+\r
 //\r
 // Header for VirtioFsFuseOpRelease and VirtioFsFuseOpReleaseDir.\r
 //\r
diff --git a/OvmfPkg/VirtioFsDxe/FuseStatFs.c b/OvmfPkg/VirtioFsDxe/FuseStatFs.c
new file mode 100644 (file)
index 0000000..e794f89
--- /dev/null
@@ -0,0 +1,102 @@
+/** @file\r
+  FUSE_STATFS 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 the FUSE_STATFS request to the Virtio Filesysem device, for retrieving\r
+  the attributes of the host-side filesystem that contains NodeId.\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_STATFS\r
+                           request to. On output, the FUSE request counter\r
+                           "VirtioFs->RequestId" will have been incremented.\r
+\r
+  @param[in] NodeId        The inode whose containing filesystem is to be\r
+                           queried for its attributes.\r
+\r
+  @param[out] FilesysAttr  The VIRTIO_FS_FUSE_STATFS_RESPONSE object describing\r
+                           the filesystem that underlies NodeId.\r
+\r
+  @retval EFI_SUCCESS  FilesysAttr 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
+VirtioFsFuseStatFs (\r
+  IN OUT VIRTIO_FS                      *VirtioFs,\r
+  IN     UINT64                         NodeId,\r
+     OUT VIRTIO_FS_FUSE_STATFS_RESPONSE *FilesysAttr\r
+     )\r
+{\r
+  VIRTIO_FS_FUSE_REQUEST        CommonReq;\r
+  VIRTIO_FS_IO_VECTOR           ReqIoVec[1];\r
+  VIRTIO_FS_SCATTER_GATHER_LIST ReqSgList;\r
+  VIRTIO_FS_FUSE_RESPONSE       CommonResp;\r
+  VIRTIO_FS_IO_VECTOR           RespIoVec[2];\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
+  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 = FilesysAttr;\r
+  RespIoVec[1].Size   = sizeof *FilesysAttr;\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
+             VirtioFsFuseOpStatFs, NodeId);\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\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 3bf64c0146fae05c96ce76807dd6698387720fa8..029c568b39c730a797405e6726f52e2ecc3353c6 100644 (file)
@@ -290,6 +290,13 @@ VirtioFsFuseOpen (
      OUT UINT64    *FuseHandle\r
   );\r
 \r
+EFI_STATUS\r
+VirtioFsFuseStatFs (\r
+  IN OUT VIRTIO_FS                      *VirtioFs,\r
+  IN     UINT64                         NodeId,\r
+     OUT VIRTIO_FS_FUSE_STATFS_RESPONSE *FilesysAttr\r
+     );\r
+\r
 EFI_STATUS\r
 VirtioFsFuseReleaseFileOrDir (\r
   IN OUT VIRTIO_FS *VirtioFs,\r
index 233c0c5c0f9a9417e973ef3ac38dcbb46ebb3967..318449db3e63ddb4b2ee268677f263e7ecb24f6d 100644 (file)
@@ -94,6 +94,7 @@
   FuseOpenDir.c\r
   FuseOpenOrCreate.c\r
   FuseRelease.c\r
+  FuseStatFs.c\r
   FuseUnlink.c\r
   Helpers.c\r
   SimpleFsClose.c\r