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. A copy is
14 * included in the COPYING file that accompanied this code.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 * Copyright (C) 2013 DataDirect Networks, Inc.
28 * Network Request Scheduler (NRS) Token Bucket Filter(TBF) policy
32 #ifndef _LUSTRE_NRS_TBF_H
33 #define _LUSTRE_NRS_TBF_H
34 #include <lustre_net.h>
46 struct nrs_tbf_jobid {
48 cfs_list_t tj_linkage;
51 struct nrs_tbf_client {
52 /** Resource object for policy instance. */
53 struct ptlrpc_nrs_resource tc_res;
54 /** Node in the hash table. */
55 cfs_hlist_node_t tc_hnode;
56 /** NID of the client. */
58 /** Jobid of the client. */
59 char tc_jobid[JOBSTATS_JOBID_SIZE];
60 /** Reference number of the client. */
62 /** Likage to rule. */
63 cfs_list_t tc_linkage;
64 /** Pointer to rule. */
65 struct nrs_tbf_rule *tc_rule;
66 /** Generation of the rule matched. */
67 __u64 tc_rule_generation;
68 /** Limit of RPC rate. */
70 /** Time to wait for next token. */
72 /** RPC token number. */
74 /** Token bucket depth. */
76 /** Time check-point. */
78 /** List of queued requests. */
80 /** Node in binary heap. */
81 cfs_binheap_node_t tc_node;
82 /** Whether the client is in heap. */
84 /** Sequence of the newest rule. */
85 __u32 tc_rule_sequence;
87 * Linkage into LRU list. Protected bucket lock of
88 * nrs_tbf_head::th_cli_hash.
93 #define MAX_TBF_NAME (16)
95 #define NTRS_STOPPING 0x0000001
96 #define NTRS_DEFAULT 0x0000002
99 /** Name of the rule. */
100 char tr_name[MAX_TBF_NAME];
101 /** Head belongs to. */
102 struct nrs_tbf_head *tr_head;
103 /** Likage to head. */
104 cfs_list_t tr_linkage;
105 /** Nid list of the rule. */
107 /** Nid list string of the rule.*/
109 /** Jobid list of the rule. */
110 cfs_list_t tr_jobids;
111 /** Jobid list string of the rule.*/
115 /** Time to wait for next token. */
117 /** Token bucket depth. */
119 /** List of client. */
120 cfs_list_t tr_cli_list;
121 /** Flags of the rule. */
123 /** Usage Reference count taken on the rule. */
125 /** Generation of the rule. */
131 int (*o_startup)(struct ptlrpc_nrs_policy *, struct nrs_tbf_head *);
132 struct nrs_tbf_client *(*o_cli_find)(struct nrs_tbf_head *,
133 struct ptlrpc_request *);
134 struct nrs_tbf_client *(*o_cli_findadd)(struct nrs_tbf_head *,
135 struct nrs_tbf_client *);
136 void (*o_cli_put)(struct nrs_tbf_head *, struct nrs_tbf_client *);
137 void (*o_cli_init)(struct nrs_tbf_client *, struct ptlrpc_request *);
138 int (*o_rule_init)(struct ptlrpc_nrs_policy *,
139 struct nrs_tbf_rule *,
140 struct nrs_tbf_cmd *);
141 int (*o_rule_dump)(struct nrs_tbf_rule *,
144 int (*o_rule_match)(struct nrs_tbf_rule *,
145 struct nrs_tbf_client *);
146 void (*o_rule_fini)(struct nrs_tbf_rule *);
149 struct nrs_tbf_dump {
155 #define NRS_TBF_TYPE_JOBID "jobid"
156 #define NRS_TBF_TYPE_NID "nid"
157 #define NRS_TBF_TYPE_MAX_LEN 20
158 #define NRS_TBF_FLAG_JOBID 0x0000001
159 #define NRS_TBF_FLAG_NID 0x0000002
161 struct nrs_tbf_bucket {
163 * LRU list, updated on each access to client. Protected by
164 * bucket lock of nrs_tbf_head::th_cli_hash.
170 * Private data structure for the TBF policy
172 struct nrs_tbf_head {
174 * Resource object for policy instance.
176 struct ptlrpc_nrs_resource th_res;
182 * Lock to protect the list of rules.
184 spinlock_t th_rule_lock;
186 * Generation of rules.
188 cfs_atomic_t th_rule_sequence;
192 struct nrs_tbf_rule *th_rule;
194 * Timer for next token.
196 #if defined(__KERNEL__) && defined(__linux__)
197 struct hrtimer th_timer;
200 * Deadline of the timer.
204 * Sequence of requests.
210 cfs_binheap_t *th_binheap;
214 cfs_hash_t *th_cli_hash;
216 * Type of TBF policy.
218 char th_type[NRS_TBF_TYPE_MAX_LEN + 1];
222 struct nrs_tbf_ops *th_ops;
228 * Index of bucket on hash table while purging.
233 enum nrs_tbf_cmd_type {
234 NRS_CTL_TBF_START_RULE = 0,
235 NRS_CTL_TBF_STOP_RULE,
236 NRS_CTL_TBF_CHANGE_RATE,
240 enum nrs_tbf_cmd_type tc_cmd;
245 cfs_list_t tc_jobids;
247 __u32 tc_valid_types;
257 * Sequence of the request.
263 * TBF policy operations.
267 * Read the the data of a TBF policy.
269 NRS_CTL_TBF_RD_RULE = PTLRPC_NRS_CTL_1ST_POL_SPEC,
271 * Write the the data of a TBF policy.