1 // SPDX-License-Identifier: GPL-2.0
4 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
5 * Use is subject to license terms.
7 * Copyright (c) 2012, 2013, Intel Corporation.
11 * This file is part of Lustre, http://www.lustre.org/
13 * kernel structure for LST console
15 * Author: Liang Zhen <liangzhen@clusterfs.com>
18 #ifndef __LST_CONSOLE_H__
19 #define __LST_CONSOLE_H__
21 #include <linux/uaccess.h>
23 #include <libcfs/libcfs.h>
24 #include <lnet/lib-types.h>
30 struct lnet_process_id nd_id; /* id of the node */
31 int nd_ref; /* reference count */
32 int nd_state; /* state of the node */
33 int nd_timeout; /* session timeout */
34 ktime_t nd_stamp; /* last RPC reply timestamp */
35 struct lstcon_rpc nd_ping; /* ping rpc */
38 /* node link descriptor */
39 struct lstcon_ndlink {
40 struct list_head ndl_link; /* chain on list */
41 struct list_head ndl_hlink; /* chain on hash */
42 struct lstcon_node *ndl_node; /* pointer to node */
45 /* (alias of nodes) group descriptor */
47 struct list_head grp_link; /* chain on global group list */
48 int grp_ref; /* reference count */
49 int grp_userland; /* has userland nodes */
50 int grp_nnode; /* # of nodes */
51 char grp_name[LST_NAME_SIZE]; /* group name */
53 struct list_head grp_trans_list; /* transaction list */
54 struct list_head grp_ndl_list; /* nodes list */
55 struct list_head grp_ndl_hash[0];/* hash table for nodes */
58 #define LST_BATCH_IDLE 0xB0 /* idle batch */
59 #define LST_BATCH_RUNNING 0xB1 /* running batch */
61 struct lstcon_tsb_hdr {
62 struct lst_bid tsb_id; /* batch ID */
63 int tsb_index; /* test index */
66 /* (tests ) batch descriptor */
68 /* test_batch header */
69 struct lstcon_tsb_hdr bat_hdr;
70 /* chain on session's batches list */
71 struct list_head bat_link;
74 /* state of the batch */
76 /* parameter for run|stop, timeout for run, force for stop */
79 char bat_name[LST_NAME_SIZE];
81 /* list head of tests (lstcon_test_t) */
82 struct list_head bat_test_list;
83 /* list head of transaction */
84 struct list_head bat_trans_list;
85 /* list head of client nodes (struct lstcon_node) */
86 struct list_head bat_cli_list;
87 /* hash table of client nodes */
88 struct list_head *bat_cli_hash;
89 /* list head of server nodes */
90 struct list_head bat_srv_list;
91 /* hash table of server nodes */
92 struct list_head *bat_srv_hash;
95 /* a single test descriptor */
97 /* test batch header */
98 struct lstcon_tsb_hdr tes_hdr;
99 /* chain on batch's tests list */
100 struct list_head tes_link;
101 /* pointer to batch */
102 struct lstcon_batch *tes_batch;
104 int tes_type; /* type of the test, i.e: bulk, ping */
105 int tes_stop_onerr; /* stop on error */
106 int tes_oneside; /* one-sided test */
107 int tes_concur; /* concurrency */
108 int tes_loop; /* loop count */
109 int tes_dist; /* nodes distribution of target group */
110 int tes_span; /* nodes span of target group */
111 int tes_cliidx; /* client index, used for RPC creating */
113 struct list_head tes_trans_list; /* transaction list */
114 struct lstcon_group *tes_src_grp; /* group run the test */
115 struct lstcon_group *tes_dst_grp; /* target group */
117 int tes_paramlen; /* test parameter length */
118 char tes_param[0]; /* test parameter */
121 #define LST_GLOBAL_HASHSIZE 503 /* global nodes hash table size */
122 #define LST_NODE_HASHSIZE 239 /* node hash table (for batch or group) */
124 #define LST_SESSION_NONE 0x0 /* no session */
125 #define LST_SESSION_ACTIVE 0x1 /* working session */
127 #define LST_CONSOLE_TIMEOUT 300 /* default console timeout */
129 struct lstcon_session {
130 struct mutex ses_mutex; /* only 1 thread in session */
131 struct lst_session_id ses_id; /* global session id */
132 u32 ses_key; /* local session key */
133 int ses_state; /* state of session */
134 int ses_timeout; /* timeout in seconds */
135 time64_t ses_laststamp; /* last operation stamp (seconds) */
136 /** tests features of the session */
137 unsigned ses_features;
138 /** features are synced with remote test nodes */
139 unsigned ses_feats_updated:1;
140 /** force creating */
141 unsigned ses_force:1;
142 /** session is shutting down */
143 unsigned ses_shutdown:1;
144 /** console is timedout */
145 unsigned ses_expired:1;
146 __u64 ses_id_cookie; /* batch id cookie */
147 char ses_name[LST_NAME_SIZE]; /* session name */
148 struct lstcon_rpc_trans *ses_ping; /* session pinger */
149 struct stt_timer ses_ping_timer; /* timer for pinger */
150 struct lstcon_trans_stat ses_trans_stat;/* transaction stats */
152 struct list_head ses_trans_list; /* global list of transaction */
153 struct list_head ses_grp_list; /* global list of groups */
154 struct list_head ses_bat_list; /* global list of batches */
155 struct list_head ses_ndl_list; /* global list of nodes */
156 struct list_head *ses_ndl_hash; /* hash table of nodes */
158 spinlock_t ses_rpc_lock; /* serialize */
159 atomic_t ses_rpc_counter;/* # of initialized RPCs */
160 struct list_head ses_rpc_freelist;/* idle console rpc */
161 }; /* session descriptor */
163 extern struct lstcon_session console_session;
165 static inline struct lstcon_trans_stat *
166 lstcon_trans_stat(void)
168 return &console_session.ses_trans_stat;
171 static inline struct list_head *
172 lstcon_id2hash(struct lnet_process_id id, struct list_head *hash)
174 unsigned int idx = LNET_NIDADDR(id.nid) % LST_NODE_HASHSIZE;
179 extern int lstcon_session_match(struct lst_sid sid);
180 extern int lstcon_session_new(char *name, int key, unsigned version,
181 int timeout, int flags);
182 extern int lstcon_session_end(void);
183 extern int lstcon_session_debug(int timeout,
184 struct list_head __user *result_up);
185 extern int lstcon_session_feats_check(unsigned feats);
186 extern int lstcon_batch_debug(int timeout, char *name,
187 int client, struct list_head __user *result_up);
188 extern int lstcon_group_debug(int timeout, char *name,
189 struct list_head __user *result_up);
190 extern int lstcon_nodes_debug(int timeout, int nnd,
191 struct lnet_process_id __user *nds_up,
192 struct list_head __user *result_up);
193 extern int lstcon_group_add(char *name);
194 extern int lstcon_group_del(char *name);
195 void lstcon_group_addref(struct lstcon_group *grp);
196 void lstcon_group_decref(struct lstcon_group *grp);
197 int lstcon_group_find(const char *name, struct lstcon_group **grpp);
198 extern int lstcon_group_clean(char *name, int args);
199 extern int lstcon_group_refresh(char *name, struct list_head __user *result_up);
200 extern int lstcon_nodes_add(char *name, int nnd,
201 struct lnet_process_id __user *nds_up,
203 struct list_head __user *result_up);
204 extern int lstcon_nodes_remove(char *name, int nnd,
205 struct lnet_process_id __user *nds_up,
206 struct list_head __user *result_up);
207 extern int lstcon_group_info(char *name, struct lstcon_ndlist_ent __user *gent_up,
208 int *index_p, int *ndent_p,
209 struct lstcon_node_ent __user *ndents_up);
210 extern int lstcon_batch_add(char *name);
211 extern int lstcon_batch_run(char *name, int timeout,
212 struct list_head __user *result_up);
213 extern int lstcon_batch_stop(char *name, int force,
214 struct list_head __user *result_up);
215 extern int lstcon_test_batch_query(char *name, int testidx,
216 int client, int timeout,
217 struct list_head __user *result_up);
218 extern int lstcon_batch_del(char *name);
219 extern int lstcon_batch_list(int idx, int namelen, char __user *name_up);
220 extern int lstcon_batch_info(char *name,
221 struct lstcon_test_batch_ent __user *ent_up,
222 int server, int testidx, int *index_p,
224 struct lstcon_node_ent __user *dents_up);
225 extern int lstcon_group_stat(char *grp_name, int timeout,
226 struct list_head __user *result_up);
227 extern int lstcon_nodes_stat(int count, struct lnet_process_id __user *ids_up,
228 int timeout, struct list_head __user *result_up);
229 extern int lstcon_test_add(char *batch_name, int type, int loop,
230 int concur, int dist, int span,
231 char *src_name, char *dst_name,
232 void *param, int paramlen, int *retp,
233 struct list_head __user *result_up);
235 int lstcon_ioctl_entry(struct notifier_block *nb,
236 unsigned long cmd, void *vdata);
238 int lstcon_console_init(void);
239 int lstcon_console_fini(void);
241 int lstcon_init_netlink(void);
242 void lstcon_fini_netlink(void);