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 struct list_head 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 struct hlist_node 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 struct list_head 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. */
79 struct list_head tc_list;
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.
90 struct list_head tc_lru;
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 struct list_head tr_linkage;
105 /** Nid list of the rule. */
106 struct list_head tr_nids;
107 /** Nid list string of the rule.*/
109 /** Jobid list of the rule. */
110 struct list_head 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 struct list_head 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 *, struct seq_file *);
142 int (*o_rule_match)(struct nrs_tbf_rule *,
143 struct nrs_tbf_client *);
144 void (*o_rule_fini)(struct nrs_tbf_rule *);
147 #define NRS_TBF_TYPE_JOBID "jobid"
148 #define NRS_TBF_TYPE_NID "nid"
149 #define NRS_TBF_TYPE_MAX_LEN 20
150 #define NRS_TBF_FLAG_JOBID 0x0000001
151 #define NRS_TBF_FLAG_NID 0x0000002
153 struct nrs_tbf_bucket {
155 * LRU list, updated on each access to client. Protected by
156 * bucket lock of nrs_tbf_head::th_cli_hash.
158 struct list_head ntb_lru;
162 * Private data structure for the TBF policy
164 struct nrs_tbf_head {
166 * Resource object for policy instance.
168 struct ptlrpc_nrs_resource th_res;
172 struct list_head th_list;
174 * Lock to protect the list of rules.
176 spinlock_t th_rule_lock;
178 * Generation of rules.
180 atomic_t th_rule_sequence;
184 struct nrs_tbf_rule *th_rule;
186 * Timer for next token.
188 struct hrtimer th_timer;
190 * Deadline of the timer.
194 * Sequence of requests.
200 cfs_binheap_t *th_binheap;
204 cfs_hash_t *th_cli_hash;
206 * Type of TBF policy.
208 char th_type[NRS_TBF_TYPE_MAX_LEN + 1];
212 struct nrs_tbf_ops *th_ops;
218 * Index of bucket on hash table while purging.
223 enum nrs_tbf_cmd_type {
224 NRS_CTL_TBF_START_RULE = 0,
225 NRS_CTL_TBF_STOP_RULE,
226 NRS_CTL_TBF_CHANGE_RATE,
230 enum nrs_tbf_cmd_type tc_cmd;
233 struct list_head tc_nids;
235 struct list_head tc_jobids;
237 __u32 tc_valid_types;
245 struct list_head tr_list;
247 * Sequence of the request.
253 * TBF policy operations.
257 * Read the the data of a TBF policy.
259 NRS_CTL_TBF_RD_RULE = PTLRPC_NRS_CTL_1ST_POL_SPEC,
261 * Write the the data of a TBF policy.