1 /*
2 Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
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
VoidFs(Block_context & ctx)42 VoidFs::VoidFs(Block_context & ctx) :
43 Ndbfs(ctx)
44 {
45 // Set received signals
46 addRecSignal(GSN_SEND_PACKED, &VoidFs::execSEND_PACKED, true);
47 addRecSignal(GSN_READ_CONFIG_REQ, &VoidFs::execREAD_CONFIG_REQ, true);
48 addRecSignal(GSN_DUMP_STATE_ORD, &VoidFs::execDUMP_STATE_ORD, true);
49 addRecSignal(GSN_STTOR, &VoidFs::execSTTOR, true);
50 addRecSignal(GSN_FSOPENREQ, &VoidFs::execFSOPENREQ, true);
51 addRecSignal(GSN_FSCLOSEREQ, &VoidFs::execFSCLOSEREQ, true);
52 addRecSignal(GSN_FSWRITEREQ, &VoidFs::execFSWRITEREQ, true);
53 addRecSignal(GSN_FSREADREQ, &VoidFs::execFSREADREQ, true);
54 addRecSignal(GSN_FSSYNCREQ, &VoidFs::execFSSYNCREQ, true);
55 addRecSignal(GSN_FSAPPENDREQ, &VoidFs::execFSAPPENDREQ, true);
56 addRecSignal(GSN_FSREMOVEREQ, &VoidFs::execFSREMOVEREQ, true);
57 addRecSignal(GSN_FSSUSPENDORD, &VoidFs::execFSSUSPENDORD, true);
58 // Set send signals
59 }
60
~VoidFs()61 VoidFs::~VoidFs()
62 {
63 }
64
65 void
execREAD_CONFIG_REQ(Signal * signal)66 VoidFs::execREAD_CONFIG_REQ(Signal* signal)
67 {
68 const ReadConfigReq * req = (ReadConfigReq*)signal->getDataPtr();
69
70 Uint32 ref = req->senderRef;
71 Uint32 senderData = req->senderData;
72
73 ReadConfigConf * conf = (ReadConfigConf*)signal->getDataPtrSend();
74 conf->senderRef = reference();
75 conf->senderData = senderData;
76 sendSignal(ref, GSN_READ_CONFIG_CONF, signal,
77 ReadConfigConf::SignalLength, JBB);
78
79 signal->theData[0] = NdbfsContinueB::ZSCAN_MEMORYCHANNEL_10MS_DELAY;
80 sendSignalWithDelay(reference(), GSN_CONTINUEB, signal, 10, 1);
81 }
82
83 void
execSTTOR(Signal * signal)84 VoidFs::execSTTOR(Signal* signal)
85 {
86 jamEntry();
87
88 if(signal->theData[1] == 0){ // StartPhase 0
89 jam();
90 signal->theData[3] = 255;
91 sendSignal(NDBCNTR_REF, GSN_STTORRY, signal, 4, JBB);
92 return;
93 }
94 ndbrequire(0);
95 }
96
97 void
execSEND_PACKED(Signal * signal)98 VoidFs::execSEND_PACKED(Signal* signal)
99 {
100 jamEntry();
101 if (scanningInProgress == false && scanIPC(signal))
102 {
103 jam();
104 scanningInProgress = true;
105 signal->theData[0] = NdbfsContinueB::ZSCAN_MEMORYCHANNEL_NO_DELAY;
106 sendSignal(reference(), GSN_CONTINUEB, signal, 1, JBB);
107 }
108 }
109
110 void
execFSOPENREQ(Signal * signal)111 VoidFs::execFSOPENREQ(Signal* signal)
112 {
113 jamEntry();
114 const FsOpenReq * const fsOpenReq = (FsOpenReq *)&signal->theData[0];
115 const BlockReference userRef = fsOpenReq->userReference;
116 const Uint32 userPointer = fsOpenReq->userPointer;
117
118 Uint32 flags = fsOpenReq->fileFlags;
119 if(flags == FsOpenReq::OM_READONLY){
120 // Initialise FsRef signal
121 FsRef * const fsRef = (FsRef *)&signal->theData[0];
122 fsRef->userPointer = userPointer;
123 fsRef->errorCode = FsRef::fsErrFileDoesNotExist;
124 fsRef->osErrorCode = ~0;
125 sendSignal(userRef, GSN_FSOPENREF, signal, 3, JBB);
126 return;
127 }
128
129 if(flags & FsOpenReq::OM_WRITEONLY || flags & FsOpenReq::OM_READWRITE){
130 signal->theData[0] = userPointer;
131 signal->theData[1] = c_maxFileNo++;
132 sendSignal(userRef, GSN_FSOPENCONF, signal, 2, JBB);
133 }
134 }
135
136 void
execFSREMOVEREQ(Signal * signal)137 VoidFs::execFSREMOVEREQ(Signal* signal)
138 {
139 jamEntry();
140 const FsRemoveReq * const req = (FsRemoveReq *)signal->getDataPtr();
141 const Uint32 userRef = req->userReference;
142 const Uint32 userPointer = req->userPointer;
143
144 signal->theData[0] = userPointer;
145 sendSignal(userRef, GSN_FSREMOVECONF, signal, 1, JBB);
146 }
147
148 /*
149 * PR0: File Pointer DR0: User reference DR1: User Pointer DR2: Flag bit 0= 1
150 * remove file
151 */
152 void
execFSCLOSEREQ(Signal * signal)153 VoidFs::execFSCLOSEREQ(Signal * signal)
154 {
155 jamEntry();
156
157 const FsCloseReq * const req = (FsCloseReq *)signal->getDataPtr();
158 const Uint32 userRef = req->userReference;
159 const Uint32 userPointer = req->userPointer;
160
161 signal->theData[0] = userPointer;
162 sendSignal(userRef, GSN_FSCLOSECONF, signal, 1, JBB);
163 }
164
165 void
execFSWRITEREQ(Signal * signal)166 VoidFs::execFSWRITEREQ(Signal* signal)
167 {
168 jamEntry();
169 const FsReadWriteReq * const req = (FsReadWriteReq *)signal->getDataPtr();
170 const Uint32 userRef = req->userReference;
171 const Uint32 userPointer = req->userPointer;
172
173 SectionHandle handle(this, signal);
174 releaseSections(handle);
175
176 signal->theData[0] = userPointer;
177 sendSignal(userRef, GSN_FSWRITECONF, signal, 1, JBB);
178 }
179
180 void
execFSREADREQ(Signal * signal)181 VoidFs::execFSREADREQ(Signal* signal)
182 {
183 jamEntry();
184
185 const FsReadWriteReq * const req = (FsReadWriteReq *)signal->getDataPtr();
186 const Uint32 userRef = req->userReference;
187 const Uint32 userPointer = req->userPointer;
188
189 SectionHandle handle(this, signal);
190 releaseSections(handle);
191
192 signal->theData[0] = userPointer;
193 sendSignal(userRef, GSN_FSREADCONF, signal, 1, JBB);
194 #if 0
195 FsRef * const fsRef = (FsRef *)&signal->theData[0];
196 fsRef->userPointer = userPointer;
197 fsRef->errorCode = FsRef::fsErrEnvironmentError;
198 fsRef->osErrorCode = ~0; // Indicate local error
199 sendSignal(userRef, GSN_FSREADREF, signal, 3, JBB);
200 #endif
201 }
202
203 void
execFSSYNCREQ(Signal * signal)204 VoidFs::execFSSYNCREQ(Signal * signal)
205 {
206 jamEntry();
207
208 BlockReference userRef = signal->theData[1];
209 const UintR userPointer = signal->theData[2];
210
211 signal->theData[0] = userPointer;
212 sendSignal(userRef, GSN_FSSYNCCONF, signal, 1, JBB);
213
214 return;
215 }
216
217 void
execFSAPPENDREQ(Signal * signal)218 VoidFs::execFSAPPENDREQ(Signal * signal)
219 {
220 const FsAppendReq * const fsReq = (FsAppendReq *)&signal->theData[0];
221 const UintR userPointer = fsReq->userPointer;
222 const BlockReference userRef = fsReq->userReference;
223 const Uint32 size = fsReq->size;
224
225 signal->theData[0] = userPointer;
226 signal->theData[1] = size << 2;
227 sendSignal(userRef, GSN_FSAPPENDCONF, signal, 2, JBB);
228 }
229
230 /*
231 * PR0: File Pointer DR0: User reference DR1: User Pointer
232 */
233 void
execFSSUSPENDORD(Signal * signal)234 VoidFs::execFSSUSPENDORD(Signal * signal)
235 {
236 jamEntry();
237 }
238
239 void
execDUMP_STATE_ORD(Signal * signal)240 VoidFs::execDUMP_STATE_ORD(Signal* signal)
241 {
242 }//VoidFs::execDUMP_STATE_ORD()
243
244
245
246 BLOCK_FUNCTIONS(VoidFs)
247
248