Whamcloud - gitweb
LU-10391 lnet: switch to large lnet_processid for matching
[fs/lustre-release.git] / lnet / selftest / console.h
1 /*
2  * GPL HEADER START
3  *
4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5  *
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.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * General Public License version 2 for more details (a copy is included
14  * in the LICENSE file that accompanied this code).
15  *
16  * You should have received a copy of the GNU General Public License
17  * version 2 along with this program; If not, see
18  * http://www.gnu.org/licenses/gpl-2.0.html
19  *
20  * GPL HEADER END
21  */
22 /*
23  * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
24  * Use is subject to license terms.
25  *
26  * Copyright (c) 2012, 2013, Intel Corporation.
27  */
28 /*
29  * This file is part of Lustre, http://www.lustre.org/
30  *
31  * lnet/selftest/console.h
32  *
33  * kernel structure for LST console
34  *
35  * Author: Liang Zhen <liangzhen@clusterfs.com>
36  */
37
38 #ifndef __LST_CONSOLE_H__
39 #define __LST_CONSOLE_H__
40
41 #include <linux/uaccess.h>
42
43 #include <libcfs/libcfs.h>
44 #include <lnet/lib-types.h>
45 #include "selftest.h"
46 #include "conrpc.h"
47
48 /* node descriptor */
49 struct lstcon_node {
50         struct lnet_process_id    nd_id;        /* id of the node */
51         int                  nd_ref;         /* reference count */
52         int                  nd_state;       /* state of the node */
53         int                  nd_timeout;     /* session timeout */
54         ktime_t                 nd_stamp;       /* last RPC reply timestamp */
55         struct lstcon_rpc       nd_ping;        /* ping rpc */
56 };
57
58 /* node link descriptor */
59 struct lstcon_ndlink {
60         struct list_head        ndl_link;       /* chain on list */
61         struct list_head        ndl_hlink;      /* chain on hash */
62         struct lstcon_node      *ndl_node;      /* pointer to node */
63 };
64
65 /* (alias of nodes) group descriptor */
66 struct lstcon_group {
67         struct list_head        grp_link;       /* chain on global group list */
68         int                     grp_ref;        /* reference count */
69         int                     grp_userland;   /* has userland nodes */
70         int                     grp_nnode;      /* # of nodes */
71         char                    grp_name[LST_NAME_SIZE];        /* group name */
72
73         struct list_head        grp_trans_list; /* transaction list */
74         struct list_head        grp_ndl_list;   /* nodes list */
75         struct list_head        grp_ndl_hash[0];/* hash table for nodes */
76 };
77
78 #define LST_BATCH_IDLE          0xB0            /* idle batch */
79 #define LST_BATCH_RUNNING       0xB1            /* running batch */
80
81 struct lstcon_tsb_hdr {
82         struct lst_bid          tsb_id;         /* batch ID */
83         int                     tsb_index;      /* test index */
84 };
85
86 /* (tests ) batch descriptor */
87 struct lstcon_batch {
88         /* test_batch header */
89         struct lstcon_tsb_hdr   bat_hdr;
90         /* chain on session's batches list */
91         struct list_head        bat_link;
92         /* # of test */
93         int                     bat_ntest;
94         /* state of the batch */
95         int                     bat_state;
96         /* parameter for run|stop, timeout for run, force for stop */
97         int                     bat_arg;
98         /* name of batch */
99         char                    bat_name[LST_NAME_SIZE];
100
101         /* list head of tests (lstcon_test_t) */
102         struct list_head        bat_test_list;
103         /* list head of transaction */
104         struct list_head        bat_trans_list;
105         /* list head of client nodes (struct lstcon_node) */
106         struct list_head        bat_cli_list;
107         /* hash table of client nodes */
108         struct list_head        *bat_cli_hash;
109         /* list head of server nodes */
110         struct list_head        bat_srv_list;
111         /* hash table of server nodes */
112         struct list_head        *bat_srv_hash;
113 };
114
115 /* a single test descriptor */
116 struct lstcon_test {
117         /* test batch header */
118         struct lstcon_tsb_hdr   tes_hdr;
119         /* chain on batch's tests list */
120         struct list_head        tes_link;
121         /* pointer to batch */
122         struct lstcon_batch     *tes_batch;
123
124         int                   tes_type;       /* type of the test, i.e: bulk, ping */
125         int                   tes_stop_onerr; /* stop on error */
126         int                   tes_oneside;    /* one-sided test */
127         int                   tes_concur;     /* concurrency */
128         int                   tes_loop;       /* loop count */
129         int                   tes_dist;       /* nodes distribution of target group */
130         int                   tes_span;       /* nodes span of target group */
131         int                   tes_cliidx;     /* client index, used for RPC creating */
132
133         struct list_head        tes_trans_list; /* transaction list */
134         struct lstcon_group     *tes_src_grp;   /* group run the test */
135         struct lstcon_group     *tes_dst_grp;   /* target group */
136
137         int                   tes_paramlen;   /* test parameter length */
138         char                  tes_param[0];   /* test parameter */
139 };
140
141 #define LST_GLOBAL_HASHSIZE     503             /* global nodes hash table size */
142 #define LST_NODE_HASHSIZE       239             /* node hash table (for batch or group) */
143
144 #define LST_SESSION_NONE        0x0             /* no session */
145 #define LST_SESSION_ACTIVE      0x1             /* working session */
146
147 #define LST_CONSOLE_TIMEOUT     300             /* default console timeout */
148
149 struct lstcon_session {
150         struct mutex            ses_mutex;      /* only 1 thread in session */
151         struct lst_sid          ses_id;         /* global session id */
152         int                     ses_key;        /* local session key */
153         int                     ses_state;      /* state of session */
154         int                     ses_timeout;    /* timeout in seconds */
155         time64_t                ses_laststamp;  /* last operation stamp (seconds) */
156         /** tests features of the session */
157         unsigned                ses_features;
158         /** features are synced with remote test nodes */
159         unsigned                ses_feats_updated:1;
160         /** force creating */
161         unsigned                ses_force:1;
162         /** session is shutting down */
163         unsigned                ses_shutdown:1;
164         /** console is timedout */
165         unsigned                ses_expired:1;
166         __u64                   ses_id_cookie;  /* batch id cookie */
167         char                    ses_name[LST_NAME_SIZE];  /* session name */
168         struct lstcon_rpc_trans *ses_ping;      /* session pinger */
169         struct stt_timer        ses_ping_timer; /* timer for pinger */
170         struct lstcon_trans_stat ses_trans_stat;/* transaction stats */
171
172         struct list_head        ses_trans_list; /* global list of transaction */
173         struct list_head        ses_grp_list;   /* global list of groups */
174         struct list_head        ses_bat_list;   /* global list of batches */
175         struct list_head        ses_ndl_list;   /* global list of nodes */
176         struct list_head        *ses_ndl_hash;  /* hash table of nodes */
177
178         spinlock_t              ses_rpc_lock;   /* serialize */
179         atomic_t                ses_rpc_counter;/* # of initialized RPCs */
180         struct list_head        ses_rpc_freelist;/* idle console rpc */
181 }; /* session descriptor */
182
183 extern struct lstcon_session console_session;
184
185 static inline struct lstcon_trans_stat *
186 lstcon_trans_stat(void)
187 {
188         return &console_session.ses_trans_stat;
189 }
190
191 static inline struct list_head *
192 lstcon_id2hash(struct lnet_process_id id, struct list_head *hash)
193 {
194         unsigned int idx = LNET_NIDADDR(id.nid) % LST_NODE_HASHSIZE;
195
196         return &hash[idx];
197 }
198
199 extern int lstcon_session_match(struct lst_sid sid);
200 extern int lstcon_session_new(char *name, int key, unsigned version,
201                               int timeout, int flags, struct lst_sid __user *sid_up);
202 extern int lstcon_session_info(struct lst_sid __user *sid_up, int __user *key,
203                                unsigned __user *verp,
204                                struct lstcon_ndlist_ent __user *entp,
205                                char __user *name_up, int len);
206 extern int lstcon_session_end(void);
207 extern int lstcon_session_debug(int timeout,
208                                 struct list_head __user *result_up);
209 extern int lstcon_session_feats_check(unsigned feats);
210 extern int lstcon_batch_debug(int timeout, char *name,
211                               int client, struct list_head __user *result_up);
212 extern int lstcon_group_debug(int timeout, char *name,
213                               struct list_head __user *result_up);
214 extern int lstcon_nodes_debug(int timeout, int nnd,
215                               struct lnet_process_id __user *nds_up,
216                               struct list_head __user *result_up);
217 extern int lstcon_group_add(char *name);
218 extern int lstcon_group_del(char *name);
219 extern int lstcon_group_clean(char *name, int args);
220 extern int lstcon_group_refresh(char *name, struct list_head __user *result_up);
221 extern int lstcon_nodes_add(char *name, int nnd,
222                             struct lnet_process_id __user *nds_up,
223                             unsigned *featp,
224                             struct list_head __user *result_up);
225 extern int lstcon_nodes_remove(char *name, int nnd,
226                                struct lnet_process_id __user *nds_up,
227                                struct list_head __user *result_up);
228 extern int lstcon_group_info(char *name, struct lstcon_ndlist_ent __user *gent_up,
229                              int *index_p, int *ndent_p,
230                              struct lstcon_node_ent __user *ndents_up);
231 extern int lstcon_group_list(int idx, int len, char __user *name_up);
232 extern int lstcon_batch_add(char *name);
233 extern int lstcon_batch_run(char *name, int timeout,
234                             struct list_head __user *result_up);
235 extern int lstcon_batch_stop(char *name, int force,
236                              struct list_head __user *result_up);
237 extern int lstcon_test_batch_query(char *name, int testidx,
238                                    int client, int timeout,
239                                    struct list_head __user *result_up);
240 extern int lstcon_batch_del(char *name);
241 extern int lstcon_batch_list(int idx, int namelen, char __user *name_up);
242 extern int lstcon_batch_info(char *name,
243                              struct lstcon_test_batch_ent __user *ent_up,
244                              int server, int testidx, int *index_p,
245                              int *ndent_p,
246                              struct lstcon_node_ent __user *dents_up);
247 extern int lstcon_group_stat(char *grp_name, int timeout,
248                              struct list_head __user *result_up);
249 extern int lstcon_nodes_stat(int count, struct lnet_process_id __user *ids_up,
250                              int timeout, struct list_head __user *result_up);
251 extern int lstcon_test_add(char *batch_name, int type, int loop,
252                            int concur, int dist, int span,
253                            char *src_name, char *dst_name,
254                            void *param, int paramlen, int *retp,
255                            struct list_head __user *result_up);
256
257 int lstcon_ioctl_entry(struct notifier_block *nb,
258                        unsigned long cmd, void *vdata);
259 int lstcon_console_init(void);
260 int lstcon_console_fini(void);
261
262 #endif