FuseFlush.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /** @file
  2. FUSE_FLUSH wrapper for the Virtio Filesystem device.
  3. Copyright (C) 2020, Red Hat, Inc.
  4. SPDX-License-Identifier: BSD-2-Clause-Patent
  5. **/
  6. #include "VirtioFsDxe.h"
  7. /**
  8. Flush changes queued on the local virtualization host to the remote storage
  9. server's memory (not storage device), over the network, by sending the
  10. FUSE_FLUSH request to the Virtio Filesystem device.
  11. The function may only be called after VirtioFsFuseInitSession() returns
  12. successfully and before VirtioFsUninit() is called.
  13. @param[in,out] VirtioFs The Virtio Filesystem device to send the FUSE_FLUSH
  14. request to. On output, the FUSE request counter
  15. "VirtioFs->RequestId" will have been incremented.
  16. @param[in] NodeId The inode number of the regular file to flush.
  17. @param[in] FuseHandle The open handle to the regular file to flush.
  18. @retval EFI_SUCCESS The regular file has been flushed.
  19. @return The "errno" value mapped to an EFI_STATUS code, if the
  20. Virtio Filesystem device explicitly reported an error.
  21. @return Error codes propagated from VirtioFsSgListsValidate(),
  22. VirtioFsFuseNewRequest(), VirtioFsSgListsSubmit(),
  23. VirtioFsFuseCheckResponse().
  24. **/
  25. EFI_STATUS
  26. VirtioFsFuseFlush (
  27. IN OUT VIRTIO_FS *VirtioFs,
  28. IN UINT64 NodeId,
  29. IN UINT64 FuseHandle
  30. )
  31. {
  32. VIRTIO_FS_FUSE_REQUEST CommonReq;
  33. VIRTIO_FS_FUSE_FLUSH_REQUEST FlushReq;
  34. VIRTIO_FS_IO_VECTOR ReqIoVec[2];
  35. VIRTIO_FS_SCATTER_GATHER_LIST ReqSgList;
  36. VIRTIO_FS_FUSE_RESPONSE CommonResp;
  37. VIRTIO_FS_IO_VECTOR RespIoVec[1];
  38. VIRTIO_FS_SCATTER_GATHER_LIST RespSgList;
  39. EFI_STATUS Status;
  40. //
  41. // Set up the scatter-gather lists.
  42. //
  43. ReqIoVec[0].Buffer = &CommonReq;
  44. ReqIoVec[0].Size = sizeof CommonReq;
  45. ReqIoVec[1].Buffer = &FlushReq;
  46. ReqIoVec[1].Size = sizeof FlushReq;
  47. ReqSgList.IoVec = ReqIoVec;
  48. ReqSgList.NumVec = ARRAY_SIZE (ReqIoVec);
  49. RespIoVec[0].Buffer = &CommonResp;
  50. RespIoVec[0].Size = sizeof CommonResp;
  51. RespSgList.IoVec = RespIoVec;
  52. RespSgList.NumVec = ARRAY_SIZE (RespIoVec);
  53. //
  54. // Validate the scatter-gather lists; calculate the total transfer sizes.
  55. //
  56. Status = VirtioFsSgListsValidate (VirtioFs, &ReqSgList, &RespSgList);
  57. if (EFI_ERROR (Status)) {
  58. return Status;
  59. }
  60. //
  61. // Populate the common request header.
  62. //
  63. Status = VirtioFsFuseNewRequest (
  64. VirtioFs,
  65. &CommonReq,
  66. ReqSgList.TotalSize,
  67. VirtioFsFuseOpFlush,
  68. NodeId
  69. );
  70. if (EFI_ERROR (Status)) {
  71. return Status;
  72. }
  73. //
  74. // Populate the FUSE_FLUSH-specific fields.
  75. //
  76. FlushReq.FileHandle = FuseHandle;
  77. FlushReq.Unused = 0;
  78. FlushReq.Padding = 0;
  79. FlushReq.LockOwner = 0;
  80. //
  81. // Submit the request.
  82. //
  83. Status = VirtioFsSgListsSubmit (VirtioFs, &ReqSgList, &RespSgList);
  84. if (EFI_ERROR (Status)) {
  85. return Status;
  86. }
  87. //
  88. // Verify the response (all response buffers are fixed size).
  89. //
  90. Status = VirtioFsFuseCheckResponse (&RespSgList, CommonReq.Unique, NULL);
  91. if (Status == EFI_DEVICE_ERROR) {
  92. DEBUG ((
  93. DEBUG_ERROR,
  94. "%a: Label=\"%s\" NodeId=%Lu FuseHandle=%Lu "
  95. "Errno=%d\n",
  96. __FUNCTION__,
  97. VirtioFs->Label,
  98. NodeId,
  99. FuseHandle,
  100. CommonResp.Error
  101. ));
  102. Status = VirtioFsErrnoToEfiStatus (CommonResp.Error);
  103. }
  104. return Status;
  105. }