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