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.
25 * Copyright (c) 2014, Intel Corporation.
29 * Network Request Scheduler (NRS) Token Bucket Filter(TBF) policy
33 #ifndef _LUSTRE_NRS_TBF_H
34 #define _LUSTRE_NRS_TBF_H
35 #include <lustre_net.h>
47 struct nrs_tbf_jobid {
49 struct list_head tj_linkage;
52 struct nrs_tbf_client {
53 /** Resource object for policy instance. */
54 struct ptlrpc_nrs_resource tc_res;
55 /** Node in the hash table. */
56 struct hlist_node tc_hnode;
57 /** NID of the client. */
59 /** Jobid of the client. */
60 char tc_jobid[LUSTRE_JOBID_SIZE];
61 /** Reference number of the client. */
63 /** Likage to rule. */
64 struct list_head tc_linkage;
65 /** Pointer to rule. */
66 struct nrs_tbf_rule *tc_rule;
67 /** Generation of the rule matched. */
68 __u64 tc_rule_generation;
69 /** Limit of RPC rate. */
71 /** Time to wait for next token. */
73 /** RPC token number. */
75 /** Token bucket depth. */
77 /** Time check-point. */
79 /** List of queued requests. */
80 struct list_head tc_list;
81 /** Node in binary heap. */
82 cfs_binheap_node_t tc_node;
83 /** Whether the client is in heap. */
85 /** Sequence of the newest rule. */
86 __u32 tc_rule_sequence;
88 * Linkage into LRU list. Protected bucket lock of
89 * nrs_tbf_head::th_cli_hash.
91 struct list_head tc_lru;
94 #define MAX_TBF_NAME (16)
96 #define NTRS_STOPPING 0x0000001
97 #define NTRS_DEFAULT 0x0000002
100 /** Name of the rule. */
101 char tr_name[MAX_TBF_NAME];
102 /** Head belongs to. */
103 struct nrs_tbf_head *tr_head;
104 /** Likage to head. */
105 struct list_head tr_linkage;
106 /** Nid list of the rule. */
107 struct list_head tr_nids;
108 /** Nid list string of the rule.*/
110 /** Jobid list of the rule. */
111 struct list_head tr_jobids;
112 /** Jobid list string of the rule.*/
116 /** Time to wait for next token. */
118 /** Token bucket depth. */
120 /** List of client. */
121 struct list_head tr_cli_list;
122 /** Flags of the rule. */
124 /** Usage Reference count taken on the rule. */
126 /** Generation of the rule. */
132 int (*o_startup)(struct ptlrpc_nrs_policy *, struct nrs_tbf_head *);
133 struct nrs_tbf_client *(*o_cli_find)(struct nrs_tbf_head *,
134 struct ptlrpc_request *);
135 struct nrs_tbf_client *(*o_cli_findadd)(struct nrs_tbf_head *,
136 struct nrs_tbf_client *);
137 void (*o_cli_put)(struct nrs_tbf_head *, struct nrs_tbf_client *);
138 void (*o_cli_init)(struct nrs_tbf_client *, struct ptlrpc_request *);
139 int (*o_rule_init)(struct ptlrpc_nrs_policy *,
140 struct nrs_tbf_rule *,
141 struct nrs_tbf_cmd *);
142 int (*o_rule_dump)(struct nrs_tbf_rule *, struct seq_file *);
143 int (*o_rule_match)(struct nrs_tbf_rule *,
144 struct nrs_tbf_client *);
145 void (*o_rule_fini)(struct nrs_tbf_rule *);
148 #define NRS_TBF_TYPE_JOBID "jobid"
149 #define NRS_TBF_TYPE_NID "nid"
150 #define NRS_TBF_TYPE_MAX_LEN 20
151 #define NRS_TBF_FLAG_JOBID 0x0000001
152 #define NRS_TBF_FLAG_NID 0x0000002
154 struct nrs_tbf_bucket {
156 * LRU list, updated on each access to client. Protected by
157 * bucket lock of nrs_tbf_head::th_cli_hash.
159 struct list_head ntb_lru;
163 * Private data structure for the TBF policy
165 struct nrs_tbf_head {
167 * Resource object for policy instance.
169 struct ptlrpc_nrs_resource th_res;
173 struct list_head th_list;
175 * Lock to protect the list of rules.
177 spinlock_t th_rule_lock;
179 * Generation of rules.
181 atomic_t th_rule_sequence;
185 struct nrs_tbf_rule *th_rule;
187 * Timer for next token.
189 struct hrtimer th_timer;
191 * Deadline of the timer.
195 * Sequence of requests.
201 cfs_binheap_t *th_binheap;
205 cfs_hash_t *th_cli_hash;
207 * Type of TBF policy.
209 char th_type[NRS_TBF_TYPE_MAX_LEN + 1];
213 struct nrs_tbf_ops *th_ops;
219 * Index of bucket on hash table while purging.
224 enum nrs_tbf_cmd_type {
225 NRS_CTL_TBF_START_RULE = 0,
226 NRS_CTL_TBF_STOP_RULE,
227 NRS_CTL_TBF_CHANGE_RATE,
231 enum nrs_tbf_cmd_type tc_cmd;
234 struct list_head tc_nids;
236 struct list_head tc_jobids;
238 __u32 tc_valid_types;
246 struct list_head tr_list;
248 * Sequence of the request.
254 * TBF policy operations.
258 * Read the the data of a TBF policy.
260 NRS_CTL_TBF_RD_RULE = PTLRPC_NRS_CTL_1ST_POL_SPEC,
262 * Write the the data of a TBF policy.