1 /*
2 Copyright (c) 2003, 2021, Oracle and/or its affiliates.
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License, version 2.0,
6 as published by the Free Software Foundation.
7
8 This program is also distributed with certain software (including
9 but not limited to OpenSSL) that is licensed under separate terms,
10 as designated in a particular file or component or in included license
11 documentation. The authors of MySQL hereby grant you an additional
12 permission to link the program and your derivative works with the
13 separately licensed software that they have included with MySQL.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License, version 2.0, for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23 */
24
25 #include "Ndbfs.hpp"
26
27 #include "AsyncFile.hpp"
28
29 #include <signaldata/FsOpenReq.hpp>
30 #include <signaldata/FsCloseReq.hpp>
31 #include <signaldata/FsReadWriteReq.hpp>
32 #include <signaldata/FsAppendReq.hpp>
33 #include <signaldata/FsRemoveReq.hpp>
34 #include <signaldata/FsConf.hpp>
35 #include <signaldata/FsRef.hpp>
36 #include <signaldata/NdbfsContinueB.hpp>
37 #include <signaldata/DumpStateOrd.hpp>
38
39 #include <RefConvert.hpp>
40 #include <Configuration.hpp>
41
42 #define JAM_FILE_ID 394
43
44
VoidFs(Block_context & ctx)45 VoidFs::VoidFs(Block_context & ctx) :
46 Ndbfs(ctx)
47 {
48 // Set received signals
49 addRecSignal(GSN_SEND_PACKED, &VoidFs::execSEND_PACKED, true);
50 addRecSignal(GSN_READ_CONFIG_REQ, &VoidFs::execREAD_CONFIG_REQ, true);
51 addRecSignal(GSN_DUMP_STATE_ORD, &VoidFs::execDUMP_STATE_ORD, true);
52 addRecSignal(GSN_STTOR, &VoidFs::execSTTOR, true);
53 addRecSignal(GSN_FSOPENREQ, &VoidFs::execFSOPENREQ, true);
54 addRecSignal(GSN_FSCLOSEREQ, &VoidFs::execFSCLOSEREQ, true);
55 addRecSignal(GSN_FSWRITEREQ, &VoidFs::execFSWRITEREQ, true);
56 addRecSignal(GSN_FSREADREQ, &VoidFs::execFSREADREQ, true);
57 addRecSignal(GSN_FSSYNCREQ, &VoidFs::execFSSYNCREQ, true);
58 addRecSignal(GSN_FSAPPENDREQ, &VoidFs::execFSAPPENDREQ, true);
59 addRecSignal(GSN_FSREMOVEREQ, &VoidFs::execFSREMOVEREQ, true);
60 addRecSignal(GSN_FSSUSPENDORD, &VoidFs::execFSSUSPENDORD, true);
61 // Set send signals
62 }
63
~VoidFs()64 VoidFs::~VoidFs()
65 {
66 }
67
68 void
execREAD_CONFIG_REQ(Signal * signal)69 VoidFs::execREAD_CONFIG_REQ(Signal* signal)
70 {
71 const ReadConfigReq * req = (ReadConfigReq*)signal->getDataPtr();
72
73 Uint32 ref = req->senderRef;
74 Uint32 senderData = req->senderData;
75
76 ReadConfigConf * conf = (ReadConfigConf*)signal->getDataPtrSend();
77 conf->senderRef = reference();
78 conf->senderData = senderData;
79 sendSignal(ref, GSN_READ_CONFIG_CONF, signal,
80 ReadConfigConf::SignalLength, JBB);
81
82 signal->theData[0] = NdbfsContinueB::ZSCAN_MEMORYCHANNEL_10MS_DELAY;
83 sendSignalWithDelay(reference(), GSN_CONTINUEB, signal, 10, 1);
84 }
85
86 void
execSTTOR(Signal * signal)87 VoidFs::execSTTOR(Signal* signal)
88 {
89 jamEntry();
90
91 if(signal->theData[1] == 0){ // StartPhase 0
92 jam();
93 signal->theData[3] = 255;
94 sendSignal(NDBCNTR_REF, GSN_STTORRY, signal, 4, JBB);
95 return;
96 }
97 ndbrequire(0);
98 }
99
100 void
execSEND_PACKED(Signal * signal)101 VoidFs::execSEND_PACKED(Signal* signal)
102 {
103 jamEntry();
104 if (scanningInProgress == false && scanIPC(signal))
105 {
106 jam();
107 scanningInProgress = true;
108 signal->theData[0] = NdbfsContinueB::ZSCAN_MEMORYCHANNEL_NO_DELAY;
109 sendSignal(reference(), GSN_CONTINUEB, signal, 1, JBB);
110 }
111 }
112
113 void
execFSOPENREQ(Signal * signal)114 VoidFs::execFSOPENREQ(Signal* signal)
115 {
116 jamEntry();
117 const FsOpenReq * const fsOpenReq = (FsOpenReq *)&signal->theData[0];
118 const BlockReference userRef = fsOpenReq->userReference;
119 const Uint32 userPointer = fsOpenReq->userPointer;
120
121 Uint32 flags = fsOpenReq->fileFlags;
122 if(flags == FsOpenReq::OM_READONLY){
123 // Initialise FsRef signal
124 FsRef * const fsRef = (FsRef *)&signal->theData[0];
125 fsRef->userPointer = userPointer;
126 fsRef->errorCode = FsRef::fsErrFileDoesNotExist;
127 fsRef->osErrorCode = ~0;
128 sendSignal(userRef, GSN_FSOPENREF, signal, 3, JBB);
129 return;
130 }
131
132 if(flags & FsOpenReq::OM_WRITEONLY || flags & FsOpenReq::OM_READWRITE){
133 signal->theData[0] = userPointer;
134 signal->theData[1] = c_maxFileNo++;
135 sendSignal(userRef, GSN_FSOPENCONF, signal, 2, JBB);
136 }
137 }
138
139 void
execFSREMOVEREQ(Signal * signal)140 VoidFs::execFSREMOVEREQ(Signal* signal)
141 {
142 jamEntry();
143 const FsRemoveReq * const req = (FsRemoveReq *)signal->getDataPtr();
144 const Uint32 userRef = req->userReference;
145 const Uint32 userPointer = req->userPointer;
146
147 signal->theData[0] = userPointer;
148 sendSignal(userRef, GSN_FSREMOVECONF, signal, 1, JBB);
149 }
150
151 /*
152 * PR0: File Pointer DR0: User reference DR1: User Pointer DR2: Flag bit 0= 1
153 * remove file
154 */
155 void
execFSCLOSEREQ(Signal * signal)156 VoidFs::execFSCLOSEREQ(Signal * signal)
157 {
158 jamEntry();
159
160 const FsCloseReq * const req = (FsCloseReq *)signal->getDataPtr();
161 const Uint32 userRef = req->userReference;
162 const Uint32 userPointer = req->userPointer;
163
164 signal->theData[0] = userPointer;
165 sendSignal(userRef, GSN_FSCLOSECONF, signal, 1, JBB);
166 }
167
168 void
execFSWRITEREQ(Signal * signal)169 VoidFs::execFSWRITEREQ(Signal* signal)
170 {
171 jamEntry();
172 const FsReadWriteReq * const req = (FsReadWriteReq *)signal->getDataPtr();
173 const Uint32 userRef = req->userReference;
174 const Uint32 userPointer = req->userPointer;
175
176 SectionHandle handle(this, signal);
177 releaseSections(handle);
178
179 signal->theData[0] = userPointer;
180 sendSignal(userRef, GSN_FSWRITECONF, signal, 1, JBB);
181 }
182
183 void
execFSREADREQ(Signal * signal)184 VoidFs::execFSREADREQ(Signal* signal)
185 {
186 jamEntry();
187
188 const FsReadWriteReq * const req = (FsReadWriteReq *)signal->getDataPtr();
189 const Uint32 userRef = req->userReference;
190 const Uint32 userPointer = req->userPointer;
191
192 SectionHandle handle(this, signal);
193 releaseSections(handle);
194
195 signal->theData[0] = userPointer;
196 sendSignal(userRef, GSN_FSREADCONF, signal, 1, JBB);
197 #if 0
198 FsRef * const fsRef = (FsRef *)&signal->theData[0];
199 fsRef->userPointer = userPointer;
200 fsRef->errorCode = FsRef::fsErrEnvironmentError;
201 fsRef->osErrorCode = ~0; // Indicate local error
202 sendSignal(userRef, GSN_FSREADREF, signal, 3, JBB);
203 #endif
204 }
205
206 void
execFSSYNCREQ(Signal * signal)207 VoidFs::execFSSYNCREQ(Signal * signal)
208 {
209 jamEntry();
210
211 BlockReference userRef = signal->theData[1];
212 const UintR userPointer = signal->theData[2];
213
214 signal->theData[0] = userPointer;
215 sendSignal(userRef, GSN_FSSYNCCONF, signal, 1, JBB);
216
217 return;
218 }
219
220 void
execFSAPPENDREQ(Signal * signal)221 VoidFs::execFSAPPENDREQ(Signal * signal)
222 {
223 const FsAppendReq * const fsReq = (FsAppendReq *)&signal->theData[0];
224 const UintR userPointer = fsReq->userPointer;
225 const BlockReference userRef = fsReq->userReference;
226 const Uint32 size = fsReq->size;
227
228 signal->theData[0] = userPointer;
229 signal->theData[1] = size << 2;
230 sendSignal(userRef, GSN_FSAPPENDCONF, signal, 2, JBB);
231 }
232
233 /*
234 * PR0: File Pointer DR0: User reference DR1: User Pointer
235 */
236 void
execFSSUSPENDORD(Signal * signal)237 VoidFs::execFSSUSPENDORD(Signal * signal)
238 {
239 jamEntry();
240 }
241
242 void
execDUMP_STATE_ORD(Signal * signal)243 VoidFs::execDUMP_STATE_ORD(Signal* signal)
244 {
245 }//VoidFs::execDUMP_STATE_ORD()
246
247
248
249 BLOCK_FUNCTIONS(VoidFs)
250
251