1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
5 #include <netinet/in.h>
6 #include <sys/socket.h>
9 #include <portals/ptlctl.h> /* needed for parse_dump */
12 #include <liblustre.h>
13 #include <linux/obd.h>
14 #include <linux/obd_class.h>
15 #include <procbridge.h>
17 #define LIBLUSTRE_TEST 1
18 #include "../utils/lctl.c"
20 struct ldlm_namespace;
24 unsigned int portal_subsystem_debug = ~0 - (S_PORTALS | S_QSWNAL | S_SOCKNAL |
27 void get_random_bytes(void *ptr, int size)
38 void *inter_module_get(char *arg)
40 if (!strcmp(arg, "tcpnal_ni"))
42 else if (!strcmp(arg, "ldlm_cli_cancel_unused"))
43 return ldlm_cli_cancel_unused;
44 else if (!strcmp(arg, "ldlm_namespace_cleanup"))
45 return ldlm_namespace_cleanup;
46 else if (!strcmp(arg, "ldlm_replay_locks"))
47 return ldlm_replay_locks;
52 /* XXX move to proper place */
53 char *portals_nid2str(int nal, ptl_nid_t nid, char *str)
59 snprintf(str, PTL_NALFMT_SIZE - 1, "%u:%u.%u.%u.%u",
60 (__u32)(nid >> 32), HIPQUAD(nid));
65 snprintf(str, PTL_NALFMT_SIZE - 1, "%u:%u",
66 (__u32)(nid >> 32), (__u32)nid);
69 snprintf(str, PTL_NALFMT_SIZE - 1, "?%d? %llx",
76 ptl_handle_ni_t tcpnal_ni;
86 struct task_struct *current;
89 libcfs_nal_cmd(struct portals_cfg *pcfg)
91 CERROR("empty function!!!\n");
95 int in_group_p(gid_t gid)
100 int init_current(int argc, char **argv)
102 current = malloc(sizeof(*current));
103 strncpy(current->comm, argv[0], sizeof(current->comm));
104 current->pid = getpid();
108 ptl_nid_t tcpnal_mynid;
110 int init_lib_portals()
115 rc = PtlInit(&max_interfaces);
117 CERROR("ksocknal: PtlNIInit failed: error %d\n", rc);
123 extern int class_handle_ioctl(unsigned int cmd, unsigned long arg);
125 int liblustre_ioctl(int dev_id, unsigned int opc, void *ptr)
131 fprintf(stderr, "Unexpected device id %d\n", dev_id);
136 rc = class_handle_ioctl(opc, (unsigned long)ptr);
143 static void generate_random_uuid(unsigned char uuid_out[16])
145 int *arr = (int*)uuid_out;
148 for (i = 0; i < sizeof(uuid_out)/sizeof(int); i++)
152 static char *echo_server_nid = NULL;
153 static char *echo_server_ostname = "obd1";
154 static char *osc_dev_name = "OSC_DEV_NAME";
155 static char *echo_dev_name = "ECHO_CLIENT_DEV_NAME";
157 static int connect_echo_client(void)
159 struct lustre_cfg lcfg;
161 char *peer = "ECHO_PEER_NID";
162 class_uuid_t osc_uuid, echo_uuid;
163 struct obd_uuid osc_uuid_str, echo_uuid_str;
167 generate_random_uuid(osc_uuid);
168 class_uuid_unparse(osc_uuid, &osc_uuid_str);
169 generate_random_uuid(echo_uuid);
170 class_uuid_unparse(echo_uuid, &echo_uuid_str);
172 if (ptl_parse_nid(&nid, echo_server_nid)) {
173 CERROR("Can't parse NID %s\n", echo_server_nid);
176 nal = ptl_name2nal("tcp");
178 CERROR("Can't parse NAL tcp\n");
183 LCFG_INIT(lcfg, LCFG_ADD_UUID, NULL);
185 lcfg.lcfg_inllen1 = strlen(peer) + 1;
186 lcfg.lcfg_inlbuf1 = peer;
188 err = class_process_config(&lcfg);
190 CERROR("failed add_uuid\n");
195 LCFG_INIT(lcfg, LCFG_ATTACH, osc_dev_name);
196 lcfg.lcfg_inlbuf1 = "osc";
197 lcfg.lcfg_inllen1 = strlen(lcfg.lcfg_inlbuf1) + 1;
198 lcfg.lcfg_inlbuf2 = osc_uuid_str.uuid;
199 lcfg.lcfg_inllen2 = strlen(lcfg.lcfg_inlbuf2) + 1;
200 err = class_process_config(&lcfg);
202 CERROR("failed attach osc\n");
207 LCFG_INIT(lcfg, LCFG_SETUP, osc_dev_name);
208 lcfg.lcfg_inlbuf1 = echo_server_ostname;
209 lcfg.lcfg_inllen1 = strlen(lcfg.lcfg_inlbuf1) + 1;
210 lcfg.lcfg_inlbuf2 = peer;
211 lcfg.lcfg_inllen2 = strlen(lcfg.lcfg_inlbuf2) + 1;
212 err = class_process_config(&lcfg);
214 CERROR("failed setup osc\n");
218 /* attach echo_client */
219 LCFG_INIT(lcfg, LCFG_ATTACH, echo_dev_name);
220 lcfg.lcfg_inlbuf1 = "echo_client";
221 lcfg.lcfg_inllen1 = strlen(lcfg.lcfg_inlbuf1) + 1;
222 lcfg.lcfg_inlbuf2 = echo_uuid_str.uuid;
223 lcfg.lcfg_inllen2 = strlen(lcfg.lcfg_inlbuf2) + 1;
224 err = class_process_config(&lcfg);
226 CERROR("failed attach echo_client\n");
230 /* setup echo_client */
231 LCFG_INIT(lcfg, LCFG_SETUP, echo_dev_name);
232 lcfg.lcfg_inlbuf1 = osc_dev_name;
233 lcfg.lcfg_inllen1 = strlen(lcfg.lcfg_inlbuf1) + 1;
234 lcfg.lcfg_inlbuf2 = NULL;
235 lcfg.lcfg_inllen2 = 0;
236 err = class_process_config(&lcfg);
238 CERROR("failed setup echo_client\n");
245 static int disconnect_echo_client(void)
247 struct lustre_cfg lcfg;
251 /* cleanup echo_client */
252 LCFG_INIT(lcfg, LCFG_CLEANUP, echo_dev_name);
253 err = class_process_config(&lcfg);
255 CERROR("failed cleanup echo_client\n");
259 /* detach echo_client */
260 LCFG_INIT(lcfg, LCFG_DETACH, echo_dev_name);
261 err = class_process_config(&lcfg);
263 CERROR("failed detach echo_client\n");
268 LCFG_INIT(lcfg, LCFG_CLEANUP, osc_dev_name);
269 err = class_process_config(&lcfg);
271 CERROR("failed cleanup osc device\n");
276 LCFG_INIT(lcfg, LCFG_DETACH, osc_dev_name);
277 err = class_process_config(&lcfg);
279 CERROR("failed detach osc device\n");
286 static void usage(const char *s)
288 printf("Usage: %s -s ost_host_name [-n ost_name]\n", s);
289 printf(" ost_host_name: the host name of echo server\n");
290 printf(" ost_name: ost name, default is \"obd1\"\n");
293 extern int time_ptlwait1;
294 extern int time_ptlwait2;
295 extern int time_ptlselect;
297 int main(int argc, char **argv)
301 while ((c = getopt(argc, argv, "s:n:")) != -1) {
304 echo_server_nid = optarg;
307 echo_server_ostname = optarg;
318 if (!echo_server_nid) {
325 tcpnal_mynid = rand();
328 portal_subsystem_debug = 0;
331 if (init_current(argc, argv) ||
332 init_obdclass() || init_lib_portals() ||
337 echo_client_init()) {
342 rc = connect_echo_client();
346 set_ioc_handler(liblustre_ioctl);
348 rc = lctl_main(1, &argv[0]);
350 rc |= disconnect_echo_client();