GNU Linux-libre 4.14.262-gnu1
[releases.git] / drivers / staging / lustre / 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) 2011, 2012, Intel Corporation.
27  */
28 /*
29  * This file is part of Lustre, http://www.lustre.org/
30  * Lustre is a trademark of Sun Microsystems, Inc.
31  *
32  * lnet/selftest/console.h
33  *
34  * kernel structure for LST console
35  *
36  * Author: Liang Zhen <liangzhen@clusterfs.com>
37  */
38
39 #ifndef __LST_CONSOLE_H__
40 #define __LST_CONSOLE_H__
41
42 #include <linux/libcfs/libcfs.h>
43 #include <linux/lnet/lib-types.h>
44 #include <uapi/linux/lnet/lnetst.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         unsigned long     nd_stamp;   /* timestamp of last replied RPC */
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                                                    */
69         int              grp_ref;                 /* reference count */
70         int              grp_userland;            /* has userland nodes */
71         int              grp_nnode;               /* # of nodes */
72         char             grp_name[LST_NAME_SIZE]; /* group name */
73
74         struct list_head grp_trans_list;          /* transaction list */
75         struct list_head grp_ndl_list;            /* nodes list */
76         struct list_head grp_ndl_hash[0];         /* hash table for nodes */
77 };
78
79 #define LST_BATCH_IDLE    0xB0      /* idle batch */
80 #define LST_BATCH_RUNNING 0xB1      /* running batch */
81
82 struct lstcon_tsb_hdr {
83         struct lst_bid   tsb_id;         /* batch ID */
84         int              tsb_index;      /* test index */
85 };
86
87 /* (tests ) batch descriptor */
88 struct lstcon_batch {
89         struct lstcon_tsb_hdr   bat_hdr;        /* test_batch header */
90         struct list_head bat_link;        /* chain on session's batches list */
91         int              bat_ntest;       /* # of test */
92         int              bat_state;       /* state of the batch */
93         int              bat_arg;         /* parameter for run|stop, timeout
94                                            * for run, force for stop
95                                            */
96         char             bat_name[LST_NAME_SIZE];/* name of batch */
97
98         struct list_head bat_test_list;   /* list head of tests (struct lstcon_test)
99                                            */
100         struct list_head bat_trans_list;  /* list head of transaction */
101         struct list_head bat_cli_list;    /* list head of client nodes
102                                            * (struct lstcon_node)
103                                            */
104         struct list_head *bat_cli_hash;   /* hash table of client nodes */
105         struct list_head bat_srv_list;    /* list head of server nodes */
106         struct list_head *bat_srv_hash;   /* hash table of server nodes */
107 };
108
109 /* a single test descriptor */
110 struct lstcon_test {
111         struct lstcon_tsb_hdr   tes_hdr;        /* test batch header */
112         struct list_head tes_link;       /* chain on batch's tests list */
113         struct lstcon_batch     *tes_batch;      /* pointer to batch */
114
115         int              tes_type;       /* type of the test, i.e: bulk, ping */
116         int              tes_stop_onerr; /* stop on error */
117         int              tes_oneside;    /* one-sided test */
118         int              tes_concur;     /* concurrency */
119         int              tes_loop;       /* loop count */
120         int              tes_dist;       /* nodes distribution of target group */
121         int              tes_span;       /* nodes span of target group */
122         int              tes_cliidx;     /* client index, used for RPC creating */
123
124         struct list_head tes_trans_list; /* transaction list */
125         struct lstcon_group     *tes_src_grp;   /* group run the test */
126         struct lstcon_group     *tes_dst_grp;   /* target group */
127
128         int              tes_paramlen;   /* test parameter length */
129         char             tes_param[0];   /* test parameter */
130 };
131
132 #define LST_GLOBAL_HASHSIZE 503      /* global nodes hash table size */
133 #define LST_NODE_HASHSIZE   239      /* node hash table (for batch or group) */
134
135 #define LST_SESSION_NONE    0x0      /* no session */
136 #define LST_SESSION_ACTIVE  0x1      /* working session */
137
138 #define LST_CONSOLE_TIMEOUT 300      /* default console timeout */
139
140 struct lstcon_session {
141         struct mutex        ses_mutex;        /* only 1 thread in session */
142         struct lst_sid      ses_id;           /* global session id */
143         int                 ses_key;          /* local session key */
144         int                 ses_state;        /* state of session */
145         int                 ses_timeout;      /* timeout in seconds */
146         time64_t            ses_laststamp;    /* last operation stamp (seconds)
147                                                */
148         unsigned int        ses_features;     /* tests features of the session
149                                                */
150         unsigned int        ses_feats_updated:1; /* features are synced with
151                                                   * remote test nodes
152                                                   */
153         unsigned int        ses_force:1;      /* force creating */
154         unsigned int        ses_shutdown:1;   /* session is shutting down */
155         unsigned int        ses_expired:1;    /* console is timedout */
156         __u64               ses_id_cookie;    /* batch id cookie */
157         char                ses_name[LST_NAME_SIZE];/* session name */
158         struct lstcon_rpc_trans *ses_ping;              /* session pinger */
159         struct stt_timer         ses_ping_timer;   /* timer for pinger */
160         struct lstcon_trans_stat ses_trans_stat;   /* transaction stats */
161
162         struct list_head    ses_trans_list;   /* global list of transaction */
163         struct list_head    ses_grp_list;     /* global list of groups */
164         struct list_head    ses_bat_list;     /* global list of batches */
165         struct list_head    ses_ndl_list;     /* global list of nodes */
166         struct list_head    *ses_ndl_hash;    /* hash table of nodes */
167
168         spinlock_t          ses_rpc_lock;     /* serialize */
169         atomic_t            ses_rpc_counter;  /* # of initialized RPCs */
170         struct list_head    ses_rpc_freelist; /* idle console rpc */
171 }; /* session descriptor */
172
173 extern struct lstcon_session     console_session;
174
175 static inline struct lstcon_trans_stat *
176 lstcon_trans_stat(void)
177 {
178         return &console_session.ses_trans_stat;
179 }
180
181 static inline struct list_head *
182 lstcon_id2hash(struct lnet_process_id id, struct list_head *hash)
183 {
184         unsigned int idx = LNET_NIDADDR(id.nid) % LST_NODE_HASHSIZE;
185
186         return &hash[idx];
187 }
188
189 int lstcon_ioctl_entry(unsigned int cmd, struct libcfs_ioctl_hdr *hdr);
190 int lstcon_console_init(void);
191 int lstcon_console_fini(void);
192 int lstcon_session_match(struct lst_sid sid);
193 int lstcon_session_new(char *name, int key, unsigned int version,
194                        int timeout, int flags, struct lst_sid __user *sid_up);
195 int lstcon_session_info(struct lst_sid __user *sid_up, int __user *key,
196                         unsigned __user *verp, struct lstcon_ndlist_ent __user *entp,
197                         char __user *name_up, int len);
198 int lstcon_session_end(void);
199 int lstcon_session_debug(int timeout, struct list_head __user *result_up);
200 int lstcon_session_feats_check(unsigned int feats);
201 int lstcon_batch_debug(int timeout, char *name,
202                        int client, struct list_head __user *result_up);
203 int lstcon_group_debug(int timeout, char *name,
204                        struct list_head __user *result_up);
205 int lstcon_nodes_debug(int timeout, int nnd,
206                        struct lnet_process_id __user *nds_up,
207                        struct list_head __user *result_up);
208 int lstcon_group_add(char *name);
209 int lstcon_group_del(char *name);
210 int lstcon_group_clean(char *name, int args);
211 int lstcon_group_refresh(char *name, struct list_head __user *result_up);
212 int lstcon_nodes_add(char *name, int nnd, struct lnet_process_id __user *nds_up,
213                      unsigned int *featp, struct list_head __user *result_up);
214 int lstcon_nodes_remove(char *name, int nnd,
215                         struct lnet_process_id __user *nds_up,
216                         struct list_head __user *result_up);
217 int lstcon_group_info(char *name, struct lstcon_ndlist_ent __user *gent_up,
218                       int *index_p, int *ndent_p,
219                       struct lstcon_node_ent __user *ndents_up);
220 int lstcon_group_list(int idx, int len, char __user *name_up);
221 int lstcon_batch_add(char *name);
222 int lstcon_batch_run(char *name, int timeout,
223                      struct list_head __user *result_up);
224 int lstcon_batch_stop(char *name, int force,
225                       struct list_head __user *result_up);
226 int lstcon_test_batch_query(char *name, int testidx,
227                             int client, int timeout,
228                             struct list_head __user *result_up);
229 int lstcon_batch_del(char *name);
230 int lstcon_batch_list(int idx, int namelen, char __user *name_up);
231 int lstcon_batch_info(char *name, struct lstcon_test_batch_ent __user *ent_up,
232                       int server, int testidx, int *index_p,
233                       int *ndent_p, struct lstcon_node_ent __user *dents_up);
234 int lstcon_group_stat(char *grp_name, int timeout,
235                       struct list_head __user *result_up);
236 int lstcon_nodes_stat(int count, struct lnet_process_id __user *ids_up,
237                       int timeout, struct list_head __user *result_up);
238 int lstcon_test_add(char *batch_name, int type, int loop,
239                     int concur, int dist, int span,
240                     char *src_name, char *dst_name,
241                     void *param, int paramlen, int *retp,
242                     struct list_head __user *result_up);
243 #endif