Whamcloud - gitweb
LU-18101 sec: fix ACL handling on recent kernels again
[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[]; /* 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         int                     tes_type;       /* type of the test, i.e: bulk, ping */
104         int                     tes_stop_onerr; /* stop on error */
105         int                     tes_oneside;    /* one-sided test */
106         int                     tes_concur;     /* concurrency */
107         int                     tes_loop;       /* loop count */
108         int                     tes_dist;       /* nodes distribution of target group */
109         int                     tes_span;       /* nodes span of target group */
110         int                     tes_cliidx;     /* client index, used for RPC creating */
111         struct list_head        tes_trans_list; /* transaction list */
112         struct lstcon_group     *tes_src_grp;   /* group run the test */
113         struct lstcon_group     *tes_dst_grp;   /* target group */
114         int                     tes_paramlen;   /* test parameter length */
115         char                    tes_param[];    /* test parameter */
116 };
117
118 #define LST_GLOBAL_HASHSIZE     503   /* global nodes hash table size */
119 #define LST_NODE_HASHSIZE       239   /* node hash table (for batch or group) */
120
121 #define LST_SESSION_NONE        0x0   /* no session */
122 #define LST_SESSION_ACTIVE      0x1   /* working session */
123
124 #define LST_CONSOLE_TIMEOUT     300   /* default console timeout */
125
126 struct lstcon_session {
127         struct mutex            ses_mutex;      /* only 1 thread in session */
128         struct lst_session_id   ses_id;         /* global session id */
129         u32                     ses_key;        /* local session key */
130         int                     ses_state;      /* state of session */
131         int                     ses_timeout;    /* timeout in seconds */
132         time64_t                ses_laststamp;  /* last operation stamp (seconds) */
133         /** tests features of the session */
134         unsigned int            ses_features;
135         /** features are synced with remote test nodes */
136         unsigned int            ses_feats_updated:1;
137         /** force creating */
138         unsigned int            ses_force:1;
139         /** session is shutting down */
140         unsigned int            ses_shutdown:1;
141         /** console is timedout */
142         unsigned int            ses_expired:1;
143         __u64                   ses_id_cookie;  /* batch id cookie */
144         char                    ses_name[LST_NAME_SIZE];  /* session name */
145         struct lstcon_rpc_trans *ses_ping;      /* session pinger */
146         struct stt_timer        ses_ping_timer; /* timer for pinger */
147         struct lstcon_trans_stat ses_trans_stat;/* transaction stats */
148
149         struct list_head        ses_trans_list; /* global list of transaction */
150         struct list_head        ses_grp_list;   /* global list of groups */
151         struct list_head        ses_bat_list;   /* global list of batches */
152         struct list_head        ses_ndl_list;   /* global list of nodes */
153         struct list_head        *ses_ndl_hash;  /* hash table of nodes */
154
155         spinlock_t              ses_rpc_lock;   /* serialize */
156         atomic_t                ses_rpc_counter;/* # of initialized RPCs */
157         struct list_head        ses_rpc_freelist;/* idle console rpc */
158 }; /* session descriptor */
159
160 extern struct lstcon_session console_session;
161
162 static inline struct lstcon_trans_stat *
163 lstcon_trans_stat(void)
164 {
165         return &console_session.ses_trans_stat;
166 }
167
168 static inline struct list_head *
169 lstcon_id2hash(struct lnet_process_id id, struct list_head *hash)
170 {
171         unsigned int idx = LNET_NIDADDR(id.nid) % LST_NODE_HASHSIZE;
172
173         return &hash[idx];
174 }
175
176 extern int lstcon_session_match(struct lst_sid sid);
177 extern int lstcon_session_new(char *name, int key, unsigned int version,
178                               int timeout, int flags);
179 extern int lstcon_session_end(void);
180 extern int lstcon_session_debug(int timeout,
181                                 struct list_head __user *result_up);
182 extern int lstcon_session_feats_check(unsigned int feats);
183 extern int lstcon_batch_debug(int timeout, char *name,
184                               int client, struct list_head __user *result_up);
185 extern int lstcon_group_debug(int timeout, char *name,
186                               struct list_head __user *result_up);
187 extern int lstcon_nodes_debug(int timeout, int nnd,
188                               struct lnet_process_id __user *nds_up,
189                               struct list_head __user *result_up);
190 extern int lstcon_group_add(char *name);
191 extern int lstcon_group_del(char *name);
192 void lstcon_group_addref(struct lstcon_group *grp);
193 void lstcon_group_decref(struct lstcon_group *grp);
194 int lstcon_group_find(const char *name, struct lstcon_group **grpp);
195 extern int lstcon_group_clean(char *name, int args);
196 extern int lstcon_group_refresh(char *name, struct list_head __user *result_up);
197 extern int lstcon_nodes_add(char *name, int nnd,
198                             struct lnet_process_id __user *nds_up,
199                             unsigned int *featp,
200                             struct list_head __user *result_up);
201 extern int lstcon_nodes_remove(char *name, int nnd,
202                                struct lnet_process_id __user *nds_up,
203                                struct list_head __user *result_up);
204 extern int lstcon_group_info(char *name,
205                              struct lstcon_ndlist_ent __user *gent_up,
206                              int *index_p, int *ndent_p,
207                              struct lstcon_node_ent __user *ndents_up);
208 extern int lstcon_batch_add(char *name);
209 extern int lstcon_batch_run(char *name, int timeout,
210                             struct list_head __user *result_up);
211 extern int lstcon_batch_stop(char *name, int force,
212                              struct list_head __user *result_up);
213 extern int lstcon_test_batch_query(char *name, int testidx,
214                                    int client, int timeout,
215                                    struct list_head __user *result_up);
216 extern int lstcon_batch_del(char *name);
217 extern int lstcon_batch_list(int idx, int namelen, char __user *name_up);
218 extern int lstcon_batch_info(char *name,
219                              struct lstcon_test_batch_ent __user *ent_up,
220                              int server, int testidx, int *index_p,
221                              int *ndent_p,
222                              struct lstcon_node_ent __user *dents_up);
223 extern int lstcon_group_stat(char *grp_name, int timeout,
224                              struct list_head __user *result_up);
225 extern int lstcon_nodes_stat(int count, struct lnet_process_id __user *ids_up,
226                              int timeout, struct list_head __user *result_up);
227 extern int lstcon_test_add(char *batch_name, int type, int loop,
228                            int concur, int dist, int span,
229                            char *src_name, char *dst_name,
230                            void *param, int paramlen, int *retp,
231                            struct list_head __user *result_up);
232
233 int lstcon_ioctl_entry(struct notifier_block *nb,
234                        unsigned long cmd, void *vdata);
235
236 int lstcon_console_init(void);
237 int lstcon_console_fini(void);
238
239 int lstcon_init_netlink(void);
240 void lstcon_fini_netlink(void);
241
242 #endif