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.
31 * This file is part of Lustre, http://www.lustre.org/
32 * Lustre is a trademark of Sun Microsystems, Inc.
34 * lnet/selftest/conctl.c
36 * Author: Liang Zhen <liangzhen@clusterfs.com>
44 #include <lnet/lnetctl.h>
45 #include <lnet/lnetst.h>
46 #include "../selftest/rpc.h"
47 #include "../selftest/selftest.h"
49 static int lstjn_stopping = 0;
50 static int lstjn_intialized = 0;
53 static struct option lstjn_options[] =
55 {"sesid", required_argument, 0, 's' },
56 {"group", required_argument, 0, 'g' },
57 {"features", required_argument, 0, 'f' },
58 {"server_mode", no_argument, 0, 'm' },
69 lstjn_rpc_done(srpc_client_rpc_t *rpc)
71 if (!lstjn_intialized)
76 lstjn_join_session(char *ses, char *grp, unsigned feats)
78 lnet_process_id_t sesid;
79 srpc_client_rpc_t *rpc;
80 srpc_join_reqst_t *req;
81 srpc_join_reply_t *rep;
82 srpc_mksn_reqst_t *sreq;
83 srpc_mksn_reply_t *srep;
86 sesid.pid = LUSTRE_LNET_PID;
87 sesid.nid = libcfs_str2nid(ses);
88 if (sesid.nid == LNET_NID_ANY) {
89 fprintf(stderr, "Invalid session NID: %s\n", ses);
93 rpc = sfw_create_rpc(sesid, SRPC_SERVICE_JOIN, feats,
94 0, 0, lstjn_rpc_done, NULL);
96 fprintf(stderr, "Out of memory\n");
100 req = &rpc->crpc_reqstmsg.msg_body.join_reqst;
102 req->join_sid = LST_INVALID_SID;
103 strncpy(req->join_group, grp, LST_NAME_SIZE);
108 rc = selftest_wait_events();
110 if (lstjn_intialized)
114 if (rpc->crpc_status != 0) {
115 fprintf(stderr, "Failed to send RPC to console: %s\n",
116 strerror(rpc->crpc_status));
117 srpc_client_rpc_decref(rpc);
121 sfw_unpack_message(&rpc->crpc_replymsg);
123 rep = &rpc->crpc_replymsg.msg_body.join_reply;
124 if (rep->join_status != 0) {
125 fprintf(stderr, "Can't join session %s group %s: %s\n",
126 ses, grp, strerror(rep->join_status));
127 srpc_client_rpc_decref(rpc);
131 if (rpc->crpc_replymsg.msg_ses_feats != feats) {
132 /* this can only happen when connecting to old console
133 * which will ignore features */
134 fprintf(stderr, "Can't join session %s group %s because "
135 "feature bits can't match: %x/%x, please set "
136 "feature bits by -f FEATURES and retry\n",
137 ses, grp, feats, rpc->crpc_replymsg.msg_ses_feats);
138 srpc_client_rpc_decref(rpc);
142 sreq = &rpc->crpc_reqstmsg.msg_body.mksn_reqst;
143 sreq->mksn_sid = rep->join_sid;
144 sreq->mksn_force = 0;
145 strcpy(sreq->mksn_name, rep->join_session);
147 srep = &rpc->crpc_replymsg.msg_body.mksn_reply;
149 rc = sfw_make_session(sreq, srep);
150 if (rc != 0 || srep->mksn_status != 0) {
151 fprintf(stderr, "Can't create session: %d, %s\n",
152 rc, strerror(srep->mksn_status));
153 srpc_client_rpc_decref(rpc);
157 fprintf(stdout, "Session %s, ID: %s, "LPU64"\n",
158 ses, libcfs_nid2str(rep->join_sid.ses_nid),
159 rep->join_sid.ses_stamp);
161 srpc_client_rpc_decref(rpc);
167 main(int argc, char **argv)
171 unsigned feats = LST_FEATS_MASK;
172 int server_mode_flag = 0;
177 const char *usage_string =
178 "Usage: lstclient --sesid ID --group GROUP "
179 "--features FEATURES [--server_mode]\n";
182 c = getopt_long(argc, argv, "s:g:f:m",
183 lstjn_options, &optidx);
196 feats = strtol(optarg, NULL, 16);
200 server_mode_flag = 1;
203 fprintf(stderr, "%s", usage_string);
208 if (optind != argc || grp == NULL || ses == NULL) {
209 fprintf(stderr, "%s", usage_string);
213 if ((feats & ~LST_FEATS_MASK) != 0) {
215 "lstclient can't understand these feature bits: %x\n",
216 (feats & ~LST_FEATS_MASK));
220 rc = libcfs_debug_init(5 * 1024 * 1024);
222 fprintf(stderr, "libcfs_debug_init() failed: %d\n", rc);
226 rc = cfs_wi_startup();
228 fprintf(stderr, "cfs_wi_startup() failed: %d\n", rc);
229 libcfs_debug_cleanup();
235 fprintf(stderr, "LNetInit() failed: %d\n", rc);
237 libcfs_debug_cleanup();
241 if (server_mode_flag)
244 rc = lnet_selftest_init();
246 fprintf(stderr, "Can't startup selftest\n");
249 libcfs_debug_cleanup();
253 rc = lstjn_join_session(ses, grp, feats);
257 signal(SIGINT, lstjn_stop);
259 fprintf(stdout, "Start handling selftest requests, Ctl-C to stop\n");
261 while (!lstjn_stopping) {
262 selftest_wait_events();
264 if (!sfw_session_removed())
267 fprintf(stdout, "Session ended\n");
272 lnet_selftest_fini();
278 libcfs_debug_cleanup();