2 * -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
3 * vim:expandtab:shiftwidth=8:tabstop=8:
7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 only,
11 * as published by the Free Software Foundation.
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License version 2 for more details (a copy is included
17 * in the LICENSE file that accompanied this code).
19 * You should have received a copy of the GNU General Public License
20 * version 2 along with this program; If not, see [sun.com URL with a
23 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
24 * CA 95054 USA or visit www.sun.com if you need additional information or
30 * Copyright 2008 Sun Microsystems, Inc. All rights reserved
31 * Use is subject to license terms.
34 * This file is part of Lustre, http://www.lustre.org/
35 * Lustre is a trademark of Sun Microsystems, Inc.
37 * lnet/selftest/conctl.c
39 * Author: Liang Zhen <liangzhen@clusterfs.com>
47 #include <lnet/lnetctl.h>
48 #include <lnet/lnetst.h>
49 #include "../selftest/rpc.h"
50 #include "../selftest/selftest.h"
52 static int lstjn_stopping = 0;
53 static int lstjn_intialized = 0;
55 unsigned int libcfs_subsystem_debug = ~0 - (S_LNET | S_LND);
56 unsigned int libcfs_debug = 0;
58 static struct option lstjn_options[] =
60 {"sesid", required_argument, 0, 's' },
61 {"group", required_argument, 0, 'g' },
62 {"server_mode", no_argument, 0, 'm' },
73 lstjn_rpc_done(srpc_client_rpc_t *rpc)
75 if (!lstjn_intialized)
80 lstjn_join_session(char *ses, char *grp)
82 lnet_process_id_t sesid;
83 srpc_client_rpc_t *rpc;
84 srpc_join_reqst_t *req;
85 srpc_join_reply_t *rep;
86 srpc_mksn_reqst_t *sreq;
87 srpc_mksn_reply_t *srep;
90 sesid.pid = LUSTRE_LNET_PID;
91 sesid.nid = libcfs_str2nid(ses);
92 if (sesid.nid == LNET_NID_ANY) {
93 fprintf(stderr, "Invalid session NID: %s\n", ses);
97 rpc = sfw_create_rpc(sesid, SRPC_SERVICE_JOIN, 0,
98 0, lstjn_rpc_done, NULL);
100 fprintf(stderr, "Out of memory\n");
104 req = &rpc->crpc_reqstmsg.msg_body.join_reqst;
106 req->join_sid = LST_INVALID_SID;
107 strncpy(req->join_group, grp, LST_NAME_SIZE);
112 rc = selftest_wait_events();
114 if (lstjn_intialized)
118 if (rpc->crpc_status != 0) {
119 fprintf(stderr, "Failed to send RPC to console: %s\n",
120 strerror(rpc->crpc_status));
121 srpc_client_rpc_decref(rpc);
125 sfw_unpack_message(&rpc->crpc_replymsg);
127 rep = &rpc->crpc_replymsg.msg_body.join_reply;
128 if (rep->join_status != 0) {
129 fprintf(stderr, "Can't join session %s group %s: %s\n",
130 ses, grp, strerror(rep->join_status));
131 srpc_client_rpc_decref(rpc);
135 sreq = &rpc->crpc_reqstmsg.msg_body.mksn_reqst;
136 sreq->mksn_sid = rep->join_sid;
137 sreq->mksn_force = 0;
138 strcpy(sreq->mksn_name, rep->join_session);
140 srep = &rpc->crpc_replymsg.msg_body.mksn_reply;
142 rc = sfw_make_session(sreq, srep);
143 if (rc != 0 || srep->mksn_status != 0) {
144 fprintf(stderr, "Can't create session: %d, %s\n",
145 rc, strerror(srep->mksn_status));
146 srpc_client_rpc_decref(rpc);
150 fprintf(stdout, "Session %s, ID: %s, %Lu\n",
151 ses, libcfs_nid2str(rep->join_sid.ses_nid),
152 rep->join_sid.ses_stamp);
154 srpc_client_rpc_decref(rpc);
160 main(int argc, char **argv)
164 int server_mode_flag = 0;
169 const char *usage_string =
170 "Usage: lstclient --sesid ID --group GROUP [--server_mode]\n";
173 c = getopt_long(argc, argv, "s:g:m",
174 lstjn_options, &optidx);
187 server_mode_flag = 1;
190 fprintf(stderr, usage_string);
195 if (optind != argc || grp == NULL || ses == NULL) {
196 fprintf(stderr, usage_string);
200 rc = libcfs_debug_init(5 * 1024 * 1024);
202 CERROR("libcfs_debug_init() failed: %d\n", rc);
208 CERROR("LNetInit() failed: %d\n", rc);
209 libcfs_debug_cleanup();
213 if (server_mode_flag)
216 rc = lnet_selftest_init();
218 fprintf(stderr, "Can't startup selftest\n");
220 libcfs_debug_cleanup();
225 rc = lstjn_join_session(ses, grp);
229 signal(SIGINT, lstjn_stop);
231 fprintf(stdout, "Start handling selftest requests, Ctl-C to stop\n");
233 while (!lstjn_stopping) {
234 selftest_wait_events();
236 if (!sfw_session_removed())
239 fprintf(stdout, "Session ended\n");
244 lnet_selftest_fini();
248 libcfs_debug_cleanup();