1 | /** @file
|
---|
2 | FUSE_FLUSH wrapper for the Virtio Filesystem device.
|
---|
3 |
|
---|
4 | Copyright (C) 2020, Red Hat, Inc.
|
---|
5 |
|
---|
6 | SPDX-License-Identifier: BSD-2-Clause-Patent
|
---|
7 | **/
|
---|
8 |
|
---|
9 | #include "VirtioFsDxe.h"
|
---|
10 |
|
---|
11 | /**
|
---|
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.
|
---|
15 |
|
---|
16 | The function may only be called after VirtioFsFuseInitSession() returns
|
---|
17 | successfully and before VirtioFsUninit() is called.
|
---|
18 |
|
---|
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.
|
---|
22 |
|
---|
23 | @param[in] NodeId The inode number of the regular file to flush.
|
---|
24 |
|
---|
25 | @param[in] FuseHandle The open handle to the regular file to flush.
|
---|
26 |
|
---|
27 | @retval EFI_SUCCESS The regular file has been flushed.
|
---|
28 |
|
---|
29 | @return The "errno" value mapped to an EFI_STATUS code, if the
|
---|
30 | Virtio Filesystem device explicitly reported an error.
|
---|
31 |
|
---|
32 | @return Error codes propagated from VirtioFsSgListsValidate(),
|
---|
33 | VirtioFsFuseNewRequest(), VirtioFsSgListsSubmit(),
|
---|
34 | VirtioFsFuseCheckResponse().
|
---|
35 | **/
|
---|
36 | EFI_STATUS
|
---|
37 | VirtioFsFuseFlush (
|
---|
38 | IN OUT VIRTIO_FS *VirtioFs,
|
---|
39 | IN UINT64 NodeId,
|
---|
40 | IN UINT64 FuseHandle
|
---|
41 | )
|
---|
42 | {
|
---|
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;
|
---|
50 | EFI_STATUS Status;
|
---|
51 |
|
---|
52 | //
|
---|
53 | // Set up the scatter-gather lists.
|
---|
54 | //
|
---|
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);
|
---|
61 |
|
---|
62 | RespIoVec[0].Buffer = &CommonResp;
|
---|
63 | RespIoVec[0].Size = sizeof CommonResp;
|
---|
64 | RespSgList.IoVec = RespIoVec;
|
---|
65 | RespSgList.NumVec = ARRAY_SIZE (RespIoVec);
|
---|
66 |
|
---|
67 | //
|
---|
68 | // Validate the scatter-gather lists; calculate the total transfer sizes.
|
---|
69 | //
|
---|
70 | Status = VirtioFsSgListsValidate (VirtioFs, &ReqSgList, &RespSgList);
|
---|
71 | if (EFI_ERROR (Status)) {
|
---|
72 | return Status;
|
---|
73 | }
|
---|
74 |
|
---|
75 | //
|
---|
76 | // Populate the common request header.
|
---|
77 | //
|
---|
78 | Status = VirtioFsFuseNewRequest (
|
---|
79 | VirtioFs,
|
---|
80 | &CommonReq,
|
---|
81 | ReqSgList.TotalSize,
|
---|
82 | VirtioFsFuseOpFlush,
|
---|
83 | NodeId
|
---|
84 | );
|
---|
85 | if (EFI_ERROR (Status)) {
|
---|
86 | return Status;
|
---|
87 | }
|
---|
88 |
|
---|
89 | //
|
---|
90 | // Populate the FUSE_FLUSH-specific fields.
|
---|
91 | //
|
---|
92 | FlushReq.FileHandle = FuseHandle;
|
---|
93 | FlushReq.Unused = 0;
|
---|
94 | FlushReq.Padding = 0;
|
---|
95 | FlushReq.LockOwner = 0;
|
---|
96 |
|
---|
97 | //
|
---|
98 | // Submit the request.
|
---|
99 | //
|
---|
100 | Status = VirtioFsSgListsSubmit (VirtioFs, &ReqSgList, &RespSgList);
|
---|
101 | if (EFI_ERROR (Status)) {
|
---|
102 | return Status;
|
---|
103 | }
|
---|
104 |
|
---|
105 | //
|
---|
106 | // Verify the response (all response buffers are fixed size).
|
---|
107 | //
|
---|
108 | Status = VirtioFsFuseCheckResponse (&RespSgList, CommonReq.Unique, NULL);
|
---|
109 | if (Status == EFI_DEVICE_ERROR) {
|
---|
110 | DEBUG ((
|
---|
111 | DEBUG_ERROR,
|
---|
112 | "%a: Label=\"%s\" NodeId=%Lu FuseHandle=%Lu "
|
---|
113 | "Errno=%d\n",
|
---|
114 | __func__,
|
---|
115 | VirtioFs->Label,
|
---|
116 | NodeId,
|
---|
117 | FuseHandle,
|
---|
118 | CommonResp.Error
|
---|
119 | ));
|
---|
120 | Status = VirtioFsErrnoToEfiStatus (CommonResp.Error);
|
---|
121 | }
|
---|
122 |
|
---|
123 | return Status;
|
---|
124 | }
|
---|