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;
52 unsigned int libcfs_subsystem_debug = ~0 - (S_LNET | S_LND);
53 unsigned int libcfs_debug = 0;
55 static struct option lstjn_options[] =
57 {"sesid", required_argument, 0, 's' },
58 {"group", required_argument, 0, 'g' },
59 {"server_mode", no_argument, 0, 'm' },
70 lstjn_rpc_done(srpc_client_rpc_t *rpc)
72 if (!lstjn_intialized)
77 lstjn_join_session(char *ses, char *grp)
79 lnet_process_id_t sesid;
80 srpc_client_rpc_t *rpc;
81 srpc_join_reqst_t *req;
82 srpc_join_reply_t *rep;
83 srpc_mksn_reqst_t *sreq;
84 srpc_mksn_reply_t *srep;
87 sesid.pid = LUSTRE_LNET_PID;
88 sesid.nid = libcfs_str2nid(ses);
89 if (sesid.nid == LNET_NID_ANY) {
90 fprintf(stderr, "Invalid session NID: %s\n", ses);
94 rpc = sfw_create_rpc(sesid, SRPC_SERVICE_JOIN, 0,
95 0, lstjn_rpc_done, NULL);
97 fprintf(stderr, "Out of memory\n");
101 req = &rpc->crpc_reqstmsg.msg_body.join_reqst;
103 req->join_sid = LST_INVALID_SID;
104 strncpy(req->join_group, grp, LST_NAME_SIZE);
109 rc = selftest_wait_events();
111 if (lstjn_intialized)
115 if (rpc->crpc_status != 0) {
116 fprintf(stderr, "Failed to send RPC to console: %s\n",
117 strerror(rpc->crpc_status));
118 srpc_client_rpc_decref(rpc);
122 sfw_unpack_message(&rpc->crpc_replymsg);
124 rep = &rpc->crpc_replymsg.msg_body.join_reply;
125 if (rep->join_status != 0) {
126 fprintf(stderr, "Can't join session %s group %s: %s\n",
127 ses, grp, strerror(rep->join_status));
128 srpc_client_rpc_decref(rpc);
132 sreq = &rpc->crpc_reqstmsg.msg_body.mksn_reqst;
133 sreq->mksn_sid = rep->join_sid;
134 sreq->mksn_force = 0;
135 strcpy(sreq->mksn_name, rep->join_session);
137 srep = &rpc->crpc_replymsg.msg_body.mksn_reply;
139 rc = sfw_make_session(sreq, srep);
140 if (rc != 0 || srep->mksn_status != 0) {
141 fprintf(stderr, "Can't create session: %d, %s\n",
142 rc, strerror(srep->mksn_status));
143 srpc_client_rpc_decref(rpc);
147 fprintf(stdout, "Session %s, ID: %s, "LPU64"\n",
148 ses, libcfs_nid2str(rep->join_sid.ses_nid),
149 rep->join_sid.ses_stamp);
151 srpc_client_rpc_decref(rpc);
157 main(int argc, char **argv)
161 int server_mode_flag = 0;
166 const char *usage_string =
167 "Usage: lstclient --sesid ID --group GROUP [--server_mode]\n";
170 c = getopt_long(argc, argv, "s:g:m",
171 lstjn_options, &optidx);
184 server_mode_flag = 1;
187 fprintf(stderr, "%s", usage_string);
192 if (optind != argc || grp == NULL || ses == NULL) {
193 fprintf(stderr, "%s", usage_string);
197 rc = libcfs_debug_init(5 * 1024 * 1024);
199 CERROR("libcfs_debug_init() failed: %d\n", rc);
203 rc = cfs_wi_startup();
205 CERROR("cfs_wi_startup() failed: %d\n", rc);
206 libcfs_debug_cleanup();
212 CERROR("LNetInit() failed: %d\n", rc);
214 libcfs_debug_cleanup();
218 if (server_mode_flag)
221 rc = lnet_selftest_init();
223 fprintf(stderr, "Can't startup selftest\n");
226 libcfs_debug_cleanup();
230 rc = lstjn_join_session(ses, grp);
234 signal(SIGINT, lstjn_stop);
236 fprintf(stdout, "Start handling selftest requests, Ctl-C to stop\n");
238 while (!lstjn_stopping) {
239 selftest_wait_events();
241 if (!sfw_session_removed())
244 fprintf(stdout, "Session ended\n");
249 lnet_selftest_fini();
255 libcfs_debug_cleanup();