staging/lustre: Replace sun.com GPLv2 URL with gnu.org one.
[deliverable/linux.git] / drivers / staging / lustre / lustre / include / lustre_net.h
CommitLineData
d7e09d03
PT
1/*
2 * GPL HEADER START
3 *
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
15 *
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
6a5b99a4 18 * http://www.gnu.org/licenses/gpl-2.0.html
d7e09d03 19 *
d7e09d03
PT
20 * GPL HEADER END
21 */
22/*
23 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Use is subject to license terms.
25 *
1dc563a6 26 * Copyright (c) 2010, 2015, Intel Corporation.
d7e09d03
PT
27 */
28/*
29 * This file is part of Lustre, http://www.lustre.org/
30 * Lustre is a trademark of Sun Microsystems, Inc.
31 */
32/** \defgroup PtlRPC Portal RPC and networking module.
33 *
34 * PortalRPC is the layer used by rest of lustre code to achieve network
35 * communications: establish connections with corresponding export and import
36 * states, listen for a service, send and receive RPCs.
37 * PortalRPC also includes base recovery framework: packet resending and
38 * replaying, reconnections, pinger.
39 *
40 * PortalRPC utilizes LNet as its transport layer.
41 *
42 * @{
43 */
44
d7e09d03
PT
45#ifndef _LUSTRE_NET_H
46#define _LUSTRE_NET_H
47
48/** \defgroup net net
49 *
50 * @{
51 */
52
9fdaf8c0 53#include "../../include/linux/libcfs/libcfs.h"
bbf00c3d
JS
54#include "../../include/linux/lnet/nidstr.h"
55#include "../../include/linux/lnet/api.h"
1accaadf
GKH
56#include "lustre/lustre_idl.h"
57#include "lustre_ha.h"
58#include "lustre_sec.h"
59#include "lustre_import.h"
60#include "lprocfs_status.h"
61#include "lu_object.h"
62#include "lustre_req_layout.h"
d7e09d03 63
1accaadf
GKH
64#include "obd_support.h"
65#include "lustre_ver.h"
d7e09d03
PT
66
67/* MD flags we _always_ use */
68#define PTLRPC_MD_OPTIONS 0
69
70/**
71 * Max # of bulk operations in one request.
72 * In order for the client and server to properly negotiate the maximum
73 * possible transfer size, PTLRPC_BULK_OPS_COUNT must be a power-of-two
74 * value. The client is free to limit the actual RPC size for any bulk
c56e256d
OD
75 * transfer via cl_max_pages_per_rpc to some non-power-of-two value.
76 */
d7e09d03
PT
77#define PTLRPC_BULK_OPS_BITS 2
78#define PTLRPC_BULK_OPS_COUNT (1U << PTLRPC_BULK_OPS_BITS)
79/**
80 * PTLRPC_BULK_OPS_MASK is for the convenience of the client only, and
81 * should not be used on the server at all. Otherwise, it imposes a
82 * protocol limitation on the maximum RPC size that can be used by any
83 * RPC sent to that server in the future. Instead, the server should
84 * use the negotiated per-client ocd_brw_size to determine the bulk
c56e256d
OD
85 * RPC count.
86 */
d7e09d03
PT
87#define PTLRPC_BULK_OPS_MASK (~((__u64)PTLRPC_BULK_OPS_COUNT - 1))
88
89/**
90 * Define maxima for bulk I/O.
91 *
92 * A single PTLRPC BRW request is sent via up to PTLRPC_BULK_OPS_COUNT
93 * of LNET_MTU sized RDMA transfers. Clients and servers negotiate the
94 * currently supported maximum between peers at connect via ocd_brw_size.
95 */
96#define PTLRPC_MAX_BRW_BITS (LNET_MTU_BITS + PTLRPC_BULK_OPS_BITS)
97#define PTLRPC_MAX_BRW_SIZE (1 << PTLRPC_MAX_BRW_BITS)
09cbfeaf 98#define PTLRPC_MAX_BRW_PAGES (PTLRPC_MAX_BRW_SIZE >> PAGE_SHIFT)
d7e09d03
PT
99
100#define ONE_MB_BRW_SIZE (1 << LNET_MTU_BITS)
101#define MD_MAX_BRW_SIZE (1 << LNET_MTU_BITS)
09cbfeaf 102#define MD_MAX_BRW_PAGES (MD_MAX_BRW_SIZE >> PAGE_SHIFT)
d7e09d03 103#define DT_MAX_BRW_SIZE PTLRPC_MAX_BRW_SIZE
09cbfeaf 104#define DT_MAX_BRW_PAGES (DT_MAX_BRW_SIZE >> PAGE_SHIFT)
d7e09d03
PT
105#define OFD_MAX_BRW_SIZE (1 << LNET_MTU_BITS)
106
107/* When PAGE_SIZE is a constant, we can check our arithmetic here with cpp! */
108# if ((PTLRPC_MAX_BRW_PAGES & (PTLRPC_MAX_BRW_PAGES - 1)) != 0)
109# error "PTLRPC_MAX_BRW_PAGES isn't a power of two"
110# endif
ea1754a0
KS
111# if (PTLRPC_MAX_BRW_SIZE != (PTLRPC_MAX_BRW_PAGES * PAGE_SIZE))
112# error "PTLRPC_MAX_BRW_SIZE isn't PTLRPC_MAX_BRW_PAGES * PAGE_SIZE"
d7e09d03
PT
113# endif
114# if (PTLRPC_MAX_BRW_SIZE > LNET_MTU * PTLRPC_BULK_OPS_COUNT)
115# error "PTLRPC_MAX_BRW_SIZE too big"
116# endif
117# if (PTLRPC_MAX_BRW_PAGES > LNET_MAX_IOV * PTLRPC_BULK_OPS_COUNT)
118# error "PTLRPC_MAX_BRW_PAGES too big"
119# endif
120
121#define PTLRPC_NTHRS_INIT 2
122
123/**
124 * Buffer Constants
125 *
126 * Constants determine how memory is used to buffer incoming service requests.
127 *
128 * ?_NBUFS # buffers to allocate when growing the pool
129 * ?_BUFSIZE # bytes in a single request buffer
130 * ?_MAXREQSIZE # maximum request service will receive
131 *
132 * When fewer than ?_NBUFS/2 buffers are posted for receive, another chunk
133 * of ?_NBUFS is added to the pool.
134 *
135 * Messages larger than ?_MAXREQSIZE are dropped. Request buffers are
136 * considered full when less than ?_MAXREQSIZE is left in them.
137 */
138/**
139 * Thread Constants
140 *
141 * Constants determine how threads are created for ptlrpc service.
142 *
143 * ?_NTHRS_INIT # threads to create for each service partition on
144 * initializing. If it's non-affinity service and
145 * there is only one partition, it's the overall #
146 * threads for the service while initializing.
147 * ?_NTHRS_BASE # threads should be created at least for each
148 * ptlrpc partition to keep the service healthy.
149 * It's the low-water mark of threads upper-limit
150 * for each partition.
151 * ?_THR_FACTOR # threads can be added on threads upper-limit for
152 * each CPU core. This factor is only for reference,
153 * we might decrease value of factor if number of cores
154 * per CPT is above a limit.
155 * ?_NTHRS_MAX # overall threads can be created for a service,
156 * it's a soft limit because if service is running
157 * on machine with hundreds of cores and tens of
158 * CPU partitions, we need to guarantee each partition
159 * has ?_NTHRS_BASE threads, which means total threads
160 * will be ?_NTHRS_BASE * number_of_cpts which can
161 * exceed ?_NTHRS_MAX.
162 *
163 * Examples
164 *
165 * #define MDS_NTHRS_INIT 2
166 * #define MDS_NTHRS_BASE 64
167 * #define MDS_NTHRS_FACTOR 8
168 * #define MDS_NTHRS_MAX 1024
169 *
170 * Example 1):
171 * ---------------------------------------------------------------------
172 * Server(A) has 16 cores, user configured it to 4 partitions so each
173 * partition has 4 cores, then actual number of service threads on each
174 * partition is:
175 * MDS_NTHRS_BASE(64) + cores(4) * MDS_NTHRS_FACTOR(8) = 96
176 *
177 * Total number of threads for the service is:
178 * 96 * partitions(4) = 384
179 *
180 * Example 2):
181 * ---------------------------------------------------------------------
182 * Server(B) has 32 cores, user configured it to 4 partitions so each
183 * partition has 8 cores, then actual number of service threads on each
184 * partition is:
185 * MDS_NTHRS_BASE(64) + cores(8) * MDS_NTHRS_FACTOR(8) = 128
186 *
187 * Total number of threads for the service is:
188 * 128 * partitions(4) = 512
189 *
190 * Example 3):
191 * ---------------------------------------------------------------------
192 * Server(B) has 96 cores, user configured it to 8 partitions so each
193 * partition has 12 cores, then actual number of service threads on each
194 * partition is:
195 * MDS_NTHRS_BASE(64) + cores(12) * MDS_NTHRS_FACTOR(8) = 160
196 *
197 * Total number of threads for the service is:
198 * 160 * partitions(8) = 1280
199 *
200 * However, it's above the soft limit MDS_NTHRS_MAX, so we choose this number
201 * as upper limit of threads number for each partition:
202 * MDS_NTHRS_MAX(1024) / partitions(8) = 128
203 *
204 * Example 4):
205 * ---------------------------------------------------------------------
206 * Server(C) have a thousand of cores and user configured it to 32 partitions
207 * MDS_NTHRS_BASE(64) * 32 = 2048
208 *
209 * which is already above soft limit MDS_NTHRS_MAX(1024), but we still need
210 * to guarantee that each partition has at least MDS_NTHRS_BASE(64) threads
211 * to keep service healthy, so total number of threads will just be 2048.
212 *
213 * NB: we don't suggest to choose server with that many cores because backend
214 * filesystem itself, buffer cache, or underlying network stack might
215 * have some SMP scalability issues at that large scale.
216 *
217 * If user already has a fat machine with hundreds or thousands of cores,
218 * there are two choices for configuration:
219 * a) create CPU table from subset of all CPUs and run Lustre on
220 * top of this subset
221 * b) bind service threads on a few partitions, see modparameters of
222 * MDS and OSS for details
223*
224 * NB: these calculations (and examples below) are simplified to help
225 * understanding, the real implementation is a little more complex,
226 * please see ptlrpc_server_nthreads_check() for details.
227 *
228 */
229
230 /*
231 * LDLM threads constants:
232 *
233 * Given 8 as factor and 24 as base threads number
234 *
235 * example 1)
236 * On 4-core machine we will have 24 + 8 * 4 = 56 threads.
237 *
238 * example 2)
239 * On 8-core machine with 2 partitions we will have 24 + 4 * 8 = 56
240 * threads for each partition and total threads number will be 112.
241 *
242 * example 3)
243 * On 64-core machine with 8 partitions we will need LDLM_NTHRS_BASE(24)
244 * threads for each partition to keep service healthy, so total threads
245 * number should be 24 * 8 = 192.
246 *
247 * So with these constants, threads number will be at the similar level
248 * of old versions, unless target machine has over a hundred cores
249 */
250#define LDLM_THR_FACTOR 8
251#define LDLM_NTHRS_INIT PTLRPC_NTHRS_INIT
252#define LDLM_NTHRS_BASE 24
253#define LDLM_NTHRS_MAX (num_online_cpus() == 1 ? 64 : 128)
254
255#define LDLM_BL_THREADS LDLM_NTHRS_AUTO_INIT
256#define LDLM_CLIENT_NBUFS 1
257#define LDLM_SERVER_NBUFS 64
258#define LDLM_BUFSIZE (8 * 1024)
259#define LDLM_MAXREQSIZE (5 * 1024)
260#define LDLM_MAXREPSIZE (1024)
261
e55c4476
JN
262#define MDS_MAXREQSIZE (5 * 1024) /* >= 4736 */
263
d7e09d03 264#define OST_MAXREQSIZE (5 * 1024)
d7e09d03
PT
265
266/* Macro to hide a typecast. */
267#define ptlrpc_req_async_args(req) ((void *)&req->rq_async_args)
268
269/**
270 * Structure to single define portal connection.
271 */
272struct ptlrpc_connection {
273 /** linkage for connections hash table */
274 struct hlist_node c_hash;
275 /** Our own lnet nid for this connection */
276 lnet_nid_t c_self;
277 /** Remote side nid for this connection */
278 lnet_process_id_t c_peer;
279 /** UUID of the other side */
280 struct obd_uuid c_remote_uuid;
281 /** reference counter for this connection */
282 atomic_t c_refcount;
283};
284
285/** Client definition for PortalRPC */
286struct ptlrpc_client {
287 /** What lnet portal does this client send messages to by default */
288 __u32 cli_request_portal;
289 /** What portal do we expect replies on */
290 __u32 cli_reply_portal;
291 /** Name of the client */
292 char *cli_name;
293};
294
295/** state flags of requests */
296/* XXX only ones left are those used by the bulk descs as well! */
297#define PTL_RPC_FL_INTR (1 << 0) /* reply wait was interrupted by user */
298#define PTL_RPC_FL_TIMEOUT (1 << 7) /* request timed out waiting for reply */
299
300#define REQ_MAX_ACK_LOCKS 8
301
302union ptlrpc_async_args {
303 /**
304 * Scratchpad for passing args to completion interpreter. Users
305 * cast to the struct of their choosing, and CLASSERT that this is
c0a2472f 306 * big enough. For _tons_ of context, kmalloc a struct and store
d7e09d03
PT
307 * a pointer to it here. The pointer_arg ensures this struct is at
308 * least big enough for that.
309 */
310 void *pointer_arg[11];
311 __u64 space[7];
312};
313
314struct ptlrpc_request_set;
315typedef int (*set_interpreter_func)(struct ptlrpc_request_set *, void *, int);
316typedef int (*set_producer_func)(struct ptlrpc_request_set *, void *);
317
318/**
319 * Definition of request set structure.
320 * Request set is a list of requests (not necessary to the same target) that
321 * once populated with RPCs could be sent in parallel.
322 * There are two kinds of request sets. General purpose and with dedicated
323 * serving thread. Example of the latter is ptlrpcd set.
324 * For general purpose sets once request set started sending it is impossible
325 * to add new requests to such set.
326 * Provides a way to call "completion callbacks" when all requests in the set
327 * returned.
328 */
329struct ptlrpc_request_set {
330 atomic_t set_refcount;
331 /** number of in queue requests */
332 atomic_t set_new_count;
333 /** number of uncompleted requests */
334 atomic_t set_remaining;
335 /** wait queue to wait on for request events */
336 wait_queue_head_t set_waitq;
337 wait_queue_head_t *set_wakeup_ptr;
338 /** List of requests in the set */
339 struct list_head set_requests;
340 /**
341 * List of completion callbacks to be called when the set is completed
342 * This is only used if \a set_interpret is NULL.
343 * Links struct ptlrpc_set_cbdata.
344 */
345 struct list_head set_cblist;
346 /** Completion callback, if only one. */
347 set_interpreter_func set_interpret;
348 /** opaq argument passed to completion \a set_interpret callback. */
349 void *set_arg;
350 /**
351 * Lock for \a set_new_requests manipulations
352 * locked so that any old caller can communicate requests to
353 * the set holder who can then fold them into the lock-free set
354 */
355 spinlock_t set_new_req_lock;
356 /** List of new yet unsent requests. Only used with ptlrpcd now. */
357 struct list_head set_new_requests;
358
359 /** rq_status of requests that have been freed already */
360 int set_rc;
361 /** Additional fields used by the flow control extension */
362 /** Maximum number of RPCs in flight */
363 int set_max_inflight;
364 /** Callback function used to generate RPCs */
365 set_producer_func set_producer;
366 /** opaq argument passed to the producer callback */
367 void *set_producer_arg;
368};
369
370/**
371 * Description of a single ptrlrpc_set callback
372 */
373struct ptlrpc_set_cbdata {
374 /** List linkage item */
375 struct list_head psc_item;
376 /** Pointer to interpreting function */
377 set_interpreter_func psc_interpret;
378 /** Opaq argument to pass to the callback */
379 void *psc_data;
380};
381
382struct ptlrpc_bulk_desc;
383struct ptlrpc_service_part;
384struct ptlrpc_service;
385
386/**
387 * ptlrpc callback & work item stuff
388 */
389struct ptlrpc_cb_id {
390 void (*cbid_fn)(lnet_event_t *ev); /* specific callback fn */
391 void *cbid_arg; /* additional arg */
392};
393
394/** Maximum number of locks to fit into reply state */
395#define RS_MAX_LOCKS 8
396#define RS_DEBUG 0
397
398/**
399 * Structure to define reply state on the server
400 * Reply state holds various reply message information. Also for "difficult"
401 * replies (rep-ack case) we store the state after sending reply and wait
402 * for the client to acknowledge the reception. In these cases locks could be
403 * added to the state for replay/failover consistency guarantees.
404 */
405struct ptlrpc_reply_state {
406 /** Callback description */
407 struct ptlrpc_cb_id rs_cb_id;
408 /** Linkage for list of all reply states in a system */
409 struct list_head rs_list;
410 /** Linkage for list of all reply states on same export */
411 struct list_head rs_exp_list;
412 /** Linkage for list of all reply states for same obd */
413 struct list_head rs_obd_list;
414#if RS_DEBUG
415 struct list_head rs_debug_list;
416#endif
417 /** A spinlock to protect the reply state flags */
418 spinlock_t rs_lock;
419 /** Reply state flags */
c56e256d 420 unsigned long rs_difficult:1; /* ACK/commit stuff */
d7e09d03 421 unsigned long rs_no_ack:1; /* no ACK, even for
c56e256d
OD
422 * difficult requests
423 */
d7e09d03
PT
424 unsigned long rs_scheduled:1; /* being handled? */
425 unsigned long rs_scheduled_ever:1;/* any schedule attempts? */
426 unsigned long rs_handled:1; /* been handled yet? */
427 unsigned long rs_on_net:1; /* reply_out_callback pending? */
428 unsigned long rs_prealloc:1; /* rs from prealloc list */
429 unsigned long rs_committed:1;/* the transaction was committed
c56e256d
OD
430 * and the rs was dispatched
431 */
d7e09d03
PT
432 /** Size of the state */
433 int rs_size;
434 /** opcode */
435 __u32 rs_opc;
436 /** Transaction number */
437 __u64 rs_transno;
438 /** xid */
439 __u64 rs_xid;
440 struct obd_export *rs_export;
441 struct ptlrpc_service_part *rs_svcpt;
442 /** Lnet metadata handle for the reply */
443 lnet_handle_md_t rs_md_h;
444 atomic_t rs_refcount;
445
17891183 446 /** Context for the service thread */
d7e09d03
PT
447 struct ptlrpc_svc_ctx *rs_svc_ctx;
448 /** Reply buffer (actually sent to the client), encoded if needed */
449 struct lustre_msg *rs_repbuf; /* wrapper */
450 /** Size of the reply buffer */
451 int rs_repbuf_len; /* wrapper buf length */
452 /** Size of the reply message */
453 int rs_repdata_len; /* wrapper msg length */
454 /**
bd9070cb 455 * Actual reply message. Its content is encrypted (if needed) to
d7e09d03 456 * produce reply buffer for actual sending. In simple case
bd9070cb 457 * of no network encryption we just set \a rs_repbuf to \a rs_msg
d7e09d03
PT
458 */
459 struct lustre_msg *rs_msg; /* reply message */
460
461 /** Number of locks awaiting client ACK */
462 int rs_nlocks;
463 /** Handles of locks awaiting client reply ACK */
464 struct lustre_handle rs_locks[RS_MAX_LOCKS];
465 /** Lock modes of locks in \a rs_locks */
52ee0d20 466 enum ldlm_mode rs_modes[RS_MAX_LOCKS];
d7e09d03
PT
467};
468
469struct ptlrpc_thread;
470
471/** RPC stages */
472enum rq_phase {
473 RQ_PHASE_NEW = 0xebc0de00,
474 RQ_PHASE_RPC = 0xebc0de01,
475 RQ_PHASE_BULK = 0xebc0de02,
476 RQ_PHASE_INTERPRET = 0xebc0de03,
477 RQ_PHASE_COMPLETE = 0xebc0de04,
478 RQ_PHASE_UNREGISTERING = 0xebc0de05,
479 RQ_PHASE_UNDEFINED = 0xebc0de06
480};
481
482/** Type of request interpreter call-back */
483typedef int (*ptlrpc_interpterer_t)(const struct lu_env *env,
484 struct ptlrpc_request *req,
485 void *arg, int rc);
486
487/**
488 * Definition of request pool structure.
489 * The pool is used to store empty preallocated requests for the case
490 * when we would actually need to send something without performing
491 * any allocations (to avoid e.g. OOM).
492 */
493struct ptlrpc_request_pool {
494 /** Locks the list */
495 spinlock_t prp_lock;
496 /** list of ptlrpc_request structs */
497 struct list_head prp_req_list;
17891183 498 /** Maximum message size that would fit into a request from this pool */
d7e09d03
PT
499 int prp_rq_size;
500 /** Function to allocate more requests for this pool */
aefd9d71 501 int (*prp_populate)(struct ptlrpc_request_pool *, int);
d7e09d03
PT
502};
503
504struct lu_context;
505struct lu_env;
506
507struct ldlm_lock;
508
509/**
510 * \defgroup nrs Network Request Scheduler
511 * @{
512 */
513struct ptlrpc_nrs_policy;
514struct ptlrpc_nrs_resource;
515struct ptlrpc_nrs_request;
516
517/**
518 * NRS control operations.
519 *
520 * These are common for all policies.
521 */
522enum ptlrpc_nrs_ctl {
523 /**
524 * Not a valid opcode.
525 */
526 PTLRPC_NRS_CTL_INVALID,
527 /**
528 * Activate the policy.
529 */
530 PTLRPC_NRS_CTL_START,
531 /**
532 * Reserved for multiple primary policies, which may be a possibility
533 * in the future.
534 */
535 PTLRPC_NRS_CTL_STOP,
536 /**
537 * Policies can start using opcodes from this value and onwards for
538 * their own purposes; the assigned value itself is arbitrary.
539 */
540 PTLRPC_NRS_CTL_1ST_POL_SPEC = 0x20,
541};
542
543/**
544 * ORR policy operations
545 */
546enum nrs_ctl_orr {
547 NRS_CTL_ORR_RD_QUANTUM = PTLRPC_NRS_CTL_1ST_POL_SPEC,
548 NRS_CTL_ORR_WR_QUANTUM,
549 NRS_CTL_ORR_RD_OFF_TYPE,
550 NRS_CTL_ORR_WR_OFF_TYPE,
551 NRS_CTL_ORR_RD_SUPP_REQ,
552 NRS_CTL_ORR_WR_SUPP_REQ,
553};
554
555/**
556 * NRS policy operations.
557 *
558 * These determine the behaviour of a policy, and are called in response to
559 * NRS core events.
560 */
561struct ptlrpc_nrs_pol_ops {
562 /**
563 * Called during policy registration; this operation is optional.
564 *
565 * \param[in,out] policy The policy being initialized
566 */
567 int (*op_policy_init) (struct ptlrpc_nrs_policy *policy);
568 /**
569 * Called during policy unregistration; this operation is optional.
570 *
571 * \param[in,out] policy The policy being unregistered/finalized
572 */
573 void (*op_policy_fini) (struct ptlrpc_nrs_policy *policy);
574 /**
575 * Called when activating a policy via lprocfs; policies allocate and
576 * initialize their resources here; this operation is optional.
577 *
578 * \param[in,out] policy The policy being started
579 *
580 * \see nrs_policy_start_locked()
581 */
582 int (*op_policy_start) (struct ptlrpc_nrs_policy *policy);
583 /**
584 * Called when deactivating a policy via lprocfs; policies deallocate
585 * their resources here; this operation is optional
586 *
587 * \param[in,out] policy The policy being stopped
588 *
589 * \see nrs_policy_stop0()
590 */
591 void (*op_policy_stop) (struct ptlrpc_nrs_policy *policy);
592 /**
593 * Used for policy-specific operations; i.e. not generic ones like
594 * \e PTLRPC_NRS_CTL_START and \e PTLRPC_NRS_CTL_GET_INFO; analogous
595 * to an ioctl; this operation is optional.
596 *
597 * \param[in,out] policy The policy carrying out operation \a opc
598 * \param[in] opc The command operation being carried out
599 * \param[in,out] arg An generic buffer for communication between the
600 * user and the control operation
601 *
602 * \retval -ve error
603 * \retval 0 success
604 *
605 * \see ptlrpc_nrs_policy_control()
606 */
607 int (*op_policy_ctl) (struct ptlrpc_nrs_policy *policy,
608 enum ptlrpc_nrs_ctl opc, void *arg);
609
610 /**
611 * Called when obtaining references to the resources of the resource
612 * hierarchy for a request that has arrived for handling at the PTLRPC
613 * service. Policies should return -ve for requests they do not wish
614 * to handle. This operation is mandatory.
615 *
616 * \param[in,out] policy The policy we're getting resources for.
617 * \param[in,out] nrq The request we are getting resources for.
618 * \param[in] parent The parent resource of the resource being
619 * requested; set to NULL if none.
620 * \param[out] resp The resource is to be returned here; the
621 * fallback policy in an NRS head should
622 * \e always return a non-NULL pointer value.
623 * \param[in] moving_req When set, signifies that this is an attempt
624 * to obtain resources for a request being moved
625 * to the high-priority NRS head by
626 * ldlm_lock_reorder_req().
627 * This implies two things:
628 * 1. We are under obd_export::exp_rpc_lock and
629 * so should not sleep.
630 * 2. We should not perform non-idempotent or can
631 * skip performing idempotent operations that
632 * were carried out when resources were first
633 * taken for the request when it was initialized
634 * in ptlrpc_nrs_req_initialize().
635 *
636 * \retval 0, +ve The level of the returned resource in the resource
637 * hierarchy; currently only 0 (for a non-leaf resource)
638 * and 1 (for a leaf resource) are supported by the
639 * framework.
640 * \retval -ve error
641 *
642 * \see ptlrpc_nrs_req_initialize()
643 * \see ptlrpc_nrs_hpreq_add_nolock()
d7e09d03
PT
644 */
645 int (*op_res_get) (struct ptlrpc_nrs_policy *policy,
646 struct ptlrpc_nrs_request *nrq,
647 const struct ptlrpc_nrs_resource *parent,
648 struct ptlrpc_nrs_resource **resp,
649 bool moving_req);
650 /**
651 * Called when releasing references taken for resources in the resource
652 * hierarchy for the request; this operation is optional.
653 *
654 * \param[in,out] policy The policy the resource belongs to
655 * \param[in] res The resource to be freed
656 *
657 * \see ptlrpc_nrs_req_finalize()
658 * \see ptlrpc_nrs_hpreq_add_nolock()
d7e09d03
PT
659 */
660 void (*op_res_put) (struct ptlrpc_nrs_policy *policy,
661 const struct ptlrpc_nrs_resource *res);
662
663 /**
664 * Obtains a request for handling from the policy, and optionally
665 * removes the request from the policy; this operation is mandatory.
666 *
667 * \param[in,out] policy The policy to poll
668 * \param[in] peek When set, signifies that we just want to
669 * examine the request, and not handle it, so the
670 * request is not removed from the policy.
671 * \param[in] force When set, it will force a policy to return a
672 * request if it has one queued.
673 *
674 * \retval NULL No request available for handling
675 * \retval valid-pointer The request polled for handling
676 *
677 * \see ptlrpc_nrs_req_get_nolock()
678 */
679 struct ptlrpc_nrs_request *
680 (*op_req_get) (struct ptlrpc_nrs_policy *policy, bool peek,
681 bool force);
682 /**
683 * Called when attempting to add a request to a policy for later
684 * handling; this operation is mandatory.
685 *
686 * \param[in,out] policy The policy on which to enqueue \a nrq
687 * \param[in,out] nrq The request to enqueue
688 *
689 * \retval 0 success
690 * \retval != 0 error
691 *
692 * \see ptlrpc_nrs_req_add_nolock()
693 */
694 int (*op_req_enqueue) (struct ptlrpc_nrs_policy *policy,
695 struct ptlrpc_nrs_request *nrq);
696 /**
697 * Removes a request from the policy's set of pending requests. Normally
698 * called after a request has been polled successfully from the policy
699 * for handling; this operation is mandatory.
700 *
701 * \param[in,out] policy The policy the request \a nrq belongs to
702 * \param[in,out] nrq The request to dequeue
d7e09d03
PT
703 */
704 void (*op_req_dequeue) (struct ptlrpc_nrs_policy *policy,
705 struct ptlrpc_nrs_request *nrq);
706 /**
707 * Called after the request being carried out. Could be used for
708 * job/resource control; this operation is optional.
709 *
710 * \param[in,out] policy The policy which is stopping to handle request
711 * \a nrq
712 * \param[in,out] nrq The request
713 *
5e42bc9d 714 * \pre assert_spin_locked(&svcpt->scp_req_lock)
d7e09d03
PT
715 *
716 * \see ptlrpc_nrs_req_stop_nolock()
717 */
718 void (*op_req_stop) (struct ptlrpc_nrs_policy *policy,
719 struct ptlrpc_nrs_request *nrq);
720 /**
721 * Registers the policy's lprocfs interface with a PTLRPC service.
722 *
723 * \param[in] svc The service
724 *
725 * \retval 0 success
726 * \retval != 0 error
727 */
728 int (*op_lprocfs_init) (struct ptlrpc_service *svc);
729 /**
730 * Unegisters the policy's lprocfs interface with a PTLRPC service.
731 *
732 * In cases of failed policy registration in
733 * \e ptlrpc_nrs_policy_register(), this function may be called for a
734 * service which has not registered the policy successfully, so
735 * implementations of this method should make sure their operations are
736 * safe in such cases.
737 *
738 * \param[in] svc The service
739 */
740 void (*op_lprocfs_fini) (struct ptlrpc_service *svc);
741};
742
743/**
744 * Policy flags
745 */
746enum nrs_policy_flags {
747 /**
748 * Fallback policy, use this flag only on a single supported policy per
749 * service. The flag cannot be used on policies that use
750 * \e PTLRPC_NRS_FL_REG_EXTERN
751 */
752 PTLRPC_NRS_FL_FALLBACK = (1 << 0),
753 /**
754 * Start policy immediately after registering.
755 */
756 PTLRPC_NRS_FL_REG_START = (1 << 1),
757 /**
758 * This is a policy registering from a module different to the one NRS
759 * core ships in (currently ptlrpc).
760 */
761 PTLRPC_NRS_FL_REG_EXTERN = (1 << 2),
762};
763
764/**
765 * NRS queue type.
766 *
767 * Denotes whether an NRS instance is for handling normal or high-priority
768 * RPCs, or whether an operation pertains to one or both of the NRS instances
769 * in a service.
770 */
771enum ptlrpc_nrs_queue_type {
772 PTLRPC_NRS_QUEUE_REG = (1 << 0),
773 PTLRPC_NRS_QUEUE_HP = (1 << 1),
774 PTLRPC_NRS_QUEUE_BOTH = (PTLRPC_NRS_QUEUE_REG | PTLRPC_NRS_QUEUE_HP)
775};
776
777/**
778 * NRS head
779 *
780 * A PTLRPC service has at least one NRS head instance for handling normal
781 * priority RPCs, and may optionally have a second NRS head instance for
782 * handling high-priority RPCs. Each NRS head maintains a list of available
783 * policies, of which one and only one policy is acting as the fallback policy,
784 * and optionally a different policy may be acting as the primary policy. For
785 * all RPCs handled by this NRS head instance, NRS core will first attempt to
786 * enqueue the RPC using the primary policy (if any). The fallback policy is
787 * used in the following cases:
788 * - when there was no primary policy in the
789 * ptlrpc_nrs_pol_state::NRS_POL_STATE_STARTED state at the time the request
790 * was initialized.
791 * - when the primary policy that was at the
792 * ptlrpc_nrs_pol_state::PTLRPC_NRS_POL_STATE_STARTED state at the time the
793 * RPC was initialized, denoted it did not wish, or for some other reason was
794 * not able to handle the request, by returning a non-valid NRS resource
795 * reference.
796 * - when the primary policy that was at the
797 * ptlrpc_nrs_pol_state::PTLRPC_NRS_POL_STATE_STARTED state at the time the
798 * RPC was initialized, fails later during the request enqueueing stage.
799 *
800 * \see nrs_resource_get_safe()
801 * \see nrs_request_enqueue()
802 */
803struct ptlrpc_nrs {
804 spinlock_t nrs_lock;
805 /** XXX Possibly replace svcpt->scp_req_lock with another lock here. */
806 /**
807 * List of registered policies
808 */
809 struct list_head nrs_policy_list;
810 /**
811 * List of policies with queued requests. Policies that have any
812 * outstanding requests are queued here, and this list is queried
813 * in a round-robin manner from NRS core when obtaining a request
814 * for handling. This ensures that requests from policies that at some
815 * point transition away from the
816 * ptlrpc_nrs_pol_state::NRS_POL_STATE_STARTED state are drained.
817 */
818 struct list_head nrs_policy_queued;
819 /**
820 * Service partition for this NRS head
821 */
822 struct ptlrpc_service_part *nrs_svcpt;
823 /**
824 * Primary policy, which is the preferred policy for handling RPCs
825 */
826 struct ptlrpc_nrs_policy *nrs_policy_primary;
827 /**
828 * Fallback policy, which is the backup policy for handling RPCs
829 */
830 struct ptlrpc_nrs_policy *nrs_policy_fallback;
831 /**
832 * This NRS head handles either HP or regular requests
833 */
834 enum ptlrpc_nrs_queue_type nrs_queue_type;
835 /**
836 * # queued requests from all policies in this NRS head
837 */
838 unsigned long nrs_req_queued;
839 /**
840 * # scheduled requests from all policies in this NRS head
841 */
842 unsigned long nrs_req_started;
843 /**
844 * # policies on this NRS
845 */
846 unsigned nrs_num_pols;
847 /**
848 * This NRS head is in progress of starting a policy
849 */
850 unsigned nrs_policy_starting:1;
851 /**
852 * In progress of shutting down the whole NRS head; used during
853 * unregistration
854 */
855 unsigned nrs_stopping:1;
856};
857
858#define NRS_POL_NAME_MAX 16
859
860struct ptlrpc_nrs_pol_desc;
861
862/**
863 * Service compatibility predicate; this determines whether a policy is adequate
864 * for handling RPCs of a particular PTLRPC service.
865 *
866 * XXX:This should give the same result during policy registration and
867 * unregistration, and for all partitions of a service; so the result should not
868 * depend on temporal service or other properties, that may influence the
869 * result.
870 */
871typedef bool (*nrs_pol_desc_compat_t) (const struct ptlrpc_service *svc,
872 const struct ptlrpc_nrs_pol_desc *desc);
873
874struct ptlrpc_nrs_pol_conf {
875 /**
876 * Human-readable policy name
877 */
878 char nc_name[NRS_POL_NAME_MAX];
879 /**
880 * NRS operations for this policy
881 */
882 const struct ptlrpc_nrs_pol_ops *nc_ops;
883 /**
884 * Service compatibility predicate
885 */
886 nrs_pol_desc_compat_t nc_compat;
887 /**
888 * Set for policies that support a single ptlrpc service, i.e. ones that
889 * have \a pd_compat set to nrs_policy_compat_one(). The variable value
890 * depicts the name of the single service that such policies are
891 * compatible with.
892 */
893 const char *nc_compat_svc_name;
894 /**
895 * Owner module for this policy descriptor; policies registering from a
896 * different module to the one the NRS framework is held within
897 * (currently ptlrpc), should set this field to THIS_MODULE.
898 */
c34d9cd8 899 struct module *nc_owner;
d7e09d03 900 /**
bd9070cb 901 * Policy registration flags; a bitmask of \e nrs_policy_flags
d7e09d03
PT
902 */
903 unsigned nc_flags;
904};
905
906/**
907 * NRS policy registering descriptor
908 *
909 * Is used to hold a description of a policy that can be passed to NRS core in
910 * order to register the policy with NRS heads in different PTLRPC services.
911 */
912struct ptlrpc_nrs_pol_desc {
913 /**
914 * Human-readable policy name
915 */
916 char pd_name[NRS_POL_NAME_MAX];
917 /**
918 * Link into nrs_core::nrs_policies
919 */
920 struct list_head pd_list;
921 /**
922 * NRS operations for this policy
923 */
924 const struct ptlrpc_nrs_pol_ops *pd_ops;
925 /**
926 * Service compatibility predicate
927 */
928 nrs_pol_desc_compat_t pd_compat;
929 /**
930 * Set for policies that are compatible with only one PTLRPC service.
931 *
932 * \see ptlrpc_nrs_pol_conf::nc_compat_svc_name
933 */
934 const char *pd_compat_svc_name;
935 /**
936 * Owner module for this policy descriptor.
937 *
938 * We need to hold a reference to the module whenever we might make use
939 * of any of the module's contents, i.e.
940 * - If one or more instances of the policy are at a state where they
941 * might be handling a request, i.e.
942 * ptlrpc_nrs_pol_state::NRS_POL_STATE_STARTED or
943 * ptlrpc_nrs_pol_state::NRS_POL_STATE_STOPPING as we will have to
944 * call into the policy's ptlrpc_nrs_pol_ops() handlers. A reference
945 * is taken on the module when
946 * \e ptlrpc_nrs_pol_desc::pd_refs becomes 1, and released when it
947 * becomes 0, so that we hold only one reference to the module maximum
948 * at any time.
949 *
950 * We do not need to hold a reference to the module, even though we
951 * might use code and data from the module, in the following cases:
952 * - During external policy registration, because this should happen in
953 * the module's init() function, in which case the module is safe from
954 * removal because a reference is being held on the module by the
955 * kernel, and iirc kmod (and I guess module-init-tools also) will
956 * serialize any racing processes properly anyway.
957 * - During external policy unregistration, because this should happen
958 * in a module's exit() function, and any attempts to start a policy
959 * instance would need to take a reference on the module, and this is
960 * not possible once we have reached the point where the exit()
961 * handler is called.
962 * - During service registration and unregistration, as service setup
963 * and cleanup, and policy registration, unregistration and policy
964 * instance starting, are serialized by \e nrs_core::nrs_mutex, so
965 * as long as users adhere to the convention of registering policies
966 * in init() and unregistering them in module exit() functions, there
967 * should not be a race between these operations.
968 * - During any policy-specific lprocfs operations, because a reference
969 * is held by the kernel on a proc entry that has been entered by a
970 * syscall, so as long as proc entries are removed during unregistration time,
971 * then unregistration and lprocfs operations will be properly
972 * serialized.
973 */
c34d9cd8 974 struct module *pd_owner;
d7e09d03
PT
975 /**
976 * Bitmask of \e nrs_policy_flags
977 */
978 unsigned pd_flags;
979 /**
980 * # of references on this descriptor
981 */
982 atomic_t pd_refs;
983};
984
985/**
986 * NRS policy state
987 *
988 * Policies transition from one state to the other during their lifetime
989 */
990enum ptlrpc_nrs_pol_state {
991 /**
992 * Not a valid policy state.
993 */
994 NRS_POL_STATE_INVALID,
995 /**
996 * Policies are at this state either at the start of their life, or
997 * transition here when the user selects a different policy to act
998 * as the primary one.
999 */
1000 NRS_POL_STATE_STOPPED,
1001 /**
1002 * Policy is progress of stopping
1003 */
1004 NRS_POL_STATE_STOPPING,
1005 /**
1006 * Policy is in progress of starting
1007 */
1008 NRS_POL_STATE_STARTING,
1009 /**
1010 * A policy is in this state in two cases:
1011 * - it is the fallback policy, which is always in this state.
1012 * - it has been activated by the user; i.e. it is the primary policy,
1013 */
1014 NRS_POL_STATE_STARTED,
1015};
1016
1017/**
1018 * NRS policy information
1019 *
1020 * Used for obtaining information for the status of a policy via lprocfs
1021 */
1022struct ptlrpc_nrs_pol_info {
1023 /**
1024 * Policy name
1025 */
1026 char pi_name[NRS_POL_NAME_MAX];
1027 /**
1028 * Current policy state
1029 */
1030 enum ptlrpc_nrs_pol_state pi_state;
1031 /**
1032 * # RPCs enqueued for later dispatching by the policy
1033 */
1034 long pi_req_queued;
1035 /**
1036 * # RPCs started for dispatch by the policy
1037 */
1038 long pi_req_started;
1039 /**
1040 * Is this a fallback policy?
1041 */
1042 unsigned pi_fallback:1;
1043};
1044
1045/**
1046 * NRS policy
1047 *
1048 * There is one instance of this for each policy in each NRS head of each
1049 * PTLRPC service partition.
1050 */
1051struct ptlrpc_nrs_policy {
1052 /**
1053 * Linkage into the NRS head's list of policies,
1054 * ptlrpc_nrs:nrs_policy_list
1055 */
1056 struct list_head pol_list;
1057 /**
1058 * Linkage into the NRS head's list of policies with enqueued
1059 * requests ptlrpc_nrs:nrs_policy_queued
1060 */
1061 struct list_head pol_list_queued;
1062 /**
1063 * Current state of this policy
1064 */
1065 enum ptlrpc_nrs_pol_state pol_state;
1066 /**
1067 * Bitmask of nrs_policy_flags
1068 */
1069 unsigned pol_flags;
1070 /**
1071 * # RPCs enqueued for later dispatching by the policy
1072 */
1073 long pol_req_queued;
1074 /**
1075 * # RPCs started for dispatch by the policy
1076 */
1077 long pol_req_started;
1078 /**
1079 * Usage Reference count taken on the policy instance
1080 */
1081 long pol_ref;
1082 /**
1083 * The NRS head this policy has been created at
1084 */
1085 struct ptlrpc_nrs *pol_nrs;
1086 /**
1087 * Private policy data; varies by policy type
1088 */
1089 void *pol_private;
1090 /**
1091 * Policy descriptor for this policy instance.
1092 */
1093 struct ptlrpc_nrs_pol_desc *pol_desc;
1094};
1095
1096/**
1097 * NRS resource
1098 *
1099 * Resources are embedded into two types of NRS entities:
1100 * - Inside NRS policies, in the policy's private data in
1101 * ptlrpc_nrs_policy::pol_private
1102 * - In objects that act as prime-level scheduling entities in different NRS
1103 * policies; e.g. on a policy that performs round robin or similar order
1104 * scheduling across client NIDs, there would be one NRS resource per unique
1105 * client NID. On a policy which performs round robin scheduling across
1106 * backend filesystem objects, there would be one resource associated with
1107 * each of the backend filesystem objects partaking in the scheduling
1108 * performed by the policy.
1109 *
1110 * NRS resources share a parent-child relationship, in which resources embedded
1111 * in policy instances are the parent entities, with all scheduling entities
1112 * a policy schedules across being the children, thus forming a simple resource
1113 * hierarchy. This hierarchy may be extended with one or more levels in the
1114 * future if the ability to have more than one primary policy is added.
1115 *
1116 * Upon request initialization, references to the then active NRS policies are
1117 * taken and used to later handle the dispatching of the request with one of
1118 * these policies.
1119 *
1120 * \see nrs_resource_get_safe()
1121 * \see ptlrpc_nrs_req_add()
1122 */
1123struct ptlrpc_nrs_resource {
1124 /**
1125 * This NRS resource's parent; is NULL for resources embedded in NRS
1126 * policy instances; i.e. those are top-level ones.
1127 */
1128 struct ptlrpc_nrs_resource *res_parent;
1129 /**
1130 * The policy associated with this resource.
1131 */
1132 struct ptlrpc_nrs_policy *res_policy;
1133};
1134
1135enum {
1136 NRS_RES_FALLBACK,
1137 NRS_RES_PRIMARY,
1138 NRS_RES_MAX
1139};
1140
1141/* \name fifo
1142 *
1143 * FIFO policy
1144 *
1145 * This policy is a logical wrapper around previous, non-NRS functionality.
1146 * It dispatches RPCs in the same order as they arrive from the network. This
1147 * policy is currently used as the fallback policy, and the only enabled policy
1148 * on all NRS heads of all PTLRPC service partitions.
1149 * @{
1150 */
1151
1152/**
1153 * Private data structure for the FIFO policy
1154 */
1155struct nrs_fifo_head {
1156 /**
1157 * Resource object for policy instance.
1158 */
1159 struct ptlrpc_nrs_resource fh_res;
1160 /**
1161 * List of queued requests.
1162 */
1163 struct list_head fh_list;
1164 /**
1165 * For debugging purposes.
1166 */
1167 __u64 fh_sequence;
1168};
1169
1170struct nrs_fifo_req {
1171 struct list_head fr_list;
1172 __u64 fr_sequence;
1173};
1174
1175/** @} fifo */
1176
d7e09d03
PT
1177/**
1178 * NRS request
1179 *
1180 * Instances of this object exist embedded within ptlrpc_request; the main
1181 * purpose of this object is to hold references to the request's resources
1182 * for the lifetime of the request, and to hold properties that policies use
1183 * use for determining the request's scheduling priority.
c56e256d 1184 */
d7e09d03
PT
1185struct ptlrpc_nrs_request {
1186 /**
1187 * The request's resource hierarchy.
1188 */
1189 struct ptlrpc_nrs_resource *nr_res_ptrs[NRS_RES_MAX];
1190 /**
1191 * Index into ptlrpc_nrs_request::nr_res_ptrs of the resource of the
1192 * policy that was used to enqueue the request.
1193 *
1194 * \see nrs_request_enqueue()
1195 */
1196 unsigned nr_res_idx;
1197 unsigned nr_initialized:1;
1198 unsigned nr_enqueued:1;
1199 unsigned nr_started:1;
1200 unsigned nr_finalized:1;
d7e09d03
PT
1201
1202 /**
1203 * Policy-specific fields, used for determining a request's scheduling
1204 * priority, and other supporting functionality.
1205 */
1206 union {
1207 /**
1208 * Fields for the FIFO policy
1209 */
1210 struct nrs_fifo_req fifo;
d7e09d03
PT
1211 } nr_u;
1212 /**
1213 * Externally-registering policies may want to use this to allocate
1214 * their own request properties.
1215 */
1216 void *ext;
1217};
1218
1219/** @} nrs */
1220
1221/**
1222 * Basic request prioritization operations structure.
1223 * The whole idea is centered around locks and RPCs that might affect locks.
1224 * When a lock is contended we try to give priority to RPCs that might lead
1225 * to fastest release of that lock.
1226 * Currently only implemented for OSTs only in a way that makes all
1227 * IO and truncate RPCs that are coming from a locked region where a lock is
1228 * contended a priority over other requests.
1229 */
1230struct ptlrpc_hpreq_ops {
1231 /**
1232 * Check if the lock handle of the given lock is the same as
1233 * taken from the request.
1234 */
1235 int (*hpreq_lock_match)(struct ptlrpc_request *, struct ldlm_lock *);
1236 /**
1237 * Check if the request is a high priority one.
1238 */
1239 int (*hpreq_check)(struct ptlrpc_request *);
1240 /**
1241 * Called after the request has been handled.
1242 */
1243 void (*hpreq_fini)(struct ptlrpc_request *);
1244};
1245
1246/**
1247 * Represents remote procedure call.
1248 *
1249 * This is a staple structure used by everybody wanting to send a request
1250 * in Lustre.
1251 */
1252struct ptlrpc_request {
1253 /* Request type: one of PTL_RPC_MSG_* */
1254 int rq_type;
1255 /** Result of request processing */
1256 int rq_status;
1257 /**
1258 * Linkage item through which this request is included into
1259 * sending/delayed lists on client and into rqbd list on server
1260 */
1261 struct list_head rq_list;
1262 /**
1263 * Server side list of incoming unserved requests sorted by arrival
1264 * time. Traversed from time to time to notice about to expire
1265 * requests and sent back "early replies" to clients to let them
1266 * know server is alive and well, just very busy to service their
1267 * requests in time
1268 */
1269 struct list_head rq_timed_list;
17891183 1270 /** server-side history, used for debugging purposes. */
d7e09d03
PT
1271 struct list_head rq_history_list;
1272 /** server-side per-export list */
1273 struct list_head rq_exp_list;
1274 /** server-side hp handlers */
1275 struct ptlrpc_hpreq_ops *rq_ops;
1276
1277 /** initial thread servicing this request */
1278 struct ptlrpc_thread *rq_svc_thread;
1279
1280 /** history sequence # */
1281 __u64 rq_history_seq;
1282 /** \addtogroup nrs
1283 * @{
1284 */
1285 /** stub for NRS request */
1286 struct ptlrpc_nrs_request rq_nrq;
1287 /** @} nrs */
1288 /** the index of service's srv_at_array into which request is linked */
c8ff1810 1289 u32 rq_at_index;
d7e09d03
PT
1290 /** Lock to protect request flags and some other important bits, like
1291 * rq_list
1292 */
1293 spinlock_t rq_lock;
1294 /** client-side flags are serialized by rq_lock */
1295 unsigned int rq_intr:1, rq_replied:1, rq_err:1,
1296 rq_timedout:1, rq_resend:1, rq_restart:1,
1297 /**
1298 * when ->rq_replay is set, request is kept by the client even
1299 * after server commits corresponding transaction. This is
1300 * used for operations that require sequence of multiple
1301 * requests to be replayed. The only example currently is file
1302 * open/close. When last request in such a sequence is
1303 * committed, ->rq_replay is cleared on all requests in the
1304 * sequence.
1305 */
1306 rq_replay:1,
1307 rq_no_resend:1, rq_waiting:1, rq_receiving_reply:1,
1308 rq_no_delay:1, rq_net_err:1, rq_wait_ctx:1,
cf378ff7
AL
1309 rq_early:1,
1310 rq_req_unlink:1, rq_reply_unlink:1,
d7e09d03
PT
1311 rq_memalloc:1, /* req originated from "kswapd" */
1312 /* server-side flags */
1313 rq_packed_final:1, /* packed final reply */
1314 rq_hp:1, /* high priority RPC */
1315 rq_at_linked:1, /* link into service's srv_at_array */
1316 rq_reply_truncate:1,
1317 rq_committed:1,
1318 /* whether the "rq_set" is a valid one */
1319 rq_invalid_rqset:1,
1320 rq_generation_set:1,
1321 /* do not resend request on -EINPROGRESS */
1322 rq_no_retry_einprogress:1,
1323 /* allow the req to be sent if the import is in recovery
c56e256d
OD
1324 * status
1325 */
ac5b1481
PS
1326 rq_allow_replay:1,
1327 /* bulk request, sent to server, but uncommitted */
1328 rq_unstable:1;
d7e09d03
PT
1329
1330 unsigned int rq_nr_resend;
1331
1332 enum rq_phase rq_phase; /* one of RQ_PHASE_* */
1333 enum rq_phase rq_next_phase; /* one of RQ_PHASE_* to be used next */
c56e256d
OD
1334 atomic_t rq_refcount; /* client-side refcount for SENT race,
1335 * server-side refcount for multiple replies
1336 */
d7e09d03
PT
1337
1338 /** Portal to which this request would be sent */
1339 short rq_request_portal; /* XXX FIXME bug 249 */
1340 /** Portal where to wait for reply and where reply would be sent */
1341 short rq_reply_portal; /* XXX FIXME bug 249 */
1342
1343 /**
1344 * client-side:
1345 * !rq_truncate : # reply bytes actually received,
1346 * rq_truncate : required repbuf_len for resend
1347 */
1348 int rq_nob_received;
1349 /** Request length */
1350 int rq_reqlen;
1351 /** Reply length */
1352 int rq_replen;
1353 /** Request message - what client sent */
1354 struct lustre_msg *rq_reqmsg;
1355 /** Reply message - server response */
1356 struct lustre_msg *rq_repmsg;
1357 /** Transaction number */
1358 __u64 rq_transno;
1359 /** xid */
1360 __u64 rq_xid;
1361 /**
17891183 1362 * List item to for replay list. Not yet committed requests get linked
d7e09d03
PT
1363 * there.
1364 * Also see \a rq_replay comment above.
1365 */
1366 struct list_head rq_replay_list;
1367
1368 /**
1369 * security and encryption data
c56e256d
OD
1370 * @{
1371 */
d7e09d03
PT
1372 struct ptlrpc_cli_ctx *rq_cli_ctx; /**< client's half ctx */
1373 struct ptlrpc_svc_ctx *rq_svc_ctx; /**< server's half ctx */
1374 struct list_head rq_ctx_chain; /**< link to waited ctx */
1375
1376 struct sptlrpc_flavor rq_flvr; /**< for client & server */
1377 enum lustre_sec_part rq_sp_from;
1378
1379 /* client/server security flags */
1380 unsigned int
1381 rq_ctx_init:1, /* context initiation */
1382 rq_ctx_fini:1, /* context destroy */
1383 rq_bulk_read:1, /* request bulk read */
1384 rq_bulk_write:1, /* request bulk write */
1385 /* server authentication flags */
1386 rq_auth_gss:1, /* authenticated by gss */
1387 rq_auth_remote:1, /* authed as remote user */
1388 rq_auth_usr_root:1, /* authed as root */
1389 rq_auth_usr_mdt:1, /* authed as mdt */
1390 rq_auth_usr_ost:1, /* authed as ost */
1391 /* security tfm flags */
1392 rq_pack_udesc:1,
1393 rq_pack_bulk:1,
1394 /* doesn't expect reply FIXME */
1395 rq_no_reply:1,
1396 rq_pill_init:1; /* pill initialized */
1397
1398 uid_t rq_auth_uid; /* authed uid */
1399 uid_t rq_auth_mapped_uid; /* authed uid mapped to */
1400
1401 /* (server side), pointed directly into req buffer */
1402 struct ptlrpc_user_desc *rq_user_desc;
1403
1404 /* various buffer pointers */
1405 struct lustre_msg *rq_reqbuf; /* req wrapper */
1406 char *rq_repbuf; /* rep buffer */
1407 struct lustre_msg *rq_repdata; /* rep wrapper msg */
1408 struct lustre_msg *rq_clrbuf; /* only in priv mode */
1409 int rq_reqbuf_len; /* req wrapper buf len */
1410 int rq_reqdata_len; /* req wrapper msg len */
1411 int rq_repbuf_len; /* rep buffer len */
1412 int rq_repdata_len; /* rep wrapper msg len */
1413 int rq_clrbuf_len; /* only in priv mode */
1414 int rq_clrdata_len; /* only in priv mode */
1415
1416 /** early replies go to offset 0, regular replies go after that */
1417 unsigned int rq_reply_off;
1418
1419 /** @} */
1420
1421 /** Fields that help to see if request and reply were swabbed or not */
1422 __u32 rq_req_swab_mask;
1423 __u32 rq_rep_swab_mask;
1424
1425 /** What was import generation when this request was sent */
1426 int rq_import_generation;
1427 enum lustre_imp_state rq_send_state;
1428
1429 /** how many early replies (for stats) */
1430 int rq_early_count;
1431
1432 /** client+server request */
1433 lnet_handle_md_t rq_req_md_h;
1434 struct ptlrpc_cb_id rq_req_cbid;
1435 /** optional time limit for send attempts */
b2d201bd 1436 long rq_delay_limit;
d7e09d03 1437 /** time request was first queued */
a649ad1d 1438 unsigned long rq_queued_time;
d7e09d03
PT
1439
1440 /* server-side... */
1441 /** request arrival time */
219e6de6 1442 struct timespec64 rq_arrival_time;
d7e09d03
PT
1443 /** separated reply state */
1444 struct ptlrpc_reply_state *rq_reply_state;
1445 /** incoming request buffer */
1446 struct ptlrpc_request_buffer_desc *rq_rqbd;
1447
1448 /** client-only incoming reply */
1449 lnet_handle_md_t rq_reply_md_h;
1450 wait_queue_head_t rq_reply_waitq;
1451 struct ptlrpc_cb_id rq_reply_cbid;
1452
1453 /** our LNet NID */
1454 lnet_nid_t rq_self;
1455 /** Peer description (the other side) */
1456 lnet_process_id_t rq_peer;
1457 /** Server-side, export on which request was received */
1458 struct obd_export *rq_export;
1459 /** Client side, import where request is being sent */
1460 struct obd_import *rq_import;
1461
1462 /** Replay callback, called after request is replayed at recovery */
1463 void (*rq_replay_cb)(struct ptlrpc_request *);
1464 /**
1465 * Commit callback, called when request is committed and about to be
1466 * freed.
1467 */
1468 void (*rq_commit_cb)(struct ptlrpc_request *);
1469 /** Opaq data for replay and commit callbacks. */
1470 void *rq_cb_data;
1471
1472 /** For bulk requests on client only: bulk descriptor */
1473 struct ptlrpc_bulk_desc *rq_bulk;
1474
1475 /** client outgoing req */
1476 /**
1477 * when request/reply sent (secs), or time when request should be sent
1478 */
219e6de6 1479 time64_t rq_sent;
d7e09d03 1480 /** time for request really sent out */
219e6de6 1481 time64_t rq_real_sent;
d7e09d03
PT
1482
1483 /** when request must finish. volatile
1484 * so that servers' early reply updates to the deadline aren't
c56e256d
OD
1485 * kept in per-cpu cache
1486 */
219e6de6 1487 volatile time64_t rq_deadline;
d7e09d03 1488 /** when req reply unlink must finish. */
219e6de6 1489 time64_t rq_reply_deadline;
d7e09d03 1490 /** when req bulk unlink must finish. */
219e6de6 1491 time64_t rq_bulk_deadline;
d7e09d03
PT
1492 /**
1493 * service time estimate (secs)
1494 * If the requestsis not served by this time, it is marked as timed out.
1495 */
1496 int rq_timeout;
1497
1498 /** Multi-rpc bits */
1499 /** Per-request waitq introduced by bug 21938 for recovery waiting */
1500 wait_queue_head_t rq_set_waitq;
1501 /** Link item for request set lists */
1502 struct list_head rq_set_chain;
1503 /** Link back to the request set */
1504 struct ptlrpc_request_set *rq_set;
1505 /** Async completion handler, called when reply is received */
1506 ptlrpc_interpterer_t rq_interpret_reply;
1507 /** Async completion context */
1508 union ptlrpc_async_args rq_async_args;
1509
1510 /** Pool if request is from preallocated list */
1511 struct ptlrpc_request_pool *rq_pool;
1512
1513 struct lu_context rq_session;
1514 struct lu_context rq_recov_session;
1515
1516 /** request format description */
1517 struct req_capsule rq_pill;
1518};
1519
1520/**
1521 * Call completion handler for rpc if any, return it's status or original
1522 * rc if there was no handler defined for this request.
1523 */
1524static inline int ptlrpc_req_interpret(const struct lu_env *env,
1525 struct ptlrpc_request *req, int rc)
1526{
d2a13989 1527 if (req->rq_interpret_reply) {
d7e09d03
PT
1528 req->rq_status = req->rq_interpret_reply(env, req,
1529 &req->rq_async_args,
1530 rc);
1531 return req->rq_status;
1532 }
1533 return rc;
1534}
1535
d7e09d03
PT
1536/*
1537 * Can the request be moved from the regular NRS head to the high-priority NRS
1538 * head (of the same PTLRPC service partition), if any?
1539 *
1540 * For a reliable result, this should be checked under svcpt->scp_req lock.
1541 */
1542static inline bool ptlrpc_nrs_req_can_move(struct ptlrpc_request *req)
1543{
1544 struct ptlrpc_nrs_request *nrq = &req->rq_nrq;
1545
1546 /**
1547 * LU-898: Check ptlrpc_nrs_request::nr_enqueued to make sure the
1548 * request has been enqueued first, and ptlrpc_nrs_request::nr_started
1549 * to make sure it has not been scheduled yet (analogous to previous
1550 * (non-NRS) checking of !list_empty(&ptlrpc_request::rq_list).
1551 */
1552 return nrq->nr_enqueued && !nrq->nr_started && !req->rq_hp;
1553}
c9f6bb96 1554
d7e09d03
PT
1555/** @} nrs */
1556
1557/**
1558 * Returns 1 if request buffer at offset \a index was already swabbed
1559 */
1560static inline int lustre_req_swabbed(struct ptlrpc_request *req, int index)
1561{
1562 LASSERT(index < sizeof(req->rq_req_swab_mask) * 8);
1563 return req->rq_req_swab_mask & (1 << index);
1564}
1565
1566/**
1567 * Returns 1 if request reply buffer at offset \a index was already swabbed
1568 */
1569static inline int lustre_rep_swabbed(struct ptlrpc_request *req, int index)
1570{
1571 LASSERT(index < sizeof(req->rq_rep_swab_mask) * 8);
1572 return req->rq_rep_swab_mask & (1 << index);
1573}
1574
1575/**
1576 * Returns 1 if request needs to be swabbed into local cpu byteorder
1577 */
1578static inline int ptlrpc_req_need_swab(struct ptlrpc_request *req)
1579{
1580 return lustre_req_swabbed(req, MSG_PTLRPC_HEADER_OFF);
1581}
1582
1583/**
1584 * Returns 1 if request reply needs to be swabbed into local cpu byteorder
1585 */
1586static inline int ptlrpc_rep_need_swab(struct ptlrpc_request *req)
1587{
1588 return lustre_rep_swabbed(req, MSG_PTLRPC_HEADER_OFF);
1589}
1590
1591/**
1592 * Mark request buffer at offset \a index that it was already swabbed
1593 */
1594static inline void lustre_set_req_swabbed(struct ptlrpc_request *req, int index)
1595{
1596 LASSERT(index < sizeof(req->rq_req_swab_mask) * 8);
1597 LASSERT((req->rq_req_swab_mask & (1 << index)) == 0);
1598 req->rq_req_swab_mask |= 1 << index;
1599}
1600
1601/**
1602 * Mark request reply buffer at offset \a index that it was already swabbed
1603 */
1604static inline void lustre_set_rep_swabbed(struct ptlrpc_request *req, int index)
1605{
1606 LASSERT(index < sizeof(req->rq_rep_swab_mask) * 8);
1607 LASSERT((req->rq_rep_swab_mask & (1 << index)) == 0);
1608 req->rq_rep_swab_mask |= 1 << index;
1609}
1610
1611/**
1612 * Convert numerical request phase value \a phase into text string description
1613 */
1614static inline const char *
1615ptlrpc_phase2str(enum rq_phase phase)
1616{
1617 switch (phase) {
1618 case RQ_PHASE_NEW:
1619 return "New";
1620 case RQ_PHASE_RPC:
1621 return "Rpc";
1622 case RQ_PHASE_BULK:
1623 return "Bulk";
1624 case RQ_PHASE_INTERPRET:
1625 return "Interpret";
1626 case RQ_PHASE_COMPLETE:
1627 return "Complete";
1628 case RQ_PHASE_UNREGISTERING:
1629 return "Unregistering";
1630 default:
1631 return "?Phase?";
1632 }
1633}
1634
1635/**
1636 * Convert numerical request phase of the request \a req into text stringi
1637 * description
1638 */
1639static inline const char *
1640ptlrpc_rqphase2str(struct ptlrpc_request *req)
1641{
1642 return ptlrpc_phase2str(req->rq_phase);
1643}
1644
1645/**
1646 * Debugging functions and helpers to print request structure into debug log
1647 * @{
1648 */
1649/* Spare the preprocessor, spoil the bugs. */
1650#define FLAG(field, str) (field ? str : "")
1651
1652/** Convert bit flags into a string */
1653#define DEBUG_REQ_FLAGS(req) \
1654 ptlrpc_rqphase2str(req), \
1655 FLAG(req->rq_intr, "I"), FLAG(req->rq_replied, "R"), \
1656 FLAG(req->rq_err, "E"), \
1657 FLAG(req->rq_timedout, "X") /* eXpired */, FLAG(req->rq_resend, "S"), \
1658 FLAG(req->rq_restart, "T"), FLAG(req->rq_replay, "P"), \
1659 FLAG(req->rq_no_resend, "N"), \
1660 FLAG(req->rq_waiting, "W"), \
1661 FLAG(req->rq_wait_ctx, "C"), FLAG(req->rq_hp, "H"), \
1662 FLAG(req->rq_committed, "M")
1663
1664#define REQ_FLAGS_FMT "%s:%s%s%s%s%s%s%s%s%s%s%s%s"
1665
1666void _debug_req(struct ptlrpc_request *req,
1667 struct libcfs_debug_msg_data *data, const char *fmt, ...)
70837c12 1668 __printf(3, 4);
d7e09d03
PT
1669
1670/**
17891183 1671 * Helper that decides if we need to print request according to current debug
d7e09d03
PT
1672 * level settings
1673 */
1674#define debug_req(msgdata, mask, cdls, req, fmt, a...) \
1675do { \
1676 CFS_CHECK_STACK(msgdata, mask, cdls); \
1677 \
1678 if (((mask) & D_CANTMASK) != 0 || \
1679 ((libcfs_debug & (mask)) != 0 && \
1680 (libcfs_subsystem_debug & DEBUG_SUBSYSTEM) != 0)) \
1681 _debug_req((req), msgdata, fmt, ##a); \
a58a38ac 1682} while (0)
d7e09d03
PT
1683
1684/**
17891183 1685 * This is the debug print function you need to use to print request structure
d7e09d03 1686 * content into lustre debug log.
c56e256d
OD
1687 * for most callers (level is a constant) this is resolved at compile time
1688 */
d7e09d03
PT
1689#define DEBUG_REQ(level, req, fmt, args...) \
1690do { \
1691 if ((level) & (D_ERROR | D_WARNING)) { \
a3ea59e0 1692 static struct cfs_debug_limit_state cdls; \
d7e09d03
PT
1693 LIBCFS_DEBUG_MSG_DATA_DECL(msgdata, level, &cdls); \
1694 debug_req(&msgdata, level, &cdls, req, "@@@ "fmt" ", ## args);\
1695 } else { \
1696 LIBCFS_DEBUG_MSG_DATA_DECL(msgdata, level, NULL); \
1697 debug_req(&msgdata, level, NULL, req, "@@@ "fmt" ", ## args); \
1698 } \
1699} while (0)
1700/** @} */
1701
1702/**
1703 * Structure that defines a single page of a bulk transfer
1704 */
1705struct ptlrpc_bulk_page {
1706 /** Linkage to list of pages in a bulk */
1707 struct list_head bp_link;
1708 /**
1709 * Number of bytes in a page to transfer starting from \a bp_pageoffset
1710 */
1711 int bp_buflen;
1712 /** offset within a page */
1713 int bp_pageoffset;
1714 /** The page itself */
1715 struct page *bp_page;
1716};
1717
1718#define BULK_GET_SOURCE 0
1719#define BULK_PUT_SINK 1
1720#define BULK_GET_SINK 2
1721#define BULK_PUT_SOURCE 3
1722
1723/**
1724 * Definition of bulk descriptor.
1725 * Bulks are special "Two phase" RPCs where initial request message
1726 * is sent first and it is followed bt a transfer (o receiving) of a large
1727 * amount of data to be settled into pages referenced from the bulk descriptors.
1728 * Bulks transfers (the actual data following the small requests) are done
1729 * on separate LNet portals.
1730 * In lustre we use bulk transfers for READ and WRITE transfers from/to OSTs.
1731 * Another user is readpage for MDT.
1732 */
1733struct ptlrpc_bulk_desc {
1734 /** completed with failure */
1735 unsigned long bd_failure:1;
1736 /** {put,get}{source,sink} */
1737 unsigned long bd_type:2;
1738 /** client side */
1739 unsigned long bd_registered:1;
1740 /** For serialization with callback */
1741 spinlock_t bd_lock;
1742 /** Import generation when request for this bulk was sent */
1743 int bd_import_generation;
1744 /** LNet portal for this bulk */
1745 __u32 bd_portal;
1746 /** Server side - export this bulk created for */
1747 struct obd_export *bd_export;
1748 /** Client side - import this bulk was sent on */
1749 struct obd_import *bd_import;
1750 /** Back pointer to the request */
1751 struct ptlrpc_request *bd_req;
1752 wait_queue_head_t bd_waitq; /* server side only WQ */
1753 int bd_iov_count; /* # entries in bd_iov */
1754 int bd_max_iov; /* allocated size of bd_iov */
1755 int bd_nob; /* # bytes covered */
1756 int bd_nob_transferred; /* # bytes GOT/PUT */
1757
1758 __u64 bd_last_xid;
1759
1760 struct ptlrpc_cb_id bd_cbid; /* network callback info */
1761 lnet_nid_t bd_sender; /* stash event::sender */
1762 int bd_md_count; /* # valid entries in bd_mds */
1763 int bd_md_max_brw; /* max entries in bd_mds */
1764 /** array of associated MDs */
1765 lnet_handle_md_t bd_mds[PTLRPC_BULK_OPS_COUNT];
1766
1767 /*
1768 * encrypt iov, size is either 0 or bd_iov_count.
1769 */
1770 lnet_kiov_t *bd_enc_iov;
1771
1772 lnet_kiov_t bd_iov[0];
1773};
1774
1775enum {
1776 SVC_STOPPED = 1 << 0,
1777 SVC_STOPPING = 1 << 1,
1778 SVC_STARTING = 1 << 2,
1779 SVC_RUNNING = 1 << 3,
1780 SVC_EVENT = 1 << 4,
1781 SVC_SIGNAL = 1 << 5,
1782};
1783
1784#define PTLRPC_THR_NAME_LEN 32
1785/**
1786 * Definition of server service thread structure
1787 */
1788struct ptlrpc_thread {
1789 /**
1790 * List of active threads in svc->srv_threads
1791 */
1792 struct list_head t_link;
1793 /**
1794 * thread-private data (preallocated memory)
1795 */
1796 void *t_data;
1797 __u32 t_flags;
1798 /**
1799 * service thread index, from ptlrpc_start_threads
1800 */
1801 unsigned int t_id;
1802 /**
1803 * service thread pid
1804 */
1805 pid_t t_pid;
1806 /**
1807 * put watchdog in the structure per thread b=14840
5d4450c4
PT
1808 *
1809 * Lustre watchdog is removed for client in the hope
1810 * of a generic watchdog can be merged in kernel.
1811 * When that happens, we should add below back.
1812 *
1813 * struct lc_watchdog *t_watchdog;
d7e09d03 1814 */
d7e09d03
PT
1815 /**
1816 * the svc this thread belonged to b=18582
1817 */
1818 struct ptlrpc_service_part *t_svcpt;
1819 wait_queue_head_t t_ctl_waitq;
1820 struct lu_env *t_env;
1821 char t_name[PTLRPC_THR_NAME_LEN];
1822};
1823
1824static inline int thread_is_init(struct ptlrpc_thread *thread)
1825{
1826 return thread->t_flags == 0;
1827}
1828
1829static inline int thread_is_stopped(struct ptlrpc_thread *thread)
1830{
1831 return !!(thread->t_flags & SVC_STOPPED);
1832}
1833
1834static inline int thread_is_stopping(struct ptlrpc_thread *thread)
1835{
1836 return !!(thread->t_flags & SVC_STOPPING);
1837}
1838
1839static inline int thread_is_starting(struct ptlrpc_thread *thread)
1840{
1841 return !!(thread->t_flags & SVC_STARTING);
1842}
1843
1844static inline int thread_is_running(struct ptlrpc_thread *thread)
1845{
1846 return !!(thread->t_flags & SVC_RUNNING);
1847}
1848
1849static inline int thread_is_event(struct ptlrpc_thread *thread)
1850{
1851 return !!(thread->t_flags & SVC_EVENT);
1852}
1853
1854static inline int thread_is_signal(struct ptlrpc_thread *thread)
1855{
1856 return !!(thread->t_flags & SVC_SIGNAL);
1857}
1858
1859static inline void thread_clear_flags(struct ptlrpc_thread *thread, __u32 flags)
1860{
1861 thread->t_flags &= ~flags;
1862}
1863
1864static inline void thread_set_flags(struct ptlrpc_thread *thread, __u32 flags)
1865{
1866 thread->t_flags = flags;
1867}
1868
1869static inline void thread_add_flags(struct ptlrpc_thread *thread, __u32 flags)
1870{
1871 thread->t_flags |= flags;
1872}
1873
1874static inline int thread_test_and_clear_flags(struct ptlrpc_thread *thread,
1875 __u32 flags)
1876{
1877 if (thread->t_flags & flags) {
1878 thread->t_flags &= ~flags;
1879 return 1;
1880 }
1881 return 0;
1882}
1883
1884/**
1885 * Request buffer descriptor structure.
1886 * This is a structure that contains one posted request buffer for service.
1887 * Once data land into a buffer, event callback creates actual request and
1888 * notifies wakes one of the service threads to process new incoming request.
1889 * More than one request can fit into the buffer.
1890 */
1891struct ptlrpc_request_buffer_desc {
1892 /** Link item for rqbds on a service */
1893 struct list_head rqbd_list;
1894 /** History of requests for this buffer */
1895 struct list_head rqbd_reqs;
1896 /** Back pointer to service for which this buffer is registered */
1897 struct ptlrpc_service_part *rqbd_svcpt;
1898 /** LNet descriptor */
1899 lnet_handle_md_t rqbd_md_h;
1900 int rqbd_refcount;
1901 /** The buffer itself */
1902 char *rqbd_buffer;
1903 struct ptlrpc_cb_id rqbd_cbid;
1904 /**
1905 * This "embedded" request structure is only used for the
1906 * last request to fit into the buffer
1907 */
1908 struct ptlrpc_request rqbd_req;
1909};
1910
1911typedef int (*svc_handler_t)(struct ptlrpc_request *req);
1912
1913struct ptlrpc_service_ops {
1914 /**
1915 * if non-NULL called during thread creation (ptlrpc_start_thread())
1916 * to initialize service specific per-thread state.
1917 */
1918 int (*so_thr_init)(struct ptlrpc_thread *thr);
1919 /**
1920 * if non-NULL called during thread shutdown (ptlrpc_main()) to
1921 * destruct state created by ->srv_init().
1922 */
1923 void (*so_thr_done)(struct ptlrpc_thread *thr);
1924 /**
1925 * Handler function for incoming requests for this service
1926 */
1927 int (*so_req_handler)(struct ptlrpc_request *req);
1928 /**
1929 * function to determine priority of the request, it's called
1930 * on every new request
1931 */
1932 int (*so_hpreq_handler)(struct ptlrpc_request *);
1933 /**
1934 * service-specific print fn
1935 */
1936 void (*so_req_printer)(void *, struct ptlrpc_request *);
1937};
1938
1939#ifndef __cfs_cacheline_aligned
1940/* NB: put it here for reducing patche dependence */
1941# define __cfs_cacheline_aligned
1942#endif
1943
1944/**
1945 * How many high priority requests to serve before serving one normal
1946 * priority request
1947 */
1948#define PTLRPC_SVC_HP_RATIO 10
1949
1950/**
1951 * Definition of PortalRPC service.
1952 * The service is listening on a particular portal (like tcp port)
1953 * and perform actions for a specific server like IO service for OST
1954 * or general metadata service for MDS.
1955 */
1956struct ptlrpc_service {
f6e42a40 1957 /** serialize sysfs operations */
d7e09d03
PT
1958 spinlock_t srv_lock;
1959 /** most often accessed fields */
1960 /** chain thru all services */
1961 struct list_head srv_list;
1962 /** service operations table */
1963 struct ptlrpc_service_ops srv_ops;
1964 /** only statically allocated strings here; we don't clean them */
1965 char *srv_name;
1966 /** only statically allocated strings here; we don't clean them */
1967 char *srv_thread_name;
1968 /** service thread list */
1969 struct list_head srv_threads;
1970 /** threads # should be created for each partition on initializing */
1971 int srv_nthrs_cpt_init;
1972 /** limit of threads number for each partition */
1973 int srv_nthrs_cpt_limit;
700815d4
DE
1974 /** Root of debugfs dir tree for this service */
1975 struct dentry *srv_debugfs_entry;
d7e09d03
PT
1976 /** Pointer to statistic data for this service */
1977 struct lprocfs_stats *srv_stats;
1978 /** # hp per lp reqs to handle */
1979 int srv_hpreq_ratio;
1980 /** biggest request to receive */
1981 int srv_max_req_size;
1982 /** biggest reply to send */
1983 int srv_max_reply_size;
1984 /** size of individual buffers */
1985 int srv_buf_size;
1986 /** # buffers to allocate in 1 group */
1987 int srv_nbuf_per_group;
1988 /** Local portal on which to receive requests */
1989 __u32 srv_req_portal;
1990 /** Portal on the client to send replies to */
1991 __u32 srv_rep_portal;
1992 /**
1993 * Tags for lu_context associated with this thread, see struct
1994 * lu_context.
1995 */
1996 __u32 srv_ctx_tags;
1997 /** soft watchdog timeout multiplier */
1998 int srv_watchdog_factor;
1999 /** under unregister_service */
2000 unsigned srv_is_stopping:1;
2001
2002 /** max # request buffers in history per partition */
2003 int srv_hist_nrqbds_cpt_max;
2004 /** number of CPTs this service bound on */
2005 int srv_ncpts;
2006 /** CPTs array this service bound on */
2007 __u32 *srv_cpts;
2008 /** 2^srv_cptab_bits >= cfs_cpt_numbert(srv_cptable) */
2009 int srv_cpt_bits;
2010 /** CPT table this service is running over */
2011 struct cfs_cpt_table *srv_cptable;
328676f8
OD
2012
2013 /* sysfs object */
2014 struct kobject srv_kobj;
2015 struct completion srv_kobj_unregister;
d7e09d03
PT
2016 /**
2017 * partition data for ptlrpc service
2018 */
2019 struct ptlrpc_service_part *srv_parts[0];
2020};
2021
2022/**
2023 * Definition of PortalRPC service partition data.
2024 * Although a service only has one instance of it right now, but we
2025 * will have multiple instances very soon (instance per CPT).
2026 *
2027 * it has four locks:
2028 * \a scp_lock
2029 * serialize operations on rqbd and requests waiting for preprocess
2030 * \a scp_req_lock
2031 * serialize operations active requests sent to this portal
2032 * \a scp_at_lock
2033 * serialize adaptive timeout stuff
2034 * \a scp_rep_lock
2035 * serialize operations on RS list (reply states)
2036 *
2037 * We don't have any use-case to take two or more locks at the same time
2038 * for now, so there is no lock order issue.
2039 */
2040struct ptlrpc_service_part {
2041 /** back reference to owner */
2042 struct ptlrpc_service *scp_service __cfs_cacheline_aligned;
2043 /* CPT id, reserved */
2044 int scp_cpt;
2045 /** always increasing number */
2046 int scp_thr_nextid;
2047 /** # of starting threads */
2048 int scp_nthrs_starting;
2049 /** # of stopping threads, reserved for shrinking threads */
2050 int scp_nthrs_stopping;
2051 /** # running threads */
2052 int scp_nthrs_running;
2053 /** service threads list */
2054 struct list_head scp_threads;
2055
2056 /**
2057 * serialize the following fields, used for protecting
2058 * rqbd list and incoming requests waiting for preprocess,
2059 * threads starting & stopping are also protected by this lock.
2060 */
b2952d62 2061 spinlock_t scp_lock __cfs_cacheline_aligned;
d7e09d03
PT
2062 /** total # req buffer descs allocated */
2063 int scp_nrqbds_total;
2064 /** # posted request buffers for receiving */
2065 int scp_nrqbds_posted;
2066 /** in progress of allocating rqbd */
2067 int scp_rqbd_allocating;
2068 /** # incoming reqs */
2069 int scp_nreqs_incoming;
2070 /** request buffers to be reposted */
2071 struct list_head scp_rqbd_idle;
2072 /** req buffers receiving */
2073 struct list_head scp_rqbd_posted;
2074 /** incoming reqs */
2075 struct list_head scp_req_incoming;
2076 /** timeout before re-posting reqs, in tick */
b2d201bd 2077 long scp_rqbd_timeout;
d7e09d03
PT
2078 /**
2079 * all threads sleep on this. This wait-queue is signalled when new
2080 * incoming request arrives and when difficult reply has to be handled.
2081 */
2082 wait_queue_head_t scp_waitq;
2083
2084 /** request history */
2085 struct list_head scp_hist_reqs;
2086 /** request buffer history */
2087 struct list_head scp_hist_rqbds;
2088 /** # request buffers in history */
2089 int scp_hist_nrqbds;
2090 /** sequence number for request */
2091 __u64 scp_hist_seq;
2092 /** highest seq culled from history */
2093 __u64 scp_hist_seq_culled;
2094
2095 /**
2096 * serialize the following fields, used for processing requests
2097 * sent to this portal
2098 */
2099 spinlock_t scp_req_lock __cfs_cacheline_aligned;
2100 /** # reqs in either of the NRS heads below */
2101 /** # reqs being served */
2102 int scp_nreqs_active;
2103 /** # HPreqs being served */
2104 int scp_nhreqs_active;
2105 /** # hp requests handled */
2106 int scp_hreq_count;
2107
2108 /** NRS head for regular requests */
2109 struct ptlrpc_nrs scp_nrs_reg;
2110 /** NRS head for HP requests; this is only valid for services that can
c56e256d
OD
2111 * handle HP requests
2112 */
d7e09d03
PT
2113 struct ptlrpc_nrs *scp_nrs_hp;
2114
2115 /** AT stuff */
2116 /** @{ */
2117 /**
2118 * serialize the following fields, used for changes on
2119 * adaptive timeout
2120 */
2121 spinlock_t scp_at_lock __cfs_cacheline_aligned;
2122 /** estimated rpc service time */
2123 struct adaptive_timeout scp_at_estimate;
2124 /** reqs waiting for replies */
2125 struct ptlrpc_at_array scp_at_array;
2126 /** early reply timer */
54319351 2127 struct timer_list scp_at_timer;
d7e09d03 2128 /** debug */
a649ad1d 2129 unsigned long scp_at_checktime;
d7e09d03
PT
2130 /** check early replies */
2131 unsigned scp_at_check;
2132 /** @} */
2133
2134 /**
2135 * serialize the following fields, used for processing
2136 * replies for this portal
2137 */
2138 spinlock_t scp_rep_lock __cfs_cacheline_aligned;
2139 /** all the active replies */
2140 struct list_head scp_rep_active;
2141 /** List of free reply_states */
2142 struct list_head scp_rep_idle;
2143 /** waitq to run, when adding stuff to srv_free_rs_list */
2144 wait_queue_head_t scp_rep_waitq;
2145 /** # 'difficult' replies */
2146 atomic_t scp_nreps_difficult;
2147};
2148
2149#define ptlrpc_service_for_each_part(part, i, svc) \
2150 for (i = 0; \
2151 i < (svc)->srv_ncpts && \
d2a13989
OD
2152 (svc)->srv_parts && \
2153 ((part) = (svc)->srv_parts[i]); i++)
d7e09d03
PT
2154
2155/**
2156 * Declaration of ptlrpcd control structure
2157 */
2158struct ptlrpcd_ctl {
2159 /**
2160 * Ptlrpc thread control flags (LIOD_START, LIOD_STOP, LIOD_FORCE)
2161 */
2162 unsigned long pc_flags;
2163 /**
2164 * Thread lock protecting structure fields.
2165 */
2166 spinlock_t pc_lock;
2167 /**
2168 * Start completion.
2169 */
2170 struct completion pc_starting;
2171 /**
2172 * Stop completion.
2173 */
2174 struct completion pc_finishing;
2175 /**
2176 * Thread requests set.
2177 */
2178 struct ptlrpc_request_set *pc_set;
2179 /**
f72f130d 2180 * Thread name used in kthread_run()
d7e09d03
PT
2181 */
2182 char pc_name[16];
2183 /**
2184 * Environment for request interpreters to run in.
2185 */
2186 struct lu_env pc_env;
2187 /**
c5c4c6fa 2188 * CPT the thread is bound on.
d7e09d03 2189 */
c5c4c6fa 2190 int pc_cpt;
d7e09d03 2191 /**
c5c4c6fa 2192 * Index of ptlrpcd thread in the array.
d7e09d03 2193 */
c5c4c6fa 2194 int pc_index;
d7e09d03
PT
2195 /**
2196 * Pointer to the array of partners' ptlrpcd_ctl structure.
2197 */
2198 struct ptlrpcd_ctl **pc_partners;
c5c4c6fa
OW
2199 /**
2200 * Number of the ptlrpcd's partners.
2201 */
2202 int pc_npartners;
d7e09d03
PT
2203 /**
2204 * Record the partner index to be processed next.
2205 */
2206 int pc_cursor;
c5c4c6fa
OW
2207 /**
2208 * Error code if the thread failed to fully start.
2209 */
2210 int pc_error;
d7e09d03
PT
2211};
2212
2213/* Bits for pc_flags */
2214enum ptlrpcd_ctl_flags {
2215 /**
2216 * Ptlrpc thread start flag.
2217 */
2218 LIOD_START = 1 << 0,
2219 /**
2220 * Ptlrpc thread stop flag.
2221 */
2222 LIOD_STOP = 1 << 1,
2223 /**
2224 * Ptlrpc thread force flag (only stop force so far).
2225 * This will cause aborting any inflight rpcs handled
2226 * by thread if LIOD_STOP is specified.
2227 */
2228 LIOD_FORCE = 1 << 2,
2229 /**
2230 * This is a recovery ptlrpc thread.
2231 */
2232 LIOD_RECOVERY = 1 << 3,
d7e09d03
PT
2233};
2234
2235/**
2236 * \addtogroup nrs
2237 * @{
2238 *
2239 * Service compatibility function; the policy is compatible with all services.
2240 *
2241 * \param[in] svc The service the policy is attempting to register with.
2242 * \param[in] desc The policy descriptor
2243 *
2244 * \retval true The policy is compatible with the service
2245 *
2246 * \see ptlrpc_nrs_pol_desc::pd_compat()
2247 */
2248static inline bool nrs_policy_compat_all(const struct ptlrpc_service *svc,
2249 const struct ptlrpc_nrs_pol_desc *desc)
2250{
2251 return true;
2252}
2253
2254/**
2255 * Service compatibility function; the policy is compatible with only a specific
2256 * service which is identified by its human-readable name at
2257 * ptlrpc_service::srv_name.
2258 *
2259 * \param[in] svc The service the policy is attempting to register with.
2260 * \param[in] desc The policy descriptor
2261 *
2262 * \retval false The policy is not compatible with the service
2263 * \retval true The policy is compatible with the service
2264 *
2265 * \see ptlrpc_nrs_pol_desc::pd_compat()
2266 */
2267static inline bool nrs_policy_compat_one(const struct ptlrpc_service *svc,
2268 const struct ptlrpc_nrs_pol_desc *desc)
2269{
d7e09d03
PT
2270 return strcmp(svc->srv_name, desc->pd_compat_svc_name) == 0;
2271}
2272
2273/** @} nrs */
2274
2275/* ptlrpc/events.c */
2276extern lnet_handle_eq_t ptlrpc_eq_h;
8150a97f
JP
2277int ptlrpc_uuid_to_peer(struct obd_uuid *uuid,
2278 lnet_process_id_t *peer, lnet_nid_t *self);
d7e09d03
PT
2279/**
2280 * These callbacks are invoked by LNet when something happened to
2281 * underlying buffer
2282 * @{
2283 */
8150a97f
JP
2284void request_out_callback(lnet_event_t *ev);
2285void reply_in_callback(lnet_event_t *ev);
2286void client_bulk_callback(lnet_event_t *ev);
2287void request_in_callback(lnet_event_t *ev);
2288void reply_out_callback(lnet_event_t *ev);
d7e09d03
PT
2289/** @} */
2290
2291/* ptlrpc/connection.c */
2292struct ptlrpc_connection *ptlrpc_connection_get(lnet_process_id_t peer,
2293 lnet_nid_t self,
2294 struct obd_uuid *uuid);
2295int ptlrpc_connection_put(struct ptlrpc_connection *c);
2296struct ptlrpc_connection *ptlrpc_connection_addref(struct ptlrpc_connection *);
2297int ptlrpc_connection_init(void);
2298void ptlrpc_connection_fini(void);
d7e09d03
PT
2299
2300/* ptlrpc/niobuf.c */
2301/**
2302 * Actual interfacing with LNet to put/get/register/unregister stuff
2303 * @{
2304 */
2305
d7e09d03
PT
2306int ptlrpc_unregister_bulk(struct ptlrpc_request *req, int async);
2307
2308static inline int ptlrpc_client_bulk_active(struct ptlrpc_request *req)
2309{
2310 struct ptlrpc_bulk_desc *desc;
2311 int rc;
2312
d7e09d03
PT
2313 desc = req->rq_bulk;
2314
2315 if (OBD_FAIL_CHECK(OBD_FAIL_PTLRPC_LONG_BULK_UNLINK) &&
219e6de6 2316 req->rq_bulk_deadline > ktime_get_real_seconds())
d7e09d03
PT
2317 return 1;
2318
2319 if (!desc)
2320 return 0;
2321
2322 spin_lock(&desc->bd_lock);
2323 rc = desc->bd_md_count;
2324 spin_unlock(&desc->bd_lock);
2325 return rc;
2326}
2327
2328#define PTLRPC_REPLY_MAYBE_DIFFICULT 0x01
2329#define PTLRPC_REPLY_EARLY 0x02
2330int ptlrpc_send_reply(struct ptlrpc_request *req, int flags);
2331int ptlrpc_reply(struct ptlrpc_request *req);
2332int ptlrpc_send_error(struct ptlrpc_request *req, int difficult);
2333int ptlrpc_error(struct ptlrpc_request *req);
2334void ptlrpc_resend_req(struct ptlrpc_request *request);
2335int ptlrpc_at_get_net_latency(struct ptlrpc_request *req);
2336int ptl_send_rpc(struct ptlrpc_request *request, int noreply);
2337int ptlrpc_register_rqbd(struct ptlrpc_request_buffer_desc *rqbd);
2338/** @} */
2339
2340/* ptlrpc/client.c */
2341/**
2342 * Client-side portals API. Everything to send requests, receive replies,
2343 * request queues, request management, etc.
2344 * @{
2345 */
63d42578
HZ
2346void ptlrpc_request_committed(struct ptlrpc_request *req, int force);
2347
d7e09d03
PT
2348void ptlrpc_init_client(int req_portal, int rep_portal, char *name,
2349 struct ptlrpc_client *);
d7e09d03
PT
2350struct ptlrpc_connection *ptlrpc_uuid_to_connection(struct obd_uuid *uuid);
2351
2352int ptlrpc_queue_wait(struct ptlrpc_request *req);
2353int ptlrpc_replay_req(struct ptlrpc_request *req);
2354int ptlrpc_unregister_reply(struct ptlrpc_request *req, int async);
d7e09d03 2355void ptlrpc_abort_inflight(struct obd_import *imp);
d7e09d03
PT
2356void ptlrpc_abort_set(struct ptlrpc_request_set *set);
2357
2358struct ptlrpc_request_set *ptlrpc_prep_set(void);
2359struct ptlrpc_request_set *ptlrpc_prep_fcset(int max, set_producer_func func,
2360 void *arg);
d7e09d03
PT
2361int ptlrpc_set_next_timeout(struct ptlrpc_request_set *);
2362int ptlrpc_check_set(const struct lu_env *env, struct ptlrpc_request_set *set);
2363int ptlrpc_set_wait(struct ptlrpc_request_set *);
2364int ptlrpc_expired_set(void *data);
2365void ptlrpc_interrupted_set(void *data);
2366void ptlrpc_mark_interrupted(struct ptlrpc_request *req);
2367void ptlrpc_set_destroy(struct ptlrpc_request_set *);
2368void ptlrpc_set_add_req(struct ptlrpc_request_set *, struct ptlrpc_request *);
2369void ptlrpc_set_add_new_req(struct ptlrpcd_ctl *pc,
2370 struct ptlrpc_request *req);
2371
2372void ptlrpc_free_rq_pool(struct ptlrpc_request_pool *pool);
aefd9d71 2373int ptlrpc_add_rqs_to_pool(struct ptlrpc_request_pool *pool, int num_rq);
d7e09d03
PT
2374
2375struct ptlrpc_request_pool *
2376ptlrpc_init_rq_pool(int, int,
aefd9d71 2377 int (*populate_pool)(struct ptlrpc_request_pool *, int));
d7e09d03
PT
2378
2379void ptlrpc_at_set_req_timeout(struct ptlrpc_request *req);
2380struct ptlrpc_request *ptlrpc_request_alloc(struct obd_import *imp,
2381 const struct req_format *format);
2382struct ptlrpc_request *ptlrpc_request_alloc_pool(struct obd_import *imp,
10457d4b
OD
2383 struct ptlrpc_request_pool *,
2384 const struct req_format *);
d7e09d03
PT
2385void ptlrpc_request_free(struct ptlrpc_request *request);
2386int ptlrpc_request_pack(struct ptlrpc_request *request,
2387 __u32 version, int opcode);
10457d4b
OD
2388struct ptlrpc_request *ptlrpc_request_alloc_pack(struct obd_import *,
2389 const struct req_format *,
2390 __u32, int);
d7e09d03
PT
2391int ptlrpc_request_bufs_pack(struct ptlrpc_request *request,
2392 __u32 version, int opcode, char **bufs,
2393 struct ptlrpc_cli_ctx *ctx);
d7e09d03 2394void ptlrpc_req_finished(struct ptlrpc_request *request);
d7e09d03
PT
2395struct ptlrpc_request *ptlrpc_request_addref(struct ptlrpc_request *req);
2396struct ptlrpc_bulk_desc *ptlrpc_prep_bulk_imp(struct ptlrpc_request *req,
2397 unsigned npages, unsigned max_brw,
2398 unsigned type, unsigned portal);
2399void __ptlrpc_free_bulk(struct ptlrpc_bulk_desc *bulk, int pin);
2400static inline void ptlrpc_free_bulk_pin(struct ptlrpc_bulk_desc *bulk)
2401{
2402 __ptlrpc_free_bulk(bulk, 1);
2403}
c9f6bb96 2404
d7e09d03
PT
2405static inline void ptlrpc_free_bulk_nopin(struct ptlrpc_bulk_desc *bulk)
2406{
2407 __ptlrpc_free_bulk(bulk, 0);
2408}
c9f6bb96 2409
d7e09d03
PT
2410void __ptlrpc_prep_bulk_page(struct ptlrpc_bulk_desc *desc,
2411 struct page *page, int pageoffset, int len, int);
2412static inline void ptlrpc_prep_bulk_page_pin(struct ptlrpc_bulk_desc *desc,
2413 struct page *page, int pageoffset,
2414 int len)
2415{
2416 __ptlrpc_prep_bulk_page(desc, page, pageoffset, len, 1);
2417}
2418
2419static inline void ptlrpc_prep_bulk_page_nopin(struct ptlrpc_bulk_desc *desc,
2420 struct page *page, int pageoffset,
2421 int len)
2422{
2423 __ptlrpc_prep_bulk_page(desc, page, pageoffset, len, 0);
2424}
2425
2426void ptlrpc_retain_replayable_request(struct ptlrpc_request *req,
2427 struct obd_import *imp);
2428__u64 ptlrpc_next_xid(void);
2429__u64 ptlrpc_sample_next_xid(void);
2430__u64 ptlrpc_req_xid(struct ptlrpc_request *request);
2431
2432/* Set of routines to run a function in ptlrpcd context */
2433void *ptlrpcd_alloc_work(struct obd_import *imp,
2434 int (*cb)(const struct lu_env *, void *), void *data);
2435void ptlrpcd_destroy_work(void *handler);
2436int ptlrpcd_queue_work(void *handler);
2437
2438/** @} */
2439struct ptlrpc_service_buf_conf {
2440 /* nbufs is buffers # to allocate when growing the pool */
2441 unsigned int bc_nbufs;
2442 /* buffer size to post */
2443 unsigned int bc_buf_size;
2444 /* portal to listed for requests on */
2445 unsigned int bc_req_portal;
2446 /* portal of where to send replies to */
2447 unsigned int bc_rep_portal;
2448 /* maximum request size to be accepted for this service */
2449 unsigned int bc_req_max_size;
2450 /* maximum reply size this service can ever send */
2451 unsigned int bc_rep_max_size;
2452};
2453
2454struct ptlrpc_service_thr_conf {
2455 /* threadname should be 8 characters or less - 6 will be added on */
2456 char *tc_thr_name;
2457 /* threads increasing factor for each CPU */
2458 unsigned int tc_thr_factor;
2459 /* service threads # to start on each partition while initializing */
2460 unsigned int tc_nthrs_init;
2461 /*
2462 * low water of threads # upper-limit on each partition while running,
2463 * service availability may be impacted if threads number is lower
2464 * than this value. It can be ZERO if the service doesn't require
2465 * CPU affinity or there is only one partition.
2466 */
2467 unsigned int tc_nthrs_base;
2468 /* "soft" limit for total threads number */
2469 unsigned int tc_nthrs_max;
2470 /* user specified threads number, it will be validated due to
c56e256d
OD
2471 * other members of this structure.
2472 */
d7e09d03
PT
2473 unsigned int tc_nthrs_user;
2474 /* set NUMA node affinity for service threads */
2475 unsigned int tc_cpu_affinity;
2476 /* Tags for lu_context associated with service thread */
2477 __u32 tc_ctx_tags;
2478};
2479
2480struct ptlrpc_service_cpt_conf {
2481 struct cfs_cpt_table *cc_cptable;
2482 /* string pattern to describe CPTs for a service */
2483 char *cc_pattern;
2484};
2485
2486struct ptlrpc_service_conf {
2487 /* service name */
2488 char *psc_name;
2489 /* soft watchdog timeout multiplifier to print stuck service traces */
2490 unsigned int psc_watchdog_factor;
2491 /* buffer information */
2492 struct ptlrpc_service_buf_conf psc_buf;
2493 /* thread information */
2494 struct ptlrpc_service_thr_conf psc_thr;
2495 /* CPU partition information */
2496 struct ptlrpc_service_cpt_conf psc_cpt;
2497 /* function table */
2498 struct ptlrpc_service_ops psc_ops;
2499};
2500
2501/* ptlrpc/service.c */
2502/**
2503 * Server-side services API. Register/unregister service, request state
2504 * management, service thread management
2505 *
2506 * @{
2507 */
d7e09d03
PT
2508void ptlrpc_dispatch_difficult_reply(struct ptlrpc_reply_state *rs);
2509void ptlrpc_schedule_difficult_reply(struct ptlrpc_reply_state *rs);
10457d4b
OD
2510struct ptlrpc_service *ptlrpc_register_service(struct ptlrpc_service_conf *conf,
2511 struct kset *parent,
2512 struct dentry *debugfs_entry);
d7e09d03
PT
2513
2514int ptlrpc_start_threads(struct ptlrpc_service *svc);
2515int ptlrpc_unregister_service(struct ptlrpc_service *service);
d7e09d03
PT
2516
2517int ptlrpc_hr_init(void);
2518void ptlrpc_hr_fini(void);
2519
2520/** @} */
2521
2522/* ptlrpc/import.c */
2523/**
2524 * Import API
2525 * @{
2526 */
2527int ptlrpc_connect_import(struct obd_import *imp);
2528int ptlrpc_init_import(struct obd_import *imp);
2529int ptlrpc_disconnect_import(struct obd_import *imp, int noclose);
2530int ptlrpc_import_recovery_state_machine(struct obd_import *imp);
d7e09d03
PT
2531
2532/* ptlrpc/pack_generic.c */
2533int ptlrpc_reconnect_import(struct obd_import *imp);
2534/** @} */
2535
2536/**
2537 * ptlrpc msg buffer and swab interface
2538 *
2539 * @{
2540 */
2541int ptlrpc_buf_need_swab(struct ptlrpc_request *req, const int inout,
2542 int index);
2543void ptlrpc_buf_set_swabbed(struct ptlrpc_request *req, const int inout,
10457d4b 2544 int index);
d7e09d03
PT
2545int ptlrpc_unpack_rep_msg(struct ptlrpc_request *req, int len);
2546int ptlrpc_unpack_req_msg(struct ptlrpc_request *req, int len);
2547
d7e09d03
PT
2548void lustre_init_msg_v2(struct lustre_msg_v2 *msg, int count, __u32 *lens,
2549 char **bufs);
2550int lustre_pack_request(struct ptlrpc_request *, __u32 magic, int count,
2551 __u32 *lens, char **bufs);
2552int lustre_pack_reply(struct ptlrpc_request *, int count, __u32 *lens,
2553 char **bufs);
2554int lustre_pack_reply_v2(struct ptlrpc_request *req, int count,
2555 __u32 *lens, char **bufs, int flags);
2556#define LPRFL_EARLY_REPLY 1
2557int lustre_pack_reply_flags(struct ptlrpc_request *, int count, __u32 *lens,
2558 char **bufs, int flags);
2559int lustre_shrink_msg(struct lustre_msg *msg, int segment,
2560 unsigned int newlen, int move_data);
2561void lustre_free_reply_state(struct ptlrpc_reply_state *rs);
2562int __lustre_unpack_msg(struct lustre_msg *m, int len);
2563int lustre_msg_hdr_size(__u32 magic, int count);
2564int lustre_msg_size(__u32 magic, int count, __u32 *lengths);
2565int lustre_msg_size_v2(int count, __u32 *lengths);
2566int lustre_packed_msg_size(struct lustre_msg *msg);
2567int lustre_msg_early_size(void);
2568void *lustre_msg_buf_v2(struct lustre_msg_v2 *m, int n, int min_size);
2569void *lustre_msg_buf(struct lustre_msg *m, int n, int minlen);
2570int lustre_msg_buflen(struct lustre_msg *m, int n);
d7e09d03
PT
2571int lustre_msg_bufcount(struct lustre_msg *m);
2572char *lustre_msg_string(struct lustre_msg *m, int n, int max_len);
2573__u32 lustre_msghdr_get_flags(struct lustre_msg *msg);
2574void lustre_msghdr_set_flags(struct lustre_msg *msg, __u32 flags);
2575__u32 lustre_msg_get_flags(struct lustre_msg *msg);
2576void lustre_msg_add_flags(struct lustre_msg *msg, int flags);
2577void lustre_msg_set_flags(struct lustre_msg *msg, int flags);
2578void lustre_msg_clear_flags(struct lustre_msg *msg, int flags);
2579__u32 lustre_msg_get_op_flags(struct lustre_msg *msg);
2580void lustre_msg_add_op_flags(struct lustre_msg *msg, int flags);
d7e09d03
PT
2581struct lustre_handle *lustre_msg_get_handle(struct lustre_msg *msg);
2582__u32 lustre_msg_get_type(struct lustre_msg *msg);
d7e09d03
PT
2583void lustre_msg_add_version(struct lustre_msg *msg, int version);
2584__u32 lustre_msg_get_opc(struct lustre_msg *msg);
d7e09d03
PT
2585__u64 lustre_msg_get_last_committed(struct lustre_msg *msg);
2586__u64 *lustre_msg_get_versions(struct lustre_msg *msg);
2587__u64 lustre_msg_get_transno(struct lustre_msg *msg);
2588__u64 lustre_msg_get_slv(struct lustre_msg *msg);
2589__u32 lustre_msg_get_limit(struct lustre_msg *msg);
2590void lustre_msg_set_slv(struct lustre_msg *msg, __u64 slv);
2591void lustre_msg_set_limit(struct lustre_msg *msg, __u64 limit);
2592int lustre_msg_get_status(struct lustre_msg *msg);
2593__u32 lustre_msg_get_conn_cnt(struct lustre_msg *msg);
d7e09d03
PT
2594__u32 lustre_msg_get_magic(struct lustre_msg *msg);
2595__u32 lustre_msg_get_timeout(struct lustre_msg *msg);
2596__u32 lustre_msg_get_service_time(struct lustre_msg *msg);
d7e09d03 2597__u32 lustre_msg_get_cksum(struct lustre_msg *msg);
d7e09d03 2598__u32 lustre_msg_calc_cksum(struct lustre_msg *msg);
1d8cb70c
GD
2599void lustre_msg_set_handle(struct lustre_msg *msg,
2600 struct lustre_handle *handle);
d7e09d03
PT
2601void lustre_msg_set_type(struct lustre_msg *msg, __u32 type);
2602void lustre_msg_set_opc(struct lustre_msg *msg, __u32 opc);
d7e09d03
PT
2603void lustre_msg_set_versions(struct lustre_msg *msg, __u64 *versions);
2604void lustre_msg_set_transno(struct lustre_msg *msg, __u64 transno);
2605void lustre_msg_set_status(struct lustre_msg *msg, __u32 status);
2606void lustre_msg_set_conn_cnt(struct lustre_msg *msg, __u32 conn_cnt);
d7e09d03
PT
2607void ptlrpc_request_set_replen(struct ptlrpc_request *req);
2608void lustre_msg_set_timeout(struct lustre_msg *msg, __u32 timeout);
2609void lustre_msg_set_service_time(struct lustre_msg *msg, __u32 service_time);
2610void lustre_msg_set_jobid(struct lustre_msg *msg, char *jobid);
2611void lustre_msg_set_cksum(struct lustre_msg *msg, __u32 cksum);
2612
2613static inline void
2614lustre_shrink_reply(struct ptlrpc_request *req, int segment,
2615 unsigned int newlen, int move_data)
2616{
2617 LASSERT(req->rq_reply_state);
2618 LASSERT(req->rq_repmsg);
2619 req->rq_replen = lustre_shrink_msg(req->rq_repmsg, segment,
2620 newlen, move_data);
2621}
2d58de78
LW
2622
2623#ifdef CONFIG_LUSTRE_TRANSLATE_ERRNOS
2624
2625static inline int ptlrpc_status_hton(int h)
2626{
2627 /*
2628 * Positive errnos must be network errnos, such as LUSTRE_EDEADLK,
2629 * ELDLM_LOCK_ABORTED, etc.
2630 */
2631 if (h < 0)
2632 return -lustre_errno_hton(-h);
2633 else
2634 return h;
2635}
2636
2637static inline int ptlrpc_status_ntoh(int n)
2638{
2639 /*
2640 * See the comment in ptlrpc_status_hton().
2641 */
2642 if (n < 0)
2643 return -lustre_errno_ntoh(-n);
2644 else
2645 return n;
2646}
2647
2648#else
2649
2650#define ptlrpc_status_hton(h) (h)
2651#define ptlrpc_status_ntoh(n) (n)
2652
2653#endif
d7e09d03
PT
2654/** @} */
2655
2656/** Change request phase of \a req to \a new_phase */
2657static inline void
2658ptlrpc_rqphase_move(struct ptlrpc_request *req, enum rq_phase new_phase)
2659{
2660 if (req->rq_phase == new_phase)
2661 return;
2662
2663 if (new_phase == RQ_PHASE_UNREGISTERING) {
2664 req->rq_next_phase = req->rq_phase;
2665 if (req->rq_import)
2666 atomic_inc(&req->rq_import->imp_unregistering);
2667 }
2668
2669 if (req->rq_phase == RQ_PHASE_UNREGISTERING) {
2670 if (req->rq_import)
2671 atomic_dec(&req->rq_import->imp_unregistering);
2672 }
2673
2674 DEBUG_REQ(D_INFO, req, "move req \"%s\" -> \"%s\"",
2675 ptlrpc_rqphase2str(req), ptlrpc_phase2str(new_phase));
2676
2677 req->rq_phase = new_phase;
2678}
2679
2680/**
2681 * Returns true if request \a req got early reply and hard deadline is not met
2682 */
2683static inline int
2684ptlrpc_client_early(struct ptlrpc_request *req)
2685{
2686 if (OBD_FAIL_CHECK(OBD_FAIL_PTLRPC_LONG_REPL_UNLINK) &&
219e6de6 2687 req->rq_reply_deadline > ktime_get_real_seconds())
d7e09d03
PT
2688 return 0;
2689 return req->rq_early;
2690}
2691
2692/**
2693 * Returns true if we got real reply from server for this request
2694 */
2695static inline int
2696ptlrpc_client_replied(struct ptlrpc_request *req)
2697{
2698 if (OBD_FAIL_CHECK(OBD_FAIL_PTLRPC_LONG_REPL_UNLINK) &&
219e6de6 2699 req->rq_reply_deadline > ktime_get_real_seconds())
d7e09d03
PT
2700 return 0;
2701 return req->rq_replied;
2702}
2703
2704/** Returns true if request \a req is in process of receiving server reply */
2705static inline int
2706ptlrpc_client_recv(struct ptlrpc_request *req)
2707{
2708 if (OBD_FAIL_CHECK(OBD_FAIL_PTLRPC_LONG_REPL_UNLINK) &&
219e6de6 2709 req->rq_reply_deadline > ktime_get_real_seconds())
d7e09d03
PT
2710 return 1;
2711 return req->rq_receiving_reply;
2712}
2713
2714static inline int
2715ptlrpc_client_recv_or_unlink(struct ptlrpc_request *req)
2716{
2717 int rc;
2718
2719 spin_lock(&req->rq_lock);
2720 if (OBD_FAIL_CHECK(OBD_FAIL_PTLRPC_LONG_REPL_UNLINK) &&
219e6de6 2721 req->rq_reply_deadline > ktime_get_real_seconds()) {
d7e09d03
PT
2722 spin_unlock(&req->rq_lock);
2723 return 1;
2724 }
cf378ff7
AL
2725 rc = req->rq_receiving_reply;
2726 rc = rc || req->rq_req_unlink || req->rq_reply_unlink;
d7e09d03
PT
2727 spin_unlock(&req->rq_lock);
2728 return rc;
2729}
2730
2731static inline void
2732ptlrpc_client_wake_req(struct ptlrpc_request *req)
2733{
d2a13989 2734 if (!req->rq_set)
d7e09d03
PT
2735 wake_up(&req->rq_reply_waitq);
2736 else
2737 wake_up(&req->rq_set->set_waitq);
2738}
2739
2740static inline void
2741ptlrpc_rs_addref(struct ptlrpc_reply_state *rs)
2742{
2743 LASSERT(atomic_read(&rs->rs_refcount) > 0);
2744 atomic_inc(&rs->rs_refcount);
2745}
2746
2747static inline void
2748ptlrpc_rs_decref(struct ptlrpc_reply_state *rs)
2749{
2750 LASSERT(atomic_read(&rs->rs_refcount) > 0);
2751 if (atomic_dec_and_test(&rs->rs_refcount))
2752 lustre_free_reply_state(rs);
2753}
2754
2755/* Should only be called once per req */
2756static inline void ptlrpc_req_drop_rs(struct ptlrpc_request *req)
2757{
d2a13989 2758 if (!req->rq_reply_state)
d7e09d03
PT
2759 return; /* shouldn't occur */
2760 ptlrpc_rs_decref(req->rq_reply_state);
2761 req->rq_reply_state = NULL;
2762 req->rq_repmsg = NULL;
2763}
2764
2765static inline __u32 lustre_request_magic(struct ptlrpc_request *req)
2766{
2767 return lustre_msg_get_magic(req->rq_reqmsg);
2768}
2769
2770static inline int ptlrpc_req_get_repsize(struct ptlrpc_request *req)
2771{
2772 switch (req->rq_reqmsg->lm_magic) {
2773 case LUSTRE_MSG_MAGIC_V2:
2774 return req->rq_reqmsg->lm_repsize;
2775 default:
2776 LASSERTF(0, "incorrect message magic: %08x\n",
2777 req->rq_reqmsg->lm_magic);
2778 return -EFAULT;
2779 }
2780}
2781
2782static inline int ptlrpc_send_limit_expired(struct ptlrpc_request *req)
2783{
2784 if (req->rq_delay_limit != 0 &&
699503bc
GKH
2785 time_before(cfs_time_add(req->rq_queued_time,
2786 cfs_time_seconds(req->rq_delay_limit)),
2787 cfs_time_current())) {
d7e09d03
PT
2788 return 1;
2789 }
2790 return 0;
2791}
2792
2793static inline int ptlrpc_no_resend(struct ptlrpc_request *req)
2794{
2795 if (!req->rq_no_resend && ptlrpc_send_limit_expired(req)) {
2796 spin_lock(&req->rq_lock);
2797 req->rq_no_resend = 1;
2798 spin_unlock(&req->rq_lock);
2799 }
2800 return req->rq_no_resend;
2801}
2802
2803static inline int
2804ptlrpc_server_get_timeout(struct ptlrpc_service_part *svcpt)
2805{
2806 int at = AT_OFF ? 0 : at_get(&svcpt->scp_at_estimate);
2807
2808 return svcpt->scp_service->srv_watchdog_factor *
2809 max_t(int, at, obd_timeout);
2810}
2811
2812static inline struct ptlrpc_service *
2813ptlrpc_req2svc(struct ptlrpc_request *req)
2814{
d7e09d03
PT
2815 return req->rq_rqbd->rqbd_svcpt->scp_service;
2816}
2817
2818/* ldlm/ldlm_lib.c */
2819/**
2820 * Target client logic
2821 * @{
2822 */
2823int client_obd_setup(struct obd_device *obddev, struct lustre_cfg *lcfg);
2824int client_obd_cleanup(struct obd_device *obddev);
2825int client_connect_import(const struct lu_env *env,
2826 struct obd_export **exp, struct obd_device *obd,
2827 struct obd_uuid *cluuid, struct obd_connect_data *,
2828 void *localdata);
2829int client_disconnect_export(struct obd_export *exp);
2830int client_import_add_conn(struct obd_import *imp, struct obd_uuid *uuid,
2831 int priority);
2832int client_import_del_conn(struct obd_import *imp, struct obd_uuid *uuid);
2833int client_import_find_conn(struct obd_import *imp, lnet_nid_t peer,
2834 struct obd_uuid *uuid);
2835int import_set_conn_priority(struct obd_import *imp, struct obd_uuid *uuid);
2836void client_destroy_import(struct obd_import *imp);
2837/** @} */
2838
d7e09d03
PT
2839/* ptlrpc/pinger.c */
2840/**
2841 * Pinger API (client side only)
2842 * @{
2843 */
2844enum timeout_event {
2845 TIMEOUT_GRANT = 1
2846};
c9f6bb96 2847
d7e09d03
PT
2848struct timeout_item;
2849typedef int (*timeout_cb_t)(struct timeout_item *, void *);
2850int ptlrpc_pinger_add_import(struct obd_import *imp);
2851int ptlrpc_pinger_del_import(struct obd_import *imp);
2852int ptlrpc_add_timeout_client(int time, enum timeout_event event,
2853 timeout_cb_t cb, void *data,
2854 struct list_head *obd_list);
2855int ptlrpc_del_timeout_client(struct list_head *obd_list,
2856 enum timeout_event event);
aff9d8e8 2857struct ptlrpc_request *ptlrpc_prep_ping(struct obd_import *imp);
d7e09d03 2858int ptlrpc_obd_ping(struct obd_device *obd);
d7e09d03
PT
2859void ptlrpc_pinger_ir_up(void);
2860void ptlrpc_pinger_ir_down(void);
2861/** @} */
2862int ptlrpc_pinger_suppress_pings(void);
2863
d7e09d03
PT
2864/* ptlrpc/ptlrpcd.c */
2865void ptlrpcd_stop(struct ptlrpcd_ctl *pc, int force);
2866void ptlrpcd_free(struct ptlrpcd_ctl *pc);
2867void ptlrpcd_wake(struct ptlrpc_request *req);
c5c4c6fa 2868void ptlrpcd_add_req(struct ptlrpc_request *req);
d7e09d03
PT
2869int ptlrpcd_addref(void);
2870void ptlrpcd_decref(void);
2871
2872/* ptlrpc/lproc_ptlrpc.c */
2873/**
2874 * procfs output related functions
2875 * @{
2876 */
9c234f6c 2877const char *ll_opcode2str(__u32 opcode);
d7e09d03
PT
2878void ptlrpc_lprocfs_register_obd(struct obd_device *obd);
2879void ptlrpc_lprocfs_unregister_obd(struct obd_device *obd);
2880void ptlrpc_lprocfs_brw(struct ptlrpc_request *req, int bytes);
d7e09d03
PT
2881/** @} */
2882
d7e09d03
PT
2883/* ptlrpc/llog_client.c */
2884extern struct llog_operations llog_client_ops;
d7e09d03
PT
2885/** @} net */
2886
2887#endif
2888/** @} PtlRPC */
This page took 0.665222 seconds and 5 git commands to generate.