2 #include <netinet/in.h>
3 #include <sys/socket.h>
6 #include <portals/ptlctl.h> /* needed for parse_dump */
10 #include <linux/obd.h>
11 #include <linux/obd_class.h>
12 #include <procbridge.h>
14 #define LIBLUSTRE_TEST 1
15 #include "../utils/lctl.c"
17 struct ldlm_namespace;
21 unsigned int portal_subsystem_debug = ~0 - (S_PORTALS | S_QSWNAL | S_SOCKNAL |
24 void *inter_module_get(char *arg)
26 if (!strcmp(arg, "tcpnal_ni"))
28 else if (!strcmp(arg, "ldlm_cli_cancel_unused"))
29 return ldlm_cli_cancel_unused;
30 else if (!strcmp(arg, "ldlm_namespace_cleanup"))
31 return ldlm_namespace_cleanup;
32 else if (!strcmp(arg, "ldlm_replay_locks"))
33 return ldlm_replay_locks;
38 /* XXX move to proper place */
39 char *portals_nid2str(int nal, ptl_nid_t nid, char *str)
45 sprintf(str, "%u:%d.%d.%d.%d", (__u32)(nid >> 32),
52 sprintf(str, "%u:%u", (__u32)(nid >> 32), (__u32)nid);
60 ptl_handle_ni_t tcpnal_ni;
70 struct task_struct *current;
73 libcfs_nal_cmd(struct portals_cfg *pcfg)
75 CERROR("empty function!!!\n");
79 int init_current(int argc, char **argv)
81 current = malloc(sizeof(*current));
82 strncpy(current->comm, argv[0], sizeof(current->comm));
83 current->pid = getpid();
87 ptl_nid_t tcpnal_mynid;
89 int init_lib_portals()
94 rc = PtlInit(&max_interfaces);
96 CERROR("ksocknal: PtlNIInit failed: error %d\n", rc);
102 extern int class_handle_ioctl(unsigned int cmd, unsigned long arg);
104 int liblustre_ioctl(int dev_id, int opc, void *ptr)
110 fprintf(stderr, "Unexpected device id %d\n", dev_id);
115 rc = class_handle_ioctl(opc, (unsigned long)ptr);
122 static void generate_random_uuid(unsigned char uuid_out[16])
124 int *arr = (int*)uuid_out;
127 for (i = 0; i < sizeof(uuid_out)/sizeof(int); i++)
131 static char *echo_server_nid = NULL;
132 static char *echo_server_ostname = "obd1";
133 static char *osc_dev_name = "OSC_DEV_NAME";
134 static char *echo_dev_name = "ECHO_CLIENT_DEV_NAME";
136 static int connect_echo_client(void)
138 struct lustre_cfg lcfg;
140 char *peer = "ECHO_PEER_NID";
141 class_uuid_t osc_uuid, echo_uuid;
142 struct obd_uuid osc_uuid_str, echo_uuid_str;
146 generate_random_uuid(osc_uuid);
147 class_uuid_unparse(osc_uuid, &osc_uuid_str);
148 generate_random_uuid(echo_uuid);
149 class_uuid_unparse(echo_uuid, &echo_uuid_str);
151 if (ptl_parse_nid(&nid, echo_server_nid)) {
152 CERROR("Can't parse NID %s\n", echo_server_nid);
155 nal = ptl_name2nal("tcp");
157 CERROR("Can't parse NAL tcp\n");
162 LCFG_INIT(lcfg, LCFG_ADD_UUID, NULL);
164 lcfg.lcfg_inllen1 = strlen(peer) + 1;
165 lcfg.lcfg_inlbuf1 = peer;
167 err = class_process_config(&lcfg);
169 CERROR("failed add_uuid\n");
174 LCFG_INIT(lcfg, LCFG_ATTACH, osc_dev_name);
175 lcfg.lcfg_inlbuf1 = "osc";
176 lcfg.lcfg_inllen1 = strlen(lcfg.lcfg_inlbuf1) + 1;
177 lcfg.lcfg_inlbuf2 = osc_uuid_str.uuid;
178 lcfg.lcfg_inllen2 = strlen(lcfg.lcfg_inlbuf2) + 1;
179 err = class_process_config(&lcfg);
181 CERROR("failed attach osc\n");
186 LCFG_INIT(lcfg, LCFG_SETUP, osc_dev_name);
187 lcfg.lcfg_inlbuf1 = echo_server_ostname;
188 lcfg.lcfg_inllen1 = strlen(lcfg.lcfg_inlbuf1) + 1;
189 lcfg.lcfg_inlbuf2 = peer;
190 lcfg.lcfg_inllen2 = strlen(lcfg.lcfg_inlbuf2) + 1;
191 err = class_process_config(&lcfg);
193 CERROR("failed setup osc\n");
197 /* attach echo_client */
198 LCFG_INIT(lcfg, LCFG_ATTACH, echo_dev_name);
199 lcfg.lcfg_inlbuf1 = "echo_client";
200 lcfg.lcfg_inllen1 = strlen(lcfg.lcfg_inlbuf1) + 1;
201 lcfg.lcfg_inlbuf2 = echo_uuid_str.uuid;
202 lcfg.lcfg_inllen2 = strlen(lcfg.lcfg_inlbuf2) + 1;
203 err = class_process_config(&lcfg);
205 CERROR("failed attach echo_client\n");
209 /* setup echo_client */
210 LCFG_INIT(lcfg, LCFG_SETUP, echo_dev_name);
211 lcfg.lcfg_inlbuf1 = osc_dev_name;
212 lcfg.lcfg_inllen1 = strlen(lcfg.lcfg_inlbuf1) + 1;
213 lcfg.lcfg_inlbuf2 = NULL;
214 lcfg.lcfg_inllen2 = 0;
215 err = class_process_config(&lcfg);
217 CERROR("failed setup echo_client\n");
224 static int disconnect_echo_client(void)
226 struct lustre_cfg lcfg;
230 /* cleanup echo_client */
231 LCFG_INIT(lcfg, LCFG_CLEANUP, echo_dev_name);
232 err = class_process_config(&lcfg);
234 CERROR("failed cleanup echo_client\n");
238 /* detach echo_client */
239 LCFG_INIT(lcfg, LCFG_DETACH, echo_dev_name);
240 err = class_process_config(&lcfg);
242 CERROR("failed detach echo_client\n");
247 LCFG_INIT(lcfg, LCFG_CLEANUP, osc_dev_name);
248 err = class_process_config(&lcfg);
250 CERROR("failed cleanup osc device\n");
255 LCFG_INIT(lcfg, LCFG_DETACH, osc_dev_name);
256 err = class_process_config(&lcfg);
258 CERROR("failed detach osc device\n");
265 static void usage(const char *s)
267 printf("Usage: %s -s ost_host_name [-n ost_name]\n", s);
268 printf(" ost_host_name: the host name of echo server\n");
269 printf(" ost_name: ost name, default is \"obd1\"\n");
272 extern int time_ptlwait1;
273 extern int time_ptlwait2;
274 extern int time_ptlselect;
276 int main(int argc, char **argv)
280 while ((c = getopt(argc, argv, "s:n:")) != -1) {
283 echo_server_nid = optarg;
286 echo_server_ostname = optarg;
297 if (!echo_server_nid) {
304 tcpnal_mynid = rand();
307 portal_subsystem_debug = 0;
310 if (init_current(argc, argv) ||
311 init_obdclass() || init_lib_portals() ||
316 echo_client_init()) {
321 rc = connect_echo_client();
325 set_ioc_handler(liblustre_ioctl);
327 rc = lctl_main(1, &argv[0]);
329 rc |= disconnect_echo_client();