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 *inter_module_get(char *arg)
29 if (!strcmp(arg, "tcpnal_ni"))
31 else if (!strcmp(arg, "ldlm_cli_cancel_unused"))
32 return ldlm_cli_cancel_unused;
33 else if (!strcmp(arg, "ldlm_namespace_cleanup"))
34 return ldlm_namespace_cleanup;
35 else if (!strcmp(arg, "ldlm_replay_locks"))
36 return ldlm_replay_locks;
41 /* XXX move to proper place */
42 char *portals_nid2str(int nal, ptl_nid_t nid, char *str)
48 snprintf(str, PTL_NALFMT_SIZE - 1, "%u:%u.%u.%u.%u",
49 (__u32)(nid >> 32), HIPQUAD(nid));
55 snprintf(str, PTL_NALFMT_SIZE - 1, "%u:%u",
56 (__u32)(nid >> 32), (__u32)nid);
59 snprintf(str, PTL_NALFMT_SIZE - 1, "?%d? %llx",
66 ptl_handle_ni_t tcpnal_ni;
76 struct task_struct *current;
79 libcfs_nal_cmd(struct portals_cfg *pcfg)
81 CERROR("empty function!!!\n");
85 int init_current(int argc, char **argv)
87 current = malloc(sizeof(*current));
88 strncpy(current->comm, argv[0], sizeof(current->comm));
89 current->pid = getpid();
93 ptl_nid_t tcpnal_mynid;
95 int init_lib_portals()
100 rc = PtlInit(&max_interfaces);
102 CERROR("ksocknal: PtlNIInit failed: error %d\n", rc);
108 extern int class_handle_ioctl(unsigned int cmd, unsigned long arg);
110 int liblustre_ioctl(int dev_id, unsigned int opc, void *ptr)
116 fprintf(stderr, "Unexpected device id %d\n", dev_id);
121 rc = class_handle_ioctl(opc, (unsigned long)ptr);
128 static void generate_random_uuid(unsigned char uuid_out[16])
130 int *arr = (int*)uuid_out;
133 for (i = 0; i < sizeof(uuid_out)/sizeof(int); i++)
137 static char *echo_server_nid = NULL;
138 static char *echo_server_ostname = "obd1";
139 static char *osc_dev_name = "OSC_DEV_NAME";
140 static char *echo_dev_name = "ECHO_CLIENT_DEV_NAME";
142 static int connect_echo_client(void)
144 struct lustre_cfg lcfg;
146 char *peer = "ECHO_PEER_NID";
147 class_uuid_t osc_uuid, echo_uuid;
148 struct obd_uuid osc_uuid_str, echo_uuid_str;
152 generate_random_uuid(osc_uuid);
153 class_uuid_unparse(osc_uuid, &osc_uuid_str);
154 generate_random_uuid(echo_uuid);
155 class_uuid_unparse(echo_uuid, &echo_uuid_str);
157 if (ptl_parse_nid(&nid, echo_server_nid)) {
158 CERROR("Can't parse NID %s\n", echo_server_nid);
161 nal = ptl_name2nal("tcp");
163 CERROR("Can't parse NAL tcp\n");
168 LCFG_INIT(lcfg, LCFG_ADD_UUID, NULL);
170 lcfg.lcfg_inllen1 = strlen(peer) + 1;
171 lcfg.lcfg_inlbuf1 = peer;
173 err = class_process_config(&lcfg);
175 CERROR("failed add_uuid\n");
180 LCFG_INIT(lcfg, LCFG_ATTACH, osc_dev_name);
181 lcfg.lcfg_inlbuf1 = "osc";
182 lcfg.lcfg_inllen1 = strlen(lcfg.lcfg_inlbuf1) + 1;
183 lcfg.lcfg_inlbuf2 = osc_uuid_str.uuid;
184 lcfg.lcfg_inllen2 = strlen(lcfg.lcfg_inlbuf2) + 1;
185 err = class_process_config(&lcfg);
187 CERROR("failed attach osc\n");
192 LCFG_INIT(lcfg, LCFG_SETUP, osc_dev_name);
193 lcfg.lcfg_inlbuf1 = echo_server_ostname;
194 lcfg.lcfg_inllen1 = strlen(lcfg.lcfg_inlbuf1) + 1;
195 lcfg.lcfg_inlbuf2 = peer;
196 lcfg.lcfg_inllen2 = strlen(lcfg.lcfg_inlbuf2) + 1;
197 err = class_process_config(&lcfg);
199 CERROR("failed setup osc\n");
203 /* attach echo_client */
204 LCFG_INIT(lcfg, LCFG_ATTACH, echo_dev_name);
205 lcfg.lcfg_inlbuf1 = "echo_client";
206 lcfg.lcfg_inllen1 = strlen(lcfg.lcfg_inlbuf1) + 1;
207 lcfg.lcfg_inlbuf2 = echo_uuid_str.uuid;
208 lcfg.lcfg_inllen2 = strlen(lcfg.lcfg_inlbuf2) + 1;
209 err = class_process_config(&lcfg);
211 CERROR("failed attach echo_client\n");
215 /* setup echo_client */
216 LCFG_INIT(lcfg, LCFG_SETUP, echo_dev_name);
217 lcfg.lcfg_inlbuf1 = osc_dev_name;
218 lcfg.lcfg_inllen1 = strlen(lcfg.lcfg_inlbuf1) + 1;
219 lcfg.lcfg_inlbuf2 = NULL;
220 lcfg.lcfg_inllen2 = 0;
221 err = class_process_config(&lcfg);
223 CERROR("failed setup echo_client\n");
230 static int disconnect_echo_client(void)
232 struct lustre_cfg lcfg;
236 /* cleanup echo_client */
237 LCFG_INIT(lcfg, LCFG_CLEANUP, echo_dev_name);
238 err = class_process_config(&lcfg);
240 CERROR("failed cleanup echo_client\n");
244 /* detach echo_client */
245 LCFG_INIT(lcfg, LCFG_DETACH, echo_dev_name);
246 err = class_process_config(&lcfg);
248 CERROR("failed detach echo_client\n");
253 LCFG_INIT(lcfg, LCFG_CLEANUP, osc_dev_name);
254 err = class_process_config(&lcfg);
256 CERROR("failed cleanup osc device\n");
261 LCFG_INIT(lcfg, LCFG_DETACH, osc_dev_name);
262 err = class_process_config(&lcfg);
264 CERROR("failed detach osc device\n");
271 static void usage(const char *s)
273 printf("Usage: %s -s ost_host_name [-n ost_name]\n", s);
274 printf(" ost_host_name: the host name of echo server\n");
275 printf(" ost_name: ost name, default is \"obd1\"\n");
278 extern int time_ptlwait1;
279 extern int time_ptlwait2;
280 extern int time_ptlselect;
282 int main(int argc, char **argv)
286 while ((c = getopt(argc, argv, "s:n:")) != -1) {
289 echo_server_nid = optarg;
292 echo_server_ostname = optarg;
303 if (!echo_server_nid) {
310 tcpnal_mynid = rand();
313 portal_subsystem_debug = 0;
316 if (init_current(argc, argv) ||
317 init_obdclass() || init_lib_portals() ||
322 echo_client_init()) {
327 rc = connect_echo_client();
331 set_ioc_handler(liblustre_ioctl);
333 rc = lctl_main(1, &argv[0]);
335 rc |= disconnect_echo_client();