4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
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.
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).
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
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
27 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
28 * Use is subject to license terms.
30 * Copyright (c) 2012, Intel Corporation.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
36 * lnet/selftest/conctl.c
38 * Author: Liang Zhen <liangzhen@clusterfs.com>
46 #include <lnet/lnetctl.h>
47 #include <lnet/lnetst.h>
48 #include "../selftest/rpc.h"
49 #include "../selftest/selftest.h"
51 static int lstjn_stopping = 0;
52 static int lstjn_intialized = 0;
55 static struct option lstjn_options[] =
57 {"sesid", required_argument, 0, 's' },
58 {"group", required_argument, 0, 'g' },
59 {"features", required_argument, 0, 'f' },
60 {"server_mode", no_argument, 0, 'm' },
71 lstjn_rpc_done(srpc_client_rpc_t *rpc)
73 if (!lstjn_intialized)
78 lstjn_join_session(char *ses, char *grp, unsigned feats)
80 lnet_process_id_t sesid;
81 srpc_client_rpc_t *rpc;
82 srpc_join_reqst_t *req;
83 srpc_join_reply_t *rep;
84 srpc_mksn_reqst_t *sreq;
85 srpc_mksn_reply_t *srep;
88 sesid.pid = LUSTRE_LNET_PID;
89 sesid.nid = libcfs_str2nid(ses);
90 if (sesid.nid == LNET_NID_ANY) {
91 fprintf(stderr, "Invalid session NID: %s\n", ses);
95 rpc = sfw_create_rpc(sesid, SRPC_SERVICE_JOIN, feats,
96 0, 0, lstjn_rpc_done, NULL);
98 fprintf(stderr, "Out of memory\n");
102 req = &rpc->crpc_reqstmsg.msg_body.join_reqst;
104 req->join_sid = LST_INVALID_SID;
105 strncpy(req->join_group, grp, LST_NAME_SIZE);
110 rc = selftest_wait_events();
112 if (lstjn_intialized)
116 if (rpc->crpc_status != 0) {
117 fprintf(stderr, "Failed to send RPC to console: %s\n",
118 strerror(rpc->crpc_status));
119 srpc_client_rpc_decref(rpc);
123 sfw_unpack_message(&rpc->crpc_replymsg);
125 rep = &rpc->crpc_replymsg.msg_body.join_reply;
126 if (rep->join_status != 0) {
127 fprintf(stderr, "Can't join session %s group %s: %s\n",
128 ses, grp, strerror(rep->join_status));
129 srpc_client_rpc_decref(rpc);
133 if (rpc->crpc_replymsg.msg_ses_feats != feats) {
134 /* this can only happen when connecting to old console
135 * which will ignore features */
136 fprintf(stderr, "Can't join session %s group %s because "
137 "feature bits can't match: %x/%x, please set "
138 "feature bits by -f FEATURES and retry\n",
139 ses, grp, feats, rpc->crpc_replymsg.msg_ses_feats);
140 srpc_client_rpc_decref(rpc);
144 sreq = &rpc->crpc_reqstmsg.msg_body.mksn_reqst;
145 sreq->mksn_sid = rep->join_sid;
146 sreq->mksn_force = 0;
147 strcpy(sreq->mksn_name, rep->join_session);
149 srep = &rpc->crpc_replymsg.msg_body.mksn_reply;
151 rc = sfw_make_session(sreq, srep);
152 if (rc != 0 || srep->mksn_status != 0) {
153 fprintf(stderr, "Can't create session: %d, %s\n",
154 rc, strerror(srep->mksn_status));
155 srpc_client_rpc_decref(rpc);
159 fprintf(stdout, "Session %s, ID: %s, "LPU64"\n",
160 ses, libcfs_nid2str(rep->join_sid.ses_nid),
161 rep->join_sid.ses_stamp);
163 srpc_client_rpc_decref(rpc);
169 main(int argc, char **argv)
173 unsigned feats = LST_FEATS_MASK;
174 int server_mode_flag = 0;
179 const char *usage_string =
180 "Usage: lstclient --sesid ID --group GROUP "
181 "--features FEATURES [--server_mode]\n";
184 c = getopt_long(argc, argv, "s:g:f:m",
185 lstjn_options, &optidx);
198 feats = strtol(optarg, NULL, 16);
202 server_mode_flag = 1;
205 fprintf(stderr, "%s", usage_string);
210 if (optind != argc || grp == NULL || ses == NULL) {
211 fprintf(stderr, "%s", usage_string);
215 if ((feats & ~LST_FEATS_MASK) != 0) {
217 "lstclient can't understand these feature bits: %x\n",
218 (feats & ~LST_FEATS_MASK));
222 rc = libcfs_debug_init(5 * 1024 * 1024);
224 fprintf(stderr, "libcfs_debug_init() failed: %d\n", rc);
228 rc = cfs_wi_startup();
230 fprintf(stderr, "cfs_wi_startup() failed: %d\n", rc);
231 libcfs_debug_cleanup();
237 fprintf(stderr, "LNetInit() failed: %d\n", rc);
239 libcfs_debug_cleanup();
243 if (server_mode_flag)
246 rc = lnet_selftest_init();
248 fprintf(stderr, "Can't startup selftest\n");
251 libcfs_debug_cleanup();
255 rc = lstjn_join_session(ses, grp, feats);
259 signal(SIGINT, lstjn_stop);
261 fprintf(stdout, "Start handling selftest requests, Ctl-C to stop\n");
263 while (!lstjn_stopping) {
264 selftest_wait_events();
266 if (!sfw_session_removed())
269 fprintf(stdout, "Session ended\n");
274 lnet_selftest_fini();
280 libcfs_debug_cleanup();