Whamcloud - gitweb
LUDOC-297 protocol: Update protocol document
[doc/protocol.git] / struct_ptlrpc_body.txt
1 Ptlrpc_body - The Lustre RPC Descriptor
2 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3 [[struct-ptlrpc-body]]
4
5 Every Lustre message starts with a header (See <<struct-lustre-msg>>)
6 describing a few generic details about the RPC, the most important of
7 which is the number and sizes of additional "buffers" that will
8 follow. The buffers just organize subsections of the RPC, and each
9 comprises a set of fields. The fields of a buffer are presented here
10 as 'struct' definitions because that is how they are actually
11 organized, and it provides a convenient way to refer to groups of
12 fields that appear together in many different RPCs. The first buffer
13 in every RPC is given by the 'ptlrpc_body' structure, also known as
14 the RPC descriptor. This descriptor identifies the type of the RPC via
15 a Lustre operation code. The value of that 'opcode', as well as
16 whether it is an RPC 'request' or 'reply', determines what other
17 buffers will be in the message following the descriptor.
18
19 [source,c]
20 ----
21 struct ptlrpc_body {
22     struct lustre_handle pb_handle;
23     __u32 pb_type;
24     __u32 pb_version;
25     __u32 pb_opc;
26     __u32 pb_status;
27     __u64 pb_last_xid;
28     __u64 pb_last_seen;
29     __u64 pb_last_committed;
30     __u64 pb_transno;
31     __u32 pb_flags;
32     __u32 pb_op_flags;
33     __u32 pb_conn_cnt;
34     __u32 pb_timeout;
35     __u32 pb_service_time;
36     __u32 pb_limit;
37     __u64 pb_slv;
38     __u64 pb_pre_versions[4];
39     __u64 pb_padding[4];
40     char  pb_jobid[32];
41 };
42 ----
43
44 include::struct_lustre_handle.txt[]
45
46 The 'pb_handle' field of the RPC descriptor is a 'lustre_handle'. In a
47 connection request RPC (MGS_CONNECT, MDS_CONNECT, or OST_CONNECT),
48 sent by a client to a target, 'pb_handle' is 0. In the reply to that
49 connection request 'pb_handle' is set to a new 'lustre_handle' that
50 uniquely identifies the target (indeed, it uniquely identifies the
51 'export', since each client gets a unique 'lustre_handle' for a given
52 target). Subsequent request messages sent this client to this target
53 will use that 'lustre_handle' (the 'pb_handle' field will be set to
54 that value) to to gain access to their shared state. In subsequent RPC
55 reply messages (after teh *_CONNECT reply) the 'pb_handle' field is
56 0. The 'lustre_handle' is persistent across client reconnects to the
57 same instance of the server, but if the client unmounts the filesystem
58 or is evicted then it must re-connect as a new client, with a new
59 'lustre_handle'.
60
61 The 'pb_type' is PTL_RPC_MSG_REQUEST in messages when they are
62 initiated, it is PTL_RPC_MSG_REPLY in a reply, and it is
63 PTL_RPC_MSG_ERR in a reply to convey that a message was received that
64 could not be interpreted, that is, if it was corrupt or
65 incomplete. The encoding of those type values is given by:
66
67 [source,c]
68 ----
69 #define PTL_RPC_MSG_REQUEST 4711
70 #define PTL_RPC_MSG_ERR     4712
71 #define PTL_RPC_MSG_REPLY   4713
72 ----
73 The 'pb_type' = PTL_RPC_MSG_ERR is only for message handling errors.
74 This may be a message that failed to be interpreted as an actual
75 message, or it may indicate some more general problem with the
76 connection between the client and the target. Note that other errors,
77 such as those that emerge from processing the actual message content,
78 do not use the PTL_RPC_MSG_ERR type.
79
80 The 'pb_status' field provides an error return code for the RPC. When
81 'pb_type' = PTL_RPC_MSG_ERR the 'pb_status' will also be set to one of
82 the following message handling errors:
83
84 .'pb_type' = PTL_RPC_MSG_ERR status return codes
85 [options="header"]
86 |====
87 | pb_status  | if
88 | -ENOMEM    | No memory for reply buffer
89 | -ENOTSUPP  | Invalid opcode
90 | -EINVAL    | Bad magic or version
91 | -EPROTO    | Request is malformed or cannot be
92                processed in current context
93 |====
94
95 A PTL_RPC_MSG_ERR message does not need to allocate memory, so it
96 should normally be sent as a reply even if there is not enough memory
97 to allocate the normal reply buffer.
98
99 In most cases there is a reply with 'pb_type' = PTL_RPC_MSG_REPLY,
100 indicating that the request was processed, but it may still have
101 'pb_status' set to a non-zero value to indicate that the request
102 encountered an error during processing (see below).  This may indicate
103 something very specific to the particular RPC, but it may also be a
104 very general sort of error. Those that are specific to particular RPCs
105 will be documented with the respective RPCs, and those that are more
106 generic are listed here:
107
108 .'pb_type' = PTL_RPC_MSG_REPLY status return codes
109 [options="header"]
110 |====
111 | pb_status    | meaning
112 | -ENOTCONN    | Client is not connected to the
113                  target, typically meaning the
114                  server was restarted or the
115                  client was evicted, and the
116                  client needs to reconnect.
117 | -EINPROGRESS | The request cannot be processed
118                  currently due to some other
119                  factor, such as during initial
120                  mount, a delay contacting the
121                  quota master during a write, or
122                  LFSCK rebuilding the OI table,
123                  but the client should continue
124                  to retry after a delay until
125                  interrupted or successful.  This
126                  avoids blocking the server
127                  threads with client requests
128                  that cannot currently be
129                  processed, but other requests
130                  might be processed in the
131                  meantime.
132 | -ESHUTDOWN   | The server is being stopped and
133                  no new connections are allowed.
134 |====
135
136 A PtlRPC reply message with 'pb_status' = -ENOTCONN can be returned
137 for any type of PtlRPC request message other than one of MGS_CONNECT,
138 MDS_CONNECT, or OST_CONNECT (those RPCs establish connections).
139 -ENOTCONN indicates that the server, the recipient of the request
140 message, does not have a valid connection for the client. This can
141 come about if a client has been evicted, or if, after a server
142 reboots, the client failed to reestablish its connection during
143 recovery. Establishing a connection is discussed more fully in
144 <<connection>>, eviction in <<eviction>>, and recovery in
145 <<recovery>>.
146
147 The 'pb_version' identifies the version of the Lustre protocol and is
148 derived from the following constants. The lower two bytes give the
149 version of PtlRPC being employed in the message, and the upper two
150 bytes encode the role of the host for the service being
151 requested. That role is one of OBD, MDS, OST, DLM, LOG, or MGS.
152
153 [source,c]
154 ----
155 #define PTLRPC_MSG_VERSION  0x00000003
156 #define LUSTRE_VERSION_MASK 0xffff0000
157 #define LUSTRE_OBD_VERSION  0x00010000
158 #define LUSTRE_MDS_VERSION  0x00020000
159 #define LUSTRE_OST_VERSION  0x00030000
160 #define LUSTRE_DLM_VERSION  0x00040000
161 #define LUSTRE_LOG_VERSION  0x00050000
162 #define LUSTRE_MGS_VERSION  0x00060000
163 ----
164
165 The 'pb_opc' value (operation code) gives the actual Lustre operation
166 that is the subject of this message. For example, MDS_CONNECT is a
167 Lustre operation (number 38). The following list gives the name used
168 and the value for each operation.
169
170 .Lustre Operation Codes ("opcodes")
171 [options="header"]
172 |====
173 | name                                   | 'pb_opc'
174 | OST_REPLY                              |  0
175 | OST_GETATTR                            |  1
176 | <<ost-setattr-rpc>>                    |  2
177 | OST_READ                               |  3
178 | OST_WRITE                              |  4
179 | OST_CREATE                             |  5
180 | OST_DESTROY                            |  6
181 | OST_GET_INFO                           |  7
182 | <<ost-connect-rpc>>                    |  8
183 | <<ost-disconnect-rpc>>                 |  9
184 | OST_PUNCH                              | 10
185 | OST_OPEN                               | 11
186 | OST_CLOSE                              | 12
187 | OST_STATFS                             | 13
188 | OST_SYNC                               | 16
189 | OST_SET_INFO                           | 17
190 | OST_QUOTACHECK                         | 18
191 | OST_QUOTACTL                           | 19
192 | OST_QUOTA_ADJUST_QUNIT                 | 20
193 |                                        |
194 | <<mds-getattr-rpc>>                    | 33
195 | MDS_GETATTR_NAME                       | 34
196 | MDS_CLOSE                              | 35
197 | MDS_REINT                              | 36
198 | MDS_READPAGE                           | 37
199 | <<mds-connect-rpc>>                    | 38
200 | <<mds-disconnect-rpc>>                 | 39
201 | <<mds-getstatus-rpc>>                  | 40
202 | <mds-statfs-rpc>>                      | 41
203 | MDS_PIN                                | 42
204 | MDS_UNPIN                              | 43
205 | MDS_SYNC                               | 44
206 | MDS_DONE_WRITING                       | 45
207 | MDS_SET_INFO                           | 46
208 | MDS_QUOTACHECK                         | 47
209 | MDS_QUOTACTL                           | 48
210 | <<mds-getxattr-rpc>>                   | 49
211 | MDS_SETXATTR                           | 50
212 | MDS_WRITEPAGE                          | 51
213 | MDS_IS_SUBDIR                          | 52
214 | MDS_GET_INFO                           | 53
215 | MDS_HSM_STATE_GET                      | 54
216 | MDS_HSM_STATE_SET                      | 55
217 | MDS_HSM_ACTION                         | 56
218 | MDS_HSM_PROGRESS                       | 57
219 | MDS_HSM_REQUEST                        | 58
220 | MDS_HSM_CT_REGISTER                    | 59
221 | MDS_HSM_CT_UNREGISTER                  | 60
222 | MDS_SWAP_LAYOUTS                       | 61
223 |                                        |
224 | <<ldlm-enqueue-rpc>>                   | 101
225 | LDLM_CONVERT                           | 102
226 | <<ldlm-cancel-rpc>>                    | 103
227 | <<ldlm-bl-callback-rpc>>               | 104
228 | <<ldlm-cp-callback-rpc>>               | 105
229 | LDLM_GL_CALLBACK                       | 106
230 | LDLM_SET_INFO                          | 107
231 |                                        |
232 | <<mgs-connect-rpc>>                    | 250
233 | <<mgs-disconnect-rpc>>                 | 251
234 | MGS_EXCEPTION                          | 252
235 | MGS_TARGET_REG                         | 253
236 | MGS_TARGET_DEL                         | 254
237 | MGS_SET_INFO                           | 255
238 | <<mgs-config-read-rpc>>                | 256
239 |                                        |
240 | OBD_PING                               | 400
241 | OBD_LOG_CANCEL                         | 401
242 | OBD_QC_CALLBACK                        | 402
243 | OBD_IDX_READ                           | 403
244 |                                        |
245 | <<llog-origin-handle-create-rpc>>      | 501
246 | <<llog-origin-handle-next-block-rpc>>  | 502
247 | <<llog-origin-handle-read-header-rpc>> | 503
248 | LLOG_ORIGIN_HANDLE_WRITE_REC           | 504
249 | LLOG_ORIGIN_HANDLE_CLOSE               | 505
250 | LLOG_ORIGIN_CONNECT                    | 506
251 | LLOG_ORIGIN_HANDLE_PREV_BLOCK          | 508
252 | LLOG_ORIGIN_HANDLE_DESTROY             | 509
253 |                                        |
254 | QUOTA_DQACQ                            | 601
255 | QUOTA_DQREL                            | 602
256 |                                        |
257 | SEQ_QUERY                              | 700
258 |                                        |
259 | SEC_CTX_INIT                           | 801
260 | SEC_CTX_INIT_CONT                      | 802
261 | SEC_CTX_FINI                           | 803
262 |                                        |
263 | FLD_QUERY                              | 900
264 | FLD_READ                               | 901
265 |                                        |
266 | UPDATE_OBJ                             | 1000
267 |====
268
269 The 'pb_status' field was already mentioned above in conjuction with
270 the 'pb_type' field in replies.  In a request message 'pb_status' is
271 set to the 'pid' of the process making the request. In a reply
272 message, a zero indicates that the service successfully initiated the
273 requested operation. When an error is being reported the value will
274 encode a standard Linux kernel (POSIX) error code as initially
275 defined for the i386/x86_64 architecture. The 'pb_status' value is
276 returned as a negative number. For example, a permissions error
277 would be indicated as -EPERM.
278
279 'pb_last_xid' and 'pb_last_seen' are not used.
280
281 The 'pb_last_committed' value is always zero in a request. In a reply
282 it is the highest transaction number that has been committed to
283 storage. See <<transno>>. This field is set in any kind of reply
284 message including pings and non-modifying transactions. If
285 'pb_last_committed' is larger than, or equal to, any of the client's
286 uncommitted requests (see 'pb_transno' below) then the server is
287 confirming those requests have been committed to stable storage. At
288 that point the client may free those request structures as they will
289 no longer be necessary for replay during recovery.
290
291 The 'pb_transno' value is zero in a new request. It is also zero for
292 replies to operations that do not modify the file system. For replies
293 to operations that do modify the file system it is the target-unique,
294 server-assigned transaction number for the client request.  See
295 <<transno>>. Upon receipt of the reply, the client copies this
296 transaction number from 'pb_transno' of the reply to 'pb_transno' of
297 the saved request.  If 'pb_transno' is larger than 'pb_last_commited'
298 (above) then the request has been processed at the target but is not
299 yet committed to stable storage.  The client must save the request for
300 later resend to the server in case the target fails before the
301 modification can be committed to disk. If the request has to be
302 replayed it will include the transaction number.
303
304 The 'pb_flags' value governs the client state machine. Currently, only
305 the least significant two bytes are used. The field encodes state
306 according to the following values:
307
308 [source,c]
309 ----
310 #define MSG_GEN_FLAG_MASK     0x0000ffff
311 #define MSG_LAST_REPLAY           0x0001
312 #define MSG_RESENT                0x0002
313 #define MSG_REPLAY                0x0004
314 #define MSG_DELAY_REPLAY          0x0010
315 #define MSG_VERSION_REPLAY        0x0020
316 #define MSG_REQ_REPLAY_DONE       0x0040
317 #define MSG_LOCK_REPLAY_DONE      0x0080
318 ----
319
320 MGS_LAST_REPLAY is currently unused. It had been used to indicate that
321 this is the last RPC request to be replayed by this client during
322 recovery.  MGS_LAST_REPLAY has been replaced by MSG_REQ_REPLAY_DONE
323 and MSG_LOCK_REPLAY_DONE.
324
325 MGS_RESENT is set when this RPC request is being resent because no
326 reply was received.
327
328 MGS_REPLAY indicates this RPC request is being replayed after the
329 client received a reply but before it was committed to storage.  The
330 'pb_transno' field holds the server-assigned transaction number.
331
332 MGS_DELAY_REPLAY is currently unused.
333
334 MSG_VERSION_REPLAY indicates that a replayed request has the
335 'pb_pre_versions' array filled with the prior object versions and can
336 be used with Version Based Recovery.
337
338 MSG_LOCK_REPLAY_DONE indicates the client has completed lock replay,
339 and is ready to finish recovery.
340
341 The 'pb_op_flags' values are specific to a particular 'pb_opc', but
342 are currently only used by the *_CONNECT RPCs.The 'pb_op_flags' value
343 for connect operations governs the client connection status state
344 machine.
345
346 [source,c]
347 ----
348 #define MSG_CONNECT_RECOVERING  0x00000001
349 #define MSG_CONNECT_RECONNECT   0x00000002
350 #define MSG_CONNECT_REPLAYABLE  0x00000004
351 #define MSG_CONNECT_LIBCLIENT   0x00000010
352 #define MSG_CONNECT_INITIAL     0x00000020
353 #define MSG_CONNECT_ASYNC       0x00000040
354 #define MSG_CONNECT_NEXT_VER    0x00000080
355 #define MSG_CONNECT_TRANSNO     0x00000100
356 ----
357
358 MSG_CONNECT_RECOVERING indicates the server is in recovery
359
360 MSG_CONNECT_RECONNECT indicates the client is reconnecting after
361 non-responsiveness from the server.
362
363 MSG_CONNECT_REPLAYABLE indicates the server connection supports RPC
364 replay (only OSTs support non-recoverable connections, but that is not
365 the default).
366
367 The MSG_CONNECT_LIBCLIENT is for the a 'liblustre' client. It is
368 currently unused.
369
370 The client sends MSG_CONNECT_INITIAL the first time the client is
371 connecting to the server.  MSG_CONNECT_INITIAL connections are not
372 allowed during server recovery.
373
374 MSG_CONNECT_ASYNC is currently unused.
375
376 MSG_CONNECT_NEXT_VER indicates that the client can understand the next
377 higher protocol version in addition to the currently used protocol, and
378 the server can reply to the connect with that higher RPC version if
379 it is supported, otherwise it will reply with the
380 same RPC version as the request.  This allows RPC protocol versions to
381 be negotiated during a transition period (e.g. upgrade from RPC from
382 LUSTRE_MSG_MAGIC_V1 to LUSTRE_MSG_MAGIC_V2).
383
384 In normal operation an initial request to connect will set
385 'pb_op_flags' to MSG_CONNECT_INITIAL (in some earlier versions
386 MSG_CONNECT_NEXT_VER was mistakenly included, though it did no
387 harm). The reply to that connection request (and all other,
388 non-connect, requests and replies) will set 'pb_op_flags' to 0.
389
390 The 'pb_conn_cnt' (connection count) value in a request message
391 reports the client's "era", which is part of the client and server's
392 shared state. The value of the era is initialized to 1 when it is
393 first connected to the target. Each subsequent connection (after an
394 eviction) increments the era for the client. Since the 'pb_conn_cnt'
395 reflects the client's era at the time the message was composed the
396 server can use this value to discard late-arriving messages requesting
397 operations on out-of-date shared state.
398
399 The 'pb_timeout' value in a request indicates how long (in seconds)
400 the requester plans to wait before timing out the operation. That is,
401 the corresponding reply for this message should arrive within this
402 time frame. The service may extend this time frame via an "early
403 reply", which is a reply to this message that notifies the requester
404 that it should extend its timeout interval by the value of the
405 'pb_timeout' field in the reply. The "early reply" does not indicate
406 the operation has actually been initiated.  Clients maintain multiple
407 request queues, called "portals", and each type of operation is
408 assigned to one of these queues. There is a timeout value associated
409 with each queue, and the timeout update affects all the messages
410 associated with the given queue, not just the specific message that
411 initiated the request. Finally, in a reply message (one that does
412 indicate the operation has been initiated) the timeout value updates
413 the timeout interval for the queue.
414
415 The 'pb_service_time' value is zero in a request. In a reply it
416 indicates how long this particular operation actually took from the
417 time it first arrived in the request queue (at the service) to the
418 time the server replied. Note that the client can use this value and
419 the local elapsed time for the operation to calculate network latency.
420
421 The 'pb_limit' value is zero in a request. In a reply it is a value
422 sent from a lock service to a client to set the maximum number of
423 locks available to the client. When dynamic lock LRU's are enabled
424 this allows for managing the size of the LRU.
425
426 The 'pb_slv' value is zero in a request. On a DLM service, the "server
427 lock volume" is a value that characterizes (estimates) the amount of
428 traffic, or load, on that lock service. It is calculated as the
429 product of the number of locks and their age. In a reply, the 'pb_slv'
430 value indicates to the client the available share of the total lock
431 load on the server that the client is allowed to consume. The client
432 is then responsible for reducing its number or (or age) of locks to
433 stay within this limit.
434
435 The array of 'pb_pre_versions' values has four entries. They are
436 always zero in a new request message. They are also zero in replies to
437 operations that do not modify the file system. For an operation that
438 does modify the file system, the reply encodes the most recent
439 transaction numbers for the objects modified by this operation, and
440 the 'pb_pre_versions' values are copied into the original request when
441 the reply arrives. If the request needs to be replayed then the
442 updated 'pb_pre_versions' values accompany the replayed request.
443
444 'pb_padding' is reserved for future use.
445
446 The 'pb_jobid' (string) value gives a unique identifier associated
447 with the process on behalf of which this message was generated. The
448 identifier is assigned to the user process by a job scheduler, if any.