Whamcloud - gitweb
- added LNET self test (landing b_self_test).
[fs/lustre-release.git] / lnet / selftest / console.h
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  * Author: Liang Zhen <liangzhen@clusterfs.com>
5  * 
6  * This file is part of Lustre, http://www.lustre.org
7  *
8  * kernel structure for LST console
9  */
10
11 #ifndef __LST_CONSOLE_H__
12 #define __LST_CONSOLE_H__
13
14 #ifdef __KERNEL__
15
16 #include <libcfs/kp30.h>
17 #include <lnet/lnet.h>
18 #include <lnet/lib-types.h>
19 #include <lnet/lnetst.h>
20 #include "selftest.h"
21 #include "conrpc.h"
22
23 typedef struct lstcon_node {
24         lnet_process_id_t       nd_id;          /* id of the node */
25         int                     nd_ref;         /* reference count */
26         int                     nd_state;       /* state of the node */
27         int                     nd_timeout;     /* session timeout */
28         cfs_time_t              nd_stamp;       /* timestamp of last replied RPC */
29         struct lstcon_rpc       nd_ping;        /* ping rpc */
30 } lstcon_node_t;                                /*** node descriptor */
31
32 typedef struct {
33         struct list_head        ndl_link;       /* chain on list */
34         struct list_head        ndl_hlink;      /* chain on hash */
35         lstcon_node_t          *ndl_node;       /* pointer to node */
36 } lstcon_ndlink_t;                              /*** node link descriptor */
37
38 typedef struct {
39         struct list_head        grp_link;       /* chain on global group list */
40         int                     grp_ref;        /* reference count */
41         int                     grp_nnode;      /* # of nodes */
42         char                    grp_name[LST_NAME_SIZE]; /* group name */
43
44         struct list_head        grp_trans_list; /* transaction list */
45         struct list_head        grp_ndl_list;   /* nodes list */
46         struct list_head        grp_ndl_hash[0];/* hash table for nodes */
47 } lstcon_group_t;                               /*** (alias of nodes) group descriptor */
48
49 #define LST_BATCH_IDLE          0xB0            /* idle batch */
50 #define LST_BATCH_RUNNING       0xB1            /* running batch */
51
52 typedef struct lstcon_tsb_hdr {
53         lst_bid_t               tsb_id;         /* batch ID */
54         int                     tsb_index;      /* test index */
55 } lstcon_tsb_hdr_t;
56
57 typedef struct {
58         lstcon_tsb_hdr_t        bat_hdr;        /* test_batch header */
59         struct list_head        bat_link;       /* chain on session's batches list */
60         int                     bat_ntest;      /* # of test */
61         int                     bat_state;      /* state of the batch */
62         int                     bat_arg;        /* parameter for run|stop, timeout for run, force for stop */
63         char                    bat_name[LST_NAME_SIZE]; /* name of batch */
64
65         struct list_head        bat_test_list;  /* list head of tests (lstcon_test_t) */
66         struct list_head        bat_trans_list; /* list head of transaction */
67         struct list_head        bat_cli_list;   /* list head of client nodes (lstcon_node_t) */
68         struct list_head       *bat_cli_hash;   /* hash table of client nodes */ 
69         struct list_head        bat_srv_list;   /* list head of server nodes */
70         struct list_head       *bat_srv_hash;   /* hash table of server nodes */
71 } lstcon_batch_t;                                  /*** (tests ) batch descritptor */
72
73 typedef struct lstcon_test {
74         lstcon_tsb_hdr_t        tes_hdr;        /* test batch header */
75         struct list_head        tes_link;       /* chain on batch's tests list */
76         lstcon_batch_t         *tes_batch;      /* pointer to batch */
77
78         int                     tes_type;       /* type of the test, i.e: bulk, ping */
79         int                     tes_stop_onerr; /* stop on error */
80         int                     tes_oneside;    /* one-sided test */
81         int                     tes_concur;     /* concurrency */
82         int                     tes_loop;       /* loop count */
83         int                     tes_dist;       /* nodes distribution of target group */
84         int                     tes_span;       /* nodes span of target group */
85         int                     tes_cliidx;     /* client index, used for RPC creating */
86
87         struct list_head        tes_trans_list; /* transaction list */
88         lstcon_group_t         *tes_src_grp;    /* group run the test */
89         lstcon_group_t         *tes_dst_grp;    /* target group */
90
91         int                     tes_paramlen;   /* test parameter length */
92         char                    tes_param[0];   /* test parameter */
93 } lstcon_test_t;                                   /*** a single test descriptor */
94
95 #define LST_GLOBAL_HASHSIZE     503             /* global nodes hash table size */
96 #define LST_NODE_HASHSIZE       239             /* node hash table (for batch or group) */
97
98 #define LST_SESSION_NONE        0x0             /* no session */
99 #define LST_SESSION_ACTIVE      0x1             /* working session */
100
101 #define LST_CONSOLE_TIMEOUT     300             /* default console timeout */
102
103 typedef struct {
104         struct semaphore        ses_mutex;      /* lock for session, only one thread can enter session */
105         lst_sid_t               ses_id;         /* global session id */
106         int                     ses_key;        /* local session key */
107         int                     ses_state;      /* state of session */
108         int                     ses_timeout;    /* timeout in seconds */
109         time_t                  ses_laststamp;  /* last operation stamp (seconds) */
110         int                     ses_force:1;    /* force creating */
111         int                     ses_shutdown:1; /* session is shutting down */
112         int                     ses_expired:1;  /* console is timedout */
113         __u64                   ses_id_cookie;  /* batch id cookie */
114         char                    ses_name[LST_NAME_SIZE];  /* session name */
115         lstcon_rpc_trans_t     *ses_ping;       /* session pinger */
116         stt_timer_t             ses_ping_timer; /* timer for pinger */
117         lstcon_trans_stat_t     ses_trans_stat; /* transaction stats */
118
119         struct list_head        ses_trans_list; /* global list of transaction */
120         struct list_head        ses_grp_list;   /* global list of groups */
121         struct list_head        ses_bat_list;   /* global list of batches */
122         struct list_head        ses_ndl_list;   /* global list of nodes */
123         struct list_head       *ses_ndl_hash;   /* hash table of nodes */
124
125         spinlock_t              ses_rpc_lock;   /* serialize */
126         int                     ses_rpc_pending; /* number of pending RPCs */
127         struct list_head        ses_rpc_list;   /* list head of RPCs */
128         struct list_head        ses_rpc_freelist; /* idle console rpc */
129 } lstcon_session_t;                             /*** session descriptor */
130
131 extern lstcon_session_t         console_session;
132 static inline lstcon_trans_stat_t *
133 lstcon_trans_stat(void)
134 {
135         return &console_session.ses_trans_stat;
136 }
137
138 static inline struct list_head *
139 lstcon_id2hash (lnet_process_id_t id, struct list_head *hash)
140 {
141         unsigned int idx = LNET_NIDADDR(id.nid) % LST_NODE_HASHSIZE;
142
143         return &hash[idx];
144 }
145
146 extern int lstcon_session_match(lst_sid_t sid);
147 extern int lstcon_session_new(char *name, int key,
148                               int timeout, int flags, lst_sid_t *sid_up);
149 extern int lstcon_session_info(lst_sid_t *sid_up, int *key,
150                                lstcon_ndlist_ent_t *entp, char *name_up, int len);
151 extern int lstcon_session_end(void);
152 extern int lstcon_session_debug(int timeout, struct list_head *result_up);
153 extern int lstcon_batch_debug(int timeout, char *name, 
154                               int client, struct list_head *result_up);
155 extern int lstcon_group_debug(int timeout, char *name,
156                               struct list_head *result_up);
157 extern int lstcon_nodes_debug(int timeout, int nnd, lnet_process_id_t *nds_up,
158                               struct list_head *result_up);
159 extern int lstcon_group_add(char *name);
160 extern int lstcon_group_del(char *name);
161 extern int lstcon_group_clean(char *name, int args);
162 extern int lstcon_group_refresh(char *name, struct list_head *result_up);
163 extern int lstcon_nodes_add(char *name, int nnd, lnet_process_id_t *nds_up,
164                             struct list_head *result_up);
165 extern int lstcon_nodes_remove(char *name, int nnd, lnet_process_id_t *nds_up,
166                                struct list_head *result_up);
167 extern int lstcon_group_info(char *name, lstcon_ndlist_ent_t *gent_up, 
168                              int *index_p, int *ndent_p, lstcon_node_ent_t *ndents_up);
169 extern int lstcon_group_list(int idx, int len, char *name_up);
170 extern int lstcon_batch_add(char *name);
171 extern int lstcon_batch_run(char *name, int timeout, struct list_head *result_up);
172 extern int lstcon_batch_stop(char *name, int force, struct list_head *result_up);
173 extern int lstcon_test_batch_query(char *name, int testidx,
174                                    int client, int timeout,
175                                    struct list_head *result_up);
176 extern int lstcon_batch_del(char *name);
177 extern int lstcon_batch_list(int idx, int namelen, char *name_up);
178 extern int lstcon_batch_info(char *name, lstcon_test_batch_ent_t *ent_up,
179                              int server, int testidx, int *index_p,
180                              int *ndent_p, lstcon_node_ent_t *dents_up);
181 extern int lstcon_group_stat(char *grp_name, int timeout,
182                              struct list_head *result_up);
183 extern int lstcon_nodes_stat(int count, lnet_process_id_t *ids_up,
184                              int timeout, struct list_head *result_up);
185 extern int lstcon_test_add(char *name, int type, int loop, int concur,
186                            int dist, int span, char *src_name, char * dst_name,
187                            void *param, int paramlen, struct list_head *result_up);
188 #endif
189
190 #endif