FuseForget.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /** @file
  2. FUSE_FORGET 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. Make the Virtio Filesysem device drop one reference count from a NodeId that
  9. the driver looked up by filename.
  10. Send the FUSE_FORGET request to the Virtio Filesysem device for this. Unlike
  11. most other FUSE requests, FUSE_FORGET doesn't elicit a response, not even the
  12. common VIRTIO_FS_FUSE_RESPONSE header.
  13. The function may only be called after VirtioFsFuseInitSession() returns
  14. successfully and before VirtioFsUninit() is called.
  15. @param[in,out] VirtioFs The Virtio Filesystem device to send the FUSE_FORGET
  16. request to. On output, the FUSE request counter
  17. "VirtioFs->RequestId" will have been incremented.
  18. @param[in] NodeId The inode number that the client learned by way of
  19. lookup, and that the server should now un-reference
  20. exactly once.
  21. @retval EFI_SUCCESS The FUSE_FORGET request has been submitted.
  22. @return Error codes propagated from VirtioFsSgListsValidate(),
  23. VirtioFsFuseNewRequest(), VirtioFsSgListsSubmit().
  24. **/
  25. EFI_STATUS
  26. VirtioFsFuseForget (
  27. IN OUT VIRTIO_FS *VirtioFs,
  28. IN UINT64 NodeId
  29. )
  30. {
  31. VIRTIO_FS_FUSE_REQUEST CommonReq;
  32. VIRTIO_FS_FUSE_FORGET_REQUEST ForgetReq;
  33. VIRTIO_FS_IO_VECTOR ReqIoVec[2];
  34. VIRTIO_FS_SCATTER_GATHER_LIST ReqSgList;
  35. EFI_STATUS Status;
  36. //
  37. // Set up the scatter-gather list (note: only request).
  38. //
  39. ReqIoVec[0].Buffer = &CommonReq;
  40. ReqIoVec[0].Size = sizeof CommonReq;
  41. ReqIoVec[1].Buffer = &ForgetReq;
  42. ReqIoVec[1].Size = sizeof ForgetReq;
  43. ReqSgList.IoVec = ReqIoVec;
  44. ReqSgList.NumVec = ARRAY_SIZE (ReqIoVec);
  45. //
  46. // Validate the scatter-gather list (request only); calculate the total
  47. // transfer size.
  48. //
  49. Status = VirtioFsSgListsValidate (VirtioFs, &ReqSgList, NULL);
  50. if (EFI_ERROR (Status)) {
  51. return Status;
  52. }
  53. //
  54. // Populate the common request header.
  55. //
  56. Status = VirtioFsFuseNewRequest (
  57. VirtioFs,
  58. &CommonReq,
  59. ReqSgList.TotalSize,
  60. VirtioFsFuseOpForget,
  61. NodeId
  62. );
  63. if (EFI_ERROR (Status)) {
  64. return Status;
  65. }
  66. //
  67. // Populate the FUSE_FORGET-specific fields.
  68. //
  69. ForgetReq.NumberOfLookups = 1;
  70. //
  71. // Submit the request. There's not going to be a response.
  72. //
  73. Status = VirtioFsSgListsSubmit (VirtioFs, &ReqSgList, NULL);
  74. return Status;
  75. }