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 2008 Sun Microsystems, Inc. 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 * lustre/liblustre/tests/echo_test.c
38 * Lustre Light user test program
41 #include <liblustre.h>
43 #include <obd_class.h>
46 #define LIBLUSTRE_TEST 1
47 #include "../utils/lctl.c"
53 int _sysio_lustre_init(void)
56 * This is an aweful HACK. Basically the problem is on
57 * Catamount, the build system links in liblustre.a to
58 * all the test executables, and at this point its not
59 * clear how to modify the build system to prevent this
60 * from happening. So providing our own call to
61 * _sysio_lustre_init() that does nothing, prevents
62 * liblustre.a from initializing.
64 * Why is liblustre.a initializing a problem anyway. Well
65 * this main() in this module calls init_obdclass(), as
66 * well as the llite_lib.c's _sysio_lustre_init(). Two
67 * calls to init_obdclass() cause an assertion. Secondly
68 * it doesn't even logically make sense, this is module
69 * does not need lustre file system functionality, it's
70 * just the echo_tester.
73 /*lprintf("--> THIS OVERRIDES liblustre.a INITIALIZATION <--\n");*/
80 extern int class_handle_ioctl(unsigned int cmd, unsigned long arg);
82 static int liblustre_ioctl(int dev_id, unsigned int opc, void *ptr)
88 fprintf(stderr, "Unexpected device id %d\n", dev_id);
93 rc = class_handle_ioctl(opc, (unsigned long)ptr);
100 static char *echo_server_nid = NULL;
101 static char *echo_server_ostname = "obd1";
102 static char *osc_dev_name = "OSC_DEV_NAME";
103 static char *echo_dev_name = "ECHO_CLIENT_DEV_NAME";
105 static int connect_echo_client(void)
107 struct lustre_cfg *lcfg;
108 struct lustre_cfg_bufs bufs;
110 char *peer = "ECHO_PEER_NID";
111 class_uuid_t osc_uuid, echo_uuid;
112 struct obd_uuid osc_uuid_str, echo_uuid_str;
116 ll_generate_random_uuid(osc_uuid);
117 class_uuid_unparse(osc_uuid, &osc_uuid_str);
118 ll_generate_random_uuid(echo_uuid);
119 class_uuid_unparse(echo_uuid, &echo_uuid_str);
121 nid = libcfs_str2nid(echo_server_nid);
122 if (nid == LNET_NID_ANY) {
123 CERROR("Can't parse NID %s\n", echo_server_nid);
128 lustre_cfg_bufs_reset(&bufs, NULL);
129 lustre_cfg_bufs_set_string(&bufs, 1, peer);
130 lcfg = lustre_cfg_new(LCFG_ADD_UUID, &bufs);
131 lcfg->lcfg_nid = nid;
132 err = class_process_config(lcfg);
133 lustre_cfg_free(lcfg);
135 CERROR("failed add_uuid\n");
140 lustre_cfg_bufs_reset(&bufs, osc_dev_name);
141 lustre_cfg_bufs_set_string(&bufs, 1, LUSTRE_OSC_NAME);
142 lustre_cfg_bufs_set_string(&bufs, 2, osc_uuid_str.uuid);
143 lcfg = lustre_cfg_new(LCFG_ATTACH, &bufs);
144 err = class_process_config(lcfg);
145 lustre_cfg_free(lcfg);
147 CERROR("failed attach osc\n");
152 lustre_cfg_bufs_reset(&bufs, osc_dev_name);
153 lustre_cfg_bufs_set_string(&bufs, 1, echo_server_ostname);
154 lustre_cfg_bufs_set_string(&bufs, 2, peer);
155 lcfg = lustre_cfg_new(LCFG_SETUP, &bufs);
156 err = class_process_config(lcfg);
157 lustre_cfg_free(lcfg);
159 CERROR("failed setup osc\n");
163 /* attach echo_client */
164 lustre_cfg_bufs_reset(&bufs, echo_dev_name);
165 lustre_cfg_bufs_set_string(&bufs, 1, "echo_client");
166 lustre_cfg_bufs_set_string(&bufs, 2, echo_uuid_str.uuid);
167 lcfg = lustre_cfg_new(LCFG_ATTACH, &bufs);
168 err = class_process_config(lcfg);
169 lustre_cfg_free(lcfg);
171 CERROR("failed attach echo_client\n");
175 /* setup echo_client */
176 lustre_cfg_bufs_reset(&bufs, echo_dev_name);
177 lustre_cfg_bufs_set_string(&bufs, 1, osc_dev_name);
178 lustre_cfg_bufs_set_string(&bufs, 2, NULL);
179 lcfg = lustre_cfg_new(LCFG_SETUP, &bufs);
180 err = class_process_config(lcfg);
181 lustre_cfg_free(lcfg);
183 CERROR("failed setup echo_client\n");
190 static int disconnect_echo_client(void)
192 struct lustre_cfg_bufs bufs;
193 struct lustre_cfg *lcfg = NULL;
197 /* cleanup echo_client */
198 lustre_cfg_bufs_reset(&bufs, echo_dev_name);
199 lcfg = lustre_cfg_new(LCFG_CLEANUP, &bufs);
200 err = class_process_config(lcfg);
202 lustre_cfg_free(lcfg);
203 CERROR("failed cleanup echo_client\n");
207 /* detach echo_client */
208 lcfg->lcfg_command = LCFG_DETACH;
209 err = class_process_config(lcfg);
210 lustre_cfg_free(lcfg);
212 CERROR("failed detach echo_client\n");
217 lustre_cfg_bufs_reset(&bufs, osc_dev_name);
218 lcfg = lustre_cfg_new(LCFG_CLEANUP, &bufs);
219 err = class_process_config(lcfg);
221 lustre_cfg_free(lcfg);
222 CERROR("failed cleanup osc device\n");
227 lcfg->lcfg_command = LCFG_DETACH;
228 err = class_process_config(lcfg);
229 lustre_cfg_free(lcfg);
231 CERROR("failed detach osc device\n");
238 static void usage(const char *s)
240 printf("Usage: %s -s ost_host_name [-n ost_name] [-x lctl_options ...]\n", s);
241 printf(" ost_host_name: the host name of echo server\n");
242 printf(" ost_name: ost name, default is \"obd1\"\n");
243 printf(" lctl_options: options to pass to lctl.\n");
244 printf(" (e.g. -x --device 1 test_getattr 10000 -5)\n");
247 extern int time_ptlwait1;
248 extern int time_ptlwait2;
249 extern int time_ptlselect;
251 int main(int argc, char **argv)
254 int xindex = -1; /* index of -x option */
256 /* loop until all options are consumed or we hit
259 while ((c = getopt(argc, argv, "s:n:x:")) != -1 &&
263 echo_server_nid = optarg;
266 echo_server_ostname = optarg;
278 * Only warn with usage() if the -x option isn't specificed
279 * because when using -x this check is not valid.
281 if (optind != argc && xindex == -1)
284 if (!echo_server_nid) {
290 libcfs_subsystem_debug = 0;
292 liblustre_init_random();
294 if (liblustre_init_current(argv[0]) ||
295 init_obdclass() || init_lib_portals() ||
301 echo_client_init()) {
306 rc = connect_echo_client();
310 set_ioc_handler(liblustre_ioctl);
314 * If the -x option is not specified pass no args to lctl
315 * otherwise pass all the options after the "-x" to lctl
317 * HACK: in the case when the -x option is specified
318 * lctl sees argv[0] == "-x" and not the real argv[0] seen
319 * in this function. If that is a problem, a mapping will
320 * have to be done to fix that. However for normal functioning
321 * it seems to be irrelavant
324 rc = lctl_main(1, &argv[0]);
326 rc = lctl_main(argc-xindex+1, &argv[xindex-1]);
328 rc |= disconnect_echo_client();