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 sprintf(str, "%u:%d.%d.%d.%d", (__u32)(nid >> 32),
53 sprintf(str, "%u:%u", (__u32)(nid >> 32), (__u32)nid);
61 ptl_handle_ni_t tcpnal_ni;
71 struct task_struct *current;
73 /* portals interfaces */
75 kportal_get_ni (int nal)
87 kportal_put_ni (int nal)
93 kportal_nal_cmd(struct portals_cfg *pcfg)
96 __u32 nal = pcfg->pcfg_nal;
102 if (nal > 0 && nal <= NAL_MAX_NR && nal_cmd[nal].nch_handler) {
103 CDEBUG(D_IOCTL, "calling handler nal: %d, cmd: %d\n", nal,
105 rc = nal_cmd[nal].nch_handler(pcfg, nal_cmd[nal].nch_private);
110 CERROR("empty function!!!\n");
115 int init_current(int argc, char **argv)
117 current = malloc(sizeof(*current));
118 strncpy(current->comm, argv[0], sizeof(current->comm));
119 current->pid = getpid();
123 ptl_nid_t tcpnal_mynid;
125 int init_lib_portals()
130 PtlInit(&max_interfaces);
131 rc = PtlNIInit(procbridge_interface, 0, 0, 0, &tcpnal_ni);
133 CERROR("ksocknal: PtlNIInit failed: error %d\n", rc);
137 PtlNIDebug(tcpnal_ni, ~0);
141 extern int class_handle_ioctl(unsigned int cmd, unsigned long arg);
143 int liblustre_ioctl(int dev_id, int opc, void *ptr)
149 fprintf(stderr, "Unexpected device id %d\n", dev_id);
154 rc = class_handle_ioctl(opc, (unsigned long)ptr);
161 static void generate_random_uuid(unsigned char uuid_out[16])
163 int *arr = (int*)uuid_out;
166 for (i = 0; i < sizeof(uuid_out)/sizeof(int); i++)
170 static char *echo_server_nid = NULL;
171 static char *echo_server_ostname = "obd1";
172 static char *osc_dev_name = "OSC_DEV_NAME";
173 static char *echo_dev_name = "ECHO_CLIENT_DEV_NAME";
175 static int connect_echo_client(void)
177 struct lustre_cfg lcfg;
179 char *peer = "ECHO_PEER_NID";
180 class_uuid_t osc_uuid, echo_uuid;
181 struct obd_uuid osc_uuid_str, echo_uuid_str;
185 generate_random_uuid(osc_uuid);
186 class_uuid_unparse(osc_uuid, &osc_uuid_str);
187 generate_random_uuid(echo_uuid);
188 class_uuid_unparse(echo_uuid, &echo_uuid_str);
190 if (ptl_parse_nid(&nid, echo_server_nid)) {
191 CERROR("Can't parse NID %s\n", echo_server_nid);
194 nal = ptl_name2nal("tcp");
196 CERROR("Can't parse NAL tcp\n");
201 LCFG_INIT(lcfg, LCFG_ADD_UUID, NULL);
203 lcfg.lcfg_inllen1 = strlen(peer) + 1;
204 lcfg.lcfg_inlbuf1 = peer;
206 err = class_process_config(&lcfg);
208 CERROR("failed add_uuid\n");
213 LCFG_INIT(lcfg, LCFG_ATTACH, osc_dev_name);
214 lcfg.lcfg_inlbuf1 = "osc";
215 lcfg.lcfg_inllen1 = strlen(lcfg.lcfg_inlbuf1) + 1;
216 lcfg.lcfg_inlbuf2 = osc_uuid_str.uuid;
217 lcfg.lcfg_inllen2 = strlen(lcfg.lcfg_inlbuf2) + 1;
218 err = class_process_config(&lcfg);
220 CERROR("failed attach osc\n");
225 LCFG_INIT(lcfg, LCFG_SETUP, osc_dev_name);
226 lcfg.lcfg_inlbuf1 = echo_server_ostname;
227 lcfg.lcfg_inllen1 = strlen(lcfg.lcfg_inlbuf1) + 1;
228 lcfg.lcfg_inlbuf2 = peer;
229 lcfg.lcfg_inllen2 = strlen(lcfg.lcfg_inlbuf2) + 1;
230 err = class_process_config(&lcfg);
232 CERROR("failed setup osc\n");
236 /* attach echo_client */
237 LCFG_INIT(lcfg, LCFG_ATTACH, echo_dev_name);
238 lcfg.lcfg_inlbuf1 = "echo_client";
239 lcfg.lcfg_inllen1 = strlen(lcfg.lcfg_inlbuf1) + 1;
240 lcfg.lcfg_inlbuf2 = echo_uuid_str.uuid;
241 lcfg.lcfg_inllen2 = strlen(lcfg.lcfg_inlbuf2) + 1;
242 err = class_process_config(&lcfg);
244 CERROR("failed attach echo_client\n");
248 /* setup echo_client */
249 LCFG_INIT(lcfg, LCFG_SETUP, echo_dev_name);
250 lcfg.lcfg_inlbuf1 = osc_dev_name;
251 lcfg.lcfg_inllen1 = strlen(lcfg.lcfg_inlbuf1) + 1;
252 lcfg.lcfg_inlbuf2 = NULL;
253 lcfg.lcfg_inllen2 = 0;
254 err = class_process_config(&lcfg);
256 CERROR("failed setup echo_client\n");
263 static int disconnect_echo_client(void)
265 struct lustre_cfg lcfg;
269 /* cleanup echo_client */
270 LCFG_INIT(lcfg, LCFG_CLEANUP, echo_dev_name);
271 err = class_process_config(&lcfg);
273 CERROR("failed cleanup echo_client\n");
277 /* detach echo_client */
278 LCFG_INIT(lcfg, LCFG_DETACH, echo_dev_name);
279 err = class_process_config(&lcfg);
281 CERROR("failed detach echo_client\n");
286 LCFG_INIT(lcfg, LCFG_CLEANUP, osc_dev_name);
287 err = class_process_config(&lcfg);
289 CERROR("failed cleanup osc device\n");
294 LCFG_INIT(lcfg, LCFG_DETACH, osc_dev_name);
295 err = class_process_config(&lcfg);
297 CERROR("failed detach osc device\n");
304 static void usage(const char *s)
306 printf("Usage: %s -s ost_host_name [-n ost_name]\n", s);
307 printf(" ost_host_name: the host name of echo server\n");
308 printf(" ost_name: ost name, default is \"obd1\"\n");
311 extern int time_ptlwait1;
312 extern int time_ptlwait2;
313 extern int time_ptlselect;
315 int main(int argc, char **argv)
319 while ((c = getopt(argc, argv, "s:n:")) != -1) {
322 echo_server_nid = optarg;
325 echo_server_ostname = optarg;
336 if (!echo_server_nid) {
343 tcpnal_mynid = rand();
346 portal_subsystem_debug = 0;
349 if (init_current(argc, argv) ||
350 init_obdclass() || init_lib_portals() ||
356 echo_client_init()) {
361 rc = connect_echo_client();
365 set_ioc_handler(liblustre_ioctl);
367 rc = lctl_main(1, &argv[0]);
369 rc |= disconnect_echo_client();