4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
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.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License version 2 for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; If not, see
17 * http://www.gnu.org/licenses/gpl-2.0.html
22 * Copyright (C) 2013 DataDirect Networks, Inc.
24 * Copyright (c) 2014, Intel Corporation.
28 * Network Request Scheduler (NRS) Token Bucket Filter(TBF) policy
32 #ifndef _LUSTRE_NRS_TBF_H
33 #define _LUSTRE_NRS_TBF_H
45 #define NRS_TBF_MATCH_FULL 0x0000001
46 #define NRS_TBF_MATCH_WILDCARD 0x0000002
48 struct nrs_tbf_jobid {
51 struct list_head tj_linkage;
54 #define MAX_U32_STR_LEN 10
55 #define NRS_TBF_KEY_LEN (LNET_NIDSTR_SIZE + LUSTRE_JOBID_SIZE + \
56 MAX_U32_STR_LEN + MAX_U32_STR_LEN + 3 + 2)
59 NRS_TBF_FLAG_INVALID = 0x0000000,
60 NRS_TBF_FLAG_JOBID = 0x0000001,
61 NRS_TBF_FLAG_NID = 0x0000002,
62 NRS_TBF_FLAG_OPCODE = 0x0000004,
63 NRS_TBF_FLAG_GENERIC = 0x0000008,
64 NRS_TBF_FLAG_UID = 0x0000010,
65 NRS_TBF_FLAG_GID = 0x0000020,
69 enum nrs_tbf_flag ti_type;
76 struct list_head nti_linkage;
79 struct nrs_tbf_client {
80 /** Resource object for policy instance. */
81 struct ptlrpc_nrs_resource tc_res;
82 /** Node in the hash table. */
83 struct hlist_node tc_hnode;
84 /** NID of the client. */
85 struct lnet_nid tc_nid;
86 /** Jobid of the client. */
87 char tc_jobid[LUSTRE_JOBID_SIZE];
88 /** opcode of the client. */
90 /** gid or uid of the client. */
92 /** Hash key of the client. */
93 char tc_key[NRS_TBF_KEY_LEN];
94 /** Reference number of the client. */
96 /** Lock to protect rule and linkage. */
97 spinlock_t tc_rule_lock;
98 /** Linkage to rule. */
99 struct list_head tc_linkage;
100 /** Pointer to rule. */
101 struct nrs_tbf_rule *tc_rule;
102 /** Generation of the rule matched. */
103 __u64 tc_rule_generation;
104 /** Limit of RPC rate. */
106 /** Time to wait for next token. */
108 /** RPC token number. */
110 /** Token bucket depth. */
112 /** Time check-point. */
114 /** Deadline of a class */
117 * Time residue: the remainder of elapsed time
118 * divided by nsecs when dequeue a request.
120 __u64 tc_nsecs_resid;
121 /** List of queued requests. */
122 struct list_head tc_list;
123 /** Node in binary heap. */
124 struct binheap_node tc_node;
125 /** Whether the client is in heap. */
127 /** Sequence of the newest rule. */
128 __u32 tc_rule_sequence;
130 * Linkage into LRU list. Protected bucket lock of
131 * nrs_tbf_head::th_cli_hash.
133 struct list_head tc_lru;
136 #define MAX_TBF_NAME (16)
138 enum nrs_rule_flags {
139 NTRS_STOPPING = 0x00000001,
140 NTRS_DEFAULT = 0x00000002,
141 NTRS_REALTIME = 0x00000004,
144 struct nrs_tbf_rule {
145 /** Name of the rule. */
146 char tr_name[MAX_TBF_NAME];
147 /** Head belongs to. */
148 struct nrs_tbf_head *tr_head;
149 /** Likage to head. */
150 struct list_head tr_linkage;
151 /** Nid list of the rule. */
152 struct list_head tr_nids;
153 /** Nid list string of the rule.*/
155 /** Jobid list of the rule. */
156 struct list_head tr_jobids;
157 /** Jobid list string of the rule.*/
159 /** uid/gid list of the rule. */
160 struct list_head tr_ids;
161 /** uid/gid list string of the rule. */
163 /** Opcode bitmap of the rule. */
164 unsigned long *tr_opcodes;
166 /** Opcode list string of the rule.*/
167 char *tr_opcodes_str;
168 /** Condition list of the rule.*/
169 struct list_head tr_conds;
170 /** Generic condition string of the rule. */
174 /** Time to wait for next token. */
175 u64 tr_nsecs_per_rpc;
176 /** Token bucket depth. */
178 /** Lock to protect the list of clients. */
179 spinlock_t tr_rule_lock;
180 /** List of client. */
181 struct list_head tr_cli_list;
182 /** Flags of the rule. */
183 enum nrs_rule_flags tr_flags;
184 /** Usage Reference count taken on the rule. */
186 /** Generation of the rule. */
192 int (*o_startup)(struct ptlrpc_nrs_policy *, struct nrs_tbf_head *);
193 struct nrs_tbf_client *(*o_cli_find)(struct nrs_tbf_head *,
194 struct ptlrpc_request *);
195 struct nrs_tbf_client *(*o_cli_findadd)(struct nrs_tbf_head *,
196 struct nrs_tbf_client *);
197 void (*o_cli_put)(struct nrs_tbf_head *, struct nrs_tbf_client *);
198 void (*o_cli_init)(struct nrs_tbf_client *, struct ptlrpc_request *);
199 int (*o_rule_init)(struct ptlrpc_nrs_policy *,
200 struct nrs_tbf_rule *,
201 struct nrs_tbf_cmd *);
202 int (*o_rule_dump)(struct nrs_tbf_rule *, struct seq_file *);
203 int (*o_rule_match)(struct nrs_tbf_rule *,
204 struct nrs_tbf_client *);
205 void (*o_rule_fini)(struct nrs_tbf_rule *);
208 #define NRS_TBF_TYPE_JOBID "jobid"
209 #define NRS_TBF_TYPE_NID "nid"
210 #define NRS_TBF_TYPE_OPCODE "opcode"
211 #define NRS_TBF_TYPE_GENERIC "generic"
212 #define NRS_TBF_TYPE_UID "uid"
213 #define NRS_TBF_TYPE_GID "gid"
214 #define NRS_TBF_TYPE_MAX_LEN 20
216 struct nrs_tbf_type {
217 const char *ntt_name;
218 enum nrs_tbf_flag ntt_flag;
219 struct nrs_tbf_ops *ntt_ops;
222 struct nrs_tbf_bucket {
224 * LRU list, updated on each access to client. Protected by
225 * bucket lock of nrs_tbf_head::th_cli_hash.
227 struct list_head ntb_lru;
231 * Private data structure for the TBF policy
233 struct nrs_tbf_head {
235 * Resource object for policy instance.
237 struct ptlrpc_nrs_resource th_res;
241 struct list_head th_list;
243 * Lock to protect the list of rules.
245 spinlock_t th_rule_lock;
247 * Generation of rules.
249 atomic_t th_rule_sequence;
253 struct nrs_tbf_rule *th_rule;
255 * Timer for next token.
257 struct hrtimer th_timer;
259 * Deadline of the timer.
263 * Sequence of requests.
269 struct binheap *th_binheap;
273 struct cfs_hash *th_cli_hash;
275 * Type of TBF policy.
277 char th_type[NRS_TBF_TYPE_MAX_LEN + 1];
281 struct nrs_tbf_ops *th_ops;
287 * Index of bucket on hash table while purging.
292 enum nrs_tbf_cmd_type {
293 NRS_CTL_TBF_START_RULE = 0,
294 NRS_CTL_TBF_STOP_RULE,
295 NRS_CTL_TBF_CHANGE_RULE,
299 enum nrs_tbf_cmd_type tc_cmd;
302 struct nrs_tbf_cmd_start {
304 struct list_head ts_nids;
306 struct list_head ts_jobids;
308 struct list_head ts_ids;
310 char *ts_opcodes_str;
311 struct list_head ts_conds;
314 enum nrs_rule_flags ts_rule_flags;
317 struct nrs_tbf_cmd_change {
327 NRS_TBF_FIELD_OPCODE,
333 struct nrs_tbf_expression {
334 enum nrs_tbf_field te_field;
335 struct list_head te_cond;
336 unsigned long *te_opcodes;
338 struct list_head te_linkage;
341 struct nrs_tbf_conjunction {
343 * link to disjunction.
345 struct list_head tc_linkage;
347 * list of logical conjunction
349 struct list_head tc_expressions;
356 struct list_head tr_list;
358 * Sequence of the request.
364 * TBF policy operations.
366 * Read the the data of a TBF policy.
368 #define NRS_CTL_TBF_RD_RULE PTLRPC_NRS_CTL_POL_SPEC_01
370 * Write the the data of a TBF policy.
372 #define NRS_CTL_TBF_WR_RULE PTLRPC_NRS_CTL_POL_SPEC_02
374 * Read the TBF policy type preset by proc entry "nrs_policies".
376 #define NRS_CTL_TBF_RD_TYPE_FLAG PTLRPC_NRS_CTL_POL_SPEC_03