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>
15 #define LIBLUSTRE_TEST 1
16 #include "../utils/lctl.c"
18 struct ldlm_namespace;
22 unsigned int portal_subsystem_debug = ~0 - (S_PORTALS | S_QSWNAL | S_SOCKNAL |
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;
181 char *peer = "ECHO_PEER_NID";
182 class_uuid_t osc_uuid, echo_uuid;
183 struct obd_uuid osc_uuid_str, echo_uuid_str;
187 generate_random_uuid(osc_uuid);
188 class_uuid_unparse(osc_uuid, &osc_uuid_str);
189 generate_random_uuid(echo_uuid);
190 class_uuid_unparse(echo_uuid, &echo_uuid_str);
192 if (ptl_parse_nid(&nid, echo_server_nid)) {
193 CERROR("Can't parse NID %s\n", echo_server_nid);
196 nal = ptl_name2nal("tcp");
198 CERROR("Can't parse NAL tcp\n");
203 LCFG_INIT(lcfg, LCFG_ADD_UUID, NULL);
205 lcfg.lcfg_inllen1 = strlen(peer) + 1;
206 lcfg.lcfg_inlbuf1 = peer;
208 err = class_process_config(&lcfg);
210 CERROR("failed add_uuid\n");
215 LCFG_INIT(lcfg, LCFG_ATTACH, osc_dev_name);
216 lcfg.lcfg_inlbuf1 = "osc";
217 lcfg.lcfg_inllen1 = strlen(lcfg.lcfg_inlbuf1) + 1;
218 lcfg.lcfg_inlbuf2 = osc_uuid_str.uuid;
219 lcfg.lcfg_inllen2 = strlen(lcfg.lcfg_inlbuf2) + 1;
220 err = class_process_config(&lcfg);
222 CERROR("failed attach osc\n");
227 LCFG_INIT(lcfg, LCFG_SETUP, osc_dev_name);
228 lcfg.lcfg_inlbuf1 = echo_server_ostname;
229 lcfg.lcfg_inllen1 = strlen(lcfg.lcfg_inlbuf1) + 1;
230 lcfg.lcfg_inlbuf2 = peer;
231 lcfg.lcfg_inllen2 = strlen(lcfg.lcfg_inlbuf2) + 1;
232 err = class_process_config(&lcfg);
234 CERROR("failed setup osc\n");
238 /* attach echo_client */
239 LCFG_INIT(lcfg, LCFG_ATTACH, echo_dev_name);
240 lcfg.lcfg_inlbuf1 = "echo_client";
241 lcfg.lcfg_inllen1 = strlen(lcfg.lcfg_inlbuf1) + 1;
242 lcfg.lcfg_inlbuf2 = echo_uuid_str.uuid;
243 lcfg.lcfg_inllen2 = strlen(lcfg.lcfg_inlbuf2) + 1;
244 err = class_process_config(&lcfg);
246 CERROR("failed attach echo_client\n");
250 /* setup echo_client */
251 LCFG_INIT(lcfg, LCFG_SETUP, echo_dev_name);
252 lcfg.lcfg_inlbuf1 = osc_dev_name;
253 lcfg.lcfg_inllen1 = strlen(lcfg.lcfg_inlbuf1) + 1;
254 lcfg.lcfg_inlbuf2 = NULL;
255 lcfg.lcfg_inllen2 = 0;
256 err = class_process_config(&lcfg);
258 CERROR("failed setup echo_client\n");
265 static int disconnect_echo_client(void)
267 struct lustre_cfg lcfg;
271 /* cleanup echo_client */
272 LCFG_INIT(lcfg, LCFG_CLEANUP, echo_dev_name);
273 err = class_process_config(&lcfg);
275 CERROR("failed cleanup echo_client\n");
279 /* detach echo_client */
280 LCFG_INIT(lcfg, LCFG_DETACH, echo_dev_name);
281 err = class_process_config(&lcfg);
283 CERROR("failed detach echo_client\n");
288 LCFG_INIT(lcfg, LCFG_CLEANUP, osc_dev_name);
289 err = class_process_config(&lcfg);
291 CERROR("failed cleanup osc device\n");
296 LCFG_INIT(lcfg, LCFG_DETACH, osc_dev_name);
297 err = class_process_config(&lcfg);
299 CERROR("failed detach osc device\n");
306 static void usage(const char *s)
308 printf("Usage: %s -s ost_host_name [-n ost_name]\n", s);
309 printf(" ost_host_name: the host name of echo server\n");
310 printf(" ost_name: ost name, default is \"obd1\"\n");
313 extern int time_ptlwait1;
314 extern int time_ptlwait2;
315 extern int time_ptlselect;
317 int main(int argc, char **argv)
321 while ((c = getopt(argc, argv, "s:n:")) != -1) {
324 echo_server_nid = optarg;
327 echo_server_ostname = optarg;
338 if (!echo_server_nid) {
345 tcpnal_mynid = rand();
348 portal_subsystem_debug = 0;
351 if (init_current(argc, argv) ||
352 init_obdclass() || init_lib_portals() ||
358 echo_client_init()) {
363 rc = connect_echo_client();
367 set_ioc_handler(liblustre_ioctl);
369 rc = lctl_main(1, &argv[0]);
371 rc |= disconnect_echo_client();