1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50#ifndef _LUSTRE_NET_H
51#define _LUSTRE_NET_H
52
53
54
55
56
57
58#include <linux/lustre_net.h>
59
60#include <linux/libcfs/libcfs.h>
61
62#include <linux/lnet/lnet.h>
63#include <lustre/lustre_idl.h>
64#include <lustre_ha.h>
65#include <lustre_sec.h>
66#include <lustre_import.h>
67#include <lprocfs_status.h>
68#include <lu_object.h>
69#include <lustre_req_layout.h>
70
71#include <obd_support.h>
72#include <lustre_ver.h>
73
74
75#define PTLRPC_MD_OPTIONS 0
76
77
78
79
80
81
82
83#define PTLRPC_BULK_OPS_BITS 2
84#define PTLRPC_BULK_OPS_COUNT (1U << PTLRPC_BULK_OPS_BITS)
85
86
87
88
89
90
91
92#define PTLRPC_BULK_OPS_MASK (~((__u64)PTLRPC_BULK_OPS_COUNT - 1))
93
94
95
96
97
98
99
100
101#define PTLRPC_MAX_BRW_BITS (LNET_MTU_BITS + PTLRPC_BULK_OPS_BITS)
102#define PTLRPC_MAX_BRW_SIZE (1 << PTLRPC_MAX_BRW_BITS)
103#define PTLRPC_MAX_BRW_PAGES (PTLRPC_MAX_BRW_SIZE >> PAGE_CACHE_SHIFT)
104
105#define ONE_MB_BRW_SIZE (1 << LNET_MTU_BITS)
106#define MD_MAX_BRW_SIZE (1 << LNET_MTU_BITS)
107#define MD_MAX_BRW_PAGES (MD_MAX_BRW_SIZE >> PAGE_CACHE_SHIFT)
108#define DT_MAX_BRW_SIZE PTLRPC_MAX_BRW_SIZE
109#define DT_MAX_BRW_PAGES (DT_MAX_BRW_SIZE >> PAGE_CACHE_SHIFT)
110#define OFD_MAX_BRW_SIZE (1 << LNET_MTU_BITS)
111
112
113# if ((PTLRPC_MAX_BRW_PAGES & (PTLRPC_MAX_BRW_PAGES - 1)) != 0)
114# error "PTLRPC_MAX_BRW_PAGES isn't a power of two"
115# endif
116# if (PTLRPC_MAX_BRW_SIZE != (PTLRPC_MAX_BRW_PAGES * PAGE_CACHE_SIZE))
117# error "PTLRPC_MAX_BRW_SIZE isn't PTLRPC_MAX_BRW_PAGES * PAGE_CACHE_SIZE"
118# endif
119# if (PTLRPC_MAX_BRW_SIZE > LNET_MTU * PTLRPC_BULK_OPS_COUNT)
120# error "PTLRPC_MAX_BRW_SIZE too big"
121# endif
122# if (PTLRPC_MAX_BRW_PAGES > LNET_MAX_IOV * PTLRPC_BULK_OPS_COUNT)
123# error "PTLRPC_MAX_BRW_PAGES too big"
124# endif
125
126#define PTLRPC_NTHRS_INIT 2
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255#define LDLM_THR_FACTOR 8
256#define LDLM_NTHRS_INIT PTLRPC_NTHRS_INIT
257#define LDLM_NTHRS_BASE 24
258#define LDLM_NTHRS_MAX (num_online_cpus() == 1 ? 64 : 128)
259
260#define LDLM_BL_THREADS LDLM_NTHRS_AUTO_INIT
261#define LDLM_CLIENT_NBUFS 1
262#define LDLM_SERVER_NBUFS 64
263#define LDLM_BUFSIZE (8 * 1024)
264#define LDLM_MAXREQSIZE (5 * 1024)
265#define LDLM_MAXREPSIZE (1024)
266
267
268
269
270
271
272
273#ifndef MDS_MAX_THREADS
274#define MDS_MAX_THREADS 1024
275#define MDS_MAX_OTHR_THREADS 256
276
277#else
278#if MDS_MAX_THREADS < PTLRPC_NTHRS_INIT
279#undef MDS_MAX_THREADS
280#define MDS_MAX_THREADS PTLRPC_NTHRS_INIT
281#endif
282#define MDS_MAX_OTHR_THREADS max(PTLRPC_NTHRS_INIT, MDS_MAX_THREADS / 2)
283#endif
284
285
286#define MDS_THR_FACTOR 8
287#define MDS_NTHRS_INIT PTLRPC_NTHRS_INIT
288#define MDS_NTHRS_MAX MDS_MAX_THREADS
289#define MDS_NTHRS_BASE min(64, MDS_NTHRS_MAX)
290
291
292#define MDS_RDPG_THR_FACTOR 4
293#define MDS_RDPG_NTHRS_INIT PTLRPC_NTHRS_INIT
294#define MDS_RDPG_NTHRS_MAX MDS_MAX_OTHR_THREADS
295#define MDS_RDPG_NTHRS_BASE min(48, MDS_RDPG_NTHRS_MAX)
296
297
298#define MDS_SETA_THR_FACTOR 4
299#define MDS_SETA_NTHRS_INIT PTLRPC_NTHRS_INIT
300#define MDS_SETA_NTHRS_MAX MDS_MAX_OTHR_THREADS
301#define MDS_SETA_NTHRS_BASE min(48, MDS_SETA_NTHRS_MAX)
302
303
304#define MDS_OTHR_NTHRS_INIT PTLRPC_NTHRS_INIT
305#define MDS_OTHR_NTHRS_MAX MDS_MAX_OTHR_THREADS
306
307#define MDS_NBUFS 64
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328#define MDS_MAXREQSIZE (5 * 1024)
329#define MDS_MAXREPSIZE (9 * 1024)
330
331
332
333
334
335#define MDS_LOV_MAXREQSIZE max(MDS_MAXREQSIZE, \
336 362 + LOV_MAX_STRIPE_COUNT * 24)
337
338
339
340
341
342
343
344
345
346#define MDS_LOV_MAXREPSIZE MDS_LOV_MAXREQSIZE
347
348
349
350
351
352
353
354
355
356
357
358#define MDS_EA_MAXREQSIZE 66288
359
360
361
362
363
364#define MDS_REG_MAXREQSIZE (((max(MDS_EA_MAXREQSIZE, \
365 MDS_LOV_MAXREQSIZE) + 1023) >> 10) << 10)
366#define MDS_REG_MAXREPSIZE MDS_REG_MAXREQSIZE
367
368
369
370
371
372
373#define MDS_OUT_MAXREQSIZE (9 * 1024)
374#define MDS_OUT_MAXREPSIZE MDS_MAXREPSIZE
375
376
377#define MDS_BUFSIZE max(MDS_MAXREQSIZE + SPTLRPC_MAX_PAYLOAD, \
378 8 * 1024)
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396#define MDS_REG_BUFSIZE max(MDS_REG_MAXREQSIZE + SPTLRPC_MAX_PAYLOAD, \
397 160 * 1024)
398
399
400
401
402
403
404#define MDS_OUT_BUFSIZE max(MDS_OUT_MAXREQSIZE + SPTLRPC_MAX_PAYLOAD, \
405 24 * 1024)
406
407
408#define FLD_MAXREQSIZE (160)
409
410
411#define FLD_MAXREPSIZE (152)
412#define FLD_BUFSIZE (1 << 12)
413
414
415
416
417#define SEQ_MAXREQSIZE (160)
418
419
420#define SEQ_MAXREPSIZE (152)
421#define SEQ_BUFSIZE (1 << 12)
422
423
424#define MGS_NTHRS_INIT (PTLRPC_NTHRS_INIT + 1)
425#define MGS_NTHRS_MAX 32
426
427#define MGS_NBUFS 64
428#define MGS_BUFSIZE (8 * 1024)
429#define MGS_MAXREQSIZE (7 * 1024)
430#define MGS_MAXREPSIZE (9 * 1024)
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457#define OSS_THR_FACTOR min_t(int, 8, \
458 NUM_CACHEPAGES >> (28 - PAGE_CACHE_SHIFT))
459#define OSS_NTHRS_INIT (PTLRPC_NTHRS_INIT + 1)
460#define OSS_NTHRS_BASE 64
461#define OSS_NTHRS_MAX 512
462
463
464#define OSS_CR_THR_FACTOR 1
465#define OSS_CR_NTHRS_INIT PTLRPC_NTHRS_INIT
466#define OSS_CR_NTHRS_BASE 8
467#define OSS_CR_NTHRS_MAX 64
468
469
470
471
472
473
474
475
476
477
478
479#define _OST_MAXREQSIZE_SUM (sizeof(struct lustre_msg) + \
480 sizeof(struct ptlrpc_body) + \
481 sizeof(struct obdo) + \
482 sizeof(struct obd_ioobj) + \
483 sizeof(struct niobuf_remote) * DT_MAX_BRW_PAGES)
484
485
486
487#define OST_MAXREQSIZE (5 * 1024)
488#define OST_IO_MAXREQSIZE max_t(int, OST_MAXREQSIZE, \
489 (((_OST_MAXREQSIZE_SUM - 1) | (1024 - 1)) + 1))
490
491#define OST_MAXREPSIZE (9 * 1024)
492#define OST_IO_MAXREPSIZE OST_MAXREPSIZE
493
494#define OST_NBUFS 64
495
496#define OST_BUFSIZE max_t(int, OST_MAXREQSIZE + 1024, 16 * 1024)
497
498
499
500
501#define OST_IO_BUFSIZE max_t(int, OST_IO_MAXREQSIZE + 1024, 64 * 1024)
502
503
504#define ptlrpc_req_async_args(req) ((void *)&req->rq_async_args)
505
506
507
508
509struct ptlrpc_connection {
510
511 struct hlist_node c_hash;
512
513 lnet_nid_t c_self;
514
515 lnet_process_id_t c_peer;
516
517 struct obd_uuid c_remote_uuid;
518
519 atomic_t c_refcount;
520};
521
522
523struct ptlrpc_client {
524
525 __u32 cli_request_portal;
526
527 __u32 cli_reply_portal;
528
529 char *cli_name;
530};
531
532
533
534#define PTL_RPC_FL_INTR (1 << 0)
535#define PTL_RPC_FL_TIMEOUT (1 << 7)
536
537#define REQ_MAX_ACK_LOCKS 8
538
539union ptlrpc_async_args {
540
541
542
543
544
545
546
547 void *pointer_arg[11];
548 __u64 space[7];
549};
550
551struct ptlrpc_request_set;
552typedef int (*set_interpreter_func)(struct ptlrpc_request_set *, void *, int);
553typedef int (*set_producer_func)(struct ptlrpc_request_set *, void *);
554
555
556
557
558
559
560
561
562
563
564
565
566struct ptlrpc_request_set {
567 atomic_t set_refcount;
568
569 atomic_t set_new_count;
570
571 atomic_t set_remaining;
572
573 wait_queue_head_t set_waitq;
574 wait_queue_head_t *set_wakeup_ptr;
575
576 struct list_head set_requests;
577
578
579
580
581
582 struct list_head set_cblist;
583
584 set_interpreter_func set_interpret;
585
586 void *set_arg;
587
588
589
590
591
592 spinlock_t set_new_req_lock;
593
594 struct list_head set_new_requests;
595
596
597 int set_rc;
598
599
600 int set_max_inflight;
601
602 set_producer_func set_producer;
603
604 void *set_producer_arg;
605};
606
607
608
609
610struct ptlrpc_set_cbdata {
611
612 struct list_head psc_item;
613
614 set_interpreter_func psc_interpret;
615
616 void *psc_data;
617};
618
619struct ptlrpc_bulk_desc;
620struct ptlrpc_service_part;
621struct ptlrpc_service;
622
623
624
625
626struct ptlrpc_cb_id {
627 void (*cbid_fn)(lnet_event_t *ev);
628 void *cbid_arg;
629};
630
631
632#define RS_MAX_LOCKS 8
633#define RS_DEBUG 0
634
635
636
637
638
639
640
641
642struct ptlrpc_reply_state {
643
644 struct ptlrpc_cb_id rs_cb_id;
645
646 struct list_head rs_list;
647
648 struct list_head rs_exp_list;
649
650 struct list_head rs_obd_list;
651#if RS_DEBUG
652 struct list_head rs_debug_list;
653#endif
654
655 spinlock_t rs_lock;
656
657 unsigned long rs_difficult:1;
658 unsigned long rs_no_ack:1;
659
660 unsigned long rs_scheduled:1;
661 unsigned long rs_scheduled_ever:1;
662 unsigned long rs_handled:1;
663 unsigned long rs_on_net:1;
664 unsigned long rs_prealloc:1;
665 unsigned long rs_committed:1;
666
667
668
669 int rs_size;
670
671 __u32 rs_opc;
672
673 __u64 rs_transno;
674
675 __u64 rs_xid;
676 struct obd_export *rs_export;
677 struct ptlrpc_service_part *rs_svcpt;
678
679 lnet_handle_md_t rs_md_h;
680 atomic_t rs_refcount;
681
682
683 struct ptlrpc_svc_ctx *rs_svc_ctx;
684
685 struct lustre_msg *rs_repbuf;
686
687 int rs_repbuf_len;
688
689 int rs_repdata_len;
690
691
692
693
694
695 struct lustre_msg *rs_msg;
696
697
698 int rs_nlocks;
699
700 struct lustre_handle rs_locks[RS_MAX_LOCKS];
701
702 ldlm_mode_t rs_modes[RS_MAX_LOCKS];
703};
704
705struct ptlrpc_thread;
706
707
708enum rq_phase {
709 RQ_PHASE_NEW = 0xebc0de00,
710 RQ_PHASE_RPC = 0xebc0de01,
711 RQ_PHASE_BULK = 0xebc0de02,
712 RQ_PHASE_INTERPRET = 0xebc0de03,
713 RQ_PHASE_COMPLETE = 0xebc0de04,
714 RQ_PHASE_UNREGISTERING = 0xebc0de05,
715 RQ_PHASE_UNDEFINED = 0xebc0de06
716};
717
718
719typedef int (*ptlrpc_interpterer_t)(const struct lu_env *env,
720 struct ptlrpc_request *req,
721 void *arg, int rc);
722
723
724
725
726
727
728
729struct ptlrpc_request_pool {
730
731 spinlock_t prp_lock;
732
733 struct list_head prp_req_list;
734
735 int prp_rq_size;
736
737 void (*prp_populate)(struct ptlrpc_request_pool *, int);
738};
739
740struct lu_context;
741struct lu_env;
742
743struct ldlm_lock;
744
745
746
747
748
749struct ptlrpc_nrs_policy;
750struct ptlrpc_nrs_resource;
751struct ptlrpc_nrs_request;
752
753
754
755
756
757
758enum ptlrpc_nrs_ctl {
759
760
761
762 PTLRPC_NRS_CTL_INVALID,
763
764
765
766 PTLRPC_NRS_CTL_START,
767
768
769
770
771 PTLRPC_NRS_CTL_STOP,
772
773
774
775
776 PTLRPC_NRS_CTL_1ST_POL_SPEC = 0x20,
777};
778
779
780
781
782enum nrs_ctl_orr {
783 NRS_CTL_ORR_RD_QUANTUM = PTLRPC_NRS_CTL_1ST_POL_SPEC,
784 NRS_CTL_ORR_WR_QUANTUM,
785 NRS_CTL_ORR_RD_OFF_TYPE,
786 NRS_CTL_ORR_WR_OFF_TYPE,
787 NRS_CTL_ORR_RD_SUPP_REQ,
788 NRS_CTL_ORR_WR_SUPP_REQ,
789};
790
791
792
793
794
795
796
797struct ptlrpc_nrs_pol_ops {
798
799
800
801
802
803 int (*op_policy_init) (struct ptlrpc_nrs_policy *policy);
804
805
806
807
808
809 void (*op_policy_fini) (struct ptlrpc_nrs_policy *policy);
810
811
812
813
814
815
816
817
818 int (*op_policy_start) (struct ptlrpc_nrs_policy *policy);
819
820
821
822
823
824
825
826
827 void (*op_policy_stop) (struct ptlrpc_nrs_policy *policy);
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843 int (*op_policy_ctl) (struct ptlrpc_nrs_policy *policy,
844 enum ptlrpc_nrs_ctl opc, void *arg);
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882 int (*op_res_get) (struct ptlrpc_nrs_policy *policy,
883 struct ptlrpc_nrs_request *nrq,
884 const struct ptlrpc_nrs_resource *parent,
885 struct ptlrpc_nrs_resource **resp,
886 bool moving_req);
887
888
889
890
891
892
893
894
895
896
897
898 void (*op_res_put) (struct ptlrpc_nrs_policy *policy,
899 const struct ptlrpc_nrs_resource *res);
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917 struct ptlrpc_nrs_request *
918 (*op_req_get) (struct ptlrpc_nrs_policy *policy, bool peek,
919 bool force);
920
921
922
923
924
925
926
927
928
929
930
931
932 int (*op_req_enqueue) (struct ptlrpc_nrs_policy *policy,
933 struct ptlrpc_nrs_request *nrq);
934
935
936
937
938
939
940
941
942
943
944 void (*op_req_dequeue) (struct ptlrpc_nrs_policy *policy,
945 struct ptlrpc_nrs_request *nrq);
946
947
948
949
950
951
952
953
954
955
956
957
958 void (*op_req_stop) (struct ptlrpc_nrs_policy *policy,
959 struct ptlrpc_nrs_request *nrq);
960
961
962
963
964
965
966
967
968 int (*op_lprocfs_init) (struct ptlrpc_service *svc);
969
970
971
972
973
974
975
976
977
978
979
980 void (*op_lprocfs_fini) (struct ptlrpc_service *svc);
981};
982
983
984
985
986enum nrs_policy_flags {
987
988
989
990
991
992 PTLRPC_NRS_FL_FALLBACK = (1 << 0),
993
994
995
996 PTLRPC_NRS_FL_REG_START = (1 << 1),
997
998
999
1000
1001 PTLRPC_NRS_FL_REG_EXTERN = (1 << 2),
1002};
1003
1004
1005
1006
1007
1008
1009
1010
1011enum ptlrpc_nrs_queue_type {
1012 PTLRPC_NRS_QUEUE_REG = (1 << 0),
1013 PTLRPC_NRS_QUEUE_HP = (1 << 1),
1014 PTLRPC_NRS_QUEUE_BOTH = (PTLRPC_NRS_QUEUE_REG | PTLRPC_NRS_QUEUE_HP)
1015};
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043struct ptlrpc_nrs {
1044 spinlock_t nrs_lock;
1045
1046
1047
1048
1049 struct list_head nrs_policy_list;
1050
1051
1052
1053
1054
1055
1056
1057
1058 struct list_head nrs_policy_queued;
1059
1060
1061
1062 struct ptlrpc_service_part *nrs_svcpt;
1063
1064
1065
1066 struct ptlrpc_nrs_policy *nrs_policy_primary;
1067
1068
1069
1070 struct ptlrpc_nrs_policy *nrs_policy_fallback;
1071
1072
1073
1074 enum ptlrpc_nrs_queue_type nrs_queue_type;
1075
1076
1077
1078 unsigned long nrs_req_queued;
1079
1080
1081
1082 unsigned long nrs_req_started;
1083
1084
1085
1086 unsigned nrs_num_pols;
1087
1088
1089
1090 unsigned nrs_policy_starting:1;
1091
1092
1093
1094
1095 unsigned nrs_stopping:1;
1096};
1097
1098#define NRS_POL_NAME_MAX 16
1099
1100struct ptlrpc_nrs_pol_desc;
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111typedef bool (*nrs_pol_desc_compat_t) (const struct ptlrpc_service *svc,
1112 const struct ptlrpc_nrs_pol_desc *desc);
1113
1114struct ptlrpc_nrs_pol_conf {
1115
1116
1117
1118 char nc_name[NRS_POL_NAME_MAX];
1119
1120
1121
1122 const struct ptlrpc_nrs_pol_ops *nc_ops;
1123
1124
1125
1126 nrs_pol_desc_compat_t nc_compat;
1127
1128
1129
1130
1131
1132
1133 const char *nc_compat_svc_name;
1134
1135
1136
1137
1138
1139 module_t *nc_owner;
1140
1141
1142
1143 unsigned nc_flags;
1144};
1145
1146
1147
1148
1149
1150
1151
1152struct ptlrpc_nrs_pol_desc {
1153
1154
1155
1156 char pd_name[NRS_POL_NAME_MAX];
1157
1158
1159
1160 struct list_head pd_list;
1161
1162
1163
1164 const struct ptlrpc_nrs_pol_ops *pd_ops;
1165
1166
1167
1168 nrs_pol_desc_compat_t pd_compat;
1169
1170
1171
1172
1173
1174 const char *pd_compat_svc_name;
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214 module_t *pd_owner;
1215
1216
1217
1218 unsigned pd_flags;
1219
1220
1221
1222 atomic_t pd_refs;
1223};
1224
1225
1226
1227
1228
1229
1230enum ptlrpc_nrs_pol_state {
1231
1232
1233
1234 NRS_POL_STATE_INVALID,
1235
1236
1237
1238
1239
1240 NRS_POL_STATE_STOPPED,
1241
1242
1243
1244 NRS_POL_STATE_STOPPING,
1245
1246
1247
1248 NRS_POL_STATE_STARTING,
1249
1250
1251
1252
1253
1254 NRS_POL_STATE_STARTED,
1255};
1256
1257
1258
1259
1260
1261
1262struct ptlrpc_nrs_pol_info {
1263
1264
1265
1266 char pi_name[NRS_POL_NAME_MAX];
1267
1268
1269
1270 enum ptlrpc_nrs_pol_state pi_state;
1271
1272
1273
1274 long pi_req_queued;
1275
1276
1277
1278 long pi_req_started;
1279
1280
1281
1282 unsigned pi_fallback:1;
1283};
1284
1285
1286
1287
1288
1289
1290
1291struct ptlrpc_nrs_policy {
1292
1293
1294
1295
1296 struct list_head pol_list;
1297
1298
1299
1300
1301 struct list_head pol_list_queued;
1302
1303
1304
1305 enum ptlrpc_nrs_pol_state pol_state;
1306
1307
1308
1309 unsigned pol_flags;
1310
1311
1312
1313 long pol_req_queued;
1314
1315
1316
1317 long pol_req_started;
1318
1319
1320
1321 long pol_ref;
1322
1323
1324
1325 struct ptlrpc_nrs *pol_nrs;
1326
1327
1328
1329 void *pol_private;
1330
1331
1332
1333 struct ptlrpc_nrs_pol_desc *pol_desc;
1334};
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363struct ptlrpc_nrs_resource {
1364
1365
1366
1367
1368 struct ptlrpc_nrs_resource *res_parent;
1369
1370
1371
1372 struct ptlrpc_nrs_policy *res_policy;
1373};
1374
1375enum {
1376 NRS_RES_FALLBACK,
1377 NRS_RES_PRIMARY,
1378 NRS_RES_MAX
1379};
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395struct nrs_fifo_head {
1396
1397
1398
1399 struct ptlrpc_nrs_resource fh_res;
1400
1401
1402
1403 struct list_head fh_list;
1404
1405
1406
1407 __u64 fh_sequence;
1408};
1409
1410struct nrs_fifo_req {
1411 struct list_head fr_list;
1412 __u64 fr_sequence;
1413};
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427struct nrs_crrn_net {
1428 struct ptlrpc_nrs_resource cn_res;
1429 cfs_binheap_t *cn_binheap;
1430 cfs_hash_t *cn_cli_hash;
1431
1432
1433
1434
1435 __u64 cn_round;
1436
1437
1438
1439
1440 __u64 cn_sequence;
1441
1442
1443
1444
1445 __u16 cn_quantum;
1446};
1447
1448
1449
1450
1451struct nrs_crrn_client {
1452 struct ptlrpc_nrs_resource cc_res;
1453 struct hlist_node cc_hnode;
1454 lnet_nid_t cc_nid;
1455
1456
1457
1458
1459 __u64 cc_round;
1460
1461
1462
1463
1464 __u64 cc_sequence;
1465 atomic_t cc_ref;
1466
1467
1468
1469
1470 __u16 cc_quantum;
1471
1472
1473
1474 __u16 cc_active;
1475};
1476
1477
1478
1479
1480struct nrs_crrn_req {
1481
1482
1483
1484
1485 __u64 cr_round;
1486
1487
1488
1489
1490 __u64 cr_sequence;
1491};
1492
1493
1494
1495
1496enum nrs_ctl_crr {
1497
1498
1499
1500 NRS_CTL_CRRN_RD_QUANTUM = PTLRPC_NRS_CTL_1ST_POL_SPEC,
1501
1502
1503
1504 NRS_CTL_CRRN_WR_QUANTUM,
1505};
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519struct nrs_orr_req_range {
1520 __u64 or_start;
1521 __u64 or_end;
1522};
1523
1524
1525
1526
1527enum nrs_orr_supp {
1528 NOS_OST_READ = (1 << 0),
1529 NOS_OST_WRITE = (1 << 1),
1530 NOS_OST_RW = (NOS_OST_READ | NOS_OST_WRITE),
1531
1532
1533
1534 NOS_DFLT = NOS_OST_READ
1535};
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545struct nrs_orr_key {
1546 union {
1547
1548 struct lu_fid ok_fid;
1549
1550 __u32 ok_idx;
1551 };
1552};
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563#define NRS_ORR_OBJ_NAME_MAX (sizeof("nrs_orr_reg_") + 3)
1564
1565
1566
1567
1568struct nrs_orr_data {
1569 struct ptlrpc_nrs_resource od_res;
1570 cfs_binheap_t *od_binheap;
1571 cfs_hash_t *od_obj_hash;
1572 struct kmem_cache *od_cache;
1573
1574
1575
1576
1577 __u64 od_round;
1578
1579
1580
1581
1582 __u64 od_sequence;
1583
1584
1585
1586 enum nrs_orr_supp od_supp;
1587
1588
1589
1590
1591 __u16 od_quantum;
1592
1593
1594
1595 bool od_physical;
1596
1597
1598
1599
1600
1601
1602
1603
1604 char od_objname[NRS_ORR_OBJ_NAME_MAX];
1605};
1606
1607
1608
1609
1610
1611struct nrs_orr_object {
1612 struct ptlrpc_nrs_resource oo_res;
1613 struct hlist_node oo_hnode;
1614
1615
1616
1617
1618 __u64 oo_round;
1619
1620
1621
1622
1623 __u64 oo_sequence;
1624
1625
1626
1627
1628 struct nrs_orr_key oo_key;
1629 atomic_t oo_ref;
1630
1631
1632
1633
1634 __u16 oo_quantum;
1635
1636
1637
1638 __u16 oo_active;
1639};
1640
1641
1642
1643
1644struct nrs_orr_req {
1645
1646
1647
1648 struct nrs_orr_req_range or_range;
1649
1650
1651
1652
1653 __u64 or_round;
1654
1655
1656
1657
1658 __u64 or_sequence;
1659
1660
1661
1662 struct nrs_orr_key or_key;
1663
1664
1665
1666
1667 unsigned int or_orr_set:1;
1668
1669
1670
1671
1672 unsigned int or_trr_set:1;
1673
1674
1675
1676
1677 unsigned int or_logical_set:1;
1678
1679
1680
1681
1682 unsigned int or_physical_set:1;
1683};
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695struct ptlrpc_nrs_request {
1696
1697
1698
1699 struct ptlrpc_nrs_resource *nr_res_ptrs[NRS_RES_MAX];
1700
1701
1702
1703
1704
1705
1706 unsigned nr_res_idx;
1707 unsigned nr_initialized:1;
1708 unsigned nr_enqueued:1;
1709 unsigned nr_started:1;
1710 unsigned nr_finalized:1;
1711 cfs_binheap_node_t nr_node;
1712
1713
1714
1715
1716
1717 union {
1718
1719
1720
1721 struct nrs_fifo_req fifo;
1722
1723
1724
1725 struct nrs_crrn_req crr;
1726
1727 struct nrs_orr_req orr;
1728 } nr_u;
1729
1730
1731
1732
1733 void *ext;
1734};
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747struct ptlrpc_hpreq_ops {
1748
1749
1750
1751
1752 int (*hpreq_lock_match)(struct ptlrpc_request *, struct ldlm_lock *);
1753
1754
1755
1756 int (*hpreq_check)(struct ptlrpc_request *);
1757
1758
1759
1760 void (*hpreq_fini)(struct ptlrpc_request *);
1761};
1762
1763
1764
1765
1766
1767
1768
1769struct ptlrpc_request {
1770
1771 int rq_type;
1772
1773 int rq_status;
1774
1775
1776
1777
1778 struct list_head rq_list;
1779
1780
1781
1782
1783
1784
1785
1786 struct list_head rq_timed_list;
1787
1788 struct list_head rq_history_list;
1789
1790 struct list_head rq_exp_list;
1791
1792 struct ptlrpc_hpreq_ops *rq_ops;
1793
1794
1795 struct ptlrpc_thread *rq_svc_thread;
1796
1797
1798 __u64 rq_history_seq;
1799
1800
1801
1802
1803 struct ptlrpc_nrs_request rq_nrq;
1804
1805
1806 time_t rq_at_index;
1807
1808
1809
1810 spinlock_t rq_lock;
1811
1812 unsigned int rq_intr:1, rq_replied:1, rq_err:1,
1813 rq_timedout:1, rq_resend:1, rq_restart:1,
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823 rq_replay:1,
1824 rq_no_resend:1, rq_waiting:1, rq_receiving_reply:1,
1825 rq_no_delay:1, rq_net_err:1, rq_wait_ctx:1,
1826 rq_early:1, rq_must_unlink:1,
1827 rq_memalloc:1,
1828
1829 rq_packed_final:1,
1830 rq_hp:1,
1831 rq_at_linked:1,
1832 rq_reply_truncate:1,
1833 rq_committed:1,
1834
1835 rq_invalid_rqset:1,
1836 rq_generation_set:1,
1837
1838 rq_no_retry_einprogress:1,
1839
1840
1841 rq_allow_replay:1;
1842
1843 unsigned int rq_nr_resend;
1844
1845 enum rq_phase rq_phase;
1846 enum rq_phase rq_next_phase;
1847 atomic_t rq_refcount;
1848
1849
1850
1851 short rq_request_portal;
1852
1853 short rq_reply_portal;
1854
1855
1856
1857
1858
1859
1860 int rq_nob_received;
1861
1862 int rq_reqlen;
1863
1864 int rq_replen;
1865
1866 struct lustre_msg *rq_reqmsg;
1867
1868 struct lustre_msg *rq_repmsg;
1869
1870 __u64 rq_transno;
1871
1872 __u64 rq_xid;
1873
1874
1875
1876
1877
1878 struct list_head rq_replay_list;
1879
1880
1881
1882
1883 struct ptlrpc_cli_ctx *rq_cli_ctx;
1884 struct ptlrpc_svc_ctx *rq_svc_ctx;
1885 struct list_head rq_ctx_chain;
1886
1887 struct sptlrpc_flavor rq_flvr;
1888 enum lustre_sec_part rq_sp_from;
1889
1890
1891 unsigned int
1892 rq_ctx_init:1,
1893 rq_ctx_fini:1,
1894 rq_bulk_read:1,
1895 rq_bulk_write:1,
1896
1897 rq_auth_gss:1,
1898 rq_auth_remote:1,
1899 rq_auth_usr_root:1,
1900 rq_auth_usr_mdt:1,
1901 rq_auth_usr_ost:1,
1902
1903 rq_pack_udesc:1,
1904 rq_pack_bulk:1,
1905
1906 rq_no_reply:1,
1907 rq_pill_init:1;
1908
1909 uid_t rq_auth_uid;
1910 uid_t rq_auth_mapped_uid;
1911
1912
1913 struct ptlrpc_user_desc *rq_user_desc;
1914
1915
1916 struct lustre_msg *rq_reqbuf;
1917 char *rq_repbuf;
1918 struct lustre_msg *rq_repdata;
1919 struct lustre_msg *rq_clrbuf;
1920 int rq_reqbuf_len;
1921 int rq_reqdata_len;
1922 int rq_repbuf_len;
1923 int rq_repdata_len;
1924 int rq_clrbuf_len;
1925 int rq_clrdata_len;
1926
1927
1928 unsigned int rq_reply_off;
1929
1930
1931
1932
1933 __u32 rq_req_swab_mask;
1934 __u32 rq_rep_swab_mask;
1935
1936
1937 int rq_import_generation;
1938 enum lustre_imp_state rq_send_state;
1939
1940
1941 int rq_early_count;
1942
1943
1944 lnet_handle_md_t rq_req_md_h;
1945 struct ptlrpc_cb_id rq_req_cbid;
1946
1947 cfs_duration_t rq_delay_limit;
1948
1949 cfs_time_t rq_queued_time;
1950
1951
1952
1953 struct timeval rq_arrival_time;
1954
1955 struct ptlrpc_reply_state *rq_reply_state;
1956
1957 struct ptlrpc_request_buffer_desc *rq_rqbd;
1958
1959
1960 lnet_handle_md_t rq_reply_md_h;
1961 wait_queue_head_t rq_reply_waitq;
1962 struct ptlrpc_cb_id rq_reply_cbid;
1963
1964
1965 lnet_nid_t rq_self;
1966
1967 lnet_process_id_t rq_peer;
1968
1969 struct obd_export *rq_export;
1970
1971 struct obd_import *rq_import;
1972
1973
1974 void (*rq_replay_cb)(struct ptlrpc_request *);
1975
1976
1977
1978
1979 void (*rq_commit_cb)(struct ptlrpc_request *);
1980
1981 void *rq_cb_data;
1982
1983
1984 struct ptlrpc_bulk_desc *rq_bulk;
1985
1986
1987
1988
1989
1990 time_t rq_sent;
1991
1992 time_t rq_real_sent;
1993
1994
1995
1996
1997 volatile time_t rq_deadline;
1998
1999 time_t rq_reply_deadline;
2000
2001 time_t rq_bulk_deadline;
2002
2003
2004
2005
2006 int rq_timeout;
2007
2008
2009
2010 wait_queue_head_t rq_set_waitq;
2011
2012 struct list_head rq_set_chain;
2013
2014 struct ptlrpc_request_set *rq_set;
2015
2016 ptlrpc_interpterer_t rq_interpret_reply;
2017
2018 union ptlrpc_async_args rq_async_args;
2019
2020
2021 struct ptlrpc_request_pool *rq_pool;
2022
2023 struct lu_context rq_session;
2024 struct lu_context rq_recov_session;
2025
2026
2027 struct req_capsule rq_pill;
2028};
2029
2030
2031
2032
2033
2034static inline int ptlrpc_req_interpret(const struct lu_env *env,
2035 struct ptlrpc_request *req, int rc)
2036{
2037 if (req->rq_interpret_reply != NULL) {
2038 req->rq_status = req->rq_interpret_reply(env, req,
2039 &req->rq_async_args,
2040 rc);
2041 return req->rq_status;
2042 }
2043 return rc;
2044}
2045
2046
2047
2048
2049int ptlrpc_nrs_policy_register(struct ptlrpc_nrs_pol_conf *conf);
2050int ptlrpc_nrs_policy_unregister(struct ptlrpc_nrs_pol_conf *conf);
2051void ptlrpc_nrs_req_hp_move(struct ptlrpc_request *req);
2052void nrs_policy_get_info_locked(struct ptlrpc_nrs_policy *policy,
2053 struct ptlrpc_nrs_pol_info *info);
2054
2055
2056
2057
2058
2059
2060
2061static inline bool ptlrpc_nrs_req_can_move(struct ptlrpc_request *req)
2062{
2063 struct ptlrpc_nrs_request *nrq = &req->rq_nrq;
2064
2065
2066
2067
2068
2069
2070
2071 return nrq->nr_enqueued && !nrq->nr_started && !req->rq_hp;
2072}
2073
2074
2075
2076
2077
2078static inline int lustre_req_swabbed(struct ptlrpc_request *req, int index)
2079{
2080 LASSERT(index < sizeof(req->rq_req_swab_mask) * 8);
2081 return req->rq_req_swab_mask & (1 << index);
2082}
2083
2084
2085
2086
2087static inline int lustre_rep_swabbed(struct ptlrpc_request *req, int index)
2088{
2089 LASSERT(index < sizeof(req->rq_rep_swab_mask) * 8);
2090 return req->rq_rep_swab_mask & (1 << index);
2091}
2092
2093
2094
2095
2096static inline int ptlrpc_req_need_swab(struct ptlrpc_request *req)
2097{
2098 return lustre_req_swabbed(req, MSG_PTLRPC_HEADER_OFF);
2099}
2100
2101
2102
2103
2104static inline int ptlrpc_rep_need_swab(struct ptlrpc_request *req)
2105{
2106 return lustre_rep_swabbed(req, MSG_PTLRPC_HEADER_OFF);
2107}
2108
2109
2110
2111
2112static inline void lustre_set_req_swabbed(struct ptlrpc_request *req, int index)
2113{
2114 LASSERT(index < sizeof(req->rq_req_swab_mask) * 8);
2115 LASSERT((req->rq_req_swab_mask & (1 << index)) == 0);
2116 req->rq_req_swab_mask |= 1 << index;
2117}
2118
2119
2120
2121
2122static inline void lustre_set_rep_swabbed(struct ptlrpc_request *req, int index)
2123{
2124 LASSERT(index < sizeof(req->rq_rep_swab_mask) * 8);
2125 LASSERT((req->rq_rep_swab_mask & (1 << index)) == 0);
2126 req->rq_rep_swab_mask |= 1 << index;
2127}
2128
2129
2130
2131
2132static inline const char *
2133ptlrpc_phase2str(enum rq_phase phase)
2134{
2135 switch (phase) {
2136 case RQ_PHASE_NEW:
2137 return "New";
2138 case RQ_PHASE_RPC:
2139 return "Rpc";
2140 case RQ_PHASE_BULK:
2141 return "Bulk";
2142 case RQ_PHASE_INTERPRET:
2143 return "Interpret";
2144 case RQ_PHASE_COMPLETE:
2145 return "Complete";
2146 case RQ_PHASE_UNREGISTERING:
2147 return "Unregistering";
2148 default:
2149 return "?Phase?";
2150 }
2151}
2152
2153
2154
2155
2156
2157static inline const char *
2158ptlrpc_rqphase2str(struct ptlrpc_request *req)
2159{
2160 return ptlrpc_phase2str(req->rq_phase);
2161}
2162
2163
2164
2165
2166
2167
2168#define FLAG(field, str) (field ? str : "")
2169
2170
2171#define DEBUG_REQ_FLAGS(req) \
2172 ptlrpc_rqphase2str(req), \
2173 FLAG(req->rq_intr, "I"), FLAG(req->rq_replied, "R"), \
2174 FLAG(req->rq_err, "E"), \
2175 FLAG(req->rq_timedout, "X") , FLAG(req->rq_resend, "S"), \
2176 FLAG(req->rq_restart, "T"), FLAG(req->rq_replay, "P"), \
2177 FLAG(req->rq_no_resend, "N"), \
2178 FLAG(req->rq_waiting, "W"), \
2179 FLAG(req->rq_wait_ctx, "C"), FLAG(req->rq_hp, "H"), \
2180 FLAG(req->rq_committed, "M")
2181
2182#define REQ_FLAGS_FMT "%s:%s%s%s%s%s%s%s%s%s%s%s%s"
2183
2184void _debug_req(struct ptlrpc_request *req,
2185 struct libcfs_debug_msg_data *data, const char *fmt, ...)
2186 __attribute__ ((format (printf, 3, 4)));
2187
2188
2189
2190
2191
2192#define debug_req(msgdata, mask, cdls, req, fmt, a...) \
2193do { \
2194 CFS_CHECK_STACK(msgdata, mask, cdls); \
2195 \
2196 if (((mask) & D_CANTMASK) != 0 || \
2197 ((libcfs_debug & (mask)) != 0 && \
2198 (libcfs_subsystem_debug & DEBUG_SUBSYSTEM) != 0)) \
2199 _debug_req((req), msgdata, fmt, ##a); \
2200} while(0)
2201
2202
2203
2204
2205
2206#define DEBUG_REQ(level, req, fmt, args...) \
2207do { \
2208 if ((level) & (D_ERROR | D_WARNING)) { \
2209 static cfs_debug_limit_state_t cdls; \
2210 LIBCFS_DEBUG_MSG_DATA_DECL(msgdata, level, &cdls); \
2211 debug_req(&msgdata, level, &cdls, req, "@@@ "fmt" ", ## args);\
2212 } else { \
2213 LIBCFS_DEBUG_MSG_DATA_DECL(msgdata, level, NULL); \
2214 debug_req(&msgdata, level, NULL, req, "@@@ "fmt" ", ## args); \
2215 } \
2216} while (0)
2217
2218
2219
2220
2221
2222struct ptlrpc_bulk_page {
2223
2224 struct list_head bp_link;
2225
2226
2227
2228 int bp_buflen;
2229
2230 int bp_pageoffset;
2231
2232 struct page *bp_page;
2233};
2234
2235#define BULK_GET_SOURCE 0
2236#define BULK_PUT_SINK 1
2237#define BULK_GET_SINK 2
2238#define BULK_PUT_SOURCE 3
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250struct ptlrpc_bulk_desc {
2251
2252 unsigned long bd_failure:1;
2253
2254 unsigned long bd_type:2;
2255
2256 unsigned long bd_registered:1;
2257
2258 spinlock_t bd_lock;
2259
2260 int bd_import_generation;
2261
2262 __u32 bd_portal;
2263
2264 struct obd_export *bd_export;
2265
2266 struct obd_import *bd_import;
2267
2268 struct ptlrpc_request *bd_req;
2269 wait_queue_head_t bd_waitq;
2270 int bd_iov_count;
2271 int bd_max_iov;
2272 int bd_nob;
2273 int bd_nob_transferred;
2274
2275 __u64 bd_last_xid;
2276
2277 struct ptlrpc_cb_id bd_cbid;
2278 lnet_nid_t bd_sender;
2279 int bd_md_count;
2280 int bd_md_max_brw;
2281
2282 lnet_handle_md_t bd_mds[PTLRPC_BULK_OPS_COUNT];
2283
2284
2285
2286
2287 lnet_kiov_t *bd_enc_iov;
2288
2289 lnet_kiov_t bd_iov[0];
2290};
2291
2292enum {
2293 SVC_STOPPED = 1 << 0,
2294 SVC_STOPPING = 1 << 1,
2295 SVC_STARTING = 1 << 2,
2296 SVC_RUNNING = 1 << 3,
2297 SVC_EVENT = 1 << 4,
2298 SVC_SIGNAL = 1 << 5,
2299};
2300
2301#define PTLRPC_THR_NAME_LEN 32
2302
2303
2304
2305struct ptlrpc_thread {
2306
2307
2308
2309 struct list_head t_link;
2310
2311
2312
2313 void *t_data;
2314 __u32 t_flags;
2315
2316
2317
2318 unsigned int t_id;
2319
2320
2321
2322 pid_t t_pid;
2323
2324
2325
2326 struct lc_watchdog *t_watchdog;
2327
2328
2329
2330 struct ptlrpc_service_part *t_svcpt;
2331 wait_queue_head_t t_ctl_waitq;
2332 struct lu_env *t_env;
2333 char t_name[PTLRPC_THR_NAME_LEN];
2334};
2335
2336static inline int thread_is_init(struct ptlrpc_thread *thread)
2337{
2338 return thread->t_flags == 0;
2339}
2340
2341static inline int thread_is_stopped(struct ptlrpc_thread *thread)
2342{
2343 return !!(thread->t_flags & SVC_STOPPED);
2344}
2345
2346static inline int thread_is_stopping(struct ptlrpc_thread *thread)
2347{
2348 return !!(thread->t_flags & SVC_STOPPING);
2349}
2350
2351static inline int thread_is_starting(struct ptlrpc_thread *thread)
2352{
2353 return !!(thread->t_flags & SVC_STARTING);
2354}
2355
2356static inline int thread_is_running(struct ptlrpc_thread *thread)
2357{
2358 return !!(thread->t_flags & SVC_RUNNING);
2359}
2360
2361static inline int thread_is_event(struct ptlrpc_thread *thread)
2362{
2363 return !!(thread->t_flags & SVC_EVENT);
2364}
2365
2366static inline int thread_is_signal(struct ptlrpc_thread *thread)
2367{
2368 return !!(thread->t_flags & SVC_SIGNAL);
2369}
2370
2371static inline void thread_clear_flags(struct ptlrpc_thread *thread, __u32 flags)
2372{
2373 thread->t_flags &= ~flags;
2374}
2375
2376static inline void thread_set_flags(struct ptlrpc_thread *thread, __u32 flags)
2377{
2378 thread->t_flags = flags;
2379}
2380
2381static inline void thread_add_flags(struct ptlrpc_thread *thread, __u32 flags)
2382{
2383 thread->t_flags |= flags;
2384}
2385
2386static inline int thread_test_and_clear_flags(struct ptlrpc_thread *thread,
2387 __u32 flags)
2388{
2389 if (thread->t_flags & flags) {
2390 thread->t_flags &= ~flags;
2391 return 1;
2392 }
2393 return 0;
2394}
2395
2396
2397
2398
2399
2400
2401
2402
2403struct ptlrpc_request_buffer_desc {
2404
2405 struct list_head rqbd_list;
2406
2407 struct list_head rqbd_reqs;
2408
2409 struct ptlrpc_service_part *rqbd_svcpt;
2410
2411 lnet_handle_md_t rqbd_md_h;
2412 int rqbd_refcount;
2413
2414 char *rqbd_buffer;
2415 struct ptlrpc_cb_id rqbd_cbid;
2416
2417
2418
2419
2420 struct ptlrpc_request rqbd_req;
2421};
2422
2423typedef int (*svc_handler_t)(struct ptlrpc_request *req);
2424
2425struct ptlrpc_service_ops {
2426
2427
2428
2429
2430 int (*so_thr_init)(struct ptlrpc_thread *thr);
2431
2432
2433
2434
2435 void (*so_thr_done)(struct ptlrpc_thread *thr);
2436
2437
2438
2439 int (*so_req_handler)(struct ptlrpc_request *req);
2440
2441
2442
2443
2444 int (*so_hpreq_handler)(struct ptlrpc_request *);
2445
2446
2447
2448 void (*so_req_printer)(void *, struct ptlrpc_request *);
2449};
2450
2451#ifndef __cfs_cacheline_aligned
2452
2453# define __cfs_cacheline_aligned
2454#endif
2455
2456
2457
2458
2459
2460#define PTLRPC_SVC_HP_RATIO 10
2461
2462
2463
2464
2465
2466
2467
2468struct ptlrpc_service {
2469
2470 spinlock_t srv_lock;
2471
2472
2473 struct list_head srv_list;
2474
2475 struct ptlrpc_service_ops srv_ops;
2476
2477 char *srv_name;
2478
2479 char *srv_thread_name;
2480
2481 struct list_head srv_threads;
2482
2483 int srv_nthrs_cpt_init;
2484
2485 int srv_nthrs_cpt_limit;
2486
2487 proc_dir_entry_t *srv_procroot;
2488
2489 struct lprocfs_stats *srv_stats;
2490
2491 int srv_hpreq_ratio;
2492
2493 int srv_max_req_size;
2494
2495 int srv_max_reply_size;
2496
2497 int srv_buf_size;
2498
2499 int srv_nbuf_per_group;
2500
2501 __u32 srv_req_portal;
2502
2503 __u32 srv_rep_portal;
2504
2505
2506
2507
2508 __u32 srv_ctx_tags;
2509
2510 int srv_watchdog_factor;
2511
2512 unsigned srv_is_stopping:1;
2513
2514
2515 int srv_hist_nrqbds_cpt_max;
2516
2517 int srv_ncpts;
2518
2519 __u32 *srv_cpts;
2520
2521 int srv_cpt_bits;
2522
2523 struct cfs_cpt_table *srv_cptable;
2524
2525
2526
2527 struct ptlrpc_service_part *srv_parts[0];
2528};
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548struct ptlrpc_service_part {
2549
2550 struct ptlrpc_service *scp_service __cfs_cacheline_aligned;
2551
2552 int scp_cpt;
2553
2554 int scp_thr_nextid;
2555
2556 int scp_nthrs_starting;
2557
2558 int scp_nthrs_stopping;
2559
2560 int scp_nthrs_running;
2561
2562 struct list_head scp_threads;
2563
2564
2565
2566
2567
2568
2569 spinlock_t scp_lock __cfs_cacheline_aligned;
2570
2571 int scp_nrqbds_total;
2572
2573 int scp_nrqbds_posted;
2574
2575 int scp_rqbd_allocating;
2576
2577 int scp_nreqs_incoming;
2578
2579 struct list_head scp_rqbd_idle;
2580
2581 struct list_head scp_rqbd_posted;
2582
2583 struct list_head scp_req_incoming;
2584
2585 cfs_duration_t scp_rqbd_timeout;
2586
2587
2588
2589
2590 wait_queue_head_t scp_waitq;
2591
2592
2593 struct list_head scp_hist_reqs;
2594
2595 struct list_head scp_hist_rqbds;
2596
2597 int scp_hist_nrqbds;
2598
2599 __u64 scp_hist_seq;
2600
2601 __u64 scp_hist_seq_culled;
2602
2603
2604
2605
2606
2607 spinlock_t scp_req_lock __cfs_cacheline_aligned;
2608
2609
2610 int scp_nreqs_active;
2611
2612 int scp_nhreqs_active;
2613
2614 int scp_hreq_count;
2615
2616
2617 struct ptlrpc_nrs scp_nrs_reg;
2618
2619
2620 struct ptlrpc_nrs *scp_nrs_hp;
2621
2622
2623
2624
2625
2626
2627
2628 spinlock_t scp_at_lock __cfs_cacheline_aligned;
2629
2630 struct adaptive_timeout scp_at_estimate;
2631
2632 struct ptlrpc_at_array scp_at_array;
2633
2634 timer_list_t scp_at_timer;
2635
2636 cfs_time_t scp_at_checktime;
2637
2638 unsigned scp_at_check;
2639
2640
2641
2642
2643
2644
2645 spinlock_t scp_rep_lock __cfs_cacheline_aligned;
2646
2647 struct list_head scp_rep_active;
2648
2649 struct list_head scp_rep_idle;
2650
2651 wait_queue_head_t scp_rep_waitq;
2652
2653 atomic_t scp_nreps_difficult;
2654};
2655
2656#define ptlrpc_service_for_each_part(part, i, svc) \
2657 for (i = 0; \
2658 i < (svc)->srv_ncpts && \
2659 (svc)->srv_parts != NULL && \
2660 ((part) = (svc)->srv_parts[i]) != NULL; i++)
2661
2662
2663
2664
2665struct ptlrpcd_ctl {
2666
2667
2668
2669 unsigned long pc_flags;
2670
2671
2672
2673 spinlock_t pc_lock;
2674
2675
2676
2677 struct completion pc_starting;
2678
2679
2680
2681 struct completion pc_finishing;
2682
2683
2684
2685 struct ptlrpc_request_set *pc_set;
2686
2687
2688
2689 char pc_name[16];
2690
2691
2692
2693 struct lu_env pc_env;
2694
2695
2696
2697 int pc_index;
2698
2699
2700
2701 int pc_npartners;
2702
2703
2704
2705 struct ptlrpcd_ctl **pc_partners;
2706
2707
2708
2709 int pc_cursor;
2710};
2711
2712
2713enum ptlrpcd_ctl_flags {
2714
2715
2716
2717 LIOD_START = 1 << 0,
2718
2719
2720
2721 LIOD_STOP = 1 << 1,
2722
2723
2724
2725
2726
2727 LIOD_FORCE = 1 << 2,
2728
2729
2730
2731 LIOD_RECOVERY = 1 << 3,
2732
2733
2734
2735 LIOD_BIND = 1 << 4,
2736};
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751static inline bool nrs_policy_compat_all(const struct ptlrpc_service *svc,
2752 const struct ptlrpc_nrs_pol_desc *desc)
2753{
2754 return true;
2755}
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770static inline bool nrs_policy_compat_one(const struct ptlrpc_service *svc,
2771 const struct ptlrpc_nrs_pol_desc *desc)
2772{
2773 LASSERT(desc->pd_compat_svc_name != NULL);
2774 return strcmp(svc->srv_name, desc->pd_compat_svc_name) == 0;
2775}
2776
2777
2778
2779
2780extern lnet_handle_eq_t ptlrpc_eq_h;
2781extern int ptlrpc_uuid_to_peer(struct obd_uuid *uuid,
2782 lnet_process_id_t *peer, lnet_nid_t *self);
2783
2784
2785
2786
2787
2788extern void request_out_callback(lnet_event_t *ev);
2789extern void reply_in_callback(lnet_event_t *ev);
2790extern void client_bulk_callback(lnet_event_t *ev);
2791extern void request_in_callback(lnet_event_t *ev);
2792extern void reply_out_callback(lnet_event_t *ev);
2793
2794
2795
2796struct ptlrpc_connection *ptlrpc_connection_get(lnet_process_id_t peer,
2797 lnet_nid_t self,
2798 struct obd_uuid *uuid);
2799int ptlrpc_connection_put(struct ptlrpc_connection *c);
2800struct ptlrpc_connection *ptlrpc_connection_addref(struct ptlrpc_connection *);
2801int ptlrpc_connection_init(void);
2802void ptlrpc_connection_fini(void);
2803extern lnet_pid_t ptl_get_pid(void);
2804
2805
2806
2807
2808
2809
2810
2811int ptlrpc_register_bulk(struct ptlrpc_request *req);
2812int ptlrpc_unregister_bulk(struct ptlrpc_request *req, int async);
2813
2814static inline int ptlrpc_client_bulk_active(struct ptlrpc_request *req)
2815{
2816 struct ptlrpc_bulk_desc *desc;
2817 int rc;
2818
2819 LASSERT(req != NULL);
2820 desc = req->rq_bulk;
2821
2822 if (OBD_FAIL_CHECK(OBD_FAIL_PTLRPC_LONG_BULK_UNLINK) &&
2823 req->rq_bulk_deadline > cfs_time_current_sec())
2824 return 1;
2825
2826 if (!desc)
2827 return 0;
2828
2829 spin_lock(&desc->bd_lock);
2830 rc = desc->bd_md_count;
2831 spin_unlock(&desc->bd_lock);
2832 return rc;
2833}
2834
2835#define PTLRPC_REPLY_MAYBE_DIFFICULT 0x01
2836#define PTLRPC_REPLY_EARLY 0x02
2837int ptlrpc_send_reply(struct ptlrpc_request *req, int flags);
2838int ptlrpc_reply(struct ptlrpc_request *req);
2839int ptlrpc_send_error(struct ptlrpc_request *req, int difficult);
2840int ptlrpc_error(struct ptlrpc_request *req);
2841void ptlrpc_resend_req(struct ptlrpc_request *request);
2842int ptlrpc_at_get_net_latency(struct ptlrpc_request *req);
2843int ptl_send_rpc(struct ptlrpc_request *request, int noreply);
2844int ptlrpc_register_rqbd(struct ptlrpc_request_buffer_desc *rqbd);
2845
2846
2847
2848
2849
2850
2851
2852
2853void ptlrpc_init_client(int req_portal, int rep_portal, char *name,
2854 struct ptlrpc_client *);
2855void ptlrpc_cleanup_client(struct obd_import *imp);
2856struct ptlrpc_connection *ptlrpc_uuid_to_connection(struct obd_uuid *uuid);
2857
2858int ptlrpc_queue_wait(struct ptlrpc_request *req);
2859int ptlrpc_replay_req(struct ptlrpc_request *req);
2860int ptlrpc_unregister_reply(struct ptlrpc_request *req, int async);
2861void ptlrpc_restart_req(struct ptlrpc_request *req);
2862void ptlrpc_abort_inflight(struct obd_import *imp);
2863void ptlrpc_cleanup_imp(struct obd_import *imp);
2864void ptlrpc_abort_set(struct ptlrpc_request_set *set);
2865
2866struct ptlrpc_request_set *ptlrpc_prep_set(void);
2867struct ptlrpc_request_set *ptlrpc_prep_fcset(int max, set_producer_func func,
2868 void *arg);
2869int ptlrpc_set_add_cb(struct ptlrpc_request_set *set,
2870 set_interpreter_func fn, void *data);
2871int ptlrpc_set_next_timeout(struct ptlrpc_request_set *);
2872int ptlrpc_check_set(const struct lu_env *env, struct ptlrpc_request_set *set);
2873int ptlrpc_set_wait(struct ptlrpc_request_set *);
2874int ptlrpc_expired_set(void *data);
2875void ptlrpc_interrupted_set(void *data);
2876void ptlrpc_mark_interrupted(struct ptlrpc_request *req);
2877void ptlrpc_set_destroy(struct ptlrpc_request_set *);
2878void ptlrpc_set_add_req(struct ptlrpc_request_set *, struct ptlrpc_request *);
2879void ptlrpc_set_add_new_req(struct ptlrpcd_ctl *pc,
2880 struct ptlrpc_request *req);
2881
2882void ptlrpc_free_rq_pool(struct ptlrpc_request_pool *pool);
2883void ptlrpc_add_rqs_to_pool(struct ptlrpc_request_pool *pool, int num_rq);
2884
2885struct ptlrpc_request_pool *
2886ptlrpc_init_rq_pool(int, int,
2887 void (*populate_pool)(struct ptlrpc_request_pool *, int));
2888
2889void ptlrpc_at_set_req_timeout(struct ptlrpc_request *req);
2890struct ptlrpc_request *ptlrpc_request_alloc(struct obd_import *imp,
2891 const struct req_format *format);
2892struct ptlrpc_request *ptlrpc_request_alloc_pool(struct obd_import *imp,
2893 struct ptlrpc_request_pool *,
2894 const struct req_format *format);
2895void ptlrpc_request_free(struct ptlrpc_request *request);
2896int ptlrpc_request_pack(struct ptlrpc_request *request,
2897 __u32 version, int opcode);
2898struct ptlrpc_request *ptlrpc_request_alloc_pack(struct obd_import *imp,
2899 const struct req_format *format,
2900 __u32 version, int opcode);
2901int ptlrpc_request_bufs_pack(struct ptlrpc_request *request,
2902 __u32 version, int opcode, char **bufs,
2903 struct ptlrpc_cli_ctx *ctx);
2904struct ptlrpc_request *ptlrpc_prep_req(struct obd_import *imp, __u32 version,
2905 int opcode, int count, __u32 *lengths,
2906 char **bufs);
2907struct ptlrpc_request *ptlrpc_prep_req_pool(struct obd_import *imp,
2908 __u32 version, int opcode,
2909 int count, __u32 *lengths, char **bufs,
2910 struct ptlrpc_request_pool *pool);
2911void ptlrpc_req_finished(struct ptlrpc_request *request);
2912void ptlrpc_req_finished_with_imp_lock(struct ptlrpc_request *request);
2913struct ptlrpc_request *ptlrpc_request_addref(struct ptlrpc_request *req);
2914struct ptlrpc_bulk_desc *ptlrpc_prep_bulk_imp(struct ptlrpc_request *req,
2915 unsigned npages, unsigned max_brw,
2916 unsigned type, unsigned portal);
2917void __ptlrpc_free_bulk(struct ptlrpc_bulk_desc *bulk, int pin);
2918static inline void ptlrpc_free_bulk_pin(struct ptlrpc_bulk_desc *bulk)
2919{
2920 __ptlrpc_free_bulk(bulk, 1);
2921}
2922static inline void ptlrpc_free_bulk_nopin(struct ptlrpc_bulk_desc *bulk)
2923{
2924 __ptlrpc_free_bulk(bulk, 0);
2925}
2926void __ptlrpc_prep_bulk_page(struct ptlrpc_bulk_desc *desc,
2927 struct page *page, int pageoffset, int len, int);
2928static inline void ptlrpc_prep_bulk_page_pin(struct ptlrpc_bulk_desc *desc,
2929 struct page *page, int pageoffset,
2930 int len)
2931{
2932 __ptlrpc_prep_bulk_page(desc, page, pageoffset, len, 1);
2933}
2934
2935static inline void ptlrpc_prep_bulk_page_nopin(struct ptlrpc_bulk_desc *desc,
2936 struct page *page, int pageoffset,
2937 int len)
2938{
2939 __ptlrpc_prep_bulk_page(desc, page, pageoffset, len, 0);
2940}
2941
2942void ptlrpc_retain_replayable_request(struct ptlrpc_request *req,
2943 struct obd_import *imp);
2944__u64 ptlrpc_next_xid(void);
2945__u64 ptlrpc_sample_next_xid(void);
2946__u64 ptlrpc_req_xid(struct ptlrpc_request *request);
2947
2948
2949void *ptlrpcd_alloc_work(struct obd_import *imp,
2950 int (*cb)(const struct lu_env *, void *), void *data);
2951void ptlrpcd_destroy_work(void *handler);
2952int ptlrpcd_queue_work(void *handler);
2953
2954
2955struct ptlrpc_service_buf_conf {
2956
2957 unsigned int bc_nbufs;
2958
2959 unsigned int bc_buf_size;
2960
2961 unsigned int bc_req_portal;
2962
2963 unsigned int bc_rep_portal;
2964
2965 unsigned int bc_req_max_size;
2966
2967 unsigned int bc_rep_max_size;
2968};
2969
2970struct ptlrpc_service_thr_conf {
2971
2972 char *tc_thr_name;
2973
2974 unsigned int tc_thr_factor;
2975
2976 unsigned int tc_nthrs_init;
2977
2978
2979
2980
2981
2982
2983 unsigned int tc_nthrs_base;
2984
2985 unsigned int tc_nthrs_max;
2986
2987
2988 unsigned int tc_nthrs_user;
2989
2990 unsigned int tc_cpu_affinity;
2991
2992 __u32 tc_ctx_tags;
2993};
2994
2995struct ptlrpc_service_cpt_conf {
2996 struct cfs_cpt_table *cc_cptable;
2997
2998 char *cc_pattern;
2999};
3000
3001struct ptlrpc_service_conf {
3002
3003 char *psc_name;
3004
3005 unsigned int psc_watchdog_factor;
3006
3007 struct ptlrpc_service_buf_conf psc_buf;
3008
3009 struct ptlrpc_service_thr_conf psc_thr;
3010
3011 struct ptlrpc_service_cpt_conf psc_cpt;
3012
3013 struct ptlrpc_service_ops psc_ops;
3014};
3015
3016
3017
3018
3019
3020
3021
3022
3023void ptlrpc_save_lock(struct ptlrpc_request *req,
3024 struct lustre_handle *lock, int mode, int no_ack);
3025void ptlrpc_commit_replies(struct obd_export *exp);
3026void ptlrpc_dispatch_difficult_reply(struct ptlrpc_reply_state *rs);
3027void ptlrpc_schedule_difficult_reply(struct ptlrpc_reply_state *rs);
3028int ptlrpc_hpreq_handler(struct ptlrpc_request *req);
3029struct ptlrpc_service *ptlrpc_register_service(
3030 struct ptlrpc_service_conf *conf,
3031 struct proc_dir_entry *proc_entry);
3032void ptlrpc_stop_all_threads(struct ptlrpc_service *svc);
3033
3034int ptlrpc_start_threads(struct ptlrpc_service *svc);
3035int ptlrpc_unregister_service(struct ptlrpc_service *service);
3036int liblustre_check_services(void *arg);
3037void ptlrpc_daemonize(char *name);
3038int ptlrpc_service_health_check(struct ptlrpc_service *);
3039void ptlrpc_server_drop_request(struct ptlrpc_request *req);
3040void ptlrpc_request_change_export(struct ptlrpc_request *req,
3041 struct obd_export *export);
3042
3043int ptlrpc_hr_init(void);
3044void ptlrpc_hr_fini(void);
3045
3046
3047
3048
3049
3050
3051
3052
3053int ptlrpc_connect_import(struct obd_import *imp);
3054int ptlrpc_init_import(struct obd_import *imp);
3055int ptlrpc_disconnect_import(struct obd_import *imp, int noclose);
3056int ptlrpc_import_recovery_state_machine(struct obd_import *imp);
3057void deuuidify(char *uuid, const char *prefix, char **uuid_start,
3058 int *uuid_len);
3059
3060
3061int ptlrpc_reconnect_import(struct obd_import *imp);
3062
3063
3064
3065
3066
3067
3068
3069int ptlrpc_buf_need_swab(struct ptlrpc_request *req, const int inout,
3070 int index);
3071void ptlrpc_buf_set_swabbed(struct ptlrpc_request *req, const int inout,
3072 int index);
3073int ptlrpc_unpack_rep_msg(struct ptlrpc_request *req, int len);
3074int ptlrpc_unpack_req_msg(struct ptlrpc_request *req, int len);
3075
3076int lustre_msg_check_version(struct lustre_msg *msg, __u32 version);
3077void lustre_init_msg_v2(struct lustre_msg_v2 *msg, int count, __u32 *lens,
3078 char **bufs);
3079int lustre_pack_request(struct ptlrpc_request *, __u32 magic, int count,
3080 __u32 *lens, char **bufs);
3081int lustre_pack_reply(struct ptlrpc_request *, int count, __u32 *lens,
3082 char **bufs);
3083int lustre_pack_reply_v2(struct ptlrpc_request *req, int count,
3084 __u32 *lens, char **bufs, int flags);
3085#define LPRFL_EARLY_REPLY 1
3086int lustre_pack_reply_flags(struct ptlrpc_request *, int count, __u32 *lens,
3087 char **bufs, int flags);
3088int lustre_shrink_msg(struct lustre_msg *msg, int segment,
3089 unsigned int newlen, int move_data);
3090void lustre_free_reply_state(struct ptlrpc_reply_state *rs);
3091int __lustre_unpack_msg(struct lustre_msg *m, int len);
3092int lustre_msg_hdr_size(__u32 magic, int count);
3093int lustre_msg_size(__u32 magic, int count, __u32 *lengths);
3094int lustre_msg_size_v2(int count, __u32 *lengths);
3095int lustre_packed_msg_size(struct lustre_msg *msg);
3096int lustre_msg_early_size(void);
3097void *lustre_msg_buf_v2(struct lustre_msg_v2 *m, int n, int min_size);
3098void *lustre_msg_buf(struct lustre_msg *m, int n, int minlen);
3099int lustre_msg_buflen(struct lustre_msg *m, int n);
3100void lustre_msg_set_buflen(struct lustre_msg *m, int n, int len);
3101int lustre_msg_bufcount(struct lustre_msg *m);
3102char *lustre_msg_string(struct lustre_msg *m, int n, int max_len);
3103__u32 lustre_msghdr_get_flags(struct lustre_msg *msg);
3104void lustre_msghdr_set_flags(struct lustre_msg *msg, __u32 flags);
3105__u32 lustre_msg_get_flags(struct lustre_msg *msg);
3106void lustre_msg_add_flags(struct lustre_msg *msg, int flags);
3107void lustre_msg_set_flags(struct lustre_msg *msg, int flags);
3108void lustre_msg_clear_flags(struct lustre_msg *msg, int flags);
3109__u32 lustre_msg_get_op_flags(struct lustre_msg *msg);
3110void lustre_msg_add_op_flags(struct lustre_msg *msg, int flags);
3111void lustre_msg_set_op_flags(struct lustre_msg *msg, int flags);
3112struct lustre_handle *lustre_msg_get_handle(struct lustre_msg *msg);
3113__u32 lustre_msg_get_type(struct lustre_msg *msg);
3114__u32 lustre_msg_get_version(struct lustre_msg *msg);
3115void lustre_msg_add_version(struct lustre_msg *msg, int version);
3116__u32 lustre_msg_get_opc(struct lustre_msg *msg);
3117__u64 lustre_msg_get_last_xid(struct lustre_msg *msg);
3118__u64 lustre_msg_get_last_committed(struct lustre_msg *msg);
3119__u64 *lustre_msg_get_versions(struct lustre_msg *msg);
3120__u64 lustre_msg_get_transno(struct lustre_msg *msg);
3121__u64 lustre_msg_get_slv(struct lustre_msg *msg);
3122__u32 lustre_msg_get_limit(struct lustre_msg *msg);
3123void lustre_msg_set_slv(struct lustre_msg *msg, __u64 slv);
3124void lustre_msg_set_limit(struct lustre_msg *msg, __u64 limit);
3125int lustre_msg_get_status(struct lustre_msg *msg);
3126__u32 lustre_msg_get_conn_cnt(struct lustre_msg *msg);
3127int lustre_msg_is_v1(struct lustre_msg *msg);
3128__u32 lustre_msg_get_magic(struct lustre_msg *msg);
3129__u32 lustre_msg_get_timeout(struct lustre_msg *msg);
3130__u32 lustre_msg_get_service_time(struct lustre_msg *msg);
3131char *lustre_msg_get_jobid(struct lustre_msg *msg);
3132__u32 lustre_msg_get_cksum(struct lustre_msg *msg);
3133#if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(2, 7, 50, 0)
3134__u32 lustre_msg_calc_cksum(struct lustre_msg *msg, int compat18);
3135#else
3136# warning "remove checksum compatibility support for b1_8"
3137__u32 lustre_msg_calc_cksum(struct lustre_msg *msg);
3138#endif
3139void lustre_msg_set_handle(struct lustre_msg *msg,struct lustre_handle *handle);
3140void lustre_msg_set_type(struct lustre_msg *msg, __u32 type);
3141void lustre_msg_set_opc(struct lustre_msg *msg, __u32 opc);
3142void lustre_msg_set_last_xid(struct lustre_msg *msg, __u64 last_xid);
3143void lustre_msg_set_last_committed(struct lustre_msg *msg,__u64 last_committed);
3144void lustre_msg_set_versions(struct lustre_msg *msg, __u64 *versions);
3145void lustre_msg_set_transno(struct lustre_msg *msg, __u64 transno);
3146void lustre_msg_set_status(struct lustre_msg *msg, __u32 status);
3147void lustre_msg_set_conn_cnt(struct lustre_msg *msg, __u32 conn_cnt);
3148void ptlrpc_req_set_repsize(struct ptlrpc_request *req, int count, __u32 *sizes);
3149void ptlrpc_request_set_replen(struct ptlrpc_request *req);
3150void lustre_msg_set_timeout(struct lustre_msg *msg, __u32 timeout);
3151void lustre_msg_set_service_time(struct lustre_msg *msg, __u32 service_time);
3152void lustre_msg_set_jobid(struct lustre_msg *msg, char *jobid);
3153void lustre_msg_set_cksum(struct lustre_msg *msg, __u32 cksum);
3154
3155static inline void
3156lustre_shrink_reply(struct ptlrpc_request *req, int segment,
3157 unsigned int newlen, int move_data)
3158{
3159 LASSERT(req->rq_reply_state);
3160 LASSERT(req->rq_repmsg);
3161 req->rq_replen = lustre_shrink_msg(req->rq_repmsg, segment,
3162 newlen, move_data);
3163}
3164
3165
3166
3167static inline void
3168ptlrpc_rqphase_move(struct ptlrpc_request *req, enum rq_phase new_phase)
3169{
3170 if (req->rq_phase == new_phase)
3171 return;
3172
3173 if (new_phase == RQ_PHASE_UNREGISTERING) {
3174 req->rq_next_phase = req->rq_phase;
3175 if (req->rq_import)
3176 atomic_inc(&req->rq_import->imp_unregistering);
3177 }
3178
3179 if (req->rq_phase == RQ_PHASE_UNREGISTERING) {
3180 if (req->rq_import)
3181 atomic_dec(&req->rq_import->imp_unregistering);
3182 }
3183
3184 DEBUG_REQ(D_INFO, req, "move req \"%s\" -> \"%s\"",
3185 ptlrpc_rqphase2str(req), ptlrpc_phase2str(new_phase));
3186
3187 req->rq_phase = new_phase;
3188}
3189
3190
3191
3192
3193static inline int
3194ptlrpc_client_early(struct ptlrpc_request *req)
3195{
3196 if (OBD_FAIL_CHECK(OBD_FAIL_PTLRPC_LONG_REPL_UNLINK) &&
3197 req->rq_reply_deadline > cfs_time_current_sec())
3198 return 0;
3199 return req->rq_early;
3200}
3201
3202
3203
3204
3205static inline int
3206ptlrpc_client_replied(struct ptlrpc_request *req)
3207{
3208 if (OBD_FAIL_CHECK(OBD_FAIL_PTLRPC_LONG_REPL_UNLINK) &&
3209 req->rq_reply_deadline > cfs_time_current_sec())
3210 return 0;
3211 return req->rq_replied;
3212}
3213
3214
3215static inline int
3216ptlrpc_client_recv(struct ptlrpc_request *req)
3217{
3218 if (OBD_FAIL_CHECK(OBD_FAIL_PTLRPC_LONG_REPL_UNLINK) &&
3219 req->rq_reply_deadline > cfs_time_current_sec())
3220 return 1;
3221 return req->rq_receiving_reply;
3222}
3223
3224static inline int
3225ptlrpc_client_recv_or_unlink(struct ptlrpc_request *req)
3226{
3227 int rc;
3228
3229 spin_lock(&req->rq_lock);
3230 if (OBD_FAIL_CHECK(OBD_FAIL_PTLRPC_LONG_REPL_UNLINK) &&
3231 req->rq_reply_deadline > cfs_time_current_sec()) {
3232 spin_unlock(&req->rq_lock);
3233 return 1;
3234 }
3235 rc = req->rq_receiving_reply || req->rq_must_unlink;
3236 spin_unlock(&req->rq_lock);
3237 return rc;
3238}
3239
3240static inline void
3241ptlrpc_client_wake_req(struct ptlrpc_request *req)
3242{
3243 if (req->rq_set == NULL)
3244 wake_up(&req->rq_reply_waitq);
3245 else
3246 wake_up(&req->rq_set->set_waitq);
3247}
3248
3249static inline void
3250ptlrpc_rs_addref(struct ptlrpc_reply_state *rs)
3251{
3252 LASSERT(atomic_read(&rs->rs_refcount) > 0);
3253 atomic_inc(&rs->rs_refcount);
3254}
3255
3256static inline void
3257ptlrpc_rs_decref(struct ptlrpc_reply_state *rs)
3258{
3259 LASSERT(atomic_read(&rs->rs_refcount) > 0);
3260 if (atomic_dec_and_test(&rs->rs_refcount))
3261 lustre_free_reply_state(rs);
3262}
3263
3264
3265static inline void ptlrpc_req_drop_rs(struct ptlrpc_request *req)
3266{
3267 if (req->rq_reply_state == NULL)
3268 return;
3269 ptlrpc_rs_decref(req->rq_reply_state);
3270 req->rq_reply_state = NULL;
3271 req->rq_repmsg = NULL;
3272}
3273
3274static inline __u32 lustre_request_magic(struct ptlrpc_request *req)
3275{
3276 return lustre_msg_get_magic(req->rq_reqmsg);
3277}
3278
3279static inline int ptlrpc_req_get_repsize(struct ptlrpc_request *req)
3280{
3281 switch (req->rq_reqmsg->lm_magic) {
3282 case LUSTRE_MSG_MAGIC_V2:
3283 return req->rq_reqmsg->lm_repsize;
3284 default:
3285 LASSERTF(0, "incorrect message magic: %08x\n",
3286 req->rq_reqmsg->lm_magic);
3287 return -EFAULT;
3288 }
3289}
3290
3291static inline int ptlrpc_send_limit_expired(struct ptlrpc_request *req)
3292{
3293 if (req->rq_delay_limit != 0 &&
3294 cfs_time_before(cfs_time_add(req->rq_queued_time,
3295 cfs_time_seconds(req->rq_delay_limit)),
3296 cfs_time_current())) {
3297 return 1;
3298 }
3299 return 0;
3300}
3301
3302static inline int ptlrpc_no_resend(struct ptlrpc_request *req)
3303{
3304 if (!req->rq_no_resend && ptlrpc_send_limit_expired(req)) {
3305 spin_lock(&req->rq_lock);
3306 req->rq_no_resend = 1;
3307 spin_unlock(&req->rq_lock);
3308 }
3309 return req->rq_no_resend;
3310}
3311
3312static inline int
3313ptlrpc_server_get_timeout(struct ptlrpc_service_part *svcpt)
3314{
3315 int at = AT_OFF ? 0 : at_get(&svcpt->scp_at_estimate);
3316
3317 return svcpt->scp_service->srv_watchdog_factor *
3318 max_t(int, at, obd_timeout);
3319}
3320
3321static inline struct ptlrpc_service *
3322ptlrpc_req2svc(struct ptlrpc_request *req)
3323{
3324 LASSERT(req->rq_rqbd != NULL);
3325 return req->rq_rqbd->rqbd_svcpt->scp_service;
3326}
3327
3328
3329
3330
3331
3332
3333int client_obd_setup(struct obd_device *obddev, struct lustre_cfg *lcfg);
3334int client_obd_cleanup(struct obd_device *obddev);
3335int client_connect_import(const struct lu_env *env,
3336 struct obd_export **exp, struct obd_device *obd,
3337 struct obd_uuid *cluuid, struct obd_connect_data *,
3338 void *localdata);
3339int client_disconnect_export(struct obd_export *exp);
3340int client_import_add_conn(struct obd_import *imp, struct obd_uuid *uuid,
3341 int priority);
3342int client_import_del_conn(struct obd_import *imp, struct obd_uuid *uuid);
3343int client_import_find_conn(struct obd_import *imp, lnet_nid_t peer,
3344 struct obd_uuid *uuid);
3345int import_set_conn_priority(struct obd_import *imp, struct obd_uuid *uuid);
3346void client_destroy_import(struct obd_import *imp);
3347
3348
3349
3350
3351
3352
3353
3354
3355enum timeout_event {
3356 TIMEOUT_GRANT = 1
3357};
3358struct timeout_item;
3359typedef int (*timeout_cb_t)(struct timeout_item *, void *);
3360int ptlrpc_pinger_add_import(struct obd_import *imp);
3361int ptlrpc_pinger_del_import(struct obd_import *imp);
3362int ptlrpc_add_timeout_client(int time, enum timeout_event event,
3363 timeout_cb_t cb, void *data,
3364 struct list_head *obd_list);
3365int ptlrpc_del_timeout_client(struct list_head *obd_list,
3366 enum timeout_event event);
3367struct ptlrpc_request * ptlrpc_prep_ping(struct obd_import *imp);
3368int ptlrpc_obd_ping(struct obd_device *obd);
3369cfs_time_t ptlrpc_suspend_wakeup_time(void);
3370void ping_evictor_start(void);
3371void ping_evictor_stop(void);
3372int ptlrpc_check_and_wait_suspend(struct ptlrpc_request *req);
3373void ptlrpc_pinger_ir_up(void);
3374void ptlrpc_pinger_ir_down(void);
3375
3376int ptlrpc_pinger_suppress_pings(void);
3377
3378
3379typedef enum {
3380
3381 PDB_POLICY_NONE = 1,
3382
3383 PDB_POLICY_FULL = 2,
3384
3385 PDB_POLICY_PAIR = 3,
3386
3387
3388
3389
3390 PDB_POLICY_NEIGHBOR = 4,
3391} pdb_policy_t;
3392
3393
3394
3395
3396
3397
3398
3399typedef enum {
3400
3401 PDL_POLICY_SAME = 1,
3402
3403 PDL_POLICY_LOCAL = 2,
3404
3405 PDL_POLICY_ROUND = 3,
3406
3407 PDL_POLICY_PREFERRED = 4,
3408} pdl_policy_t;
3409
3410
3411void ptlrpcd_stop(struct ptlrpcd_ctl *pc, int force);
3412void ptlrpcd_free(struct ptlrpcd_ctl *pc);
3413void ptlrpcd_wake(struct ptlrpc_request *req);
3414void ptlrpcd_add_req(struct ptlrpc_request *req, pdl_policy_t policy, int idx);
3415void ptlrpcd_add_rqset(struct ptlrpc_request_set *set);
3416int ptlrpcd_addref(void);
3417void ptlrpcd_decref(void);
3418
3419
3420
3421
3422
3423
3424const char* ll_opcode2str(__u32 opcode);
3425#ifdef LPROCFS
3426void ptlrpc_lprocfs_register_obd(struct obd_device *obd);
3427void ptlrpc_lprocfs_unregister_obd(struct obd_device *obd);
3428void ptlrpc_lprocfs_brw(struct ptlrpc_request *req, int bytes);
3429#else
3430static inline void ptlrpc_lprocfs_register_obd(struct obd_device *obd) {}
3431static inline void ptlrpc_lprocfs_unregister_obd(struct obd_device *obd) {}
3432static inline void ptlrpc_lprocfs_brw(struct ptlrpc_request *req, int bytes) {}
3433#endif
3434
3435
3436
3437int llog_origin_handle_open(struct ptlrpc_request *req);
3438int llog_origin_handle_destroy(struct ptlrpc_request *req);
3439int llog_origin_handle_prev_block(struct ptlrpc_request *req);
3440int llog_origin_handle_next_block(struct ptlrpc_request *req);
3441int llog_origin_handle_read_header(struct ptlrpc_request *req);
3442int llog_origin_handle_close(struct ptlrpc_request *req);
3443int llog_origin_handle_cancel(struct ptlrpc_request *req);
3444
3445
3446extern struct llog_operations llog_client_ops;
3447
3448
3449
3450#endif
3451
3452