1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
6 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 only,
10 * as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License version 2 for more details (a copy is included
16 * in the LICENSE file that accompanied this code).
18 * You should have received a copy of the GNU General Public License
19 * version 2 along with this program; If not, see
20 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
22 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23 * CA 95054 USA or visit www.sun.com if you need additional information or
29 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
30 * Use is subject to license terms.
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;
54 unsigned int libcfs_subsystem_debug = ~0 - (S_LNET | S_LND);
55 unsigned int libcfs_debug = 0;
57 static struct option lstjn_options[] =
59 {"sesid", required_argument, 0, 's' },
60 {"group", required_argument, 0, 'g' },
61 {"server_mode", no_argument, 0, 'm' },
72 lstjn_rpc_done(srpc_client_rpc_t *rpc)
74 if (!lstjn_intialized)
79 lstjn_join_session(char *ses, char *grp)
81 lnet_process_id_t sesid;
82 srpc_client_rpc_t *rpc;
83 srpc_join_reqst_t *req;
84 srpc_join_reply_t *rep;
85 srpc_mksn_reqst_t *sreq;
86 srpc_mksn_reply_t *srep;
89 sesid.pid = LUSTRE_LNET_PID;
90 sesid.nid = libcfs_str2nid(ses);
91 if (sesid.nid == LNET_NID_ANY) {
92 fprintf(stderr, "Invalid session NID: %s\n", ses);
96 rpc = sfw_create_rpc(sesid, SRPC_SERVICE_JOIN, 0,
97 0, lstjn_rpc_done, NULL);
99 fprintf(stderr, "Out of memory\n");
103 req = &rpc->crpc_reqstmsg.msg_body.join_reqst;
105 req->join_sid = LST_INVALID_SID;
106 strncpy(req->join_group, grp, LST_NAME_SIZE);
111 rc = selftest_wait_events();
113 if (lstjn_intialized)
117 if (rpc->crpc_status != 0) {
118 fprintf(stderr, "Failed to send RPC to console: %s\n",
119 strerror(rpc->crpc_status));
120 srpc_client_rpc_decref(rpc);
124 sfw_unpack_message(&rpc->crpc_replymsg);
126 rep = &rpc->crpc_replymsg.msg_body.join_reply;
127 if (rep->join_status != 0) {
128 fprintf(stderr, "Can't join session %s group %s: %s\n",
129 ses, grp, strerror(rep->join_status));
130 srpc_client_rpc_decref(rpc);
134 sreq = &rpc->crpc_reqstmsg.msg_body.mksn_reqst;
135 sreq->mksn_sid = rep->join_sid;
136 sreq->mksn_force = 0;
137 strcpy(sreq->mksn_name, rep->join_session);
139 srep = &rpc->crpc_replymsg.msg_body.mksn_reply;
141 rc = sfw_make_session(sreq, srep);
142 if (rc != 0 || srep->mksn_status != 0) {
143 fprintf(stderr, "Can't create session: %d, %s\n",
144 rc, strerror(srep->mksn_status));
145 srpc_client_rpc_decref(rpc);
149 fprintf(stdout, "Session %s, ID: %s, "LPU64"\n",
150 ses, libcfs_nid2str(rep->join_sid.ses_nid),
151 rep->join_sid.ses_stamp);
153 srpc_client_rpc_decref(rpc);
159 main(int argc, char **argv)
163 int server_mode_flag = 0;
168 const char *usage_string =
169 "Usage: lstclient --sesid ID --group GROUP [--server_mode]\n";
172 c = getopt_long(argc, argv, "s:g:m",
173 lstjn_options, &optidx);
186 server_mode_flag = 1;
189 fprintf(stderr, "%s", usage_string);
194 if (optind != argc || grp == NULL || ses == NULL) {
195 fprintf(stderr, "%s", usage_string);
199 rc = libcfs_debug_init(5 * 1024 * 1024);
201 CERROR("libcfs_debug_init() failed: %d\n", rc);
205 rc = cfs_wi_startup();
207 CERROR("cfs_wi_startup() failed: %d\n", rc);
208 libcfs_debug_cleanup();
214 CERROR("LNetInit() failed: %d\n", rc);
216 libcfs_debug_cleanup();
220 if (server_mode_flag)
223 rc = lnet_selftest_init();
225 fprintf(stderr, "Can't startup selftest\n");
228 libcfs_debug_cleanup();
232 rc = lstjn_join_session(ses, grp);
236 signal(SIGINT, lstjn_stop);
238 fprintf(stdout, "Start handling selftest requests, Ctl-C to stop\n");
240 while (!lstjn_stopping) {
241 selftest_wait_events();
243 if (!sfw_session_removed())
246 fprintf(stdout, "Session ended\n");
251 lnet_selftest_fini();
257 libcfs_debug_cleanup();