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>
25 #include <linux/obd.h>
26 #include <linux/obd_class.h>
28 #define LIBLUSTRE_TEST 1
29 #include "../utils/lctl.c"
33 extern int class_handle_ioctl(unsigned int cmd, unsigned long arg);
45 char *portals_id2str(int nal, ptl_process_id_t id, char *str)
55 snprintf(str, PTL_NALFMT_SIZE - 1, "%u:%u.%u.%u.%u,%u",
56 (__u32)(id.nid >> 32), HIPQUAD((id.nid)) , id.pid);
61 snprintf(str, PTL_NALFMT_SIZE - 1, "%u:%u,%u",
62 (__u32)(id.nid >> 32), (__u32)id.nid, id.pid);
65 snprintf(str, PTL_NALFMT_SIZE - 1, "?%d? %llx,%lx",
66 nal, (long long)id.nid, (long)id.pid );
73 static int liblustre_ioctl(int dev_id, unsigned int opc, void *ptr)
79 fprintf(stderr, "Unexpected device id %d\n", dev_id);
84 rc = class_handle_ioctl(opc, (unsigned long)ptr);
91 static char *echo_server_nid = NULL;
92 static char *echo_server_ostname = "obd1";
93 static char *osc_dev_name = "OSC_DEV_NAME";
94 static char *echo_dev_name = "ECHO_CLIENT_DEV_NAME";
96 static int connect_echo_client(void)
98 struct lustre_cfg *lcfg;
99 struct lustre_cfg_bufs bufs;
101 char *peer = "ECHO_PEER_NID";
102 class_uuid_t osc_uuid, echo_uuid;
103 struct obd_uuid osc_uuid_str, echo_uuid_str;
107 generate_random_uuid(osc_uuid);
108 class_uuid_unparse(osc_uuid, &osc_uuid_str);
109 generate_random_uuid(echo_uuid);
110 class_uuid_unparse(echo_uuid, &echo_uuid_str);
112 if (ptl_parse_nid(&nid, echo_server_nid)) {
113 CERROR("Can't parse NID %s\n", echo_server_nid);
116 nal = ptl_name2nal("tcp");
118 CERROR("Can't parse NAL tcp\n");
122 lustre_cfg_bufs_reset(&bufs, NULL);
123 lustre_cfg_bufs_set_string(&bufs, 1, peer);
124 lcfg = lustre_cfg_new(LCFG_ADD_UUID, &bufs);
125 lcfg->lcfg_nid = nid;
126 lcfg->lcfg_nal = nal;
127 err = class_process_config(lcfg);
128 lustre_cfg_free(lcfg);
130 CERROR("failed add_uuid\n");
133 lustre_cfg_bufs_reset(&bufs, LUSTRE_OSC_NAME);
134 lustre_cfg_bufs_set_string(&bufs, 2, osc_uuid_str.uuid);
135 lcfg = lustre_cfg_new(LCFG_ATTACH, &bufs);
136 err = class_process_config(lcfg);
137 lustre_cfg_free(lcfg);
139 CERROR("failed attach osc\n");
144 lustre_cfg_bufs_reset(&bufs, osc_dev_name);
145 lustre_cfg_bufs_set_string(&bufs, 1, echo_server_ostname);
146 lustre_cfg_bufs_set_string(&bufs, 2, peer);
147 lcfg = lustre_cfg_new(LCFG_SETUP, &bufs);
148 err = class_process_config(lcfg);
149 lustre_cfg_free(lcfg);
151 CERROR("failed setup osc\n");
155 /* attach echo_client */
156 lustre_cfg_bufs_reset(&bufs, echo_dev_name);
157 lustre_cfg_bufs_set_string(&bufs, 1, "echo_client");
158 lustre_cfg_bufs_set_string(&bufs, 2, echo_uuid_str.uuid);
159 lcfg = lustre_cfg_new(LCFG_ATTACH, &bufs);
160 err = class_process_config(lcfg);
161 lustre_cfg_free(lcfg);
163 CERROR("failed attach echo_client\n");
167 /* setup echo_client */
168 lustre_cfg_bufs_reset(&bufs, echo_dev_name);
169 lustre_cfg_bufs_set_string(&bufs, 1, osc_dev_name);
170 lustre_cfg_bufs_set_string(&bufs, 2, NULL);
171 lcfg = lustre_cfg_new(LCFG_SETUP, &bufs);
172 err = class_process_config(lcfg);
173 lustre_cfg_free(lcfg);
175 CERROR("failed setup echo_client\n");
182 static int disconnect_echo_client(void)
184 struct lustre_cfg lcfg;
188 /* cleanup echo_client */
189 lustre_cfg_bufs_reset(&bufs, echo_dev_name);
190 lcfg = lustre_cfg_new(LCFG_CLEANUP, &bufs);
191 err = class_process_config(lcfg);
193 lustre_cfg_free(lcfg);
194 CERROR("failed cleanup echo_client\n");
198 /* detach echo_client */
199 lcfg->lcfg_command = LCFG_DETACH;
200 err = class_process_config(lcfg);
201 lustre_cfg_free(lcfg);
203 CERROR("failed detach echo_client\n");
208 lustre_cfg_bufs_reset(&bufs, osc_dev_name);
209 lcfg = lustre_cfg_new(LCFG_CLEANUP, &bufs);
210 err = class_process_config(lcfg);
212 lustre_cfg_free(lcfg);
213 CERROR("failed cleanup osc device\n");
218 lcfg->lcfg_command = LCFG_DETACH;
219 err = class_process_config(lcfg);
220 lustre_cfg_free(lcfg);
222 CERROR("failed detach osc device\n");
229 static void usage(const char *s)
231 printf("Usage: %s -s ost_host_name [-n ost_name]\n", s);
232 printf(" ost_host_name: the host name of echo server\n");
233 printf(" ost_name: ost name, default is \"obd1\"\n");
236 extern int time_ptlwait1;
237 extern int time_ptlwait2;
238 extern int time_ptlselect;
240 int main(int argc, char **argv)
244 while ((c = getopt(argc, argv, "s:n:")) != -1) {
247 echo_server_nid = optarg;
250 echo_server_ostname = optarg;
261 if (!echo_server_nid) {
267 portal_subsystem_debug = 0;
269 liblustre_init_random();
270 liblustre_set_nal_nid();
272 if (liblustre_init_current(argv[0]) ||
273 init_obdclass() || init_lib_portals() ||
278 echo_client_init()) {
283 rc = connect_echo_client();
287 set_ioc_handler(liblustre_ioctl);
289 rc = lctl_main(1, &argv[0]);
291 rc |= disconnect_echo_client();