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;
74 libcfs_nal_cmd(struct portals_cfg *pcfg)
76 CERROR("empty function!!!\n");
80 int init_current(int argc, char **argv)
82 current = malloc(sizeof(*current));
83 strncpy(current->comm, argv[0], sizeof(current->comm));
84 current->pid = getpid();
88 ptl_nid_t tcpnal_mynid;
90 int init_lib_portals()
95 rc = PtlInit(&max_interfaces);
97 CERROR("ksocknal: PtlNIInit failed: error %d\n", rc);
103 extern int class_handle_ioctl(unsigned int cmd, unsigned long arg);
105 int liblustre_ioctl(int dev_id, int opc, void *ptr)
111 fprintf(stderr, "Unexpected device id %d\n", dev_id);
116 rc = class_handle_ioctl(opc, (unsigned long)ptr);
123 static void generate_random_uuid(unsigned char uuid_out[16])
125 int *arr = (int*)uuid_out;
128 for (i = 0; i < sizeof(uuid_out)/sizeof(int); i++)
132 static char *echo_server_nid = NULL;
133 static char *echo_server_ostname = "obd1";
134 static char *osc_dev_name = "OSC_DEV_NAME";
135 static char *echo_dev_name = "ECHO_CLIENT_DEV_NAME";
137 static int connect_echo_client(void)
139 struct lustre_cfg lcfg;
141 char *peer = "ECHO_PEER_NID";
142 class_uuid_t osc_uuid, echo_uuid;
143 struct obd_uuid osc_uuid_str, echo_uuid_str;
147 generate_random_uuid(osc_uuid);
148 class_uuid_unparse(osc_uuid, &osc_uuid_str);
149 generate_random_uuid(echo_uuid);
150 class_uuid_unparse(echo_uuid, &echo_uuid_str);
152 if (ptl_parse_nid(&nid, echo_server_nid)) {
153 CERROR("Can't parse NID %s\n", echo_server_nid);
156 nal = ptl_name2nal("tcp");
158 CERROR("Can't parse NAL tcp\n");
163 LCFG_INIT(lcfg, LCFG_ADD_UUID, NULL);
165 lcfg.lcfg_inllen1 = strlen(peer) + 1;
166 lcfg.lcfg_inlbuf1 = peer;
168 err = class_process_config(&lcfg);
170 CERROR("failed add_uuid\n");
175 LCFG_INIT(lcfg, LCFG_ATTACH, osc_dev_name);
176 lcfg.lcfg_inlbuf1 = "osc";
177 lcfg.lcfg_inllen1 = strlen(lcfg.lcfg_inlbuf1) + 1;
178 lcfg.lcfg_inlbuf2 = osc_uuid_str.uuid;
179 lcfg.lcfg_inllen2 = strlen(lcfg.lcfg_inlbuf2) + 1;
180 err = class_process_config(&lcfg);
182 CERROR("failed attach osc\n");
187 LCFG_INIT(lcfg, LCFG_SETUP, osc_dev_name);
188 lcfg.lcfg_inlbuf1 = echo_server_ostname;
189 lcfg.lcfg_inllen1 = strlen(lcfg.lcfg_inlbuf1) + 1;
190 lcfg.lcfg_inlbuf2 = peer;
191 lcfg.lcfg_inllen2 = strlen(lcfg.lcfg_inlbuf2) + 1;
192 err = class_process_config(&lcfg);
194 CERROR("failed setup osc\n");
198 /* attach echo_client */
199 LCFG_INIT(lcfg, LCFG_ATTACH, echo_dev_name);
200 lcfg.lcfg_inlbuf1 = "echo_client";
201 lcfg.lcfg_inllen1 = strlen(lcfg.lcfg_inlbuf1) + 1;
202 lcfg.lcfg_inlbuf2 = echo_uuid_str.uuid;
203 lcfg.lcfg_inllen2 = strlen(lcfg.lcfg_inlbuf2) + 1;
204 err = class_process_config(&lcfg);
206 CERROR("failed attach echo_client\n");
210 /* setup echo_client */
211 LCFG_INIT(lcfg, LCFG_SETUP, echo_dev_name);
212 lcfg.lcfg_inlbuf1 = osc_dev_name;
213 lcfg.lcfg_inllen1 = strlen(lcfg.lcfg_inlbuf1) + 1;
214 lcfg.lcfg_inlbuf2 = NULL;
215 lcfg.lcfg_inllen2 = 0;
216 err = class_process_config(&lcfg);
218 CERROR("failed setup echo_client\n");
225 static int disconnect_echo_client(void)
227 struct lustre_cfg lcfg;
231 /* cleanup echo_client */
232 LCFG_INIT(lcfg, LCFG_CLEANUP, echo_dev_name);
233 err = class_process_config(&lcfg);
235 CERROR("failed cleanup echo_client\n");
239 /* detach echo_client */
240 LCFG_INIT(lcfg, LCFG_DETACH, echo_dev_name);
241 err = class_process_config(&lcfg);
243 CERROR("failed detach echo_client\n");
248 LCFG_INIT(lcfg, LCFG_CLEANUP, osc_dev_name);
249 err = class_process_config(&lcfg);
251 CERROR("failed cleanup osc device\n");
256 LCFG_INIT(lcfg, LCFG_DETACH, osc_dev_name);
257 err = class_process_config(&lcfg);
259 CERROR("failed detach osc device\n");
266 static void usage(const char *s)
268 printf("Usage: %s -s ost_host_name [-n ost_name]\n", s);
269 printf(" ost_host_name: the host name of echo server\n");
270 printf(" ost_name: ost name, default is \"obd1\"\n");
273 extern int time_ptlwait1;
274 extern int time_ptlwait2;
275 extern int time_ptlselect;
277 int main(int argc, char **argv)
281 while ((c = getopt(argc, argv, "s:n:")) != -1) {
284 echo_server_nid = optarg;
287 echo_server_ostname = optarg;
298 if (!echo_server_nid) {
305 tcpnal_mynid = rand();
308 portal_subsystem_debug = 0;
311 if (init_current(argc, argv) ||
312 init_obdclass() || init_lib_portals() ||
317 echo_client_init()) {
322 rc = connect_echo_client();
326 set_ioc_handler(liblustre_ioctl);
328 rc = lctl_main(1, &argv[0]);
330 rc |= disconnect_echo_client();