2 #include <netinet/in.h>
3 #include <sys/socket.h>
6 #include <portals/api-support.h> /* needed for ptpctl.h */
7 #include <portals/ptlctl.h> /* needed for parse_dump */
10 #include <liblustre.h>
11 #include <linux/obd.h>
12 #include <linux/obd_class.h>
13 #include <procbridge.h>
14 #include <linux/obd_ost.h>
16 #define LIBLUSTRE_TEST 1
17 #include "../utils/lctl.c"
19 struct ldlm_namespace;
23 unsigned int portal_subsystem_debug = ~0 - (S_PORTALS | S_NAL);
25 void *inter_module_get(char *arg)
27 if (!strcmp(arg, "tcpnal_ni"))
29 else if (!strcmp(arg, "ldlm_cli_cancel_unused"))
30 return ldlm_cli_cancel_unused;
31 else if (!strcmp(arg, "ldlm_namespace_cleanup"))
32 return ldlm_namespace_cleanup;
33 else if (!strcmp(arg, "ldlm_replay_locks"))
34 return ldlm_replay_locks;
39 /* XXX move to proper place */
40 char *portals_nid2str(int nal, ptl_nid_t nid, char *str)
46 snprintf(str, PTL_NALFMT_SIZE - 1, "%u:%u.%u.%u.%u",
47 (__u32)(nid >> 32), HIPQUAD(nid));
53 snprintf(str, PTL_NALFMT_SIZE - 1, "%u:%u",
54 (__u32)(nid >> 32), (__u32)nid);
57 snprintf(str, PTL_NALFMT_SIZE - 1, "?%d? %llx",
64 ptl_handle_ni_t tcpnal_ni;
74 struct task_struct *current;
76 /* portals interfaces */
78 kportal_get_ni (int nal)
90 kportal_put_ni (int nal)
96 kportal_nal_cmd(struct portals_cfg *pcfg)
99 __u32 nal = pcfg->pcfg_nal;
105 if (nal > 0 && nal <= NAL_MAX_NR && nal_cmd[nal].nch_handler) {
106 CDEBUG(D_IOCTL, "calling handler nal: %d, cmd: %d\n", nal,
108 rc = nal_cmd[nal].nch_handler(pcfg, nal_cmd[nal].nch_private);
113 CERROR("empty function!!!\n");
118 int init_current(int argc, char **argv)
120 current = malloc(sizeof(*current));
121 strncpy(current->comm, argv[0], sizeof(current->comm));
122 current->pid = getpid();
126 ptl_nid_t tcpnal_mynid;
128 int init_lib_portals()
133 rc = PtlNIInit(procbridge_interface, 0, 0, 0, &tcpnal_ni);
135 CERROR("ksocknal: PtlNIInit failed: error %d\n", rc);
139 PtlNIDebug(tcpnal_ni, ~0);
143 extern int class_handle_ioctl(unsigned int cmd, unsigned long arg);
145 int liblustre_ioctl(int dev_id, int opc, void *ptr)
151 fprintf(stderr, "Unexpected device id %d\n", dev_id);
156 rc = class_handle_ioctl(opc, (unsigned long)ptr);
163 static void generate_random_uuid(unsigned char uuid_out[16])
165 int *arr = (int*)uuid_out;
168 for (i = 0; i < sizeof(uuid_out)/sizeof(int); i++)
172 static char *echo_server_nid = NULL;
173 static char *echo_server_ostname = "obd1";
174 static char *osc_dev_name = "OSC_DEV_NAME";
175 static char *echo_dev_name = "ECHO_CLIENT_DEV_NAME";
177 static int connect_echo_client(void)
179 struct lustre_cfg *lcfg;
180 struct lustre_cfg_bufs bufs;
182 char *peer = "ECHO_PEER_NID";
183 class_uuid_t osc_uuid, echo_uuid;
184 struct obd_uuid osc_uuid_str, echo_uuid_str;
188 generate_random_uuid(osc_uuid);
189 class_uuid_unparse(osc_uuid, &osc_uuid_str);
190 generate_random_uuid(echo_uuid);
191 class_uuid_unparse(echo_uuid, &echo_uuid_str);
193 if (ptl_parse_nid(&nid, echo_server_nid)) {
194 CERROR("Can't parse NID %s\n", echo_server_nid);
197 nal = ptl_name2nal("tcp");
199 CERROR("Can't parse NAL tcp\n");
204 lustre_cfg_bufs_reset(&bufs, NULL);
205 lustre_cfg_bufs_set_string(&bufs, 1, peer);
206 lcfg = lustre_cfg_new(LCFG_ADD_UUID, &bufs);
207 lcfg->lcfg_nid = nid;
208 lcfg->lcfg_nal = nal;
209 err = class_process_config(lcfg);
210 lustre_cfg_free(lcfg);
212 CERROR("failed add_uuid\n");
217 lustre_cfg_bufs_reset(&bufs, LUSTRE_OSC_NAME);
218 lustre_cfg_bufs_set_string(&bufs, 2, osc_uuid_str.uuid);
219 lcfg = lustre_cfg_new(LCFG_ATTACH, &bufs);
220 err = class_process_config(lcfg);
221 lustre_cfg_free(lcfg);
223 CERROR("failed attach osc\n");
228 lustre_cfg_bufs_reset(&bufs, osc_dev_name);
229 lustre_cfg_bufs_set_string(&bufs, 1, echo_server_ostname);
230 lustre_cfg_bufs_set_string(&bufs, 2, peer);
231 lcfg = lustre_cfg_new(LCFG_SETUP, &bufs);
232 err = class_process_config(lcfg);
233 lustre_cfg_free(lcfg);
235 CERROR("failed setup osc\n");
239 /* attach echo_client */
240 lustre_cfg_bufs_reset(&bufs, echo_dev_name);
241 lustre_cfg_bufs_set_string(&bufs, 1, "echo_client");
242 lustre_cfg_bufs_set_string(&bufs, 2, echo_uuid_str.uuid);
243 lcfg = lustre_cfg_new(LCFG_ATTACH, &bufs);
244 err = class_process_config(lcfg);
245 lustre_cfg_free(lcfg);
247 CERROR("failed attach echo_client\n");
251 /* setup echo_client */
252 lustre_cfg_bufs_reset(&bufs, echo_dev_name);
253 lustre_cfg_bufs_set_string(&bufs, 1, osc_dev_name);
254 lustre_cfg_bufs_set_string(&bufs, 2, NULL);
255 lcfg = lustre_cfg_new(LCFG_SETUP, &bufs);
256 err = class_process_config(lcfg);
257 lustre_cfg_free(lcfg);
259 CERROR("failed setup echo_client\n");
266 static int disconnect_echo_client(void)
268 struct lustre_cfg_bufs bufs;
269 struct lustre_cfg *lcfg = NULL;
273 /* cleanup echo_client */
274 lustre_cfg_bufs_reset(&bufs, echo_dev_name);
275 lcfg = lustre_cfg_new(LCFG_CLEANUP, &bufs);
276 err = class_process_config(lcfg);
278 lustre_cfg_free(lcfg);
279 CERROR("failed cleanup echo_client\n");
283 /* detach echo_client */
284 lcfg->lcfg_command = LCFG_DETACH;
285 err = class_process_config(lcfg);
286 lustre_cfg_free(lcfg);
288 CERROR("failed detach echo_client\n");
293 lustre_cfg_bufs_reset(&bufs, osc_dev_name);
294 lcfg = lustre_cfg_new(LCFG_CLEANUP, &bufs);
295 err = class_process_config(lcfg);
297 lustre_cfg_free(lcfg);
298 CERROR("failed cleanup osc device\n");
303 lcfg->lcfg_command = LCFG_DETACH;
304 err = class_process_config(lcfg);
305 lustre_cfg_free(lcfg);
307 CERROR("failed detach osc device\n");
314 static void usage(const char *s)
316 printf("Usage: %s -s ost_host_name [-n ost_name]\n", s);
317 printf(" ost_host_name: the host name of echo server\n");
318 printf(" ost_name: ost name, default is \"obd1\"\n");
321 extern int time_ptlwait1;
322 extern int time_ptlwait2;
323 extern int time_ptlselect;
325 int main(int argc, char **argv)
329 while ((c = getopt(argc, argv, "s:n:")) != -1) {
332 echo_server_nid = optarg;
335 echo_server_ostname = optarg;
346 if (!echo_server_nid) {
353 tcpnal_mynid = rand();
356 portal_subsystem_debug = 0;
359 if (init_current(argc, argv) ||
360 init_obdclass() || init_lib_portals() ||
366 echo_client_init()) {
371 rc = connect_echo_client();
375 set_ioc_handler(liblustre_ioctl);
377 rc = lctl_main(1, &argv[0]);
379 rc |= disconnect_echo_client();