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 void *inter_module_get(char *arg)
24 if (!strcmp(arg, "tcpnal_ni"))
26 else if (!strcmp(arg, "ldlm_cli_cancel_unused"))
27 return ldlm_cli_cancel_unused;
28 else if (!strcmp(arg, "ldlm_namespace_cleanup"))
29 return ldlm_namespace_cleanup;
30 else if (!strcmp(arg, "ldlm_replay_locks"))
31 return ldlm_replay_locks;
36 /* XXX move to proper place */
37 char *portals_nid2str(int nal, ptl_nid_t nid, char *str)
43 sprintf(str, "%u:%d.%d.%d.%d", (__u32)(nid >> 32),
50 sprintf(str, "%u:%u", (__u32)(nid >> 32), (__u32)nid);
58 ptl_handle_ni_t tcpnal_ni;
68 struct task_struct *current;
70 /* portals interfaces */
72 kportal_get_ni (int nal)
84 kportal_put_ni (int nal)
90 kportal_nal_cmd(struct portals_cfg *pcfg)
93 __u32 nal = pcfg->pcfg_nal;
99 if (nal > 0 && nal <= NAL_MAX_NR && nal_cmd[nal].nch_handler) {
100 CDEBUG(D_IOCTL, "calling handler nal: %d, cmd: %d\n", nal,
102 rc = nal_cmd[nal].nch_handler(pcfg, nal_cmd[nal].nch_private);
107 CERROR("empty function!!!\n");
112 int init_current(int argc, char **argv)
114 current = malloc(sizeof(*current));
115 strncpy(current->comm, argv[0], sizeof(current->comm));
116 current->pid = getpid();
120 ptl_nid_t tcpnal_mynid;
122 int init_lib_portals()
127 rc = PtlNIInit(procbridge_interface, 0, 0, 0, &tcpnal_ni);
129 CERROR("ksocknal: PtlNIInit failed: error %d\n", rc);
133 PtlNIDebug(tcpnal_ni, ~0);
137 extern int class_handle_ioctl(unsigned int cmd, unsigned long arg);
139 int liblustre_ioctl(int dev_id, int opc, void *ptr)
145 fprintf(stderr, "Unexpected device id %d\n", dev_id);
150 rc = class_handle_ioctl(opc, (unsigned long)ptr);
157 static void generate_random_uuid(unsigned char uuid_out[16])
159 int *arr = (int*)uuid_out;
162 for (i = 0; i < sizeof(uuid_out)/sizeof(int); i++)
166 static char *echo_server_nid = NULL;
167 static char *echo_server_ostname = "obd1";
168 static char *osc_dev_name = "OSC_DEV_NAME";
169 static char *echo_dev_name = "ECHO_CLIENT_DEV_NAME";
171 static int connect_echo_client(void)
173 struct lustre_cfg lcfg;
175 char *peer = "ECHO_PEER_NID";
176 class_uuid_t osc_uuid, echo_uuid;
177 struct obd_uuid osc_uuid_str, echo_uuid_str;
181 generate_random_uuid(osc_uuid);
182 class_uuid_unparse(osc_uuid, &osc_uuid_str);
183 generate_random_uuid(echo_uuid);
184 class_uuid_unparse(echo_uuid, &echo_uuid_str);
186 if (ptl_parse_nid(&nid, echo_server_nid)) {
187 CERROR("Can't parse NID %s\n", echo_server_nid);
190 nal = ptl_name2nal("tcp");
192 CERROR("Can't parse NAL tcp\n");
197 LCFG_INIT(lcfg, LCFG_ADD_UUID, NULL);
199 lcfg.lcfg_inllen1 = strlen(peer) + 1;
200 lcfg.lcfg_inlbuf1 = peer;
202 err = class_process_config(&lcfg);
204 CERROR("failed add_uuid\n");
209 LCFG_INIT(lcfg, LCFG_ATTACH, osc_dev_name);
210 lcfg.lcfg_inlbuf1 = "osc";
211 lcfg.lcfg_inllen1 = strlen(lcfg.lcfg_inlbuf1) + 1;
212 lcfg.lcfg_inlbuf2 = osc_uuid_str.uuid;
213 lcfg.lcfg_inllen2 = strlen(lcfg.lcfg_inlbuf2) + 1;
214 err = class_process_config(&lcfg);
216 CERROR("failed attach osc\n");
221 LCFG_INIT(lcfg, LCFG_SETUP, osc_dev_name);
222 lcfg.lcfg_inlbuf1 = echo_server_ostname;
223 lcfg.lcfg_inllen1 = strlen(lcfg.lcfg_inlbuf1) + 1;
224 lcfg.lcfg_inlbuf2 = peer;
225 lcfg.lcfg_inllen2 = strlen(lcfg.lcfg_inlbuf2) + 1;
226 err = class_process_config(&lcfg);
228 CERROR("failed setup osc\n");
232 /* attach echo_client */
233 LCFG_INIT(lcfg, LCFG_ATTACH, echo_dev_name);
234 lcfg.lcfg_inlbuf1 = "echo_client";
235 lcfg.lcfg_inllen1 = strlen(lcfg.lcfg_inlbuf1) + 1;
236 lcfg.lcfg_inlbuf2 = echo_uuid_str.uuid;
237 lcfg.lcfg_inllen2 = strlen(lcfg.lcfg_inlbuf2) + 1;
238 err = class_process_config(&lcfg);
240 CERROR("failed attach echo_client\n");
244 /* setup echo_client */
245 LCFG_INIT(lcfg, LCFG_SETUP, echo_dev_name);
246 lcfg.lcfg_inlbuf1 = osc_dev_name;
247 lcfg.lcfg_inllen1 = strlen(lcfg.lcfg_inlbuf1) + 1;
248 lcfg.lcfg_inlbuf2 = NULL;
249 lcfg.lcfg_inllen2 = 0;
250 err = class_process_config(&lcfg);
252 CERROR("failed setup echo_client\n");
259 static int disconnect_echo_client(void)
261 struct lustre_cfg lcfg;
265 /* cleanup echo_client */
266 LCFG_INIT(lcfg, LCFG_CLEANUP, echo_dev_name);
267 err = class_process_config(&lcfg);
269 CERROR("failed cleanup echo_client\n");
273 /* detach echo_client */
274 LCFG_INIT(lcfg, LCFG_DETACH, echo_dev_name);
275 err = class_process_config(&lcfg);
277 CERROR("failed detach echo_client\n");
282 LCFG_INIT(lcfg, LCFG_CLEANUP, osc_dev_name);
283 err = class_process_config(&lcfg);
285 CERROR("failed cleanup osc device\n");
290 LCFG_INIT(lcfg, LCFG_DETACH, osc_dev_name);
291 err = class_process_config(&lcfg);
293 CERROR("failed detach osc device\n");
300 static void usage(const char *s)
302 printf("Usage: %s -s ost_host_name [-n ost_name]\n", s);
303 printf(" ost_host_name: the host name of echo server\n");
304 printf(" ost_name: ost name, default is \"obd1\"\n");
307 extern int time_ptlwait1;
308 extern int time_ptlwait2;
309 extern int time_ptlselect;
311 int main(int argc, char **argv)
315 while ((c = getopt(argc, argv, "s:n:")) != -1) {
318 echo_server_nid = optarg;
321 echo_server_ostname = optarg;
332 if (!echo_server_nid) {
339 tcpnal_mynid = rand();
342 portal_subsystem_debug = 0;
345 if (init_current(argc, argv) ||
346 init_obdclass() || init_lib_portals() ||
352 echo_client_init()) {
357 rc = connect_echo_client();
361 set_ioc_handler(liblustre_ioctl);
363 rc = lctl_main(1, &argv[0]);
365 rc |= disconnect_echo_client();