Whamcloud - gitweb
LU-1095 llite: improve max_readahead console messages
[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.sun.com/software/products/lustre/docs/GPLv2.pdf
19  *
20  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21  * CA 95054 USA or visit www.sun.com if you need additional information or
22  * have any questions.
23  *
24  * GPL HEADER END
25  */
26 /*
27  * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
28  * Use is subject to license terms.
29  *
30  * Copyright (c) 2012, 2013, Intel Corporation.
31  */
32 /*
33  * This file is part of Lustre, http://www.lustre.org/
34  * Lustre is a trademark of Sun Microsystems, Inc.
35  *
36  * lnet/selftest/console.h
37  *
38  * kernel structure for LST console
39  *
40  * Author: Liang Zhen <liangzhen@clusterfs.com>
41  */
42
43 #ifndef __LST_CONSOLE_H__
44 #define __LST_CONSOLE_H__
45
46 #ifdef __KERNEL__
47
48 #include <libcfs/libcfs.h>
49 #include <lnet/lnet.h>
50 #include <lnet/lib-types.h>
51 #include <lnet/lnetst.h>
52 #include "selftest.h"
53 #include "conrpc.h"
54
55 typedef struct lstcon_node {
56         lnet_process_id_t    nd_id;          /* id of the node */
57         int                  nd_ref;         /* reference count */
58         int                  nd_state;       /* state of the node */
59         int                  nd_timeout;     /* session timeout */
60         cfs_time_t           nd_stamp;       /* timestamp of last replied RPC */
61         struct lstcon_rpc    nd_ping;        /* ping rpc */
62 } lstcon_node_t;                                /*** node descriptor */
63
64 typedef struct {
65         struct list_head        ndl_link;       /* chain on list */
66         struct list_head        ndl_hlink;      /* chain on hash */
67         lstcon_node_t           *ndl_node;      /* pointer to node */
68 } lstcon_ndlink_t;                              /*** node link descriptor */
69
70 typedef struct {
71         struct list_head        grp_link;       /* chain on global group list */
72         int                     grp_ref;        /* reference count */
73         int                     grp_userland;   /* has userland nodes */
74         int                     grp_nnode;      /* # of nodes */
75         char                    grp_name[LST_NAME_SIZE];        /* group name */
76
77         struct list_head        grp_trans_list; /* transaction list */
78         struct list_head        grp_ndl_list;   /* nodes list */
79         struct list_head        grp_ndl_hash[0];/* hash table for nodes */
80 } lstcon_group_t;               /*** (alias of nodes) group descriptor */
81
82 #define LST_BATCH_IDLE          0xB0            /* idle batch */
83 #define LST_BATCH_RUNNING       0xB1            /* running batch */
84
85 typedef struct lstcon_tsb_hdr {
86         lst_bid_t               tsb_id;         /* batch ID */
87         int                     tsb_index;      /* test index */
88 } lstcon_tsb_hdr_t;
89
90 typedef struct {
91         /* test_batch header */
92         lstcon_tsb_hdr_t        bat_hdr;
93         /* chain on session's batches list */
94         struct list_head        bat_link;
95         /* # of test */
96         int                     bat_ntest;
97         /* state of the batch */
98         int                     bat_state;
99         /* parameter for run|stop, timeout for run, force for stop */
100         int                     bat_arg;
101         /* name of batch */
102         char                    bat_name[LST_NAME_SIZE];
103
104         /* list head of tests (lstcon_test_t) */
105         struct list_head        bat_test_list;
106         /* list head of transaction */
107         struct list_head        bat_trans_list;
108         /* list head of client nodes (lstcon_node_t) */
109         struct list_head        bat_cli_list;
110         /* hash table of client nodes */
111         struct list_head        *bat_cli_hash;
112         /* list head of server nodes */
113         struct list_head        bat_srv_list;
114         /* hash table of server nodes */
115         struct list_head        *bat_srv_hash;
116 } lstcon_batch_t;               /*** (tests ) batch descritptor */
117
118 typedef struct lstcon_test {
119         /* test batch header */
120         lstcon_tsb_hdr_t        tes_hdr;
121         /* chain on batch's tests list */
122         struct list_head        tes_link;
123         /* pointer to batch */
124         lstcon_batch_t         *tes_batch;
125
126         int                   tes_type;       /* type of the test, i.e: bulk, ping */
127         int                   tes_stop_onerr; /* stop on error */
128         int                   tes_oneside;    /* one-sided test */
129         int                   tes_concur;     /* concurrency */
130         int                   tes_loop;       /* loop count */
131         int                   tes_dist;       /* nodes distribution of target group */
132         int                   tes_span;       /* nodes span of target group */
133         int                   tes_cliidx;     /* client index, used for RPC creating */
134
135         struct list_head        tes_trans_list; /* transaction list */
136         lstcon_group_t          *tes_src_grp;   /* group run the test */
137         lstcon_group_t          *tes_dst_grp;   /* target group */
138
139         int                   tes_paramlen;   /* test parameter length */
140         char                  tes_param[0];   /* test parameter */
141 } lstcon_test_t;                                /*** a single test descriptor */
142
143 #define LST_GLOBAL_HASHSIZE     503             /* global nodes hash table size */
144 #define LST_NODE_HASHSIZE       239             /* node hash table (for batch or group) */
145
146 #define LST_SESSION_NONE        0x0             /* no session */
147 #define LST_SESSION_ACTIVE      0x1             /* working session */
148
149 #define LST_CONSOLE_TIMEOUT     300             /* default console timeout */
150
151 typedef struct {
152         struct mutex            ses_mutex;      /* only 1 thread in session */
153         lst_sid_t               ses_id;         /* global session id */
154         int                     ses_key;        /* local session key */
155         int                     ses_state;      /* state of session */
156         int                     ses_timeout;    /* timeout in seconds */
157         time_t                  ses_laststamp;  /* last operation stamp (seconds) */
158         /** tests features of the session */
159         unsigned                ses_features;
160         /** features are synced with remote test nodes */
161         unsigned                ses_feats_updated:1;
162         /** force creating */
163         unsigned                ses_force:1;
164         /** session is shutting down */
165         unsigned                ses_shutdown:1;
166         /** console is timedout */
167         unsigned                ses_expired:1;
168         __u64                   ses_id_cookie;  /* batch id cookie */
169         char                    ses_name[LST_NAME_SIZE];  /* session name */
170         lstcon_rpc_trans_t     *ses_ping;       /* session pinger */
171         stt_timer_t             ses_ping_timer; /* timer for pinger */
172         lstcon_trans_stat_t     ses_trans_stat; /* transaction stats */
173
174         struct list_head        ses_trans_list; /* global list of transaction */
175         struct list_head        ses_grp_list;   /* global list of groups */
176         struct list_head        ses_bat_list;   /* global list of batches */
177         struct list_head        ses_ndl_list;   /* global list of nodes */
178         struct list_head        *ses_ndl_hash;  /* hash table of nodes */
179
180         spinlock_t              ses_rpc_lock;   /* serialize */
181         atomic_t                ses_rpc_counter;/* # of initialized RPCs */
182         struct list_head        ses_rpc_freelist;/* idle console rpc */
183 } lstcon_session_t;             /*** session descriptor */
184
185 extern lstcon_session_t         console_session;
186
187 static inline lstcon_trans_stat_t *
188 lstcon_trans_stat(void)
189 {
190         return &console_session.ses_trans_stat;
191 }
192
193 static inline struct list_head *
194 lstcon_id2hash(lnet_process_id_t id, struct list_head *hash)
195 {
196         unsigned int idx = LNET_NIDADDR(id.nid) % LST_NODE_HASHSIZE;
197
198         return &hash[idx];
199 }
200
201 extern int lstcon_session_match(lst_sid_t sid);
202 extern int lstcon_session_new(char *name, int key, unsigned version,
203                               int timeout, int flags, lst_sid_t __user *sid_up);
204 extern int lstcon_session_info(lst_sid_t __user *sid_up, int __user *key,
205                                unsigned __user *verp,
206                                lstcon_ndlist_ent_t __user *entp,
207                                char __user *name_up, int len);
208 extern int lstcon_session_end(void);
209 extern int lstcon_session_debug(int timeout,
210                                 struct list_head __user *result_up);
211 extern int lstcon_session_feats_check(unsigned feats);
212 extern int lstcon_batch_debug(int timeout, char *name,
213                               int client, struct list_head __user *result_up);
214 extern int lstcon_group_debug(int timeout, char *name,
215                               struct list_head __user *result_up);
216 extern int lstcon_nodes_debug(int timeout, int nnd,
217                               lnet_process_id_t __user *nds_up,
218                               struct list_head __user *result_up);
219 extern int lstcon_group_add(char *name);
220 extern int lstcon_group_del(char *name);
221 extern int lstcon_group_clean(char *name, int args);
222 extern int lstcon_group_refresh(char *name, struct list_head __user *result_up);
223 extern int lstcon_nodes_add(char *name, int nnd,
224                             lnet_process_id_t __user *nds_up,
225                             unsigned *featp,
226                             struct list_head __user *result_up);
227 extern int lstcon_nodes_remove(char *name, int nnd,
228                                lnet_process_id_t __user *nds_up,
229                                struct list_head __user *result_up);
230 extern int lstcon_group_info(char *name, lstcon_ndlist_ent_t __user *gent_up,
231                              int *index_p, int *ndent_p,
232                              lstcon_node_ent_t __user *ndents_up);
233 extern int lstcon_group_list(int idx, int len, char __user *name_up);
234 extern int lstcon_batch_add(char *name);
235 extern int lstcon_batch_run(char *name, int timeout,
236                             struct list_head __user *result_up);
237 extern int lstcon_batch_stop(char *name, int force,
238                              struct list_head __user *result_up);
239 extern int lstcon_test_batch_query(char *name, int testidx,
240                                    int client, int timeout,
241                                    struct list_head __user *result_up);
242 extern int lstcon_batch_del(char *name);
243 extern int lstcon_batch_list(int idx, int namelen, char __user *name_up);
244 extern int lstcon_batch_info(char *name, lstcon_test_batch_ent_t __user *ent_up,
245                              int server, int testidx, int *index_p,
246                              int *ndent_p, lstcon_node_ent_t __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, lnet_process_id_t __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 #endif
257
258 int lstcon_console_init(void);
259 int lstcon_console_fini(void);
260
261 #endif