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