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. */
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 cfs_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 struct cfs_bitmap *tr_opcodes;
165 /** Opcode list string of the rule.*/
166 char *tr_opcodes_str;
167 /** Condition list of the rule.*/
168 struct list_head tr_conds;
169 /** Generic condition string of the rule. */
173 /** Time to wait for next token. */
175 /** Token bucket depth. */
177 /** Lock to protect the list of clients. */
178 spinlock_t tr_rule_lock;
179 /** List of client. */
180 struct list_head tr_cli_list;
181 /** Flags of the rule. */
182 enum nrs_rule_flags tr_flags;
183 /** Usage Reference count taken on the rule. */
185 /** Generation of the rule. */
191 int (*o_startup)(struct ptlrpc_nrs_policy *, struct nrs_tbf_head *);
192 struct nrs_tbf_client *(*o_cli_find)(struct nrs_tbf_head *,
193 struct ptlrpc_request *);
194 struct nrs_tbf_client *(*o_cli_findadd)(struct nrs_tbf_head *,
195 struct nrs_tbf_client *);
196 void (*o_cli_put)(struct nrs_tbf_head *, struct nrs_tbf_client *);
197 void (*o_cli_init)(struct nrs_tbf_client *, struct ptlrpc_request *);
198 int (*o_rule_init)(struct ptlrpc_nrs_policy *,
199 struct nrs_tbf_rule *,
200 struct nrs_tbf_cmd *);
201 int (*o_rule_dump)(struct nrs_tbf_rule *, struct seq_file *);
202 int (*o_rule_match)(struct nrs_tbf_rule *,
203 struct nrs_tbf_client *);
204 void (*o_rule_fini)(struct nrs_tbf_rule *);
207 #define NRS_TBF_TYPE_JOBID "jobid"
208 #define NRS_TBF_TYPE_NID "nid"
209 #define NRS_TBF_TYPE_OPCODE "opcode"
210 #define NRS_TBF_TYPE_GENERIC "generic"
211 #define NRS_TBF_TYPE_UID "uid"
212 #define NRS_TBF_TYPE_GID "gid"
213 #define NRS_TBF_TYPE_MAX_LEN 20
215 struct nrs_tbf_type {
216 const char *ntt_name;
217 enum nrs_tbf_flag ntt_flag;
218 struct nrs_tbf_ops *ntt_ops;
221 struct nrs_tbf_bucket {
223 * LRU list, updated on each access to client. Protected by
224 * bucket lock of nrs_tbf_head::th_cli_hash.
226 struct list_head ntb_lru;
230 * Private data structure for the TBF policy
232 struct nrs_tbf_head {
234 * Resource object for policy instance.
236 struct ptlrpc_nrs_resource th_res;
240 struct list_head th_list;
242 * Lock to protect the list of rules.
244 spinlock_t th_rule_lock;
246 * Generation of rules.
248 atomic_t th_rule_sequence;
252 struct nrs_tbf_rule *th_rule;
254 * Timer for next token.
256 struct hrtimer th_timer;
258 * Deadline of the timer.
262 * Sequence of requests.
268 struct cfs_binheap *th_binheap;
272 struct cfs_hash *th_cli_hash;
274 * Type of TBF policy.
276 char th_type[NRS_TBF_TYPE_MAX_LEN + 1];
280 struct nrs_tbf_ops *th_ops;
286 * Index of bucket on hash table while purging.
291 enum nrs_tbf_cmd_type {
292 NRS_CTL_TBF_START_RULE = 0,
293 NRS_CTL_TBF_STOP_RULE,
294 NRS_CTL_TBF_CHANGE_RULE,
298 enum nrs_tbf_cmd_type tc_cmd;
301 struct nrs_tbf_cmd_start {
303 struct list_head ts_nids;
305 struct list_head ts_jobids;
307 struct list_head ts_ids;
309 struct cfs_bitmap *ts_opcodes;
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 struct cfs_bitmap *te_opcodes;
337 struct list_head te_linkage;
340 struct nrs_tbf_conjunction {
342 * link to disjunction.
344 struct list_head tc_linkage;
346 * list of logical conjunction
348 struct list_head tc_expressions;
355 struct list_head tr_list;
357 * Sequence of the request.
363 * TBF policy operations.
367 * Read the the data of a TBF policy.
369 NRS_CTL_TBF_RD_RULE = PTLRPC_NRS_CTL_1ST_POL_SPEC,
371 * Write the the data of a TBF policy.
375 * Read the TBF policy type preset by proc entry "nrs_policies".
377 NRS_CTL_TBF_RD_TYPE_FLAG,