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 rhash_head tc_rhash;
84 struct hlist_node tc_hnode;
85 /** NID of the client. */
86 struct lnet_nid tc_nid;
87 /** Jobid of the client. */
88 char tc_jobid[LUSTRE_JOBID_SIZE];
89 /** opcode of the client. */
91 /** gid or uid of the client. */
93 /** Hash key of the client. */
94 char tc_key[NRS_TBF_KEY_LEN];
95 /** Reference number of the client. */
97 /** Lock to protect rule and linkage. */
98 spinlock_t tc_rule_lock;
99 /** Linkage to rule. */
100 struct list_head tc_linkage;
101 /** Pointer to rule. */
102 struct nrs_tbf_rule *tc_rule;
103 /** Generation of the rule matched. */
104 __u64 tc_rule_generation;
105 /** Limit of RPC rate. */
107 /** Time to wait for next token. */
109 /** RPC token number. */
111 /** Token bucket depth. */
113 /** Time check-point. */
115 /** Deadline of a class */
118 * Time residue: the remainder of elapsed time
119 * divided by nsecs when dequeue a request.
121 __u64 tc_nsecs_resid;
122 /** List of queued requests. */
123 struct list_head tc_list;
124 /** Node in binary heap. */
125 struct binheap_node tc_node;
126 /** Whether the client is in heap. */
128 /** Sequence of the newest rule. */
129 __u32 tc_rule_sequence;
131 * Linkage into LRU list. Protected bucket lock of
132 * nrs_tbf_head::th_cli_hash.
134 struct list_head tc_lru;
136 * RCU head for rhashtable handling
138 struct rcu_head tc_rcu_head;
141 #define MAX_TBF_NAME (16)
143 enum nrs_rule_flags {
144 NTRS_STOPPING = 0x00000001,
145 NTRS_DEFAULT = 0x00000002,
146 NTRS_REALTIME = 0x00000004,
149 struct nrs_tbf_rule {
150 /** Name of the rule. */
151 char tr_name[MAX_TBF_NAME];
152 /** Head belongs to. */
153 struct nrs_tbf_head *tr_head;
154 /** Likage to head. */
155 struct list_head tr_linkage;
156 /** Nid list of the rule. */
157 struct list_head tr_nids;
158 /** Nid list string of the rule.*/
160 /** Jobid list of the rule. */
161 struct list_head tr_jobids;
162 /** Jobid list string of the rule.*/
164 /** uid/gid list of the rule. */
165 struct list_head tr_ids;
166 /** uid/gid list string of the rule. */
168 /** Opcode bitmap of the rule. */
169 unsigned long *tr_opcodes;
171 /** Opcode list string of the rule.*/
172 char *tr_opcodes_str;
173 /** Condition list of the rule.*/
174 struct list_head tr_conds;
175 /** Generic condition string of the rule. */
179 /** Time to wait for next token. */
180 u64 tr_nsecs_per_rpc;
181 /** Token bucket depth. */
183 /** Lock to protect the list of clients. */
184 spinlock_t tr_rule_lock;
185 /** List of client. */
186 struct list_head tr_cli_list;
187 /** Flags of the rule. */
188 enum nrs_rule_flags tr_flags;
189 /** Usage Reference count taken on the rule. */
191 /** Generation of the rule. */
197 int (*o_startup)(struct ptlrpc_nrs_policy *, struct nrs_tbf_head *);
198 struct nrs_tbf_client *(*o_cli_find)(struct nrs_tbf_head *,
199 struct ptlrpc_request *);
200 struct nrs_tbf_client *(*o_cli_findadd)(struct nrs_tbf_head *,
201 struct nrs_tbf_client *);
202 void (*o_cli_put)(struct nrs_tbf_head *, struct nrs_tbf_client *);
203 void (*o_cli_init)(struct nrs_tbf_client *, struct ptlrpc_request *);
204 int (*o_rule_init)(struct ptlrpc_nrs_policy *,
205 struct nrs_tbf_rule *,
206 struct nrs_tbf_cmd *);
207 int (*o_rule_dump)(struct nrs_tbf_rule *, struct seq_file *);
208 int (*o_rule_match)(struct nrs_tbf_rule *,
209 struct nrs_tbf_client *);
210 void (*o_rule_fini)(struct nrs_tbf_rule *);
213 #define NRS_TBF_TYPE_JOBID "jobid"
214 #define NRS_TBF_TYPE_NID "nid"
215 #define NRS_TBF_TYPE_OPCODE "opcode"
216 #define NRS_TBF_TYPE_GENERIC "generic"
217 #define NRS_TBF_TYPE_UID "uid"
218 #define NRS_TBF_TYPE_GID "gid"
219 #define NRS_TBF_TYPE_MAX_LEN 20
221 struct nrs_tbf_type {
222 const char *ntt_name;
223 enum nrs_tbf_flag ntt_flag;
224 struct nrs_tbf_ops *ntt_ops;
227 struct nrs_tbf_bucket {
229 * LRU list, updated on each access to client. Protected by
230 * bucket lock of nrs_tbf_head::th_cli_hash.
232 struct list_head ntb_lru;
236 * Private data structure for the TBF policy
238 struct nrs_tbf_head {
240 * Resource object for policy instance.
242 struct ptlrpc_nrs_resource th_res;
246 struct rhashtable th_cli_rhash ____cacheline_aligned_in_smp;
250 struct list_head th_list;
252 * Lock to protect the list of rules.
254 spinlock_t th_rule_lock;
256 * Generation of rules.
258 atomic_t th_rule_sequence;
262 struct nrs_tbf_rule *th_rule;
264 * Timer for next token.
266 struct hrtimer th_timer;
268 * Deadline of the timer.
272 * Sequence of requests.
278 struct binheap *th_binheap;
282 struct cfs_hash *th_cli_hash;
284 * Type of TBF policy.
286 char th_type[NRS_TBF_TYPE_MAX_LEN + 1];
290 struct nrs_tbf_ops *th_ops;
296 * Index of bucket on hash table while purging.
301 enum nrs_tbf_cmd_type {
302 NRS_CTL_TBF_START_RULE = 0,
303 NRS_CTL_TBF_STOP_RULE,
304 NRS_CTL_TBF_CHANGE_RULE,
308 enum nrs_tbf_cmd_type tc_cmd;
311 struct nrs_tbf_cmd_start {
313 struct list_head ts_nids;
315 struct list_head ts_jobids;
317 struct list_head ts_ids;
319 char *ts_opcodes_str;
320 struct list_head ts_conds;
323 enum nrs_rule_flags ts_rule_flags;
326 struct nrs_tbf_cmd_change {
336 NRS_TBF_FIELD_OPCODE,
342 struct nrs_tbf_expression {
343 enum nrs_tbf_field te_field;
344 struct list_head te_cond;
345 unsigned long *te_opcodes;
347 struct list_head te_linkage;
350 struct nrs_tbf_conjunction {
352 * link to disjunction.
354 struct list_head tc_linkage;
356 * list of logical conjunction
358 struct list_head tc_expressions;
365 struct list_head tr_list;
367 * Sequence of the request.
373 * TBF policy operations.
375 * Read the the data of a TBF policy.
377 #define NRS_CTL_TBF_RD_RULE PTLRPC_NRS_CTL_POL_SPEC_01
379 * Write the the data of a TBF policy.
381 #define NRS_CTL_TBF_WR_RULE PTLRPC_NRS_CTL_POL_SPEC_02
383 * Read the TBF policy type preset by proc entry "nrs_policies".
385 #define NRS_CTL_TBF_RD_TYPE_FLAG PTLRPC_NRS_CTL_POL_SPEC_03