1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Lustre Light user test program
6 * Copyright (c) 2002-2004 Cluster File Systems, Inc.
8 * This file is part of Lustre, http://www.lustre.org.
10 * Lustre is free software; you can redistribute it and/or
11 * modify it under the terms of version 2 of the GNU General Public
12 * License as published by the Free Software Foundation.
14 * Lustre is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with Lustre; if not, write to the Free Software
21 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 #include <liblustre.h>
26 #include <obd_class.h>
29 #define LIBLUSTRE_TEST 1
30 #include "../utils/lctl.c"
36 int _sysio_lustre_init(void)
39 * This is an aweful HACK. Basically the problem is on
40 * Catamount, the build system links in liblustre.a to
41 * all the test executables, and at this point its not
42 * clear how to modify the build system to prevent this
43 * from happening. So providing our own call to
44 * _sysio_lustre_init() that does nothing, prevents
45 * liblustre.a from initializing.
47 * Why is liblustre.a initializing a problem anyway. Well
48 * this main() in this module calls init_obdclass(), as
49 * well as the llite_lib.c's _sysio_lustre_init(). Two
50 * calls to init_obdclass() cause an assertion. Secondly
51 * it doesn't even logically make sense, this is module
52 * does not need lustre file system functionality, it's
53 * just the echo_tester.
56 /*lprintf("--> THIS OVERRIDES liblustre.a INITIALIZATION <--\n");*/
63 extern int class_handle_ioctl(unsigned int cmd, unsigned long arg);
65 static int liblustre_ioctl(int dev_id, unsigned int opc, void *ptr)
71 fprintf(stderr, "Unexpected device id %d\n", dev_id);
76 rc = class_handle_ioctl(opc, (unsigned long)ptr);
83 static char *echo_server_nid = NULL;
84 static char *echo_server_ostname = "obd1";
85 static char *osc_dev_name = "OSC_DEV_NAME";
86 static char *echo_dev_name = "ECHO_CLIENT_DEV_NAME";
88 static int connect_echo_client(void)
90 struct lustre_cfg *lcfg;
91 struct lustre_cfg_bufs bufs;
93 char *peer = "ECHO_PEER_NID";
94 class_uuid_t osc_uuid, echo_uuid;
95 struct obd_uuid osc_uuid_str, echo_uuid_str;
99 generate_random_uuid(osc_uuid);
100 class_uuid_unparse(osc_uuid, &osc_uuid_str);
101 generate_random_uuid(echo_uuid);
102 class_uuid_unparse(echo_uuid, &echo_uuid_str);
104 nid = libcfs_str2nid(echo_server_nid);
105 if (nid == LNET_NID_ANY) {
106 CERROR("Can't parse NID %s\n", echo_server_nid);
111 lustre_cfg_bufs_reset(&bufs, NULL);
112 lustre_cfg_bufs_set_string(&bufs, 1, peer);
113 lcfg = lustre_cfg_new(LCFG_ADD_UUID, &bufs);
114 lcfg->lcfg_nid = nid;
115 err = class_process_config(lcfg);
116 lustre_cfg_free(lcfg);
118 CERROR("failed add_uuid\n");
123 lustre_cfg_bufs_reset(&bufs, osc_dev_name);
124 lustre_cfg_bufs_set_string(&bufs, 1, LUSTRE_OSC_NAME);
125 lustre_cfg_bufs_set_string(&bufs, 2, osc_uuid_str.uuid);
126 lcfg = lustre_cfg_new(LCFG_ATTACH, &bufs);
127 err = class_process_config(lcfg);
128 lustre_cfg_free(lcfg);
130 CERROR("failed attach osc\n");
135 lustre_cfg_bufs_reset(&bufs, osc_dev_name);
136 lustre_cfg_bufs_set_string(&bufs, 1, echo_server_ostname);
137 lustre_cfg_bufs_set_string(&bufs, 2, peer);
138 lcfg = lustre_cfg_new(LCFG_SETUP, &bufs);
139 err = class_process_config(lcfg);
140 lustre_cfg_free(lcfg);
142 CERROR("failed setup osc\n");
146 /* attach echo_client */
147 lustre_cfg_bufs_reset(&bufs, echo_dev_name);
148 lustre_cfg_bufs_set_string(&bufs, 1, "echo_client");
149 lustre_cfg_bufs_set_string(&bufs, 2, echo_uuid_str.uuid);
150 lcfg = lustre_cfg_new(LCFG_ATTACH, &bufs);
151 err = class_process_config(lcfg);
152 lustre_cfg_free(lcfg);
154 CERROR("failed attach echo_client\n");
158 /* setup echo_client */
159 lustre_cfg_bufs_reset(&bufs, echo_dev_name);
160 lustre_cfg_bufs_set_string(&bufs, 1, osc_dev_name);
161 lustre_cfg_bufs_set_string(&bufs, 2, NULL);
162 lcfg = lustre_cfg_new(LCFG_SETUP, &bufs);
163 err = class_process_config(lcfg);
164 lustre_cfg_free(lcfg);
166 CERROR("failed setup echo_client\n");
173 static int disconnect_echo_client(void)
175 struct lustre_cfg_bufs bufs;
176 struct lustre_cfg *lcfg = NULL;
180 /* cleanup echo_client */
181 lustre_cfg_bufs_reset(&bufs, echo_dev_name);
182 lcfg = lustre_cfg_new(LCFG_CLEANUP, &bufs);
183 err = class_process_config(lcfg);
185 lustre_cfg_free(lcfg);
186 CERROR("failed cleanup echo_client\n");
190 /* detach echo_client */
191 lcfg->lcfg_command = LCFG_DETACH;
192 err = class_process_config(lcfg);
193 lustre_cfg_free(lcfg);
195 CERROR("failed detach echo_client\n");
200 lustre_cfg_bufs_reset(&bufs, osc_dev_name);
201 lcfg = lustre_cfg_new(LCFG_CLEANUP, &bufs);
202 err = class_process_config(lcfg);
204 lustre_cfg_free(lcfg);
205 CERROR("failed cleanup osc device\n");
210 lcfg->lcfg_command = LCFG_DETACH;
211 err = class_process_config(lcfg);
212 lustre_cfg_free(lcfg);
214 CERROR("failed detach osc device\n");
221 static void usage(const char *s)
223 printf("Usage: %s -s ost_host_name [-n ost_name] [-x lctl_options ...]\n", s);
224 printf(" ost_host_name: the host name of echo server\n");
225 printf(" ost_name: ost name, default is \"obd1\"\n");
226 printf(" lctl_options: options to pass to lctl.\n");
227 printf(" (e.g. -x --device 1 test_getattr 10000 -5)\n");
230 extern int time_ptlwait1;
231 extern int time_ptlwait2;
232 extern int time_ptlselect;
234 int main(int argc, char **argv)
237 int xindex = -1; /* index of -x option */
239 /* loop until all options are consumed or we hit
242 while ((c = getopt(argc, argv, "s:n:x:")) != -1 &&
246 echo_server_nid = optarg;
249 echo_server_ostname = optarg;
261 * Only warn with usage() if the -x option isn't specificed
262 * because when using -x this check is not valid.
264 if (optind != argc && xindex == -1)
267 if (!echo_server_nid) {
273 libcfs_subsystem_debug = 0;
275 liblustre_init_random();
277 if (liblustre_init_current(argv[0]) ||
278 init_obdclass() || init_lib_portals() ||
283 echo_client_init()) {
288 rc = connect_echo_client();
292 set_ioc_handler(liblustre_ioctl);
296 * If the -x option is not specified pass no args to lctl
297 * otherwise pass all the options after the "-x" to lctl
299 * HACK: in the case when the -x option is specified
300 * lctl sees argv[0] == "-x" and not the real argv[0] seen
301 * in this function. If that is a problem, a mapping will
302 * have to be done to fix that. However for normal functioning
303 * it seems to be irrelavant
306 rc = lctl_main(1, &argv[0]);
308 rc = lctl_main(argc-xindex+1, &argv[xindex-1]);
310 rc |= disconnect_echo_client();