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