1 | /** @file
|
---|
2 | FUSE_INIT 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 | Send a FUSE_INIT request to the Virtio Filesystem device, for starting the
|
---|
13 | FUSE session.
|
---|
14 |
|
---|
15 | From virtio-v1.1-cs01-87fa6b5d8155, 5.11.5 Device Initialization: "On
|
---|
16 | initialization the driver first discovers the device's virtqueues. The FUSE
|
---|
17 | session is started by sending a FUSE_INIT request as defined by the FUSE
|
---|
18 | protocol on one request virtqueue."
|
---|
19 |
|
---|
20 | The function may only be called after VirtioFsInit() returns successfully and
|
---|
21 | before VirtioFsUninit() is called.
|
---|
22 |
|
---|
23 | @param[in,out] VirtioFs The Virtio Filesystem device to send the FUSE_INIT
|
---|
24 | request to. The FUSE request counter
|
---|
25 | "VirtioFs->RequestId" is set to 1 on output. The
|
---|
26 | maximum write buffer size exposed in the FUSE_INIT
|
---|
27 | response is saved in "VirtioFs->MaxWrite", on
|
---|
28 | output.
|
---|
29 |
|
---|
30 | @retval EFI_SUCCESS The FUSE session has been started.
|
---|
31 |
|
---|
32 | @retval EFI_UNSUPPORTED FUSE interface version or feature negotiation
|
---|
33 | failed.
|
---|
34 |
|
---|
35 | @return The "errno" value mapped to an EFI_STATUS code, if
|
---|
36 | the Virtio Filesystem device explicitly reported an
|
---|
37 | error.
|
---|
38 |
|
---|
39 | @return Error codes propagated from
|
---|
40 | VirtioFsSgListsValidate(), VirtioFsFuseNewRequest(),
|
---|
41 | VirtioFsSgListsSubmit(),
|
---|
42 | VirtioFsFuseCheckResponse().
|
---|
43 | **/
|
---|
44 | EFI_STATUS
|
---|
45 | VirtioFsFuseInitSession (
|
---|
46 | IN OUT VIRTIO_FS *VirtioFs
|
---|
47 | )
|
---|
48 | {
|
---|
49 | VIRTIO_FS_FUSE_REQUEST CommonReq;
|
---|
50 | VIRTIO_FS_FUSE_INIT_REQUEST InitReq;
|
---|
51 | VIRTIO_FS_IO_VECTOR ReqIoVec[2];
|
---|
52 | VIRTIO_FS_SCATTER_GATHER_LIST ReqSgList;
|
---|
53 | VIRTIO_FS_FUSE_RESPONSE CommonResp;
|
---|
54 | VIRTIO_FS_FUSE_INIT_RESPONSE InitResp;
|
---|
55 | VIRTIO_FS_IO_VECTOR RespIoVec[2];
|
---|
56 | VIRTIO_FS_SCATTER_GATHER_LIST RespSgList;
|
---|
57 | EFI_STATUS Status;
|
---|
58 |
|
---|
59 | //
|
---|
60 | // Initialize the FUSE request counter.
|
---|
61 | //
|
---|
62 | VirtioFs->RequestId = 1;
|
---|
63 |
|
---|
64 | //
|
---|
65 | // Set up the scatter-gather lists.
|
---|
66 | //
|
---|
67 | ReqIoVec[0].Buffer = &CommonReq;
|
---|
68 | ReqIoVec[0].Size = sizeof CommonReq;
|
---|
69 | ReqIoVec[1].Buffer = &InitReq;
|
---|
70 | ReqIoVec[1].Size = sizeof InitReq;
|
---|
71 | ReqSgList.IoVec = ReqIoVec;
|
---|
72 | ReqSgList.NumVec = ARRAY_SIZE (ReqIoVec);
|
---|
73 |
|
---|
74 | RespIoVec[0].Buffer = &CommonResp;
|
---|
75 | RespIoVec[0].Size = sizeof CommonResp;
|
---|
76 | RespIoVec[1].Buffer = &InitResp;
|
---|
77 | RespIoVec[1].Size = sizeof InitResp;
|
---|
78 | RespSgList.IoVec = RespIoVec;
|
---|
79 | RespSgList.NumVec = ARRAY_SIZE (RespIoVec);
|
---|
80 |
|
---|
81 | //
|
---|
82 | // Validate the scatter-gather lists; calculate the total transfer sizes.
|
---|
83 | //
|
---|
84 | Status = VirtioFsSgListsValidate (VirtioFs, &ReqSgList, &RespSgList);
|
---|
85 | if (EFI_ERROR (Status)) {
|
---|
86 | return Status;
|
---|
87 | }
|
---|
88 |
|
---|
89 | //
|
---|
90 | // Populate the common request header.
|
---|
91 | //
|
---|
92 | Status = VirtioFsFuseNewRequest (VirtioFs, &CommonReq, ReqSgList.TotalSize,
|
---|
93 | VirtioFsFuseOpInit, 0);
|
---|
94 | if (EFI_ERROR (Status)) {
|
---|
95 | return Status;
|
---|
96 | }
|
---|
97 |
|
---|
98 | //
|
---|
99 | // Populate the FUSE_INIT-specific fields.
|
---|
100 | //
|
---|
101 | InitReq.Major = VIRTIO_FS_FUSE_MAJOR;
|
---|
102 | InitReq.Minor = VIRTIO_FS_FUSE_MINOR;
|
---|
103 | InitReq.MaxReadahead = 0;
|
---|
104 | InitReq.Flags = VIRTIO_FS_FUSE_INIT_REQ_F_DO_READDIRPLUS;
|
---|
105 |
|
---|
106 | //
|
---|
107 | // Submit the request.
|
---|
108 | //
|
---|
109 | Status = VirtioFsSgListsSubmit (VirtioFs, &ReqSgList, &RespSgList);
|
---|
110 | if (EFI_ERROR (Status)) {
|
---|
111 | return Status;
|
---|
112 | }
|
---|
113 |
|
---|
114 | //
|
---|
115 | // Verify the response (all response buffers are fixed size).
|
---|
116 | //
|
---|
117 | Status = VirtioFsFuseCheckResponse (&RespSgList, CommonReq.Unique, NULL);
|
---|
118 | if (EFI_ERROR (Status)) {
|
---|
119 | if (Status == EFI_DEVICE_ERROR) {
|
---|
120 | DEBUG ((DEBUG_ERROR, "%a: Label=\"%s\" Errno=%d\n", __FUNCTION__,
|
---|
121 | VirtioFs->Label, CommonResp.Error));
|
---|
122 | Status = VirtioFsErrnoToEfiStatus (CommonResp.Error);
|
---|
123 | }
|
---|
124 | return Status;
|
---|
125 | }
|
---|
126 |
|
---|
127 | //
|
---|
128 | // Check FUSE interface version / feature compatibility.
|
---|
129 | //
|
---|
130 | if (InitResp.Major < InitReq.Major ||
|
---|
131 | (InitResp.Major == InitReq.Major && InitResp.Minor < InitReq.Minor) ||
|
---|
132 | (InitResp.Flags & VIRTIO_FS_FUSE_INIT_REQ_F_DO_READDIRPLUS) == 0 ||
|
---|
133 | InitResp.MaxWrite < SIZE_4KB) {
|
---|
134 | return EFI_UNSUPPORTED;
|
---|
135 | }
|
---|
136 |
|
---|
137 | //
|
---|
138 | // Save the maximum write buffer size for FUSE_WRITE requests.
|
---|
139 | //
|
---|
140 | VirtioFs->MaxWrite = InitResp.MaxWrite;
|
---|
141 | return EFI_SUCCESS;
|
---|
142 | }
|
---|