Whamcloud - gitweb
LU-6142 selftest: SPDX for lnet/selftest/
[fs/lustre-release.git] / lnet / selftest / console.h
1 // SPDX-License-Identifier: GPL-2.0
2
3 /*
4  * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
5  * Use is subject to license terms.
6  *
7  * Copyright (c) 2012, 2013, Intel Corporation.
8  */
9
10 /*
11  * This file is part of Lustre, http://www.lustre.org/
12  *
13  * kernel structure for LST console
14  *
15  * Author: Liang Zhen <liangzhen@clusterfs.com>
16  */
17
18 #ifndef __LST_CONSOLE_H__
19 #define __LST_CONSOLE_H__
20
21 #include <linux/uaccess.h>
22
23 #include <libcfs/libcfs.h>
24 #include <lnet/lib-types.h>
25 #include "selftest.h"
26 #include "conrpc.h"
27
28 /* node descriptor */
29 struct lstcon_node {
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 */
36 };
37
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 */
43 };
44
45 /* (alias of nodes) group descriptor */
46 struct lstcon_group {
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 */
52
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 */
56 };
57
58 #define LST_BATCH_IDLE          0xB0            /* idle batch */
59 #define LST_BATCH_RUNNING       0xB1            /* running batch */
60
61 struct lstcon_tsb_hdr {
62         struct lst_bid          tsb_id;         /* batch ID */
63         int                     tsb_index;      /* test index */
64 };
65
66 /* (tests ) batch descriptor */
67 struct lstcon_batch {
68         /* test_batch header */
69         struct lstcon_tsb_hdr   bat_hdr;
70         /* chain on session's batches list */
71         struct list_head        bat_link;
72         /* # of test */
73         int                     bat_ntest;
74         /* state of the batch */
75         int                     bat_state;
76         /* parameter for run|stop, timeout for run, force for stop */
77         int                     bat_arg;
78         /* name of batch */
79         char                    bat_name[LST_NAME_SIZE];
80
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;
93 };
94
95 /* a single test descriptor */
96 struct lstcon_test {
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;
103
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 */
112
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 */
116
117         int                   tes_paramlen;   /* test parameter length */
118         char                  tes_param[0];   /* test parameter */
119 };
120
121 #define LST_GLOBAL_HASHSIZE     503             /* global nodes hash table size */
122 #define LST_NODE_HASHSIZE       239             /* node hash table (for batch or group) */
123
124 #define LST_SESSION_NONE        0x0             /* no session */
125 #define LST_SESSION_ACTIVE      0x1             /* working session */
126
127 #define LST_CONSOLE_TIMEOUT     300             /* default console timeout */
128
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 */
151
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 */
157
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 */
162
163 extern struct lstcon_session console_session;
164
165 static inline struct lstcon_trans_stat *
166 lstcon_trans_stat(void)
167 {
168         return &console_session.ses_trans_stat;
169 }
170
171 static inline struct list_head *
172 lstcon_id2hash(struct lnet_process_id id, struct list_head *hash)
173 {
174         unsigned int idx = LNET_NIDADDR(id.nid) % LST_NODE_HASHSIZE;
175
176         return &hash[idx];
177 }
178
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,
202                             unsigned *featp,
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,
223                              int *ndent_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);
234
235 int lstcon_ioctl_entry(struct notifier_block *nb,
236                        unsigned long cmd, void *vdata);
237
238 int lstcon_console_init(void);
239 int lstcon_console_fini(void);
240
241 int lstcon_init_netlink(void);
242 void lstcon_fini_netlink(void);
243
244 #endif