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 NRS_TBF_KEY_LEN (LNET_NIDSTR_SIZE + LUSTRE_JOBID_SIZE + 3 + 2)
55 struct nrs_tbf_client {
56 /** Resource object for policy instance. */
57 struct ptlrpc_nrs_resource tc_res;
58 /** Node in the hash table. */
59 struct hlist_node tc_hnode;
60 /** NID of the client. */
62 /** Jobid of the client. */
63 char tc_jobid[LUSTRE_JOBID_SIZE];
64 /** opcode of the client. */
66 /** Hash key of the client. */
67 char tc_key[NRS_TBF_KEY_LEN];
68 /** Reference number of the client. */
70 /** Lock to protect rule and linkage. */
71 spinlock_t tc_rule_lock;
72 /** Linkage to rule. */
73 struct list_head tc_linkage;
74 /** Pointer to rule. */
75 struct nrs_tbf_rule *tc_rule;
76 /** Generation of the rule matched. */
77 __u64 tc_rule_generation;
78 /** Limit of RPC rate. */
80 /** Time to wait for next token. */
82 /** RPC token number. */
84 /** Token bucket depth. */
86 /** Time check-point. */
88 /** List of queued requests. */
89 struct list_head tc_list;
90 /** Node in binary heap. */
91 struct cfs_binheap_node tc_node;
92 /** Whether the client is in heap. */
94 /** Sequence of the newest rule. */
95 __u32 tc_rule_sequence;
97 * Linkage into LRU list. Protected bucket lock of
98 * nrs_tbf_head::th_cli_hash.
100 struct list_head tc_lru;
103 #define MAX_TBF_NAME (16)
105 #define NTRS_STOPPING 0x0000001
106 #define NTRS_DEFAULT 0x0000002
108 struct nrs_tbf_rule {
109 /** Name of the rule. */
110 char tr_name[MAX_TBF_NAME];
111 /** Head belongs to. */
112 struct nrs_tbf_head *tr_head;
113 /** Likage to head. */
114 struct list_head tr_linkage;
115 /** Nid list of the rule. */
116 struct list_head tr_nids;
117 /** Nid list string of the rule.*/
119 /** Jobid list of the rule. */
120 struct list_head tr_jobids;
121 /** Jobid list string of the rule.*/
123 /** Opcode bitmap of the rule. */
124 struct cfs_bitmap *tr_opcodes;
125 /** Opcode list string of the rule.*/
126 char *tr_opcodes_str;
127 /** Condition list of the rule.*/
128 struct list_head tr_conds;
129 /** Generic condition string of the rule. */
133 /** Time to wait for next token. */
135 /** Token bucket depth. */
137 /** Lock to protect the list of clients. */
138 spinlock_t tr_rule_lock;
139 /** List of client. */
140 struct list_head tr_cli_list;
141 /** Flags of the rule. */
143 /** Usage Reference count taken on the rule. */
145 /** Generation of the rule. */
151 int (*o_startup)(struct ptlrpc_nrs_policy *, struct nrs_tbf_head *);
152 struct nrs_tbf_client *(*o_cli_find)(struct nrs_tbf_head *,
153 struct ptlrpc_request *);
154 struct nrs_tbf_client *(*o_cli_findadd)(struct nrs_tbf_head *,
155 struct nrs_tbf_client *);
156 void (*o_cli_put)(struct nrs_tbf_head *, struct nrs_tbf_client *);
157 void (*o_cli_init)(struct nrs_tbf_client *, struct ptlrpc_request *);
158 int (*o_rule_init)(struct ptlrpc_nrs_policy *,
159 struct nrs_tbf_rule *,
160 struct nrs_tbf_cmd *);
161 int (*o_rule_dump)(struct nrs_tbf_rule *, struct seq_file *);
162 int (*o_rule_match)(struct nrs_tbf_rule *,
163 struct nrs_tbf_client *);
164 void (*o_rule_fini)(struct nrs_tbf_rule *);
167 #define NRS_TBF_TYPE_JOBID "jobid"
168 #define NRS_TBF_TYPE_NID "nid"
169 #define NRS_TBF_TYPE_OPCODE "opcode"
170 #define NRS_TBF_TYPE_GENERIC "generic"
171 #define NRS_TBF_TYPE_MAX_LEN 20
174 NRS_TBF_FLAG_INVALID = 0x0000000,
175 NRS_TBF_FLAG_JOBID = 0x0000001,
176 NRS_TBF_FLAG_NID = 0x0000002,
177 NRS_TBF_FLAG_OPCODE = 0x0000004,
178 NRS_TBF_FLAG_GENERIC = 0x0000008,
181 struct nrs_tbf_type {
182 const char *ntt_name;
183 enum nrs_tbf_flag ntt_flag;
184 struct nrs_tbf_ops *ntt_ops;
187 struct nrs_tbf_bucket {
189 * LRU list, updated on each access to client. Protected by
190 * bucket lock of nrs_tbf_head::th_cli_hash.
192 struct list_head ntb_lru;
196 * Private data structure for the TBF policy
198 struct nrs_tbf_head {
200 * Resource object for policy instance.
202 struct ptlrpc_nrs_resource th_res;
206 struct list_head th_list;
208 * Lock to protect the list of rules.
210 spinlock_t th_rule_lock;
212 * Generation of rules.
214 atomic_t th_rule_sequence;
218 struct nrs_tbf_rule *th_rule;
220 * Timer for next token.
222 struct hrtimer th_timer;
224 * Deadline of the timer.
228 * Sequence of requests.
234 struct cfs_binheap *th_binheap;
238 struct cfs_hash *th_cli_hash;
240 * Type of TBF policy.
242 char th_type[NRS_TBF_TYPE_MAX_LEN + 1];
246 struct nrs_tbf_ops *th_ops;
252 * Index of bucket on hash table while purging.
257 enum nrs_tbf_cmd_type {
258 NRS_CTL_TBF_START_RULE = 0,
259 NRS_CTL_TBF_STOP_RULE,
260 NRS_CTL_TBF_CHANGE_RULE,
264 enum nrs_tbf_cmd_type tc_cmd;
267 struct nrs_tbf_cmd_start {
269 struct list_head ts_nids;
271 struct list_head ts_jobids;
273 struct cfs_bitmap *ts_opcodes;
274 char *ts_opcodes_str;
275 struct list_head ts_conds;
281 struct nrs_tbf_cmd_change {
291 NRS_TBF_FIELD_OPCODE,
295 struct nrs_tbf_expression {
296 enum nrs_tbf_field te_field;
297 struct list_head te_cond;
298 struct cfs_bitmap *te_opcodes;
299 struct list_head te_linkage;
302 struct nrs_tbf_conjunction {
304 * link to disjunction.
306 struct list_head tc_linkage;
308 * list of logical conjunction
310 struct list_head tc_expressions;
317 struct list_head tr_list;
319 * Sequence of the request.
325 * TBF policy operations.
329 * Read the the data of a TBF policy.
331 NRS_CTL_TBF_RD_RULE = PTLRPC_NRS_CTL_1ST_POL_SPEC,
333 * Write the the data of a TBF policy.
337 * Read the TBF policy type preset by proc entry "nrs_policies".
339 NRS_CTL_TBF_RD_TYPE_FLAG,